mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
Guard coverage initialization before BASE writes and test publication faults
This commit is contained in:
1 parent
2d0a20bdc0
commit
903263e080
4 files changed
+101
No files matched your search
@@ -114,6 +114,13 @@ func (s *WALStore) InitializeChunkCoverage(ctx context.Context, epoch uint64, se
|
||||
return err
|
||||
}
|
||||
current := v.pub.current()
|
||||
v.pub.descMu.Lock()
|
||||
resetting := v.pub.otherValid && v.pub.other.Nonce != current.Nonce
|
||||
v.pub.descMu.Unlock()
|
||||
if current.BaseState != BaseNone || resetting {
|
||||
s.mu.RUnlock()
|
||||
return fmt.Errorf("%w: initialize coverage during BASE install or reset", errDescriptorTransition)
|
||||
}
|
||||
if current.LocalWorkEpoch > epoch {
|
||||
s.mu.RUnlock()
|
||||
return fmt.Errorf("%w: coverage epoch moved backwards", errDescriptorTransition)
|
||||
|
||||
@@ -3,6 +3,7 @@ package storage
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -343,3 +344,92 @@ func TestChunkCoverageDataSyncPrecedesBitmapPreparation(t *testing.T) {
|
||||
}
|
||||
prepared.abandonV3()
|
||||
}
|
||||
|
||||
func TestChunkCoverageFailedPublicationResumesAfterRecovery(t *testing.T) {
|
||||
for _, point := range []string{"write1", "write2", "sync1", "sync2", "read1", "read2"} {
|
||||
t.Run(point, func(t *testing.T) {
|
||||
s, path := newMappedCheckpointStoreV3(t)
|
||||
s.HoldExtentDrainUntilChunkLayer()
|
||||
if _, err := s.Recover(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
seed := func(uint64, uint64) (ChunkCoverageSeed, error) { return ChunkCoverageSeed{Blocks: []uint64{1}}, nil }
|
||||
writes, syncs, reads := 0, 0, 0
|
||||
originalSync, originalRead := s.v3.pub.io.fsync, s.v3.pub.io.readSlot
|
||||
injected := errors.New("lost " + point)
|
||||
s.v3.testBeforeSlotWrite = func() error {
|
||||
writes++
|
||||
if point == fmt.Sprint("write", writes) {
|
||||
return injected
|
||||
}
|
||||
return nil
|
||||
}
|
||||
s.v3.pub.io.fsync = func() error {
|
||||
syncs++
|
||||
if point == fmt.Sprint("sync", syncs) {
|
||||
return injected
|
||||
}
|
||||
return originalSync()
|
||||
}
|
||||
s.v3.pub.io.readSlot = func(off int64, b []byte) error {
|
||||
reads++
|
||||
if point == fmt.Sprint("read", reads) {
|
||||
return injected
|
||||
}
|
||||
return originalRead(off, b)
|
||||
}
|
||||
if err := s.InitializeChunkCoverage(context.Background(), 7, seed, coverageNoPages); err == nil {
|
||||
t.Fatal("uncertain initialization completed")
|
||||
}
|
||||
s.v3.testBeforeSlotWrite = nil
|
||||
s.v3.pub.io.fsync, s.v3.pub.io.readSlot = originalSync, originalRead
|
||||
if err := s.InitializeChunkCoverage(context.Background(), 7, seed, coverageNoPages); err == nil {
|
||||
t.Fatal("latched initialization completed before reopen")
|
||||
}
|
||||
_ = s.Close()
|
||||
next, err := openWALStoreV3MapInternalForTest(path, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { next.Close() })
|
||||
next.HoldExtentDrainUntilChunkLayer()
|
||||
next.DisableAutoFlushForRecoveryTest()
|
||||
if _, err := next.Recover(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := next.InitializeChunkCoverage(context.Background(), 7, seed, func(view ChunkCoverageReader) error {
|
||||
if c, p, err := view.Coverage(0); err != nil || c != CoverageSome || p != 0 {
|
||||
return fmt.Errorf("prepared view %d/%d: %v", c, p, err)
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if c, p, err := next.Coverage(0); err != nil || c != CoverageSome || p != 0 {
|
||||
t.Fatalf("reopened view %d/%d: %v", c, p, err)
|
||||
}
|
||||
current := next.v3.pub.current()
|
||||
next.v3.pub.descMu.Lock()
|
||||
other := next.v3.pub.other
|
||||
next.v3.pub.descMu.Unlock()
|
||||
if current.MapFormatID != mapFormatIDCoverage || other.MapFormatID != mapFormatIDCoverage || current.LocalWorkEpoch != 7 || other.LocalWorkEpoch != 7 {
|
||||
t.Fatal("returned before both bitmap slots were published")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestChunkCoverageInitializationRefusesActiveBaseBeforeWriting(t *testing.T) {
|
||||
s, _ := newMappedCheckpointStoreV3(t)
|
||||
s.HoldExtentDrainUntilChunkLayer()
|
||||
if _, err := s.Recover(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_ = beginV3(t, s, 0, idA)
|
||||
before := s.v3.pub.current()
|
||||
seedCalls, pageCalls := 0, 0
|
||||
err := s.InitializeChunkCoverage(context.Background(), 7, func(uint64, uint64) (ChunkCoverageSeed, error) { seedCalls++; return ChunkCoverageSeed{}, nil }, func(ChunkCoverageReader) error { pageCalls++; return nil })
|
||||
if err == nil || seedCalls != 0 || pageCalls != 0 || s.v3.pub.current() != before {
|
||||
t.Fatalf("active BASE refusal wrote state: err=%v seed=%d pages=%d changed=%v", err, seedCalls, pageCalls, s.v3.pub.current() != before)
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,8 @@ then does the store publish the bitmap root and epoch together and complete the
|
||||
two-slot fence, including sync and exact readback of both slots. The caller may
|
||||
write the completion header and remove legacy presence only after success.
|
||||
A same-epoch retry reuses the recovered bitmap and calls preparePages again.
|
||||
An active BASE install or descriptor reset refuses before calling either
|
||||
callback or publishing any candidate.
|
||||
|
||||
A later epoch may seed an empty map. Each chunk position is raised to the
|
||||
acknowledged frontier at the reset. Retained WAL records at or below that
|
||||
|
||||
@@ -5,3 +5,5 @@ MoveWide2 WAL suffix restores local bits core/storage/walstore_map_checkpoint_v3
|
||||
MoveWide2 Drop before FinishAttach core/storage/chunk_coverage.go:WALStore.InitializeChunkCoverage; core/storage/walstore_map_checkpoint_v3.go:recordMapReplayV3 core/storage/chunk_coverage_test.go:TestChunkCoverageNewEpochDoesNotReplayClearedLocalWork STUB
|
||||
MoveWide2 typed atomic bitmap observation core/storage/chunk_coverage.go:WALStore.Coverage core/storage/chunk_coverage_test.go:TestChunkCoverageRequiresSuccessfulRecovery; core/storage/chunk_coverage_test.go:TestChunkCoverageSeedsPartialWholeAndLastShortChunk STUB
|
||||
MoveWide2 bounded fanout format and shared COW nodes core/storage/chunk_coverage_map.go:encodeCoverageTreeRootV3; core/storage/chunk_coverage_map.go:coverageTreeRefsV3 core/storage/chunk_coverage_test.go:TestChunkCoverageTreeKeepsBothIndexBranches STUB
|
||||
SlotFence uncertain publication resumes only after reopen and recovery core/storage/chunk_coverage.go:WALStore.InitializeChunkCoverage; core/storage/chunk_coverage.go:WALStore.finishCoverageFenceLocked core/storage/chunk_coverage_test.go:TestChunkCoverageFailedPublicationResumesAfterRecovery STUB
|
||||
SlotFence BASE and reset exclude upgrade before callback or publication core/storage/chunk_coverage.go:WALStore.InitializeChunkCoverage core/storage/chunk_coverage_test.go:TestChunkCoverageInitializationRefusesActiveBaseBeforeWriting STUB
|
||||
|
Reference in new issue
Block a user