mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 10:37:23 +01:00
fix(storage): retain checkpoint proof across newer WAL appends
This commit is contained in:
1 parent
adf9b9e2a7
commit
49b9fe67b7
4 files changed
+142
-15
No files matched your search
@@ -0,0 +1,131 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestChunkLayerV3_CheckpointProgressUnderContinuousAppends(t *testing.T) {
|
||||
s, _ := newMappedCheckpointStoreV3(t)
|
||||
remote := newFakeChunkRemote()
|
||||
mustAttach(t, s, remote, ctConfig(1))
|
||||
if _, err := s.Write(0, blk(1)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := s.Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
realSync := s.v3.ownedMap.syncFile
|
||||
t.Cleanup(func() { s.v3.ownedMap.syncFile = realSync })
|
||||
refusals := 0
|
||||
for round := uint32(0); round < 8; round++ {
|
||||
injected := false
|
||||
s.v3.ownedMap.syncFile = func() error {
|
||||
if !injected {
|
||||
injected = true
|
||||
if _, err := s.Write(round+1, blk(byte(round+2))); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return realSync()
|
||||
}
|
||||
err := s.flusher.flushOnce()
|
||||
s.v3.ownedMap.syncFile = realSync
|
||||
if err != nil && !errors.Is(err, ErrMapCoverageStale) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if errors.Is(err, ErrMapCoverageStale) {
|
||||
refusals++
|
||||
}
|
||||
if !injected {
|
||||
t.Fatal("cycle did not overlap a write")
|
||||
}
|
||||
if _, err := s.Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
cp := s.CheckpointLSN()
|
||||
t.Logf("continuous writes: cycles8 refusals%d cp%d wack%d dirty%d", refusals, cp, s.v3.wack.Load(), s.dm.len())
|
||||
if cp == 0 {
|
||||
t.Fatal("checkpoint made no progress across eight completed extent/map persistence cycles while newer appends continued")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckpointV3_NewerBatchReplaysAfterPreparedPrefix(t *testing.T) {
|
||||
s, path := newMappedCheckpointStoreV3(t)
|
||||
remote := newFakeChunkRemote()
|
||||
layer := mustAttach(t, s, remote, ctConfig(1))
|
||||
if _, err := s.Write(1, blk(0x11)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := s.Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s.v3.testMapPrepared = func() {
|
||||
if _, err := s.WriteBatch(1, [][]byte{blk(0xB2), blk(0xC3)}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := s.Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if err := s.flusher.flushOnce(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s.v3.testMapPrepared = nil
|
||||
d := s.v3.pub.current()
|
||||
if d.CheckpointLSN != 1 || d.MapCoveredCheckpoint != 1 || s.dm.len() != 2 {
|
||||
t.Fatalf("prefix cp=%d C=%d dirty=%d", d.CheckpointLSN, d.MapCoveredCheckpoint, s.dm.len())
|
||||
}
|
||||
if err := layer.Close(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
crashRecoveryHardeningStore(t, s)
|
||||
s.mu.Lock()
|
||||
s.closed = true
|
||||
s.mu.Unlock()
|
||||
r, err := openWALStoreV3ForTest(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r.DisableAutoFlushForRecoveryTest()
|
||||
t.Cleanup(func() { _ = r.Close() })
|
||||
if _, err = r.Recover(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for lba, want := range map[uint32][]byte{1: blk(0xB2), 2: blk(0xC3)} {
|
||||
if !bytes.Equal(readV3(t, r, lba), want) {
|
||||
t.Fatalf("replayed LBA%d lost", lba)
|
||||
}
|
||||
}
|
||||
restored := mustAttach(t, r, remote, ctConfig(1))
|
||||
cut, err := restored.Cut(ctTimeout(t))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
image := remote.imageOf(t, cut.Head)
|
||||
if !bytes.Equal(image[4096:8192], blk(0xB2)) || !bytes.Equal(image[8192:12288], blk(0xC3)) {
|
||||
t.Fatal("capture omitted newer replayed batch")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckpointV3_EffectiveBaseWriteStillInvalidatesProof(t *testing.T) {
|
||||
s, _ := newMappedCheckpointStoreV3(t)
|
||||
h := beginV3(t, s, 0, idA)
|
||||
cp := s.CheckpointLSN()
|
||||
prepared, err := s.prepareOwnedMapCheckpointV3(cp)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
before := s.v3.pub.current()
|
||||
if err = h.WriteBase(1, blk(0xA7)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = s.v3.pub.publishMapV3(&s.mu, nil, prepared, nil); !errors.Is(err, ErrMapCoverageStale) {
|
||||
t.Fatalf("effective BASE mutation proof accepted: %v", err)
|
||||
}
|
||||
if s.v3.pub.current() != before {
|
||||
t.Fatal("stale BASE candidate changed slots")
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,8 @@ func (l *chunkLayerImpl) usesOwnedMapV3() bool { return l.s.v3 != nil && l.s.v3.
|
||||
// (or an authority-checked no-op), outside bmMu/stMu and the capture barrier.
|
||||
// The capture's mutation versions were sampled under the quiesced barrier.
|
||||
// Store.mu prevents a WAL append from slipping between the version check and
|
||||
// the UNKNOWN update. A later write updates max LSN and invalidates proofs.
|
||||
// the UNKNOWN update. A later WAL append updates max LSN and stays retained;
|
||||
// an effective UNKNOWN change or lifecycle transition invalidates proofs.
|
||||
// A failed map publication leaves the old disk UNKNOWN conservative; a map
|
||||
// persistence failure also latches the store, while the remote HEAD remains
|
||||
// the successfully captured image. No remote durability claim is undone.
|
||||
|
||||
@@ -144,8 +144,10 @@ func TestWALStoreV3_PreparedCheckpointRefusesChangedProof(t *testing.T) {
|
||||
release()
|
||||
select {
|
||||
case err := <-done:
|
||||
if !errors.Is(err, ErrMapCoverageStale) {
|
||||
if event == "recover" && !errors.Is(err, ErrMapCoverageStale) {
|
||||
t.Errorf("stale prepared checkpoint=%v", err)
|
||||
} else if event == "write" && err != nil {
|
||||
t.Errorf("newer retained append invalidated prefix coverage: %v", err)
|
||||
}
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatal("flusher did not settle")
|
||||
@@ -156,8 +158,10 @@ func TestWALStoreV3_PreparedCheckpointRefusesChangedProof(t *testing.T) {
|
||||
t.Fatal("flusher result without join")
|
||||
}
|
||||
s.v3.testMapPrepared = nil
|
||||
if s.v3.pub.current() != before {
|
||||
if event == "recover" && s.v3.pub.current() != before {
|
||||
t.Error("stale proof published a checkpoint")
|
||||
} else if event == "write" && s.CheckpointLSN() != 1 {
|
||||
t.Error("newer retained append blocked the older checkpoint")
|
||||
}
|
||||
if s.stickyIOFault() != nil {
|
||||
t.Error("proof refusal incorrectly latched a persistence fault")
|
||||
|
||||
@@ -654,13 +654,9 @@ func (s *WALStore) appendWriteV3(lba uint32, data []byte, lsn uint64) (uint64, e
|
||||
if s.v3.w == nil {
|
||||
return 0, errWALBindingV3 // a half-published reset before its Recover
|
||||
}
|
||||
// Reserve proof invalidation before the WAL can change. This is under
|
||||
// the existing store lock; a refused append only causes conservative retry.
|
||||
if s.v3.mapProof != nil {
|
||||
if err := s.v3.mapProof.mutatedV3(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
// A strictly newer append stays in the retained WAL suffix. It cannot
|
||||
// invalidate coverage of an older checkpoint prefix; effective BASE and
|
||||
// lifecycle mutations still invalidate the map proof at their own seams.
|
||||
if err := s.rolloverCheckpointV3Locked(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -710,11 +706,6 @@ func (s *WALStore) writeBatchV3Locked(startLBA uint32, blocks [][]byte, firstLSN
|
||||
s.instr.recordWALCopy(len(payload), time.Since(copyStart))
|
||||
n := uint64(len(blocks))
|
||||
lastLSN := firstLSN + n - 1
|
||||
if s.v3.mapProof != nil {
|
||||
if err := s.v3.mapProof.mutatedV3(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
e := walEntryV3{LSN: firstLSN, BatchCount: n, Type: walEntryWriteBatch, LBA: uint64(startLBA), Length: uint32(len(payload)), Data: payload}
|
||||
if err := s.rolloverCheckpointV3Locked(); err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in new issue
Block a user