seaweed-block: red: a paused delete-intent adopter re-tags a page staged again after its window

An adopter checks the delete-intent window, then re-tags the page. If it
pauses between the two while a cleaner pass removes the unlinked page and
another executor of the same operation stages it again at the new base,
the adopter takes that page over under the old base's writer tag.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Opus 5.5 committed 2026-12-05 06:26:35 -08:00
1 parent b7631e6a3b
commit 0d852d63e1
1 file changed
+69
@@ -0,0 +1,69 @@
package layout
import (
"context"
"errors"
"testing"
)
// pausedAfterWindow is the store as a paused adopter sees it: its first HEAD
// read returns the HEAD of that moment, and then, before the adopter acts on
// it, the rest of the cluster moves on (pause).
type pausedAfterWindow struct {
*chainStore
reads int
pause func()
}
func (s *pausedAfterWindow) ReadHead(ctx context.Context) (Head, bool, error) {
h, found, err := s.chainStore.ReadHead(ctx)
s.reads++
if s.reads == 1 && s.pause != nil {
s.pause()
}
return h, found, err
}
// An adopter that passed its delete-intent window and then paused must not
// re-tag the page once the window has moved on. During its pause a cleaner
// pass moved the HEAD generation, the unlinked page was deleted, and another
// executor of the same operation staged it again at the new base. Acting on
// its stale window, the adopter would take over that new executor's page
// under the old base's writer tag; it must refuse instead and leave the page
// as the new executor staged it.
func TestAPausedAdopterDoesNotRetagAPageStagedAgainAfterItsWindow(t *testing.T) {
s, c, p := deleteIntentFixture(t)
ctx := context.Background()
base := s.h.Gen
if _, err := StageSnapshotDeletePage(ctx, s, base, p); err != nil {
t.Fatal(err)
}
rel, err := c.Ref.Path()
if err != nil {
t.Fatal(err)
}
paused := &pausedAfterWindow{chainStore: s, pause: func() {
// A cleaner pass (two HEAD generations) removes the unlinked page,
// then another executor stages it again at the new base.
s.h.Gen = base + 2
delete(s.objs, s.full(rel))
if _, err := StageSnapshotDeletePage(ctx, s, base+2, p); err != nil {
t.Errorf("the second executor's staging: %v", err)
}
}}
adoptErr := adoptDeleteIntentPage(ctx, paused, s.volume, base, c.Ref)
meta, found, err := s.Stat(ctx, rel)
if err != nil || !found {
t.Fatalf("stat the page: %v %v", found, err)
}
if meta.Session != p.Producer || meta.Mark != "" {
t.Fatalf("the paused adopter re-tagged the page staged at the new base: tags %+v (adopt: %v), want the second executor's %q", meta, adoptErr, p.Producer)
}
if adoptErr == nil {
t.Fatal("the paused adopter acted on a window that had moved on: want a refusal")
}
if !errors.Is(adoptErr, ErrPrecondition) && !errors.Is(adoptErr, ErrBusy) {
t.Fatalf("the paused adopter was refused with %v, want ErrPrecondition or ErrBusy", adoptErr)
}
}