Repository navigation
Commit 1d56fcd
Share the fsyncs: group commit, AddBatch, AddWait, TryPeek
Per-op durability used to serialize every producer on the disk: two
fsyncs per record, under the queue mutex, with readers stalled behind
them. The whole change hangs on one new invariant — a STAGED record's
bytes are written past the published extent while the header, the
cursors and the counts do not move — so a flush leader can release the
mutex during its fsyncs and nothing (readers, commits, Stats, a crash)
can see a record whose bytes are not yet durable. Publication is a
span: data fsync for everyone staged, one header write, one header
fsync. Every staged record lives in the active file (cycling, batch,
Requeue, Sync and Close quiesce first), so a failed publication
discards exactly one contiguous tail.
Group commit: an Add that arrives while a flush is in flight stages
its record and rides the next span; a solo Add leads a span of one and
allocates nothing, so the single-producer path stays 0 allocs/op and
within noise of its old cost. Concurrent durable Adds go ~7x faster on
this machine, each still individually durable when it returns. The
span's failure arms mirror the solo append's exactly — data-fsync
latches with nothing published, header-write discards with nothing
latched, header-fsync latches with the span real in the page cache —
and faults_test.go pins ordering and arms for all three shapes (solo,
group, batch) under the same injection points.
AddBatch(items) amortizes the same span across a batch from one
goroutine (~50x per record here) and reports how many leading items
were placed and durable when it stops early. AddWait(ctx, v) is the
blocking half of MaxBytes backpressure: it parks on a space signal
that every commit-capable consume op raises, and still fails fast on
ErrRecordTooLarge. TryPeek inspects the head without consuming — no
cursor moves, and a damaged head previews as an UNCOUNTED ErrCorrupt
so the consume that follows books the event exactly once.
Add and AddWait now marshal BEFORE taking the lock, into pooled
buffers, so codecs run concurrently across producers and a slow codec
no longer stalls consumers; AddBatch marshals under the lock. The
failure arms unreachable without a seam are covered in the faults
build (unpublishSpan, discardStaged, rollbackAppend at 100% there).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>1 parent 56024e6 commit 1d56fcd
9 files changed
Lines changed: 1634 additions & 42 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
28 | | - | |
29 | | - | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
| |||
350 | 352 | | |
351 | 353 | | |
352 | 354 | | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
353 | 399 | | |
354 | | - | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
355 | 406 | | |
356 | 407 | | |
357 | 408 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
182 | | - | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
183 | 185 | | |
184 | 186 | | |
185 | 187 | | |
| |||
194 | 196 | | |
195 | 197 | | |
196 | 198 | | |
| 199 | + | |
197 | 200 | | |
198 | 201 | | |
199 | 202 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
0 commit comments