mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 02:27:26 +01:00
test(storage): exercise held and uncertain real map checkpoints
This commit is contained in:
1 parent
623ffedb69
commit
c2f8a5aee1
4 files changed
+164
-3
No files matched your search
@@ -304,6 +304,9 @@ func (m *chunkLSNMapV3) Prepare(g, C uint64, entries []chunkLSNEntryV3, prior *c
|
||||
func (m *chunkLSNMapV3) prepareNextV3(C uint64, entries []chunkLSNEntryV3, prior *chunkMapCandidateV3) (*chunkMapCandidateV3, error) {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
if m.failed != nil {
|
||||
return nil, m.failed
|
||||
}
|
||||
if m.lastGeneration >= counterMaxV3 {
|
||||
return nil, ErrCounterExhausted
|
||||
}
|
||||
|
||||
@@ -51,6 +51,9 @@ func (s *WALStore) prepareOwnedMapCheckpointV3(cp uint64) (*preparedMapPublicati
|
||||
|
||||
func (s *WALStore) persistOwnedMapCheckpointV3(highestLSN uint64) error {
|
||||
v := s.v3
|
||||
if err := s.stickyIOFault(); err != nil {
|
||||
return err
|
||||
}
|
||||
cp := min(highestLSN, v.wack.Load())
|
||||
s.mu.RLock()
|
||||
floorSource := s.recycleFloorSrc
|
||||
@@ -79,6 +82,9 @@ func (s *WALStore) persistOwnedMapCheckpointV3(highestLSN uint64) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if h := v.testMapPrepared; h != nil {
|
||||
h()
|
||||
}
|
||||
v.syncMu.Lock()
|
||||
defer v.syncMu.Unlock()
|
||||
wack := v.wack.Load()
|
||||
|
||||
@@ -3,7 +3,9 @@ package storage
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func newMappedCheckpointStoreV3(t *testing.T) (*WALStore, string) {
|
||||
@@ -37,9 +39,10 @@ func TestWALStoreV3_AutomaticMapCheckpoint(t *testing.T) {
|
||||
if s.dm.len() != 0 {
|
||||
t.Error("covered dirty entries not retired")
|
||||
}
|
||||
if err = s.Close(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
crashRecoveryHardeningStore(t, s) // no Close/final flush or descriptor refresh
|
||||
s.mu.Lock()
|
||||
s.closed = true
|
||||
s.mu.Unlock() // cleanup must not touch the crashed file
|
||||
r, err := openWALStoreV3ForTest(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -93,3 +96,151 @@ func TestWALStoreV3_AutomaticMapPersistenceFailureLatchesStore(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestWALStoreV3_PreparedCheckpointRefusesChangedProof(t *testing.T) {
|
||||
for _, event := range []string{"write", "recover"} {
|
||||
t.Run(event, func(t *testing.T) {
|
||||
s, _ := newMappedCheckpointStoreV3(t)
|
||||
writeSynced(t, s, 1, 1)
|
||||
entered, resume, joined := make(chan struct{}), make(chan struct{}), make(chan struct{})
|
||||
done := make(chan error, 1)
|
||||
var once sync.Once
|
||||
release := func() { once.Do(func() { close(resume) }) }
|
||||
s.v3.testMapPrepared = func() { close(entered); <-resume }
|
||||
t.Cleanup(func() {
|
||||
release()
|
||||
select {
|
||||
case <-joined:
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Error("flusher did not join")
|
||||
}
|
||||
})
|
||||
go func() { defer close(joined); done <- s.flusher.flushOnce() }()
|
||||
select {
|
||||
case <-entered:
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatal("actual flusher did not persist a map candidate")
|
||||
}
|
||||
if event == "write" {
|
||||
if _, err := s.Write(2, blk(2)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
} else {
|
||||
if _, err := s.Recover(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
before := s.v3.pub.current()
|
||||
release()
|
||||
select {
|
||||
case err := <-done:
|
||||
if !errors.Is(err, ErrMapCoverageStale) {
|
||||
t.Errorf("stale prepared checkpoint=%v", err)
|
||||
}
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatal("flusher did not settle")
|
||||
}
|
||||
select {
|
||||
case <-joined:
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatal("flusher result without join")
|
||||
}
|
||||
s.v3.testMapPrepared = nil
|
||||
if s.v3.pub.current() != before {
|
||||
t.Error("stale proof published a checkpoint")
|
||||
}
|
||||
if s.stickyIOFault() != nil {
|
||||
t.Error("proof refusal incorrectly latched a persistence fault")
|
||||
}
|
||||
if s.dm.len() == 0 {
|
||||
t.Error("proof refusal lost retry ownership")
|
||||
}
|
||||
if _, err := s.Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.flusher.flushOnce(); err != nil {
|
||||
t.Fatalf("fresh candidate retry: %v", err)
|
||||
}
|
||||
want := uint64(1)
|
||||
if event == "write" {
|
||||
want = 2
|
||||
}
|
||||
d := s.v3.pub.current()
|
||||
if d.CheckpointLSN != want || d.MapCoveredCheckpoint != want {
|
||||
t.Fatalf("fresh retry cp=%d C=%d want%d", d.CheckpointLSN, d.MapCoveredCheckpoint, want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
func TestWALStoreV3_AutomaticMapClampedProgressRetries(t *testing.T) {
|
||||
s, _ := newMappedCheckpointStoreV3(t)
|
||||
if err := s.SetWMode(WModeLagged); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
writeSynced(t, s, 1, 1)
|
||||
if _, err := s.Write(2, blk(2)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.flusher.flushOnce(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
d := s.v3.pub.current()
|
||||
if d.CheckpointLSN != 1 || d.MapCoveredCheckpoint != 1 || s.dm.len() != 1 {
|
||||
t.Fatal("clamped automatic checkpoint lost retry ownership")
|
||||
}
|
||||
if _, err := s.Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.flusher.flushOnce(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
d = s.v3.pub.current()
|
||||
if d.CheckpointLSN != 2 || d.MapCoveredCheckpoint != 2 || s.dm.len() != 0 {
|
||||
t.Fatal("later Sync did not advance automatic checkpoint and coverage")
|
||||
}
|
||||
}
|
||||
func TestWALStoreV3_UncertainMapCheckpointPinsDependencies(t *testing.T) {
|
||||
s, path := newMappedCheckpointStoreV3(t)
|
||||
writeSynced(t, s, 1, 1)
|
||||
before := s.v3.pub.current()
|
||||
injected := errors.New("descriptor response lost after full pwrite")
|
||||
realWrite := s.v3.pub.io.writeSlot
|
||||
s.v3.pub.io.writeSlot = func(off int64, b []byte) error {
|
||||
if err := realWrite(off, b); err != nil {
|
||||
return err
|
||||
}
|
||||
return injected
|
||||
}
|
||||
if err := s.flusher.flushOnce(); !errors.Is(err, ErrDescriptorPublishUncertain) {
|
||||
t.Fatalf("uncertain checkpoint=%v", err)
|
||||
}
|
||||
if s.v3.pub.current() != before || s.dm.len() != 1 {
|
||||
t.Fatal("unknown publication advanced in-memory checkpoint or retired dirty entries")
|
||||
}
|
||||
uncertain, ok := s.v3.pub.uncertainCandidate()
|
||||
if !ok {
|
||||
t.Fatal("unknown publication lost candidate pin")
|
||||
}
|
||||
if _, _, err := readChunkLSNMapV3(s.v3.ownedMap.fd, uncertain, 4); err != nil {
|
||||
t.Fatalf("unknown slot references missing map: %v", err)
|
||||
}
|
||||
if _, err := s.Sync(); err == nil {
|
||||
t.Fatal("unknown publication allowed Sync")
|
||||
}
|
||||
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)
|
||||
}
|
||||
if !bytes.Equal(readV3(t, r, 1), blk(1)) {
|
||||
t.Fatal("resolved checkpoint lost extent data")
|
||||
}
|
||||
}
|
||||
@@ -81,6 +81,7 @@ type walStoreV3State struct {
|
||||
testRecoverHold func()
|
||||
testBatchBeforeAck func()
|
||||
testSyncBeforeCompletion func()
|
||||
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()
|
||||
|
||||
Reference in new issue
Block a user