Skip to content

Run TorQ on L, korze and PeachQ - #769

Closed
jaen15marcos wants to merge 8 commits into
DataIntellectTech:masterfrom
jaen15marcos:engine-compat
Closed

jaen15marcos wants to merge 8 commits into
DataIntellectTech:masterfrom
jaen15marcos:engine-compat

Conversation

@jaen15marcos

@jaen15marcos jaen15marcos commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor
  • code/common/engine.q (new): which engine TorQ runs on and what it can do .proc.engine: -engine on the command line, else KDBENGINE, else detected (.pq.version -> PeachQ; started as l or .pq namespace -> L; otherwise kdb+/KDB-X, including the free 32-bit editions and older kdb+ without .z.l) .proc.capabilities: one table of features (kdb+ release + how to check it). kdb+/KDB-X: by version, exactly the .z.K tests TorQ already had - never probed. Other engines: each feature is tried in a trap, in process, writing no files and running no shell commands. .proc.supports`pipereplay checks the named-pipe replay (mkfifo, Linux only) the first time it is asked for
  • torq.q: loads engine.q first; engine name and version in the banner; the engine and capabilities are logged for every process (.proc.logengine); checkdependency makes sure .proc.a exists before appending (L rejects x,: on an undefined global)
    every former .z.K check reads .proc.capabilities (u.q, gateway.q, writeaccess.q, permissions.q, trackservers.q); tickerlogreplay.q asks .proc.supports`pipereplay
  • pubsub.q: the publish function is chosen once, at load, from .proc.capabilities`broadcast: master’s pub (-25!), unchanged, where -25! is available, else the new pubeach (one send per subscriber) - so no publish pays for the check. The choice is made before .u.pub and .ps.publish copy .stpps.pub, so both follow it. Against checking on every publish, one-row publishes are faster on every engine
  • grafana.q: .Q.t type map sized to the engine’s .Q.t
  • setenv.sh: QCMD taken from the environment when set
  • tests/engine: 54 tests for all of the above; tests/stp/pubsub: two checks against a real subscriber - .stpps.pub is pubeach exactly where -25! is missing (and the copies follow it), and pubeach delivers on every engine

@jaen15marcos
jaen15marcos force-pushed the engine-compat branch 2 times, most recently from 4cac2d4 to 5465541 Compare November 10, 2026 20:50
@jaen15marcos jaen15marcos changed the title Run TorQ on kdb+, L and PeachQ Run TorQ on L, korze and PeachQ Nov 11, 2026
jaen15marcos added a commit to jaen15marcos/TorQ that referenced this pull request Nov 11, 2026
A new suite which starts a monitor and calls start, as its web page does
on every connection. start subscribes heartbeat, logmsg and lmchart with
.html.wssub; lmchart is a function, and the original wssub stopped with
'type on it, so start never returned its data. The checks: start runs;
calling it twice leaves one subscription each; each subscription is the
handle and ` (all syms), as the original wssub registers for a table;
wssub ` subscribes every value; an unknown name is still rejected.

Master fails the start and wssub ` checks with 'type; with the html.q
fix in this PR all pass on KDB-X, and with DataIntellectTech#769 also on L and PeachQ.
@jaen15marcos
jaen15marcos marked this pull request as ready for review November 11, 2026 02:03
@jaen15marcos
jaen15marcos marked this pull request as draft November 11, 2026 02:15
engine.q detects the q engine (-engine, KDBENGINE or auto-detection) and
builds a capabilities table: kdb+ by version, exactly as the existing .z.K
checks did, and L, PeachQ and Korze by probing each feature. Every former
.z.K check now reads that table, so the same code runs on all four engines.
kdb+/KDB-X behaviour is unchanged except where noted.

Korze support:
- engine.q: Korze is detected by its .S namespace or its long .z.K. The
  features table holds each probe's name, looked up with .proc probe
  (Korze tables cannot hold functions). The deferred probe uses a handle
  no connection can have (0Wi), and the unix-socket probe also accepts
  Korze's bare 'hop.
- torq.q: the loaded-files list holds symbols, checked with in (Korze's
  in never matched the old string list, so every file loaded twice). The
  appends to .proc.loadedf and .proc.a name the global in full: on Korze,
  x,: on a global in a function called from an exec replaces x.
