Skip to content

Commit b74ad0e

Browse files
authored
new writedown mode partbyenum and new intraday process (#656)
* added partbyenum writedown mode * new idb process * added idb process * changing EOL to unix * changed idb logic * idb notification logging refined * createalias refined and added to os.q * addressed comments, removed gmttime, refactored * correcting indentation, removing reload function from idbstandard.q * removing unused server types from wdb * added back comment in processes/wdb.q * added hsym to folder parameters * added testing wdb partbyenum * added test for idb process, added hsym to hdbdir and wdbdir parmters for idb * added documentation for partbyenum and idb * added graphics for idb docs * EOL changed to LF * IDB is accessible via Gateway * IDB doesn't fail on restart or empty database * IDB reworked - connects to WDB and registers itself with WDB. IDB has no significant downtime now. WDB now initialises the DB after EOD rollover. * WDB refactored to support new writedown mode partbyenum more * IDB intraday reload and logging improved. Fixed some comments.
1 parent 1595084 commit b74ad0e

File tree

27 files changed

+754
-305
lines changed

27 files changed

+754
-305
lines changed

code/common/merge.q

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,19 @@ getextrapartitiontype:{[tablename]
2020
tabparts
2121
};
2222

23-
/- function to check each partiton type specified in sort.csv is actually present in specified table
23+
/- function to check each partition type specified in sort.csv is actually present in specified table
2424
checkpartitiontype:{[tablename;extrapartitiontype]
2525
$[count colsnotintab:extrapartitiontype where not extrapartitiontype in cols get tablename;
2626
.lg.e[`checkpart;"parted columns ",(", " sv string colsnotintab)," are defined in sort.csv but not present in ",(string tablename)," table"];
2727
.lg.o[`checkpart;"all parted columns defined in sort.csv are present in ",(string tablename)," table"]];
2828
};
2929

30+
/- function to check if the extra partition column has a symbol type
31+
checksymboltype:{[tablename;extrapartitiontype]
32+
$[all extrapartitiontype in exec c from meta[tablename] where t="s";
33+
.lg.o[`checksymbol;"all columns do have a symbol type in ",(string tablename)," table"];
34+
.lg.e[`checksymbol;"not all columns ",string[extrapartitiontype]," do have a symbol type in ",(string tablename)," table"]];
35+
};
3036

3137

3238
/- function to get list of distinct combiniations for partition directories
@@ -66,7 +72,7 @@ mergebypart:{[tablename;dest;partchunks]
6672
.lg.o[`merge;"upserting ",(string count chunks)," rows to ",string dest];
6773
/-merge columns to permanent storage
6874
.[upsert;(dest;chunks);
69-
{.lg.e[`merge;"failed to merge to ", sting[dest], " from segments ", (", " sv string chunks)];}];
75+
{.lg.e[`merge;"failed to merge to ", string[dest], " from segments ", (", " sv string chunks)];}];
7076
};
7177

7278
/-merge data from partition in temporary storage to permanent storage, column by column rather than by entire partition

code/common/os.q

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ df:{(`$("/";"\\")[NT]sv -1_v;`$-1#v:("/";"\\")[NT]vs pth(string x;x)[10h=type x]
2121
run:{system"q ",x}
2222
kill:{[p]@[(`::p);"\\\\";1];}
2323
sleep:{x:string x; system("sleep ",x;"timeout /t ",x," >nul")[NT]}
24-
pthq:{[x] $[10h=type x;ssr [x;"\\";"/"];`$ -1 _ ssr [string (` sv x,`);"\\";"/"]]}
24+
pthq:{[x] $[10h=type x;ssr [x;"\\";"/"];`$ -1 _ ssr [string (` sv x,`);"\\";"/"]]}

code/processes/idb.q

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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

Comments
 (0)