Repository navigation
Feature/wdb module #137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Feature/wdb module #137
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
ba9954d
di.torq.proc.wdb 0.3.0: port legacy wdb, with sort and sortworker mod…
pkaiserq 3296bc3
di.torq.proc.wdb: fixes from review
pkaiserq fa89281
Merge branch 'main' into feature/wdb-module
DI-Dexter 8019834
di.torq.proc.wdb: init subscriptions only on the save path, and fix t…
DI-Dexter 562d159
di.torq.proc.wdb: address the review findings
DI-Dexter c0c6c43
di.torq.proc.wdb: close two gaps against legacy wdb
DI-Dexter b58ac79
di.subscriptions: install the default endofperiod callback there, not…
DI-Dexter c7521b2
Revert the endofperiod work - feature-segmentedtp owns it
DI-Dexter efdf8fd
Merge remote-tracking branch 'upstream/main' into wdb-merge-main
DI-Dexter 44e60f4
Drop the stray email file; strip the hsym colon from idb path logging
DI-Dexter e0672c2
di.torq.proc.wdb: stop the sort fixture's table leaking into a re-run
DI-Dexter 921247c
di.torq.proc.wdb: silence the shell for the deliberately failing move
DI-Dexter 9c2f687
di.torq.proc.wdb: quietshell must not swallow a throw
DI-Dexter f3d9148
di.torq.proc.wdb: restore legacy reload, endofperiod stub and numtab …
DI-Dexter 0552a8c
di.torq.proc.wdb: document the numtab upgrade, stop restating di.merg…
DI-Dexter a164edc
di.torq.proc.wdb: close three gaps against the module standards in PR…
DI-Dexter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,117 +1,105 @@ | ||
| / di.torq.proc.idb - intraday database process type. Mounts the WDB's *working* directory (the | ||
| / same `savedir` the wdb writes/appends into during the day, before EOD sort+move into the | ||
| / hdb - see di.torq.proc.wdb) so queries can see today's not-yet-persisted-to-hdb data intraday. | ||
| / --- | ||
| / v1 is a minimal, di.torq.proc.hdb-shaped mount + remount: di.torq.proc.idb only exposes a | ||
| / remotely-triggerable `.idb.intradayreload[]`, same shape as di.torq.proc.hdb's `.hdb.reload[]` - | ||
| / something else has to call it after data changes on disk. idb itself never polls or pushes; | ||
| / that something else is the wdb, which calls `.idb.intradayreload[]` on every idbtypes connection two | ||
| / ways - after any intraday flush that actually wrote something (unconditional), and again at | ||
| / EOD if `idb` is opted into `reloadorder` (see di.torq.proc.wdb's wdb.q/wdb.md). | ||
| / --- | ||
| / It mounts savedir ITSELF, as a partitioned database, exactly as legacy TorQ's idb does in | ||
| / default writedown mode (idbdir::.Q.dd[savedir;`]). So the tables carry a virtual `date` column | ||
| / and the idb never needs to know which date the wdb is on - a new day's partition simply appears | ||
| / under the root and the next reload picks it up. Mounting a single date directory instead would | ||
| / mean tracking the wdb's partition, which wall-clock .z.d gets wrong for any end of day that is | ||
| / not at midnight. | ||
| / --- | ||
| / The wdb enumerates every flushed table against ITS hdbdir, not against savedir (see | ||
| / di.torq.proc.wdb's flushtable, `.Q.en[.z.m.hdbdir;...]`) - live, on every flush, not just at | ||
| / EOD (`.Q.en` extends the domain AND rewrites hdbdir/sym on disk whenever it sees a symbol | ||
| / that domain doesn't already have). So the mounted working-partition tables' symbol columns | ||
| / are enumerated (foreign-keyed) against that SAME hdbdir/sym, not anything under savedir - | ||
| / idb needs `hdbdir` as its own config, purely to load that file into its own session's root | ||
| / `sym`, independently of mounting savedir. Without it, `` `sym `` never exists in the idb's | ||
| / session and a symbol column reads back as raw enum indices instead of symbols. | ||
| / di.torq.proc.idb - ported from TorQ's idb.q | ||
| / mounts the wdb's working directory so today's data can be queried before it reaches the hdb | ||
|
|
||
| astz:{[x] $[11h=abs type x;x;`$(),x]} | ||
| tolong:{[x] $[10h=abs type x;"J"$(),x;"j"$x]} | ||
|
|
||
| / legacy TorQ's symfilehaschanged. Size, not mtime: .Q.en only ever appends. | ||
| / hcount is trapped where legacy calls it bare: the wdb creates hdb/sym on its first .Q.en, so a | ||
| / wdb that is up but has not flushed yet leaves us statting a file that is not there. | ||
| symfilehaschanged:{[] | ||
| .z.m.symsize<>@[hcount;.z.m.symfilepath;0] | ||
| } | ||
|
|
||
| / legacy TorQ's `load symfilepath` - it names the variable after the file, so it sets root `sym` | ||
| / even from inside a use-loaded module (verified). REPLACES rather than merges: the file is the | ||
| / enumeration domain and the on-disk columns are positions in it, so root sym must match its order | ||
| / exactly - a union against a reordered sym resolves every symbol column to the wrong value. | ||
| readsym:{[f] | ||
| load f; | ||
| .z.m.log[`info][`loadsym;"loaded sym domain (",(string count get `sym),") from ",string f]; | ||
| .z.m.symsize:@[hcount;f;0]; | ||
| / force loads sym file; the size is only recorded once the load succeeds, so a failed read is retried | ||
| loadsym:{[] | ||
| .z.m.log[`info][`load;"loading the sym file"]; | ||
| @[{load x;.z.m.symsize:@[hcount;x;0]};.z.m.symfilepath;{.z.m.log[`error][`load;"failed to load sym file: ",(1_string .z.m.symfilepath)," error: ",x]}]; | ||
| } | ||
|
|
||
| / force-load the sym domain; the caller decides whether to skip, as legacy splits loaddb from | ||
| / intradayreload. A missing file is logged and survived - symsize stays 0 so the next reload | ||
| / picks it up once a wdb has flushed. | ||
| loadsym:{[] | ||
| .z.m.log[`info][`loadsym;"loading the sym file"]; | ||
| @[readsym;.z.m.symfilepath;{.z.m.log[`error][`loadsym;"failed to load sym file: ",(1_string .z.m.symfilepath),", with error: ",x]}]; | ||
| / force loads IDB | ||
| loadidb:{[] | ||
| .z.m.log[`info][`load;"loading the db"]; | ||
| @[system;"l ",1_string .z.m.idbdir;{.z.m.log[`error][`load;"failed to load IDB: ",(1_string .z.m.idbdir)," error: ",x]}]; | ||
| .z.m.partitionsize:count key .z.m.idbdir; | ||
| } | ||
|
|
||
| / (re)mount savedir as a partitioned db. Empty or absent is normal - the wdb creates it on its | ||
| / first flush - so warn and leave what is loaded rather than let system "l" take the process down. | ||
| domount:{[] | ||
| d:1_string .z.m.savedir; | ||
| $[count key .z.m.savedir; | ||
| [system "l ",d; .z.m.log[`info][`domount;"loaded tables: ",", " sv string tables[]]]; | ||
| .z.m.log[`warn][`domount;"no working directory at ",d," yet - nothing to mount"]]; | ||
| / force loads the idb and the sym file | ||
| loaddb:{[] | ||
| starttime:.z.t; | ||
| loadsym[]; | ||
| loadidb[]; | ||
| .z.m.log[`info][`load;"IDB load has been finished for partition: ",(string .z.m.currentpartition),". Time taken(ms): ",string .z.t-starttime]; | ||
| } | ||
|
|
||
| / the wdb has rolled to a new day (legacy's .idb.rollover). The root mount finds the new day by | ||
| / itself, so .z.m.partition drives nothing today - it is kept for the two things that will need it: | ||
| / gateway routing (legacy's .proc.getattributes) and the partition-scoped writedown modes, where | ||
| / the mount is savedir/<partition> rather than the root. Not exposed until one of them lands. | ||
| / sets current partition and force loads the idb and the sym file. Called by the wdb after EOD. | ||
| rollover:{[pt] | ||
| .z.m.partition:pt; | ||
| .z.m.log[`info][`rollover;"wdb rolled to partition ",string pt]; | ||
| intradayreload[]; | ||
| .z.m.currentpartition:pt; | ||
| .z.m.idbdir:.Q.dd[.z.m.savedir;$[.z.m.writedownmode~`default;`;pt]]; | ||
| .z.m.log[`info][`rollover;"IDB folder has been set to: ",1_string .z.m.idbdir]; | ||
| loaddb[]; | ||
| } | ||
|
|
||
| / reloads the db. Called by the wdb after an intraday flush. | ||
| intradayreload:{[] | ||
|
DI-Dexter marked this conversation as resolved.
Resolved
|
||
| .z.m.log[`info][`reload;"reloading idb from ",1_string .z.m.savedir]; | ||
| starttime:.z.t; | ||
| if[symfilehaschanged[];loadsym[]]; | ||
| domount[]; | ||
| if[partitioncounthaschanged[];loadidb[]]; | ||
| clearrowcountcache[]; | ||
| .z.m.log[`info][`intradayreload;"IDB reload has been finished for partition: ",(string .z.m.currentpartition),". Time taken(ms): ",string .z.t-starttime]; | ||
| } | ||
|
|
||
| / ask the wdb where it is writing and set our state from it - same name and job as legacy's. | ||
| / The two must agree on savedir and hdbdir, and config on both sides drifts apart. | ||
| / checks if sym file has changed since last load of the IDB; hcount trapped as hdb/sym is absent until the wdb's first .Q.en | ||
| symfilehaschanged:{[] .z.m.symsize<>@[hcount;.z.m.symfilepath;0]} | ||
|
|
||
| / checks if count of partitions has changed since last reload of the IDB. Records new partition count if changed. | ||
| / the default writedown method doesn't need db reloading as no new directory is being created there. | ||
| partitioncounthaschanged:{[] | ||
| if[(1j~.z.m.partitionsize) and .z.m.writedownmode~`default;:0b]; | ||
| $[.z.m.partitionsize<>c:count key .z.m.idbdir;[.z.m.partitionsize:c;1b];0b] | ||
| } | ||
|
|
||
| / this makes sure running "count trade" queries will return correct row count | ||
| clearrowcountcache:{[] set[`.Q.pn;.Q.pt!(count .Q.pt)#()]} | ||
|
|
||
| / reads savedir, hdbdir, the current partition and the writedown mode from the wdb | ||
| setparametersfromwdb:{[config] | ||
| wt:$[`wdbtypes in key config;astz config`wdbtypes;`wdb]; | ||
| t:$[`connecttimeoutms in key config;tolong config`connecttimeoutms;30000]; | ||
| (.z.m.svc`startup)[config,(enlist`connections)!enlist enlist wt]; | ||
| if[not (.z.m.svc`waitfortype)[wt;t;500]; | ||
| '"di.torq.proc.idb: no ",(string wt)," connection within ",(string t),"ms - cannot resolve savedir/hdbdir"]; | ||
| h:(.z.m.svc`gethandlebytype)[wt;`any]; | ||
| / the error carries the offending name, so it needs no interpolation of our own | ||
| p:@[h;(each;value;`.wdb.savedir`.wdb.hdbdir`.wdb.currentpartition);{'"di.torq.proc.idb: could not read from the wdb: ",x}]; | ||
| / the wdb's paths are already hsyms; keep them as such and build the sym path with .Q.dd, as | ||
| / legacy's symfilepath does. It is never partition-scoped - every day enumerates against the one. | ||
| .z.m.savedir:p 0; | ||
| .z.m.symfilepath:.Q.dd[p 1;`sym]; | ||
| .z.m.partition:p 2; | ||
| .z.m.log[`info][`setparametersfromwdb;"savedir=",(1_string .z.m.savedir),", partition=",string .z.m.partition]; | ||
| .z.m.log[`info][`init;"querying WDB, HDB locations, current partition and writedown mode from WDB"]; | ||
| params:@[h;(each;value;`.wdb.savedir`.wdb.hdbdir`.wdb.currentpartition`.wdb.writedownmode);{'"di.torq.proc.idb: could not read from the wdb: ",x}]; | ||
| .z.m.savedir:hsym params 0; | ||
| .z.m.currentpartition:params 2; | ||
| .z.m.symfilepath:.Q.dd[hsym params 1;`sym]; | ||
| .z.m.writedownmode:params 3; | ||
| .z.m.idbdir:.Q.dd[.z.m.savedir;$[.z.m.writedownmode~`default;`;.z.m.currentpartition]]; | ||
| .z.m.log[`info][`init;"Current settings: db folder: ",(1_string .z.m.idbdir),", sym file: ",(1_string .z.m.symfilepath),", writedownmode: ",string .z.m.writedownmode]; | ||
| } | ||
|
|
||
| / helper function to support queries against the sym column | ||
| maptoint:{[val] | ||
| $[(abs type val) in 5 6 7h; | ||
| / if using an integer column, clamp value between 0 and max int (null maps to 0) | ||
| 0|2147483647&`long$val; | ||
| / if using a symbol column, enumerate against the hdb sym file | ||
| (`. `sym)?`TORQNULLSYMBOL^val] | ||
| } | ||
|
|
||
| / helper function to support queries against the sym column in partbyfirstchar | ||
| mapfctoint:{[val] .Q.an?$[0<type val;first each;first] string val} | ||
|
|
||
| / reads deps and the wdb's parameters, then loads the db and the sym file | ||
| init:{[config;deps] | ||
| if[not `log in key deps;'"di.torq.proc.idb: log dependency is required - see di.util.log"]; | ||
| .z.m.log:deps`log; | ||
| if[not `servers in key deps;'"di.torq.proc.idb: servers dependency is required - injected by di.torq, see di.torq.servers"]; | ||
| .z.m.svc:deps`servers; | ||
| setparametersfromwdb config; | ||
| .z.m.log[`info][`init;"mounting idb from ",1_string .z.m.savedir]; | ||
| / symsize starts at 0, which is also what a missing sym file stats as - so the first load always | ||
| / happens, and readsym only records a size on success | ||
| .z.m.symsize:0; | ||
| loadsym[]; | ||
| domount[]; | ||
| / publish the IPC-callable surface at a real root-level name - use-loading this file | ||
| / compiles it into a private namespace (see di.torq.proc.hdb.init's identical note: a remote | ||
| / `.idb.intradayreload[]` call would otherwise hit an undefined-function error). | ||
| .z.m.partitionsize:0; | ||
| .z.m.log[`info][`init;"loading the db and the sym file first time"]; | ||
| loaddb[]; | ||
| / use-loading compiles into a private namespace, so publish the IPC surface and query helpers at root | ||
| set[`.idb.intradayreload;intradayreload]; | ||
| set[`.idb.rollover;rollover]; | ||
| set[`maptoint;maptoint]; | ||
| set[`mapfctoint;mapfctoint]; | ||
| .z.m.log[`info][`init;"Initialisation of the IDB is done."]; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 0.2.0 | ||
| 0.3.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,4 +2,4 @@ | |
|
|
||
| version:first read0`:::VERSION | ||
|
|
||
| export:([init;endofday;version]) | ||
| export:([init;endofday;endofdaysort;version]) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.