From 858720738c8ca959ce0db50cf0a7983bad8220ef Mon Sep 17 00:00:00 2001 From: pingqiu Date: Wed, 2 Dec 2026 03:43:06 -0800 Subject: [PATCH] storage: no upgrade pass on a store this start created A new volume's store (an empty HEAD, every chunk local and zero) is unknown only because its upgrade had no seed; the first cut takes its chunks as candidates. The procedures' first snapshots were refused in_progress by that pass. A restart before the first cut runs it. Co-Authored-By: Claude Opus 5.5 --- .../core/storage/chunk_format_level_test.go | 53 ++++++++++++------- .../core/storage/chunk_upgrade_wire.go | 7 ++- 2 files changed, 40 insertions(+), 20 deletions(-) diff --git a/seaweed-block/core/storage/chunk_format_level_test.go b/seaweed-block/core/storage/chunk_format_level_test.go index 78c8825c77..bf31ed354a 100644 --- a/seaweed-block/core/storage/chunk_format_level_test.go +++ b/seaweed-block/core/storage/chunk_format_level_test.go @@ -286,25 +286,40 @@ func TestAV11AttachRefusesARemoteThatDeclinesTheHeadFormat(t *testing.T) { } } -// A fresh store (every chunk absent, nothing local to compare) upgraded at -// level 1 with no clean-stop proof runs no compare pass and holds no cut: -// its chunks are absent, not unknown, so the first cut (a snapshot right -// after a new volume starts) is not refused in_progress. +// A store this start created (a new volume: an empty HEAD, every chunk local +// and zero) upgraded at level 1 with no clean-stop proof runs no compare pass +// and holds no cut, so the first cut (a snapshot right after a new volume +// starts) is not refused in_progress. A fresh-from-HEAD store whose chunks +// are absent runs none either (nothing unknown). func TestAFreshStoreAtLevelOneRunsNoUpgradePass(t *testing.T) { - withV11Format(t) - withoutPassWait(t) - s, l, _ := lazyFreshVolume(t) - l.stMu.Lock() - pass := l.pass - l.stMu.Unlock() - if pass != nil { - t.Fatalf("a fresh store started an upgrade pass (status %+v); want none: nothing unknown to compare", l.Stats().UpgradePass) - } - if _, err := s.Write(1, makeBlock(ctBlockSize, 0xF1)); err != nil { - t.Fatal(err) - } - var refusal *ErrUpgradePassInProgress - if _, err := l.Cut(ctTimeout(t)); errors.As(err, &refusal) || err != nil { - t.Fatalf("the first cut of a fresh store at level 1: %v, want it to run", err) + for _, tc := range []string{"created this start, empty HEAD", "fresh from HEAD, chunks absent"} { + t.Run(tc, func(t *testing.T) { + withV11Format(t) + withoutPassWait(t) + var s *WALStore + var l *chunkLayerImpl + if tc == "created this start, empty HEAD" { + s, _ = newChunkTestStore(t) + cfg := ctConfig(2) + cfg.Bitmap = nil + cfg.FreshFromHead, cfg.CreatedThisStart = true, true + l = mustAttach(t, s, newFakeChunkRemote(), cfg).(*chunkLayerImpl) + } else { + s, l, _ = lazyFreshVolume(t) + } + l.stMu.Lock() + pass := l.pass + l.stMu.Unlock() + if pass != nil { + t.Fatalf("%s: an upgrade pass started (status %+v); want none", tc, l.Stats().UpgradePass) + } + if _, err := s.Write(1, makeBlock(ctBlockSize, 0xF1)); err != nil { + t.Fatal(err) + } + var refusal *ErrUpgradePassInProgress + if _, err := l.Cut(ctTimeout(t)); errors.As(err, &refusal) || err != nil { + t.Fatalf("%s: the first cut at level 1: %v, want it to run", tc, err) + } + }) } } diff --git a/seaweed-block/core/storage/chunk_upgrade_wire.go b/seaweed-block/core/storage/chunk_upgrade_wire.go index 6d73b46b19..d6dc8d5d78 100644 --- a/seaweed-block/core/storage/chunk_upgrade_wire.go +++ b/seaweed-block/core/storage/chunk_upgrade_wire.go @@ -63,8 +63,13 @@ func (l *chunkLayerImpl) prepareUpgradePass(upgradedNow bool) error { // upgrade by this attach (its chunks are unknown) or when a page was // rebuilt at open. Chunks unknown only because they were written are // dirty: cuts take them. + // A store this start created has never held data: its chunks are all + // zero, known to need no compare (unknown only because the upgrade had no + // seed); the first cut takes them as candidates. A restart before that + // cut is not created this start and runs the pass. _, anyU := sh.firstUnknown() - if (!anyU && !sh.rebuilt) || (os.IsNotExist(statErr) && !upgradedNow && !sh.rebuilt) { + createdNow := upgradedNow && l.cfg.CreatedThisStart + if (!anyU && !sh.rebuilt) || (createdNow && !sh.rebuilt) || (os.IsNotExist(statErr) && !upgradedNow && !sh.rebuilt) { state := "none" if upgradedNow && l.cfg.CleanStop != nil { state = "seeded"