test: expose checkpoint persistence refusals and successes

This commit is contained in:
pingqiu committed 2026-11-19 02:44:25 -08:00
1 parent c728fb4191
commit 3aa38eadd8
2 files changed
+113

No files matched your search

@@ -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)
}
}
@@ -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())
}
}