|
| 1 | +/-default parameters |
| 2 | +\d .idb |
| 3 | + |
| 4 | +wdbtypes:@[value;wdbtypes;`wdb]; |
| 5 | + |
| 6 | +/-these parameters are only used once their value has been set with values retrieved from the WBD. |
| 7 | +writedownmode:idbdir:savedir:currentpartition:symfilepath:`; |
| 8 | +symsize:partitionsize:0; |
| 9 | + |
| 10 | +/-force loads sym file |
| 11 | +loadsym:{[] |
| 12 | + .lg.o[`load;"loading the sym file"]; |
| 13 | + @[load;symfilepath; {.lg.e[`load;"failed to load sym file: ",string[symfilepath]," error: ",x]}]; |
| 14 | + symsize::hcount symfilepath; |
| 15 | + }; |
| 16 | + |
| 17 | +/-force loads IDB |
| 18 | +loadidb:{[] |
| 19 | + .lg.o[`load;"loading the db"]; |
| 20 | + @[system; "l ", 1_string idbdir; {.lg.e[`load;"failed to load IDB: ",string[idbdir]," error: ",x]}]; |
| 21 | + partitionsize::count key idbdir; |
| 22 | + }; |
| 23 | + |
| 24 | +/- force loads the idb and the sym file |
| 25 | +loaddb:{[] |
| 26 | + starttime:.proc.ct[]; |
| 27 | + loadsym[]; |
| 28 | + loadidb[]; |
| 29 | + .lg.o[`load;"IDB load has been finished for partition: ",string[currentpartition],". Time taken(ms): ",string .proc.ct[]-starttime]; |
| 30 | + }; |
| 31 | + |
| 32 | +/- sets current partition and force loads the idb and the sym file. Called by the WDB after EOD. |
| 33 | +rollover:{[pt] |
| 34 | + currentpartition::pt; |
| 35 | + idbdir::.Q.dd[savedir; currentpartition]; |
| 36 | + loaddb[]; |
| 37 | + }; |
| 38 | + |
| 39 | +/- reloads the db. Called by wdb process midday/eod. |
| 40 | +intradayreload:{[] |
| 41 | + starttime:.proc.ct[]; |
| 42 | + if[symfilehaschanged[];loadsym[]]; |
| 43 | + if[partitioncounthaschanged[];loadidb[]]; |
| 44 | + .lg.o[`intradayreload;"IDB reload has been finished for partition: ",string[savedir],". Time taken(ms): ",string .proc.ct[]-starttime]; |
| 45 | + }; |
| 46 | + |
| 47 | +/- checks if sym file has changed since last reload of the IDB. Records new sym size if changed. |
| 48 | +symfilehaschanged:{[] |
| 49 | + $[symsize<>c:hcount symfilepath;[symsize::c; 1b];0b] |
| 50 | + }; |
| 51 | + |
| 52 | +/- checks if count of partitions has changed since last reload of the IDB. Records new partition count if changed. |
| 53 | +/- the default writedown method doesn't need db reloading as no new directory is being created there. |
| 54 | +partitioncounthaschanged:{[] |
| 55 | + if[writedownmode~`default;:0b]; |
| 56 | + $[partitionsize<>c:count key idbdir;[partitionsize::c; 1b];0b] |
| 57 | + }; |
| 58 | + |
| 59 | +setparametersfromwdb:{[wdbHandle] |
| 60 | + .lg.o[`init;"querying WDB, HDB locations, current partition and writedown mode from WDB"]; |
| 61 | + params:@[wdbHandle; (each;value;`.wdb.savedir`.wdb.hdbdir`.wdb.currentpartition`.wdb.writedownmode); {.lg.e[`connection; "Failed to retrieve values from WDB."]; 'x}]; |
| 62 | + savedir::hsym params[0]; |
| 63 | + currentpartition::params[2]; |
| 64 | + symfilepath::.Q.dd[hsym params[1]; `sym]; |
| 65 | + writedownmode::params[3]; |
| 66 | + idbdir::.Q.dd[savedir; $[writedownmode~`default;`;currentpartition]]; |
| 67 | + .lg.o[`init;"Current settings: db folder: ",string[idbdir],", sym file: ",string[symfilepath],", writedownmode: ", string writedownmode]; |
| 68 | + }; |
| 69 | + |
| 70 | +init:{[] |
| 71 | + .lg.o[`init; "searching for servers"]; |
| 72 | + .servers.startup[]; |
| 73 | + .lg.o[`init;"getting connection handle to the WDB"]; |
| 74 | + w:.servers.gethandlebytype[wdbtypes;`any]; |
| 75 | + /-exit if no valid handle |
| 76 | + if[0=count w; .lg.e[`connection;"no connection to the WDB could be established... failed to initialise."];:()]; |
| 77 | + .lg.o[`init;"found a WDB process"]; |
| 78 | + /-setting parameters in .idb namespace from WDB |
| 79 | + setparametersfromwdb[w]; |
| 80 | + .lg.o[`init;"loading the db and the sym file first time"]; |
| 81 | + loaddb[]; |
| 82 | + .lg.o[`init;"registering IDBs on WDB process..."]; |
| 83 | + /-send sync message to WDB to register the existing IDBs. |
| 84 | + @[w;(`.servers.registerfromdiscovery;`idb;0b);{.lg.e[`connection;"Failed to register IDB with WDB."];'x}]; |
| 85 | + .lg.o[`init; "Initialisation of the IDB is done."]; |
| 86 | + } |
| 87 | + |
| 88 | +\d . |
| 89 | + |
| 90 | +.idb.init[]; |
| 91 | + |
| 92 | +/- helper function to support queries against the sym column |
| 93 | +maptoint:{[symbol] |
| 94 | + sym?symbol |
| 95 | + }; |
0 commit comments