diff --git a/seaweed-block/core/storage/wal_io_v3.go b/seaweed-block/core/storage/wal_io_v3.go index 6e8757047d..4ae4eacff5 100644 --- a/seaweed-block/core/storage/wal_io_v3.go +++ b/seaweed-block/core/storage/wal_io_v3.go @@ -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 { diff --git a/seaweed-block/core/storage/wal_io_v3_test.go b/seaweed-block/core/storage/wal_io_v3_test.go index 025bf27098..e52c06bffc 100644 --- a/seaweed-block/core/storage/wal_io_v3_test.go +++ b/seaweed-block/core/storage/wal_io_v3_test.go @@ -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) + } +}