From 504d0d1b555beddcd17934054835fead32058bfb Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sat, 28 Nov 2026 07:16:04 -0800 Subject: [PATCH] fix, cli: default create to NVMe TCP and exercise lost-answer retries --- seaweed-block/cmd/sw-block/volume_create.go | 5 +- .../cmd/sw-block/volume_create_test.go | 56 ++++++++++++++++++- .../docs/design/create-and-place-command.md | 17 +++++- seaweed-block/docs/standalone-deployment.md | 24 ++++++++ 4 files changed, 98 insertions(+), 4 deletions(-) diff --git a/seaweed-block/cmd/sw-block/volume_create.go b/seaweed-block/cmd/sw-block/volume_create.go index 4115f0db7c..e0995b37f3 100644 --- a/seaweed-block/cmd/sw-block/volume_create.go +++ b/seaweed-block/cmd/sw-block/volume_create.go @@ -26,7 +26,7 @@ func runOpsVolumeCreate(args []string, stdout, stderr io.Writer) int { fs.Usage = func() { fmt.Fprintln(stderr, usage) } master := fs.String("master", "", "master gRPC address") size := fs.Uint64("size-bytes", 0, "volume size in bytes (multiple of 4096)") - protocol := fs.String("protocol", "iscsi", "iscsi or nvme") + protocol := fs.String("protocol", "nvme", "nvme (default) or iscsi") transport := fs.String("transport", "", "NVMe transport: tcp (default) or rdma") server := fs.String("server-id", "", "already registered host") replica := fs.String("replica-id", "", "replica identity") @@ -77,7 +77,8 @@ func runOpsVolumeCreate(args []string, stdout, stderr io.Writer) int { return fail("create reply", status.Error(codes.FailedPrecondition, "identity or geometry does not match; no binding or placement attempted")) } if !v.GetStoreReady() { - return fail("create", status.Error(codes.Unavailable, "created, store not ready; no binding or placement attempted")) + fmt.Fprintln(stderr, "sw-block ops volume create: created, store not ready; no binding or placement attempted; retry the identical name, geometry and placement") + return 75 } ws := control.NewWorkspaceServiceClient(conn) b, err := ws.RegisterWorkspaceBinding(ctx, binding) diff --git a/seaweed-block/cmd/sw-block/volume_create_test.go b/seaweed-block/cmd/sw-block/volume_create_test.go index edd9827d52..f2394840fa 100644 --- a/seaweed-block/cmd/sw-block/volume_create_test.go +++ b/seaweed-block/cmd/sw-block/volume_create_test.go @@ -8,6 +8,7 @@ import ( "reflect" "strings" "sync" + "sync/atomic" "testing" "github.com/seaweedfs/seaweed-block/core/authority" @@ -118,6 +119,23 @@ func TestOpsVolumeCreateAndPlaceWithoutMasterRestart(t *testing.T) { } } +func TestOpsVolumeCreateDefaultsToSupportedNVMeTCP(t *testing.T) { + s := &createAndPlaceReceiver{} + all := createAndPlaceArgs(serveCreateAndPlace(t, s)) + var args []string + for i := 0; i < len(all); i++ { + if all[i] == "--protocol" || all[i] == "--transport" { + i++ + continue + } + args = append(args, all[i]) + } + var out, errout bytes.Buffer + if code := run(args, &out, &errout); code != 0 { + t.Fatalf("default must create supported nvme/tcp: exit=%d out=%q err=%q", code, &out, &errout) + } +} + func TestOpsVolumeCreateStopsAfterRefusedOrUnknownStep(t *testing.T) { for i, step := range []string{"create", "bind", "place"} { for _, tc := range []struct { @@ -206,10 +224,35 @@ func TestOpsVolumeCreateValidatesBeforeAnyRPC(t *testing.T) { } func TestOpsVolumeCreateAndPlaceRetriesAgainstRunningMaster(t *testing.T) { + for _, lostReply := range []string{control.LifecycleService_CreateVolume_FullMethodName, control.WorkspaceService_RegisterWorkspaceBinding_FullMethodName, control.WorkspaceService_PlaceWorkspace_FullMethodName} { + t.Run(lostReply, func(t *testing.T) { testCreateAndPlaceLostReply(t, lostReply) }) + } +} + +func testCreateAndPlaceLostReply(t *testing.T, lostReply string) { + t.Helper() for _, key := range []string{"SW_BLOCK_TLS_CERT", "SW_BLOCK_TLS_KEY", "SW_BLOCK_TLS_CA"} { t.Setenv(key, "") } + var dropped atomic.Bool + var bindingCalls, placementCalls atomic.Int32 + // Lose the answer AFTER the real receiver commits. The client must stop, + // then an identical invocation must settle by the receiver's idempotence. + loseAnswer := func(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) { + if info.FullMethod == control.WorkspaceService_RegisterWorkspaceBinding_FullMethodName { + bindingCalls.Add(1) + } + if info.FullMethod == control.WorkspaceService_PlaceWorkspace_FullMethodName { + placementCalls.Add(1) + } + reply, err := handler(ctx, req) + if err == nil && info.FullMethod == lostReply && dropped.CompareAndSwap(false, true) { + return nil, status.Error(codes.Unavailable, "answer lost after commit") + } + return reply, err + } h, stop := startDeleteMaster(t, master.Config{Listen: "127.0.0.1:0", AuthorityStoreDir: t.TempDir(), LifecycleStoreDir: t.TempDir(), WorkspaceRPC: true, + ServerOptions: []grpc.ServerOption{grpc.ChainUnaryInterceptor(loseAnswer)}, WorkspaceHeadReader: func(context.Context, string) (authority.WorkspaceHead, error) { return authority.WorkspaceHead{}, fmt.Errorf("create-and-place must not inspect a holder HEAD") }, @@ -219,6 +262,17 @@ func TestOpsVolumeCreateAndPlaceRetriesAgainstRunningMaster(t *testing.T) { t.Fatal(err) } args := createAndPlaceArgs(h.Addr()) + var interrupted, diagnostics bytes.Buffer + if code := run(args, &interrupted, &diagnostics); code != 75 || interrupted.Len() != 0 || !dropped.Load() { + t.Fatalf("lost answer: code=%d out=%q err=%q", code, &interrupted, &diagnostics) + } + if lostReply == control.LifecycleService_CreateVolume_FullMethodName && bindingCalls.Load() != 0 || lostReply != control.WorkspaceService_PlaceWorkspace_FullMethodName && placementCalls.Load() != 0 { + t.Fatal("continued after unknown outcome") + } + before, err := lifecycleClient(t, h.Addr()).GetVolume(context.Background(), &control.GetLifecycleVolumeRequest{VolumeId: "new-volume"}) + if err != nil || !before.GetStoreReady() { + t.Fatalf("create was not committed before lost answer: %v %v", before, err) + } var first string for i := 0; i < 2; i++ { var out, errout bytes.Buffer @@ -232,7 +286,7 @@ func TestOpsVolumeCreateAndPlaceRetriesAgainstRunningMaster(t *testing.T) { } } v, err := lifecycleClient(t, h.Addr()).GetVolume(context.Background(), &control.GetLifecycleVolumeRequest{VolumeId: "new-volume"}) - if err != nil || !v.GetStoreReady() || v.GetSizeBytes() != 268435456 || v.GetReplicationFactor() != 1 { + if err != nil || !v.GetStoreReady() || v.GetSizeBytes() != 268435456 || v.GetReplicationFactor() != 1 || v.GetLayoutId() != before.GetLayoutId() { t.Fatalf("master volume=%v err=%v", v, err) } // Changing the desired placement cannot overwrite the recorded placement. diff --git a/seaweed-block/docs/design/create-and-place-command.md b/seaweed-block/docs/design/create-and-place-command.md index 8816a5c71f..a55fb82d4d 100644 --- a/seaweed-block/docs/design/create-and-place-command.md +++ b/seaweed-block/docs/design/create-and-place-command.md @@ -50,7 +50,7 @@ admission, matching reply identity and readiness. The real-master test checks identical retries and conflicting placement without restarting the master. These are control-plane tests, not guest-I/O acceptance. -The default protocol is `iscsi` with no transport; `nvme` defaults to `tcp`. +The default protocol is `nvme` with `tcp`, the supported guest path. Success prints one JSON object with `status: "placement_recorded"`, `volume`, `layout_id`, `server_id` and `replica_id`. Exit 2 means invalid arguments or connection configuration, 78 means a definite refusal, and 75 means an unknown @@ -58,6 +58,21 @@ RPC outcome or a not-ready store. On an error, the command stops before the next step. Earlier acknowledged steps remain recorded; retry the same name, geometry and placement. There is no automatic retry or rollback. +Use an admin identity for the complete command: `CreateVolume` and +`PlaceWorkspace` require operator, while `RegisterWorkspaceBinding` requires +admin; all three use strict audit admission. An operator-only caller can leave +a created volume when binding is refused. A retry with a different placement +cannot overwrite the existing intent: the master's conflicting-placement +refusal remains the owner of that decision. + +To abandon a created or prepared-but-unplaced volume, use `ops chunk +volume-delete` as documented for a volume that never served. It removes the +store and commits master deletion, including prepared bindings and their two +endpoint reservations. Do not erase a binding file or the master record by +hand. An already placed volume may have acquired a line or lease; follow the +documented delete admission and printed lease horizon, or the running +holder's seal/revoke/ACK procedure if it served. Deleted names are not reused. + Existing contracts relied on: M2 authority/assignment in invariants.md; INV-AUTH-HOLDER-IDENTITY-001 and INV-VOL-ID-NO-REUSE-001; core/host/master/services.go CreateVolume; diff --git a/seaweed-block/docs/standalone-deployment.md b/seaweed-block/docs/standalone-deployment.md index 42ecaae51e..6b043d71c5 100644 --- a/seaweed-block/docs/standalone-deployment.md +++ b/seaweed-block/docs/standalone-deployment.md @@ -310,6 +310,30 @@ retry with the identical name, size, protocol, host, replica and endpoints. The command does not roll back partial work. Its default deadline is 10 seconds for all three RPCs (`--timeout` changes only the wait). +The default is NVMe/TCP. Use an **admin** identity for the whole command: +`CreateVolume` and `PlaceWorkspace` require operator, but preparing the binding +requires admin. All three are strict audited writes. An operator-only identity +may create the store and then be refused at binding registration. + +New volumes are limited to **256 GiB** (274877906944 bytes). A larger create +is refused with exit 78; its diagnostic includes `volume too large` and +`exceeds the maximum of 274877906944 bytes`. No binding or placement follows. + +To abandon the volume after creation or binding, delete the volume that never +served: + +```bash +sw-block ops chunk volume-delete --master MASTER --volume v1 \ + --chunk-filer FILER --request-id abandon-v1 +``` + +Keep that request id for retries. Completion removes the volume's store and +master placement/binding records, releasing both prepared endpoint +reservations. Do not remove master files by hand. If placement already resulted +in a lease, obey the printed `live until` horizon; if the holder served, follow +the seal/revoke/ACK steps in [Delete a volume](volume-lifecycle.md#delete-a-volume). +The deleted name cannot be reused in this release. + Check with `sw-block ops workspace show --master 127.0.0.1:9180 --volume v1`; it names the first missing piece: `workspace RPC disabled`, `lifecycle store unavailable`, or `workspace move requires an existing RF1