Commit 923dcb4
fix(ilp): cursor SF review fixes — perf, cap, torn-tail, races
Multi-issue review pass over the cursor SF stack from PR-17. Each
fix lands with a regression test (or extends an existing one); full
QWP suite green at 1053 tests.
- recovery sort: SegmentRing.openExisting used selection sort, which
regressed the legacy SegmentLog perf fix (commit 86b6e6f) on the
cursor path. Replaced with median-of-three in-place quicksort —
median-of-three needed because lexicographic readdir returns our
zero-padded hex names already-sorted, the worst case for a naive
pivot. testLargeSegmentCountReopensInOrder guards against
regression.
- cap accounting: SegmentManager.register/deregister ignored the
bytes a recovered or adopted ring already owns, so the documented
sf_max_total_bytes cap could be exceeded by a full segment-set on
restart. Now seeds totalBytes from ring.totalSegmentBytes() and
serviceRing updates the counter under the same lock so concurrent
register/deregister stays consistent.
- torn-tail observability: openExisting silently truncated on the
first bad CRC with no log or signal. Now distinguishes attempted-
but-failed frame writes (non-zero bytes past lastGood) from clean
unwritten space; emits WARN with byte count + offset and exposes
tornTailBytes() for diagnostics. No false alarms on fresh hot
spares or partial fills.
- drainOrphans Javadoc: setter claimed scan/log only with drainer
runtime "as a follow-up", but build() spawns the
BackgroundDrainerPool. Rewritten to describe actual adoption.
- BackgroundDrainerPool submit/close race: volatile-boolean gate
let close() return while submit() was about to register a drainer.
AtomicInteger CAS gate with sign-bit closed flag closes the window.
- CursorWebSocketSendLoop close hangs and reconnect leak: start()
try/catches Thread.start() and assigns ioThread only on success;
close() guards on isAlive() and closes the current client field;
reconnect closes the previous WebSocketClient before assigning the
new one.
- row-API methods accepting rows after the I/O loop went terminal:
table()/longColumn()/atNow() etc. now surface the loop's terminal
error on the next call instead of swallowing it until the next
flush().
- non-success ACK not marking the loop fatal: the I/O response
handler now routes through recordFatal so the loop exits cleanly
instead of looping on the same rejected frame.
- CursorSendEngine close() left .sfa files when fully drained:
captures fullyDrained before ring.close() and unlinks all segment
files via unlinkAllSegmentFiles(dir) when nothing is pending
replay.
- SegmentRing recovery leaked empty .sfa files: openExisting now
Files.remove(path) after closing zero-frame segments instead of
letting them accumulate across restart cycles.
- closeFlushTimeoutMillis sentinel collision: -1 was both the
documented "no timeout" value and the parameter-not-set sentinel.
Introduced CLOSE_FLUSH_TIMEOUT_NOT_SET = Long.MIN_VALUE; -1 now
correctly disables the timeout.
- Windows files.c read/write/append accepted negative lengths and
silently overflowed DWORD. New clamp_len helper rejects < 0 and
clamps to MAXDWORD per call.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 267b380 commit 923dcb4
24 files changed
Lines changed: 2101 additions & 111 deletions
File tree
- core/src
- main
- c/windows
- java/io/questdb/client
- cutlass/qwp/client
- sf/cursor
- test/java/io/questdb/client/test/cutlass/qwp/client
- sf/cursor
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
145 | 145 | | |
146 | 146 | | |
147 | 147 | | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
148 | 162 | | |
149 | 163 | | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
150 | 170 | | |
151 | 171 | | |
152 | 172 | | |
153 | 173 | | |
154 | 174 | | |
155 | | - | |
| 175 | + | |
156 | 176 | | |
157 | 177 | | |
158 | 178 | | |
| |||
165 | 185 | | |
166 | 186 | | |
167 | 187 | | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
168 | 194 | | |
169 | 195 | | |
170 | 196 | | |
171 | 197 | | |
172 | 198 | | |
173 | | - | |
| 199 | + | |
174 | 200 | | |
175 | 201 | | |
176 | 202 | | |
| |||
179 | 205 | | |
180 | 206 | | |
181 | 207 | | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
182 | 214 | | |
183 | | - | |
| 215 | + | |
184 | 216 | | |
185 | 217 | | |
186 | 218 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
681 | 681 | | |
682 | 682 | | |
683 | 683 | | |
684 | | - | |
685 | | - | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
686 | 689 | | |
687 | 690 | | |
688 | 691 | | |
| |||
1036 | 1039 | | |
1037 | 1040 | | |
1038 | 1041 | | |
1039 | | - | |
| 1042 | + | |
1040 | 1043 | | |
1041 | 1044 | | |
1042 | 1045 | | |
| |||
1919 | 1922 | | |
1920 | 1923 | | |
1921 | 1924 | | |
1922 | | - | |
1923 | | - | |
1924 | | - | |
| 1925 | + | |
| 1926 | + | |
| 1927 | + | |
1925 | 1928 | | |
1926 | 1929 | | |
1927 | | - | |
1928 | | - | |
1929 | | - | |
| 1930 | + | |
| 1931 | + | |
| 1932 | + | |
| 1933 | + | |
| 1934 | + | |
| 1935 | + | |
| 1936 | + | |
1930 | 1937 | | |
1931 | | - | |
1932 | | - | |
1933 | | - | |
1934 | | - | |
1935 | | - | |
| 1938 | + | |
| 1939 | + | |
| 1940 | + | |
1936 | 1941 | | |
1937 | 1942 | | |
1938 | 1943 | | |
| |||
Lines changed: 32 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
879 | 879 | | |
880 | 880 | | |
881 | 881 | | |
882 | | - | |
883 | | - | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
884 | 887 | | |
885 | | - | |
886 | | - | |
887 | | - | |
888 | | - | |
889 | | - | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
890 | 902 | | |
891 | | - | |
892 | | - | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
893 | 906 | | |
894 | 907 | | |
895 | 908 | | |
| |||
1445 | 1458 | | |
1446 | 1459 | | |
1447 | 1460 | | |
| 1461 | + | |
| 1462 | + | |
| 1463 | + | |
| 1464 | + | |
| 1465 | + | |
| 1466 | + | |
| 1467 | + | |
| 1468 | + | |
| 1469 | + | |
| 1470 | + | |
1448 | 1471 | | |
1449 | 1472 | | |
1450 | 1473 | | |
| |||
Lines changed: 61 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| |||
51 | 52 | | |
52 | 53 | | |
53 | 54 | | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
54 | 69 | | |
55 | 70 | | |
56 | 71 | | |
57 | 72 | | |
58 | | - | |
59 | 73 | | |
60 | 74 | | |
61 | 75 | | |
| |||
77 | 91 | | |
78 | 92 | | |
79 | 93 | | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
80 | 99 | | |
81 | 100 | | |
82 | | - | |
83 | | - | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
84 | 109 | | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
90 | 123 | | |
91 | 124 | | |
92 | | - | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
93 | 130 | | |
94 | 131 | | |
95 | 132 | | |
| |||
103 | 140 | | |
104 | 141 | | |
105 | 142 | | |
106 | | - | |
107 | | - | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
108 | 158 | | |
109 | 159 | | |
110 | 160 | | |
| |||
0 commit comments