Attributes · Attributes in the Tick Architecture · Practice Question
How Do Attributes Propagate From the Tickerplant to Subscribers?
Question
Does the RDB need to apply attributes manually at startup, or does it inherit them from the tickerplant? Explain how this works in KX's kdb+tick.
Solution
In kdb+tick, the tickerplant applies the grouped attribute to the sym column of every table, and the RDB inherits it through the schema it receives when it subscribes.
/ In the tickerplant (tick.q), .u.tick applies g# to sym in every table:
@[;`sym;`g#]each t
/ The RDB (tick/r.q) subscribes and initialises its tables from the reply:
.u.rep .(hopen `$":",.u.x 0)"(.u.sub[`;`];`.u `i`L)";
/ .u.rep sets each table to the empty schema it received, then replays the log:
.u.rep:{(.[;();:;].)each x;if[null first y;:()];-11!y;system "cd ",1_-10_string first reverse y};After this, in the RDB:
attr trade`sym / `g — inherited from the tickerplant's schemaExplanation
The tickerplant loads the table schemas from a schema file (by default tick/sym.q), and .u.tick applies `g# to the sym column of each table.
When the RDB subscribes, it calls .u.sub[;] synchronously. For each table, the reply contains the table's name and its current (empty) contents — so the schema arrives with the attribute already on sym. .u.rep assigns each of these, so the RDB's tables start out with `g# on sym before any data has arrived.
The RDB's upd function is insert, and g# is kept on append, so the attribute survives both the log replay at startup (-11! re-runs the logged upd calls) and every live update after it.
At end of day, r.q's .u.end saves the tables with .Q.hdpf, which also empties them, and then re-applies `g# to sym on the tables that had it:
.u.end:{t:tables`.;t@:where `g=attr each t@\:`sym;.Q.hdpf[`$":",.u.x 1;`:.;x;`sym];@[;`sym;`g#] each t;};So in standard kdb+tick, the RDB does not need to apply the attribute itself. Other subscribers that build their own tables, rather than taking the schema from .u.sub, would need to apply it explicitly — for example with update `g#sym from `trade.