diff --git a/seaweed-block/core/frontend/chunkstore/chunk_remote.go b/seaweed-block/core/frontend/chunkstore/chunk_remote.go index aff708783b..4c8dcc5da0 100644 --- a/seaweed-block/core/frontend/chunkstore/chunk_remote.go +++ b/seaweed-block/core/frontend/chunkstore/chunk_remote.go @@ -378,6 +378,11 @@ func (r *ChunkRemote) GetHead(ctx context.Context) (storage.ChunkHead, error) { return r.resolveManifest(ctx, h) } +// GetHeadRoot validates publication identity without reading segment bodies. +func (r *ChunkRemote) GetHeadRoot(ctx context.Context) (storage.ChunkHead, error) { + return r.getHeadRoot(ctx) +} + // getHeadRoot validates the root and its CAS attributes without reading any // immutable segment. CASHead only needs authority and lineage from this root. func (r *ChunkRemote) getHeadRoot(ctx context.Context) (storage.ChunkHead, error) { diff --git a/seaweed-block/core/frontend/chunkstore/head_cas_root_test.go b/seaweed-block/core/frontend/chunkstore/head_cas_root_test.go index d65183c90e..ed22ed0be0 100644 --- a/seaweed-block/core/frontend/chunkstore/head_cas_root_test.go +++ b/seaweed-block/core/frontend/chunkstore/head_cas_root_test.go @@ -48,6 +48,10 @@ func TestManifest_CASReadsOnlyRoot(t *testing.T) { if gen != h.Gen+1 || tracked.roots != 1 || tracked.children != 0 { t.Fatalf("CAS gen=%d root reads=%d child reads=%d", gen, tracked.roots, tracked.children) } + root, err := r.GetHeadRoot(context.Background()) + if err != nil || root.Gen != gen || root.Epoch != h.Epoch || root.Holder != h.Holder || tracked.children != 0 { + t.Fatalf("confirmation resolved segments: root=%+v children=%d err=%v", root, tracked.children, err) + } if _, err := r.GetHead(context.Background()); err == nil { t.Fatal("GetHead skipped segment resolution") } diff --git a/seaweed-block/core/frontend/durable/provider_chunk.go b/seaweed-block/core/frontend/durable/provider_chunk.go index fed1eed93e..227ab87a12 100644 --- a/seaweed-block/core/frontend/durable/provider_chunk.go +++ b/seaweed-block/core/frontend/durable/provider_chunk.go @@ -514,6 +514,15 @@ func (r *closeBoundRemote) GetHead(ctx context.Context) (storage.ChunkHead, erro return r.ChunkRemote.GetHead(c) } +func (r *closeBoundRemote) GetHeadRoot(ctx context.Context) (storage.ChunkHead, error) { + c, end := r.bind(ctx) + defer end() + if reader, ok := r.ChunkRemote.(storage.ChunkHeadRootReader); ok { + return reader.GetHeadRoot(c) + } + return r.ChunkRemote.GetHead(c) +} + func (r *closeBoundRemote) CASHead(ctx context.Context, expected storage.ChunkHeadVersion, next storage.ChunkHead) (uint64, error) { c, end := r.bind(ctx) defer end() diff --git a/seaweed-block/core/storage/chunk_head_belt.go b/seaweed-block/core/storage/chunk_head_belt.go index 21e01c4208..c8e565097c 100644 --- a/seaweed-block/core/storage/chunk_head_belt.go +++ b/seaweed-block/core/storage/chunk_head_belt.go @@ -11,12 +11,24 @@ import ( // detection belt, not a substitute for a single HEAD serialization point. const chunkHeadCoolingWindow = 5 * time.Second +// ChunkHeadRootReader confirms publication identity without resolving every +// immutable manifest. The returned Chunks need not be populated. +type ChunkHeadRootReader interface { + GetHeadRoot(context.Context) (ChunkHead, error) +} + func confirmChunkHead(ctx context.Context, remote chunkRemote, want chunkHead) error { - got, err := remote.GetHead(ctx) + var got chunkHead + var err error + if reader, ok := remote.(ChunkHeadRootReader); ok { + got, err = reader.GetHeadRoot(ctx) + } else { + got, err = remote.GetHead(ctx) + } if err != nil { return fmt.Errorf("storage: HEAD publication confirmation: %w: %w", errChunkCASOutcomeUnknown, err) } - if got.Gen != want.Gen || !sameProposal(got, want) { + if got.Gen != want.Gen || got.Epoch != want.Epoch || got.Holder != want.Holder { log.Printf("ALARM: HEAD publication displaced: wanted gen=%d epoch=%d holder=%q, read gen=%d epoch=%d holder=%q", want.Gen, want.Epoch, want.Holder, got.Gen, got.Epoch, got.Holder) return fmt.Errorf("%w: HEAD publication displaced", errChunkLayerFenced) }