mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 10:37:23 +01:00
Merge pull request #634 from seaweedfs/feat/standalone-volume-resolve
feat: resolve standalone volume layout identity from the master
This commit is contained in:
commit
e5bb90c4e2
4 files changed
+178
-1
No files matched your search
@@ -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 <id> --chunk-filer <host:port> [--chunk-path /swblock/chunks]")
|
||||
fmt.Fprintln(w, " sw-block ops chunk verify --volume <id> --chunk-filer <host:port> [--chunk-path /swblock/chunks] [--depth meta|bindings|data] [--orphans] [--timeout <d>]")
|
||||
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 <addr> [--timeout 10s] <name> (prints the master layout id)")
|
||||
fmt.Fprintln(w, " sw-block ops volume-unheld --path <volume-file> (exit 0: no process on this host holds it; local filesystems only)")
|
||||
fmt.Fprintln(w, " sw-block ops workspace force-move --master <addr> --volume <id> --target-host <server-id> --target-data <addr> --target-ctrl <addr> --request-id <id> --confirm-forced <volume>@<epoch> [--dry-run]")
|
||||
fmt.Fprintln(w, " sw-block ops workspace lost-range --master <addr> --volume <id> [--request-id <id>] (authority only; no bypass: see `sw-block ops workspace help`)")
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"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.
|
||||
func runOpsVolume(args []string, stdout, stderr io.Writer) int {
|
||||
const usage = "usage: sw-block ops volume resolve --master <addr> [--timeout 10s] <name>"
|
||||
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)
|
||||
// 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
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
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()
|
||||
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)
|
||||
}
|
||||
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
|
||||
exit int
|
||||
}{
|
||||
{"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 != tc.exit || 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -176,6 +176,33 @@ 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 <printed-id>` along with `--volume-id v1`
|
||||
and the other startup flags. For the example systemd units, add
|
||||
`--layout-id <printed-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`. 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 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
|
||||
|
||||
| Variable | Flag | Default | Meaning |
|
||||
|
||||
Reference in new issue
Block a user