test: expose whole-map checkpoint copy at one TiB

This commit is contained in:
pingqiu committed 2026-11-30 21:37:16 -08:00
1 parent 468b7a3db2
commit a8d922942b
2 files changed
+67

No files matched your search

@@ -0,0 +1,56 @@
package storage
import (
"path/filepath"
"runtime"
"testing"
)
// This allocation bound is deliberately loose: one changed leaf and its
// bounded-fanout ancestors fit well below it, whereas copying the 1-TiB
// entry vector alone costs 6 MiB. It is a copy-cost control, not a CPU or
// whole-store stop qualification.
func TestChunkMapCheckpointOneChangedPageDoesNotCopyTheWholeMap(t *testing.T) {
d := mapDescriptorV3(t)
d.VolumeSize = 1 << 40
d.MapFormatID = mapFormatIDCoverage
const chunkBlocks = 1024
m, err := createChunkLSNMapV3(filepath.Join(t.TempDir(), "map"), d, chunkBlocks)
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() {
if err := m.Close(); err != nil {
t.Error(err)
}
})
shape, err := mapShapeForV3(d, chunkBlocks)
if err != nil {
t.Fatal(err)
}
empty := &chunkLocalBits{}
entries := make([]chunkLSNEntryV3, shape.chunks)
for i := range entries {
entries[i] = chunkLSNEntryV3{Unknown: true, Local: empty}
}
prior, err := m.Prepare(1, 0, entries, nil)
if err != nil {
t.Fatal(err)
}
entries[0] = chunkLSNEntryV3{LSN: 1, Unknown: true, Local: empty.mark(0, chunkBlocks)}
runtime.GC()
var before, after runtime.MemStats
runtime.ReadMemStats(&before)
next, err := m.Prepare(2, 1, entries, prior)
runtime.ReadMemStats(&after)
if err != nil {
t.Fatal(err)
}
if prior.entries[0].LSN != 0 || next.entries[0].LSN != 1 {
t.Fatal("preparation changed the prior snapshot or lost the changed page")
}
const allocationBound = 2 << 20
if allocated := after.TotalAlloc - before.TotalAlloc; allocated > allocationBound {
t.Fatalf("one changed page allocated %d bytes at 1 TiB; bound %d excludes a whole-map copy", allocated, allocationBound)
}
}
@@ -0,0 +1,11 @@
# version: page-reuse/1
step condition outcome
write any time, also between prepare and publish the page's memory version rises; the page is dirty while its memory version exceeds its retired version
prepare a page is dirty its content goes to a fresh extent; the candidate captures its memory version
prepare a page is clean the candidate reuses the SELECTED slot root's extent for it (never the other slot's)
publish succeeded (slot written and synced) retire each captured page at its CAPTURED version only; release the log up to it; a newer memory version stays dirty
publish failed cleanly the candidate is kept for retry and keeps its pins; nothing is retired
abandon a candidate is dropped nothing is retired; its fresh extents become garbage
crash during publish the slot write landed whole or not; the selected root decides; retired versions are rebuilt from it; the log was never released above it
retire before publish refused: a page is marked clean only up to a durable root or the candidate that captured it
free an extent only if no valid slot root (selected or other) and no kept or uncertain candidate names it
1 # version: page-reuse/1
2 step condition outcome
3 write any time, also between prepare and publish the page's memory version rises; the page is dirty while its memory version exceeds its retired version
4 prepare a page is dirty its content goes to a fresh extent; the candidate captures its memory version
5 prepare a page is clean the candidate reuses the SELECTED slot root's extent for it (never the other slot's)
6 publish succeeded (slot written and synced) retire each captured page at its CAPTURED version only; release the log up to it; a newer memory version stays dirty
7 publish failed cleanly the candidate is kept for retry and keeps its pins; nothing is retired
8 abandon a candidate is dropped nothing is retired; its fresh extents become garbage
9 crash during publish the slot write landed whole or not; the selected root decides; retired versions are rebuilt from it; the log was never released above it
10 retire before publish refused: a page is marked clean only up to a durable root or the candidate that captured it
11 free an extent only if no valid slot root (selected or other) and no kept or uncertain candidate names it