help to read ld function from ticker-plant's tick.q

Would someone may help explaining what’s happening with ld function?

e.g. where’s L defined?

What it does symbol by symbol …

Thanks a lot!

My aim is to read whole https://github.com/KxSystems/kdb-tick/blob/master/tick.q content, but currently strugling with particular line:

|
| |
| ld:{if[not type key L::`$(-10_string L),string x;.[L;();:;()]];i::j::-11!(-2;L);if[0<=type i;-2 (string L)," is a corrupt log. Truncate to length “,(string last i),” and restart";exit 1];hopen L}; |
|
|

Hi Pranas

The line above this function brings you into the .u namespace inside the tickerplant (by calling \d .u). In the root namespace you could replace every instance of L with .u.L which is the file handle to the logfile that the tickerplant is currently writing to. As such, L here refers to that same log. E.g.:

  q).u.L

`:/home/jburrows/hdb/database2018.03.19

This also means that the function ld outside the .u namespace would need to be called as .u.ld

If you check the function below .u.ld, i.e. tick (or .u.tick outside the .u namespace):

tick:{init;if[not min(timesym~2#key flip value@)each t;'timesym];@[;sym;g#]each t;d::.z.D;if[l::count y;L::$“:”,y,“/”,x,10#“.”;l::ld d]};

You’ll see .u.init is called (.u.init is defined in .u.q) and at the very end of the function, .u.L is defined.

Hope this helps,

James

On Monday, March 19, 2018 at 8:30:38 AM UTC, Pranas Baliuka wrote:

Would someone may help explaining what’s happening with ld function?

e.g. where’s L defined?

What it does symbol by symbol …

Thanks a lot!

My aim is to read whole https://github.com/KxSystems/kdb-tick/blob/master/tick.q content, but currently strugling with particular line:

|
| |
| ld:{if[not type key L::`$(-10_string L),string x;.[L;();:;()]];i::j::-11!(-2;L);if[0<=type i;-2 (string L)," is a corrupt log. Truncate to length “,(string last i),” and restart";exit 1];hopen L}; |
|
|

Hi Pranas, to add on more information, in line with your original request,

Splitting this function up into smaller chunks, and noting that .u.L has been initialised on the call to .u.tick.

if[not type key L::`$(-10_string L),string x;.[L;();:;()]]

The logfile name is a combination of the src parameter and the date the logfile is relevant to.

A string representation of a date is 10 chars in length. This portion of code, updates the date portion of the logfile name, using the input argument, checks to see if that file exists using key

and, if it doesn’t, then creates an empty kdb log file with that name using  .[L;();:;()]]

i::j::-11!(-2;L);

This portion creates two counter variables (one of which is used when the TP is run in batch mode) that tracks the number of updates in the log file and un-published.

These are used by clients to “recover” from the log file. The -11!(2;L) calculates the number of updates in an existing logfile. Usually this will be zero, but on an intra-day restart this may not be the case.

  if[0<=type i;-2 (string L)," is a corrupt log. Truncate to length “,(string last i),” and restart";exit 1]

If i is positive, an issue exists with the log. The TP simply exists.

  hopen L

Finally a handle to the logfile is opened, and is the functions return, which is assigned to .u.l. This is used by other functions to append to the log.