mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 11:07:31 +01:00
test: pin the online RF1 create-and-place command seam
This commit is contained in:
1 parent
0d6cfdf8c2
commit
640813e8e6
2 files changed
+137
No files matched your search
@@ -0,0 +1,81 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"net"
|
||||
"reflect"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
control "github.com/seaweedfs/seaweed-block/core/rpc/control"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
// The S1 command's public seam: a running master's existing lifecycle and
|
||||
// workspace RPCs. This receiver checks the operator's intent, not private CLI
|
||||
// functions. No test-only command implementation stands in for the command.
|
||||
type createAndPlaceReceiver struct {
|
||||
control.UnimplementedLifecycleServiceServer
|
||||
control.UnimplementedWorkspaceServiceServer
|
||||
mu sync.Mutex
|
||||
calls []string
|
||||
}
|
||||
|
||||
func (s *createAndPlaceReceiver) CreateVolume(_ context.Context, q *control.CreateVolumeRequest) (*control.CreateVolumeResponse, error) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
if q.GetVolumeId() != "new-volume" || q.GetSizeBytes() != 268435456 || q.GetReplicationFactor() != 1 || q.GetProtocol() != "nvme" || q.GetFrontendTransport() != "tcp" || q.GetSourceVolume() != "" || q.GetSourceSnapshot() != "" || q.GetCreateRequestId() != "" {
|
||||
return nil, status.Error(codes.InvalidArgument, "wrong ordinary RF1 create intent")
|
||||
}
|
||||
s.calls = append(s.calls, "create")
|
||||
return &control.CreateVolumeResponse{VolumeId: q.VolumeId, SizeBytes: q.SizeBytes, ReplicationFactor: 1, Protocol: "nvme", FrontendTransport: "tcp", LayoutId: "1234567890abcdef1234567890abcdef", BlockSize: 4096, ChunkBytes: 4194304, StoreReady: true}, nil
|
||||
}
|
||||
|
||||
func (s *createAndPlaceReceiver) RegisterWorkspaceBinding(_ context.Context, q *control.WorkspaceBinding) (*control.WorkspaceBinding, error) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
if !reflect.DeepEqual(s.calls, []string{"create"}) || q.GetVolumeId() != "new-volume" || q.GetServerId() != "registered-host" || q.GetDataAddr() != "192.0.2.10:9201" || q.GetCtrlAddr() != "192.0.2.10:9202" || q.GetRetired() {
|
||||
return nil, status.Error(codes.FailedPrecondition, "binding must follow store-ready create with exact endpoints")
|
||||
}
|
||||
s.calls = append(s.calls, "bind")
|
||||
return q, nil
|
||||
}
|
||||
|
||||
func (s *createAndPlaceReceiver) PlaceWorkspace(_ context.Context, q *control.WorkspacePlacement) (*control.WorkspaceEmpty, error) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
if !reflect.DeepEqual(s.calls, []string{"create", "bind"}) || q.GetVolumeId() != "new-volume" || q.GetServerId() != "registered-host" || q.GetReplicaId() != "r1" {
|
||||
return nil, status.Error(codes.FailedPrecondition, "placement must follow the exact prepared binding")
|
||||
}
|
||||
s.calls = append(s.calls, "place")
|
||||
return &control.WorkspaceEmpty{}, nil
|
||||
}
|
||||
|
||||
func TestOpsVolumeCreateAndPlaceWithoutMasterRestart(t *testing.T) {
|
||||
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)
|
||||
}
|
||||
s := &createAndPlaceReceiver{}
|
||||
server := grpc.NewServer()
|
||||
control.RegisterLifecycleServiceServer(server, s)
|
||||
control.RegisterWorkspaceServiceServer(server, s)
|
||||
go func() { _ = server.Serve(lis) }()
|
||||
t.Cleanup(server.Stop)
|
||||
var out, errout bytes.Buffer
|
||||
code := run([]string{"ops", "volume", "create", "--master", lis.Addr().String(), "--size-bytes", "268435456", "--protocol", "nvme", "--transport", "tcp", "--server-id", "registered-host", "--replica-id", "r1", "--data-addr", "192.0.2.10:9201", "--ctrl-addr", "192.0.2.10:9202", "--timeout", "5s", "new-volume"}, &out, &errout)
|
||||
if code != 0 {
|
||||
t.Fatalf("online create-and-place: exit=%d stdout=%q stderr=%q", code, &out, &errout)
|
||||
}
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
if !reflect.DeepEqual(s.calls, []string{"create", "bind", "place"}) {
|
||||
t.Fatalf("master RPCs=%v; want one create, binding, placement on the running master", s.calls)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
# Online create and placement command (v1.0.1 S1)
|
||||
|
||||
Draft design and red test. This branch must not merge before v1.0.0 is cut.
|
||||
S1 is the single-replica operations item: create a volume and record its
|
||||
placement online, without restarting blockmaster. It composes existing RPCs;
|
||||
it does not add a state, grant, promotion, host registration or kernel transition.
|
||||
|
||||
Proposed operator interface:
|
||||
|
||||
```sh
|
||||
sw-block ops volume create --master MASTER --size-bytes 268435456 \
|
||||
--protocol nvme --transport tcp --server-id registered-host --replica-id r1 \
|
||||
--data-addr 192.0.2.10:9201 --ctrl-addr 192.0.2.10:9202 \
|
||||
--timeout 10s new-volume
|
||||
```
|
||||
|
||||
The node must already be registered. Online host registration is outside S1.
|
||||
The command validates all local arguments before any RPC, then invokes
|
||||
LifecycleService.CreateVolume with RF1, waits for its store-ready answer,
|
||||
registers the exact per-volume WorkspaceBinding, and calls PlaceWorkspace.
|
||||
It uses the existing authenticated connection options. A successful answer
|
||||
means placement recorded, not a lease issued or a target serving. Starting the
|
||||
unit, assignment and guest connection remain separate operator steps.
|
||||
|
||||
CreateVolume owns the volume record and the store-ready gate. The existing
|
||||
binding receiver owns endpoint reservations and registered-node checks.
|
||||
PlaceWorkspace owns placement admission under workspaceMu and its publisher
|
||||
guard. The command never writes these stores directly, mints an epoch, or
|
||||
uses time to decide authority. Its one context deadline only bounds waiting.
|
||||
|
||||
| Last completed step | Refused next step | Unknown next outcome |
|
||||
| --- | --- | --- |
|
||||
| none | report refusal; do not call binding/placement | report unknown create; retry same name and geometry |
|
||||
| store-ready create | leave volume created; do not place | report binding unknown; retry identical intent |
|
||||
| binding | leave binding prepared; no success claim | report placement unknown; retry identical intent |
|
||||
| placement | report placement recorded, never serving | no success without an acknowledged placement result |
|
||||
|
||||
There is no client journal, rollback or atomic three-record claim. Identical
|
||||
retries use existing receiver idempotence. Changed geometry/identity, conflicting
|
||||
bindings and an existing assignment must remain subject to receiver refusal;
|
||||
the CLI must validate the returned create identity/geometry before proceeding.
|
||||
No ordinary-create request ID is sent: that existing field denotes restore.
|
||||
|
||||
The first red test, TestOpsVolumeCreateAndPlaceWithoutMasterRestart, invokes
|
||||
the real CLI dispatcher against public gRPC receivers. It requires exactly
|
||||
create -> bind -> place with the stated RF1 intent while one endpoint remains
|
||||
running. It fails on main because only volume resolve exists. It proves the
|
||||
missing command seam, not real store creation or guest I/O. Subsequent vertical
|
||||
slices must cover refusal/unknown outcomes, argument admission, matching reply
|
||||
identity, repeat intent and a real-master integration run before readiness.
|
||||
|
||||
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;
|
||||
core/host/master/workspace_binding.go RegisterWorkspaceBinding/PlaceWorkspace;
|
||||
core/rpc/proto/control.proto and workspace.proto. No guard is changed here.
|
||||
Reference in new issue
Block a user