From 88cfb04f71b6890332502cb42b0380b08655ee6a Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 19 Nov 2026 00:50:33 -0800 Subject: [PATCH 1/8] test: expose checkpoint persistence refusals and successes --- .../durable/checkpoint_status_test.go | 62 +++++++++++++++++++ .../storage/checkpoint_diagnostics_test.go | 51 +++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 seaweed-block/core/frontend/durable/checkpoint_status_test.go create mode 100644 seaweed-block/core/storage/checkpoint_diagnostics_test.go diff --git a/seaweed-block/core/frontend/durable/checkpoint_status_test.go b/seaweed-block/core/frontend/durable/checkpoint_status_test.go new file mode 100644 index 0000000000..7b46ce5f64 --- /dev/null +++ b/seaweed-block/core/frontend/durable/checkpoint_status_test.go @@ -0,0 +1,62 @@ +package durable_test + +import ( + "context" + "encoding/json" + "testing" + "time" + + "github.com/seaweedfs/seaweed-block/core/frontend/durable" + "github.com/seaweedfs/seaweed-block/core/storage" +) + +func TestDurableProvider_CheckpointPersistenceStatus(t *testing.T) { + remote := storage.NewMemChunkRemote() + p, err := durable.NewDurableProvider(durable.ProviderConfig{ + Impl: durable.ImplWALStoreChunk, StorageRoot: t.TempDir(), BlockSize: 4096, + NumBlocks: 64, ChunkBlocks: 4, ChunkCaptureInterval: 0, + ChunkRemoteFor: func(string) (storage.ChunkRemote, error) { return remote, nil }, + }, v1View()) + if err != nil { + t.Fatal(err) + } + t.Cleanup(func() { p.Close() }) + if _, err := p.RecoverVolume(context.Background(), "v1"); err != nil { + t.Fatal(err) + } + be, err := p.Open(context.Background(), "v1") + if err != nil { + t.Fatal(err) + } + if _, err := be.Write(context.Background(), 0, make([]byte, 4096)); err != nil { + t.Fatal(err) + } + if err := be.Sync(context.Background()); err != nil { + t.Fatal(err) + } + deadline := time.Now().Add(5 * time.Second) + for { + statuses := p.DurableStatuses() + raw, err := json.Marshal(statuses) + if err != nil { + t.Fatal(err) + } + var wire []struct { + CheckpointPersistence *struct { + Successes uint64 + Refusals uint64 + Failures uint64 + } + } + if err := json.Unmarshal(raw, &wire); err != nil { + t.Fatal(err) + } + if len(wire) == 1 && wire[0].CheckpointPersistence != nil && wire[0].CheckpointPersistence.Successes > 0 { + return + } + if time.Now().After(deadline) { + t.Fatalf("no checkpoint persist status in durable response: %s", raw) + } + time.Sleep(10 * time.Millisecond) + } +} diff --git a/seaweed-block/core/storage/checkpoint_diagnostics_test.go b/seaweed-block/core/storage/checkpoint_diagnostics_test.go new file mode 100644 index 0000000000..d811d47dde --- /dev/null +++ b/seaweed-block/core/storage/checkpoint_diagnostics_test.go @@ -0,0 +1,51 @@ +package storage + +import ( + "encoding/json" + "errors" + "strings" + "testing" +) + +func TestCheckpointDiagnostics_RefusalThenSuccess(t *testing.T) { + s, _ := newMappedCheckpointStoreV3(t) + writeSynced(t, s, 1, 1) + s.v3.testMapPrepared = func() { + if _, err := s.Write(2, blk(2)); err != nil { + t.Fatal(err) + } + } + before := s.v3.pub.current() + err := s.flusher.flushOnce() + if !errors.Is(err, ErrMapCoverageStale) { + t.Fatalf("refusal: %v", err) + } + if !strings.Contains(err.Error(), "proof_changed") { + t.Errorf("missing refusal reason: %v", err) + } + if s.v3.pub.current() != before || s.dm.len() != 2 || s.stickyIOFault() != nil { + t.Fatal("refusal changed publication/retry/fault state") + } + raw, _ := json.Marshal(s.FlusherInstrumentation()) + var counts map[string]uint64 + if err := json.Unmarshal(raw, &counts); err != nil { + t.Fatal(err) + } + if counts["CheckpointRefusals"] != 1 || counts["CheckpointSuccesses"] != 0 { + t.Fatalf("refusal counters: %s", raw) + } + s.v3.testMapPrepared = nil + if _, err := s.Sync(); err != nil { + t.Fatal(err) + } + if err := s.flusher.flushOnce(); err != nil { + t.Fatal(err) + } + raw, _ = json.Marshal(s.FlusherInstrumentation()) + if err := json.Unmarshal(raw, &counts); err != nil { + t.Fatal(err) + } + if counts["CheckpointRefusals"] != 1 || counts["CheckpointSuccesses"] != 1 || s.CheckpointLSN() != 2 || s.dm.len() != 0 { + t.Fatalf("retry counters/state: %s cp=%d", raw, s.CheckpointLSN()) + } +} From 751fe4ad0e9fb3ce26a7801edbcf89a31fd2e27f Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 19 Nov 2026 00:52:26 -0800 Subject: [PATCH 2/8] storage: report checkpoint retry reasons and cumulative outcomes --- .../durable/checkpoint_status_test.go | 3 + .../core/frontend/durable/provider.go | 31 ++++----- .../core/frontend/durable/storage_adapter.go | 42 +++++++----- .../core/storage/checkpoint_diagnostics.go | 64 ++++++++++++++++++ .../storage/checkpoint_diagnostics_test.go | 67 +++++++++++++++++++ .../core/storage/chunk_map_publication_v3.go | 20 +++--- seaweed-block/core/storage/flusher.go | 9 +-- .../core/storage/flusher_instrumentation.go | 9 +++ .../storage/walstore_map_checkpoint_v3.go | 10 +-- 9 files changed, 204 insertions(+), 51 deletions(-) create mode 100644 seaweed-block/core/storage/checkpoint_diagnostics.go diff --git a/seaweed-block/core/frontend/durable/checkpoint_status_test.go b/seaweed-block/core/frontend/durable/checkpoint_status_test.go index 7b46ce5f64..b3ad4cb9ce 100644 --- a/seaweed-block/core/frontend/durable/checkpoint_status_test.go +++ b/seaweed-block/core/frontend/durable/checkpoint_status_test.go @@ -21,6 +21,9 @@ func TestDurableProvider_CheckpointPersistenceStatus(t *testing.T) { t.Fatal(err) } t.Cleanup(func() { p.Close() }) + if _, err := p.EnsureStorage("v1"); err != nil { + t.Fatal(err) + } if _, err := p.RecoverVolume(context.Background(), "v1"); err != nil { t.Fatal(err) } diff --git a/seaweed-block/core/frontend/durable/provider.go b/seaweed-block/core/frontend/durable/provider.go index 2e89b88c45..2fa5faf8bb 100644 --- a/seaweed-block/core/frontend/durable/provider.go +++ b/seaweed-block/core/frontend/durable/provider.go @@ -253,21 +253,22 @@ type volHandle struct { // handle. It intentionally exposes lineage and readiness facts without giving // callers a control surface. type VolumeStatus struct { - VolumeID string - Path string - Impl string - ReplicaID string - Epoch uint64 - EndpointVersion uint64 - Latched bool - Operational bool - FrontierKnown bool - DurableLSN uint64 - RetainedLSN uint64 - HeadLSN uint64 - Evidence string - Closed bool - WriteProfile WriteProfileStatus + VolumeID string + Path string + Impl string + ReplicaID string + Epoch uint64 + EndpointVersion uint64 + Latched bool + Operational bool + FrontierKnown bool + DurableLSN uint64 + RetainedLSN uint64 + HeadLSN uint64 + Evidence string + Closed bool + WriteProfile WriteProfileStatus + CheckpointPersistence *storage.CheckpointPersistenceStatus `json:",omitempty"` // Chunk is the chunk layer's state and cut counters; walstore-chunk // volumes only. Chunk *ChunkStatus diff --git a/seaweed-block/core/frontend/durable/storage_adapter.go b/seaweed-block/core/frontend/durable/storage_adapter.go index 69b2b7ad8a..c7ec6169e9 100644 --- a/seaweed-block/core/frontend/durable/storage_adapter.go +++ b/seaweed-block/core/frontend/durable/storage_adapter.go @@ -288,6 +288,13 @@ func (b *StorageBackend) durableStatus(volumeID, path, impl string) VolumeStatus if c, ok := b.storage.(interface{ HolesSuspected() uint64 }); ok { holes = c.HolesSuspected() } + var checkpoint *storage.CheckpointPersistenceStatus + if reporter, ok := b.storage.(interface { + CheckpointPersistence() storage.CheckpointPersistenceStatus + }); ok { + snapshot := reporter.CheckpointPersistence() + checkpoint = &snapshot + } writeProfile := b.WriteProfile() if instrumented, ok := b.storage.(storage.WriteInstrumented); ok { storageProfile := instrumented.WriteInstrumentation() @@ -316,23 +323,24 @@ func (b *StorageBackend) durableStatus(volumeID, path, impl string) VolumeStatus writeProfile.DirtyMapUpdateDurationNanos = storageProfile.DirtyMapUpdateDurationNanos } return VolumeStatus{ - Warnings: warnings, - HolesSuspected: holes, - VolumeID: volumeID, - Path: path, - Impl: impl, - ReplicaID: id.ReplicaID, - Epoch: id.Epoch, - EndpointVersion: id.EndpointVersion, - Latched: id.Epoch > 0 && id.EndpointVersion > 0, - Operational: b.operational.Load(), - FrontierKnown: true, - DurableLSN: durableLSN, - RetainedLSN: retainedLSN, - HeadLSN: headLSN, - Evidence: evidence, - Closed: closed, - WriteProfile: writeProfile, + Warnings: warnings, + HolesSuspected: holes, + VolumeID: volumeID, + Path: path, + Impl: impl, + ReplicaID: id.ReplicaID, + Epoch: id.Epoch, + EndpointVersion: id.EndpointVersion, + Latched: id.Epoch > 0 && id.EndpointVersion > 0, + Operational: b.operational.Load(), + FrontierKnown: true, + DurableLSN: durableLSN, + RetainedLSN: retainedLSN, + HeadLSN: headLSN, + Evidence: evidence, + Closed: closed, + WriteProfile: writeProfile, + CheckpointPersistence: checkpoint, } } diff --git a/seaweed-block/core/storage/checkpoint_diagnostics.go b/seaweed-block/core/storage/checkpoint_diagnostics.go new file mode 100644 index 0000000000..2fc3fd3af5 --- /dev/null +++ b/seaweed-block/core/storage/checkpoint_diagnostics.go @@ -0,0 +1,64 @@ +package storage + +import ( + "errors" + "log" + "time" +) + +// CheckpointPersistenceStatus counts flusher checkpoint calls in this open. +// Success includes a safely clamped/unchanged checkpoint; it is not a slot-write +// count. Fields are cumulative atomic observations, not a coherent frontier. +type CheckpointPersistenceStatus struct { + Successes uint64 + Refusals uint64 + Failures uint64 +} + +func (s *WALStore) CheckpointPersistence() CheckpointPersistenceStatus { + if s.flusher == nil { + return CheckpointPersistenceStatus{} + } + i := &s.flusher.instr + return CheckpointPersistenceStatus{i.checkpointSuccesses.Load(), i.checkpointRefusals.Load(), i.checkpointFailures.Load()} +} + +func (i *flusherInstrumentation) recordCheckpoint(err error) { + switch { + case err == nil: + i.checkpointSuccesses.Add(1) + case errors.Is(err, ErrMapCoverageStale): + i.checkpointRefusals.Add(1) + default: + i.checkpointFailures.Add(1) + } +} + +type mapCoverageRefusal string + +func (r mapCoverageRefusal) Error() string { return ErrMapCoverageStale.Error() + ": " + string(r) } +func (r mapCoverageRefusal) Unwrap() error { return ErrMapCoverageStale } + +// Owned exclusively by the flusher run loop; no storage lock or I/O ordering +// changes. Terminal errors are never rate limited. +type checkpointLogLimiter struct { + last time.Time + suppressed uint64 +} + +func (l *checkpointLogLimiter) report(err error, now time.Time) { + if !errors.Is(err, ErrMapCoverageStale) { + log.Printf("storage: flusher: %v", err) + return + } + if !l.last.IsZero() && now.Sub(l.last) < 30*time.Second { + l.suppressed++ + return + } + var reason mapCoverageRefusal + if !errors.As(err, &reason) { + reason = "unspecified" + } + log.Printf("storage: flusher: checkpoint deferred reason=%s suppressed=%d: %v", reason, l.suppressed, err) + l.last, l.suppressed = now, 0 +} diff --git a/seaweed-block/core/storage/checkpoint_diagnostics_test.go b/seaweed-block/core/storage/checkpoint_diagnostics_test.go index d811d47dde..2670beb977 100644 --- a/seaweed-block/core/storage/checkpoint_diagnostics_test.go +++ b/seaweed-block/core/storage/checkpoint_diagnostics_test.go @@ -1,14 +1,19 @@ package storage import ( + "bytes" "encoding/json" "errors" + "fmt" + "log" "strings" "testing" + "time" ) func TestCheckpointDiagnostics_RefusalThenSuccess(t *testing.T) { s, _ := newMappedCheckpointStoreV3(t) + mustAttach(t, s, newFakeChunkRemote(), ctConfig(1)) writeSynced(t, s, 1, 1) s.v3.testMapPrepared = func() { if _, err := s.Write(2, blk(2)); err != nil { @@ -49,3 +54,65 @@ func TestCheckpointDiagnostics_RefusalThenSuccess(t *testing.T) { t.Fatalf("retry counters/state: %s cp=%d", raw, s.CheckpointLSN()) } } + +func TestCheckpointDiagnostics_PrepareRefusalAndIOFailure(t *testing.T) { + for _, fault := range []bool{false, true} { + t.Run(fmt.Sprint(fault), func(t *testing.T) { + s, _ := newMappedCheckpointStoreV3(t) + mustAttach(t, s, newFakeChunkRemote(), ctConfig(1)) + writeSynced(t, s, 1, 1) + realSync := s.v3.ownedMap.syncFile + injected := errors.New("checkpoint map fsync fault") + once := false + s.v3.ownedMap.syncFile = func() error { + if fault { + return injected + } + if !once { + once = true + if _, err := s.Write(2, blk(2)); err != nil { + t.Fatal(err) + } + } + return realSync() + } + err := s.flusher.flushOnce() + got := s.CheckpointPersistence() + if fault { + if !errors.Is(err, injected) || got.Failures != 1 || got.Refusals != 0 || s.stickyIOFault() == nil { + t.Fatalf("fault %v counts=%+v", err, got) + } + } else { + if !errors.Is(err, ErrMapCoverageStale) || !strings.Contains(err.Error(), "proof_changed_during_prepare") || got.Refusals != 1 || got.Failures != 0 || s.stickyIOFault() != nil { + t.Fatalf("refusal %v counts=%+v", err, got) + } + } + if got.Successes != 0 || s.CheckpointLSN() != 0 || s.dm.len() == 0 { + t.Fatal("failed checkpoint advanced or lost retry ownership") + } + }) + } +} + +func TestCheckpointDiagnostics_LogRateLimit(t *testing.T) { + var out bytes.Buffer + old := log.Writer() + log.SetOutput(&out) + t.Cleanup(func() { log.SetOutput(old) }) + var limiter checkpointLogLimiter + now := time.Unix(100, 0) + stale := fmt.Errorf("persist checkpoint: %w", mapCoverageRefusal("proof_changed")) + limiter.report(stale, now) + for i := 0; i < 5; i++ { + limiter.report(stale, now.Add(time.Second)) + } + // A terminal failure must remain visible while refusals are suppressed. + terminal := errors.New("real fsync fault") + limiter.report(terminal, now.Add(2*time.Second)) + limiter.report(terminal, now.Add(3*time.Second)) + limiter.report(stale, now.Add(30*time.Second)) + got := out.String() + if strings.Count(got, "checkpoint deferred") != 2 || strings.Count(got, "real fsync fault") != 2 || !strings.Contains(got, "reason=proof_changed suppressed=5") { + t.Fatalf("logs: %s", got) + } +} diff --git a/seaweed-block/core/storage/chunk_map_publication_v3.go b/seaweed-block/core/storage/chunk_map_publication_v3.go index 8869949475..2ef10237b2 100644 --- a/seaweed-block/core/storage/chunk_map_publication_v3.go +++ b/seaweed-block/core/storage/chunk_map_publication_v3.go @@ -57,7 +57,7 @@ type preparedMapPublicationV3 struct { // Preparation takes the sidecar mutex and I/O only, before store/desc locks. func prepareMapPublicationV3(m *chunkLSNMapV3, d *mapProofEpochV3, g, C uint64, entries []chunkLSNEntryV3, prior *chunkMapCandidateV3) (*preparedMapPublicationV3, error) { if m == nil || d == nil { - return nil, ErrMapCoverageStale + return nil, mapCoverageRefusal("map_binding_missing") } proof := d.snapshotV3() c, e := m.Prepare(g, C, entries, prior) @@ -66,7 +66,7 @@ func prepareMapPublicationV3(m *chunkLSNMapV3, d *mapProofEpochV3, g, C uint64, } if !proof.validV3(d) { m.abandonCandidateV3(c) // prepared but never publishable - return nil, ErrMapCoverageStale + return nil, mapCoverageRefusal("proof_changed_during_prepare") } return &preparedMapPublicationV3{candidate: c, proof: proof}, nil } @@ -84,13 +84,13 @@ func sameMapTupleV3(d descriptorV3, c *chunkMapCandidateV3) bool { // even when none of its pages belong to the selected generation. func (p *descriptorPublisherV3) bindMapV3(c *chunkMapCandidateV3, d *mapProofEpochV3) error { if c == nil || c.owner == nil || d == nil { - return ErrMapCoverageStale + return mapCoverageRefusal("map_binding_missing") } p.descMu.Lock() current, other, otherValid := p.cur, p.other, p.otherValid p.descMu.Unlock() if !sameMapTupleV3(current, c) { - return ErrMapCoverageStale + return mapCoverageRefusal("map_tuple_changed") } if _, _, e := readChunkLSNMapV3(c.owner.fd, current, c.owner.chunkBlocks); e != nil { return e @@ -106,7 +106,7 @@ func (p *descriptorPublisherV3) bindMapV3(c *chunkMapCandidateV3, d *mapProofEpo p.descMu.Lock() defer p.descMu.Unlock() if p.cur != current || p.otherValid != otherValid || (otherValid && p.other != other) { - return ErrMapCoverageStale + return mapCoverageRefusal("descriptor_changed_during_bind") } p.mapCurrent = c p.mapDomain = d @@ -115,7 +115,7 @@ func (p *descriptorPublisherV3) bindMapV3(c *chunkMapCandidateV3, d *mapProofEpo func (p *descriptorPublisherV3) validateMapPublicationV3(next descriptorV3, prepared *preparedMapPublicationV3) error { if p.mapCurrent == nil { if prepared != nil { - return ErrMapCoverageStale + return mapCoverageRefusal("map_not_bound") } return nil } // dark core not bound yet @@ -123,20 +123,20 @@ func (p *descriptorPublisherV3) validateMapPublicationV3(next descriptorV3, prep if prepared != nil { c = prepared.candidate if c == nil || c.owner != p.mapCurrent.owner || !prepared.proof.validV3(p.mapDomain) { - return ErrMapCoverageStale + return mapCoverageRefusal("proof_changed") } if c.generation <= p.mapCurrent.generation || c.covered < p.mapCurrent.covered { - return ErrMapCoverageStale + return mapCoverageRefusal("candidate_superseded") } } if !sameMapTupleV3(next, c) || c.covered < next.CheckpointLSN || c.covered > next.W { - return ErrMapCoverageStale + return mapCoverageRefusal("map_coverage_mismatch") } return nil } func (p *descriptorPublisherV3) publishMapV3(storeMu sync.Locker, snap func(), prepared *preparedMapPublicationV3, mutate func(*descriptorV3) error) (descriptorV3, error) { if prepared == nil || prepared.candidate == nil { - return descriptorV3{}, ErrMapCoverageStale + return descriptorV3{}, mapCoverageRefusal("candidate_missing") } d, err := p.publishWithMapV3(storeMu, snap, func(d *descriptorV3) error { if mutate != nil { diff --git a/seaweed-block/core/storage/flusher.go b/seaweed-block/core/storage/flusher.go index 6d52d7bf24..930e057a89 100644 --- a/seaweed-block/core/storage/flusher.go +++ b/seaweed-block/core/storage/flusher.go @@ -3,7 +3,6 @@ package storage import ( "encoding/binary" "fmt" - "log" "sort" "sync" "sync/atomic" @@ -111,6 +110,7 @@ func (f *flusher) runWithStartSignal(started chan<- struct{}) { if started != nil { close(started) } + var diagnostics checkpointLogLimiter for { select { case <-f.stopCh: @@ -120,11 +120,11 @@ func (f *flusher) runWithStartSignal(started chan<- struct{}) { return case <-ticker.C: if err := f.flushOnce(); err != nil { - log.Printf("storage: flusher: %v", err) + diagnostics.report(err, time.Now()) } case <-f.notifyCh: if err := f.flushOnce(); err != nil { - log.Printf("storage: flusher (notify): %v", err) + diagnostics.report(err, time.Now()) } } } @@ -283,6 +283,7 @@ func (f *flusher) flushOnceInternal(allowClosed bool) (err error) { } else { publishErr = store.persistCheckpointAndRelease(maxLSN, maxLSNPhys, maxLSNEntrySize) } + f.instr.recordCheckpoint(publishErr) if err := publishErr; err != nil { return fmt.Errorf("flusher: persist checkpoint %d: %w", maxLSN, err) } @@ -313,7 +314,7 @@ func (f *flusher) flushOnceInternal(allowClosed bool) (err error) { store.mu.Lock() if !store.v3.flushLifetimeValidV3(recoveryGen) { store.mu.Unlock() - return ErrMapCoverageStale + return mapCoverageRefusal("recovery_lifetime_changed") } checkpoint = store.checkpointLSN if checkpoint >= maxLSN && maxLSN+1 > store.walTail { diff --git a/seaweed-block/core/storage/flusher_instrumentation.go b/seaweed-block/core/storage/flusher_instrumentation.go index 3d7cf587fb..ec3fcf1827 100644 --- a/seaweed-block/core/storage/flusher_instrumentation.go +++ b/seaweed-block/core/storage/flusher_instrumentation.go @@ -12,6 +12,9 @@ const maxCheckpointWriteBytes = 1 << 20 // checkpoint work. Operation counters include failed attempts; byte counters // include only successful writes. type FlusherInstrumentationStatus struct { + CheckpointSuccesses uint64 + CheckpointRefusals uint64 + CheckpointFailures uint64 CyclesStarted uint64 CyclesSucceeded uint64 CyclesFailed uint64 @@ -63,6 +66,9 @@ type FlusherInstrumentationStatus struct { } type flusherInstrumentation struct { + checkpointSuccesses atomic.Uint64 + checkpointRefusals atomic.Uint64 + checkpointFailures atomic.Uint64 cyclesStarted atomic.Uint64 cyclesSucceeded atomic.Uint64 cyclesFailed atomic.Uint64 @@ -284,6 +290,9 @@ func updateAtomicMax(target *atomic.Uint64, value uint64) { func (i *flusherInstrumentation) snapshot() FlusherInstrumentationStatus { return FlusherInstrumentationStatus{ + CheckpointSuccesses: i.checkpointSuccesses.Load(), + CheckpointRefusals: i.checkpointRefusals.Load(), + CheckpointFailures: i.checkpointFailures.Load(), CyclesStarted: i.cyclesStarted.Load(), CyclesSucceeded: i.cyclesSucceeded.Load(), CyclesFailed: i.cyclesFailed.Load(), diff --git a/seaweed-block/core/storage/walstore_map_checkpoint_v3.go b/seaweed-block/core/storage/walstore_map_checkpoint_v3.go index 029d0ba210..c8273bb740 100644 --- a/seaweed-block/core/storage/walstore_map_checkpoint_v3.go +++ b/seaweed-block/core/storage/walstore_map_checkpoint_v3.go @@ -33,7 +33,7 @@ func (s *WALStore) prepareOwnedMapCheckpointV3(cp uint64) (*preparedMapPublicati if prior == nil || prior.owner != v.ownedMap || domain != v.mapProof { v.pub.descMu.Unlock() s.mu.RUnlock() - return nil, ErrMapCoverageStale + return nil, mapCoverageRefusal("map_binding_changed") } proof := domain.snapshotV3() entries := append([]chunkLSNEntryV3(nil), v.mapEntries...) @@ -45,7 +45,7 @@ func (s *WALStore) prepareOwnedMapCheckpointV3(cp uint64) (*preparedMapPublicati } if !proof.validV3(domain) { v.ownedMap.abandonCandidateV3(c) // prepared but never publishable - return nil, ErrMapCoverageStale + return nil, mapCoverageRefusal("proof_changed_during_prepare") } return &preparedMapPublicationV3{candidate: c, proof: proof}, nil } @@ -70,7 +70,7 @@ func (s *WALStore) persistOwnedMapCheckpointV3(highestLSN, recoveryGen uint64) e s.mu.Lock() defer s.mu.Unlock() if !v.flushLifetimeValidV3(recoveryGen) { - return ErrMapCoverageStale + return mapCoverageRefusal("recovery_lifetime_changed") } return s.rolloverCheckpointV3Locked() } @@ -118,7 +118,7 @@ func (s *WALStore) publishCheckpointV3(cp uint64, seed bool, recoveryGen uint64) // I/O and could belong to a newer Recover lifetime than those bytes. if !v.flushLifetimeValidV3(recoveryGen) { prepared.abandonV3() - return descriptorV3{}, ErrMapCoverageStale + return descriptorV3{}, mapCoverageRefusal("recovery_lifetime_changed") } wack := v.wack.Load() if seed { @@ -126,7 +126,7 @@ func (s *WALStore) publishCheckpointV3(cp uint64, seed bool, recoveryGen uint64) } if wack < cp { prepared.abandonV3() - return descriptorV3{}, ErrMapCoverageStale + return descriptorV3{}, mapCoverageRefusal("checkpoint_above_wack") } s.mu.RLock() retention := s.recoveryRetentionLSNs From a1209b2d90957e9038a3819a9f871d9151fe7006 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 19 Nov 2026 00:53:32 -0800 Subject: [PATCH 3/8] storage: print the stable checkpoint refusal reason --- seaweed-block/core/storage/checkpoint_diagnostics.go | 2 +- seaweed-block/docs/design/invariants.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/seaweed-block/core/storage/checkpoint_diagnostics.go b/seaweed-block/core/storage/checkpoint_diagnostics.go index 2fc3fd3af5..46aa71e185 100644 --- a/seaweed-block/core/storage/checkpoint_diagnostics.go +++ b/seaweed-block/core/storage/checkpoint_diagnostics.go @@ -59,6 +59,6 @@ func (l *checkpointLogLimiter) report(err error, now time.Time) { if !errors.As(err, &reason) { reason = "unspecified" } - log.Printf("storage: flusher: checkpoint deferred reason=%s suppressed=%d: %v", reason, l.suppressed, err) + log.Printf("storage: flusher: checkpoint deferred reason=%s suppressed=%d: %v", string(reason), l.suppressed, err) l.last, l.suppressed = now, 0 } diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index f310af1eea..80bd9fb7df 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -63,7 +63,7 @@ stateDiagram-v2 | FaultLatched | FaultLatched | every later `Sync`, write, checkpoint and `Recover` on the same open store is refused | `core/storage/walstore.go` `stickyIOFault` | `INV-WAL-FSYNC-STICKY-001` | | any | Closed | `Close`; a store with a latched fault does not write the final superblock | `core/storage/walstore.go` `WALStore.Close` | — | -Production C11 file persistence was removed in row 14b: the durable provider no longer constructs a bitmap sidecar, and the historical file codec exists only in `legacy_c11_file_fixture_test.go`. `INV-CUT-BITMAP-001` retains its explicit legacy engine tests until row 14a; it does not certify the v3 disk format. Native checkpoint/capture coverage is `TestWALStoreV3_AutomaticMapCheckpoint`, `TestChunkLayerV3_CaptureUsesOwnedMapAfterCheckpoint`, and `TestChunkLayer_OwnedMapIncrementalAfterRestart` (checkpointed and WAL-only changes survive reopen without a C11 sidecar). The production map publication/coverage rules remain `INV-WAL-V3-MAP-PUBLISH-001`; no descriptor transition, format or durability boundary changes here. The receiver session bitmap (`INV-RECV-BITMAP-CORE`) is separate and unchanged. +Production C11 file persistence was removed in row 14b: the durable provider no longer constructs a bitmap sidecar, and the historical file codec exists only in `legacy_c11_file_fixture_test.go`. `INV-CUT-BITMAP-001` retains its explicit legacy engine tests until row 14a; it does not certify the v3 disk format. Native checkpoint/capture coverage is `TestCheckpointDiagnostics_RefusalThenSuccess`, `TestCheckpointDiagnostics_PrepareRefusalAndIOFailure`, `TestWALStoreV3_AutomaticMapCheckpoint`, `TestChunkLayerV3_CaptureUsesOwnedMapAfterCheckpoint`, and `TestChunkLayer_OwnedMapIncrementalAfterRestart` (checkpointed and WAL-only changes survive reopen without a C11 sidecar). The production map publication/coverage rules remain `INV-WAL-V3-MAP-PUBLISH-001`; no descriptor transition, format or durability boundary changes here. The receiver session bitmap (`INV-RECV-BITMAP-CORE`) is separate and unchanged. Public walstore Create now selects mapped format v3/impl3 (mode C by default, mode A by create option). Open and offline readonly use A/B slot and owned-map validation; valid legacy formats are refused with `ErrUnsupportedLegacyFormat`, rather than silently retrofitted. The temporary old-engine/raw-codec test scope and every named native replacement are recorded in [the legacy inventory](format-v3-legacy-test-inventory.md). Native recovery validates nonce/cursor binding and a contiguous physical LSN prefix before applying the mode-specific W rule; an acknowledged-range integrity failure blocks startup. The provider's create geometry, auto probe, capture, HEAD restore and readonly/status controls exercise the public selector (`INV-WAL-V3-ACTIVATION-001`). Before reading v3 slots, both read/write and offline read-only open acquire an exclusive nonblocking file lock; the offline migration CLI acquires the same lock before any descriptor read or mutation (`INV-WAL-V3-OWNER-001`). Contention refuses open/migration without changing bytes; descriptor close or process exit releases ownership. This implements the existing offline-migration precondition, not a new serving state. The mapped v3 checkpoint also carries a complete-record physical tail through the covered LSN minus the configured retention window; partial batches remain retained. The existing sole publisher then performs metadata-only rollover when the fallback still pins that prefix. Reuse still requires both valid same-nonce slot tails and retirement of checkpointed dirty references under writer exclusion; idle, unchanged-checkpoint and admission paths also settle a pinned fallback. An unlocked catch-up scan revalidates the coherent checkpoint and tail before emitting anything. A failed rollover latches and grants no reuse (`INV-WAL-V3-RECLAIM-001`). From 2ed15f2c03dc88f8c4a692224ced6fdfd60cdfe1 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 19 Nov 2026 00:54:29 -0800 Subject: [PATCH 4/8] storage: distinguish recovery and map generation refusals --- .../core/host/volume/status_server_test.go | 24 ++++++++++++------- seaweed-block/core/storage/descriptor_v3.go | 2 +- seaweed-block/core/storage/walstore_v3.go | 4 ++-- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/seaweed-block/core/host/volume/status_server_test.go b/seaweed-block/core/host/volume/status_server_test.go index 50fffb65d1..cbdf18d3eb 100644 --- a/seaweed-block/core/host/volume/status_server_test.go +++ b/seaweed-block/core/host/volume/status_server_test.go @@ -7,6 +7,7 @@ import ( "bytes" "context" "encoding/json" + "github.com/seaweedfs/seaweed-block/core/storage" "net/http" "net/http/httptest" "strings" @@ -981,15 +982,16 @@ func TestStatusServer_DurableStatusEndpoint_EnabledAfterStart_ReturnsLineage(t * } defer func() { _ = s.Close(context.Background()) }() s.SetDurableStatusSource(stubDurableStatusSource{vols: []durable.VolumeStatus{{ - VolumeID: "v1", - Path: "/tmp/v1.bin", - Impl: "smartwal", - ReplicaID: "r1", - Epoch: 1, - EndpointVersion: 1, - Latched: true, - Operational: true, - Evidence: "recovered LSN=0", + VolumeID: "v1", + Path: "/tmp/v1.bin", + Impl: "smartwal", + ReplicaID: "r1", + Epoch: 1, + EndpointVersion: 1, + Latched: true, + Operational: true, + Evidence: "recovered LSN=0", + CheckpointPersistence: &storage.CheckpointPersistenceStatus{Successes: 3, Refusals: 2, Failures: 1}, }}}) resp, err := http.Get("http://" + addr + "/status/durable?volume=v1") @@ -1015,6 +1017,10 @@ func TestStatusServer_DurableStatusEndpoint_EnabledAfterStart_ReturnsLineage(t * if len(body.Volumes) != 1 || !body.Volumes[0].Latched || !body.Volumes[0].Operational || body.Volumes[0].Epoch != 1 { t.Fatalf("unexpected durable volume body: %+v", body.Volumes) } + checkpoint := body.Volumes[0].CheckpointPersistence + if checkpoint == nil || checkpoint.Successes != 3 || checkpoint.Refusals != 2 || checkpoint.Failures != 1 { + t.Fatalf("checkpoint counters missing from HTTP response: %+v", checkpoint) + } } func TestG9B_StatusProjection_ReturnedReplicaCanBeDurableReadyButFrontendNotReady(t *testing.T) { diff --git a/seaweed-block/core/storage/descriptor_v3.go b/seaweed-block/core/storage/descriptor_v3.go index 1300ef199a..62310d03a4 100644 --- a/seaweed-block/core/storage/descriptor_v3.go +++ b/seaweed-block/core/storage/descriptor_v3.go @@ -332,7 +332,7 @@ func mergeDescriptorV3Mode(cur, next *descriptorV3, reset bool) error { next.MapLineage != cur.MapLineage || next.MapFormatID != cur.MapFormatID { if next.MapGeneration <= cur.MapGeneration { return fmt.Errorf("%w: %w: map root change without a higher generation (%d -> %d)", - ErrMapCoverageStale, errDescriptorTransition, cur.MapGeneration, next.MapGeneration) + mapCoverageRefusal("map_generation_not_increasing"), errDescriptorTransition, cur.MapGeneration, next.MapGeneration) } if next.MapLineage != cur.MapLineage { return fmt.Errorf("%w: map lineage change outside an install or reset", errDescriptorTransition) diff --git a/seaweed-block/core/storage/walstore_v3.go b/seaweed-block/core/storage/walstore_v3.go index 7cd2bd4045..a4d2542241 100644 --- a/seaweed-block/core/storage/walstore_v3.go +++ b/seaweed-block/core/storage/walstore_v3.go @@ -1111,7 +1111,7 @@ func (f *flusher) readDirtyRecordV3Cached(e snapshotEntry, cache *flushRecordCac store := f.store d := store.v3.pub.current() if cache != nil && !store.v3.flushLifetimeValidV3(cache.recoveryGen) { - return nil, 0, ErrMapCoverageStale + return nil, 0, mapCoverageRefusal("recovery_lifetime_changed") } var entry walEntryV3 var size uint64 @@ -1180,7 +1180,7 @@ func (s *WALStore) persistCheckpointV3(highestLSN, recoveryGen uint64) error { v.syncMu.Lock() defer v.syncMu.Unlock() if !v.flushLifetimeValidV3(recoveryGen) { - return ErrMapCoverageStale + return mapCoverageRefusal("recovery_lifetime_changed") } wack := v.wack.Load() if wack < checkpoint { From 8674d46b6daf43aaea8980cb0680415487266128 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 19 Nov 2026 09:41:07 -0800 Subject: [PATCH 5/8] test: retain bounded stale-prepare checks with typed refusal reasons --- seaweed-block/core/storage/chunk_map_extents_v3_test.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/seaweed-block/core/storage/chunk_map_extents_v3_test.go b/seaweed-block/core/storage/chunk_map_extents_v3_test.go index 72cf43e1af..ed343e1a35 100644 --- a/seaweed-block/core/storage/chunk_map_extents_v3_test.go +++ b/seaweed-block/core/storage/chunk_map_extents_v3_test.go @@ -1,6 +1,7 @@ package storage import ( + "errors" "os" "path/filepath" "testing" @@ -430,7 +431,9 @@ func TestChunkMapExtentsV3ProofStalePreparesStayBounded(t *testing.T) { } cp := s.v3.pub.current().CheckpointLSN for i := 0; i < 150; i++ { - if _, err := s.prepareOwnedMapCheckpointV3(cp); err != ErrMapCoverageStale { + _, err := s.prepareOwnedMapCheckpointV3(cp) + var reason mapCoverageRefusal + if !errors.Is(err, ErrMapCoverageStale) || !errors.As(err, &reason) || reason != "proof_changed_during_prepare" { t.Fatalf("checkpoint prepare %d: err = %v, want ErrMapCoverageStale", i, err) } } @@ -438,7 +441,9 @@ func TestChunkMapExtentsV3ProofStalePreparesStayBounded(t *testing.T) { for i := 0; i < 150; i++ { g += 1000 entries := append([]chunkLSNEntryV3(nil), s.v3.mapEntries...) - if _, err := prepareMapPublicationV3(m, s.v3.mapProof, g, cp, entries, nil); err != ErrMapCoverageStale { + _, err := prepareMapPublicationV3(m, s.v3.mapProof, g, cp, entries, nil) + var reason mapCoverageRefusal + if !errors.Is(err, ErrMapCoverageStale) || !errors.As(err, &reason) || reason != "proof_changed_during_prepare" { t.Fatalf("publication prepare %d: err = %v, want ErrMapCoverageStale", i, err) } } From a31c73f1387eed92b2ee507d4d5abd27741c41ab Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 19 Nov 2026 09:43:37 -0800 Subject: [PATCH 6/8] style: align the v3 test hooks after budget integration --- seaweed-block/core/storage/walstore_v3.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seaweed-block/core/storage/walstore_v3.go b/seaweed-block/core/storage/walstore_v3.go index a4d2542241..95b44551c3 100644 --- a/seaweed-block/core/storage/walstore_v3.go +++ b/seaweed-block/core/storage/walstore_v3.go @@ -84,7 +84,7 @@ type walStoreV3State struct { // testAfterRollover runs in a v3 write after the checkpoint rollover and // before the payload append (write-command budget, #252). testAfterRollover func() - testMapPrepared func() // outside all publication locks, after owned-map persistence + testMapPrepared func() // outside all publication locks, after owned-map persistence // testReadResolved runs in a v3 read after the dirty map resolved the // LBA's WAL position and before the record is read. testReadResolved func() From a2deedc49a1508f2c5489dee156ff84f7d50e531 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 19 Nov 2026 10:26:54 -0800 Subject: [PATCH 7/8] storage: report the persisted checkpoint and its last advance CheckpointPersistenceStatus now carries the persisted CheckpointLSN and the count and time of the checkpoint calls that moved it. A success that was clamped or left the checkpoint unchanged is not an advance, so a starved checkpoint shows Successes rising while LastAdvance stays frozen. Co-Authored-By: Claude Opus 5.5 --- .../durable/checkpoint_status_test.go | 13 ++++-- .../core/storage/checkpoint_diagnostics.go | 37 ++++++++++++---- .../storage/checkpoint_diagnostics_test.go | 42 +++++++++++++++++++ seaweed-block/core/storage/flusher.go | 3 +- .../core/storage/flusher_instrumentation.go | 2 + 5 files changed, 85 insertions(+), 12 deletions(-) diff --git a/seaweed-block/core/frontend/durable/checkpoint_status_test.go b/seaweed-block/core/frontend/durable/checkpoint_status_test.go index b3ad4cb9ce..e3eed2d4f2 100644 --- a/seaweed-block/core/frontend/durable/checkpoint_status_test.go +++ b/seaweed-block/core/frontend/durable/checkpoint_status_test.go @@ -46,15 +46,20 @@ func TestDurableProvider_CheckpointPersistenceStatus(t *testing.T) { } var wire []struct { CheckpointPersistence *struct { - Successes uint64 - Refusals uint64 - Failures uint64 + Successes uint64 + Refusals uint64 + Failures uint64 + CheckpointLSN uint64 + Advances uint64 + LastAdvance time.Time } } if err := json.Unmarshal(raw, &wire); err != nil { t.Fatal(err) } - if len(wire) == 1 && wire[0].CheckpointPersistence != nil && wire[0].CheckpointPersistence.Successes > 0 { + if len(wire) == 1 && wire[0].CheckpointPersistence != nil && wire[0].CheckpointPersistence.Successes > 0 && + wire[0].CheckpointPersistence.CheckpointLSN > 0 && wire[0].CheckpointPersistence.Advances > 0 && + !wire[0].CheckpointPersistence.LastAdvance.IsZero() { return } if time.Now().After(deadline) { diff --git a/seaweed-block/core/storage/checkpoint_diagnostics.go b/seaweed-block/core/storage/checkpoint_diagnostics.go index 46aa71e185..68303be17a 100644 --- a/seaweed-block/core/storage/checkpoint_diagnostics.go +++ b/seaweed-block/core/storage/checkpoint_diagnostics.go @@ -8,25 +8,48 @@ import ( // CheckpointPersistenceStatus counts flusher checkpoint calls in this open. // Success includes a safely clamped/unchanged checkpoint; it is not a slot-write -// count. Fields are cumulative atomic observations, not a coherent frontier. +// count. Advances counts only the successes that moved the persisted +// CheckpointLSN, and LastAdvance is when the latest one did (zero: none in +// this open), so a starved checkpoint shows Successes rising while +// LastAdvance stays frozen. Fields are cumulative atomic observations, not a +// coherent frontier. type CheckpointPersistenceStatus struct { - Successes uint64 - Refusals uint64 - Failures uint64 + Successes uint64 + Refusals uint64 + Failures uint64 + CheckpointLSN uint64 + Advances uint64 + LastAdvance time.Time } func (s *WALStore) CheckpointPersistence() CheckpointPersistenceStatus { if s.flusher == nil { - return CheckpointPersistenceStatus{} + return CheckpointPersistenceStatus{CheckpointLSN: s.CheckpointLSN()} } i := &s.flusher.instr - return CheckpointPersistenceStatus{i.checkpointSuccesses.Load(), i.checkpointRefusals.Load(), i.checkpointFailures.Load()} + st := CheckpointPersistenceStatus{ + Successes: i.checkpointSuccesses.Load(), + Refusals: i.checkpointRefusals.Load(), + Failures: i.checkpointFailures.Load(), + CheckpointLSN: s.CheckpointLSN(), + Advances: i.checkpointAdvances.Load(), + } + if ns := i.checkpointLastAdvanceNanos.Load(); ns != 0 { + st.LastAdvance = time.Unix(0, ns) + } + return st } -func (i *flusherInstrumentation) recordCheckpoint(err error) { +// recordCheckpoint classifies one flusher checkpoint call; before and after +// are the persisted CheckpointLSN around it. +func (i *flusherInstrumentation) recordCheckpoint(err error, before, after uint64, now time.Time) { switch { case err == nil: i.checkpointSuccesses.Add(1) + if after > before { + i.checkpointAdvances.Add(1) + i.checkpointLastAdvanceNanos.Store(now.UnixNano()) + } case errors.Is(err, ErrMapCoverageStale): i.checkpointRefusals.Add(1) default: diff --git a/seaweed-block/core/storage/checkpoint_diagnostics_test.go b/seaweed-block/core/storage/checkpoint_diagnostics_test.go index 2670beb977..6eb79badca 100644 --- a/seaweed-block/core/storage/checkpoint_diagnostics_test.go +++ b/seaweed-block/core/storage/checkpoint_diagnostics_test.go @@ -116,3 +116,45 @@ func TestCheckpointDiagnostics_LogRateLimit(t *testing.T) { t.Fatalf("logs: %s", got) } } + +// A starved checkpoint: flush cycles keep succeeding (clamped to the +// acknowledged frontier, nothing persisted moves) while the persisted +// CheckpointLSN and the last advance stay frozen. Only a real move of the +// persisted checkpoint counts as an advance. +func TestCheckpointDiagnostics_StarvedCheckpointIsVisible(t *testing.T) { + s, _ := newMappedCheckpointStoreV3(t) + mustAttach(t, s, newFakeChunkRemote(), ctConfig(1)) + writeSynced(t, s, 1, 1) + if err := s.flusher.flushOnce(); err != nil { + t.Fatal(err) + } + first := s.CheckpointPersistence() + if first.CheckpointLSN != 1 || first.Advances != 1 || first.LastAdvance.IsZero() || first.Successes != 1 { + t.Fatalf("first checkpoint: %+v", first) + } + for i := uint32(0); i < 3; i++ { // written, never synced: the checkpoint is clamped at 1 + if _, err := s.Write(2+i, blk(byte(2+i))); err != nil { + t.Fatal(err) + } + if err := s.flusher.flushOnce(); err != nil { + t.Fatal(err) + } + } + starved := s.CheckpointPersistence() + if starved.Successes <= first.Successes { + t.Fatalf("flush cycles did not keep succeeding: %+v", starved) + } + if starved.CheckpointLSN != 1 || starved.Advances != 1 || !starved.LastAdvance.Equal(first.LastAdvance) { + t.Fatalf("a clamped success counted as an advance: first %+v starved %+v", first, starved) + } + if _, err := s.Sync(); err != nil { + t.Fatal(err) + } + if err := s.flusher.flushOnce(); err != nil { + t.Fatal(err) + } + moved := s.CheckpointPersistence() + if moved.CheckpointLSN != s.CheckpointLSN() || moved.CheckpointLSN <= 1 || moved.Advances != 2 || moved.LastAdvance.Before(first.LastAdvance) { + t.Fatalf("after sync the checkpoint advance was not recorded: %+v", moved) + } +} diff --git a/seaweed-block/core/storage/flusher.go b/seaweed-block/core/storage/flusher.go index 930e057a89..9c6175e044 100644 --- a/seaweed-block/core/storage/flusher.go +++ b/seaweed-block/core/storage/flusher.go @@ -278,12 +278,13 @@ func (f *flusher) flushOnceInternal(allowClosed bool) (err error) { // The released tail is persisted with the checkpoint, before the // writer may reuse those bytes. var publishErr error + cpBefore := store.CheckpointLSN() if store.v3 != nil { publishErr = store.persistCheckpointV3(maxLSN, recoveryGen) } else { publishErr = store.persistCheckpointAndRelease(maxLSN, maxLSNPhys, maxLSNEntrySize) } - f.instr.recordCheckpoint(publishErr) + f.instr.recordCheckpoint(publishErr, cpBefore, store.CheckpointLSN(), time.Now()) if err := publishErr; err != nil { return fmt.Errorf("flusher: persist checkpoint %d: %w", maxLSN, err) } diff --git a/seaweed-block/core/storage/flusher_instrumentation.go b/seaweed-block/core/storage/flusher_instrumentation.go index ec3fcf1827..939da10058 100644 --- a/seaweed-block/core/storage/flusher_instrumentation.go +++ b/seaweed-block/core/storage/flusher_instrumentation.go @@ -69,6 +69,8 @@ type flusherInstrumentation struct { checkpointSuccesses atomic.Uint64 checkpointRefusals atomic.Uint64 checkpointFailures atomic.Uint64 + checkpointAdvances atomic.Uint64 + checkpointLastAdvanceNanos atomic.Int64 cyclesStarted atomic.Uint64 cyclesSucceeded atomic.Uint64 cyclesFailed atomic.Uint64 From 97d8e680917433271c9388453125f6e3569e6c26 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 19 Nov 2026 10:57:40 -0800 Subject: [PATCH 8/8] storage: test that only an advance moves the last-advance time Supplied distinct times show an advancing success updates LastAdvance while an unchanged success, a refusal and a failure keep it; the starved-checkpoint test now requires the second advance to be later. Co-Authored-By: Claude Opus 5.5 --- .../storage/checkpoint_diagnostics_test.go | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/seaweed-block/core/storage/checkpoint_diagnostics_test.go b/seaweed-block/core/storage/checkpoint_diagnostics_test.go index 6eb79badca..8ce1cbcd80 100644 --- a/seaweed-block/core/storage/checkpoint_diagnostics_test.go +++ b/seaweed-block/core/storage/checkpoint_diagnostics_test.go @@ -154,7 +154,33 @@ func TestCheckpointDiagnostics_StarvedCheckpointIsVisible(t *testing.T) { t.Fatal(err) } moved := s.CheckpointPersistence() - if moved.CheckpointLSN != s.CheckpointLSN() || moved.CheckpointLSN <= 1 || moved.Advances != 2 || moved.LastAdvance.Before(first.LastAdvance) { + if moved.CheckpointLSN != s.CheckpointLSN() || moved.CheckpointLSN <= 1 || moved.Advances != 2 || !moved.LastAdvance.After(first.LastAdvance) { t.Fatalf("after sync the checkpoint advance was not recorded: %+v", moved) } } + +// Only an advancing success moves LastAdvance; an unchanged success, a +// refusal and a failure leave the latest advance time as it was. +func TestCheckpointDiagnostics_LastAdvanceFollowsOnlyAdvances(t *testing.T) { + var i flusherInstrumentation + t0 := time.Unix(1000, 0) + at := func() time.Time { return time.Unix(0, i.checkpointLastAdvanceNanos.Load()) } + i.recordCheckpoint(nil, 0, 5, t0) + if !at().Equal(t0) || i.checkpointAdvances.Load() != 1 { + t.Fatalf("first advance: %v %d", at(), i.checkpointAdvances.Load()) + } + i.recordCheckpoint(nil, 5, 5, t0.Add(time.Second)) + i.recordCheckpoint(mapCoverageRefusal("proof_changed"), 5, 5, t0.Add(2*time.Second)) + i.recordCheckpoint(errors.New("fsync fault"), 5, 5, t0.Add(3*time.Second)) + if !at().Equal(t0) || i.checkpointAdvances.Load() != 1 { + t.Fatalf("a non-advance moved LastAdvance: %v advances=%d", at(), i.checkpointAdvances.Load()) + } + t1 := t0.Add(4 * time.Second) + i.recordCheckpoint(nil, 5, 9, t1) + if !at().Equal(t1) || i.checkpointAdvances.Load() != 2 { + t.Fatalf("second advance: %v %d", at(), i.checkpointAdvances.Load()) + } + if i.checkpointSuccesses.Load() != 3 || i.checkpointRefusals.Load() != 1 || i.checkpointFailures.Load() != 1 { + t.Fatalf("classification: s=%d r=%d f=%d", i.checkpointSuccesses.Load(), i.checkpointRefusals.Load(), i.checkpointFailures.Load()) + } +}