- tests/k4unit.q: KUact returns 1b (on Korze, an exec whose function
  returns :: for every row fails with 'type).

Engine compatibility fixes, found by running every Starter Pack process:
- engine.q: new capability memstats, true when .Q.w[] works. Korze has no
  .Q.w, so its end of day stopped after the first table. dbwriteutils.q,
  monitoringchecks.q and dqc/memoryusage.q use .Q.w only where it exists.
- engine.q: supports takes a list of names and gives one answer each; a
  name that is not a feature gives 0b and is not stored. Spaces in
  KDBENGINE and -engine are ignored.
- gateway.q: on Korze only, each query's join function and postback are
  kept in .gw.queryfuncs, a dictionary keyed by queryid, instead of in
  queryqueue's join and postback columns. Korze cannot store a function in
  a table or select a column that holds one, so every gateway query failed.
  funcsapart is set once at load and selects the path; other engines keep
  the original columns. The purge keeps the dictionary in step.
- gateway.q: the pre-3.6 sync path (L, and kdb+ before 3.6) applies a
  string join as the deferred path does; a "sum" join returned "".
- dqc/advanceddtd.q: the local mfy is now missy; L has a built-in mfy that
  cannot be assigned, so dqc1 failed to load on L.

Tests: tests/engine, 54 k4unit tests of detection, capabilities, probes
and the fixes above.

Tested on KDB-X 5.0, L (2026.11.01), PeachQ 0.91 and Korze v1.0.7051:
tests/engine 54/54 on each; with the bug-fix PR merged, tests/bugfixes
4/4 on each. Every Starter Pack process started on each engine: ticks
reach rdb1, sctp1 subscribes and the gateway answers on all four. The
gateway was also run live against the original: identical on KDB-X and
PeachQ, on L only the string join differs, and Korze now answers every
query.

Publishing to subscribers on an engine without -25! (L) is in its own PR
(faster tickerplant publishing), which chooses the publish function once,
at load, from the broadcast capability added here.
.stpps.pub sends to subscribers of all syms with -25! (broadcast). On an
engine without -25! (L) the new pubeach sends one message per subscriber
instead. Which one .stpps.pub is gets decided once, when pubsub.q loads,
from the broadcast capability in engine.q (DataIntellectTech#769), so no publish pays for
a check, and master's pub is unchanged. The choice is made above
.u.pub:.stpps.pub and .ps.publish:.stpps.pub, which copy pub when the
file loads, so both follow it. Without DataIntellectTech#769 there is no capabilities
table and pub is kept, so on its own this changes nothing.

tests/stp/pubsub: two checks while the test process is subscribed to the
pubsub process: .stpps.pub is pubeach exactly where the engine has no
-25! and the copies follow it; and a row published through pubeach
reaches the subscriber, on every engine.

Tested with DataIntellectTech#769 on KDB-X 5.0, L (2026.11.09), PeachQ 0.91: both checks
pass, and tests/stp/pubsub otherwise gives the same results as master.
One-row publishes to two subscribers, median of five alternating rounds
of 20,000: KDB-X -2.7%, L -17.4%, PeachQ -3.7%, Korze -14.5% per publish
against a check on every publish; in immediate mode the tickerplant used
less CPU on all four engines.
@jaen15marcos
jaen15marcos marked this pull request as ready for review November 11, 2026 02:30
@jaen15marcos
jaen15marcos marked this pull request as draft November 12, 2026 14:09
After the first engine-compat commit I ran TorQ's own test suites and
the full Starter Pack stack on each engine. These are the places where the
code, or a test, leaned on something only kdb+ does. Every change gives
the same result on kdb+ as before; none of them is a behaviour change
there.

Korze

- pubsub.q: a filtered subscription is added to the subscription table
  as a one-row table. Added as a list, Korze lost a level of the
  filter's nesting and every publish to a filtered subscriber failed.
- pubsub.q: pubclear resets one table at a time. With a single name in
  the list, Korze's amend stored a list where the schema should be.
- trackservers.q: getservers returned eight columns when it found
  nothing and seven otherwise. kdb+ will join those two shapes when one
  is empty; Korze won't, which stopped the WDB's reload at end of day.
  Both exits now return the same seven columns.
- stplog.q: the exit handler checked the exit code with x~0i. Korze
  passes it as a long, so a clean exit was logged as a bad one and the
  logs were left open. It now checks 0=x.
- stplog.q: in custom logging mode the tickerplant would not start,
  because Korze fails on the infix "logtabs except where ...". The
  bracket form except[logtabs;where ...] works everywhere.
- pcapdecoder.q: getips joins with sv/: where it used sv '. Korze has
  no each-both form of sv with an atom on the left.
- dqe/bucketcount.q: `minute$time in place of time.minute, which Korze
  reads as a variable inside a namespaced function.
- engine.q: defines .Q.A and .Q.a when the engine has none. TorQ itself
  only needs .Q.an, but most of the test suites build data with them.
- k4unit.q: the before and after phases no longer return :: from an
  exec, which Korze rejects, so suites with set-up rows can run.

L

- wdb.q: maptoint enumerates its value as a list. L can't enumerate a
  single symbol against the sym file, so in partbyenum mode the save
  timer failed and nothing was written.
- pcapdecoder.q: getflags casts the flag bits to long. On L, 2 vs a
  byte gives ints, which no longer join the long padding.

PeachQ

- dqe.q: init read the keyed timer table as .timer.timer[;`periodstart]
  and added a timespan to a datetime. PeachQ implements neither, so the
  data quality engine didn't load. It now uses exec and timestamps.

Tests

- helperfunctions.q: kill9proc, isalive and deadproccheck found a
  process by looking for a "q" in its name. Korze's executable is z and
  L can show up as memfd:, so they now match on TorQ's own arguments.
- stp/wdb: load the sym list before reading the saved partitions, and
  ask for the HDB folder with a string. Korze needs the sym list in
  memory to read an enumerated column, and returns a dictionary applied
  by name over IPC unevaluated.
- stp/upds: read the error log by replaying it. get on a log file
  returns nothing on Korze. TorQ itself only ever replays logs.
- stp/chainedeod: 00:00:00:10 written as 00:00:00.100, which is what
  kdb+ reads it as and Korze can parse.
- stp/chainedstp, stp/subscription: the deliberately bad update is a
  one-item list, not a bare symbol. A logged message made only of
  symbols is executed on replay by kdb+ and treated as data by Korze.
- tests/engine: one more test, for the alphabet constants.

Tested on KDB-X 5.0, L 2026.11.09, PeachQ 0.91 and Korze 1.0.7051,
together with the bugfixes branch. tests/engine passes 55/55 on all
four. The 19 tickerplant and monitor suites pass 630/630 on KDB-X. The
12 suites these changes touch pass 394/394 on L and 389/396 on Korze
(a timing row in periodend and six rows of custommode are left), and
297/297 on PeachQ, which cannot run stp/wdb. tests/stp/custommode is
repaired on the bugfixes branch, because it is broken on master for
every engine.
Running all nineteen tickerplant suites on each engine, on a second
machine and not as root, turned up four more places where TorQ leaned
on kdb+ behaviour.

- torq.sh: stop kills the pid it already found from the process's
  arguments. It used to ask lsof which process was listening on the
  port, and lsof cannot see the sockets of an L process unless you are
  root, so stop printed kill's usage message and left the process
  running. That is what failed stp/recovery and stp/wdb on L for a
  normal user.
- subscriptions.q: the function sent to an old-style tickerplant calls
  (.u.sub\:)[x;y], with the each-left in parentheses. Korze can't run
  the bare .u.sub\:[x;y] inside a function that has been sent to
  another process, so nothing could subscribe to tickerplant.q there.
  The parenthesised form means the same and costs the same.
- tickerlogreplay.q: a zipped log is replayed through a named pipe,
  which L, PeachQ and Korze can't do, and TorQ refused the log. Where
  the engine has no pipe replay it now unzips to a temporary file and
  replays that. This also covers kdb+ before 4.0.
- tests/engine: two tests asserted that refusal and now assert the
  replay. stp/tpvalidation loads the sym list before reading the saved
  partitions, as stp/wdb does.

On L 2026.11.09, stp/tickerlog goes from 59/68 to 68/68. On Korze,
stp/tpvalidation goes from 7/23 to 24/24. tests/engine still passes
55/55 on KDB-X, L, PeachQ and Korze, and KDB-X is unchanged on the
suites these files touch.
dqe1 runs each check on another process by sending it the check's
function, and gets the result back through a postback projection. Korze
cannot run a functional select, or the bracketed each-both f'[x;y],
inside a function which arrived from another process, and every check
and the postback use one or the other. So on Korze every check failed
on the HDB, and came back as "error: server fail".

On Korze only, a check which is a plain function is now sent as its
source text and compiled where it runs, and the postback is sent by
name with an id; dqe1 keeps what the projection used to carry until
the result returns. kdb+, L and PeachQ use the same code as before.

With the Starter Pack's nine configured checks run against its HDB,
Korze now records the same results as KDB-X: 7 rows in resultstab and
3 in advancedres, with no errors. Before, it recorded none.
… needs

Korze 1.07297 (13 Nov 2026) fixes most of the differences this branch
worked around, and reports its version differently. This brings the
branch in line with it.

Detection (engine.q):
- Korze is recognised by .z.KK, which returns `korze, as its author
  suggests. Any engine which defines .z.KK is recognised the same way.
- L is recognised by .z.L being a number.
- Both names raise an error on kdb+, so they are read inside a trap.
- The old test for Korze (a long .z.K) no longer holds: .z.K is now
  the float 1.07297.

Needed for the new Korze to start (torq.q):
- checkdependency judged "requires kdb 3.4" against .z.K, which on
  another engine is that engine's own version. Korze's 1.07 failed it,
  so no Starter Pack process started. A kdb requirement is now checked
  on kdb+ only; what another engine can do is in .proc.capabilities.

Workarounds removed, back to master's code, because the new Korze
behaves as kdb+ does:
- gateway.q: join functions and postbacks are kept in the query table
  again (a table column can hold functions). The separate dictionary
  and its three helpers are gone.
- pubsub.q: a filtered subscription is upserted as a list row.
- trackservers.q: getservers returns master's result when nothing
  matches (a table joins an empty one with other columns).
- stplog.q: "logtabs except where ..." and the exit code matched with
  x~0i.
- pcapdecoder.q: getips uses sv ' again.
- k4unit.q: back to master (an exec may return ::).
- dqe.q: the Korze-only way of sending a check (as source text, with
  a named postback) is gone. With the Starter Pack's nine checks run
  against its HDB, the new build records the same results either way.

Still needed on Korze, and kept: .Q.A and .Q.a are missing, .Q.w is
missing, an amend with a one-item list of names stores a list, a
dictionary of tables returns :: for a missing key, time.minute in a
namespaced function, and kdb+-written tick logs and partitions cannot
be read.

Tested on KDB-X 5.0, L 2026.11.09, PeachQ 0.91.20261113 and Korze
1.07297. tests/engine passes 55/55 on all four. KDB-X passes all 19
tickerplant suites, 632/632, and Korze 588/632, the same as the old
build did before this change. On Korze the whole Starter Pack stack
starts with no errors and the data quality checks return.
Korze v1.0.7337 (14 Nov 2026) fixes five more of the differences this
branch worked around, so that code goes back to master's.

- pubsub.q: pubclear amends the list of tables in one call again (an
  amend with a one-item list of names now assigns the value).
- subscriptions.q: the function sent to an old-style tickerplant uses
  .u.sub\:[x;y] again.
- dqe/bucketcount.q: time.minute again (it now works in a function
  defined in a namespace). The file is back to master.
- torq.q: checkdependency appends to a again, as on master.
- tests/stp/chainedeod: the time literal 00:00:00:10 again.

Tested with both PRs merged, each suite in a fresh environment, on
KDB-X 5.0, L 2026.11.09, PeachQ 0.91.20261113 and Korze 1.07337:
tests/engine passes 55/55 on all four. The nineteen tickerplant and
monitor suites give KDB-X 632/632, L 630/630 and Korze 595/632 (588
on Korze 1.07297 before this change).
…stp/upds passes 44/44 on KDB-X, L, PeachQ and

Korze.
@jaen15marcos
jaen15marcos marked this pull request as ready for review November 15, 2026 22:03
@jaen15marcos

Copy link
Copy Markdown
Contributor Author

Replaced by a series of smaller PRs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant