From 565a91b6dc7addb8c549161b60ed4fabbd3a2f22 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 30 Nov 2026 11:25:55 -0800 Subject: [PATCH] durable: red tests, the removed experimental engines are refused typed v1.1 removes the experimental engines smartwal and parallel-walstore. These controls fail on main, where both still open: - a volume carrying a removed engine's magic (SWAW; SWPW at offset 0, or only at 4096 when the first parallel-walstore header is torn) is refused with the typed RemovedEngineError under the auto and the walstore selector, and the file stays byte-identical; - the removed names are refused typed by the provider, by blockvolume --durable-impl, and by the Kubernetes launcher. The seam adds the error type and its advice ("created by a removed experimental engine; copy the data to a walstore volume with v1.0.x first"); RemovedEngineName refuses nothing yet. Co-Authored-By: Claude Opus 5.5 --- .../blockvolume/durable_impl_default_test.go | 21 ++++++- .../core/frontend/durable/provider.go | 33 ++++++++++ .../durable/provider_auto_impl_test.go | 61 +++++++++++++++++++ .../core/launcher/k8s_renderer_test.go | 14 +++++ 4 files changed, 128 insertions(+), 1 deletion(-) diff --git a/seaweed-block/cmd/blockvolume/durable_impl_default_test.go b/seaweed-block/cmd/blockvolume/durable_impl_default_test.go index 87147c8a77..1a0bab9561 100644 --- a/seaweed-block/cmd/blockvolume/durable_impl_default_test.go +++ b/seaweed-block/cmd/blockvolume/durable_impl_default_test.go @@ -1,6 +1,12 @@ package main -import "testing" +import ( + "errors" + "strings" + "testing" + + "github.com/seaweedfs/seaweed-block/core/frontend/durable" +) // --durable-impl defaults to empty (auto): new volumes are walstore, and an // existing volume opens with its on-disk format. smartwal is experimental @@ -31,3 +37,16 @@ func TestBlockvolumeDurableImplExplicitValues(t *testing.T) { t.Fatal("--durable-impl=bogus accepted") } } + +// The removed experimental engines' names are refused typed, with the advice +// an operator acts on; nothing selects them any more. +func TestBlockvolumeRefusesRemovedEngineNames(t *testing.T) { + for _, impl := range []string{"smartwal", "parallel-walstore"} { + args := append(phase150RequiredBlockvolumeArgs(), "--durable-root=/tmp/sw-block", "--durable-impl="+impl) + _, err := parseFlags(args) + var removed *durable.RemovedEngineError + if !errors.As(err, &removed) || string(removed.Engine) != impl || !strings.Contains(err.Error(), durable.RemovedEngineAdvice) { + t.Fatalf("--durable-impl=%s: err=%v, want the typed removed-engine refusal", impl, err) + } + } +} diff --git a/seaweed-block/core/frontend/durable/provider.go b/seaweed-block/core/frontend/durable/provider.go index f1221dd525..0a00bd16c8 100644 --- a/seaweed-block/core/frontend/durable/provider.go +++ b/seaweed-block/core/frontend/durable/provider.go @@ -79,6 +79,39 @@ const DefaultChunkBlocks = 1024 // tests can errors.Is on it. var ErrImplKindMismatch = errors.New("durable: impl kind mismatch between selector and on-disk superblock") +// RemovedEngineAdvice is what an operator is told about a volume created by an +// experimental engine that this release no longer carries (smartwal, +// parallel-walstore): it does not open, and nothing converts it in place. +const RemovedEngineAdvice = "created by a removed experimental engine; copy the data to a walstore volume with v1.0.x first" + +// removedEngines maps each removed experimental engine's selector name to its +// on-disk magic. Only the names and magics remain, so both are refused typed. +var removedEngines = map[ImplName]string{"smartwal": "SWAW", "parallel-walstore": "SWPW"} + +// parallelHeaderSlot1 is the offset of a parallel-walstore volume's second +// header, which carries the same magic: a volume whose first header is torn is +// still recognised (and refused) by it. +const parallelHeaderSlot1 = 4096 + +// RemovedEngineError refuses a selector naming a removed experimental engine +// (Path empty), or a volume such an engine created (Path set). Match it with +// errors.As. +type RemovedEngineError struct { + Engine ImplName + Path string +} + +func (e *RemovedEngineError) Error() string { + if e.Path != "" { + return fmt.Sprintf("durable: %s was %s (engine %s)", e.Path, RemovedEngineAdvice, e.Engine) + } + return fmt.Sprintf("durable: impl %q is a removed experimental engine; a volume it %s", e.Engine, RemovedEngineAdvice) +} + +// RemovedEngineName returns the typed refusal for a selector naming a removed +// experimental engine, or nil. (Seam: nothing is refused yet.) +func RemovedEngineName(name string) error { return nil } + // ErrVolumeNotOpen is returned by RecoverVolume / Close when the // volumeID has not been Open'd. var ErrVolumeNotOpen = errors.New("durable: volume not opened") diff --git a/seaweed-block/core/frontend/durable/provider_auto_impl_test.go b/seaweed-block/core/frontend/durable/provider_auto_impl_test.go index 5d2e3112af..37d9023650 100644 --- a/seaweed-block/core/frontend/durable/provider_auto_impl_test.go +++ b/seaweed-block/core/frontend/durable/provider_auto_impl_test.go @@ -7,6 +7,7 @@ import ( "io" "os" "path/filepath" + "strings" "testing" "github.com/seaweedfs/seaweed-block/core/frontend" @@ -154,3 +155,63 @@ func TestDurableProvider_AutoRefusesUnknownOnDiskFormat(t *testing.T) { t.Fatalf("auto Open of an unrecognized file: %v, want ErrImplKindMismatch", err) } } + +// removedEngineFile writes a volume file carrying a removed engine's magic: +// at offset 0, or (a parallel-walstore volume whose first header is torn) +// only in its second header at 4096. +func removedEngineFile(t *testing.T, root string, magic0, magic4096 string) []byte { + t.Helper() + buf := bytes.Repeat([]byte{0xA5}, 8192) + copy(buf[0:4], magic0) + copy(buf[4096:4100], magic4096) + if err := os.WriteFile(filepath.Join(root, "v1.bin"), buf, 0o600); err != nil { + t.Fatal(err) + } + return buf +} + +// A volume created by a removed experimental engine is refused typed, with +// the advice an operator acts on, under the auto and the walstore selector +// alike (no selector coerces it), and the refusal never writes the file. +func TestDurableProvider_RefusesRemovedEngineVolumes(t *testing.T) { + for _, c := range []struct { + name, magic0, magic4096 string + engine durable.ImplName + }{ + {"smartwal", "SWAW", "", "smartwal"}, + {"parallel-walstore", "SWPW", "SWPW", "parallel-walstore"}, + {"parallel-walstore torn first header", "BAD!", "SWPW", "parallel-walstore"}, + } { + for _, sel := range []durable.ImplName{durable.ImplAuto, durable.ImplWALStore} { + t.Run(c.name+"/selector="+string(sel), func(t *testing.T) { + root := t.TempDir() + before := removedEngineFile(t, root, c.magic0, c.magic4096) + p := autoProvider(t, root, sel) + _, err := p.Open(context.Background(), "v1") + var removed *durable.RemovedEngineError + if !errors.As(err, &removed) || removed.Engine != c.engine || removed.Path == "" || !strings.Contains(err.Error(), durable.RemovedEngineAdvice) { + t.Fatalf("Open: err=%v, want the typed removed-engine refusal for %s", err, c.engine) + } + if err := p.Close(); err != nil { + t.Fatal(err) + } + after, rerr := os.ReadFile(filepath.Join(root, "v1.bin")) + if rerr != nil || !bytes.Equal(before, after) { + t.Fatalf("the refused volume file changed (err %v)", rerr) + } + }) + } + } +} + +// The removed engines' selector names are refused typed when a provider is +// built, before any volume is touched. +func TestDurableProvider_RefusesRemovedEngineNames(t *testing.T) { + for _, name := range []durable.ImplName{"smartwal", "parallel-walstore"} { + _, err := durable.NewDurableProvider(durable.ProviderConfig{Impl: name, StorageRoot: t.TempDir(), BlockSize: 4096, NumBlocks: 16}, newStubView(healthyProj(frontend.Identity{VolumeID: "v1", ReplicaID: "r1", Epoch: 1, EndpointVersion: 1}))) + var removed *durable.RemovedEngineError + if !errors.As(err, &removed) || removed.Engine != name || removed.Path != "" || !strings.Contains(err.Error(), durable.RemovedEngineAdvice) { + t.Fatalf("Impl %q: err=%v, want the typed removed-engine refusal", name, err) + } + } +} diff --git a/seaweed-block/core/launcher/k8s_renderer_test.go b/seaweed-block/core/launcher/k8s_renderer_test.go index 72963477aa..11006076bd 100644 --- a/seaweed-block/core/launcher/k8s_renderer_test.go +++ b/seaweed-block/core/launcher/k8s_renderer_test.go @@ -786,3 +786,17 @@ func TestK8sRenderer_MasterTLSMountsTheServersNodeSecret(t *testing.T) { t.Fatalf("external status with master TLS: %v, want refused", err) } } + +// The removed experimental engines are refused with the advice an operator +// acts on; no manifest selects them. +func TestK8sRendererRefusesRemovedEngines(t *testing.T) { + for _, impl := range []string{"smartwal", "parallel-walstore"} { + _, err := RenderBlockVolumeDeployments(sampleWorkloadPlan(), K8sRenderConfig{ + MasterAddr: "m:9333", + DurableImpl: impl, + }) + if err == nil || !strings.Contains(err.Error(), "removed experimental engine") || !strings.Contains(err.Error(), "copy the data to a walstore volume with v1.0.x first") { + t.Fatalf("DurableImpl %q: err=%v, want the removed-engine refusal", impl, err) + } + } +}