mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 02:57:37 +01:00
Merge pull request #260 from seaweedfs/fix/move-refusal-reasons
master: name a refused move's precondition; allow any port on the target host
This commit is contained in:
commit
b7af4c8e8c
5 files changed
+412
-3
No files matched your search
@@ -0,0 +1,202 @@
|
||||
package master
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"log"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/authority"
|
||||
"github.com/seaweedfs/seaweed-block/core/lifecycle"
|
||||
control "github.com/seaweedfs/seaweed-block/core/rpc/control"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
type syncBuffer struct {
|
||||
mu sync.Mutex
|
||||
b bytes.Buffer
|
||||
}
|
||||
|
||||
func (s *syncBuffer) Write(p []byte) (int, error) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
return s.b.Write(p)
|
||||
}
|
||||
|
||||
func (s *syncBuffer) String() string {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
return s.b.String()
|
||||
}
|
||||
|
||||
// A refused move names the precondition that failed, in the gRPC status and
|
||||
// in the master log: an unknown source, an unregistered target node, a
|
||||
// target that is the source, or target endpoints that are not registered
|
||||
// (with what is registered: the node's pair, or the volume's live bindings
|
||||
// on that node).
|
||||
func TestWorkspaceMoveRefusalNamesTheMissingPrecondition(t *testing.T) {
|
||||
logs := &syncBuffer{}
|
||||
m, err := New(Config{Listen: "127.0.0.1:0", AuthorityStoreDir: t.TempDir(), LifecycleStoreDir: t.TempDir(), WorkspaceRPC: true,
|
||||
Logger: log.New(logs, "", 0),
|
||||
WorkspaceHeadReader: func(context.Context, string) (authority.WorkspaceHead, error) {
|
||||
return authority.WorkspaceHead{Gen: 9, Epoch: 1, Holder: "node-a/r1", RemoteLSN: 42, Detached: true}, nil
|
||||
}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
m.Start()
|
||||
defer closeTestMaster(t, m)
|
||||
conn, err := grpc.NewClient(m.Addr(), grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer conn.Close()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
ws, lc := control.NewWorkspaceServiceClient(conn), control.NewLifecycleServiceClient(conn)
|
||||
for _, n := range []lifecycle.NodeRegistration{
|
||||
{ServerID: "node-a", DataAddr: "127.0.0.1:19101", CtrlAddr: "127.0.0.1:19102"},
|
||||
{ServerID: "node-b", DataAddr: "127.0.0.1:19301", CtrlAddr: "127.0.0.1:19302"},
|
||||
} {
|
||||
if _, err := m.Lifecycle().Nodes.RegisterNode(n); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
for _, v := range []string{"placed", "unplaced", "bound"} {
|
||||
if _, err := lc.CreateVolume(ctx, &control.CreateVolumeRequest{VolumeId: v, SizeBytes: 1 << 20, ReplicationFactor: 1}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if _, err := m.Lifecycle().Placements.ApplyPlan(lifecycle.PlacementPlan{VolumeID: "placed", DesiredRF: 1,
|
||||
Candidates: []lifecycle.PlacementCandidate{{VolumeID: "placed", ServerID: "node-a", ReplicaID: "r1", Source: lifecycle.PlacementSourceExistingReplica}}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// "bound" has explicit per-volume bindings: its source on node-a and a
|
||||
// prepared target on node-b at slot 2.
|
||||
for _, b := range []*control.WorkspaceBinding{
|
||||
{VolumeId: "bound", ServerId: "node-a", DataAddr: "127.0.0.1:19121", CtrlAddr: "127.0.0.1:19122"},
|
||||
{VolumeId: "bound", ServerId: "node-b", DataAddr: "127.0.0.1:19321", CtrlAddr: "127.0.0.1:19322"},
|
||||
} {
|
||||
if _, err := ws.RegisterWorkspaceBinding(ctx, b); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if _, err := ws.PlaceWorkspace(ctx, &control.WorkspacePlacement{VolumeId: "bound", ServerId: "node-a", ReplicaId: "r1"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
move := func(vol, server, data, ctrl string) *control.WorkspaceMove {
|
||||
return &control.WorkspaceMove{RequestId: vol + "-" + server + "-" + data, VolumeId: vol, ExpectedReplicaId: "r1", ExpectedEpoch: 1, TargetReplicaId: "r1",
|
||||
TargetServerId: server, TargetDataAddr: data, TargetCtrlAddr: ctrl, Kind: "clean"}
|
||||
}
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
q *control.WorkspaceMove
|
||||
want string
|
||||
}{
|
||||
{"unknown source", move("unplaced", "node-b", "127.0.0.1:19301", "127.0.0.1:19302"), `move source unknown: no issued move or placement names replica "r1" at epoch 1`},
|
||||
{"unknown target node", move("placed", "node-z", "127.0.0.1:19301", "127.0.0.1:19302"), `move target node "node-z" is not registered`},
|
||||
{"target is the source", move("placed", "node-a", "127.0.0.1:19101", "127.0.0.1:19102"), `move target "node-a" is the current source host`},
|
||||
{"target on another host", move("placed", "node-b", "10.9.9.9:19311", "127.0.0.1:19312"),
|
||||
`move target endpoints 10.9.9.9:19311/127.0.0.1:19312 on "node-b" are not registered (not on the node's hosts: it registers 127.0.0.1:19301/127.0.0.1:19302; no per-volume binding is prepared)`},
|
||||
{"explicit binding elsewhere", move("bound", "node-b", "127.0.0.1:19301", "127.0.0.1:19302"),
|
||||
`move target endpoints 127.0.0.1:19301/127.0.0.1:19302 on "node-b" are not registered (live bindings on that node: 127.0.0.1:19321/127.0.0.1:19322)`},
|
||||
} {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
_, err := ws.MoveWorkspace(ctx, c.q)
|
||||
if status.Code(err) != codes.FailedPrecondition || status.Convert(err).Message() != c.want {
|
||||
t.Fatalf("refusal %v; want FailedPrecondition %q", err, c.want)
|
||||
}
|
||||
if line := `MoveWorkspace refused volume="` + c.q.VolumeId + `" request="` + c.q.RequestId + `": ` + c.want; !strings.Contains(logs.String(), line) {
|
||||
t.Fatalf("log lacks %q:\n%s", line, logs.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
// Slot-0 and slot-1 targets on the node's host pass these preconditions
|
||||
// (they fail later, at the clean-move ACK check, for a different reason).
|
||||
for _, data := range []string{"127.0.0.1:19301", "127.0.0.1:19311"} {
|
||||
_, err = ws.MoveWorkspace(ctx, move("placed", "node-b", data, "127.0.0.1:19312"))
|
||||
if err == nil || strings.Contains(err.Error(), "move target") || strings.Contains(err.Error(), "move source") {
|
||||
t.Fatalf("target %s on the node's host: %v; want past the endpoint preconditions", data, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// blockingWriter blocks the first write that contains marker until
|
||||
// released; other writes pass.
|
||||
type blockingWriter struct {
|
||||
marker string
|
||||
entered, release chan struct{}
|
||||
once sync.Once
|
||||
}
|
||||
|
||||
func (b *blockingWriter) Write(p []byte) (int, error) {
|
||||
if !strings.Contains(string(p), b.marker) {
|
||||
return len(p), nil
|
||||
}
|
||||
first := false
|
||||
b.once.Do(func() { first = true })
|
||||
if first {
|
||||
close(b.entered)
|
||||
<-b.release
|
||||
}
|
||||
return len(p), nil
|
||||
}
|
||||
|
||||
// A refused move is logged after workspaceMu is released: while the log
|
||||
// writer is blocked, another workspace RPC still gets the lock.
|
||||
func TestWorkspaceMoveRefusalLogsOutsideTheWorkspaceLock(t *testing.T) {
|
||||
w := &blockingWriter{marker: "MoveWorkspace refused", entered: make(chan struct{}), release: make(chan struct{})}
|
||||
m, err := New(Config{Listen: "127.0.0.1:0", AuthorityStoreDir: t.TempDir(), LifecycleStoreDir: t.TempDir(), WorkspaceRPC: true, Logger: log.New(w, "", 0),
|
||||
WorkspaceHeadReader: func(context.Context, string) (authority.WorkspaceHead, error) { return authority.WorkspaceHead{}, nil }})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
m.Start()
|
||||
defer closeTestMaster(t, m)
|
||||
var releaseOnce sync.Once
|
||||
release := func() { releaseOnce.Do(func() { close(w.release) }) }
|
||||
defer release()
|
||||
conn, err := grpc.NewClient(m.Addr(), grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer conn.Close()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
ws := control.NewWorkspaceServiceClient(conn)
|
||||
if _, err := control.NewLifecycleServiceClient(conn).CreateVolume(ctx, &control.CreateVolumeRequest{VolumeId: "v", SizeBytes: 1 << 20, ReplicationFactor: 1}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
done := make(chan error, 1)
|
||||
go func() {
|
||||
_, err := ws.MoveWorkspace(ctx, &control.WorkspaceMove{RequestId: "r", VolumeId: "v", ExpectedReplicaId: "r1", ExpectedEpoch: 1, TargetReplicaId: "r1",
|
||||
TargetServerId: "node-b", TargetDataAddr: "127.0.0.1:19301", TargetCtrlAddr: "127.0.0.1:19302", Kind: "clean"})
|
||||
done <- err
|
||||
}()
|
||||
select {
|
||||
case <-w.entered:
|
||||
case <-time.After(10 * time.Second):
|
||||
t.Fatal("the refusal was never logged")
|
||||
}
|
||||
qctx, qcancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer qcancel()
|
||||
if _, err := ws.QueryWorkspace(qctx, &control.WorkspaceVolume{VolumeId: "v"}); err != nil {
|
||||
t.Fatalf("workspace RPC while the refusal log is blocked: %v; want workspaceMu free", err)
|
||||
}
|
||||
release()
|
||||
select {
|
||||
case err := <-done:
|
||||
if status.Code(err) != codes.FailedPrecondition {
|
||||
t.Fatalf("move: %v", err)
|
||||
}
|
||||
case <-time.After(10 * time.Second):
|
||||
t.Fatal("the move did not return after the log was released")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
package master
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/authority"
|
||||
"github.com/seaweedfs/seaweed-block/core/lifecycle"
|
||||
control "github.com/seaweedfs/seaweed-block/core/rpc/control"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
)
|
||||
|
||||
// The T08 shape: two volumes without per-volume bindings, nodes registered
|
||||
// at slot 0 of their host. "a1" holds slot 0 on node-a; "a2" lives on
|
||||
// node-b and moves back to node-a. Its target lands on slot 1 (slot 0 is
|
||||
// held) and is granted; a target on a1's live slot-0 endpoints is refused by
|
||||
// the collision check, and one on another host's address by the ownership
|
||||
// check. The grant routes a2 to the slot-1 endpoints it asked for.
|
||||
func TestWorkspaceMoveToAnotherSlotOnTheTargetHost(t *testing.T) {
|
||||
heads := map[string]authority.WorkspaceHead{"a2": {Gen: 9, Epoch: 1, Holder: "node-b/r1", RemoteLSN: 42, Detached: true}}
|
||||
m, err := New(Config{Listen: "127.0.0.1:0", AuthorityStoreDir: t.TempDir(), LifecycleStoreDir: t.TempDir(), WorkspaceRPC: true,
|
||||
WorkspaceHeadReader: func(_ context.Context, v string) (authority.WorkspaceHead, error) { return heads[v], nil }})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
m.Start()
|
||||
defer closeTestMaster(t, m)
|
||||
conn, err := grpc.NewClient(m.Addr(), grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer conn.Close()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
|
||||
defer cancel()
|
||||
ws, lc := control.NewWorkspaceServiceClient(conn), control.NewLifecycleServiceClient(conn)
|
||||
slot := func(base, n int) (string, string) {
|
||||
return "127.0.0.1:" + strconv.Itoa(base+10*n+1), "127.0.0.1:" + strconv.Itoa(base+10*n+2)
|
||||
}
|
||||
for _, n := range []struct {
|
||||
id string
|
||||
base int
|
||||
}{{"node-a", 19100}, {"node-b", 19300}} {
|
||||
d, c := slot(n.base, 0)
|
||||
if _, err := m.Lifecycle().Nodes.RegisterNode(lifecycle.NodeRegistration{ServerID: n.id, DataAddr: d, CtrlAddr: c}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
place := func(vol, server string, base int) authority.AuthorityBasis {
|
||||
t.Helper()
|
||||
if _, err := lc.CreateVolume(ctx, &control.CreateVolumeRequest{VolumeId: vol, SizeBytes: 1 << 20, ReplicationFactor: 1}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := m.Lifecycle().Placements.ApplyPlan(lifecycle.PlacementPlan{VolumeID: vol, DesiredRF: 1,
|
||||
Candidates: []lifecycle.PlacementCandidate{{VolumeID: vol, ServerID: server, ReplicaID: "r1", Source: lifecycle.PlacementSourceExistingReplica}}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
d, c := slot(base, 0)
|
||||
if _, err := control.NewObservationServiceClient(conn).ReportHeartbeat(ctx, &control.HeartbeatReport{ServerId: server, SentAt: timestamppb.Now(), Reachable: true, Eligible: true,
|
||||
Slots: []*control.HeartbeatSlot{{VolumeId: vol, ReplicaId: "r1", DataAddr: d, CtrlAddr: c}}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := m.RunLifecycleProductTick(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return waitAuthorityLine(t, m.Publisher(), vol)
|
||||
}
|
||||
a1 := place("a1", "node-a", 19100) // holds node-a slot 0
|
||||
a2 := place("a2", "node-b", 19300)
|
||||
if a1.DataAddr != "127.0.0.1:19101" || a2.DataAddr != "127.0.0.1:19301" {
|
||||
t.Fatalf("fixture lines a1=%+v a2=%+v", a1, a2)
|
||||
}
|
||||
// a2 stops cleanly on node-b: lease, revocation, ACK of its detached HEAD.
|
||||
id := &control.WorkspaceIdentity{VolumeId: "a2", ReplicaId: "r1", Epoch: a2.Epoch}
|
||||
if _, err := ws.RenewWorkspaceLease(ctx, id); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := ws.RevokeWorkspace(ctx, id); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := ws.AckWorkspaceRevoked(ctx, &control.WorkspaceRevocationAck{Identity: id, HeadGen: 9}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
move := func(req, data, ctrl string) *control.WorkspaceMove {
|
||||
return &control.WorkspaceMove{RequestId: req, VolumeId: "a2", ExpectedReplicaId: "r1", ExpectedEpoch: a2.Epoch, TargetReplicaId: "r1",
|
||||
TargetServerId: "node-a", TargetDataAddr: data, TargetCtrlAddr: ctrl, Kind: "clean"}
|
||||
}
|
||||
d0, c0 := slot(19100, 0)
|
||||
if _, err := ws.MoveWorkspace(ctx, move("onto-a1", d0, c0)); err == nil || !strings.Contains(err.Error(), "endpoint belongs to live assignment") {
|
||||
t.Fatalf("move onto a1's live slot-0 endpoints: %v; want the collision refusal", err)
|
||||
}
|
||||
if _, err := ws.MoveWorkspace(ctx, move("other-host", "10.9.9.9:19111", "10.9.9.9:19112")); err == nil || !strings.Contains(err.Error(), `endpoints 10.9.9.9:19111/10.9.9.9:19112 on "node-a" are not registered`) {
|
||||
t.Fatalf("move to another host's address: %v; want the ownership refusal", err)
|
||||
}
|
||||
d1, c1 := slot(19100, 1)
|
||||
if _, err := ws.MoveWorkspace(ctx, move("ctrl-other-host", d1, "10.9.9.9:19112")); err == nil || !strings.Contains(err.Error(), `on "node-a" are not registered`) {
|
||||
t.Fatalf("move with its ctrl endpoint on another host: %v; want the ownership refusal", err)
|
||||
}
|
||||
// Invalid endpoints on the right host are refused before anything is
|
||||
// written: the epoch, the journal, the lease and the ACK stay as they were.
|
||||
before := m.Publisher().WorkspaceState("a2")
|
||||
for _, bad := range []struct{ name, data, ctrl string }{
|
||||
{"non-numeric port", "127.0.0.1:bad", c1},
|
||||
{"port 0", "127.0.0.1:0", c1},
|
||||
{"port 65536", d1, "127.0.0.1:65536"},
|
||||
{"empty port", "127.0.0.1:", c1},
|
||||
{"data equals ctrl", d1, d1},
|
||||
} {
|
||||
if _, err := ws.MoveWorkspace(ctx, move("bad-"+bad.name, bad.data, bad.ctrl)); err == nil || !strings.Contains(err.Error(), "move target endpoints invalid") {
|
||||
t.Fatalf("%s: %v; want the invalid-endpoint refusal", bad.name, err)
|
||||
}
|
||||
after := m.Publisher().WorkspaceState("a2")
|
||||
line, _ := m.Publisher().VolumeAuthorityLine("a2")
|
||||
if line.Epoch != a2.Epoch || after == nil || len(after.Moves) != 0 || after.Ack == nil || before.Ack == nil || *after.Ack != *before.Ack || after.Lease == nil || !after.Lease.Revoking {
|
||||
t.Fatalf("%s: state changed by a refused move: line %+v state %+v", bad.name, line, after)
|
||||
}
|
||||
}
|
||||
g, err := ws.MoveWorkspace(ctx, move("slot-1", d1, c1))
|
||||
if err != nil {
|
||||
t.Fatalf("move to node-a slot 1 while slot 0 is held: %v", err)
|
||||
}
|
||||
line, ok := m.Publisher().VolumeAuthorityLine("a2")
|
||||
if !g.Issued || g.NewHost != "node-a" || g.OldHost != "node-b" || !ok || line.Epoch != g.NewEpoch || line.DataAddr != d1 || line.CtrlAddr != c1 {
|
||||
t.Fatalf("grant %+v line %+v; want a2 issued on node-a at %s/%s", g, line, d1, c1)
|
||||
}
|
||||
if l1, _ := m.Publisher().VolumeAuthorityLine("a1"); l1.DataAddr != d0 || l1.Epoch != a1.Epoch {
|
||||
t.Fatalf("a1 changed: %+v", l1)
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@ package master
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/authority"
|
||||
@@ -143,6 +145,14 @@ func (s *services) MoveWorkspace(ctx context.Context, q *control.WorkspaceMove)
|
||||
}
|
||||
// Remote reads never hold the workspace mutation lock. Re-read every
|
||||
// local precondition below; Publisher checks the expected epoch atomically.
|
||||
// A refusal is logged after the lock is released (deferred first, so it
|
||||
// runs last): a slow log writer never holds workspaceMu.
|
||||
var refusal string
|
||||
defer func() {
|
||||
if refusal != "" {
|
||||
s.host.log.Printf("blockmaster: MoveWorkspace refused volume=%q request=%q: %s", q.GetVolumeId(), q.GetRequestId(), refusal)
|
||||
}
|
||||
}()
|
||||
s.host.workspaceMu.Lock()
|
||||
defer s.host.workspaceMu.Unlock()
|
||||
if err := ctx.Err(); err != nil {
|
||||
@@ -157,14 +167,32 @@ func (s *services) MoveWorkspace(ctx context.Context, q *control.WorkspaceMove)
|
||||
if err != nil {
|
||||
return nil, workspaceError(err)
|
||||
}
|
||||
matched := !explicit && target.DataAddr == q.GetTargetDataAddr() && target.CtrlAddr == q.GetTargetCtrlAddr()
|
||||
// A volume without per-volume bindings may move to any port on the
|
||||
// target node's registered hosts (a host runs several slots): the host
|
||||
// match ties the endpoints to that node's registration (it trusts the
|
||||
// registration; it is not an identity proof). The collision check below
|
||||
// still refuses endpoints another assignment or binding owns.
|
||||
matched := !explicit && sameHost(q.GetTargetDataAddr(), target.DataAddr) && sameHost(q.GetTargetCtrlAddr(), target.CtrlAddr)
|
||||
endpointErr := lifecycle.ValidateWorkspaceEndpoints(lifecycle.WorkspaceBinding{VolumeID: q.GetVolumeId(), ServerID: q.GetTargetServerId(), DataAddr: q.GetTargetDataAddr(), CtrlAddr: q.GetTargetCtrlAddr()})
|
||||
for _, b := range bindings {
|
||||
if !b.Retired && b.ServerID == q.GetTargetServerId() && b.DataAddr == q.GetTargetDataAddr() && b.CtrlAddr == q.GetTargetCtrlAddr() {
|
||||
matched = true
|
||||
}
|
||||
}
|
||||
if oldHost == "" || !ok || target.ServerID == oldHost || !matched {
|
||||
return nil, status.Error(codes.FailedPrecondition, "move needs known source slot and registered target endpoints")
|
||||
switch {
|
||||
case endpointErr != nil:
|
||||
refusal = fmt.Sprintf("move target endpoints invalid: %v", endpointErr)
|
||||
case oldHost == "":
|
||||
refusal = fmt.Sprintf("move source unknown: no issued move or placement names replica %q at epoch %d", q.GetExpectedReplicaId(), q.GetExpectedEpoch())
|
||||
case !ok:
|
||||
refusal = fmt.Sprintf("move target node %q is not registered", q.GetTargetServerId())
|
||||
case target.ServerID == oldHost:
|
||||
refusal = fmt.Sprintf("move target %q is the current source host", target.ServerID)
|
||||
case !matched:
|
||||
refusal = fmt.Sprintf("move target endpoints %s/%s on %q are not registered (%s)", q.GetTargetDataAddr(), q.GetTargetCtrlAddr(), target.ServerID, registeredTargetEndpoints(target, bindings, explicit))
|
||||
}
|
||||
if refusal != "" {
|
||||
return nil, status.Error(codes.FailedPrecondition, refusal)
|
||||
}
|
||||
if err = s.host.workspaceEndpointsAvailable(lifecycle.WorkspaceBinding{VolumeID: q.GetVolumeId(), ServerID: target.ServerID, DataAddr: q.GetTargetDataAddr(), CtrlAddr: q.GetTargetCtrlAddr()}); err != nil {
|
||||
return nil, workspaceError(err)
|
||||
@@ -180,6 +208,32 @@ func (s *services) MoveWorkspace(ctx context.Context, q *control.WorkspaceMove)
|
||||
return grantFact(r), nil
|
||||
}
|
||||
|
||||
// sameHost reports whether two host:port addresses name the same host:
|
||||
// canonical host parts (equivalent IP spellings equal), no name resolution.
|
||||
func sameHost(a, b string) bool {
|
||||
ha := lifecycle.WorkspaceEndpointHost(a)
|
||||
return ha != "" && ha == lifecycle.WorkspaceEndpointHost(b)
|
||||
}
|
||||
|
||||
// registeredTargetEndpoints describes what a move to target may name: the
|
||||
// node's own pair for a volume without explicit bindings, else its live
|
||||
// bindings on that node.
|
||||
func registeredTargetEndpoints(target lifecycle.NodeRegistration, bindings []lifecycle.WorkspaceBinding, explicit bool) string {
|
||||
if !explicit {
|
||||
return fmt.Sprintf("not on the node's hosts: it registers %s/%s; no per-volume binding is prepared", target.DataAddr, target.CtrlAddr)
|
||||
}
|
||||
var live []string
|
||||
for _, b := range bindings {
|
||||
if !b.Retired && b.ServerID == target.ServerID {
|
||||
live = append(live, b.DataAddr+"/"+b.CtrlAddr)
|
||||
}
|
||||
}
|
||||
if len(live) == 0 {
|
||||
return "the volume has explicit bindings but none live on that node"
|
||||
}
|
||||
return "live bindings on that node: " + strings.Join(live, ", ")
|
||||
}
|
||||
|
||||
func (s *services) QueryWorkspace(ctx context.Context, q *control.WorkspaceVolume) (*control.WorkspaceStatus, error) {
|
||||
s.host.workspaceMu.Lock()
|
||||
defer s.host.workspaceMu.Unlock()
|
||||
|
||||
@@ -119,6 +119,25 @@ func validateWorkspaceBinding(b WorkspaceBinding) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ValidateWorkspaceEndpoints applies a binding's endpoint rules (host:port
|
||||
// with a numeric port 1..65535, data and ctrl distinct) without registering
|
||||
// anything.
|
||||
func ValidateWorkspaceEndpoints(b WorkspaceBinding) error { return validateWorkspaceBinding(b) }
|
||||
|
||||
// WorkspaceEndpointHost returns addr's host in canonical form (equivalent IP
|
||||
// spellings compare equal; names lower-cased; no DNS), or "" if addr is not
|
||||
// host:port.
|
||||
func WorkspaceEndpointHost(addr string) string {
|
||||
h, _, err := net.SplitHostPort(addr)
|
||||
if err != nil || h == "" {
|
||||
return ""
|
||||
}
|
||||
if ip := net.ParseIP(h); ip != nil {
|
||||
return ip.String()
|
||||
}
|
||||
return strings.ToLower(h)
|
||||
}
|
||||
|
||||
// Compare numeric ports and equivalent IP spellings without DNS/network I/O.
|
||||
func workspaceEndpointKey(addr string) string {
|
||||
h, p, err := net.SplitHostPort(addr)
|
||||
|
||||
@@ -93,6 +93,7 @@ blockmaster's publisher is the only component that mints epochs. Diagrams: the a
|
||||
| Granted | Revoking | `BeginWorkspaceRevocation` for the matching lease; a renew now returns the revoking lease with the granted expiry, min(horizon, deadline), without extending it | `core/authority/workspace.go` `BeginWorkspaceRevocation`; `core/authority/workspace_lease_view.go` `RenewWorkspaceLease`, `WorkspaceLeaseReply` | `INV-WS-CLEAN-MOVE-001` |
|
||||
| Revoking | Acked | `AckWorkspaceRevocation` from the holder at the current epoch, a nonzero HEAD generation, the lease still valid; a different second acknowledgement is refused | `core/authority/workspace.go` `AckWorkspaceRevocation` | `INV-WS-CLEAN-MOVE-001`, `INV-WS-REVOKE-ACK-001` |
|
||||
| Acked | Moved (clean) | HEAD detached by the expected holder at the expected epoch, and the acknowledgement names that HEAD generation | `core/authority/workspace.go` `prepareWorkspaceMoveLocked` | `INV-WS-CLEAN-MOVE-001` |
|
||||
| Acked or Expired | (move refused, nothing written) | blockmaster admits a move only with valid target endpoints (host:port, port 1..65535, data and ctrl distinct), a known source host, a registered target node other than the source, and target endpoints that either match a live per-volume binding or, for a volume without bindings, lie on the target node's registered hosts (any port) and are not owned by another assignment or binding; each refusal names its condition and is logged | `core/host/master/workspace_service.go` `MoveWorkspace` | `INV-WS-CLEAN-MOVE-001`, `INV-WS-FORCED-MOVE-001` |
|
||||
| Granted or Revoking | Expired | the durable horizon or the granted deadline passes | `core/authority/workspace_lease_view.go` `RenewWorkspaceLease`; `core/authority/workspace.go` `AckWorkspaceRevocation` | `INV-WS-FORCED-MOVE-001` |
|
||||
| Expired | Moved (forced) | explicit force; the persisted lease horizon (at least every grant) plus the clock-skew bound and the granted or restart deadline plus the bound have both passed | `core/authority/workspace.go` `prepareWorkspaceMoveLocked` | `INV-WS-FORCED-MOVE-001`, `INV-WS-LEASE-HORIZON-001` |
|
||||
| Moved | epoch issued | the move journal record is durable first; a retried request id gets the same epoch | `core/authority/workspace.go` `prepareWorkspaceMoveLocked`, `MoveWorkspace` | `INV-AUTH-MOVE-JOURNAL-001` |
|
||||
|
||||
Reference in new issue
Block a user