test: preserve last acknowledged v3 record at cursor exhaustion

This commit is contained in:
pingqiu committed 2026-11-17 02:04:15 -08:00
1 parent f3cccff9cc
commit cd074a7b0c
2 files changed
+25 -3

No files matched your search

+6 -3
View File
@@ -179,10 +179,13 @@ func scanWALV3(fd *os.File, d descriptorV3) (walScanResultV3, error) {
if d.MigrationPhase != MigrationNormal {
return r, ErrMigrationIncomplete
}
if d.WALSize > counterMaxV3-d.RetainedTail {
return r, ErrCounterExhausted
// The mathematical lap end may exceed the last representable cursor.
// Clamp the scan, not the acknowledged history: exhaustion refuses NEW
// appends but must not make a valid last record unrecoverable.
limit := uint64(counterMaxV3)
if d.WALSize <= counterMaxV3-d.RetainedTail {
limit = d.RetainedTail + d.WALSize
}
limit := d.RetainedTail + d.WALSize
start := d.RetainedTail
base := d.CheckpointLSN
if d.BaseState != BaseNone {
@@ -316,3 +316,22 @@ func TestWALIOV3_ScanRequiresActualSourceBounds(t *testing.T) {
t.Fatalf("truncated source bounds error=%v", err)
}
}
func TestWALIOV3_LastRepresentableRecordStillRecovers(t *testing.T) {
start := uint64(counterMaxV3) - 70
f, p, w := newWALIOTestV3(t, start, start)
d := p.current()
if _, err := w.append(walEntryV3{LSN: 1, Type: walEntryBarrier}, 0); err != nil {
t.Fatal(err)
}
r, err := scanWALV3(f, d)
if err != nil {
t.Fatal(err)
}
if len(r.Records) != 1 || r.Frontier != 1 || r.End != counterMaxV3 {
t.Fatalf("last representable scan=%+v", r)
}
if _, err := w.append(walEntryV3{LSN: 2, Type: walEntryBarrier}, 0); !errors.Is(err, ErrCounterExhausted) {
t.Fatalf("next append=%v", err)
}
}