From 3de99a839c49be879136e6f96e4a3baa89345bfd Mon Sep 17 00:00:00 2001 From: pingqiu Date: Wed, 25 Nov 2026 19:09:59 -0800 Subject: [PATCH 1/3] feat: resolve standalone volume layout identity through the master --- seaweed-block/cmd/sw-block/main.go | 5 +- seaweed-block/cmd/sw-block/volume_resolve.go | 41 +++++++++ .../cmd/sw-block/volume_resolve_test.go | 91 +++++++++++++++++++ seaweed-block/docs/standalone-deployment.md | 22 +++++ 4 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 seaweed-block/cmd/sw-block/volume_resolve.go create mode 100644 seaweed-block/cmd/sw-block/volume_resolve_test.go diff --git a/seaweed-block/cmd/sw-block/main.go b/seaweed-block/cmd/sw-block/main.go index 81bfc7e5dd..8b4230e9e9 100644 --- a/seaweed-block/cmd/sw-block/main.go +++ b/seaweed-block/cmd/sw-block/main.go @@ -82,7 +82,7 @@ func run(args []string, stdout, stderr io.Writer) int { return ops.VolumeStatusExitInvalid } if len(args) < 2 { - fmt.Fprintln(stderr, "sw-block: expected subcommand ops status|inventory|list|cluster|volumes|describe|timeline|explain|report|dashboard|generate-helm-values|operator-status|lifecycle-owner|authority-executor|rebuild-target-owner|failback-target-owner|failback-executor|frontend-publication-target-owner|frontend-publication-executor|chunk|volume-unheld|workspace") + fmt.Fprintln(stderr, "sw-block: expected subcommand ops status|inventory|list|cluster|volumes|describe|timeline|explain|report|dashboard|generate-helm-values|operator-status|lifecycle-owner|authority-executor|rebuild-target-owner|failback-target-owner|failback-executor|frontend-publication-target-owner|frontend-publication-executor|chunk|volume|volume-unheld|workspace") usage(stderr) return ops.VolumeStatusExitInvalid } @@ -125,6 +125,8 @@ func run(args []string, stdout, stderr io.Writer) int { return runOpsFrontendPublicationExecutor(args[2:], stdout, stderr) case "chunk": return runOpsChunk(args[2:], stdout, stderr) + case "volume": + return runOpsVolume(args[2:], stdout, stderr) case "volume-unheld": return runOpsVolumeUnheld(args[2:], stdout, stderr) case "workspace": @@ -2296,6 +2298,7 @@ func usage(w io.Writer) { fmt.Fprintln(w, " sw-block ops chunk show --volume --chunk-filer [--chunk-path /swblock/chunks]") fmt.Fprintln(w, " sw-block ops chunk verify --volume --chunk-filer [--chunk-path /swblock/chunks] [--depth meta|bindings|data] [--orphans] [--timeout ]") fmt.Fprintln(w, " (read-only; every root HEAD names is checked; exit 0 clean, 3 findings, 1 incomplete; --depth data needs --timeout)") + fmt.Fprintln(w, " sw-block ops volume resolve --master [--timeout 10s] (prints the master layout id)") fmt.Fprintln(w, " sw-block ops volume-unheld --path (exit 0: no process on this host holds it; local filesystems only)") fmt.Fprintln(w, " sw-block ops workspace force-move --master --volume --target-host --target-data --target-ctrl --request-id --confirm-forced @ [--dry-run]") fmt.Fprintln(w, " sw-block ops workspace lost-range --master --volume [--request-id ] (authority only; no bypass: see `sw-block ops workspace help`)") diff --git a/seaweed-block/cmd/sw-block/volume_resolve.go b/seaweed-block/cmd/sw-block/volume_resolve.go new file mode 100644 index 0000000000..91bb8c58ca --- /dev/null +++ b/seaweed-block/cmd/sw-block/volume_resolve.go @@ -0,0 +1,41 @@ +package main + +import ( + "context" + "flag" + "fmt" + "io" + "time" + + "github.com/seaweedfs/seaweed-block/core/ops" +) + +// runOpsVolume exposes the same master name binding used by ops chunk. +func runOpsVolume(args []string, stdout, stderr io.Writer) int { + const usage = "usage: sw-block ops volume resolve --master [--timeout 10s] " + if len(args) == 0 || args[0] != "resolve" { + fmt.Fprintln(stderr, usage) + return ops.VolumeStatusExitInvalid + } + fs := flag.NewFlagSet("sw-block ops volume resolve", flag.ContinueOnError) + fs.SetOutput(stderr) + fs.Usage = func() { fmt.Fprintln(stderr, usage) } + master := fs.String("master", "", "master gRPC address") + timeout := fs.Duration("timeout", 10*time.Second, "master query timeout") + if err := fs.Parse(args[1:]); err != nil { + return ops.VolumeStatusExitInvalid + } + if *master == "" || *timeout <= 0 || fs.NArg() != 1 || fs.Arg(0) == "" { + fmt.Fprintln(stderr, usage) + return ops.VolumeStatusExitInvalid + } + ctx, cancel := context.WithTimeout(context.Background(), *timeout) + defer cancel() + id, err := resolveVolumeID(ctx, *master, fs.Arg(0)) + if err != nil { + fmt.Fprintf(stderr, "sw-block ops volume resolve: %v\n", err) + return ops.VolumeStatusExitInvalid + } + fmt.Fprintln(stdout, id.String()) + return ops.VolumeStatusExitOK +} diff --git a/seaweed-block/cmd/sw-block/volume_resolve_test.go b/seaweed-block/cmd/sw-block/volume_resolve_test.go new file mode 100644 index 0000000000..f60d575a1f --- /dev/null +++ b/seaweed-block/cmd/sw-block/volume_resolve_test.go @@ -0,0 +1,91 @@ +package main + +import ( + "bytes" + "context" + "net" + "sync" + "testing" + + "github.com/seaweedfs/seaweed-block/core/rpc/control" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +type volumeResolveServer struct { + control.UnimplementedLifecycleServiceServer + mu sync.Mutex + reply *control.CreateVolumeResponse + err error + names []string +} + +func (s *volumeResolveServer) GetVolume(_ context.Context, q *control.GetLifecycleVolumeRequest) (*control.CreateVolumeResponse, error) { + s.mu.Lock() + s.names = append(s.names, q.GetVolumeId()) + s.mu.Unlock() + return s.reply, s.err +} +func serveVolumeResolver(t *testing.T, s *volumeResolveServer) string { + t.Helper() + lis, err := net.Listen("tcp", "127.0.0.1:0") + if err != nil { + t.Fatal(err) + } + server := grpc.NewServer() + control.RegisterLifecycleServiceServer(server, s) + go func() { _ = server.Serve(lis) }() + t.Cleanup(server.Stop) + return lis.Addr().String() +} +func TestOpsVolumeResolvePrintsOnlyMasterLayoutID(t *testing.T) { + const id = "1234567890abcdef1234567890abcdef" + s := &volumeResolveServer{reply: &control.CreateVolumeResponse{VolumeId: "v1", LayoutId: id}} + addr := serveVolumeResolver(t, s) + var out, errout bytes.Buffer + code := run([]string{"ops", "volume", "resolve", "--master", addr, "v1"}, &out, &errout) + if code != 0 || out.String() != id+"\n" || errout.Len() != 0 { + t.Fatalf("code=%d stdout=%q stderr=%q", code, &out, &errout) + } + s.mu.Lock() + defer s.mu.Unlock() + if len(s.names) != 1 || s.names[0] != "v1" { + t.Fatalf("resolved names=%v", s.names) + } +} + +func TestOpsVolumeResolveRefusesMissingOrForeignIdentity(t *testing.T) { + for _, tc := range []struct { + name, volume, id string + err error + }{ + {"missing", "", "", status.Error(codes.NotFound, "no such volume")}, + {"unavailable", "", "", status.Error(codes.Unavailable, "master unavailable")}, + {"invalid-id", "v1", "bad", nil}, + {"wrong-name", "v2", "1234567890abcdef1234567890abcdef", nil}, + } { + t.Run(tc.name, func(t *testing.T) { + s := &volumeResolveServer{reply: &control.CreateVolumeResponse{VolumeId: tc.volume, LayoutId: tc.id}, err: tc.err} + addr := serveVolumeResolver(t, s) + var out, errout bytes.Buffer + code := run([]string{"ops", "volume", "resolve", "--master", addr, "v1"}, &out, &errout) + if code != 2 || out.Len() != 0 || errout.Len() == 0 { + t.Fatalf("code=%d stdout=%q stderr=%q", code, &out, &errout) + } + }) + } +} +func TestOpsVolumeResolveRequiresOneNameAndBoundedQuery(t *testing.T) { + for _, args := range [][]string{ + {}, {"other"}, {"resolve", "v1"}, {"resolve", "--master", "unused"}, + {"resolve", "--master", "unused", "v1", "v2"}, + {"resolve", "--master", "unused", "--timeout", "0s", "v1"}, + } { + var out, errout bytes.Buffer + code := run(append([]string{"ops", "volume"}, args...), &out, &errout) + if code != 2 || out.Len() != 0 || errout.Len() == 0 { + t.Fatalf("args=%v code=%d stdout=%q stderr=%q", args, code, &out, &errout) + } + } +} diff --git a/seaweed-block/docs/standalone-deployment.md b/seaweed-block/docs/standalone-deployment.md index fe88d55bc4..2dab348f0f 100644 --- a/seaweed-block/docs/standalone-deployment.md +++ b/seaweed-block/docs/standalone-deployment.md @@ -176,6 +176,28 @@ that store. This release has no `sw-block` command that creates that record. Che volume`. A move target must also be a registered node, or the move is refused with `move target node "s2" is not registered`. +### Resolve the LOCAL volume's layout id + +Before starting a standalone `walstore-chunk` blockvolume for an existing +volume, ask the same master for its layout id: + +```bash +sw-block ops volume resolve --master 127.0.0.1:9180 v1 +``` + +The command prints only the full 32-hex-digit id and a newline. Pass that +value as `blockvolume --layout-id ` along with `--volume-id v1` +and the other startup flags. For the example systemd units, add +`--layout-id ` to `SWB_VOLUME_EXTRA_ARGS` in +`/etc/sw-block/blockvolume.env` before starting the service. Resolve each +volume separately; do not mint an id or copy another volume's value. + +This is a read-only query of the master's volume record, using the same +TLS and token environment settings as `ops chunk`. A missing volume, an +invalid identity or an unreachable master returns nonzero and prints no id; +fix that error before starting blockvolume. The query does not create a +volume or prove frontend readiness. + ## blockmaster settings | Variable | Flag | Default | Meaning | From 7d9e1b0a349f3d338d3b73486d9f0819ca9d4aff Mon Sep 17 00:00:00 2001 From: pingqiu Date: Wed, 25 Nov 2026 19:12:21 -0800 Subject: [PATCH 2/3] docs: name the volume resolver mutual TLS environment --- seaweed-block/docs/standalone-deployment.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/seaweed-block/docs/standalone-deployment.md b/seaweed-block/docs/standalone-deployment.md index 2dab348f0f..4be2a7abc9 100644 --- a/seaweed-block/docs/standalone-deployment.md +++ b/seaweed-block/docs/standalone-deployment.md @@ -193,7 +193,10 @@ and the other startup flags. For the example systemd units, add volume separately; do not mint an id or copy another volume's value. This is a read-only query of the master's volume record, using the same -TLS and token environment settings as `ops chunk`. A missing volume, an +TLS and token environment settings as `ops chunk`. For a replicated installation +using mutual TLS, set all three file paths: `SW_BLOCK_TLS_CERT` (client +certificate), `SW_BLOCK_TLS_KEY` (client private key) and `SW_BLOCK_TLS_CA` +(CA that verifies the master). A missing volume, an invalid identity or an unreachable master returns nonzero and prints no id; fix that error before starting blockvolume. The query does not create a volume or prove frontend readiness. From 477ac30e130a96216ed7ac2144509f5079945855 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Wed, 25 Nov 2026 19:15:04 -0800 Subject: [PATCH 3/3] fix: distinguish retryable volume resolution from final refusal --- seaweed-block/cmd/sw-block/volume_resolve.go | 12 +++++++++++- seaweed-block/cmd/sw-block/volume_resolve_test.go | 15 ++++++++++----- seaweed-block/docs/standalone-deployment.md | 6 ++++-- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/seaweed-block/cmd/sw-block/volume_resolve.go b/seaweed-block/cmd/sw-block/volume_resolve.go index 91bb8c58ca..8c8b72b78c 100644 --- a/seaweed-block/cmd/sw-block/volume_resolve.go +++ b/seaweed-block/cmd/sw-block/volume_resolve.go @@ -8,6 +8,8 @@ import ( "time" "github.com/seaweedfs/seaweed-block/core/ops" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" ) // runOpsVolume exposes the same master name binding used by ops chunk. @@ -34,7 +36,15 @@ func runOpsVolume(args []string, stdout, stderr io.Writer) int { id, err := resolveVolumeID(ctx, *master, fs.Arg(0)) if err != nil { fmt.Fprintf(stderr, "sw-block ops volume resolve: %v\n", err) - return ops.VolumeStatusExitInvalid + // Match blockvolume: an unavailable or unknown master answer is retryable; + // a definite refusal or invalid local configuration needs correction. + if s, ok := status.FromError(err); ok { + switch s.Code() { + case codes.Unavailable, codes.DeadlineExceeded, codes.Canceled, codes.Unknown, codes.Internal: + return 75 + } + } + return 78 } fmt.Fprintln(stdout, id.String()) return ops.VolumeStatusExitOK diff --git a/seaweed-block/cmd/sw-block/volume_resolve_test.go b/seaweed-block/cmd/sw-block/volume_resolve_test.go index f60d575a1f..b09730564e 100644 --- a/seaweed-block/cmd/sw-block/volume_resolve_test.go +++ b/seaweed-block/cmd/sw-block/volume_resolve_test.go @@ -29,6 +29,9 @@ func (s *volumeResolveServer) GetVolume(_ context.Context, q *control.GetLifecyc } func serveVolumeResolver(t *testing.T, s *volumeResolveServer) string { t.Helper() + for _, key := range []string{"SW_BLOCK_TLS_CERT", "SW_BLOCK_TLS_KEY", "SW_BLOCK_TLS_CA"} { + t.Setenv(key, "") + } lis, err := net.Listen("tcp", "127.0.0.1:0") if err != nil { t.Fatal(err) @@ -59,18 +62,20 @@ func TestOpsVolumeResolveRefusesMissingOrForeignIdentity(t *testing.T) { for _, tc := range []struct { name, volume, id string err error + exit int }{ - {"missing", "", "", status.Error(codes.NotFound, "no such volume")}, - {"unavailable", "", "", status.Error(codes.Unavailable, "master unavailable")}, - {"invalid-id", "v1", "bad", nil}, - {"wrong-name", "v2", "1234567890abcdef1234567890abcdef", nil}, + {"missing", "", "", status.Error(codes.NotFound, "no such volume"), 78}, + {"unavailable", "", "", status.Error(codes.Unavailable, "master unavailable"), 75}, + {"deadline", "", "", status.Error(codes.DeadlineExceeded, "query timed out"), 75}, + {"invalid-id", "v1", "bad", nil, 78}, + {"wrong-name", "v2", "1234567890abcdef1234567890abcdef", nil, 78}, } { t.Run(tc.name, func(t *testing.T) { s := &volumeResolveServer{reply: &control.CreateVolumeResponse{VolumeId: tc.volume, LayoutId: tc.id}, err: tc.err} addr := serveVolumeResolver(t, s) var out, errout bytes.Buffer code := run([]string{"ops", "volume", "resolve", "--master", addr, "v1"}, &out, &errout) - if code != 2 || out.Len() != 0 || errout.Len() == 0 { + if code != tc.exit || out.Len() != 0 || errout.Len() == 0 { t.Fatalf("code=%d stdout=%q stderr=%q", code, &out, &errout) } }) diff --git a/seaweed-block/docs/standalone-deployment.md b/seaweed-block/docs/standalone-deployment.md index 4be2a7abc9..e7056c0b07 100644 --- a/seaweed-block/docs/standalone-deployment.md +++ b/seaweed-block/docs/standalone-deployment.md @@ -197,8 +197,10 @@ TLS and token environment settings as `ops chunk`. For a replicated installation using mutual TLS, set all three file paths: `SW_BLOCK_TLS_CERT` (client certificate), `SW_BLOCK_TLS_KEY` (client private key) and `SW_BLOCK_TLS_CA` (CA that verifies the master). A missing volume, an -invalid identity or an unreachable master returns nonzero and prints no id; -fix that error before starting blockvolume. The query does not create a +invalid identity or an unreachable master prints no id. Exit 75 means the +master answer is unavailable or unknown: retry the query. Exit 78 means a +definite refusal (including not found or an invalid identity): correct it +before starting blockvolume. Invalid command arguments return 2. The query does not create a volume or prove frontend readiness. ## blockmaster settings