mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 10:07:28 +01:00
Refuse presence reseeding after the chunk coverage marker
This commit is contained in:
1 parent
1d732c1da5
commit
32a7f1f74d
6 files changed
+83
-47
No files matched your search
+1
-1
@@ -123,5 +123,5 @@ core/transport/replica.go FencingRound.Recv
|
||||
core/transport/replica.go ReplicationPeer.CatchUp
|
||||
core/transport/replica.go ReplicationPeer.Rebuild
|
||||
core/transport/replica.go ReplicationPeer.Ship
|
||||
core/storage/chunk_coverage.go MoveWide2.FinishAttach
|
||||
core/storage/chunk_coverage.go SlotFence.Publish
|
||||
core/storage/chunk_coverage_map.go MoveWide2.Write
|
||||
|
@@ -20,6 +20,14 @@ const (
|
||||
// initialized. An old presence cache is not evidence for this answer.
|
||||
var ErrChunkCoverageUnavailable = errors.New("storage: durable chunk coverage unavailable; initialize the bitmap before using coverage")
|
||||
|
||||
// ChunkCoverageEpochMismatchError refuses upgrade seeding across a marked
|
||||
// local-work epoch. Attach-after-move, not legacy presence, owns that transition.
|
||||
type ChunkCoverageEpochMismatchError struct{ StoredEpoch, RequestedEpoch uint64 }
|
||||
|
||||
func (e *ChunkCoverageEpochMismatchError) Error() string {
|
||||
return fmt.Sprintf("storage: chunk coverage epoch %d differs from requested epoch %d; attach-after-move must establish the epoch", e.StoredEpoch, e.RequestedEpoch)
|
||||
}
|
||||
|
||||
// ChunkCoverageSeed supplies the legacy local blocks of a chunk during the
|
||||
// one-way upgrade. Blocks are offsets within the chunk. All avoids enumerating
|
||||
// every block of a wholly local chunk; All and Blocks must not both be set.
|
||||
@@ -96,7 +104,8 @@ func (s *WALStore) Coverage(chunk uint64) (LocalCoverage, uint64, error) {
|
||||
// InitializeChunkCoverage runs before chunk attachment, with extent draining
|
||||
// held and recovery complete. The seed reads no guest bytes; it describes the
|
||||
// legacy presence and recovered local blocks. A completed same-epoch call is
|
||||
// idempotent. A later epoch may clear old local work through an empty seed.
|
||||
// idempotent. After a marker, presence is never seeded again; a different
|
||||
// epoch is refused because attach-after-move owns that transition.
|
||||
// The bitmap pages are persisted first; preparePages then receives an immutable
|
||||
// view and must persist the matching chunk-record pages. Only after it succeeds
|
||||
// does the store publish both descriptor slots. The caller writes the record's
|
||||
@@ -130,9 +139,15 @@ func (s *WALStore) InitializeChunkCoverage(ctx context.Context, epoch uint64, se
|
||||
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)
|
||||
if current.ChunkStateFormat != 0 {
|
||||
if current.LocalWorkEpoch != epoch {
|
||||
s.mu.RUnlock()
|
||||
return &ChunkCoverageEpochMismatchError{StoredEpoch: current.LocalWorkEpoch, RequestedEpoch: epoch}
|
||||
}
|
||||
if current.MapFormatID != mapFormatIDCoverage {
|
||||
s.mu.RUnlock()
|
||||
return ErrChunkCoverageUnavailable
|
||||
}
|
||||
}
|
||||
position := v.wack.Load()
|
||||
if s.nextLSN-1 != position {
|
||||
|
||||
@@ -120,47 +120,66 @@ func TestChunkCoverageCheckpointKeepsAllAcrossAPageBoundary(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestChunkCoverageNewEpochDoesNotReplayClearedLocalWork(t *testing.T) {
|
||||
s, path := newMappedCheckpointStoreV3(t)
|
||||
func TestChunkCoverageMarkedEpochNeverReseedsPresence(t *testing.T) {
|
||||
for _, want := range []uint64{6, 7, 8} {
|
||||
t.Run(fmt.Sprint(want), func(t *testing.T) {
|
||||
s, _ := newMappedCheckpointStoreV3(t)
|
||||
s.HoldExtentDrainUntilChunkLayer()
|
||||
if _, err := s.Recover(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.InitializeChunkCoverage(context.Background(), 7, func(uint64, uint64) (ChunkCoverageSeed, error) { return ChunkCoverageSeed{}, nil }, coverageNoPages); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := s.Write(1, make([]byte, 4096)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := s.Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
before := s.v3.pub.current()
|
||||
seeds, pages := 0, 0
|
||||
err := s.InitializeChunkCoverage(context.Background(), want, func(uint64, uint64) (ChunkCoverageSeed, error) { seeds++; return ChunkCoverageSeed{All: true}, nil }, func(view ChunkCoverageReader) error {
|
||||
pages++
|
||||
if c, p, err := view.Coverage(0); err != nil || c != CoverageSome || p != 1 {
|
||||
t.Fatalf("bitmap view %d/%d %v", c, p, err)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if seeds != 0 {
|
||||
t.Fatalf("read presence after marker: %d", seeds)
|
||||
}
|
||||
if want == 7 {
|
||||
if err != nil || pages != 1 {
|
||||
t.Fatalf("same epoch did not rebuild from bitmap: %v pages=%d", err, pages)
|
||||
}
|
||||
} else {
|
||||
var mismatch *ChunkCoverageEpochMismatchError
|
||||
if !errors.As(err, &mismatch) || mismatch.StoredEpoch != 7 || mismatch.RequestedEpoch != want || pages != 0 || before != s.v3.pub.current() {
|
||||
t.Fatalf("epoch mismatch not typed/unchanged: %v pages=%d", err, pages)
|
||||
}
|
||||
}
|
||||
if c, p, err := s.Coverage(0); err != nil || c != CoverageSome || p != 1 {
|
||||
t.Fatalf("marked bits changed: %d/%d %v", c, p, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestChunkCoverageMarkerWithoutBitmapCannotReadPresence(t *testing.T) {
|
||||
s, _ := newMappedCheckpointStoreV3(t)
|
||||
s.HoldExtentDrainUntilChunkLayer()
|
||||
if _, err := s.Recover(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
empty := func(chunk, blocks uint64) (ChunkCoverageSeed, error) { return ChunkCoverageSeed{}, nil }
|
||||
if err := s.InitializeChunkCoverage(context.Background(), 7, empty, coverageNoPages); err != nil {
|
||||
if err := s.FenceChunkStateUpgrade(7); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := s.Write(1, make([]byte, 4096)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := s.Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.InitializeChunkCoverage(context.Background(), 8, empty, coverageNoPages); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
crashStore(t, s)
|
||||
next, err := openWALStoreV3MapInternalForTest(path, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
next.HoldExtentDrainUntilChunkLayer()
|
||||
next.DisableAutoFlushForRecoveryTest()
|
||||
t.Cleanup(func() { next.Close() })
|
||||
if _, err := next.Recover(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if coverage, pos, err := next.Coverage(0); err != nil || coverage != CoverageNone || pos != 1 {
|
||||
t.Fatalf("old epoch resurrected: %d/%d %v", coverage, pos, err)
|
||||
}
|
||||
if _, err := next.Write(2, make([]byte, 4096)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := next.Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if coverage, pos, err := next.Coverage(0); err != nil || coverage != CoverageSome || pos != 2 {
|
||||
t.Fatalf("new work missing: %d/%d %v", coverage, pos, err)
|
||||
before := s.v3.pub.current()
|
||||
seeds, pages := 0, 0
|
||||
err := s.InitializeChunkCoverage(context.Background(), 7, func(uint64, uint64) (ChunkCoverageSeed, error) { seeds++; return ChunkCoverageSeed{All: true}, nil }, func(ChunkCoverageReader) error { pages++; return nil })
|
||||
if !errors.Is(err, ErrChunkCoverageUnavailable) || seeds != 0 || pages != 0 || before != s.v3.pub.current() {
|
||||
t.Fatalf("marked legacy map read presence: err=%v seed=%d pages=%d", err, seeds, pages)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,11 +20,13 @@ 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
|
||||
position cannot reintroduce dropped bits; newer records do introduce bits.
|
||||
This is the store boundary for Drop followed by FinishAttach, not a daemon
|
||||
upgrade caller. Failed or uncertain descriptor publication retains the existing
|
||||
Presence is evidence only before the marker. Once marked at this epoch, the
|
||||
initializer never calls seed: it rebuilds pages from the recovered bitmap. A
|
||||
marked store without a readable initialized bitmap refuses as unavailable.
|
||||
A marker at another epoch returns `ChunkCoverageEpochMismatchError` before
|
||||
calling either callback or writing storage. Attach-after-move owns Drop and
|
||||
the new epoch; this initialization API cannot reset or reseed a marked store.
|
||||
Failed or uncertain descriptor publication retains the existing
|
||||
fault latch and requires reopening.
|
||||
|
||||
## Map format 2
|
||||
|
||||
@@ -617,7 +617,7 @@ The "Machine / transition" column refers to Part A. Notes under a table record w
|
||||
| `INV-CHUNK-RECORD-PAGES-CURRENT-001` | An unfinished chunk record is used, and its header written, only when every page passes its check and is valid through exactly the store's synced position after recovery (behind: missed writes; ahead: not durable); an unmarked store discards it; the header follows the two-slot fence. | M1 Opened (chunk record load, v1.1 upgrade) | `core/storage/chunk_record.go` `loadChunkRecord`, `completeChunkRecord` | `TestUnfinishedRecordPagesBehindTheStoreAreNotTrusted`, `TestUnfinishedRecordAfterAnOldCheckpointIsDiscarded`, `TestStalePagesAreNeverCompleted`, `TestUnfinishedPagesAheadOfTheStoreAreNotTrusted`, `TestCompleteRecordAheadOfTheStoreIsNotTrusted`, `TestCompleteRecordPagePositions`, `TestRecordHeaderWaitsForTheFence`, `TestRecordHeaderIsNotWrittenAheadOfTheSyncedStore`, `TestDamagedPage` (`core/storage/chunk_record_test.go`) | SlotFence `PagesCurrent`, `FenceHolds`; pages carry chunk-kernel/2 states (the per-chunk state models are not in this repository) | STUB |
|
||||
| `INV-CHUNK-RECORD-PAYLOAD-001` | Persisting and loading a chunk record preserves every entry's state and hash, including entries on either side of a segment boundary. | M1 chunk record codec (caller not wired) | `core/storage/chunk_record.go` `encodeChunkRecordPage`, `decodeChunkRecordPage` | `TestRecordEntryPayloadRoundTripsAcrossSegments` (`core/storage/chunk_record_test.go`; state-zero and one-entry hash-drop controls) | Encoding fidelity; no state transition change | STUB |
|
||||
| `INV-CHUNK-LOCAL-COVERAGE-001` | Coverage returns local none/some/all and the chunk position from one observation; it is unavailable until successful recovery and bitmap initialization. | M1 chunk bitmap (caller not wired) | `core/storage/chunk_coverage.go` `WALStore.Coverage`, `WALStore.InitializeChunkCoverage` | `TestChunkCoverageInitializesEmptyWithoutFabricatingLocalBlocks`, `TestChunkCoverageAcknowledgedWriteSurvivesReplay`, `TestChunkCoverageCheckpointKeepsAllAcrossAPageBoundary`, `TestChunkCoverageRequiresSuccessfulRecovery` (`core/storage/chunk_coverage_test.go`) | MoveWide2 durable per-block map premise; SlotFence publication | STUB |
|
||||
| `INV-CHUNK-LOCAL-DROP-001` | A new epoch's cleared local bits are not resurrected by retained WAL records at or below the bitmap's persisted position. | M1 bitmap epoch initialization (caller not wired) | `core/storage/walstore_map_checkpoint_v3.go` `recordMapReplayV3`; `core/storage/chunk_coverage.go` `WALStore.InitializeChunkCoverage` | `TestChunkCoverageNewEpochDoesNotReplayClearedLocalWork` (`core/storage/chunk_coverage_test.go`; retained-prefix replay mutation) | MoveWide2.Drop, MoveWide2.FinishAttach | STUB |
|
||||
| `INV-CHUNK-LOCAL-EPOCH-001` | After a format marker, initialization never reads legacy presence: the same epoch rebuilds pages from the bitmap; another epoch is refused without changing storage. | M1 bitmap initialization (caller not wired) | `core/storage/chunk_coverage.go` `WALStore.InitializeChunkCoverage` | `TestChunkCoverageMarkedEpochNeverReseedsPresence`, `TestChunkCoverageMarkerWithoutBitmapCannotReadPresence` (`core/storage/chunk_coverage_test.go`) | SlotFence marker authority; UpgradeWide3 | STUB |
|
||||
|
||||
| `INV-WAL-V3-DESCRIPTOR-SELECT-001` | Of the two v3 descriptor slots, open selects the valid selectable slot with the higher slotGen, and never a prepared migration slot. | M1 Opened (v3 descriptor selection) | `core/storage/superblock_v3.go` `selectSlotV3` | `TestSlotV3Selection` (`core/storage/superblock_v3_test.go`); `TestWALStoreV3CloseKeepsTheNewestSlotAAndItsW` (`core/storage/walstore_close_v3_test.go`) | — | ACTIVE |
|
||||
| `INV-WAL-V3-DESCRIPTOR-CONFLICT-001` | Open is refused when both v3 descriptor slots are valid but carry the same slotGen with different bytes, or disagree on the UUID or the geometry. | M1 Opened (v3 descriptor selection) | `core/storage/superblock_v3.go` `selectSlotV3`, `sameGeometryV3` | `TestSlotV3Selection` (`core/storage/superblock_v3_test.go`) | — | ACTIVE |
|
||||
|
||||
@@ -2,7 +2,7 @@ model item go_function tests status
|
||||
SlotFence prepare pages before publishing the field core/storage/chunk_coverage.go:WALStore.InitializeChunkCoverage core/storage/chunk_coverage_test.go:TestChunkCoveragePreparedViewPrecedesTheFence; core/storage/chunk_coverage_test.go:TestChunkCoveragePreparedReaderRemainsImmutableAfterWrites STUB
|
||||
MoveWide2 durable per-block map premise core/storage/chunk_coverage_map.go:readCoverageMapPagesV3; core/storage/walstore_map_checkpoint_v3.go:prepareOwnedMapCheckpointV3 core/storage/chunk_coverage_test.go:TestChunkCoverageCheckpointKeepsAllAcrossAPageBoundary STUB
|
||||
MoveWide2 WAL suffix restores local bits core/storage/walstore_map_checkpoint_v3.go:recordMapReplayV3 core/storage/chunk_coverage_test.go:TestChunkCoverageAcknowledgedWriteSurvivesReplay STUB
|
||||
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
|
||||
SlotFence marker excludes legacy seeding and cross-epoch initialization core/storage/chunk_coverage.go:WALStore.InitializeChunkCoverage core/storage/chunk_coverage_test.go:TestChunkCoverageMarkedEpochNeverReseedsPresence; core/storage/chunk_coverage_test.go:TestChunkCoverageMarkerWithoutBitmapCannotReadPresence 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
|
||||
|
||||
|
Reference in new issue
Block a user