Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 27 additions & 19 deletions code/wdb/writedown.q
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,34 @@ tabsizes:([tablename:`symbol$()] rowcount:`long$(); bytes:`long$()); /- ke

savetables:{[dir;pt;forcesave;tabname]
/- check row count
/- forcesave will write flush the data to disk irrespective of counts
if[forcesave or maxrows[tabname] < arows: count value tabname;
arows:count value tabname;
.lg.o[`rowcheck;"the ",(string tabname)," table consists of ", (string arows), " rows"];
/- upsert data to partition
.lg.o[`save;"saving ",(string tabname)," data to partition ", string pt];
.[
upsert;
(` sv .Q.par[dir;pt;tabname],`;.Q.en[hdbsettings[`hdbdir];r:0!.save.manipulate[tabname;`. tabname]]);
{[e] .lg.e[`savetables;"Failed to save table to disk : ",e];'e}
];
/- make addition to tabsizes
.lg.o[`track;"appending table details to tabsizes"];
.wdb.tabsizes+:([tablename:enlist tabname]rowcount:enlist arows;bytes:enlist -22!r);
/- empty the table
.lg.o[`delete;"deleting ",(string tabname)," data from in-memory table"];
@[`.;tabname;0#];
/- run a garbage collection (if enabled)
if[gc;.gc.run[]];
:1b;
]; 0b};

/- exit early if 0 row count, return 0b for no changes to table
if[0 = arows;:0b];

/- forcesave will write flush the data to disk irrespective of counts
if[forcesave or maxrows[tabname] < arows;
/- upsert data to partition
.lg.o[`save;"saving ",(string tabname)," data to partition ", string pt];
.[
upsert;
(` sv .Q.par[dir;pt;tabname],`;.Q.en[hdbsettings[`hdbdir];r:0!.save.manipulate[tabname;`. tabname]]);
{[e] .lg.e[`savetables;"Failed to save table to disk : ",e];'e}
];
/- make addition to tabsizes
.lg.o[`track;"appending table details to tabsizes"];
.wdb.tabsizes+:([tablename:enlist tabname]rowcount:enlist arows;bytes:enlist -22!r);
/- empty the table
.lg.o[`delete;"deleting ",(string tabname)," data from in-memory table"];
@[`.;tabname;0#];
/- run a garbage collection (if enabled)
if[gc;.gc.run[]];
:1b;
];
:0b
};


\d .
/-endofperiod function
Expand Down