Commit 519f5e4
fix(ilp): trim acked frames from active SF segment
Pre-fix behaviour: SegmentLog.trim only deleted sealed segments. Frames
that the server had acknowledged but lived in the still-open active
segment stayed on disk until the next natural rotation. On restart the
new sender replayed those frames and the public Sender.storeAndForward
contract — "trimmed when the server acknowledges it" — was load-bearing
on server-side seqTxn dedup to avoid duplicate rows. Worst case at the
default 64 MiB segment size: ~640 acked batches re-shipped per restart.
Fix: when every frame in the active segment has been acked, force-rotate
the active (sealing the file) and immediately remove the just-sealed
segment. nextSeq is preserved across the auto-rotate so subsequent
appends keep monotonic FSNs. The only safe-guard is the rotate-OOM
recovery state from the M2 fix: when active.sealed is already true,
the sealed pass above has already trimmed the file and force-rotate
is skipped.
Tests:
- testTrimRotatesAndDropsFullyAckedActiveSegment (SegmentLogTest):
unit-level proof that trim with full coverage drops the active
contents to a fresh empty segment, with nextSeq preserved.
- testTrimPartialAckOfActiveLeavesItIntact (SegmentLogTest, replaces
testTrimNeverDeletesActive): proves partial ACKs do not seal a
segment that still contains unacked data.
- testRestartAfterAckedBatchesReplaysNothing (SfIntegrationTest):
end-to-end. Send 5 batches, wait for trim, close, reopen with a
fresh sender, send one more, assert server saw exactly 6 frames
(5 originals + 1 new, no replays).
- testCapturedBytesMatchWireBytes (SfIntegrationTest): updated to use
a non-acking handler so the test thread's log.replay() doesn't race
the I/O thread's trim.
- testAutoReconnectAndReplay (SfIntegrationTest): expected frame
count drops from 5 to 4 (msg1 trimmed before reconnect, no replay).
- testMultiTableSurvivesReconnect (SfIntegrationTest): expected frame
count drops from 6 to 5 (alpha-1 trimmed before reconnect).
Public API:
- Sender.storeAndForwardDir Javadoc rewritten to honestly describe the
new contract: acked batches are reclaimed in real time; only batches
whose ACK had not been received before sender shutdown are replayed
on the next sender against the same directory.
Full suite: 1975 tests pass, zero regressions.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent acb32b9 commit 519f5e4
4 files changed
Lines changed: 289 additions & 30 deletions
File tree
- core/src
- main/java/io/questdb/client
- cutlass/qwp/client/sf
- test/java/io/questdb/client/test/cutlass/qwp/client/sf
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1569 | 1569 | | |
1570 | 1570 | | |
1571 | 1571 | | |
1572 | | - | |
1573 | | - | |
1574 | | - | |
| 1572 | + | |
| 1573 | + | |
| 1574 | + | |
| 1575 | + | |
| 1576 | + | |
| 1577 | + | |
| 1578 | + | |
| 1579 | + | |
| 1580 | + | |
| 1581 | + | |
| 1582 | + | |
| 1583 | + | |
| 1584 | + | |
| 1585 | + | |
| 1586 | + | |
| 1587 | + | |
1575 | 1588 | | |
1576 | 1589 | | |
1577 | 1590 | | |
| |||
Lines changed: 40 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
256 | 256 | | |
257 | 257 | | |
258 | 258 | | |
259 | | - | |
260 | | - | |
261 | | - | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
262 | 271 | | |
263 | 272 | | |
264 | 273 | | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
265 | 302 | | |
266 | 303 | | |
267 | 304 | | |
| |||
Lines changed: 72 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
246 | 246 | | |
247 | 247 | | |
248 | 248 | | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
249 | 255 | | |
250 | | - | |
| 256 | + | |
251 | 257 | | |
252 | 258 | | |
253 | 259 | | |
| |||
259 | 265 | | |
260 | 266 | | |
261 | 267 | | |
262 | | - | |
263 | | - | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
264 | 272 | | |
265 | 273 | | |
266 | 274 | | |
267 | 275 | | |
268 | 276 | | |
269 | 277 | | |
270 | | - | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
271 | 339 | | |
272 | 340 | | |
273 | 341 | | |
| |||
0 commit comments