From fff7e219598809c115652572a84049ae0457bbe7 Mon Sep 17 00:00:00 2001 From: Marcos Jaen Date: Wed, 18 Nov 2026 10:28:37 -0500 Subject: [PATCH 1/5] Fix four segmented tickerplant bugs - End of day and end of period called .stpps.pubclear[.stplg.t]. That list is every table in the process, including logmsg, but pubclear resets each table from the publish schemas, which since #638 have no entry for logmsg. A dictionary of tables returns an empty copy of its first table for a key it does not have, so at every roll logmsg was quietly replaced by an empty table with another table's columns. The three calls now pass .stpps.t, as the batch code already does. - The exit handler closed .stpps.t, the published tables, although a log is opened for every table in .stplg.logtabs. On a clean shutdown the logmsg log stayed open and its row in the meta table kept a null end time. It now closes .stplg.logtabs, the list end of day uses. - A chained tickerplant that is not creating logs replaces the loghandles view with a dictionary of no-ops (#368). If it was then switched to create its own logs, they were opened but nothing was written to them, because loghandles was still that dictionary. The view is now restored when a chained tickerplant opens logs. - At each end of period a chained tickerplant moved .stplg.currperiod on but never .stplg.nextperiod, so after its first roll nextperiod named the period that had just started. It now moves on with its parent: the new period plus the parent's period length. --- code/segmentedtickerplant/stplog.q | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/code/segmentedtickerplant/stplog.q b/code/segmentedtickerplant/stplog.q index b587c7311..95c284601 100644 --- a/code/segmentedtickerplant/stplog.q +++ b/code/segmentedtickerplant/stplog.q @@ -5,6 +5,9 @@ currlog:([tbl:`symbol$()]logname:`symbol$();handle:`int$()) // View of log file handles for faster lookups loghandles::exec tbl!handle from currlog +// Re-establish the view above. A chained tickerplant which is not creating logs replaces it with a dictionary of +// no-ops (see init); without this, switching that process to create its own logs opened them but wrote nothing +restoreloghandles:{value "loghandles::exec tbl!handle from currlog"}; \d .stplg @@ -184,10 +187,12 @@ endofdaydata:@[value;`.stplg.endofdaydata;{ {`proctype`procname`tables!(.proc.pr // passes on eop messages to subscribers and rolls logs endofperiod:{[currentpd;nextpd;data] .lg.o[`endofperiod;"flushing remaining data to subscribers and clearing tables"]; - .stpps.pubclear[.stplg.t]; + // the published tables only: pubclear resets a table from the publish schemas, which have no entry for logmsg + .stpps.pubclear[.stpps.t]; .lg.o[`endofperiod;"executing end of period for ",.Q.s1 `currentperiod`nextperiod!(currentpd;nextpd)]; .stpps.endp[currentpd;nextpd;data]; // sends endofperiod message to subscribers currperiod::nextpd; // increments current period + nextperiod::nextpd+nextpd-currentpd; // and the next one: the SCTP rolls when its parent does if[.sctp.loggingmode=`create;periodrollover[data]] // logs only rolled if in create mode }; @@ -195,7 +200,7 @@ endofperiod:{[currentpd;nextpd;data] // eop log roll is stopped if eod is also going to be triggered (roll is not stopped in SCTP) stpeoperiod:{[currentpd;nextpd;data;rolllogs] .lg.o[`endofperiod;"flushing remaining data to subscribers and clearing tables"]; - .stpps.pubclear[.stplg.t]; + .stpps.pubclear[.stpps.t]; .lg.o[`stpeoperiod;"passing on endofperiod message to subscribers"]; .stpps.endp[currentpd;nextpd;data]; // sends endofperiod message to subscribers currperiod::nextperiod; // increments current period @@ -215,7 +220,7 @@ periodrollover:{[data] // common eod for STP and SCTP to send out eod messages and roll logs endofday:{[date;data] .lg.o[`endofday;"flushing remaining data to subscribers and clearing tables"]; - .stpps.pubclear[.stplg.t]; + .stpps.pubclear[.stpps.t]; .lg.o[`endofday;"executing end of day for ",.Q.s1 .eodtime.d]; .stpps.end[date;data]; // sends endofday message to subscribers dayrollover[data]; @@ -259,6 +264,7 @@ init:{[dbname] seqnum::0; if[(value `..createlogs) or .sctp.loggingmode=`create; + if[.sctp.chainedtp;`.[`restoreloghandles][]]; createdld[dbname;.eodtime.d]; openlog[multilog;dldir;;.z.p+.eodtime.dailyadj]each logtabs; // If appropriate, roll error log @@ -294,6 +300,6 @@ init:{[dbname] // exit before logs are touched if process is an sctp NOT in create mode if[.sctp.chainedtp and not .sctp.loggingmode=`create; :()]; .lg.o[`stpexit;"Closing off log files"]; - .stpm.updmeta[.stplg.multilog][`close;.stpps.t;.z.p]; - .stplg.closelog each .stpps.t; + .stpm.updmeta[.stplg.multilog][`close;.stplg.logtabs;.z.p]; + .stplg.closelog each .stplg.logtabs; }] From 1bc586d2ea268be7cf9846732bd09cb40ef4acf9 Mon Sep 17 00:00:00 2001 From: Marcos Jaen Date: Wed, 18 Nov 2026 10:28:37 -0500 Subject: [PATCH 2/5] Fix the WDB's end-of-day merge in col mode, and the default .save.postreplay - Since partbyenum came in (#656), merge only merges the partitions listed in .merge.partsizes. The WDB still sent that table to the sort processes, and the sort process to its workers, only in part and hybrid mode. In col mode they had an empty table, so at end of day they wrote an empty partition to the HDB and deleted the saved data. merge/wdb did not catch it because its WDBs loaded their settings after wdb.q, so they saved in default mode and never took the merge path at all. The settings now load first. - The default .save.postreplay was @[value;`postreplay;{[d;p] }]: when no postreplay is defined, the trap passes the error to its handler, so the default became a projection of {[d;p] } on the error string, and every end of day which called .save.postreplay[dir;date] stopped with 'rank (introduced by #762). The handler now returns the no-op function. stp/wdb partbyenum.csv triggers a WDB end of day and then checks the HDB; with the old default the trigger and both HDB checks failed. A new row calls the WDB's hook with (dir;date), as wdb.q does at end of day, so a regression fails with its cause named. --- code/common/dbwriteutils.q | 2 +- code/processes/wdb.q | 12 ++++-------- tests/merge/wdb/config/process.csv | 12 ++++++------ tests/stp/wdb/partbyenum.csv | 1 + 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/code/common/dbwriteutils.q b/code/common/dbwriteutils.q index 97a997fb5..f3bdc6a72 100644 --- a/code/common/dbwriteutils.q +++ b/code/common/dbwriteutils.q @@ -79,7 +79,7 @@ manipulate:{[t;x] /- post eod/replay, this is called after the date has been persisted to disk and sorted and /- takes a directory (typically hdb directory) and partition value as parameters -postreplay:@[value;`postreplay;{[d;p] }]; +postreplay:@[value;`postreplay;{[e] {[d;p] }}]; / - functions for running and descriptively logging garbage collection \d .gc diff --git a/code/processes/wdb.q b/code/processes/wdb.q index f67a1a77b..44de1cbfb 100644 --- a/code/processes/wdb.q +++ b/code/processes/wdb.q @@ -397,10 +397,8 @@ endofdaymerge:{[dir;pt;tablist;mergelimits;hdbsettings;mergemethod;writedownmode $[tempfix2 and ((system "s")<0); [.lg.o[`merge;"merging on worker"]; {(neg x)(`.wdb.reloadsymfile;y);(neg x)(::)}[;.Q.dd[hdbsettings `hdbdir;`sym]] each .z.pd[]; - /-upsert .merge.partsize data to sort workers, only needed for part and hybrid method - if[(mergemode~`hybrid)or(mergemode~`part); - {(neg x)(upsert;`.merge.partsizes;y);(neg x)(::)}[;.merge.partsizes] each .z.pd[]; - ]; + /-upsert .merge.partsize data to sort workers, whatever the merge method: merge only merges the partitions listed there + {(neg x)(upsert;`.merge.partsizes;y);(neg x)(::)}[;.merge.partsizes] each .z.pd[]; merge[dir;pt;;mergelimits;hdbsettings;mergemethod;writedownmode] peach flip (key tablist;value tablist); /-clear out in memory table, .merge.partsizes, and call sort worker processes to do the same .lg.o[`eod;"Delete from partsizes"]; @@ -513,10 +511,8 @@ informgateway:{[message] informsortandreload:{[dir;pt;tablist;writedownmode;mergelimits;hdbsettings;mergemethod] .lg.o[`informsortandreload;"attempting to contact sort process to initiate data ",$[writedownmode~`default;"sort";"merge"]]; $[count sortprocs:.servers.getservers[`proctype;sorttypes;()!();1b;0b]; - [if[(mergemode~`hybrid)or(mergemode~`part); - // for part and hybrid method sort procs need access to partsizes table data - upsert data tp sort procs - {(neg x)(upsert;`.merge.partsizes;y);(neg x)(::)}[;.merge.partsizes] each exec w from sortprocs; - ]; + // sort procs need the partsizes table data whatever the merge method: merge only merges the partitions listed there + [{(neg x)(upsert;`.merge.partsizes;y);(neg x)(::)}[;.merge.partsizes] each exec w from sortprocs; {.[{neg[y]@x;neg[y][]};(x;y);{.lg.e[`informsortandreload;"unable to run command on sort and reload process"];'x}]}[(`.wdb.endofdaysort;dir;pt;tablist;writedownmode;mergelimits;hdbsettings;mergemethod);] each exec w from sortprocs; ]; [.lg.e[`informsortandreload;"can't connect to the sortandreload - no sortandreload process detected"]; diff --git a/tests/merge/wdb/config/process.csv b/tests/merge/wdb/config/process.csv index 61487a923..e8958d9ad 100644 --- a/tests/merge/wdb/config/process.csv +++ b/tests/merge/wdb/config/process.csv @@ -2,9 +2,9 @@ host,port,proctype,procname,U,localtime,g,T,w,load,startwithall,extras,qcmd localhost,{KDBBASEPORT}+101,discovery,discovery1,${TORQAPPHOME}/appconfig/passwords/accesslist.txt,1,0,,,${KDBCODE}/processes/discovery.q,1,, localhost,{KDBBASEPORT}+100,segmentedtickerplant,stptestpartby,${TORQAPPHOME}/appconfig/passwords/accesslist.txt,1,0,,,${KDBCODE}/processes/segmentedtickerplant.q,1,-schemafile ${KDBTESTS}/merge/wdb//xdaily.q, localhost,{KDBBASEPORT}+103,hdb,hdb1,${TORQAPPHOME}/appconfig/passwords/accesslist.txt,1,1,60,4000,${KDBTESTS}/merge/wdb/testhdb,1,, -localhost,{KDBBASEPORT}+104,wdb,wdbcol,${TORQAPPHOME}/appconfig/passwords/accesslist.txt,1,1,,,${KDBCODE}/processes/wdb.q ${KDBTESTS}/merge/wdb/config/wdbsettings.q ${KDBTESTS}/merge/wdb/mockdata.q,1,, -localhost,{KDBBASEPORT}+105,wdb,wdbhybrid,${TORQAPPHOME}/appconfig/passwords/accesslist.txt,1,1,,,${KDBCODE}/processes/wdb.q ${KDBTESTS}/merge/wdb/config/wdbsettings.q ${KDBTESTS}/merge/wdb/mockdata.q,1,, -localhost,{KDBBASEPORT}+106,wdb,wdbpart,${TORQAPPHOME}/appconfig/passwords/accesslist.txt,1,1,,,${KDBCODE}/processes/wdb.q ${KDBTESTS}/merge/wdb/config/wdbsettings.q ${KDBTESTS}/merge/wdb/mockdata.q,1,, -localhost,{KDBBASEPORT}+109,sort,sort1,${TORQAPPHOME}/appconfig/passwords/accesslist.txt,1,1,,,${KDBCODE}/processes/wdb.q ${KDBTESTS}/merge/wdb/config/wdbsettings.q,1,-s -2, -localhost,{KDBBASEPORT}+110,sortworker,sortworker1,,1,1,,,${KDBCODE}/processes/wdb.q ${KDBTESTS}/merge/wdb/config/wdbsettings.q,1,, -localhost,{KDBBASEPORT}+111,sortworker,sortworker2,,1,1,,,${KDBCODE}/processes/wdb.q ${KDBTESTS}/merge/wdb/config/wdbsettings.q,1,, +localhost,{KDBBASEPORT}+104,wdb,wdbcol,${TORQAPPHOME}/appconfig/passwords/accesslist.txt,1,1,,,${KDBTESTS}/merge/wdb/config/wdbsettings.q ${KDBCODE}/processes/wdb.q ${KDBTESTS}/merge/wdb/mockdata.q,1,, +localhost,{KDBBASEPORT}+105,wdb,wdbhybrid,${TORQAPPHOME}/appconfig/passwords/accesslist.txt,1,1,,,${KDBTESTS}/merge/wdb/config/wdbsettings.q ${KDBCODE}/processes/wdb.q ${KDBTESTS}/merge/wdb/mockdata.q,1,, +localhost,{KDBBASEPORT}+106,wdb,wdbpart,${TORQAPPHOME}/appconfig/passwords/accesslist.txt,1,1,,,${KDBTESTS}/merge/wdb/config/wdbsettings.q ${KDBCODE}/processes/wdb.q ${KDBTESTS}/merge/wdb/mockdata.q,1,, +localhost,{KDBBASEPORT}+109,sort,sort1,${TORQAPPHOME}/appconfig/passwords/accesslist.txt,1,1,,,${KDBTESTS}/merge/wdb/config/wdbsettings.q ${KDBCODE}/processes/wdb.q,1,-s -2, +localhost,{KDBBASEPORT}+110,sortworker,sortworker1,,1,1,,,${KDBTESTS}/merge/wdb/config/wdbsettings.q ${KDBCODE}/processes/wdb.q,1,, +localhost,{KDBBASEPORT}+111,sortworker,sortworker2,,1,1,,,${KDBTESTS}/merge/wdb/config/wdbsettings.q ${KDBCODE}/processes/wdb.q,1,, diff --git a/tests/stp/wdb/partbyenum.csv b/tests/stp/wdb/partbyenum.csv index 2fae50992..c7278d2bc 100644 --- a/tests/stp/wdb/partbyenum.csv +++ b/tests/stp/wdb/partbyenum.csv @@ -26,6 +26,7 @@ run,0,0,q,wdbHandle(`.u.end;`.wdb.currentpartition),1,,"Trigger EOD on WDB" run,0,0,q,.proc.sys "sleep 3",1,,"Wait for merge to HDB to happen" true,0,0,q,(2*count[first testtrade])~hdbHandle "count select from trade",1,,"Check trade in hdb" true,0,0,q,(2*count[first testquote])~hdbHandle "count select from quote",1,,"Check quote in hdb" +true,0,0,q,(::)~wdbHandle(`.save.postreplay;`:/tmp;2026.01.01),1,,"Check the WDB's end-of-day hook .save.postreplay takes (dir;date)" after,0,0,q,kill9proc each ("stpnone";"wdbenum";"hdb1"),1,,"Stop all procs" after,0,0,q,.os.deldir logdir,1,,"Delete test segmented tickerplant logs" after,0,0,q,.os.deldir 1_string temphdbdir,1,,"Delete temp HDB" From d4c39f4ff0144f15790ffc9ef19a3a1a4cc06bc1 Mon Sep 17 00:00:00 2001 From: Marcos Jaen Date: Wed, 18 Nov 2026 10:28:37 -0500 Subject: [PATCH 3/5] Fix the tickerplant, WDB, IDB and HDB tests that could not pass, did not write results or depended on timing Tickerplant suites: - stp/pubsub: seven rows from #391 call rdbHandle, which the suite never defines. They now use the suite's own publisher, with one row that gives it trades to filter. - stp/eod and three chained suites still called .stplg.stpeod, which #523 folded into .stplg.endofday. - stp/eod, stp/periodend and stp/chainedperiodend sized the meta table by the publish list, which is one short since #638. - stp/tz upserted six values into the time zone table, which has had four columns since the tzinfo file was regenerated in #603. - stp/custommode expected quote_iex, trade_iex and heartbeat, which the Starter Pack schema no longer has, so the suite now has its own schema file. It also moved the logs with setenv on KDBTPLOG, which the tickerplant has read once at start-up since #638; it now sets .stplg.kdbtplog. Its bad update is now a one-item list, the shape every update has, and its file count is compared by value. - Seven run.sh passed -results where runtests.q reads -testresults, so those suites never wrote a results file; chainedeodlognone, chainedlogmodes and chainedrecovery also left $write out of their test command, so run.sh -w did not write theirs either. - tests/helperfunctions.q: gethandle opened a new handle on every call and never closed the old one. A process has a limit on open connections, and stp/wdb reopened handles often enough to reach it. - stp/batching: defbatch.csv resumed publication with .z.ts[] and checked the RDB's row count on the very next line, racing the asynchronous publish (it failed about one run in three). It now waits a second first, as membatch.csv does. - stp/periodend and stp/chainedperiodend measured the period that was open when the test started. The chained tickerplant's starts when the test switches its logging on with .stplg.init, part-way through a period, so its length could never match; the plain tickerplant's first period starts when the process starts, so the check failed whenever no roll had happened yet. Both tests now wait for a roll first, so they measure a whole period. The check's comment said 1 microsecond; 1e6 nanoseconds is 1 millisecond. WDB, IDB and HDB suites: - stp/idbdefault and stp/idbpartbyenum queried quote_iex, which the Starter Pack schema no longer has, so the gateway returned an error string; they now query packets, which the tests never publish to. They also started the gateway with the IDBs and then slept 3 seconds, so the gateway's one attempt to connect could find an IDB not listening yet, and on a busy machine a handle could still be missing when the suite opened it. They now start the WDB, the HDB and the IDBs, wait until each accepts a connection, then start the gateway and wait until it has connected to them (waitforhandle and waitforgateway in tests/helperfunctions.q, up to 30 seconds each). idbdefault looked for today's partition with .z.D, the local date, where the WDB partitions by the UTC date, so it failed every evening west of UTC; it now uses .z.d. Both trigger a WDB end of day, which needs the .save.postreplay fix above. - merge/tplogreplay loaded treplaysettings.q, but the file is tpreplaysettings.q, so its replays never ran partandmerge and the temp-directory checks failed. With the right file the checks still failed: they look at .replay.tempdir in the test process, which kept the default instead of the directory the replay uses. The test's settings now set it to that directory. - wdb/intpartbyenum looked for today's partition with .z.D, the local date, where the WDB partitions by the UTC date, so it failed every evening west of UTC; it now uses .z.d. - schemas checked quote_iex and trade_iex against the application's schema file, which no longer has them. Like stp/custommode, it now has its own schema file. It also wrote into and loaded the Starter Pack's sample HDB, whose 2015 partitions do not have the suite's newer tables, so the HDB could only start where reading those tables is left until a query asks for them. The suite now writes and loads its own HDB, which run.sh removes at the end. - stp/wdb: singlelog, tabperiod and tabular load the sym list the WDBs enumerated against before loading the saved partitions, and partbyenum reads the HDB folder with the query ".wdb.hdbsettings`hdbdir" instead of sending (`.wdb.hdbsettings;`hdbdir), which applies a dictionary as if it were a function. Timing: - stp/chainedlogmodes waits 11 seconds on a 10-second period and expects exactly one end of period. A wait that began in the last second of a period held two, and the suite failed rows 21 and 43 (about one run in ten). Each wait now begins straight after an end of period reaches the RDB, and the RDB's count is reset there, so the wait holds exactly one; row 43 checks the count since that reset. --- tests/helperfunctions.q | 14 ++++++++++- tests/merge/tplogreplay/settings.q | 4 +++- tests/schemas/database.q | 6 +++++ tests/schemas/process.csv | 6 ++--- tests/schemas/run.sh | 6 +++++ tests/stp/batching/defbatch.csv | 1 + tests/stp/chainedeod/eodroutine.csv | 2 +- tests/stp/chainedeod/run.sh | 4 ++-- tests/stp/chainedeodlognone/run.sh | 4 ++-- tests/stp/chainedeodlognone/sctplognone.csv | 2 +- tests/stp/chainedlogmodes/eodroutine.csv | 10 ++++---- tests/stp/chainedlogmodes/run.sh | 4 ++-- tests/stp/chainedlogmodes/settings.q | 7 ++++++ tests/stp/chainedperiodend/endp.csv | 13 ++++++----- tests/stp/chainedperiodend/run.sh | 4 ++-- tests/stp/chainedperiodend/settings.q | 6 ++++- tests/stp/chainedrecovery/run.sh | 4 ++-- tests/stp/chainedstp/run.sh | 2 +- tests/stp/custommode/database.q | 6 +++++ tests/stp/custommode/logs.csv | 10 ++++---- tests/stp/custommode/metaroll.csv | 4 ++-- tests/stp/custommode/process.csv | 2 +- tests/stp/eod/eodroutine.csv | 4 ++-- tests/stp/idbdefault/idbdefault.csv | 26 +++++++++++---------- tests/stp/idbpartbyenum/idbenum.csv | 17 ++++++++------ tests/stp/periodend/endp.csv | 11 +++++---- tests/stp/periodend/settings.q | 6 ++++- tests/stp/pubsub/pubsub.csv | 15 ++++++------ tests/stp/tz/settings.q | 3 ++- tests/stp/upds/run.sh | 2 +- tests/stp/wdb/partbyenum.csv | 2 +- tests/stp/wdb/singlelog.csv | 1 + tests/stp/wdb/tabperiod.csv | 1 + tests/stp/wdb/tabular.csv | 1 + tests/wdb/intpartbyenum/intpartbyenum.csv | 2 +- 35 files changed, 136 insertions(+), 76 deletions(-) create mode 100644 tests/schemas/database.q create mode 100644 tests/stp/custommode/database.q diff --git a/tests/helperfunctions.q b/tests/helperfunctions.q index b8ad95f21..84f66d970 100644 --- a/tests/helperfunctions.q +++ b/tests/helperfunctions.q @@ -16,6 +16,18 @@ isalive:{[proc] any "q" in' @[system;"pgrep -lf ",proc," -u $USER";" "]}; // Have slightly more fluid handle opening mechanic - update: force it to open a new handle each time gethandle:{[name] - .z.pc exec first w from .servers.SERVERS where procname=name; + .z.pc h:exec first w from .servers.SERVERS where procname=name; + // close the old handle as well: .z.pc only marks it closed, and a process can run out of connections + if[not null h;@[hclose;h;()]]; exec first w from .servers.getservers[`procname;name;()!();1b;1b] }; + +// Wait up to 30 seconds for a process to accept a connection, and return its handle (null if it never did): a fixed +// sleep after starting several processes at once is not always long enough +waitforhandle:{[name] t:.z.p+0D00:00:30; while[(null h:gethandle name) and .z.pabs "i"$logperiod-mends-mstarts,1,,"Check that the new metatable periods are within 1 microsec of the stated period" +true,0,0,q,all 1e6>abs "i"$logperiod-mends-mstarts,1,,"Check that the new metatable periods are within 1 millisecond of the stated period" true,0,0,q,(mseq+1h)~sctpHandle"exec last seq from .stpm.metatable",1,,"Check that the sequence number has incremented by 1" -true,0,0,q,tabs~raze sctpHandle"exec neg[count .stpps.t]#tbls from .stpm.metatable",1,,"Check that the correct tables are incremented" +true,0,0,q,tabs~raze sctpHandle"exec neg[count .stplg.logtabs]#tbls from .stpm.metatable",1,,"Check that the correct tables are incremented" true,0,0,q,("T"$-6#string currlog[`trade;`logname])~"t"$period`next,1,,"Check trade log name rolled" after,0,0,q,"system ""rm -rf "",1_string sctpHandle(`.stplg.dldir)",1,,"Delete logs folder" \ No newline at end of file diff --git a/tests/stp/chainedperiodend/run.sh b/tests/stp/chainedperiodend/run.sh index 0a2c08825..0d553355f 100755 --- a/tests/stp/chainedperiodend/run.sh +++ b/tests/stp/chainedperiodend/run.sh @@ -14,10 +14,10 @@ ${TORQHOME}/torq.sh start discovery1 stp1 sctp1 rdball rdbsymfilt rdbonetab -cs -proctype test -procname test1 \ -test ${testpath} \ -load ${KDBTESTS}/helperfunctions.q ${testpath}/settings.q \ - -results ${KDBTESTS}/stp/results/ \ + -testresults ${KDBTESTS}/stp/results/ \ -procfile ${testpath}/process.csv \ -runtime $run \ - $debug $stop $quiet + $debug $stop $write $quiet # Shut down procs ${TORQHOME}/torq.sh stop discovery1 stp1 sctp1 rdball rdbsymfilt rdbonetab -csv ${testpath}/process.csv diff --git a/tests/stp/chainedperiodend/settings.q b/tests/stp/chainedperiodend/settings.q index 8616e5db0..6b6883874 100644 --- a/tests/stp/chainedperiodend/settings.q +++ b/tests/stp/chainedperiodend/settings.q @@ -14,4 +14,8 @@ testquote:(10?`4;(5?50.0),50+5?50.0;10?100.0;10?100i;10?100i;10?.Q.A;10?.Q.A;10# endp:{[x;y;z] .tst.endp:@[{1+value x};`.tst.endp;0]}; // Flag to save tests to disk -.k4.savetodisk:1b; \ No newline at end of file +.k4.savetodisk:1b; + +// Wait up to 15 s for the tickerplant on handle h to roll its logs, so that the period the test measures is a whole +// one: the log opened at start-up (or by .stplg.init) starts part-way through a period +waitroll:{[h] i:h".stplg.i"; do[150; if[i.z.p+.eodtime.dailyadj",1,,"Check logging period times" true,0,0,q,stpHandle".stplg.nextperiod~.stplg.currperiod+.stplg.multilogperiod",1,,"Check logging period times" -run,0,0,q,"stpHandle @/: `.u.upd ,/: ((`trade;testtrade);(`quote;testquote);(`heartbeat;`error))",1,,"Send trade,quote and bad updates to STP" +run,0,0,q,"stpHandle @/: `.u.upd ,/: ((`trade;testtrade);(`quote;testquote);(`heartbeat;enlist`error))",1,,"Send trade,quote and bad updates to STP" run,0,0,q,system "sleep 1",1,,"Wait for updates to publish" run,0,0,q,![-11;] each stpHandle"exec logname from currlog where tbl in `trade`quote`segmentederrorlogfile",1,,"Get log contents" true,0,0,q,(c1+10)~rdbHandle @/: ("count trade";"count quote"),1,,"Check tables updated in the RDB" true,0,0,q,(l1+10)~count each (trade;quote),1,,"Check tables updated correctly in logs" -true,0,0,q,`error~.tst.err,1,,"Check error logs updated" -after,0,0,q,stpHandle(setenv;`KDBTPLOG;deflogs),1,,"Change STP logging directory to default" +true,0,0,q,`error~first .tst.err,1,,"Check error logs updated" +after,0,0,q,stpHandle({.stplg.kdbtplog:`$x};deflogs),1,,"Change STP logging directory to default" after,0,0,q,stpHandle(system;"t 1000"),1,,"Turn on timer" after,0,0,q,"system""rm -r "",tstlogs",1,,"Clear log directory" \ No newline at end of file diff --git a/tests/stp/custommode/metaroll.csv b/tests/stp/custommode/metaroll.csv index 9712d9ad9..0471b7e75 100644 --- a/tests/stp/custommode/metaroll.csv +++ b/tests/stp/custommode/metaroll.csv @@ -1,6 +1,6 @@ action,ms,bytes,lang,code,repeat,minver,comment before,0,0,q,.servers.startup[],1,,"Set up connection management" -before,0,0,q,stpHandle(setenv;`KDBTPLOG;tstlogs),1,,"Change STP logging directory" +before,0,0,q,stpHandle({.stplg.kdbtplog:`$x};tstlogs),1,,"Change STP logging directory" before,0,0,q,stpHandle"delete from `.stpm.metatable",1,,"Delete meta table" before,0,0,q,stpHandle"setup[`defaultbatch]",1,,"Re-init STP" before,0,0,q,stpHandle".stplg.init[string .proc.procname]",1,,"Re-init STP" @@ -37,5 +37,5 @@ true,0,0,q,period[`next]~stpHandle".stplg.currperiod",1,,"Check period rolled co true,0,0,q,all ("T"$-6#'string exec logname from clog where tbl in `trade`heartbeat)="t"$period[`next],1,,"Check trade/heartbeat log names rolled" true,0,0,q,qlog~clog[`quote;`logname],1,,"Check quote log not rolled" true,0,0,q,not (~/) exec logname from clog where tbl in `trade`quote,1,,"Check trade and quote writing to different logs" -after,0,0,q,stpHandle(setenv;`KDBTPLOG;deflogs),1,,"Change STP logging directory to default" +after,0,0,q,stpHandle({.stplg.kdbtplog:`$x};deflogs),1,,"Change STP logging directory to default" after,0,0,q,"system""rm -r "",tstlogs",1,,"Clear log directory" \ No newline at end of file diff --git a/tests/stp/custommode/process.csv b/tests/stp/custommode/process.csv index f7d8ec663..0c5383285 100644 --- a/tests/stp/custommode/process.csv +++ b/tests/stp/custommode/process.csv @@ -1,4 +1,4 @@ host,port,proctype,procname,U,localtime,g,T,w,load,startwithall,extras,qcmd localhost,{KDBBASEPORT}+100,discovery,discovery1,${TORQHOME}/appconfig/passwords/accesslist.txt,1,0,,,${KDBCODE}/processes/discovery.q,1,,q -localhost,{KDBBASEPORT}+101,segmentedtickerplant,stp1,${TORQHOME}/appconfig/passwords/accesslist.txt,1,0,,,${KDBCODE}/processes/segmentedtickerplant.q,1,-schemafile ${TORQHOME}/database.q -.stplg.multilog custom -.stplg.customcsv ${KDBTESTS}/stpcustom.csv,q +localhost,{KDBBASEPORT}+101,segmentedtickerplant,stp1,${TORQHOME}/appconfig/passwords/accesslist.txt,1,0,,,${KDBCODE}/processes/segmentedtickerplant.q,1,-schemafile ${KDBTESTS}/stp/custommode/database.q -.stplg.multilog custom -.stplg.customcsv ${KDBTESTS}/stpcustom.csv,q localhost,{KDBBASEPORT}+102,rdb,rdb1,${TORQHOME}/appconfig/passwords/accesslist.txt,1,1,180,,${KDBCODE}/processes/rdb.q,1,-.rdb.replaylog 0b,q diff --git a/tests/stp/eod/eodroutine.csv b/tests/stp/eod/eodroutine.csv index fc2708984..4cc7c2616 100644 --- a/tests/stp/eod/eodroutine.csv +++ b/tests/stp/eod/eodroutine.csv @@ -6,14 +6,14 @@ before,0,0,q,stpHandle:gethandle[`stp1],1,,"Get STP handle" before,0,0,q,rdbHandle:gethandle[`rdb1],1,,"Get RDB handle" before,0,0,q,rdbHandle"endofday:{[x;y] .tst.eod:1b}",1,,"Overwrite RDB endofday function" before,0,0,q,meta1:stpHandle".stpm.metatable",1,,"Get initial meta table" -before,0,0,q,tcount:count stpHandle".stpps.t",1,,"Get table count" +before,0,0,q,tcount:count stpHandle".stplg.logtabs",1,,"Get table count" before,0,0,q,adj:stpHandle".eodtime.dailyadj",1,,"Get time adjustment" before,0,0,q,eod1:stpHandle".eodtime.d",1,,"Get initial date" before,0,0,q,dir1:stpHandle".stplg.dldir",1,,"Get initial log directory" before,0,0,q,db:stpHandle"string .proc.procname",1,,"Get dbname" run,0,0,q,now:.z.p,1,,"Get current time" run,0,0,q,eoddata: stpHandle".stplg.endofdaydata[]",1,,"Get eod data to send" -run,0,0,q,"stpHandle(`.stplg.stpeod;.eodtime.d;eoddata,(enlist `p)!enlist now)",1,,"Run EoD function on STP" +run,0,0,q,"stpHandle(`.stplg.endofday;.eodtime.d;eoddata,(enlist `p)!enlist now)",1,,"Run EoD function on STP" run,0,0,q,meta2:get .Q.dd[dir1;`stpmeta],1,,"Get meta table from disk" run,0,0,q,eod2:stpHandle".eodtime.d",1,,"Get new date" run,0,0,q,dir2:stpHandle".stplg.dldir",1,,"Get new log directory" diff --git a/tests/stp/idbdefault/idbdefault.csv b/tests/stp/idbdefault/idbdefault.csv index 6c32642be..894c99234 100644 --- a/tests/stp/idbdefault/idbdefault.csv +++ b/tests/stp/idbdefault/idbdefault.csv @@ -2,32 +2,34 @@ action,ms,bytes,lang,code,repeat,minver,comment before,0,0,q,.servers.startup[],1,,"Start TorQ connection management" before,0,0,q,startproc["stp1"],1,,"Start STP" before,0,0,q,.proc.sys "sleep 3",1,,"Wait for proc to start" -before,0,0,q,stpHandle:gethandle[`stp1],1,,"Open STP handle" +before,0,0,q,stpHandle:waitforhandle[`stp1],1,,"Open STP handle, once the STP has started" before,0,0,q,logdir:1_string stpHandle(`.stplg.dldir),1,,"Get location of log directory" before,0,0,q,.proc.sys "sleep 3",1,,"Wait for connections to get set up" before,0,0,q,.os.md hdbdir,1,,"Creating HDB directory" -before,0,0,q,startproc each ("wdbdefault";"hdb1";"gateway1";"idbdefault"),1,,"Start WDB, HDB, GW and IDB" -before,0,0,q,.proc.sys "sleep 3",1,,"Wait for procs to start" -before,0,0,q,wdbHandle:gethandle[`wdbdefault],1,,"Open WDB handle" -before,0,0,q,idbHandle:gethandle[`idbdefault],1,,"Open IDB handle" -before,0,0,q,gwHandle:gethandle[`gateway1],1,,"Open GW handle" +before,0,0,q,startproc each ("wdbdefault";"hdb1";"idbdefault"),1,,"Start WDB, HDB and IDB" +before,0,0,q,wdbHandle:waitforhandle[`wdbdefault],1,,"Open WDB handle, once the WDB has started" +before,0,0,q,idbHandle:waitforhandle[`idbdefault],1,,"Open IDB handle, once the IDB has started" +before,0,0,q,waitforhandle[`hdb1],1,,"Wait for hdb1 to start" +before,0,0,q,startproc "gateway1",1,,"Start GW once the processes it connects to are up, so it finds them" +before,0,0,q,gwHandle:waitforhandle[`gateway1],1,,"Open GW handle, once the gateway has started" +before,0,0,q,waitforgateway[gwHandle;`idb`hdb!1 1],1,,"Wait for the gateway to connect to the IDB and the HDB" before,0,0,q,wdbHandle(set;`.wdb.numtab;`quote`trade!7 8),1,,"Set low treshold numbers for merging" -true,0,0,q,neg[gwHandle](`.gw.asyncexec;"select from trade where date=.z.D";`idb);0~count gwHandle[],1,,"Check if trade table initialised correctly with 0 rows" +true,0,0,q,neg[gwHandle](`.gw.asyncexec;"select from trade where date=.z.d";`idb);0~count gwHandle[],1,,"Check if trade table initialised correctly with 0 rows" run,0,0,q,"stpHandle @/: `.u.upd ,/: ((`trade;testtrade);(`quote;testquote))",1,,"Send trade and quote updates to STP" run,0,0,q,.proc.sys "sleep 3",1,,"Wait for updates to get published" -true,0,0,q,"neg[gwHandle](`.gw.asyncexec;""select from trade where date=.z.D, sym=`GOOG"";`idb);5~count gwHandle[]",1,,"Check trade update was correctly published" -true,0,0,q,"neg[gwHandle](`.gw.asyncexec;""select from quote_iex where date=.z.D"";`idb);0~count gwHandle[]",1,,"Check if table that not have been published has 0 rows" +true,0,0,q,"neg[gwHandle](`.gw.asyncexec;""select from trade where date=.z.d, sym=`GOOG"";`idb);5~count gwHandle[]",1,,"Check trade update was correctly published" +true,0,0,q,"neg[gwHandle](`.gw.asyncexec;""select from packets where date=.z.d"";`idb);0~count gwHandle[]",1,,"Check if table that not have been published has 0 rows" run,0,0,q,wdbHandle(`.u.end;`.wdb.currentpartition),1,,"Trigger EOD on WDB" run,0,0,q,.proc.sys "sleep 3",1,,"Wait for merge to HDB to happen" true,0,0,q,neg[gwHandle](`.gw.asyncexec;"select from trade where sym in `GOOG";`hdb);5~count gwHandle[],1,,"Check if HDB has the merged data" true,0,0,q,0=sum idbHandle@/: {raze ("count select from ";x)} each string wdbHandle(`.wdb.tablelist;()),1,,"Check if all tables have been correctly initilised with 0 rows after eod trigger" -true,0,0,q,neg[gwHandle](`.gw.asyncexec;"select from trade where date=.z.D+1";`idb);0~count gwHandle[],1,,"Check if IDB has been emptied." +true,0,0,q,neg[gwHandle](`.gw.asyncexec;"select from trade where date=.z.d+1";`idb);0~count gwHandle[],1,,"Check if IDB has been emptied." run,0,0,q,"stpHandle @/: `.u.upd ,/: ((`trade;testtrade);(`quote;testquote))",1,,"Send trade and quote updates to STP" run,0,0,q,.proc.sys "sleep 3",1,,"Wait for updates to get published" -true,0,0,q,"neg[gwHandle](`.gw.asyncexec;""select from trade where date=.z.D+1, sym=`GOOG"";`idb);5~count gwHandle[]",1,,"Check trade update was correctly published" +true,0,0,q,"neg[gwHandle](`.gw.asyncexec;""select from trade where date=.z.d+1, sym=`GOOG"";`idb);5~count gwHandle[]",1,,"Check trade update was correctly published" run,0,0,q,"stpHandle @/: `.u.upd ,/: ((`trade;enlist[(count[testtrade[0]]#`round2)],1_testtrade);(`quote;testquote))",1,,"Publish some new data to the tickplant with new symbol" run,0,0,q,.proc.sys "sleep 3",1,,"Wait for updates to get published" -true,0,0,q,"neg[gwHandle](`.gw.asyncexec;""select from trade where date=.z.D+1, sym=`round2"";`idb);10~count gwHandle[]",1,,"Check if IDB was reloaded and is aware if the new symbol" +true,0,0,q,"neg[gwHandle](`.gw.asyncexec;""select from trade where date=.z.d+1, sym=`round2"";`idb);10~count gwHandle[]",1,,"Check if IDB was reloaded and is aware if the new symbol" true,0,0,q,20~idbHandle"count trade",1,,"Check if row counts in IDB was reloaded correctly" after,0,0,q,hclose each (wdbHandle;gwHandle;idbHandle);,1,,"Close handles" after,0,0,q,stopproc each ("idbdefault";"wdbdefault";"hdb1";"gateway1";"stp1"),1,,"Stop all procs" diff --git a/tests/stp/idbpartbyenum/idbenum.csv b/tests/stp/idbpartbyenum/idbenum.csv index 41e563725..023ac338c 100644 --- a/tests/stp/idbpartbyenum/idbenum.csv +++ b/tests/stp/idbpartbyenum/idbenum.csv @@ -2,21 +2,24 @@ action,ms,bytes,lang,code,repeat,minver,comment before,0,0,q,.servers.startup[],1,,"Start TorQ connection management" before,0,0,q,startproc["stp1"],1,,"Start STP" before,0,0,q,.proc.sys "sleep 3",1,,"Wait for proc to start" -before,0,0,q,stpHandle:gethandle[`stp1],1,,"Open STP handle" +before,0,0,q,stpHandle:waitforhandle[`stp1],1,,"Open STP handle, once the STP has started" before,0,0,q,logdir:1_string stpHandle(`.stplg.dldir),1,,"Get location of log directory" before,0,0,q,.proc.sys "sleep 3",1,,"Wait for connections to get set up" before,0,0,q,.os.md hdbdir,1,,"Creating HDB directory" -before,0,0,q,startproc each ("wdbenum";"hdb1";"gateway1";"idbenum";"idbenum2"),1,,"Start WDB, HDB, GW, IDB and IDB2" -before,0,0,q,.proc.sys "sleep 3",1,,"Wait for procs to start" -before,0,0,q,wdbHandle:gethandle[`wdbenum],1,,"Open WDB handle" -before,0,0,q,idbHandle:gethandle[`idbenum],1,,"Open IDB handle" -before,0,0,q,gwHandle:gethandle[`gateway1],1,,"Open GW handle" +before,0,0,q,startproc each ("wdbenum";"hdb1";"idbenum";"idbenum2"),1,,"Start WDB, HDB and IDBs" +before,0,0,q,wdbHandle:waitforhandle[`wdbenum],1,,"Open WDB handle, once the WDB has started" +before,0,0,q,idbHandle:waitforhandle[`idbenum],1,,"Open IDB handle, once the IDB has started" +before,0,0,q,waitforhandle[`idbenum2],1,,"Wait for idbenum2 to start" +before,0,0,q,waitforhandle[`hdb1],1,,"Wait for hdb1 to start" +before,0,0,q,startproc "gateway1",1,,"Start GW once the processes it connects to are up, so it finds them" +before,0,0,q,gwHandle:waitforhandle[`gateway1],1,,"Open GW handle, once the gateway has started" +before,0,0,q,waitforgateway[gwHandle;`idb`hdb!2 1],1,,"Wait for the gateway to connect to the IDBs and the HDB" before,0,0,q,wdbHandle(set;`.wdb.numtab;`quote`trade!7 8),1,,"Set low treshold numbers for merging" true,0,0,q,neg[gwHandle](`.gw.asyncexec;"select from trade";`idb);0~count gwHandle[],1,,"Check if trade table initialised correctly with 0 rows" run,0,0,q,"stpHandle @/: `.u.upd ,/: ((`trade;testtrade);(`quote;testquote))",1,,"Send trade and quote updates to STP" run,0,0,q,.proc.sys "sleep 3",1,,"Wait for updates to get published" true,0,0,q,neg[gwHandle](`.gw.asyncexec;"select from trade where int=maptoint[`GOOG]";`idb);5~count gwHandle[],1,,"Check trade update was correctly published and maptoint works" -true,0,0,q,neg[gwHandle](`.gw.asyncexec;"select from quote_iex";`idb);0~count gwHandle[],1,,"Check if table that not have been published has 0 rows" +true,0,0,q,neg[gwHandle](`.gw.asyncexec;"select from packets";`idb);0~count gwHandle[],1,,"Check if table that not have been published has 0 rows" run,0,0,q,wdbHandle(`.u.end;`.wdb.currentpartition),1,,"Trigger EOD on WDB" run,0,0,q,.proc.sys "sleep 3",1,,"Wait for merge to HDB to happen" true,0,0,q,neg[gwHandle](`.gw.asyncexec;"select from trade where sym=`GOOG";`hdb);5~count gwHandle[],1,,"Check if HDB has the merged data" diff --git a/tests/stp/periodend/endp.csv b/tests/stp/periodend/endp.csv index 03cbdc72c..ed771592d 100644 --- a/tests/stp/periodend/endp.csv +++ b/tests/stp/periodend/endp.csv @@ -2,20 +2,21 @@ action,ms,bytes,lang,code,repeat,minver,comment beforeany,0,0,q,system "sleep 5",1,,"Wait for all procs to go up" before,0,0,q,.servers.startup[],1,,"Get connection management set up" before,0,0,q,stpHandle:gethandle[`stp1],1,,"Get STP handle" +before,0,0,q,waitroll stpHandle,1,,"Wait for a log roll, so that the period measured below is a whole one" before,0,0,q,rdbHandles:`all`sym`tab!gethandle each `rdball`rdbsymfilt`rdbonetab,1,,"Get RDB handles" before,0,0,q,(value rdbHandles) @\: (set;`endofperiod;endp),1,,"Set dummy endofperiod function on each sub" -before,0,0,q,tcount:count tabs:stpHandle".stpps.t",1,,"Get number of tables" +before,0,0,q,tcount:count tabs:stpHandle".stplg.logtabs",1,,"Get number of tables" before,0,0,q,logperiod:stpHandle".stplg.multilogperiod",1,,"Get logging period" before,0,0,q,metacount:stpHandle"count .stpm.metatable",1,,"Get initial table count" -before,0,0,q,mstarts:stpHandle"neg[count .stpps.t]#exec start from .stpm.metatable",1,,"Get most recent start times" +before,0,0,q,mstarts:stpHandle"neg[count .stplg.logtabs]#exec start from .stpm.metatable",1,,"Get most recent start times" before,0,0,q,mseq:stpHandle"exec last seq from .stpm.metatable",1,,"Get most recent sequence number" before,0,0,q,period:`curr`next!stpHandle".stplg[`currperiod`nextperiod]",1,,"Get current and next roll periods" before,0,0,q,system "sleep 11",1,,"Wait for a full period" -run,0,0,q,mends:(stpHandle"neg[2*count .stpps.t]#exec end from .stpm.metatable") except 0Np,1,,"Get previous period end times" +run,0,0,q,mends:(stpHandle"neg[2*count .stplg.logtabs]#exec end from .stpm.metatable") except 0Np,1,,"Get previous period end times" run,0,0,q,currlog:stpHandle"currlog",1,,"Get currlog table" true,0,0,q,all 0=(value rdbHandles) @\: (`.tst.endp),1,,"Check the endofperiod function has been triggered once on all subs" true,0,0,q,(metacount+tcount)~stpHandle"count .stpm.metatable",1,,"Check that the STP metatable count has increased correctly" -true,0,0,q,all 1e6>abs "i"$logperiod-mends-mstarts,1,,"Check that the new metatable periods are within 1 microsec of the stated period" +true,0,0,q,all 1e6>abs "i"$logperiod-mends-mstarts,1,,"Check that the new metatable periods are within 1 millisecond of the stated period" true,0,0,q,(mseq+1h)~stpHandle"exec last seq from .stpm.metatable",1,,"Check that the sequence number has incremented by 1" -true,0,0,q,tabs~raze stpHandle"exec neg[count .stpps.t]#tbls from .stpm.metatable",1,,"Check that the correct tables are incremented" +true,0,0,q,tabs~raze stpHandle"exec neg[count .stplg.logtabs]#tbls from .stpm.metatable",1,,"Check that the correct tables are incremented" true,0,0,q,("T"$-6#string currlog[`trade;`logname])~"t"$period`next,1,,"Check trade log name rolled" \ No newline at end of file diff --git a/tests/stp/periodend/settings.q b/tests/stp/periodend/settings.q index 34eb51309..dde680ee1 100644 --- a/tests/stp/periodend/settings.q +++ b/tests/stp/periodend/settings.q @@ -10,4 +10,8 @@ testtrade:((5#`GOOG),5?`4;10?100.0;10?100i;10#0b;10?.Q.A;10?.Q.A;10#`buy); testquote:(10?`4;(5?50.0),50+5?50.0;10?100.0;10?100i;10?100i;10?.Q.A;10?.Q.A;10#`3); // End period function to send to subs -endp:{[x;y;z] .tst.endp:@[{1+value x};`.tst.endp;0]}; \ No newline at end of file +endp:{[x;y;z] .tst.endp:@[{1+value x};`.tst.endp;0]}; + +// Wait up to 15 s for the tickerplant on handle h to roll its logs, so that the period the test measures is a whole +// one: the log opened at start-up (or by .stplg.init) starts part-way through a period +waitroll:{[h] i:h".stplg.i"; do[150; if[i Date: Wed, 18 Nov 2026 15:14:13 -0500 Subject: [PATCH 4/5] End a chained tickerplant's day when it writes no logs A chained tickerplant in loggingmode none or parent (the Starter Pack's sctp1) opens no logs, so it never sets .stplg.dldir. At end of day .stplg.dayrollover still closed its logs: the meta update failed with '.stplg.dldir, and the rest of the rollover did not run. The process logged the error at every end of day, and was not reinitialised, so its message and row counts (.stplg.msgcount, and .stplg.rowcount, which subdetails gives subscribers as rowcounts) and .stplg.seqnum carried on from the day before. Its date had already moved on, and its subscribers had the end of day. .stplg.haslogs is the condition init opens logs on: createlogs, or loggingmode create. dayrollover closes the day's logs only where it holds, and so does .z.exit, which skipped only a chained tickerplant not in create mode: a tickerplant with createlogs off failed the same way, at end of day and on exit. tests/stp/chainedeodlognone checks that the chained tickerplant counted the first updates, and that its counts start again from 0 after the end of day. --- code/segmentedtickerplant/stplog.q | 19 +++++++++++++------ tests/stp/chainedeodlognone/sctplognone.csv | 2 ++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/code/segmentedtickerplant/stplog.q b/code/segmentedtickerplant/stplog.q index 95c284601..7ad4feaf4 100644 --- a/code/segmentedtickerplant/stplog.q +++ b/code/segmentedtickerplant/stplog.q @@ -14,6 +14,10 @@ restoreloghandles:{value "loghandles::exec tbl!handle from currlog"}; // Name of error log file errorlogname:@[value;`.stplg.errorlogname;`segmentederrorlogfile] +// Whether this process writes logs of its own: a tickerplant with createlogs on, or a chained tickerplant creating its +// own (loggingmode create). init opens them; dayrollover and .z.exit close them only where init opened them +haslogs:{(value `..createlogs) or .sctp.loggingmode=`create}; + // Create stp log directory // Log structure `:stplogs/date/tabname_time createdld:{[name;date] @@ -232,9 +236,12 @@ dayrollover:{[data] system"t 0";'"next roll is in the past"]; // timer off getnextendUTC[]; // grabs next end time .eodtime.d+:1; // increment current day - .stpm.updmeta[multilog][`close;logtabs;(data`p)+.eodtime.dailyadj]; // update meta tables - .stpm.metatable:0#.stpm.metatable; - closelog each logtabs; // close current day logs + // only a process with logs of its own has logs to close: a chained tickerplant in loggingmode none or parent has no + // log directory (.stplg.dldir), and closing failed there before the process was reinitialised + if[haslogs[]; + .stpm.updmeta[multilog][`close;logtabs;(data`p)+.eodtime.dailyadj]; // update meta tables + .stpm.metatable:0#.stpm.metatable; + closelog each logtabs]; // close current day logs init[string .proc.procname]; // reinitialise process .lg.o[`dayrollover;"end of day complete, new value for date is ",.Q.s1 .eodtime.d]; } @@ -263,7 +270,7 @@ init:{[dbname] i::1; seqnum::0; - if[(value `..createlogs) or .sctp.loggingmode=`create; + if[haslogs[]; if[.sctp.chainedtp;`.[`restoreloghandles][]]; createdld[dbname;.eodtime.d]; openlog[multilog;dldir;;.z.p+.eodtime.dailyadj]each logtabs; @@ -297,8 +304,8 @@ init:{[dbname] .lg.o[`stpexit; "Complete!"] ]; - // exit before logs are touched if process is an sctp NOT in create mode - if[.sctp.chainedtp and not .sctp.loggingmode=`create; :()]; + // exit before logs are touched if the process has none (an sctp NOT in create mode, or an stp with createlogs off) + if[not .stplg.haslogs[]; :()]; .lg.o[`stpexit;"Closing off log files"]; .stpm.updmeta[.stplg.multilog][`close;.stplg.logtabs;.z.p]; .stplg.closelog each .stplg.logtabs; diff --git a/tests/stp/chainedeodlognone/sctplognone.csv b/tests/stp/chainedeodlognone/sctplognone.csv index 981f8e5b8..b9bd203ad 100644 --- a/tests/stp/chainedeodlognone/sctplognone.csv +++ b/tests/stp/chainedeodlognone/sctplognone.csv @@ -13,6 +13,7 @@ before,0,0,q,sctpEod1:sctpHandle".eodtime.d",1,,"Get initial date on SCTP" before,0,0,q,stpDir1:stpHandle".stplg.dldir",1,,"Get initial log directory for STP" true,0,0,q,@[{x".stplg.dldir";0b};sctpHandle;{1b}],1,,"Make sure log directory for SCTP not defined" true,0,0,q,all rdbHandle"{count value x} each `trade`quote",1,,"Both trade & quote got records from SCTP" +true,0,0,q,0 Date: Tue, 1 Dec 2026 09:45:01 -0500 Subject: [PATCH 5/5] Take master's postreplay default and fix the RDB's forced end of day dbwriteutils.q: .save.postreplay's default is master's line again. #786 fixed the same default on master with {{[d;p] }}; this branch had {[e] {[d;p] }}, which does the same. Using master's line leaves dbwriteutils.q unchanged by this branch. rdb.q: restoretimeout restores the timeout only where timeoutreset has saved one. timeoutreset runs from a timer one minute before the scheduled roll, so an end of day which that timer did not prepare (one forced on the tickerplant) stopped the RDB's reload on an undefined .rdb.timeout, and the RDB kept the day's rows. tests/schemas/run.sh: the suite stops its processes and starts them again straight away, and torq.sh start skips a process that is still running. A tickerplant that took a moment to exit was therefore missing for the second half of the suite, and its five tickerplant checks failed. run.sh now waits, ten seconds at most, until the processes have stopped. --- code/common/dbwriteutils.q | 2 +- code/processes/rdb.q | 4 +++- tests/schemas/run.sh | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/code/common/dbwriteutils.q b/code/common/dbwriteutils.q index f3bdc6a72..5366696df 100644 --- a/code/common/dbwriteutils.q +++ b/code/common/dbwriteutils.q @@ -79,7 +79,7 @@ manipulate:{[t;x] /- post eod/replay, this is called after the date has been persisted to disk and sorted and /- takes a directory (typically hdb directory) and partition value as parameters -postreplay:@[value;`postreplay;{[e] {[d;p] }}]; +postreplay:@[value;`postreplay;{{[d;p] }}]; / - functions for running and descriptively logging garbage collection \d .gc diff --git a/code/processes/rdb.q b/code/processes/rdb.q index d9e36dd1a..0a22f98aa 100644 --- a/code/processes/rdb.q +++ b/code/processes/rdb.q @@ -204,7 +204,9 @@ notpconnected:{[] /-resets timeout to 0 before EOD writedown timeoutreset:{.rdb.timeout:system"T";system"T 0"}; -restoretimeout:{system["T ", string .rdb.timeout]}; +/-(only where timeoutreset has run: an end of day which the timer above did not prepare, such as one forced on the +/-tickerplant, leaves the timeout as it is, and without the check the end of day stopped here on an undefined variable) +restoretimeout:{if[`timeout in key `.rdb;system["T ", string .rdb.timeout]]}; \d . /- make sure that the process will make a connection to each of the gateways and hdb types diff --git a/tests/schemas/run.sh b/tests/schemas/run.sh index 12ccf5409..7b8fbba9c 100755 --- a/tests/schemas/run.sh +++ b/tests/schemas/run.sh @@ -21,6 +21,8 @@ ${TORQHOME}/torq.sh summary -csv ${testpath}/process.csv -procfile ${testpath}/process.csv -quiet ${TORQHOME}/torq.sh stop all -csv ${testpath}/process.csv +#wait until they have stopped (10 seconds at most): torq.sh start skips a process that is still running +for i in $(seq 50); do ${TORQHOME}/torq.sh summary -csv ${testpath}/process.csv | grep -q " up " || break; sleep 0.2; done # Do the tests #start procs