mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 18:47:20 +01:00
feat: register per-volume workspace endpoints and chosen-node intent
This commit is contained in:
1 parent
baca5fd3a9
commit
52cd6debc5
13 files changed
+1100
-59
No files matched your search
@@ -118,6 +118,20 @@ type WorkspaceMoveRequest struct {
|
||||
|
||||
// MoveWorkspace is the authority-owned guarded RF1 move seam. The host layer
|
||||
// validates volume eligibility and reads HEAD before calling this boundary.
|
||||
// RecordWorkspacePlacement serializes initial desired placement persistence
|
||||
// against authority publication. persist must not call back into Publisher.
|
||||
func (p *Publisher) RecordWorkspacePlacement(ctx context.Context, volume string, persist func() error) error {
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
if err := ctx.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, _, ok := p.workspaceLineLocked(volume); ok {
|
||||
return fmt.Errorf("workspace placement: volume already assigned; use move")
|
||||
}
|
||||
return persist()
|
||||
}
|
||||
|
||||
func (p *Publisher) MoveWorkspace(ctx context.Context, req WorkspaceMoveRequest, head WorkspaceHead) (WorkspaceMoveRecord, error) {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return WorkspaceMoveRecord{}, err
|
||||
|
||||
@@ -85,9 +85,10 @@ type Config struct {
|
||||
// blockmaster. The stores are controller input only; assignment
|
||||
// publication remains owned by authority.Controller/Publisher.
|
||||
type LifecycleStores struct {
|
||||
Volumes *lifecycle.FileStore
|
||||
Nodes *lifecycle.NodeInventoryStore
|
||||
Placements *lifecycle.PlacementIntentStore
|
||||
Volumes *lifecycle.FileStore
|
||||
Nodes *lifecycle.NodeInventoryStore
|
||||
Placements *lifecycle.PlacementIntentStore
|
||||
WorkspaceBindings *lifecycle.WorkspaceBindingStore
|
||||
}
|
||||
|
||||
// Host is the composed master-side block product daemon. Lifecycle
|
||||
@@ -105,11 +106,14 @@ type Host struct {
|
||||
grpc *grpc.Server
|
||||
topo authority.AcceptedTopology
|
||||
lifecycle *LifecycleStores
|
||||
events *eventRing
|
||||
promotionMu sync.RWMutex
|
||||
promotionProber PromotionEvidenceProvider
|
||||
cancel context.CancelFunc
|
||||
wg sync.WaitGroup
|
||||
// RPC registration/place/move/ACK/delete and product ticks serialize here.
|
||||
// Order: workspaceMu -> publisher or lifecycle store locks (not reversed).
|
||||
workspaceMu sync.Mutex
|
||||
events *eventRing
|
||||
promotionMu sync.RWMutex
|
||||
promotionProber PromotionEvidenceProvider
|
||||
cancel context.CancelFunc
|
||||
wg sync.WaitGroup
|
||||
|
||||
started atomic.Bool
|
||||
}
|
||||
@@ -241,6 +245,13 @@ func New(cfg Config) (*Host, error) {
|
||||
h.obs = obs
|
||||
h.ln = ln
|
||||
h.lifecycle = lifecycleStores
|
||||
if h.lifecycle != nil {
|
||||
if err := h.reconcileWorkspaceBindings(); err != nil {
|
||||
_ = ln.Close()
|
||||
_ = boot.Close()
|
||||
return nil, fmt.Errorf("master.New: workspace binding recovery: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
if cfg.FrontendPublicationRuntimeHTTP {
|
||||
addr := cfg.FrontendPublicationRuntimeListen
|
||||
@@ -295,10 +306,15 @@ func openLifecycleStores(dir string) (*LifecycleStores, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
bindings, err := lifecycle.OpenWorkspaceBindingStore(filepath.Join(dir, "workspace-bindings"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &LifecycleStores{
|
||||
Volumes: volumes,
|
||||
Nodes: nodes,
|
||||
Placements: placements,
|
||||
Volumes: volumes,
|
||||
Nodes: nodes,
|
||||
Placements: placements,
|
||||
WorkspaceBindings: bindings,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -50,6 +50,8 @@ func (h *Host) SetPromotionEvidenceProvider(p PromotionEvidenceProvider) {
|
||||
// directive queue. It never calls Publisher.apply; Publisher remains the only
|
||||
// authority minter through its normal Run loop.
|
||||
func (h *Host) RunLifecycleProductTick() (LifecycleProductTickResult, error) {
|
||||
h.workspaceMu.Lock()
|
||||
defer h.workspaceMu.Unlock()
|
||||
stores := h.Lifecycle()
|
||||
if stores == nil {
|
||||
return LifecycleProductTickResult{}, nil
|
||||
|
||||
@@ -75,6 +75,8 @@ func (s *services) CreateVolume(ctx context.Context, req *control.CreateVolumeRe
|
||||
}
|
||||
|
||||
func (s *services) DeleteVolume(ctx context.Context, req *control.DeleteVolumeRequest) (*control.DeleteVolumeResponse, error) {
|
||||
s.host.workspaceMu.Lock()
|
||||
defer s.host.workspaceMu.Unlock()
|
||||
stores := s.host.Lifecycle()
|
||||
if stores == nil {
|
||||
return nil, status.Error(codes.FailedPrecondition, "lifecycle store is not configured")
|
||||
@@ -88,6 +90,9 @@ func (s *services) DeleteVolume(ctx context.Context, req *control.DeleteVolumeRe
|
||||
if err := stores.Volumes.DeleteVolume(req.GetVolumeId()); err != nil {
|
||||
return nil, lifecycleError("delete volume", err)
|
||||
}
|
||||
if err := stores.WorkspaceBindings.DeleteVolume(req.GetVolumeId()); err != nil {
|
||||
return nil, lifecycleError("delete workspace bindings", err)
|
||||
}
|
||||
return &control.DeleteVolumeResponse{}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
package master
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/lifecycle"
|
||||
control "github.com/seaweedfs/seaweed-block/core/rpc/control"
|
||||
)
|
||||
|
||||
func bindingFact(b lifecycle.WorkspaceBinding) *control.WorkspaceBinding {
|
||||
return &control.WorkspaceBinding{VolumeId: b.VolumeID, ServerId: b.ServerID, DataAddr: b.DataAddr, CtrlAddr: b.CtrlAddr, Retired: b.Retired}
|
||||
}
|
||||
|
||||
func (s *services) RegisterWorkspaceBinding(ctx context.Context, q *control.WorkspaceBinding) (*control.WorkspaceBinding, error) {
|
||||
s.host.workspaceMu.Lock()
|
||||
defer s.host.workspaceMu.Unlock()
|
||||
if err := s.workspaceVolume(q.GetVolumeId()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := ctx.Err(); err != nil {
|
||||
return nil, workspaceError(err)
|
||||
}
|
||||
if err := s.host.reconcileWorkspaceBindings(); err != nil {
|
||||
return nil, workspaceError(err)
|
||||
}
|
||||
if _, ok := s.host.lifecycle.Nodes.GetNode(q.GetServerId()); !ok {
|
||||
return nil, workspaceError(fmt.Errorf("workspace binding: unknown server"))
|
||||
}
|
||||
b := lifecycle.WorkspaceBinding{VolumeID: q.GetVolumeId(), ServerID: q.GetServerId(), DataAddr: q.GetDataAddr(), CtrlAddr: q.GetCtrlAddr(), Retired: q.GetRetired()}
|
||||
// Legacy assignments also reserve their live endpoints. Merely preparing
|
||||
// the first explicit target must not make the old source pair reusable.
|
||||
for _, v := range s.host.lifecycle.Volumes.ListVolumes() {
|
||||
if v.Spec.VolumeID == b.VolumeID {
|
||||
continue
|
||||
}
|
||||
line, ok := s.host.Publisher().VolumeAuthorityLine(v.Spec.VolumeID)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
state := s.host.Publisher().WorkspaceState(v.Spec.VolumeID)
|
||||
if state != nil && state.Ack != nil && state.Ack.Epoch == line.Epoch {
|
||||
continue
|
||||
}
|
||||
if b.EndpointsOverlap(lifecycle.WorkspaceBinding{DataAddr: line.DataAddr, CtrlAddr: line.CtrlAddr}) {
|
||||
return nil, workspaceError(fmt.Errorf("workspace binding: endpoint belongs to live assignment"))
|
||||
}
|
||||
}
|
||||
if err := s.host.lifecycle.WorkspaceBindings.Register(b); err != nil {
|
||||
return nil, workspaceError(err)
|
||||
}
|
||||
return bindingFact(b), nil
|
||||
}
|
||||
|
||||
func (h *Host) workspaceSourceHost(volume, replica string, epoch uint64) string {
|
||||
if state := h.Publisher().WorkspaceState(volume); state != nil {
|
||||
for _, r := range state.Moves {
|
||||
if r.Issued && r.NewReplicaID == replica && r.NewEpoch == epoch {
|
||||
return r.NewHost
|
||||
}
|
||||
}
|
||||
}
|
||||
if p, ok := h.lifecycle.Placements.GetPlacement(volume); ok {
|
||||
for _, slot := range p.Slots {
|
||||
if slot.ReplicaID == replica {
|
||||
return slot.ServerID
|
||||
}
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// Recover retirement after a crash between the authority ACK/issued record
|
||||
// and binding persistence. Epoch-tagged retirements cannot retire a later
|
||||
// re-registration when an old Move/ACK is retried or replayed on restart.
|
||||
// Caller owns workspaceMu, or Host.New has not exposed the host yet.
|
||||
func (h *Host) reconcileWorkspaceBindings() error {
|
||||
for _, v := range h.lifecycle.Volumes.ListVolumes() {
|
||||
volume := v.Spec.VolumeID
|
||||
state := h.Publisher().WorkspaceState(volume)
|
||||
if state == nil {
|
||||
continue
|
||||
}
|
||||
for _, m := range state.Moves {
|
||||
if m.Issued {
|
||||
if err := h.lifecycle.WorkspaceBindings.Retire(volume, m.OldHost, m.OldEpoch); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
if a := state.Ack; a != nil {
|
||||
host := h.workspaceSourceHost(volume, a.ReplicaID, a.Epoch)
|
||||
if host != "" {
|
||||
if err := h.lifecycle.WorkspaceBindings.Retire(volume, host, a.Epoch); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *services) PlaceWorkspace(ctx context.Context, q *control.WorkspacePlacement) (*control.WorkspaceEmpty, error) {
|
||||
s.host.workspaceMu.Lock()
|
||||
defer s.host.workspaceMu.Unlock()
|
||||
if err := s.workspaceVolume(q.GetVolumeId()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list, _, err := s.host.lifecycle.WorkspaceBindings.Get(q.GetVolumeId())
|
||||
if err != nil {
|
||||
return nil, workspaceError(err)
|
||||
}
|
||||
var binding *lifecycle.WorkspaceBinding
|
||||
for _, b := range list {
|
||||
if b.ServerID == q.GetServerId() && !b.Retired {
|
||||
copy := b
|
||||
binding = ©
|
||||
}
|
||||
}
|
||||
if binding == nil || q.GetReplicaId() == "" {
|
||||
return nil, workspaceError(fmt.Errorf("workspace placement: active prepared binding and replica required"))
|
||||
}
|
||||
if _, ok := s.host.lifecycle.Nodes.GetNode(q.GetServerId()); !ok {
|
||||
return nil, workspaceError(fmt.Errorf("workspace placement: unknown server"))
|
||||
}
|
||||
err = s.host.Publisher().RecordWorkspacePlacement(ctx, q.GetVolumeId(), func() error {
|
||||
if p, ok := s.host.lifecycle.Placements.GetPlacement(q.GetVolumeId()); ok {
|
||||
if len(p.Slots) == 1 && p.Slots[0].ServerID == binding.ServerID && p.Slots[0].ReplicaID == q.GetReplicaId() && p.Slots[0].DataAddr == binding.DataAddr && p.Slots[0].CtrlAddr == binding.CtrlAddr {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("workspace placement: existing intent differs")
|
||||
}
|
||||
_, e := s.host.lifecycle.Placements.ApplyPlan(lifecycle.PlacementPlan{VolumeID: q.GetVolumeId(), DesiredRF: 1, Candidates: []lifecycle.PlacementCandidate{{VolumeID: q.GetVolumeId(), ServerID: binding.ServerID, ReplicaID: q.GetReplicaId(), Source: lifecycle.PlacementSourceExistingReplica, DataAddr: binding.DataAddr, CtrlAddr: binding.CtrlAddr}}})
|
||||
return e
|
||||
})
|
||||
if err != nil {
|
||||
return nil, workspaceError(err)
|
||||
}
|
||||
return &control.WorkspaceEmpty{}, nil
|
||||
}
|
||||
@@ -0,0 +1,266 @@
|
||||
package master
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"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"
|
||||
)
|
||||
|
||||
func TestWorkspaceBindingPlacesRF1OnChosenNode(t *testing.T) {
|
||||
h, err := New(Config{Listen: "127.0.0.1:0", AuthorityStoreDir: t.TempDir(), LifecycleStoreDir: t.TempDir(), WorkspaceRPC: true, WorkspaceHeadReader: func(context.Context, string) (authority.WorkspaceHead, error) { return authority.WorkspaceHead{}, nil }})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
h.Start()
|
||||
defer closeTestMaster(t, h)
|
||||
conn, err := grpc.NewClient(h.Addr(), grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer conn.Close()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
client := control.NewWorkspaceServiceClient(conn)
|
||||
if _, err = control.NewLifecycleServiceClient(conn).CreateVolume(ctx, &control.CreateVolumeRequest{VolumeId: "chosen", SizeBytes: 1 << 20, ReplicationFactor: 1}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = h.Lifecycle().Nodes.RegisterNode(lifecycle.NodeRegistration{ServerID: "node-chosen", DataAddr: "127.0.0.1:9200", CtrlAddr: "127.0.0.1:9100"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b := &control.WorkspaceBinding{VolumeId: "chosen", ServerId: "node-chosen", DataAddr: "127.0.0.1:19200", CtrlAddr: "127.0.0.1:19100"}
|
||||
if _, err = client.RegisterWorkspaceBinding(ctx, b); err != nil {
|
||||
t.Fatalf("register chosen per-volume binding: %v", err)
|
||||
}
|
||||
if _, err = client.PlaceWorkspace(ctx, &control.WorkspacePlacement{VolumeId: "chosen", ServerId: "node-chosen", ReplicaId: "r1"}); err != nil {
|
||||
t.Fatal("place chosen RF1", err)
|
||||
}
|
||||
p, ok := h.Lifecycle().Placements.GetPlacement("chosen")
|
||||
if !ok || len(p.Slots) != 1 || p.Slots[0].ServerID != "node-chosen" || p.Slots[0].DataAddr != b.DataAddr || p.Slots[0].CtrlAddr != b.CtrlAddr {
|
||||
t.Fatal("wrong chosen intent", p)
|
||||
}
|
||||
if _, ok := h.Publisher().VolumeAuthorityLine("chosen"); ok {
|
||||
t.Fatal("placement minted authority without observation")
|
||||
}
|
||||
if _, err = control.NewObservationServiceClient(conn).ReportHeartbeat(ctx, &control.HeartbeatReport{ServerId: "node-chosen", SentAt: timestamppb.Now(), Reachable: true, Eligible: true, Slots: []*control.HeartbeatSlot{{VolumeId: "chosen", ReplicaId: "r1", DataAddr: b.DataAddr, CtrlAddr: b.CtrlAddr}}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = h.RunLifecycleProductTick(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
line := waitAuthorityLine(t, h.Publisher(), "chosen")
|
||||
if line.ReplicaID != "r1" || line.DataAddr != b.DataAddr || line.CtrlAddr != b.CtrlAddr {
|
||||
t.Fatal("wrong chosen assignment", line)
|
||||
}
|
||||
if _, err = client.PlaceWorkspace(ctx, &control.WorkspacePlacement{VolumeId: "chosen", ServerId: "node-chosen", ReplicaId: "different"}); err == nil {
|
||||
t.Fatal("assigned volume accepted new placement")
|
||||
}
|
||||
}
|
||||
|
||||
func TestWorkspaceBindingsMoveTwoVolumesToOneHost(t *testing.T) {
|
||||
workspaceBindingsMove(t, false)
|
||||
}
|
||||
|
||||
func TestWorkspaceBindingsForcedRetiresOnlyAfterIssue(t *testing.T) {
|
||||
workspaceBindingsMove(t, true)
|
||||
}
|
||||
|
||||
func workspaceBindingsMove(t *testing.T, forced bool) {
|
||||
cfg := Config{Listen: "127.0.0.1:0", AuthorityStoreDir: t.TempDir(), LifecycleStoreDir: t.TempDir(), WorkspaceRPC: true, WorkspaceHeadReader: func(context.Context, string) (authority.WorkspaceHead, error) {
|
||||
return authority.WorkspaceHead{Gen: 9, Epoch: 1, Holder: "node-a/r1", RemoteLSN: 42, Detached: true}, nil
|
||||
}}
|
||||
h, err := New(cfg)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
h.Start()
|
||||
defer closeTestMaster(t, h)
|
||||
conn, err := grpc.NewClient(h.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()
|
||||
client := control.NewWorkspaceServiceClient(conn)
|
||||
for _, server := range []string{"node-a", "node-b"} {
|
||||
if _, err = h.Lifecycle().Nodes.RegisterNode(lifecycle.NodeRegistration{ServerID: server, DataAddr: "127.0.0.1:9200", CtrlAddr: "127.0.0.1:9100"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
volumes := []string{"vol-one", "vol-two"}
|
||||
if forced {
|
||||
volumes = volumes[:1]
|
||||
}
|
||||
for i, vol := range volumes {
|
||||
if _, err = control.NewLifecycleServiceClient(conn).CreateVolume(ctx, &control.CreateVolumeRequest{VolumeId: vol, SizeBytes: 1 << 20, ReplicationFactor: 1}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
src := &control.WorkspaceBinding{VolumeId: vol, ServerId: "node-a", DataAddr: fmt.Sprintf("127.0.0.1:%d", 19200+i), CtrlAddr: fmt.Sprintf("127.0.0.1:%d", 19100+i)}
|
||||
target := &control.WorkspaceBinding{VolumeId: vol, ServerId: "node-b", DataAddr: fmt.Sprintf("127.0.0.1:%d", 29200+i), CtrlAddr: fmt.Sprintf("127.0.0.1:%d", 29100+i)}
|
||||
for _, b := range []*control.WorkspaceBinding{src, target} {
|
||||
if _, err = client.RegisterWorkspaceBinding(ctx, b); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if _, err = client.PlaceWorkspace(ctx, &control.WorkspacePlacement{VolumeId: vol, ServerId: "node-a", ReplicaId: "r1"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = control.NewObservationServiceClient(conn).ReportHeartbeat(ctx, &control.HeartbeatReport{ServerId: "node-a", SentAt: timestamppb.Now(), Reachable: true, Eligible: true, Slots: []*control.HeartbeatSlot{{VolumeId: vol, ReplicaId: "r1", DataAddr: src.DataAddr, CtrlAddr: src.CtrlAddr}}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = h.RunLifecycleProductTick(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
line := waitAuthorityLine(t, h.Publisher(), vol)
|
||||
id := &control.WorkspaceIdentity{VolumeId: vol, ReplicaId: "r1", Epoch: line.Epoch}
|
||||
lease, e := client.RenewWorkspaceLease(ctx, id)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if forced {
|
||||
select {
|
||||
case <-time.After(time.Until(time.Unix(0, lease.ExpiresAtNs)) + 20*time.Millisecond):
|
||||
case <-ctx.Done():
|
||||
t.Fatal(ctx.Err())
|
||||
}
|
||||
} else {
|
||||
if _, err = client.RevokeWorkspace(ctx, id); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = client.AckWorkspaceRevoked(ctx, &control.WorkspaceRevocationAck{Identity: id, HeadGen: 9}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
before, e := client.QueryWorkspace(ctx, &control.WorkspaceVolume{VolumeId: vol})
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
for _, b := range before.Bindings {
|
||||
if b.ServerId == "node-a" && b.Retired == forced {
|
||||
t.Fatal("source retirement occurred at wrong boundary", b)
|
||||
}
|
||||
}
|
||||
q := &control.WorkspaceMove{RequestId: vol + "-bad", VolumeId: vol, ExpectedReplicaId: "r1", ExpectedEpoch: line.Epoch, TargetReplicaId: "r1", TargetServerId: "node-b", TargetDataAddr: "127.0.0.1:9200", TargetCtrlAddr: "127.0.0.1:9100", Kind: "clean"}
|
||||
if forced {
|
||||
q.Kind = "forced"
|
||||
q.Force = true
|
||||
}
|
||||
if _, err = client.MoveWorkspace(ctx, q); err == nil {
|
||||
t.Fatal("explicit volume fell back to legacy node pair")
|
||||
}
|
||||
q.RequestId = vol + "-move"
|
||||
q.TargetDataAddr = target.DataAddr
|
||||
q.TargetCtrlAddr = target.CtrlAddr
|
||||
if _, err = client.MoveWorkspace(ctx, q); err != nil {
|
||||
t.Fatal("prepared per-volume target refused", err)
|
||||
}
|
||||
got, ok := h.Publisher().VolumeAuthorityLine(vol)
|
||||
if !ok || got.Epoch != 2 || got.DataAddr != target.DataAddr || got.CtrlAddr != target.CtrlAddr {
|
||||
t.Fatal("wrong moved authority", got)
|
||||
}
|
||||
placement, _ := h.Lifecycle().Placements.GetPlacement(vol)
|
||||
if placement.Slots[0].ServerID != "node-a" {
|
||||
t.Fatal("move rewrote source intent", placement)
|
||||
}
|
||||
state, err := client.QueryWorkspace(ctx, &control.WorkspaceVolume{VolumeId: vol})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(state.Bindings) != 2 {
|
||||
t.Fatal("missing bindings", state)
|
||||
}
|
||||
for _, b := range state.Bindings {
|
||||
if (b.ServerId == "node-a") != b.Retired {
|
||||
t.Fatal("wrong binding lifecycle", b)
|
||||
}
|
||||
}
|
||||
}
|
||||
closeTestMaster(t, h)
|
||||
h2, err := New(cfg)
|
||||
if err != nil {
|
||||
t.Fatal("restart", err)
|
||||
}
|
||||
h2.Start()
|
||||
defer closeTestMaster(t, h2)
|
||||
c2, err := grpc.NewClient(h2.Addr(), grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c2.Close()
|
||||
for _, v := range volumes {
|
||||
state, e := control.NewWorkspaceServiceClient(c2).QueryWorkspace(ctx, &control.WorkspaceVolume{VolumeId: v})
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if len(state.Bindings) != 2 || len(state.Moves) != 1 || state.Moves[0].NewEpoch != 2 {
|
||||
t.Fatal("restart lost binding/grant", state)
|
||||
}
|
||||
for _, b := range state.Bindings {
|
||||
if (b.ServerId == "node-a") != b.Retired {
|
||||
t.Fatal("restart changed retirement", b)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestWorkspaceBindingsRejectCollisionsAndLiveChangesAndDeleteCleans(t *testing.T) {
|
||||
h, e := New(Config{Listen: "127.0.0.1:0", AuthorityStoreDir: t.TempDir(), LifecycleStoreDir: t.TempDir(), WorkspaceRPC: true, WorkspaceHeadReader: func(context.Context, string) (authority.WorkspaceHead, error) { return authority.WorkspaceHead{}, nil }})
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
h.Start()
|
||||
defer closeTestMaster(t, h)
|
||||
c, e := grpc.NewClient(h.Addr(), grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
defer c.Close()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
client, life := control.NewWorkspaceServiceClient(c), control.NewLifecycleServiceClient(c)
|
||||
for _, v := range []string{"a", "b", "c"} {
|
||||
if _, e = life.CreateVolume(ctx, &control.CreateVolumeRequest{VolumeId: v, SizeBytes: 1 << 20, ReplicationFactor: 1}); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
}
|
||||
if _, e = h.Lifecycle().Nodes.RegisterNode(lifecycle.NodeRegistration{ServerID: "node", DataAddr: "127.0.0.1:9000", CtrlAddr: "127.0.0.1:9001"}); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
a := &control.WorkspaceBinding{VolumeId: "a", ServerId: "unknown", DataAddr: "127.0.0.1:10000", CtrlAddr: "127.0.0.1:10001"}
|
||||
if _, e = client.RegisterWorkspaceBinding(ctx, a); e == nil {
|
||||
t.Fatal("unknown server accepted")
|
||||
}
|
||||
a.ServerId = "node"
|
||||
for i := 0; i < 2; i++ {
|
||||
if _, e = client.RegisterWorkspaceBinding(ctx, a); e != nil {
|
||||
t.Fatal("idempotent registration", e)
|
||||
}
|
||||
}
|
||||
changed := &control.WorkspaceBinding{VolumeId: a.VolumeId, ServerId: a.ServerId, DataAddr: "127.0.0.1:10002", CtrlAddr: a.CtrlAddr}
|
||||
if _, e = client.RegisterWorkspaceBinding(ctx, changed); e == nil {
|
||||
t.Fatal("live binding changed")
|
||||
}
|
||||
for _, pair := range [][2]string{{a.DataAddr, a.CtrlAddr}, {a.CtrlAddr, "127.0.0.1:10003"}, {"127.0.0.1:010000", "127.0.0.1:10003"}, {"[::ffff:127.0.0.1]:10000", "127.0.0.1:10003"}} {
|
||||
if _, e = client.RegisterWorkspaceBinding(ctx, &control.WorkspaceBinding{VolumeId: "b", ServerId: "node", DataAddr: pair[0], CtrlAddr: pair[1]}); e == nil {
|
||||
t.Fatal("live endpoint collision accepted")
|
||||
}
|
||||
}
|
||||
if _, e = life.DeleteVolume(ctx, &control.DeleteVolumeRequest{VolumeId: "a"}); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if _, bound, e := h.Lifecycle().WorkspaceBindings.Get("a"); e != nil || bound {
|
||||
t.Fatal("deleted volume retained binding", bound, e)
|
||||
}
|
||||
a.VolumeId = "c"
|
||||
if _, e = client.RegisterWorkspaceBinding(ctx, a); e != nil {
|
||||
t.Fatal("deleted volume did not release endpoints", e)
|
||||
}
|
||||
}
|
||||
@@ -4,9 +4,49 @@ The opt-in master surface is `WorkspaceService` in `workspace.proto`. Enable it
|
||||
with `blockmaster --workspace-rpc --workspace-head-base-url <filer directory URL>`
|
||||
and a lifecycle store. Other volumes continue using the existing assignment
|
||||
protocol. Workspace operations require an existing RF=1 volume. The target node
|
||||
must be registered with matching data/control endpoints; the source node comes
|
||||
must be registered; explicit volumes use their prepared per-volume endpoints,
|
||||
while volumes with no binding retain node-pair compatibility. The source comes
|
||||
from its placement or the previous issued move, not a caller's evidence flag.
|
||||
|
||||
## Per-volume endpoint preparation and placement
|
||||
|
||||
W6 allocates listener ports and calls `RegisterWorkspaceBinding` with volume,
|
||||
registered server ID, data address and control address before placement or move.
|
||||
The binding is a durable endpoint reservation, not authority or readiness.
|
||||
Registration is idempotent for the same pair; changing a live binding or taking
|
||||
another live volume's endpoint is refused. Prepared pairs also reserve their
|
||||
ports. Numeric IP/port spellings are normalized for collision checks without
|
||||
performing DNS lookup. Callers must use consistent DNS names for endpoints.
|
||||
|
||||
`PlaceWorkspace {volume_id, server_id, replica_id}` records chosen-node intent
|
||||
for an existing, unassigned RF=1 volume with an active prepared binding. It does
|
||||
not create a volume or mint an epoch. Existing different placement intent is
|
||||
refused rather than silently replacing a queued plan. Observation and the
|
||||
existing controller/publisher path still establish the assignment. Repeated
|
||||
identical intent is allowed before assignment; assigned volumes use Move.
|
||||
|
||||
Move validates the PREPARED target binding and leaves the source placement
|
||||
unchanged. Once a volume has any explicit binding, it never uses the legacy
|
||||
node-level pair, even if all its bindings are retired. CLEAN retires the source
|
||||
binding only after its durable clean ACK. FORCED retires it only after the new
|
||||
epoch is issued. Retirement carries the old epoch, making crash recovery and
|
||||
old-request replay harmless to a later re-prepared binding. Registration may
|
||||
reuse retired ports; a live target must be prepared again before another move.
|
||||
Volume deletion removes its binding marker and reservations after deleting
|
||||
lifecycle state. Failed deletion can be retried.
|
||||
|
||||
Bindings are a file-synced, atomic snapshot with directory fsync. Ambiguous
|
||||
publication errors fence binding reads/mutations until restart. Startup and
|
||||
registration reconcile retirement from persisted ACK/issued move records, so
|
||||
a crash between authority persistence and binding retirement is recoverable.
|
||||
`QueryWorkspace` returns the per-volume bindings including their retired state.
|
||||
|
||||
Host workspace operations and product ticks serialize with `workspaceMu`.
|
||||
Lock order is host workspace mutex, then Publisher or lifecycle-store locks.
|
||||
Initial placement persists under a Publisher unassigned guard; its callback
|
||||
must never call Publisher. Store reads do not hold their mutex while calling
|
||||
Publisher. Lease renewal remains independent of the host workspace mutex.
|
||||
|
||||
The RPCs grant/renew a lease, request revocation, record the old holder's ACK,
|
||||
request a move, and query persisted state. Leases bind volume, holder and epoch.
|
||||
The master owns a 30-second expiry. After expiry, that same assignment cannot
|
||||
|
||||
@@ -76,6 +76,8 @@ func (s *services) RevokeWorkspace(ctx context.Context, q *control.WorkspaceIden
|
||||
}
|
||||
|
||||
func (s *services) AckWorkspaceRevoked(ctx context.Context, q *control.WorkspaceRevocationAck) (*control.WorkspaceEmpty, error) {
|
||||
s.host.workspaceMu.Lock()
|
||||
defer s.host.workspaceMu.Unlock()
|
||||
id := q.GetIdentity()
|
||||
if err := s.workspaceVolume(id.GetVolumeId()); err != nil {
|
||||
return nil, err
|
||||
@@ -83,6 +85,9 @@ func (s *services) AckWorkspaceRevoked(ctx context.Context, q *control.Workspace
|
||||
if err := s.host.Publisher().AckWorkspaceRevocation(ctx, id.GetVolumeId(), authority.WorkspaceRevokeAck{ReplicaID: id.GetReplicaId(), Epoch: id.GetEpoch(), HeadGen: q.GetHeadGen()}); err != nil {
|
||||
return nil, workspaceError(err)
|
||||
}
|
||||
if err := s.host.reconcileWorkspaceBindings(); err != nil {
|
||||
return nil, workspaceError(err)
|
||||
}
|
||||
return &control.WorkspaceEmpty{}, nil
|
||||
}
|
||||
|
||||
@@ -92,28 +97,24 @@ func grantFact(r authority.WorkspaceMoveRecord) *control.WorkspaceGrant {
|
||||
}
|
||||
|
||||
func (s *services) MoveWorkspace(ctx context.Context, q *control.WorkspaceMove) (*control.WorkspaceGrant, error) {
|
||||
s.host.workspaceMu.Lock()
|
||||
defer s.host.workspaceMu.Unlock()
|
||||
if err := s.workspaceVolume(q.GetVolumeId()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
oldHost := ""
|
||||
if state := s.host.Publisher().WorkspaceState(q.GetVolumeId()); state != nil {
|
||||
for _, r := range state.Moves {
|
||||
if r.Issued && r.NewReplicaID == q.GetExpectedReplicaId() && r.NewEpoch == q.GetExpectedEpoch() {
|
||||
oldHost = r.NewHost
|
||||
}
|
||||
}
|
||||
}
|
||||
if oldHost == "" {
|
||||
if placement, ok := s.host.lifecycle.Placements.GetPlacement(q.GetVolumeId()); ok {
|
||||
for _, slot := range placement.Slots {
|
||||
if slot.ReplicaID == q.GetExpectedReplicaId() {
|
||||
oldHost = slot.ServerID
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
oldHost := s.host.workspaceSourceHost(q.GetVolumeId(), q.GetExpectedReplicaId(), q.GetExpectedEpoch())
|
||||
target, ok := s.host.lifecycle.Nodes.GetNode(q.GetTargetServerId())
|
||||
if oldHost == "" || !ok || target.ServerID == oldHost || target.DataAddr != q.GetTargetDataAddr() || target.CtrlAddr != q.GetTargetCtrlAddr() {
|
||||
bindings, explicit, err := s.host.lifecycle.WorkspaceBindings.Get(q.GetVolumeId())
|
||||
if err != nil {
|
||||
return nil, workspaceError(err)
|
||||
}
|
||||
matched := !explicit && target.DataAddr == q.GetTargetDataAddr() && target.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")
|
||||
}
|
||||
// Always bound the configured reader, even when the caller omitted a deadline.
|
||||
@@ -128,14 +129,26 @@ func (s *services) MoveWorkspace(ctx context.Context, q *control.WorkspaceMove)
|
||||
if err != nil {
|
||||
return nil, workspaceError(err)
|
||||
}
|
||||
if err = s.host.reconcileWorkspaceBindings(); err != nil {
|
||||
return nil, workspaceError(err)
|
||||
}
|
||||
return grantFact(r), nil
|
||||
}
|
||||
|
||||
func (s *services) QueryWorkspace(ctx context.Context, q *control.WorkspaceVolume) (*control.WorkspaceStatus, error) {
|
||||
s.host.workspaceMu.Lock()
|
||||
defer s.host.workspaceMu.Unlock()
|
||||
if err := s.workspaceVolume(q.GetVolumeId()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out := &control.WorkspaceStatus{}
|
||||
bindings, _, err := s.host.lifecycle.WorkspaceBindings.Get(q.GetVolumeId())
|
||||
if err != nil {
|
||||
return nil, workspaceError(err)
|
||||
}
|
||||
for _, b := range bindings {
|
||||
out.Bindings = append(out.Bindings, bindingFact(b))
|
||||
}
|
||||
state := s.host.Publisher().WorkspaceState(q.GetVolumeId())
|
||||
if state == nil {
|
||||
return out, nil
|
||||
|
||||
@@ -0,0 +1,244 @@
|
||||
package lifecycle
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// WorkspaceBinding is prepared endpoint ownership, not assignment/readiness.
|
||||
// Retired entries remain as a per-volume marker: explicit volumes never fall
|
||||
// back to node-level addresses, even after all their bindings are retired.
|
||||
type WorkspaceBinding struct {
|
||||
VolumeID string `json:"volume_id"`
|
||||
ServerID string `json:"server_id"`
|
||||
DataAddr string `json:"data_addr"`
|
||||
CtrlAddr string `json:"ctrl_addr"`
|
||||
Retired bool `json:"retired,omitempty"`
|
||||
RetiredEpoch uint64 `json:"retired_epoch,omitempty"` // idempotent authority retirement event
|
||||
}
|
||||
|
||||
type WorkspaceBindingStore struct {
|
||||
mu sync.Mutex
|
||||
dir string
|
||||
records map[string][]WorkspaceBinding
|
||||
uncertain bool
|
||||
}
|
||||
|
||||
func OpenWorkspaceBindingStore(dir string) (*WorkspaceBindingStore, error) {
|
||||
if err := os.MkdirAll(dir, 0755); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s := &WorkspaceBindingStore{dir: dir, records: map[string][]WorkspaceBinding{}}
|
||||
b, err := os.ReadFile(filepath.Join(dir, "bindings.json"))
|
||||
if os.IsNotExist(err) {
|
||||
return s, nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = json.Unmarshal(b, &s.records); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if s.records == nil {
|
||||
return nil, fmt.Errorf("workspace bindings: null state")
|
||||
}
|
||||
for v, list := range s.records {
|
||||
if err = validateVolumeID(v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
seen := map[string]bool{}
|
||||
for _, r := range list {
|
||||
if r.VolumeID != v || seen[r.ServerID] {
|
||||
return nil, fmt.Errorf("workspace bindings: inconsistent record")
|
||||
}
|
||||
seen[r.ServerID] = true
|
||||
if err = validateWorkspaceBinding(r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !r.Retired {
|
||||
if err = bindingCollision(s.records, r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return s, nil
|
||||
}
|
||||
|
||||
func validateWorkspaceBinding(b WorkspaceBinding) error {
|
||||
if err := validateVolumeID(b.VolumeID); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateServerID(b.ServerID); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, a := range []string{b.DataAddr, b.CtrlAddr} {
|
||||
h, p, e := net.SplitHostPort(a)
|
||||
n, e2 := strconv.Atoi(p)
|
||||
if e != nil || e2 != nil || h == "" || n < 1 || n > 65535 {
|
||||
return fmt.Errorf("workspace binding: invalid endpoint %q", a)
|
||||
}
|
||||
}
|
||||
if workspaceEndpointKey(b.DataAddr) == workspaceEndpointKey(b.CtrlAddr) {
|
||||
return fmt.Errorf("workspace binding: endpoints must differ")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Compare numeric ports and equivalent IP spellings without DNS/network I/O.
|
||||
func workspaceEndpointKey(addr string) string {
|
||||
h, p, err := net.SplitHostPort(addr)
|
||||
if err != nil {
|
||||
return addr
|
||||
}
|
||||
n, err := strconv.Atoi(p)
|
||||
if err != nil {
|
||||
return addr
|
||||
}
|
||||
if ip := net.ParseIP(h); ip != nil {
|
||||
h = ip.String()
|
||||
} else {
|
||||
h = strings.ToLower(h)
|
||||
}
|
||||
return net.JoinHostPort(h, strconv.Itoa(n))
|
||||
}
|
||||
|
||||
func (b WorkspaceBinding) EndpointsOverlap(other WorkspaceBinding) bool {
|
||||
d, c := workspaceEndpointKey(b.DataAddr), workspaceEndpointKey(b.CtrlAddr)
|
||||
od, oc := workspaceEndpointKey(other.DataAddr), workspaceEndpointKey(other.CtrlAddr)
|
||||
return d == od || d == oc || c == od || c == oc
|
||||
}
|
||||
|
||||
func bindingCollision(all map[string][]WorkspaceBinding, b WorkspaceBinding) error {
|
||||
for _, list := range all {
|
||||
for _, r := range list {
|
||||
if r.Retired || (r.VolumeID == b.VolumeID && r.ServerID == b.ServerID) {
|
||||
continue
|
||||
}
|
||||
if b.EndpointsOverlap(r) {
|
||||
return fmt.Errorf("workspace binding: endpoint reserved by %s on %s", r.VolumeID, r.ServerID)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *WorkspaceBindingStore) Get(volume string) ([]WorkspaceBinding, bool, error) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
if s.uncertain {
|
||||
return nil, false, fmt.Errorf("workspace bindings uncertain; restart required")
|
||||
}
|
||||
list, ok := s.records[volume]
|
||||
return append([]WorkspaceBinding(nil), list...), ok, nil
|
||||
}
|
||||
|
||||
func (s *WorkspaceBindingStore) Register(b WorkspaceBinding) error {
|
||||
if b.Retired {
|
||||
return fmt.Errorf("workspace binding: retired is server-owned")
|
||||
}
|
||||
if err := validateWorkspaceBinding(b); err != nil {
|
||||
return err
|
||||
}
|
||||
return s.update(func(all map[string][]WorkspaceBinding) error {
|
||||
if err := bindingCollision(all, b); err != nil {
|
||||
return err
|
||||
}
|
||||
list := all[b.VolumeID]
|
||||
for i, r := range list {
|
||||
if r.ServerID == b.ServerID {
|
||||
if !r.Retired && r.DataAddr == b.DataAddr && r.CtrlAddr == b.CtrlAddr {
|
||||
return nil
|
||||
}
|
||||
if !r.Retired {
|
||||
return fmt.Errorf("workspace binding: live binding cannot change")
|
||||
}
|
||||
list[i] = b
|
||||
list[i].RetiredEpoch = r.RetiredEpoch
|
||||
all[b.VolumeID] = list
|
||||
return nil
|
||||
}
|
||||
}
|
||||
all[b.VolumeID] = append(list, b)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func (s *WorkspaceBindingStore) Retire(volume, server string, epoch uint64) error {
|
||||
return s.update(func(all map[string][]WorkspaceBinding) error {
|
||||
for i := range all[volume] {
|
||||
if all[volume][i].ServerID == server && epoch > all[volume][i].RetiredEpoch {
|
||||
all[volume][i].Retired = true
|
||||
all[volume][i].RetiredEpoch = epoch
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func (s *WorkspaceBindingStore) DeleteVolume(volume string) error {
|
||||
return s.update(func(all map[string][]WorkspaceBinding) error { delete(all, volume); return nil })
|
||||
}
|
||||
|
||||
// Atomic snapshot includes collision ownership across volumes. No in-memory
|
||||
// mutation is committed before durable publication. An ambiguous filesystem
|
||||
// error latches the store fail-closed until reload, including read admission.
|
||||
func (s *WorkspaceBindingStore) update(change func(map[string][]WorkspaceBinding) error) error {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
if s.uncertain {
|
||||
return fmt.Errorf("workspace bindings uncertain; restart required")
|
||||
}
|
||||
all := make(map[string][]WorkspaceBinding, len(s.records))
|
||||
for v, l := range s.records {
|
||||
all[v] = append([]WorkspaceBinding(nil), l...)
|
||||
}
|
||||
if err := change(all); err != nil {
|
||||
return err
|
||||
}
|
||||
b, err := json.Marshal(all)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
old, _ := json.Marshal(s.records)
|
||||
if bytes.Equal(b, old) {
|
||||
return nil
|
||||
}
|
||||
f, err := os.CreateTemp(s.dir, "bindings-*.tmp")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer os.Remove(f.Name())
|
||||
if _, err = f.Write(b); err == nil {
|
||||
err = f.Sync()
|
||||
}
|
||||
closeErr := f.Close()
|
||||
if err == nil {
|
||||
err = closeErr
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = os.Rename(f.Name(), filepath.Join(s.dir, "bindings.json")); err != nil {
|
||||
s.uncertain = true
|
||||
return err
|
||||
}
|
||||
d, err := os.Open(s.dir)
|
||||
if err == nil {
|
||||
err = d.Sync()
|
||||
_ = d.Close()
|
||||
}
|
||||
if err != nil {
|
||||
s.uncertain = true
|
||||
return err
|
||||
}
|
||||
s.records = all
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package lifecycle
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestWorkspaceBindingRetirementReplayDoesNotRetireRepreparedTarget(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
s, e := OpenWorkspaceBindingStore(dir)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
b := WorkspaceBinding{VolumeID: "v", ServerID: "node", DataAddr: "127.0.0.1:10000", CtrlAddr: "127.0.0.1:10001"}
|
||||
if e = s.Register(b); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if e = s.Retire("v", "node", 1); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if list, bound, e := s.Get("v"); e != nil || !bound || !list[0].Retired {
|
||||
t.Fatal("retirement lost explicit marker", list, bound, e)
|
||||
}
|
||||
b.DataAddr = "127.0.0.1:10002"
|
||||
if e = s.Register(b); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if e = s.Retire("v", "node", 1); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
s, e = OpenWorkspaceBindingStore(dir)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
list, bound, e := s.Get("v")
|
||||
if e != nil || !bound || len(list) != 1 || list[0].Retired || list[0].DataAddr != b.DataAddr {
|
||||
t.Fatal("old retirement killed new binding", list, bound, e)
|
||||
}
|
||||
if e = s.Retire("v", "node", 2); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
list, _, e = s.Get("v")
|
||||
if e != nil || !list[0].Retired {
|
||||
t.Fatal(list, e)
|
||||
}
|
||||
}
|
||||
@@ -550,6 +550,7 @@ type WorkspaceStatus struct {
|
||||
Lease *WorkspaceLeaseFact `protobuf:"bytes,1,opt,name=lease,proto3" json:"lease,omitempty"`
|
||||
RevocationAck *WorkspaceRevocationAck `protobuf:"bytes,2,opt,name=revocation_ack,json=revocationAck,proto3" json:"revocation_ack,omitempty"`
|
||||
Moves []*WorkspaceGrant `protobuf:"bytes,3,rep,name=moves,proto3" json:"moves,omitempty"`
|
||||
Bindings []*WorkspaceBinding `protobuf:"bytes,4,rep,name=bindings,proto3" json:"bindings,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
@@ -605,6 +606,149 @@ func (x *WorkspaceStatus) GetMoves() []*WorkspaceGrant {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *WorkspaceStatus) GetBindings() []*WorkspaceBinding {
|
||||
if x != nil {
|
||||
return x.Bindings
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type WorkspaceBinding struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
VolumeId string `protobuf:"bytes,1,opt,name=volume_id,json=volumeId,proto3" json:"volume_id,omitempty"`
|
||||
ServerId string `protobuf:"bytes,2,opt,name=server_id,json=serverId,proto3" json:"server_id,omitempty"`
|
||||
DataAddr string `protobuf:"bytes,3,opt,name=data_addr,json=dataAddr,proto3" json:"data_addr,omitempty"`
|
||||
CtrlAddr string `protobuf:"bytes,4,opt,name=ctrl_addr,json=ctrlAddr,proto3" json:"ctrl_addr,omitempty"`
|
||||
Retired bool `protobuf:"varint,5,opt,name=retired,proto3" json:"retired,omitempty"` // server output only
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *WorkspaceBinding) Reset() {
|
||||
*x = WorkspaceBinding{}
|
||||
mi := &file_workspace_proto_msgTypes[8]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *WorkspaceBinding) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*WorkspaceBinding) ProtoMessage() {}
|
||||
|
||||
func (x *WorkspaceBinding) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_workspace_proto_msgTypes[8]
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use WorkspaceBinding.ProtoReflect.Descriptor instead.
|
||||
func (*WorkspaceBinding) Descriptor() ([]byte, []int) {
|
||||
return file_workspace_proto_rawDescGZIP(), []int{8}
|
||||
}
|
||||
|
||||
func (x *WorkspaceBinding) GetVolumeId() string {
|
||||
if x != nil {
|
||||
return x.VolumeId
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *WorkspaceBinding) GetServerId() string {
|
||||
if x != nil {
|
||||
return x.ServerId
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *WorkspaceBinding) GetDataAddr() string {
|
||||
if x != nil {
|
||||
return x.DataAddr
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *WorkspaceBinding) GetCtrlAddr() string {
|
||||
if x != nil {
|
||||
return x.CtrlAddr
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *WorkspaceBinding) GetRetired() bool {
|
||||
if x != nil {
|
||||
return x.Retired
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
type WorkspacePlacement struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
VolumeId string `protobuf:"bytes,1,opt,name=volume_id,json=volumeId,proto3" json:"volume_id,omitempty"`
|
||||
ServerId string `protobuf:"bytes,2,opt,name=server_id,json=serverId,proto3" json:"server_id,omitempty"`
|
||||
ReplicaId string `protobuf:"bytes,3,opt,name=replica_id,json=replicaId,proto3" json:"replica_id,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *WorkspacePlacement) Reset() {
|
||||
*x = WorkspacePlacement{}
|
||||
mi := &file_workspace_proto_msgTypes[9]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *WorkspacePlacement) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*WorkspacePlacement) ProtoMessage() {}
|
||||
|
||||
func (x *WorkspacePlacement) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_workspace_proto_msgTypes[9]
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use WorkspacePlacement.ProtoReflect.Descriptor instead.
|
||||
func (*WorkspacePlacement) Descriptor() ([]byte, []int) {
|
||||
return file_workspace_proto_rawDescGZIP(), []int{9}
|
||||
}
|
||||
|
||||
func (x *WorkspacePlacement) GetVolumeId() string {
|
||||
if x != nil {
|
||||
return x.VolumeId
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *WorkspacePlacement) GetServerId() string {
|
||||
if x != nil {
|
||||
return x.ServerId
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *WorkspacePlacement) GetReplicaId() string {
|
||||
if x != nil {
|
||||
return x.ReplicaId
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
var File_workspace_proto protoreflect.FileDescriptor
|
||||
|
||||
const file_workspace_proto_rawDesc = "" +
|
||||
@@ -658,12 +802,26 @@ const file_workspace_proto_rawDesc = "" +
|
||||
"\x06issued\x18\n" +
|
||||
" \x01(\bR\x06issued\x12\x19\n" +
|
||||
"\bold_host\x18\v \x01(\tR\aoldHost\x12\x19\n" +
|
||||
"\bnew_host\x18\f \x01(\tR\anewHost\"\xeb\x01\n" +
|
||||
"\bnew_host\x18\f \x01(\tR\anewHost\"\xb2\x02\n" +
|
||||
"\x0fWorkspaceStatus\x12A\n" +
|
||||
"\x05lease\x18\x01 \x01(\v2+.seaweedfs.block.control.WorkspaceLeaseFactR\x05lease\x12V\n" +
|
||||
"\x0erevocation_ack\x18\x02 \x01(\v2/.seaweedfs.block.control.WorkspaceRevocationAckR\rrevocationAck\x12=\n" +
|
||||
"\x05moves\x18\x03 \x03(\v2'.seaweedfs.block.control.WorkspaceGrantR\x05moves2\xa7\x04\n" +
|
||||
"\x10WorkspaceService\x12n\n" +
|
||||
"\x05moves\x18\x03 \x03(\v2'.seaweedfs.block.control.WorkspaceGrantR\x05moves\x12E\n" +
|
||||
"\bbindings\x18\x04 \x03(\v2).seaweedfs.block.control.WorkspaceBindingR\bbindings\"\xa0\x01\n" +
|
||||
"\x10WorkspaceBinding\x12\x1b\n" +
|
||||
"\tvolume_id\x18\x01 \x01(\tR\bvolumeId\x12\x1b\n" +
|
||||
"\tserver_id\x18\x02 \x01(\tR\bserverId\x12\x1b\n" +
|
||||
"\tdata_addr\x18\x03 \x01(\tR\bdataAddr\x12\x1b\n" +
|
||||
"\tctrl_addr\x18\x04 \x01(\tR\bctrlAddr\x12\x18\n" +
|
||||
"\aretired\x18\x05 \x01(\bR\aretired\"m\n" +
|
||||
"\x12WorkspacePlacement\x12\x1b\n" +
|
||||
"\tvolume_id\x18\x01 \x01(\tR\bvolumeId\x12\x1b\n" +
|
||||
"\tserver_id\x18\x02 \x01(\tR\bserverId\x12\x1d\n" +
|
||||
"\n" +
|
||||
"replica_id\x18\x03 \x01(\tR\treplicaId2\x81\x06\n" +
|
||||
"\x10WorkspaceService\x12p\n" +
|
||||
"\x18RegisterWorkspaceBinding\x12).seaweedfs.block.control.WorkspaceBinding\x1a).seaweedfs.block.control.WorkspaceBinding\x12f\n" +
|
||||
"\x0ePlaceWorkspace\x12+.seaweedfs.block.control.WorkspacePlacement\x1a'.seaweedfs.block.control.WorkspaceEmpty\x12n\n" +
|
||||
"\x13RenewWorkspaceLease\x12*.seaweedfs.block.control.WorkspaceIdentity\x1a+.seaweedfs.block.control.WorkspaceLeaseFact\x12j\n" +
|
||||
"\x0fRevokeWorkspace\x12*.seaweedfs.block.control.WorkspaceIdentity\x1a+.seaweedfs.block.control.WorkspaceLeaseFact\x12o\n" +
|
||||
"\x13AckWorkspaceRevoked\x12/.seaweedfs.block.control.WorkspaceRevocationAck\x1a'.seaweedfs.block.control.WorkspaceEmpty\x12`\n" +
|
||||
@@ -682,7 +840,7 @@ func file_workspace_proto_rawDescGZIP() []byte {
|
||||
return file_workspace_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_workspace_proto_msgTypes = make([]protoimpl.MessageInfo, 8)
|
||||
var file_workspace_proto_msgTypes = make([]protoimpl.MessageInfo, 10)
|
||||
var file_workspace_proto_goTypes = []any{
|
||||
(*WorkspaceIdentity)(nil), // 0: seaweedfs.block.control.WorkspaceIdentity
|
||||
(*WorkspaceVolume)(nil), // 1: seaweedfs.block.control.WorkspaceVolume
|
||||
@@ -692,27 +850,34 @@ var file_workspace_proto_goTypes = []any{
|
||||
(*WorkspaceMove)(nil), // 5: seaweedfs.block.control.WorkspaceMove
|
||||
(*WorkspaceGrant)(nil), // 6: seaweedfs.block.control.WorkspaceGrant
|
||||
(*WorkspaceStatus)(nil), // 7: seaweedfs.block.control.WorkspaceStatus
|
||||
(*WorkspaceBinding)(nil), // 8: seaweedfs.block.control.WorkspaceBinding
|
||||
(*WorkspacePlacement)(nil), // 9: seaweedfs.block.control.WorkspacePlacement
|
||||
}
|
||||
var file_workspace_proto_depIdxs = []int32{
|
||||
0, // 0: seaweedfs.block.control.WorkspaceRevocationAck.identity:type_name -> seaweedfs.block.control.WorkspaceIdentity
|
||||
3, // 1: seaweedfs.block.control.WorkspaceStatus.lease:type_name -> seaweedfs.block.control.WorkspaceLeaseFact
|
||||
4, // 2: seaweedfs.block.control.WorkspaceStatus.revocation_ack:type_name -> seaweedfs.block.control.WorkspaceRevocationAck
|
||||
6, // 3: seaweedfs.block.control.WorkspaceStatus.moves:type_name -> seaweedfs.block.control.WorkspaceGrant
|
||||
0, // 4: seaweedfs.block.control.WorkspaceService.RenewWorkspaceLease:input_type -> seaweedfs.block.control.WorkspaceIdentity
|
||||
0, // 5: seaweedfs.block.control.WorkspaceService.RevokeWorkspace:input_type -> seaweedfs.block.control.WorkspaceIdentity
|
||||
4, // 6: seaweedfs.block.control.WorkspaceService.AckWorkspaceRevoked:input_type -> seaweedfs.block.control.WorkspaceRevocationAck
|
||||
5, // 7: seaweedfs.block.control.WorkspaceService.MoveWorkspace:input_type -> seaweedfs.block.control.WorkspaceMove
|
||||
1, // 8: seaweedfs.block.control.WorkspaceService.QueryWorkspace:input_type -> seaweedfs.block.control.WorkspaceVolume
|
||||
3, // 9: seaweedfs.block.control.WorkspaceService.RenewWorkspaceLease:output_type -> seaweedfs.block.control.WorkspaceLeaseFact
|
||||
3, // 10: seaweedfs.block.control.WorkspaceService.RevokeWorkspace:output_type -> seaweedfs.block.control.WorkspaceLeaseFact
|
||||
2, // 11: seaweedfs.block.control.WorkspaceService.AckWorkspaceRevoked:output_type -> seaweedfs.block.control.WorkspaceEmpty
|
||||
6, // 12: seaweedfs.block.control.WorkspaceService.MoveWorkspace:output_type -> seaweedfs.block.control.WorkspaceGrant
|
||||
7, // 13: seaweedfs.block.control.WorkspaceService.QueryWorkspace:output_type -> seaweedfs.block.control.WorkspaceStatus
|
||||
9, // [9:14] is the sub-list for method output_type
|
||||
4, // [4:9] is the sub-list for method input_type
|
||||
4, // [4:4] is the sub-list for extension type_name
|
||||
4, // [4:4] is the sub-list for extension extendee
|
||||
0, // [0:4] is the sub-list for field type_name
|
||||
0, // 0: seaweedfs.block.control.WorkspaceRevocationAck.identity:type_name -> seaweedfs.block.control.WorkspaceIdentity
|
||||
3, // 1: seaweedfs.block.control.WorkspaceStatus.lease:type_name -> seaweedfs.block.control.WorkspaceLeaseFact
|
||||
4, // 2: seaweedfs.block.control.WorkspaceStatus.revocation_ack:type_name -> seaweedfs.block.control.WorkspaceRevocationAck
|
||||
6, // 3: seaweedfs.block.control.WorkspaceStatus.moves:type_name -> seaweedfs.block.control.WorkspaceGrant
|
||||
8, // 4: seaweedfs.block.control.WorkspaceStatus.bindings:type_name -> seaweedfs.block.control.WorkspaceBinding
|
||||
8, // 5: seaweedfs.block.control.WorkspaceService.RegisterWorkspaceBinding:input_type -> seaweedfs.block.control.WorkspaceBinding
|
||||
9, // 6: seaweedfs.block.control.WorkspaceService.PlaceWorkspace:input_type -> seaweedfs.block.control.WorkspacePlacement
|
||||
0, // 7: seaweedfs.block.control.WorkspaceService.RenewWorkspaceLease:input_type -> seaweedfs.block.control.WorkspaceIdentity
|
||||
0, // 8: seaweedfs.block.control.WorkspaceService.RevokeWorkspace:input_type -> seaweedfs.block.control.WorkspaceIdentity
|
||||
4, // 9: seaweedfs.block.control.WorkspaceService.AckWorkspaceRevoked:input_type -> seaweedfs.block.control.WorkspaceRevocationAck
|
||||
5, // 10: seaweedfs.block.control.WorkspaceService.MoveWorkspace:input_type -> seaweedfs.block.control.WorkspaceMove
|
||||
1, // 11: seaweedfs.block.control.WorkspaceService.QueryWorkspace:input_type -> seaweedfs.block.control.WorkspaceVolume
|
||||
8, // 12: seaweedfs.block.control.WorkspaceService.RegisterWorkspaceBinding:output_type -> seaweedfs.block.control.WorkspaceBinding
|
||||
2, // 13: seaweedfs.block.control.WorkspaceService.PlaceWorkspace:output_type -> seaweedfs.block.control.WorkspaceEmpty
|
||||
3, // 14: seaweedfs.block.control.WorkspaceService.RenewWorkspaceLease:output_type -> seaweedfs.block.control.WorkspaceLeaseFact
|
||||
3, // 15: seaweedfs.block.control.WorkspaceService.RevokeWorkspace:output_type -> seaweedfs.block.control.WorkspaceLeaseFact
|
||||
2, // 16: seaweedfs.block.control.WorkspaceService.AckWorkspaceRevoked:output_type -> seaweedfs.block.control.WorkspaceEmpty
|
||||
6, // 17: seaweedfs.block.control.WorkspaceService.MoveWorkspace:output_type -> seaweedfs.block.control.WorkspaceGrant
|
||||
7, // 18: seaweedfs.block.control.WorkspaceService.QueryWorkspace:output_type -> seaweedfs.block.control.WorkspaceStatus
|
||||
12, // [12:19] is the sub-list for method output_type
|
||||
5, // [5:12] is the sub-list for method input_type
|
||||
5, // [5:5] is the sub-list for extension type_name
|
||||
5, // [5:5] is the sub-list for extension extendee
|
||||
0, // [0:5] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_workspace_proto_init() }
|
||||
@@ -726,7 +891,7 @@ func file_workspace_proto_init() {
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: unsafe.Slice(unsafe.StringData(file_workspace_proto_rawDesc), len(file_workspace_proto_rawDesc)),
|
||||
NumEnums: 0,
|
||||
NumMessages: 8,
|
||||
NumMessages: 10,
|
||||
NumExtensions: 0,
|
||||
NumServices: 1,
|
||||
},
|
||||
|
||||
@@ -19,11 +19,13 @@ import (
|
||||
const _ = grpc.SupportPackageIsVersion9
|
||||
|
||||
const (
|
||||
WorkspaceService_RenewWorkspaceLease_FullMethodName = "/seaweedfs.block.control.WorkspaceService/RenewWorkspaceLease"
|
||||
WorkspaceService_RevokeWorkspace_FullMethodName = "/seaweedfs.block.control.WorkspaceService/RevokeWorkspace"
|
||||
WorkspaceService_AckWorkspaceRevoked_FullMethodName = "/seaweedfs.block.control.WorkspaceService/AckWorkspaceRevoked"
|
||||
WorkspaceService_MoveWorkspace_FullMethodName = "/seaweedfs.block.control.WorkspaceService/MoveWorkspace"
|
||||
WorkspaceService_QueryWorkspace_FullMethodName = "/seaweedfs.block.control.WorkspaceService/QueryWorkspace"
|
||||
WorkspaceService_RegisterWorkspaceBinding_FullMethodName = "/seaweedfs.block.control.WorkspaceService/RegisterWorkspaceBinding"
|
||||
WorkspaceService_PlaceWorkspace_FullMethodName = "/seaweedfs.block.control.WorkspaceService/PlaceWorkspace"
|
||||
WorkspaceService_RenewWorkspaceLease_FullMethodName = "/seaweedfs.block.control.WorkspaceService/RenewWorkspaceLease"
|
||||
WorkspaceService_RevokeWorkspace_FullMethodName = "/seaweedfs.block.control.WorkspaceService/RevokeWorkspace"
|
||||
WorkspaceService_AckWorkspaceRevoked_FullMethodName = "/seaweedfs.block.control.WorkspaceService/AckWorkspaceRevoked"
|
||||
WorkspaceService_MoveWorkspace_FullMethodName = "/seaweedfs.block.control.WorkspaceService/MoveWorkspace"
|
||||
WorkspaceService_QueryWorkspace_FullMethodName = "/seaweedfs.block.control.WorkspaceService/QueryWorkspace"
|
||||
)
|
||||
|
||||
// WorkspaceServiceClient is the client API for WorkspaceService service.
|
||||
@@ -32,6 +34,10 @@ const (
|
||||
//
|
||||
// Opt-in RF=1 workspace authority protocol. Epochs are minted only by Publisher.
|
||||
type WorkspaceServiceClient interface {
|
||||
// Register a caller-allocated per-volume pair before placement or move.
|
||||
RegisterWorkspaceBinding(ctx context.Context, in *WorkspaceBinding, opts ...grpc.CallOption) (*WorkspaceBinding, error)
|
||||
// Desired chosen-node intent only; this never directly mints authority.
|
||||
PlaceWorkspace(ctx context.Context, in *WorkspacePlacement, opts ...grpc.CallOption) (*WorkspaceEmpty, error)
|
||||
RenewWorkspaceLease(ctx context.Context, in *WorkspaceIdentity, opts ...grpc.CallOption) (*WorkspaceLeaseFact, error)
|
||||
RevokeWorkspace(ctx context.Context, in *WorkspaceIdentity, opts ...grpc.CallOption) (*WorkspaceLeaseFact, error)
|
||||
AckWorkspaceRevoked(ctx context.Context, in *WorkspaceRevocationAck, opts ...grpc.CallOption) (*WorkspaceEmpty, error)
|
||||
@@ -47,6 +53,26 @@ func NewWorkspaceServiceClient(cc grpc.ClientConnInterface) WorkspaceServiceClie
|
||||
return &workspaceServiceClient{cc}
|
||||
}
|
||||
|
||||
func (c *workspaceServiceClient) RegisterWorkspaceBinding(ctx context.Context, in *WorkspaceBinding, opts ...grpc.CallOption) (*WorkspaceBinding, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(WorkspaceBinding)
|
||||
err := c.cc.Invoke(ctx, WorkspaceService_RegisterWorkspaceBinding_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *workspaceServiceClient) PlaceWorkspace(ctx context.Context, in *WorkspacePlacement, opts ...grpc.CallOption) (*WorkspaceEmpty, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(WorkspaceEmpty)
|
||||
err := c.cc.Invoke(ctx, WorkspaceService_PlaceWorkspace_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *workspaceServiceClient) RenewWorkspaceLease(ctx context.Context, in *WorkspaceIdentity, opts ...grpc.CallOption) (*WorkspaceLeaseFact, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(WorkspaceLeaseFact)
|
||||
@@ -103,6 +129,10 @@ func (c *workspaceServiceClient) QueryWorkspace(ctx context.Context, in *Workspa
|
||||
//
|
||||
// Opt-in RF=1 workspace authority protocol. Epochs are minted only by Publisher.
|
||||
type WorkspaceServiceServer interface {
|
||||
// Register a caller-allocated per-volume pair before placement or move.
|
||||
RegisterWorkspaceBinding(context.Context, *WorkspaceBinding) (*WorkspaceBinding, error)
|
||||
// Desired chosen-node intent only; this never directly mints authority.
|
||||
PlaceWorkspace(context.Context, *WorkspacePlacement) (*WorkspaceEmpty, error)
|
||||
RenewWorkspaceLease(context.Context, *WorkspaceIdentity) (*WorkspaceLeaseFact, error)
|
||||
RevokeWorkspace(context.Context, *WorkspaceIdentity) (*WorkspaceLeaseFact, error)
|
||||
AckWorkspaceRevoked(context.Context, *WorkspaceRevocationAck) (*WorkspaceEmpty, error)
|
||||
@@ -118,6 +148,12 @@ type WorkspaceServiceServer interface {
|
||||
// pointer dereference when methods are called.
|
||||
type UnimplementedWorkspaceServiceServer struct{}
|
||||
|
||||
func (UnimplementedWorkspaceServiceServer) RegisterWorkspaceBinding(context.Context, *WorkspaceBinding) (*WorkspaceBinding, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method RegisterWorkspaceBinding not implemented")
|
||||
}
|
||||
func (UnimplementedWorkspaceServiceServer) PlaceWorkspace(context.Context, *WorkspacePlacement) (*WorkspaceEmpty, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method PlaceWorkspace not implemented")
|
||||
}
|
||||
func (UnimplementedWorkspaceServiceServer) RenewWorkspaceLease(context.Context, *WorkspaceIdentity) (*WorkspaceLeaseFact, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method RenewWorkspaceLease not implemented")
|
||||
}
|
||||
@@ -154,6 +190,42 @@ func RegisterWorkspaceServiceServer(s grpc.ServiceRegistrar, srv WorkspaceServic
|
||||
s.RegisterService(&WorkspaceService_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _WorkspaceService_RegisterWorkspaceBinding_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(WorkspaceBinding)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(WorkspaceServiceServer).RegisterWorkspaceBinding(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: WorkspaceService_RegisterWorkspaceBinding_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(WorkspaceServiceServer).RegisterWorkspaceBinding(ctx, req.(*WorkspaceBinding))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _WorkspaceService_PlaceWorkspace_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(WorkspacePlacement)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(WorkspaceServiceServer).PlaceWorkspace(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: WorkspaceService_PlaceWorkspace_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(WorkspaceServiceServer).PlaceWorkspace(ctx, req.(*WorkspacePlacement))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _WorkspaceService_RenewWorkspaceLease_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(WorkspaceIdentity)
|
||||
if err := dec(in); err != nil {
|
||||
@@ -251,6 +323,14 @@ var WorkspaceService_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "seaweedfs.block.control.WorkspaceService",
|
||||
HandlerType: (*WorkspaceServiceServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "RegisterWorkspaceBinding",
|
||||
Handler: _WorkspaceService_RegisterWorkspaceBinding_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "PlaceWorkspace",
|
||||
Handler: _WorkspaceService_PlaceWorkspace_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "RenewWorkspaceLease",
|
||||
Handler: _WorkspaceService_RenewWorkspaceLease_Handler,
|
||||
|
||||
@@ -4,6 +4,10 @@ option go_package = "github.com/seaweedfs/seaweed-block/core/rpc/control;control
|
||||
|
||||
// Opt-in RF=1 workspace authority protocol. Epochs are minted only by Publisher.
|
||||
service WorkspaceService {
|
||||
// Register a caller-allocated per-volume pair before placement or move.
|
||||
rpc RegisterWorkspaceBinding(WorkspaceBinding) returns (WorkspaceBinding);
|
||||
// Desired chosen-node intent only; this never directly mints authority.
|
||||
rpc PlaceWorkspace(WorkspacePlacement) returns (WorkspaceEmpty);
|
||||
rpc RenewWorkspaceLease(WorkspaceIdentity) returns (WorkspaceLeaseFact);
|
||||
rpc RevokeWorkspace(WorkspaceIdentity) returns (WorkspaceLeaseFact);
|
||||
rpc AckWorkspaceRevoked(WorkspaceRevocationAck) returns (WorkspaceEmpty);
|
||||
@@ -34,4 +38,13 @@ message WorkspaceGrant {
|
||||
message WorkspaceStatus {
|
||||
WorkspaceLeaseFact lease = 1; WorkspaceRevocationAck revocation_ack = 2;
|
||||
repeated WorkspaceGrant moves = 3;
|
||||
repeated WorkspaceBinding bindings = 4;
|
||||
}
|
||||
message WorkspaceBinding {
|
||||
string volume_id = 1; string server_id = 2;
|
||||
string data_addr = 3; string ctrl_addr = 4;
|
||||
bool retired = 5; // server output only
|
||||
}
|
||||
message WorkspacePlacement {
|
||||
string volume_id = 1; string server_id = 2; string replica_id = 3;
|
||||
}
|
||||
Reference in new issue
Block a user