From 037db1e6cdbe63e478ae5f164773671b4712f2d7 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Tue, 17 Nov 2026 08:04:41 -0800 Subject: [PATCH] fix(storage): gate eviction on owned-map capture dirt --- seaweed-block/core/storage/chunk_layer.go | 12 ++++-------- .../core/storage/chunk_layer_map_v3_test.go | 4 ++++ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/seaweed-block/core/storage/chunk_layer.go b/seaweed-block/core/storage/chunk_layer.go index 54c50f61a8..2c133cc8b3 100644 --- a/seaweed-block/core/storage/chunk_layer.go +++ b/seaweed-block/core/storage/chunk_layer.go @@ -1638,16 +1638,12 @@ func (l *chunkLayerImpl) EvictChunk(idx uint64) error { if idx >= l.numChunks { return fmt.Errorf("%w: chunk %d out of range", errChunkEvictRefused, idx) } - walDirty := false - for _, e := range l.s.dm.snapshot() { - if l.chunkOf(e.LBA) == idx { - walDirty = true - break - } - } + // The same owned-map/WAL dirt that capture must publish also forbids + // eviction: a later fill from the older HEAD must not overwrite it. + dirtyCandidate := l.captureCandidates()[idx] l.stMu.Lock() switch { - case l.head.Gen == 0, l.hashMode, l.allDirty, l.hdr.Base != chunkBaseNone, l.dirty[idx], l.inflight[idx], walDirty: + case l.head.Gen == 0, l.hashMode, l.allDirty, l.hdr.Base != chunkBaseNone, l.dirty[idx], l.inflight[idx], dirtyCandidate: l.stMu.Unlock() return fmt.Errorf("%w: chunk %d is dirty since HEAD or HEAD is unknown", errChunkEvictRefused, idx) } diff --git a/seaweed-block/core/storage/chunk_layer_map_v3_test.go b/seaweed-block/core/storage/chunk_layer_map_v3_test.go index 291cfb2aca..b3ad2be3c6 100644 --- a/seaweed-block/core/storage/chunk_layer_map_v3_test.go +++ b/seaweed-block/core/storage/chunk_layer_map_v3_test.go @@ -99,6 +99,10 @@ func TestChunkLayerV3_MaxLSNSelectsAfterReopenWithCleanLegacyBitmap(t *testing.T t.Fatalf("setup needs known map maxLSN2 and no WAL dirt: %+v", es[1]) } secondLayer := attachCleanMapFixtureV3(t, r, f, first.Head) + if err := secondLayer.EvictChunk(1); !errors.Is(err, errChunkEvictRefused) { + t.Errorf("eviction ignored owned-map dirt: %v", err) + } + second, err := secondLayer.Cut(ctTimeout(t)) if err != nil { t.Fatal(err)