Commit efde7bc
fix(ilp): harden SF disk-full retry, reconnect, and CRC paths
Multiple correctness fixes to the QWiP store-and-forward client that
were silently losing data under realistic outage scenarios.
Critical:
- markSending() moved after segmentLog.append; nextBatchSequence only
advances on append success. Disk-full retry no longer crashes with
IllegalStateException + drift exception, recycling the buffer
without persistence (C1, C2).
- doReconnectCycle no longer drops pendingBuffer on every reconnect
attempt. Buffer survives across attempts and is persisted by the
post-reconnect ACTIVE state (C3).
- createActive closes fd in try/catch on writeHeader/fsync failure;
no more fd leak on every failed rotation under disk pressure (C4).
- scanActive/replaySegment reject Files.length(fd) == -1 instead of
treating it as "empty segment" (C5).
Moderate:
- scanActive distinguishes torn tail from mid-stream CRC mismatch;
bit-rot followed by trailing bytes throws instead of silently
truncating (M1).
- Files.close accepts any fd >= 0 (was refusing 0/1/2, leaking lock
fd in containers where stdin/stdout/stderr were pre-closed) (M2).
- Connect-string sf_max_bytes / sf_max_total_bytes parsed as long;
was capped at ~2 GB by parseIntValue (M3).
- WebSocketSendQueue.client made volatile so close-during-reconnect
reads the live ref, not a stale one (M4).
- SegmentLog uses ObjList instead of java.util.ArrayList; bytesOnDisk
is cached and updated incrementally so append() is O(1) zero-alloc
on the I/O hot path (M6, N3).
- Each Segment caches a native UTF-8 path pointer; remove(String) is
no longer called per-trim, eliminating the byte[] alloc on the I/O
thread per ACK (M7).
- retryStalled always re-flags interrupt status (M8).
Cleanup:
- Dead WebSocketSendQueue.safeSendBatch removed (N1).
- @FunctionalInterface on Reconnector (N2).
- Inline FQNs in QwpWebSocketSender / Sender replaced with imports (N6).
- setSegmentLog overload pair co-located with cleaner doc (N8).
- Javadoc added to Files.java public surface and Crc32c.update (N9).
- Single-arg failConnection overload removed; every call site is now
explicit about fatal vs non-fatal (N10).
Infrastructure:
- New FilesFacade interface + DefaultFilesFacade impl in
io.questdb.client.std. SegmentLog refactored to use the facade so
tests can inject OS-level failures (short writes, fstat -1, fsync
EIO) without filesystem-level tricks.
Tests:
- 12 new red regression tests for the bug fixes above (now green).
- 5 coverage-gap tests for previously-untested error paths (M9):
unsupported version header, baseSeq mismatch, multi-active
rejection, oldestSeq edge cases, short-write recovery via
fault-injection.
- Full SF + Files suite: 70 tests pass.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent f5afbf6 commit efde7bc
12 files changed
Lines changed: 1847 additions & 170 deletions
File tree
- core/src
- main/java/io/questdb/client
- cutlass/qwp/client
- sf
- std
- test/java/io/questdb/client/test
- cutlass/qwp/client/sf
- std
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
| 40 | + | |
39 | 41 | | |
40 | 42 | | |
41 | 43 | | |
| |||
931 | 933 | | |
932 | 934 | | |
933 | 935 | | |
934 | | - | |
| 936 | + | |
935 | 937 | | |
936 | 938 | | |
937 | 939 | | |
| |||
942 | 944 | | |
943 | 945 | | |
944 | 946 | | |
945 | | - | |
| 947 | + | |
946 | 948 | | |
947 | 949 | | |
948 | | - | |
| 950 | + | |
949 | 951 | | |
950 | | - | |
| 952 | + | |
951 | 953 | | |
952 | 954 | | |
953 | 955 | | |
| |||
1589 | 1591 | | |
1590 | 1592 | | |
1591 | 1593 | | |
1592 | | - | |
| 1594 | + | |
1593 | 1595 | | |
1594 | 1596 | | |
1595 | 1597 | | |
| |||
1606 | 1608 | | |
1607 | 1609 | | |
1608 | 1610 | | |
1609 | | - | |
| 1611 | + | |
1610 | 1612 | | |
1611 | 1613 | | |
1612 | 1614 | | |
| |||
1694 | 1696 | | |
1695 | 1697 | | |
1696 | 1698 | | |
| 1699 | + | |
| 1700 | + | |
| 1701 | + | |
| 1702 | + | |
| 1703 | + | |
| 1704 | + | |
| 1705 | + | |
| 1706 | + | |
| 1707 | + | |
| 1708 | + | |
| 1709 | + | |
1697 | 1710 | | |
1698 | 1711 | | |
1699 | 1712 | | |
| |||
2071 | 2084 | | |
2072 | 2085 | | |
2073 | 2086 | | |
2074 | | - | |
| 2087 | + | |
2075 | 2088 | | |
2076 | 2089 | | |
2077 | 2090 | | |
2078 | 2091 | | |
2079 | 2092 | | |
2080 | 2093 | | |
2081 | | - | |
| 2094 | + | |
2082 | 2095 | | |
2083 | 2096 | | |
2084 | 2097 | | |
| |||
Lines changed: 29 additions & 24 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| |||
167 | 168 | | |
168 | 169 | | |
169 | 170 | | |
170 | | - | |
| 171 | + | |
171 | 172 | | |
172 | 173 | | |
173 | 174 | | |
| |||
348 | 349 | | |
349 | 350 | | |
350 | 351 | | |
351 | | - | |
| 352 | + | |
352 | 353 | | |
353 | 354 | | |
354 | 355 | | |
| |||
1192 | 1193 | | |
1193 | 1194 | | |
1194 | 1195 | | |
1195 | | - | |
1196 | | - | |
1197 | | - | |
1198 | | - | |
1199 | | - | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
1200 | 1199 | | |
1201 | | - | |
| 1200 | + | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
| 1204 | + | |
| 1205 | + | |
1202 | 1206 | | |
1203 | 1207 | | |
1204 | 1208 | | |
1205 | 1209 | | |
1206 | | - | |
| 1210 | + | |
1207 | 1211 | | |
1208 | 1212 | | |
1209 | 1213 | | |
1210 | 1214 | | |
1211 | | - | |
1212 | | - | |
1213 | | - | |
1214 | | - | |
1215 | | - | |
1216 | | - | |
1217 | | - | |
1218 | | - | |
1219 | | - | |
1220 | | - | |
1221 | | - | |
1222 | | - | |
1223 | | - | |
1224 | | - | |
| 1215 | + | |
| 1216 | + | |
| 1217 | + | |
| 1218 | + | |
| 1219 | + | |
1225 | 1220 | | |
1226 | | - | |
| 1221 | + | |
1227 | 1222 | | |
1228 | 1223 | | |
1229 | 1224 | | |
| |||
1239 | 1234 | | |
1240 | 1235 | | |
1241 | 1236 | | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
1242 | 1247 | | |
1243 | 1248 | | |
1244 | 1249 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
0 commit comments