mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 10:37:23 +01:00
Merge pull request #251 from seaweedfs/fix/checkpoint-refusal-diagnostics
storage: distinguish and rate-limit checkpoint proof refusals
This commit is contained in:
commit
37179d16eb
14 files changed
+443
-67
No files matched your search
@@ -0,0 +1,70 @@
|
||||
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.EnsureStorage("v1"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
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
|
||||
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 &&
|
||||
wire[0].CheckpointPersistence.CheckpointLSN > 0 && wire[0].CheckpointPersistence.Advances > 0 &&
|
||||
!wire[0].CheckpointPersistence.LastAdvance.IsZero() {
|
||||
return
|
||||
}
|
||||
if time.Now().After(deadline) {
|
||||
t.Fatalf("no checkpoint persist status in durable response: %s", raw)
|
||||
}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
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. 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
|
||||
CheckpointLSN uint64
|
||||
Advances uint64
|
||||
LastAdvance time.Time
|
||||
}
|
||||
|
||||
func (s *WALStore) CheckpointPersistence() CheckpointPersistenceStatus {
|
||||
if s.flusher == nil {
|
||||
return CheckpointPersistenceStatus{CheckpointLSN: s.CheckpointLSN()}
|
||||
}
|
||||
i := &s.flusher.instr
|
||||
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
|
||||
}
|
||||
|
||||
// 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:
|
||||
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", string(reason), l.suppressed, err)
|
||||
l.last, l.suppressed = now, 0
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
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 {
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
// 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.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())
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -278,11 +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, cpBefore, store.CheckpointLSN(), time.Now())
|
||||
if err := publishErr; err != nil {
|
||||
return fmt.Errorf("flusher: persist checkpoint %d: %w", maxLSN, err)
|
||||
}
|
||||
@@ -313,7 +315,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 {
|
||||
|
||||
@@ -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,11 @@ type FlusherInstrumentationStatus struct {
|
||||
}
|
||||
|
||||
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
|
||||
@@ -284,6 +292,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(),
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
@@ -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 {
|
||||
|
||||
@@ -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`).
|
||||
|
||||
|
||||
Reference in new issue
Block a user