fix(storage): gate eviction on owned-map capture dirt

This commit is contained in:
pingqiu committed 2026-11-17 08:04:41 -08:00
1 parent 673fdf3015
commit 037db1e6cd
2 files changed
+8 -8

No files matched your search

+4 -8
View File
@@ -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)
}
@@ -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)