mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 02:27:26 +01:00
Reproduce unreadable half-fence map after legacy page reuse
This commit is contained in:
1 parent
903263e080
commit
3f0fe6bfec
2 files changed
+94
No files matched your search
@@ -433,3 +433,85 @@ func TestChunkCoverageInitializationRefusesActiveBaseBeforeWriting(t *testing.T)
|
||||
t.Fatalf("active BASE refusal wrote state: err=%v seed=%d pages=%d changed=%v", err, seedCalls, pageCalls, s.v3.pub.current() != before)
|
||||
}
|
||||
}
|
||||
|
||||
// The legacy allocator sees only the unmarked slot's root. Its next candidate
|
||||
// may reuse pages named solely by the marked slot before it publishes a slot.
|
||||
func TestChunkCoverageHalfFenceReusedMapOpensTheIntactLegacySlot(t *testing.T) {
|
||||
s, path := newMappedCheckpointStoreV3(t)
|
||||
s.HoldExtentDrainUntilChunkLayer()
|
||||
if _, err := s.Recover(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
payload := make([]byte, 4096)
|
||||
payload[0] = 0xa7
|
||||
if _, err := s.Write(1, payload); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := s.Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
writes := 0
|
||||
s.v3.testBeforeSlotWrite = func() error {
|
||||
writes++
|
||||
if writes == 2 {
|
||||
return errors.New("half fence")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if err := s.InitializeChunkCoverage(context.Background(), 7, func(uint64, uint64) (ChunkCoverageSeed, error) { return ChunkCoverageSeed{Blocks: []uint64{1}}, nil }, coverageNoPages); err == nil {
|
||||
t.Fatal("half fence completed")
|
||||
}
|
||||
marked := s.v3.pub.current()
|
||||
legacy := s.v3.pub.other
|
||||
if marked.MapFormatID != mapFormatIDCoverage || legacy.ChunkStateFormat != 0 {
|
||||
t.Fatal("control did not leave one marked and one legacy slot")
|
||||
}
|
||||
s.v3.testBeforeSlotWrite = nil
|
||||
_ = s.Close()
|
||||
// Use the unchanged format-1 allocator with exactly the slot/root the old
|
||||
// decoder can see. Stop after preparing pages, before publishing its slot.
|
||||
oldMap, prior, err := openChunkLSNMapV3(path+".chunkmap", legacy, 4)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
entries := append([]chunkLSNEntryV3(nil), prior.entries...)
|
||||
entries[0].Unknown = !entries[0].Unknown
|
||||
_, err = oldMap.Prepare(prior.generation+1, prior.covered, entries, prior)
|
||||
if err != nil {
|
||||
oldMap.Close()
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Verify the modeled old allocation really destroyed the marked dependency,
|
||||
// and that the unmarked slot's dependency is still independently readable.
|
||||
if _, _, err := readChunkLSNMapV3(oldMap.fd, marked, 4); err == nil {
|
||||
oldMap.Close()
|
||||
t.Fatal("control did not reuse the marked map")
|
||||
}
|
||||
if _, _, err := readChunkLSNMapV3(oldMap.fd, legacy, 4); err != nil {
|
||||
oldMap.Close()
|
||||
t.Fatalf("legacy dependency damaged: %v", err)
|
||||
}
|
||||
if err := oldMap.Close(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
next, err := openWALStoreV3MapInternalForTest(path, true)
|
||||
if err != nil {
|
||||
t.Fatalf("intact legacy slot could not reopen after half-fence page reuse: %v", err)
|
||||
}
|
||||
defer next.Close()
|
||||
next.DisableAutoFlushForRecoveryTest()
|
||||
next.HoldExtentDrainUntilChunkLayer()
|
||||
if next.v3.pub.current().ChunkStateFormat != 0 {
|
||||
t.Fatal("reused marked map was trusted")
|
||||
}
|
||||
if _, err := next.Recover(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got, err := next.Read(1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if string(got) != string(payload) {
|
||||
t.Fatal("legacy fallback lost acknowledged bytes")
|
||||
}
|
||||
}
|
||||
@@ -65,3 +65,15 @@ WAL write/replay, and checkpoint observations. Fill/BASE bitmap updates and
|
||||
metadata-only persistence still need integration. The disk tree allows bounded
|
||||
fanout, but the current runtime retains full entry/reference arrays and scans
|
||||
them during preparation. No proportional runtime cost or scale claim is made.
|
||||
|
||||
## Open half-fence recovery premise
|
||||
|
||||
The fault control `TestChunkCoverageHalfFenceReusedMapOpensTheIntactLegacySlot`
|
||||
is intentionally RED in this draft. It leaves one marked map-format-2 slot,
|
||||
opens the unmarked format-1 root with the unchanged legacy map allocator,
|
||||
prepares the allocator's next candidate without publishing its descriptor,
|
||||
and confirms that the new map was overwritten while the old map remains
|
||||
intact. Current reopening refuses the selected damaged map. Safe fallback to
|
||||
an intact legacy slot needs the extended SlotFence model before implementation.
|
||||
The test also requires acknowledged bytes to replay exactly after that fallback;
|
||||
it cannot pass by accepting an unreadable root or skipping recovery.
|
||||
Reference in new issue
Block a user