Skip to content

di.torq.proc.segmentedtp: log memorybatch rows buffered at a roll - #154

Merged
DI-Dexter merged 4 commits into
mainfrom
rollover-bug-fix
Nov 11, 2026
Merged

DI-Dexter merged 4 commits into
mainfrom
rollover-bug-fix

Conversation

@alowrydi

@alowrydi alowrydi commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator

Title: di.torq.proc.segmentedtp: log memorybatch rows buffered at a roll

Summary

In memorybatch mode, an update arriving past a period or day roll ran the roll before the next timer tick. pubclear then published the buffered rows without writing them to a log, so they reached subscribers and the HDB but no log, and a process replaying the logs could not recover them.

.stplg.flushbatch now runs the timer's write, publish and count step as the first step of stpeoperiod, endofday and the chained endofperiod. Buffered rows go to the closing log, and the update that triggers a roll goes to the new log. segmentedtp goes to 0.2.1.

Testing

k4unit (di.torq.proc.segmentedtp): 110 of 110 pass. Adds a standalone and a chained memorybatch peer, covering period and day rolls through an update and through the chained peer. Run against the original stplog.q, the same tests give 7 failures.

TorqX-POC data-capture-1 stack, forced rolls. Same scenarios with and without the fix, on the same base commit:

Scenario Without fix With fix
3 hour rolls during a burst: trade rows missing from logs 24 of 7519 0 of 7499
Same rolls: quote rows missing from logs 25 of 7519 0 of 7499
Last-value cache restarted from logs, compared with the RDB no match, 24 symbols missing exact match
verify.q eod2: orders logs vs HDB difference 1 0
End of day during a burst: trade / quote logs vs HDB difference 8 / 8 0 / 0

Real 17:00 hour roll, nothing forced, with the fix. Burst from 16:59:30 to 17:00:30:

  • 14949 trade and 14949 quote burst rows sent, all logged once and all in the RDB
  • closing logs hold only rows from before 17:00 (last trade row 16:59:59.9965) and new logs only rows from 17:00 on
  • last-value cache restarted from logs matched the RDB on all 14954 symbols
  • logs vs HDB difference of 0 on all four tables, after a forced end of day to get the data into the HDB

Not covered

  • A natural midnight roll: every end of day tested was forced
  • Replay on the RDB or WDB: recovery was only tested on the last-value process
  • Chained memorybatch on a full stack: unit tests only
  • The real-roll run was a single roll with no side-by-side run without the fix

An update arriving past a period or day roll ran the roll before the next
timer tick, so pubclear published buffered rows without writing them to a log.
A process replaying the logs could not recover those rows.

Flush the batch to the closing log as the first step of stpeoperiod, endofday
and the chained endofperiod. The update that triggers a roll still goes to the
new log.

Add a standalone and a chained memorybatch peer to the tests, covering period
and day rolls through an update and through the chained peer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread di/torq/proc/segmentedtp/test.q Resolved
@DI-Software-Engineering

Copy link
Copy Markdown

DIReview Summary

0 critical | 1 warning(s) | 0 suggestion(s)

⚠️ Spec check skipped — tracker lookup failed (NO_REF_FOUND). Standards axis only.

@DI-Dexter

Copy link
Copy Markdown
Collaborator

Tested against main. The suite passes, and removing the fix gives the 7 failures you listed.

Needs changing

VERSION conflicts with #152. Main is now 0.3.0, so this becomes 0.3.1.

Worth including: defaultbatch has the same root cause

Looks like this is an underlying issue in TorQ as well and the problem was ported over. A roll triggered by an update skips the timer step that adds tmpmsgcount to msgcount, so the counts go wrong. On the suite's defaultbatch peer:

closed log: real / stpmeta new log: real / msgcount
tick before the roll 2 / 2 1 / 1
roll through an update 2 / 0 1 / 3

The overcount lasts until the next roll. With two more updates logged but not yet published, replaying msgcount messages returned `d`e`f while `e`f were still unpublished, so a subscriber joining then would get those two again when they publish. I measured the replay and the pending rows, not the second delivery. tickerlogreplay only takes log names from stpmeta, so the wrong count there doesn't lose data.

Calling the mode's own timer step fixes both modes and drops the mode check:

.stplg.flushbatch:{.stplg.ts[];}

With this, the update-triggered case gives 2 / 2 and 1 / 1, the replay returns only `d, and the suite still passes. It would need its own defaultbatch test row.

Small

The new segmentedtp.md bullet could say this differs from TorQ, since TorQ master still publishes these rows without logging them.

alowrydi and others added 2 commits November 6, 2026 10:42
Resolve the segmentedtp VERSION conflict with #152 as 0.3.1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…roll

defaultbatch had the same root cause as memorybatch. A roll triggered by an
update skipped the timer step that adds tmpmsgcount to msgcount, so the closed
log's stpmeta msgcount was too low and the new log's too high until the next
roll. Replaying msgcount messages could then return rows not yet published.

Call the active mode's own timer step, which covers every mode and drops the
mode check.

Add defaultbatch tests for period and day rolls through an update, covering
the stpmeta count, the new log's count and replay. Note in segmentedtp.md that
this differs from TorQ.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@DI-Software-Engineering

Copy link
Copy Markdown

DIReview Summary

0 critical | 0 warning(s) | 2 suggestion(s)

