mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 10:37:23 +01:00
Keep prepared coverage immutable and bound eager map geometry
This commit is contained in:
1 parent
3f0fe6bfec
commit
1d732c1da5
6 files changed
+105
-5
No files matched your search
@@ -31,10 +31,19 @@ type ChunkCoverageSeed struct {
|
||||
// ChunkCoverageReader is the atomic read seam shared by the live store and an
|
||||
// immutable prepared bitmap. The prepared view lets the caller persist record
|
||||
// pages before the store publishes its one-way descriptor fence.
|
||||
// A read costs O(1), performs no I/O and returns coverage and position together.
|
||||
// The live store takes lifecycle/store read locks; the prepared reader takes no
|
||||
// locks and remains immutable after the callback returns. Bounds, unavailable
|
||||
// recovery/initialization and latched store faults are errors, never CoverageNone.
|
||||
type ChunkCoverageReader interface {
|
||||
Coverage(chunk uint64) (LocalCoverage, uint64, error)
|
||||
}
|
||||
|
||||
var (
|
||||
_ ChunkCoverageReader = (*WALStore)(nil)
|
||||
_ ChunkCoverageReader = chunkCoverageSnapshot{}
|
||||
)
|
||||
|
||||
type chunkCoverageSnapshot struct {
|
||||
entries []chunkLSNEntryV3
|
||||
position uint64
|
||||
@@ -196,7 +205,7 @@ func (s *WALStore) InitializeChunkCoverage(ctx context.Context, epoch uint64, se
|
||||
return err
|
||||
}
|
||||
prepared := &preparedMapPublicationV3{candidate: candidate, proof: proof}
|
||||
if err := preparePages(chunkCoverageSnapshot{entries: entries, position: position}); err != nil {
|
||||
if err := preparePages(chunkCoverageSnapshot{entries: append([]chunkLSNEntryV3(nil), entries...), position: position}); err != nil {
|
||||
prepared.abandonV3()
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -10,6 +10,33 @@ import (
|
||||
|
||||
const coveragePagePayload uint64 = 4000
|
||||
|
||||
// Admission for the current eager runtime, not a disk-format limit. Count the
|
||||
// logical bitmap and entry/reference tables before allocating any of them.
|
||||
// A later paged runtime can lift this without another on-disk format change.
|
||||
const coverageShapeBudget uint64 = 1 << 30
|
||||
|
||||
func coverageShapeAdmitted(shape mapShapeV3, cb uint64) bool {
|
||||
remaining := coverageShapeBudget
|
||||
take := func(count, width uint64) bool {
|
||||
if width == 0 || count > remaining/width {
|
||||
return false
|
||||
}
|
||||
remaining -= count * width
|
||||
return true
|
||||
}
|
||||
if cb > counterMaxV3-63 || !take(shape.chunks, ((cb+63)/64)*8) || !take(shape.chunks, chunkMapEntryMemoryBytes) {
|
||||
return false
|
||||
}
|
||||
for nodes := shape.pages; ; nodes = (nodes + coverageTreeFanout - 1) / coverageTreeFanout {
|
||||
if !take(nodes, 40) {
|
||||
return false
|
||||
}
|
||||
if nodes <= coverageTreeFanout {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type coverageMapMetadata struct{ zeroPosition uint64 }
|
||||
type coverageMapPreparation struct {
|
||||
format uint32
|
||||
|
||||
@@ -2,6 +2,7 @@ package storage
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
@@ -515,3 +516,59 @@ func TestChunkCoverageHalfFenceReusedMapOpensTheIntactLegacySlot(t *testing.T) {
|
||||
t.Fatal("legacy fallback lost acknowledged bytes")
|
||||
}
|
||||
}
|
||||
|
||||
func TestChunkCoveragePreparedReaderRemainsImmutableAfterWrites(t *testing.T) {
|
||||
s, _ := newMappedCheckpointStoreV3(t)
|
||||
s.HoldExtentDrainUntilChunkLayer()
|
||||
if _, err := s.Recover(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var prepared ChunkCoverageReader
|
||||
if err := s.InitializeChunkCoverage(context.Background(), 7, func(uint64, uint64) (ChunkCoverageSeed, error) { return ChunkCoverageSeed{}, nil }, func(view ChunkCoverageReader) error { prepared = view; return nil }); 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 c, p, err := s.Coverage(0); err != nil || c != CoverageSome || p != 1 {
|
||||
t.Fatalf("live %d/%d: %v", c, p, err)
|
||||
}
|
||||
if c, p, err := prepared.Coverage(0); err != nil || c != CoverageNone || p != 0 {
|
||||
t.Fatalf("retained prepared view changed: %d/%d: %v", c, p, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestChunkCoverageRejectsRehashedImpossibleBitmapGeometry(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)
|
||||
}
|
||||
d := s.v3.pub.current()
|
||||
const impossibleChunkBlocks = uint64(1) << 63
|
||||
// Stop the red before exercising the allocator: the old admission accepts
|
||||
// petabytes of references here. This assertion is the safe negative control.
|
||||
if shape, err := mapShapeForV3(d, impossibleChunkBlocks); err == nil {
|
||||
t.Fatalf("impossible allocation admitted: %+v", shape)
|
||||
}
|
||||
root := make([]byte, 4096)
|
||||
if _, err := s.v3.ownedMap.fd.ReadAt(root, int64(d.MapRootLocator)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
binary.LittleEndian.PutUint64(root[56:], impossibleChunkBlocks)
|
||||
hash := mapDigestV3(mapRootDomainV3, root[:4064])
|
||||
copy(root[4064:], hash[:])
|
||||
d.MapRootHash = hash
|
||||
if _, err := s.v3.ownedMap.fd.WriteAt(root, int64(d.MapRootLocator)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, _, err := readChunkLSNMapV3(s.v3.ownedMap.fd, d, impossibleChunkBlocks); !errors.Is(err, ErrMapInvalid) {
|
||||
t.Fatalf("rehashed impossible root answered %v", err)
|
||||
}
|
||||
}
|
||||
@@ -67,6 +67,9 @@ func mapShapeForV3(d descriptorV3, cb uint64) (mapShapeV3, error) {
|
||||
}
|
||||
if d.MapFormatID == mapFormatIDCoverage {
|
||||
s.raw, s.aligned = 4096, 4096
|
||||
if !coverageShapeAdmitted(s, cb) {
|
||||
return s, ErrMapInvalid
|
||||
}
|
||||
return s, nil
|
||||
}
|
||||
s.raw = 120 + 40*s.pages
|
||||
|
||||
@@ -53,8 +53,8 @@ domains. A zero locator AND zero hash is a virtual subtree: every entry has
|
||||
the root's default position, Unknown true, and no local bits. A physical page
|
||||
at locator zero has a nonzero hash. Virtual references pin no file extent.
|
||||
|
||||
Unchanged leaves and index branches are shared across roots. New pages are
|
||||
synced before their root, and the root is synced before descriptor publication.
|
||||
Unchanged leaves and index branches are shared across roots. New leaves are
|
||||
synced first; index pages and the root share the final sync before descriptor publication.
|
||||
A captured bitmap's data file is synced before preparing its metadata pages.
|
||||
|
||||
## Qualification boundary
|
||||
@@ -64,7 +64,11 @@ are integrated and qualified. This draft implements recovery, initialization,
|
||||
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.
|
||||
them during preparation. No proportional runtime cost or scale claim is made. Before allocation, eager
|
||||
runtime admission limits the combined logical bitmap and entry/reference tables
|
||||
to a 1-GiB shape estimate. This is a runtime guard, not an on-disk format limit
|
||||
or a total resident-memory promise; larger geometry refuses with ErrMapInvalid
|
||||
until a paged implementation is qualified.
|
||||
|
||||
## Open half-fence recovery premise
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
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 STUB
|
||||
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
|
||||
|
||||
|
Reference in new issue
Block a user