From dfe64e1658a36becc0581f6de79834b8b5da4a6f Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 23 Nov 2026 19:52:57 -0800 Subject: [PATCH 1/5] docs: state flat image references and shared-space retention Co-Authored-By: Codex --- seaweed-block/docs/design/agent-workspace-design.md | 2 +- seaweed-block/docs/design/invariants.md | 3 ++- seaweed-block/docs/operator-guide.md | 4 ++-- seaweed-block/docs/standalone-deployment.md | 12 +++++++++++- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/seaweed-block/docs/design/agent-workspace-design.md b/seaweed-block/docs/design/agent-workspace-design.md index 6efab16f51..d6b38299c2 100644 --- a/seaweed-block/docs/design/agent-workspace-design.md +++ b/seaweed-block/docs/design/agent-workspace-design.md @@ -103,7 +103,7 @@ Per volume, under the chunk base directory in the filer (`core/frontend/chunksto - Each HEAD is logically full: restore never chains deltas. - A flat (format 1) HEAD is upgraded at its next cut ([chunk manifests](../chunk-manifests.md)). In a host-side proxy, the root of a 10 GiB volume shrank from 261,531 bytes (flat) to 2,172 bytes (two-level) (§13). -**How versions share data.** A HEAD, a snapshot and a fork root are each a complete map from chunk index to chunk key. There is no backing chain and no per-layer bitmap that falls through to a parent, as qcow2 backing files or overlay layers have. +**How versions share data.** A HEAD, a snapshot and a fork root are each a complete map from chunk index to chunk key. There is no backing chain and no per-layer bitmap that falls through to a parent, as qcow2 backing files or overlay layers have. This is `INV-HEAD-FLAT-001`: immutable segment indirection is part of one image map, not a parent-image chain. - A cut uploads a new key only for a chunk whose content changed (§5, step 6) and rewrites only the segments that list such chunks. Every other index keeps its key, and every other segment its object, from the previous HEAD. A snapshot copies the root; a fork writes a new root with the same references (§6). Neither copies a chunk or a segment. - So a chunk that was not rewritten after a snapshot is the same object in that snapshot, in every later snapshot and in HEAD. A chunk rewritten after the snapshot has an old key that only the snapshot (and any earlier version that shares it) still references. - A read looks up one map: the root, one segment, one chunk. It never walks a chain, and deleting a version never requires merging another one. diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index e6252c26ab..7134d244ac 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -497,7 +497,7 @@ Tests: `TestSnapshotSchedule_SlotsAreOffsetPerVolume`, `_FailureIsTypedAndBacksO ## Part B. Invariant ledger -320 rows: 249 ACTIVE, 68 STUB, 3 ARCHIVED; 15 kept from the internal ledger, 303 new. +321 rows: 250 ACTIVE, 68 STUB, 3 ARCHIVED; 15 kept from the internal ledger, 306 new. The "Machine / transition" column refers to Part A. Notes under a table record what a row does not cover and, for kept rows, what was narrowed from the internal ledger. @@ -887,6 +887,7 @@ Notes: | ID | Statement | Machine / transition | Enforced in | Test | TLA+ property | Status | |---|---|---|---|---|---|---| +| `INV-HEAD-FLAT-001` | Every HEAD and snapshot root is a complete image map, directly or through immutable segments. Forks preserve original object owners; reads never fall through to a parent HEAD or snapshot, so successive forks add no backing-chain depth. | M6 snapshot: published → fork | `core/frontend/chunkstore/catalog.go` `Fork`; `core/frontend/chunkstore/manifest.go` `qualifyManifestKey`, `resolveManifest` | `TestFork_ForkOfForkKeepsOriginalOwner` (`core/frontend/chunkstore/catalog_test.go`); `TestManifest_ForkAfterParentSnapshotDelete` (`core/frontend/chunkstore/manifest_test.go`) | —; existing representation, no new transition | ACTIVE | | `INV-CHUNK-WRITE-ONCE-001` | Chunk and segment keys are write-once: a key that exists or once existed is refused, and a volume writes only its own keys. | M6 key: Bound | `core/frontend/chunkstore/chunk_remote.go` `putObject` | `TestChunkRemote_KeysAreWriteOnce` (`core/frontend/chunkstore/chunk_remote_test.go`); `TestChunkLayer_C5_ChunksAreImmutable` (`core/storage/chunk_layer_contract_test.go`) | — | ACTIVE | | `INV-MAINT-ONE-OWNER` | Only the current attached handle with matching replica/epoch/endpoint admits maintenance; one attached volume admits at most one pass; elapsed ticks coalesce and never enqueue catch-up work. | M8 Armed → Running | `provider_chunk.go` `chunkMaintenanceLoop` | `TestMaintenanceCoalescesWhileOnePassIsHeld`, `TestMaintenancePassHasOneDeadline`, `TestMaintenanceRejectsForeignLineageBeforeAdmission`, `TestMaintenanceSameHandleRearmsAfterJoinedStop` | `MaintenanceOwner` `OneOwner`, `CurrentHandleAtAdmission` | ACTIVE | | `INV-MAINT-SCOPE` | Per-volume GC traces foreign roots while restricting candidate reclamation, intent expiry and copy settlement to its volume; namespace coverage is not imported. | M8 scoped GC | `gc.go` `Collector.run`; `gc_copy.go` `SweepCopies`; `gc_execution.go` `ExecuteVolumeGC` | `TestVolumeGC_ForeignIntentRootsAndLocalCandidates`, `TestVolumeGC_DoesNotImportGlobalMark`, `TestVolumeGC_ForeignEligibleCaptureIntentStaysProtected`, `TestVolumeGC_ForeignEligibleCopyIsNotSettled` | `ScopedMaintenanceGC` `ForeignRootSurvives`, `ForeignCandidatesUntouched`, `OwnCoverageOnly` | ACTIVE | diff --git a/seaweed-block/docs/operator-guide.md b/seaweed-block/docs/operator-guide.md index 8adf89485c..98e32a3f93 100644 --- a/seaweed-block/docs/operator-guide.md +++ b/seaweed-block/docs/operator-guide.md @@ -135,10 +135,10 @@ default) can expire the host's slots; keep host clocks synchronized. - scheduled and manual snapshots; - deleting snapshots, and getting space back: - GC deletes the chunks after the grace (`--grace`, 1 hour by default), so a deleted snapshot's space is - reclaimed about 2 hours after the delete; + reclaimed about 2 hours after the delete unless still referenced by a snapshot, fork or restore; - then the asynchronous SeaweedFS vacuum compacts the volume files; - `ops chunk verify`; -- restoring a snapshot into a new, independent volume. +- forking a snapshot into a new volume that shares immutable objects, or restoring it into a new, independent volume. A snapshot can be refused with `host_slot_busy` / `no background slot` (retryable) while every host slot is held by other volumes' cuts; retry with the same request id. With many volumes on a host, a snapshot may wait for a slot: diff --git a/seaweed-block/docs/standalone-deployment.md b/seaweed-block/docs/standalone-deployment.md index a1a08f1e57..b7a0112f80 100644 --- a/seaweed-block/docs/standalone-deployment.md +++ b/seaweed-block/docs/standalone-deployment.md @@ -506,7 +506,7 @@ Space comes back in two steps. Neither is immediate. 1. **GC deletes the chunks**, after the grace. The grace is `sw-block ops chunk gc --grace`, **1 hour by default**. - A deleted snapshot keeps its chunks rooted for the grace after the delete. - A chunk is then reclaimed only once two complete GC marks, at least the grace apart, have both seen it unreferenced. - - With the default grace, a deleted snapshot's chunks are reclaimed about **2 hours** after the delete. That needs a GC pass at least 1 hour after the delete and another at least 1 hour after that. + - With the default grace, a deleted snapshot's unreferenced chunks are reclaimed about **2 hours** after the delete. Chunks still referenced by another snapshot, fork or restore remain live. That needs a GC pass at least 1 hour after the delete and another at least 1 hour after that. - Automatic GC is off by default (`--chunk-maintenance-gc`), so run the passes yourself: ```bash @@ -564,6 +564,16 @@ therefore see every chunk of every volume and snapshot as unreferenced. - Space is returned only by the two steps above (`sw-block ops chunk gc`, then a SeaweedFS vacuum). `volume.vacuum` is safe: it compacts needles that were already deleted. +### Forking a snapshot into a new volume + +A fork creates a new volume sharing the snapshot's immutable chunks and segments: + +```bash +sw-block ops chunk fork --source v1 --snapshot before-upgrade --target v2 --chunk-filer FILER --request-id fork-v2 +``` + +Keep the request id to retry an uncertain result. The new HEAD contains a complete image map; reads do not walk back through parent volumes or snapshots. A fork of a fork preserves the original object owners without adding a backing chain. Deleting the source snapshot does not delete objects still referenced by the fork. Use restore when the target must eventually own its data independently. + ### Restoring a snapshot into a new volume A restore makes a new, independent volume from a snapshot. The source volume and its snapshot can be deleted afterwards. From 6a4420983c8b8208815fa403c0ca3792e91e62f5 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 23 Nov 2026 19:59:06 -0800 Subject: [PATCH 2/5] test: prove flat grandchild reads and template source retirement Co-Authored-By: Codex --- .../template_retirement_integration_test.go | 61 +++++++++++++++ .../frontend/chunkstore/flat_head_test.go | 78 +++++++++++++++++++ seaweed-block/docs/design/invariants.md | 2 +- seaweed-block/docs/standalone-deployment.md | 38 +++++++++ 4 files changed, 178 insertions(+), 1 deletion(-) create mode 100644 seaweed-block/cmd/blockvolume/template_retirement_integration_test.go create mode 100644 seaweed-block/core/frontend/chunkstore/flat_head_test.go diff --git a/seaweed-block/cmd/blockvolume/template_retirement_integration_test.go b/seaweed-block/cmd/blockvolume/template_retirement_integration_test.go new file mode 100644 index 0000000000..5c86ba1be0 --- /dev/null +++ b/seaweed-block/cmd/blockvolume/template_retirement_integration_test.go @@ -0,0 +1,61 @@ +//go:build subprocess && chunkstore_integration + +package main_test + +import ( + "testing" + "time" +) + +// TestProcedureRetireTemplateSource runs the template-holder procedure: +// fork the seed, publish the template on the holder, fork a consumer, then +// seal/revoke/ACK and delete the original source. No GC grace is advanced; +// the final ordinary pass proves its command and reads, not reclamation. +func TestProcedureRetireTemplateSource(t *testing.T) { + env := startHandoffEnvWith(t, 1, []string{"template-holder", "consumer"}) + env.volExtra = []string{"--chunk-capture-interval", "0", "--chunk-snapshot-schedule", "off"} + source := env.start(t, "blockvolume-source", "s1") + e := env.adopt(t, source, "s1") + const template = "template-holder" + want := map[uint64][]byte{5: pattern("template-seed!!")} + env.writeBlock(t, "s1", 5, want[5]) + env.snapshot(t, "s1", "v1", "seed") + for _, step := range []struct{ source, snapshot, target string }{ + {"v1", "seed", template}, {template, "template-v1", "consumer"}, + } { + env.h.command(t, "ops", "chunk", "fork", "--source", step.source, "--snapshot", step.snapshot, + "--target", step.target, "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath, + "--request-id", "fork-"+step.target) + env.startTarget(t, step.target, "blockvolume-"+step.target) + env.requireBlocks(t, "n-"+step.target, 0, 16, want) + env.requireEdges(t, "n-"+step.target) + if step.target == template { + env.snapshot(t, "n-"+template, template, "template-v1") + } + } + g := env.seal(t, "s1", e) + env.revoke(t, e, g) + // The process must ACK and exit naturally; a signal would skip the ACK. + if err := source.wait(30 * time.Second); err != nil { + t.Fatalf("source did not exit naturally after revocation: %v", err) + } + env.waitAck(t, e, g) + env.deleteSnapshot(t, "v1", "seed") + out, stderr, code := env.volumeDelete(t, "delete-template-source") + requireDeleteCompleted(t, out, stderr, code, false) + env.requireDeletedForGood(t, "delete-template-source") + check := func() { + for _, vol := range []string{template, "consumer"} { + env.h.command(t, "ops", "chunk", "verify", "--volume", vol, "--all-snapshots", "--depth", "data", + "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath) + env.requireBlocks(t, "n-"+vol, 0, 16, want) + env.requireEdges(t, "n-"+vol) + } + env.requireSnapshotNames(t, template, "template-v1") + } + check() + env.h.command(t, "ops", "chunk", "gc", "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath, + "--master", env.h.masterAddr, "--apply") + check() + t.Logf("template source retired; %s/template-v1 and consumer read unchanged after a default-grace GC pass", template) +} diff --git a/seaweed-block/core/frontend/chunkstore/flat_head_test.go b/seaweed-block/core/frontend/chunkstore/flat_head_test.go new file mode 100644 index 0000000000..b83d032c70 --- /dev/null +++ b/seaweed-block/core/frontend/chunkstore/flat_head_test.go @@ -0,0 +1,78 @@ +package chunkstore + +import ( + "bytes" + "context" + "path" + "testing" +) + +func TestForkGrandchildReadsEveryBlockWithoutAncestorImages(t *testing.T) { + f, b, c, source := catalogFixture(t) + ctx := context.Background() + if _, err := c.CreateSnapshot(ctx, "v1", SnapshotRequest{Name: "seed", RequestID: "seed"}, source); err != nil { + t.Fatal(err) + } + if _, err := c.Fork(ctx, ForkRequest{Source: "v1", Snapshot: "seed", Target: "v2", RequestID: "parent"}); err != nil { + t.Fatal(err) + } + parent, err := NewChunkRemote(f, b, catBase+"/v2") + if err != nil { + t.Fatal(err) + } + ph, err := parent.GetHead(ctx) + if err != nil { + t.Fatal(err) + } + if _, err := c.CreateSnapshot(ctx, "v2", SnapshotRequest{Name: "template", RequestID: "template"}, ph); err != nil { + t.Fatal(err) + } + if _, err := c.Fork(ctx, ForkRequest{Source: "v2", Snapshot: "template", Target: "v3", RequestID: "grandchild"}); err != nil { + t.Fatal(err) + } + // Remove only ancestor image metadata, preserving immutable object bindings. + for vol, name := range map[string]string{"v1": "seed", "v2": "template"} { + attempt := snapPath(t, f, vol, name) + for _, entry := range []string{attempt, path.Join(catBase, vol, snapNamesDir, name), path.Join(catBase, vol, headName)} { + if err := f.DeleteEntry(ctx, path.Dir(entry), path.Base(entry), nil); err != nil { + t.Fatal(err) + } + if _, err := f.LookupEntry(ctx, path.Dir(entry), path.Base(entry)); err == nil { + t.Fatalf("ancestor image metadata remains: %s", entry) + } + } + } + // Open a fresh reader: no cached parent HEAD or snapshot can supply data. + grandchild, err := NewChunkRemote(f, b, catBase+"/v3") + if err != nil { + t.Fatal(err) + } + h, err := grandchild.GetHead(ctx) + if err != nil { + t.Fatal(err) + } + if len(h.Chunks) != 2 { + t.Fatalf("grandchild lost its complete image: %d chunks", len(h.Chunks)) + } + for block := uint64(0); block < uint64(catGeo.NumBlocks); block++ { + got := make([]byte, catGeo.BlockSize) + if ref, ok := h.Chunks[block/uint64(catGeo.ChunkBlocks)]; ok { + data, err := grandchild.Get(ctx, ref.Key) + if err != nil { + t.Fatalf("block %d: %v", block, err) + } + off := (block % uint64(catGeo.ChunkBlocks)) * uint64(catGeo.BlockSize) + copy(got, data[off:off+uint64(catGeo.BlockSize)]) + } + var fill byte + switch block / uint64(catGeo.ChunkBlocks) { + case 0: + fill = 0x10 + case 3: + fill = 0x13 + } + if !bytes.Equal(got, bytes.Repeat([]byte{fill}, int(catGeo.BlockSize))) { + t.Fatalf("block %d differs after ancestor images were removed", block) + } + } +} diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index 7134d244ac..b0d3c0580f 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -887,7 +887,7 @@ Notes: | ID | Statement | Machine / transition | Enforced in | Test | TLA+ property | Status | |---|---|---|---|---|---|---| -| `INV-HEAD-FLAT-001` | Every HEAD and snapshot root is a complete image map, directly or through immutable segments. Forks preserve original object owners; reads never fall through to a parent HEAD or snapshot, so successive forks add no backing-chain depth. | M6 snapshot: published → fork | `core/frontend/chunkstore/catalog.go` `Fork`; `core/frontend/chunkstore/manifest.go` `qualifyManifestKey`, `resolveManifest` | `TestFork_ForkOfForkKeepsOriginalOwner` (`core/frontend/chunkstore/catalog_test.go`); `TestManifest_ForkAfterParentSnapshotDelete` (`core/frontend/chunkstore/manifest_test.go`) | —; existing representation, no new transition | ACTIVE | +| `INV-HEAD-FLAT-001` | Every HEAD and snapshot root is a complete image map, directly or through immutable segments. Forks preserve original object owners; reads never fall through to a parent HEAD or snapshot, so successive forks add no backing-chain depth. | M6 snapshot: published → fork | `core/frontend/chunkstore/catalog.go` `Fork`; `core/frontend/chunkstore/manifest.go` `qualifyManifestKey`, `resolveManifest` | `TestForkGrandchildReadsEveryBlockWithoutAncestorImages` (`core/frontend/chunkstore/flat_head_test.go`); `TestFork_ForkOfForkKeepsOriginalOwner` (`core/frontend/chunkstore/catalog_test.go`); `TestManifest_ForkAfterParentSnapshotDelete` (`core/frontend/chunkstore/manifest_test.go`) | —; existing representation, no new transition | ACTIVE | | `INV-CHUNK-WRITE-ONCE-001` | Chunk and segment keys are write-once: a key that exists or once existed is refused, and a volume writes only its own keys. | M6 key: Bound | `core/frontend/chunkstore/chunk_remote.go` `putObject` | `TestChunkRemote_KeysAreWriteOnce` (`core/frontend/chunkstore/chunk_remote_test.go`); `TestChunkLayer_C5_ChunksAreImmutable` (`core/storage/chunk_layer_contract_test.go`) | — | ACTIVE | | `INV-MAINT-ONE-OWNER` | Only the current attached handle with matching replica/epoch/endpoint admits maintenance; one attached volume admits at most one pass; elapsed ticks coalesce and never enqueue catch-up work. | M8 Armed → Running | `provider_chunk.go` `chunkMaintenanceLoop` | `TestMaintenanceCoalescesWhileOnePassIsHeld`, `TestMaintenancePassHasOneDeadline`, `TestMaintenanceRejectsForeignLineageBeforeAdmission`, `TestMaintenanceSameHandleRearmsAfterJoinedStop` | `MaintenanceOwner` `OneOwner`, `CurrentHandleAtAdmission` | ACTIVE | | `INV-MAINT-SCOPE` | Per-volume GC traces foreign roots while restricting candidate reclamation, intent expiry and copy settlement to its volume; namespace coverage is not imported. | M8 scoped GC | `gc.go` `Collector.run`; `gc_copy.go` `SweepCopies`; `gc_execution.go` `ExecuteVolumeGC` | `TestVolumeGC_ForeignIntentRootsAndLocalCandidates`, `TestVolumeGC_DoesNotImportGlobalMark`, `TestVolumeGC_ForeignEligibleCaptureIntentStaysProtected`, `TestVolumeGC_ForeignEligibleCopyIsNotSettled` | `ScopedMaintenanceGC` `ForeignRootSurvives`, `ForeignCandidatesUntouched`, `OwnCoverageOnly` | ACTIVE | diff --git a/seaweed-block/docs/standalone-deployment.md b/seaweed-block/docs/standalone-deployment.md index b7a0112f80..06e0c37ef5 100644 --- a/seaweed-block/docs/standalone-deployment.md +++ b/seaweed-block/docs/standalone-deployment.md @@ -574,6 +574,44 @@ sw-block ops chunk fork --source v1 --snapshot before-upgrade --target v2 --chun Keep the request id to retry an uncertain result. The new HEAD contains a complete image map; reads do not walk back through parent volumes or snapshots. A fork of a fork preserves the original object owners without adding a backing chain. Deleting the source snapshot does not delete objects still referenced by the fork. Use restore when the target must eventually own its data independently. +### Retiring the source of a template + +A template is an ordinary immutable snapshot, not a separate volume kind. Keep the volume holding an offered template snapshot: volume deletion refuses while any snapshot name exists. To retire the original source instead, first move the template image into a dedicated holder using existing fork and snapshot operations. + +Prerequisites: `v1` is serving, its only snapshot is `seed`, and the standalone cluster spec has new volume placements for `template-holder` and `consumer`. Neither target blockvolume has started yet. Use the same filer and chunk namespace throughout. + +1. Create the holder: + + ```bash + sw-block ops chunk fork --source v1 --snapshot seed --target template-holder --chunk-filer FILER --request-id fork-template-holder + ``` + +2. Start `template-holder` with the normal standalone blockvolume command and its own volume id, endpoints and local root. Wait for its frontend readiness; read back the seed's known data before proceeding. Take the template snapshot: + + ```bash + sw-block ops chunk snapshot --volume template-holder --status-addr HOLDER_STATUS --name template-v1 + ``` + +3. Create a consumer, start its blockvolume on its own placement and root, and verify its known data: + + ```bash + sw-block ops chunk fork --source template-holder --snapshot template-v1 --target consumer --chunk-filer FILER --request-id fork-consumer + ``` + +4. Stop the source writer. Follow [Delete a volume](volume-lifecycle.md#delete-a-volume) for `v1`: plain detach, revoke its exact replica/epoch/sealed generation, wait for its recorded ACK and natural exit, delete `seed`, then delete `v1`. Do not signal the process in place of waiting for its ACK. Require the completed delete answer and `show` state `deleted` before continuing. + +5. Verify both surviving images, including the holder's template snapshot: + + ```bash + sw-block ops chunk verify --volume template-holder --all-snapshots --depth data --chunk-filer FILER + sw-block ops chunk verify --volume consumer --all-snapshots --depth data --chunk-filer FILER + sw-block ops chunk gc --chunk-filer FILER --master MASTER --apply + ``` + + Read back the known data again and repeat both verify commands after the pass. This immediate pass is not a reclamation measurement: its default grace has not elapsed. Continue namespace-wide GC as described above for unused objects; attached-volume maintenance alone does not collect a deleted source's namespace. + +Keep `template-holder/template-v1` while it is offered for new consumers. Retiring that snapshot later does not delete objects still referenced by existing consumers. Deleting the holder volume itself still requires the ordinary seal/revoke/ACK and snapshot-deletion procedure; do not remove its backing filer directory or object bindings by hand. + ### Restoring a snapshot into a new volume A restore makes a new, independent volume from a snapshot. The source volume and its snapshot can be deleted afterwards. From a7bac0b2ae2a1c7eb3ac1ddec6b72d0b0c8c9c06 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 23 Nov 2026 19:59:19 -0800 Subject: [PATCH 3/5] test: use an exact block pattern in the retirement procedure Co-Authored-By: Codex --- .../cmd/blockvolume/template_retirement_integration_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seaweed-block/cmd/blockvolume/template_retirement_integration_test.go b/seaweed-block/cmd/blockvolume/template_retirement_integration_test.go index 5c86ba1be0..9d19893679 100644 --- a/seaweed-block/cmd/blockvolume/template_retirement_integration_test.go +++ b/seaweed-block/cmd/blockvolume/template_retirement_integration_test.go @@ -17,7 +17,7 @@ func TestProcedureRetireTemplateSource(t *testing.T) { source := env.start(t, "blockvolume-source", "s1") e := env.adopt(t, source, "s1") const template = "template-holder" - want := map[uint64][]byte{5: pattern("template-seed!!")} + want := map[uint64][]byte{5: pattern("template-seed!!!")} env.writeBlock(t, "s1", 5, want[5]) env.snapshot(t, "s1", "v1", "seed") for _, step := range []struct{ source, snapshot, target string }{ From 7ea9b7ab02289b00186ca96ca20a6d9ebfad4edf Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 23 Nov 2026 20:01:10 -0800 Subject: [PATCH 4/5] test: bound template verification in the procedure and guide Co-Authored-By: Codex --- .../cmd/blockvolume/template_retirement_integration_test.go | 2 +- seaweed-block/docs/standalone-deployment.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/seaweed-block/cmd/blockvolume/template_retirement_integration_test.go b/seaweed-block/cmd/blockvolume/template_retirement_integration_test.go index 9d19893679..c4da02ffb6 100644 --- a/seaweed-block/cmd/blockvolume/template_retirement_integration_test.go +++ b/seaweed-block/cmd/blockvolume/template_retirement_integration_test.go @@ -46,7 +46,7 @@ func TestProcedureRetireTemplateSource(t *testing.T) { env.requireDeletedForGood(t, "delete-template-source") check := func() { for _, vol := range []string{template, "consumer"} { - env.h.command(t, "ops", "chunk", "verify", "--volume", vol, "--all-snapshots", "--depth", "data", + env.h.command(t, "ops", "chunk", "verify", "--volume", vol, "--all-snapshots", "--depth", "data", "--timeout", "2m", "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath) env.requireBlocks(t, "n-"+vol, 0, 16, want) env.requireEdges(t, "n-"+vol) diff --git a/seaweed-block/docs/standalone-deployment.md b/seaweed-block/docs/standalone-deployment.md index 06e0c37ef5..c04d06e2e4 100644 --- a/seaweed-block/docs/standalone-deployment.md +++ b/seaweed-block/docs/standalone-deployment.md @@ -603,8 +603,8 @@ Prerequisites: `v1` is serving, its only snapshot is `seed`, and the standalone 5. Verify both surviving images, including the holder's template snapshot: ```bash - sw-block ops chunk verify --volume template-holder --all-snapshots --depth data --chunk-filer FILER - sw-block ops chunk verify --volume consumer --all-snapshots --depth data --chunk-filer FILER + sw-block ops chunk verify --volume template-holder --all-snapshots --depth data --timeout 2m --chunk-filer FILER + sw-block ops chunk verify --volume consumer --all-snapshots --depth data --timeout 2m --chunk-filer FILER sw-block ops chunk gc --chunk-filer FILER --master MASTER --apply ``` From ca7819fab23d89219bf8896d6f7dc59ca637ab12 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 23 Nov 2026 20:04:58 -0800 Subject: [PATCH 5/5] docs: separate the template retirement procedure for review Co-Authored-By: Codex --- .../template_retirement_integration_test.go | 61 ------------------- seaweed-block/docs/standalone-deployment.md | 38 ------------ 2 files changed, 99 deletions(-) delete mode 100644 seaweed-block/cmd/blockvolume/template_retirement_integration_test.go diff --git a/seaweed-block/cmd/blockvolume/template_retirement_integration_test.go b/seaweed-block/cmd/blockvolume/template_retirement_integration_test.go deleted file mode 100644 index c4da02ffb6..0000000000 --- a/seaweed-block/cmd/blockvolume/template_retirement_integration_test.go +++ /dev/null @@ -1,61 +0,0 @@ -//go:build subprocess && chunkstore_integration - -package main_test - -import ( - "testing" - "time" -) - -// TestProcedureRetireTemplateSource runs the template-holder procedure: -// fork the seed, publish the template on the holder, fork a consumer, then -// seal/revoke/ACK and delete the original source. No GC grace is advanced; -// the final ordinary pass proves its command and reads, not reclamation. -func TestProcedureRetireTemplateSource(t *testing.T) { - env := startHandoffEnvWith(t, 1, []string{"template-holder", "consumer"}) - env.volExtra = []string{"--chunk-capture-interval", "0", "--chunk-snapshot-schedule", "off"} - source := env.start(t, "blockvolume-source", "s1") - e := env.adopt(t, source, "s1") - const template = "template-holder" - want := map[uint64][]byte{5: pattern("template-seed!!!")} - env.writeBlock(t, "s1", 5, want[5]) - env.snapshot(t, "s1", "v1", "seed") - for _, step := range []struct{ source, snapshot, target string }{ - {"v1", "seed", template}, {template, "template-v1", "consumer"}, - } { - env.h.command(t, "ops", "chunk", "fork", "--source", step.source, "--snapshot", step.snapshot, - "--target", step.target, "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath, - "--request-id", "fork-"+step.target) - env.startTarget(t, step.target, "blockvolume-"+step.target) - env.requireBlocks(t, "n-"+step.target, 0, 16, want) - env.requireEdges(t, "n-"+step.target) - if step.target == template { - env.snapshot(t, "n-"+template, template, "template-v1") - } - } - g := env.seal(t, "s1", e) - env.revoke(t, e, g) - // The process must ACK and exit naturally; a signal would skip the ACK. - if err := source.wait(30 * time.Second); err != nil { - t.Fatalf("source did not exit naturally after revocation: %v", err) - } - env.waitAck(t, e, g) - env.deleteSnapshot(t, "v1", "seed") - out, stderr, code := env.volumeDelete(t, "delete-template-source") - requireDeleteCompleted(t, out, stderr, code, false) - env.requireDeletedForGood(t, "delete-template-source") - check := func() { - for _, vol := range []string{template, "consumer"} { - env.h.command(t, "ops", "chunk", "verify", "--volume", vol, "--all-snapshots", "--depth", "data", "--timeout", "2m", - "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath) - env.requireBlocks(t, "n-"+vol, 0, 16, want) - env.requireEdges(t, "n-"+vol) - } - env.requireSnapshotNames(t, template, "template-v1") - } - check() - env.h.command(t, "ops", "chunk", "gc", "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath, - "--master", env.h.masterAddr, "--apply") - check() - t.Logf("template source retired; %s/template-v1 and consumer read unchanged after a default-grace GC pass", template) -} diff --git a/seaweed-block/docs/standalone-deployment.md b/seaweed-block/docs/standalone-deployment.md index c04d06e2e4..b7a0112f80 100644 --- a/seaweed-block/docs/standalone-deployment.md +++ b/seaweed-block/docs/standalone-deployment.md @@ -574,44 +574,6 @@ sw-block ops chunk fork --source v1 --snapshot before-upgrade --target v2 --chun Keep the request id to retry an uncertain result. The new HEAD contains a complete image map; reads do not walk back through parent volumes or snapshots. A fork of a fork preserves the original object owners without adding a backing chain. Deleting the source snapshot does not delete objects still referenced by the fork. Use restore when the target must eventually own its data independently. -### Retiring the source of a template - -A template is an ordinary immutable snapshot, not a separate volume kind. Keep the volume holding an offered template snapshot: volume deletion refuses while any snapshot name exists. To retire the original source instead, first move the template image into a dedicated holder using existing fork and snapshot operations. - -Prerequisites: `v1` is serving, its only snapshot is `seed`, and the standalone cluster spec has new volume placements for `template-holder` and `consumer`. Neither target blockvolume has started yet. Use the same filer and chunk namespace throughout. - -1. Create the holder: - - ```bash - sw-block ops chunk fork --source v1 --snapshot seed --target template-holder --chunk-filer FILER --request-id fork-template-holder - ``` - -2. Start `template-holder` with the normal standalone blockvolume command and its own volume id, endpoints and local root. Wait for its frontend readiness; read back the seed's known data before proceeding. Take the template snapshot: - - ```bash - sw-block ops chunk snapshot --volume template-holder --status-addr HOLDER_STATUS --name template-v1 - ``` - -3. Create a consumer, start its blockvolume on its own placement and root, and verify its known data: - - ```bash - sw-block ops chunk fork --source template-holder --snapshot template-v1 --target consumer --chunk-filer FILER --request-id fork-consumer - ``` - -4. Stop the source writer. Follow [Delete a volume](volume-lifecycle.md#delete-a-volume) for `v1`: plain detach, revoke its exact replica/epoch/sealed generation, wait for its recorded ACK and natural exit, delete `seed`, then delete `v1`. Do not signal the process in place of waiting for its ACK. Require the completed delete answer and `show` state `deleted` before continuing. - -5. Verify both surviving images, including the holder's template snapshot: - - ```bash - sw-block ops chunk verify --volume template-holder --all-snapshots --depth data --timeout 2m --chunk-filer FILER - sw-block ops chunk verify --volume consumer --all-snapshots --depth data --timeout 2m --chunk-filer FILER - sw-block ops chunk gc --chunk-filer FILER --master MASTER --apply - ``` - - Read back the known data again and repeat both verify commands after the pass. This immediate pass is not a reclamation measurement: its default grace has not elapsed. Continue namespace-wide GC as described above for unused objects; attached-volume maintenance alone does not collect a deleted source's namespace. - -Keep `template-holder/template-v1` while it is offered for new consumers. Retiring that snapshot later does not delete objects still referenced by existing consumers. Deleting the holder volume itself still requires the ordinary seal/revoke/ACK and snapshot-deletion procedure; do not remove its backing filer directory or object bindings by hand. - ### Restoring a snapshot into a new volume A restore makes a new, independent volume from a snapshot. The source volume and its snapshot can be deleted afterwards.