From b8bca3382eab53313f59a294aed41ee39385bf35 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Wed, 2 Dec 2026 02:50:49 -0800 Subject: [PATCH] Pin shared image and object state across queue refusals --- .../chunkstore/layout/queue_capacity_test.go | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/seaweed-block/core/frontend/chunkstore/layout/queue_capacity_test.go b/seaweed-block/core/frontend/chunkstore/layout/queue_capacity_test.go index 1872a466d0..63c6a2bc2a 100644 --- a/seaweed-block/core/frontend/chunkstore/layout/queue_capacity_test.go +++ b/seaweed-block/core/frontend/chunkstore/layout/queue_capacity_test.go @@ -1,12 +1,23 @@ package layout import ( + "bytes" "context" "errors" "reflect" "testing" ) +// Copy bytes as well as metadata: retaining object pointers would let an +// in-place mutation change both the observed state and the expected value. +func queueObjectSnapshot(s *chainStore) map[string]memObject { + out := make(map[string]memObject, len(s.objs)) + for name, o := range s.objs { + out[name] = memObject{data: append([]byte(nil), o.data...), meta: o.meta} + } + return out +} + func TestDeleteIntentQueueFullKeepsBothWorkAndReferences(t *testing.T) { ctx := context.Background() s, first, p := deleteIntentFixture(t) @@ -36,9 +47,23 @@ func TestDeleteIntentQueueFullKeepsBothWorkAndReferences(t *testing.T) { } // Draining the first slot must preserve weekly's live image. Retry then // atomically unlinks that exact incarnation and publishes its own work. + weekly := before.Snapshots["weekly"] + shared := queueObjectSnapshot(s) if _, err := RunConsumeSnapshotDeleteIntent(ctx, s, r); err != nil { t.Fatal(err) } + if got, found := s.h.Snapshots["weekly"]; !found || !reflect.DeepEqual(got, weekly) { + t.Fatalf("first drain changed the retained weekly incarnation: got=%+v want=%+v", got, weekly) + } + // The page names the shared root, its segment and payload. Check all of + // them now, before weekly is unlinked and reclamation becomes permitted. + for _, rel := range p.Entries { + want, found := shared[s.full(rel)] + got, present := s.objs[s.full(rel)] + if !found || !present || !bytes.Equal(got.data, want.data) || got.meta != want.meta { + t.Fatalf("first drain changed weekly's shared image object %s", rel) + } + } if _, err := RunDeleteSnapshotWithIntent(ctx, s, s.h.Gen, second); err != nil { t.Fatal(err) } @@ -70,12 +95,16 @@ func TestGenericListQueueFullCannotOverwritePendingWork(t *testing.T) { } second := ListCursor{Ref: ref, Kind: p.Kind, Producer: p.Producer, Generation: p.Generation} before, updates := s.h.clone(), s.updates + objects, writes := queueObjectSnapshot(s), append([]string(nil), s.writes...) if _, err := RunPublishList(ctx, s, me, "s1", s.h.Gen, second); !errors.Is(err, ErrQueueFull) { t.Fatalf("want typed queue_full, got %v", err) } if !reflect.DeepEqual(*s.h, before) || s.updates != updates { t.Fatal("full queue was overwritten") } + if !reflect.DeepEqual(queueObjectSnapshot(s), objects) || !reflect.DeepEqual(s.writes, writes) { + t.Fatal("generic full-slot refusal mutated objects or attempted an object write") + } if _, err := RunPublishList(ctx, s, me, "s1", first.Generation-1, first); err != nil { t.Fatalf("same-list replay refused: %v", err) }