⚠️ Spec check skipped — tracker lookup failed (NO_REF_FOUND). Standards axis only.

Suggestions

  • di/util/cfg/cfg.q:49 — The scale function's infinity check compares the raw value against the type-specific infinity constants, but the inf variable is set to the positive infinity for the input type and then abs x is compared against it. For a float input (-8h or -9h), inf is set to 0w (positive float infinity). However, when x is a float NaN or when the type is -8h (real), inf would be 0w (float), not 0we (real infinity). The check if[inf=abs x;...] compares a real infinity (0we) against 0w (float infinity) — these are different types and the equality would not catch a real infinity. Specifically, for -8h (real type), inf is assigned 0w (a float, -9h), not 0we. So a real infinity (0We) would not be caught, scale would attempt to compute (float$0We)*float$x which yields a float infinity, pass the 9.2e18 check (since 0w > 9.2e18), and then reach u*x which returns a real — but the null check in astimespan would then fail. Fix: for type -8h, set inf:0We.
  • di/timer/init.q:149 — The new disable condition if[not r[nextstart] within (r[created]&r[created]^rstartattime;0Wp^rmaxtime)]usesr[created]^rstartattimeto fill a nullstartattimewithcreated. However, ^(fill) in q fills nulls in the left argument from the right — i.e.x^yfills nulls inxwithy. So r[created]^rstartattimefills nulls increated(a timestamp) withstartattime. If createdis never null, this is always justr[created], making startattime irrelevant. The intended logic is presumably rstartattime^rcreated (fill nulls in startattime with created), so the lower bound is startattime when set, else created. As written, the lower bound is always r[created](sincecreatedis never null), meaningstartattime` has no effect on the disable check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread di/torq/proc/segmentedtp/test.q Resolved
@DI-Software-Engineering

Copy link
Copy Markdown

DIReview Summary

0 critical | 1 warning(s) | 0 suggestion(s)

⚠️ Spec check skipped — tracker lookup failed (NO_REF_FOUND). Standards axis only.

@alowrydi

alowrydi commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator Author

DIReview Summary

0 critical | 0 warning(s) | 2 suggestion(s)

⚠️ Spec check skipped — tracker lookup failed (NO_REF_FOUND). Standards axis only.

Suggestions

  • di/util/cfg/cfg.q:49 — The scale function's infinity check compares the raw value against the type-specific infinity constants, but the inf variable is set to the positive infinity for the input type and then abs x is compared against it. For a float input (-8h or -9h), inf is set to 0w (positive float infinity). However, when x is a float NaN or when the type is -8h (real), inf would be 0w (float), not 0we (real infinity). The check if[inf=abs x;...] compares a real infinity (0we) against 0w (float infinity) — these are different types and the equality would not catch a real infinity. Specifically, for -8h (real type), inf is assigned 0w (a float, -9h), not 0we. So a real infinity (0We) would not be caught, scale would attempt to compute (float$0We)*float$x which yields a float infinity, pass the 9.2e18 check (since 0w > 9.2e18), and then reach u*x which returns a real — but the null check in astimespan would then fail. Fix: for type -8h, set inf:0We.
  • di/timer/init.q:149 — The new disable condition if[not r[nextstart] within (r[created]&r[created]^rstartattime;0Wp^rmaxtime)]usesr[created]^rstartattimeto fill a nullstartattimewithcreated. However, ^(fill) in q fills nulls in the left argument from the right — i.e.x^yfills nulls inxwithy. So r[created]^rstartattimefills nulls increated(a timestamp) withstartattime. If createdis never null, this is always justr[created], making startattime irrelevant. The intended logic is presumably rstartattime^rcreated (fill nulls in startattime with created), so the lower bound is startattime when set, else created. As written, the lower bound is always r[created](sincecreatedis never null), meaningstartattime` has no effect on the disable check.

Thanks, all addressed in f16d153 and 47e23bb:

  • VERSION: merged main and set it to 0.3.1.
  • defaultbatch: .stplg.flushbatch is now {.stplg.ts[];} as you suggested, so it covers every mode with no mode check.
  • Tests: added a defaultbatch section for period and day rolls through an update. It checks the stpmeta count, the new log's count and that replay returns only published rows. With the previous helper, 4 of the new rows fail. The other 3 (published once, new day's count) pass either way, so they only guard against regressions.
  • segmentedtp.md: the behaviour bullet now covers both modes and says this differs from TorQ. I checked that against TorQ master, where stpeoperiod and endofday call pubclear without the timer step.

The update-triggered period roll now gives 2 / 2 and 1 / 1, matching your numbers. My rows use different symbols, so replay returns only c where yours returned d. Like you, I measured the replay rather than a subscriber actually receiving rows twice.

The full suite passes. On the TorqX-POC data-capture-1 stack, I re-ran the burst across forced rolls: no rows lost, lvc1 recovered exactly, and logs matched the HDB on all four tables. The real 17:00 roll ran before these changes and hasn't been repeated, and a natural midnight roll is still untested.

I've also merged main (a939d11), which only brought in #88, and the segmentedtp suite passes on the result.

@alowrydi
alowrydi requested a review from DI-Dexter November 6, 2026 10:52
@DI-Dexter

Copy link
Copy Markdown
Collaborator

Thanks Aaron, all four addressed. Tested and the suite passes, approving.

@DI-Dexter
DI-Dexter merged commit 302c336 into main Nov 11, 2026
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.

3 participants