mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 18:47:20 +01:00
feat(sw-block): volume stop releases a walstore-chunk volume's lease; a stopped volume reads stopped (#997)
Merge note (pull_request_target spec-trace workflow has a startup_failure on every branch since 2026-12-02 22:45Z, so its checks run locally): - Test run 47238226538 succeeded (go test (linux), process-level tests (real binaries)) on head b832a4f3 against main e288c091, the current main head. - spec-trace-check.sh and public-text-check.sh, run with the main branch's scripts against this head and body: both exit 0. - Code review ACCEPT on the stop side (ce6df853) and on 16bee1a9 (start side and version handling): 'volume stop' on a host that holds the volume's binding revokes its own epoch and waits one lease for the recorded acknowledgement before reporting released, keeps the binding, and disables the unit; 'volume start' then makes the same-host clean move to the next epoch, refuses with a typed error when the owner is unknown or unreadable (no force advice unless this host owns the line), starts a never-published volume on the existing path, and uses the previous behaviour against a pre-v1.1.1 master. - Model check PASS on 16bee1a9 (stop and restart model, review 6180486751). - Delta read ACCEPT on 30566308 (test-only restore fixture now answers like a real master; START queries the restore master; no production path change). b832a4f3 = main merge, trace tsv union only.
This commit is contained in:
1 parent
1bc905e7b8
commit
8831d1fe2c
33 files changed
+1899
-100
No files matched your search
+5
@@ -11,8 +11,12 @@ cmd/sw-block/volume_backup.go RestoreCommand.Abort
|
||||
cmd/sw-block/volume_backup.go RestoreCommand.AbortVerify
|
||||
cmd/sw-block/volume_backup.go RestoreCommand.Run
|
||||
cmd/sw-block/volume_backup.go RestoreCommand.Start
|
||||
cmd/sw-block/volume_start_release.go StopAndRestart.IssueClean
|
||||
cmd/sw-block/volume_start_release.go StopAndRestart.ReadClean
|
||||
cmd/sw-block/volume_start_release.go StopAndRestart.SameEpochReopen
|
||||
cmd/sw-block/volume_verbs.go CutTime.CliGiveUp
|
||||
cmd/sw-block/volume_verbs.go CutTime.Poll
|
||||
cmd/sw-block/workspace_show.go MoveAdmission.ReadForMove
|
||||
core/authority/authority.go DeleteRetire.Retire
|
||||
core/authority/authority_store_file.go DeleteRetire.Retire
|
||||
core/authority/workspace.go HolderInterface.ForcedMove
|
||||
@@ -204,6 +208,7 @@ core/host/master/services.go FormatGate.Report
|
||||
core/host/master/spec_retirement.go DeleteRetire.ReadOK
|
||||
core/host/master/store_attestation.go ReplicationPeer.Attest
|
||||
core/host/master/workspace_binding.go FormatGate.Grant
|
||||
core/host/master/workspace_binding.go MoveAdmission.Ack
|
||||
core/host/master/workspace_service.go FormatGate.Place
|
||||
core/host/master/workspace_service.go FormatGate.Renew
|
||||
core/host/master/workspace_service.go MoveAdmission.ReadForMove
|
||||
|
||||
|
@@ -0,0 +1,95 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
control "github.com/seaweedfs/seaweed-block/core/rpc/control"
|
||||
)
|
||||
|
||||
// Control: a v1.1.0 master's QueryWorkspace answer after a clean revoke+ACK.
|
||||
// The ACK identity carries no server id (the old master never set it) and
|
||||
// there is no current_holder. Same binding, lease and ACK epoch as a release.
|
||||
func oldMasterReleased() *control.WorkspaceStatus {
|
||||
return &control.WorkspaceStatus{
|
||||
Lease: &control.WorkspaceLeaseFact{ReplicaId: "r1", Epoch: 3, Revoking: true, ValidForNs: 0},
|
||||
RevocationAck: &control.WorkspaceRevocationAck{Identity: &control.WorkspaceIdentity{VolumeId: "v1", ReplicaId: "r1", Epoch: 3}, HeadGen: 9},
|
||||
Bindings: []*control.WorkspaceBinding{{VolumeId: "v1", ServerId: "s1", DataAddr: "127.0.0.1:9201", CtrlAddr: "127.0.0.1:9202"}},
|
||||
}
|
||||
}
|
||||
|
||||
func TestControl997OldMasterStopUsesLegacyWithoutRevoke(t *testing.T) {
|
||||
h := newFakeHost(t)
|
||||
env := h.env(t)
|
||||
old := releaseQuery
|
||||
releaseQuery = func(context.Context, string, string) (*control.WorkspaceStatus, error) {
|
||||
return oldMasterReleased(), nil
|
||||
}
|
||||
t.Cleanup(func() { releaseQuery = old })
|
||||
var out bytes.Buffer
|
||||
result := releaseLease(context.Background(), env, map[string]string{"SWB_MASTER_ADDR": "master", "SWB_VOLUME_ID": "v1", "SWB_REPLICA_ID": "r1", "SWB_SERVER_ID": "s1"}, true, &out)
|
||||
if !result.Legacy || result.Released || len(h.lease.revoked()) != 0 {
|
||||
t.Fatalf("old-master stop=%+v", result)
|
||||
}
|
||||
// A server-less old ACK still cannot assert the newer exact-identity fact.
|
||||
if r, _ := leaseVerdict(oldMasterReleased(), "v1", "r1", "s1", 3); r.Released {
|
||||
t.Fatal("weakened ACK identity check")
|
||||
}
|
||||
}
|
||||
|
||||
func TestControl997OldMasterStartRefusesTheReleasedVolume(t *testing.T) {
|
||||
old := releaseQuery
|
||||
releaseQuery = func(context.Context, string, string) (*control.WorkspaceStatus, error) {
|
||||
return oldMasterReleased(), nil
|
||||
}
|
||||
t.Cleanup(func() { releaseQuery = old })
|
||||
var out, errs bytes.Buffer
|
||||
v := volumeSpec{VolumeID: "v1", ReplicaID: "r1", ServerID: "s1", Master: "127.0.0.1:1", DataAddr: "127.0.0.1:9201", CtrlAddr: "127.0.0.1:9202"}
|
||||
code := prepareVolumeStart(context.Background(), v, &out, &errs)
|
||||
t.Logf("start against an old master: code=%d %s", code, errs.String())
|
||||
if code != 0 {
|
||||
t.Errorf("volume start of a cleanly stopped volume refuses against a v1.1.0 master")
|
||||
}
|
||||
}
|
||||
|
||||
func TestOwnerUnreadableDoesNotSelectLegacyStartOrStop(t *testing.T) {
|
||||
h := newFakeHost(t)
|
||||
env := h.env(t)
|
||||
stubResolve(t, "00112233445566778899aabbccddeeff", nil)
|
||||
old := releaseQuery
|
||||
reply := oldMasterReleased()
|
||||
reply.OwnerUnreadable = true
|
||||
releaseQuery = func(context.Context, string, string) (*control.WorkspaceStatus, error) { return reply, nil }
|
||||
t.Cleanup(func() { releaseQuery = old })
|
||||
code, _, errs := runStart(env, h.spec(true), startOpts{Wait: time.Second})
|
||||
if code != 2 || h.called("enable") != 0 || !strings.Contains(errs, "volume_start_owner_unknown") {
|
||||
t.Fatalf("unreadable start=%d %s", code, errs)
|
||||
}
|
||||
var out bytes.Buffer
|
||||
result := releaseLease(context.Background(), env, map[string]string{"SWB_MASTER_ADDR": "master", "SWB_VOLUME_ID": "v1", "SWB_REPLICA_ID": "r1", "SWB_SERVER_ID": "s1"}, true, &out)
|
||||
if result.Legacy || result.Released || !strings.Contains(result.Message, "owner unknown") || len(h.lease.revoked()) != 0 {
|
||||
t.Fatalf("unreadable stop=%+v", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOwnerUnreadableShowKeepsLeaseAndMoveFacts(t *testing.T) {
|
||||
newFakeHost(t)
|
||||
reply := oldMasterReleased()
|
||||
reply.OwnerUnreadable = true
|
||||
reply.Moves = []*control.WorkspaceGrant{{RequestId: "historical", VolumeId: "v1", OldEpoch: 2, NewEpoch: 3, OldReplicaId: "r1", NewReplicaId: "r1", Issued: true}}
|
||||
f := &fakeWorkspace{status: reply}
|
||||
addr, _ := startFakeWorkspace(t, f)
|
||||
var out, errs bytes.Buffer
|
||||
code := runWorkspaceShow([]string{"--master", addr, "--volume", "v1"}, &out, &errs)
|
||||
for _, want := range []string{"owner observation: unreadable", "replica: r1", "epoch: 3", "recorded ACK: r1@3", "move: request=historical", "binding: host=s1"} {
|
||||
if !strings.Contains(out.String(), want) {
|
||||
t.Fatalf("missing %q: code=%d %s %s", want, code, out.String(), errs.String())
|
||||
}
|
||||
}
|
||||
if code != 0 || f.n("MoveWorkspace") != 0 {
|
||||
t.Fatalf("show=%d %s", code, errs.String())
|
||||
}
|
||||
}
|
||||
@@ -179,20 +179,21 @@ type restoreMaster struct {
|
||||
control.UnimplementedLifecycleServiceServer
|
||||
control.UnimplementedWorkspaceServiceServer
|
||||
control.UnimplementedEvidenceServiceServer
|
||||
mu sync.Mutex
|
||||
vols map[string]*restoreRec
|
||||
ids map[string]layout.VolumeID // layout ids the master minted
|
||||
src chunkstore.VolumeRef // vol-a in the catalog, with snapshot s1
|
||||
cat *chunkstore.BCatalog
|
||||
creates int
|
||||
binds int
|
||||
places int
|
||||
reserves int
|
||||
bound map[string]*control.WorkspaceBinding
|
||||
placed map[string]string // volume -> replica
|
||||
published map[string]bool // the authority line exists (the holder started)
|
||||
failNext string // "create-lost", "create-half", "create-notready", "place-lost", "bind-refuse", "publish-race[-other|-reread-fails]"
|
||||
statusErr bool // the next QueryVolumeStatus fails (Unavailable)
|
||||
mu sync.Mutex
|
||||
vols map[string]*restoreRec
|
||||
ids map[string]layout.VolumeID // layout ids the master minted
|
||||
src chunkstore.VolumeRef // vol-a in the catalog, with snapshot s1
|
||||
cat *chunkstore.BCatalog
|
||||
creates int
|
||||
binds int
|
||||
places int
|
||||
reserves int
|
||||
bound map[string]*control.WorkspaceBinding
|
||||
placed map[string]string // volume -> replica
|
||||
placedHost map[string]string // committed placement host, independent of prepared bindings
|
||||
published map[string]bool // the authority line exists (the holder started)
|
||||
failNext string // "create-lost", "create-half", "create-notready", "place-lost", "bind-refuse", "publish-race[-other|-reread-fails]"
|
||||
statusErr bool // the next QueryVolumeStatus fails (Unavailable)
|
||||
}
|
||||
|
||||
type restoreRec struct {
|
||||
@@ -334,7 +335,7 @@ func (m *restoreMaster) PlaceWorkspace(_ context.Context, q *control.WorkspacePl
|
||||
}
|
||||
m.statusErr = m.failNext == "publish-race-reread-fails"
|
||||
m.failNext = ""
|
||||
m.placed[q.VolumeId], m.published[q.VolumeId] = rep, true
|
||||
m.placed[q.VolumeId], m.placedHost[q.VolumeId], m.published[q.VolumeId] = rep, q.ServerId, true
|
||||
}
|
||||
if m.published[q.VolumeId] { // RecordWorkspacePlacement once a line exists
|
||||
return nil, status.Error(codes.FailedPrecondition, "workspace placement: volume already assigned; use move")
|
||||
@@ -342,7 +343,7 @@ func (m *restoreMaster) PlaceWorkspace(_ context.Context, q *control.WorkspacePl
|
||||
if rep, ok := m.placed[q.VolumeId]; ok && rep != q.ReplicaId {
|
||||
return nil, status.Error(codes.FailedPrecondition, "placement differs from the recorded one")
|
||||
}
|
||||
m.placed[q.VolumeId] = q.ReplicaId
|
||||
m.placed[q.VolumeId], m.placedHost[q.VolumeId] = q.ReplicaId, q.ServerId
|
||||
if m.failNext == "place-lost" {
|
||||
m.failNext = ""
|
||||
return nil, status.Error(codes.Unavailable, "reply lost")
|
||||
@@ -353,9 +354,16 @@ func (m *restoreMaster) PlaceWorkspace(_ context.Context, q *control.WorkspacePl
|
||||
func (m *restoreMaster) QueryWorkspace(_ context.Context, q *control.WorkspaceVolume) (*control.WorkspaceStatus, error) {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
// Bindings only: no holder ever renews here, so no lease is granted,
|
||||
// the interval a published line spends before its first lease.
|
||||
out := &control.WorkspaceStatus{}
|
||||
// No holder renews here, so no lease is granted. The modern owner
|
||||
// observation distinguishes pre-publication from the committed target.
|
||||
out := &control.WorkspaceStatus{NeverPublished: !m.published[q.GetVolumeId()]}
|
||||
if m.published[q.GetVolumeId()] {
|
||||
if host := m.placedHost[q.GetVolumeId()]; host != "" {
|
||||
out.CurrentHolder = &control.WorkspaceIdentity{VolumeId: q.GetVolumeId(), ServerId: host, ReplicaId: m.placed[q.GetVolumeId()], Epoch: 1}
|
||||
} else {
|
||||
out.OwnerUnreadable = true
|
||||
}
|
||||
}
|
||||
if b, ok := m.bound[q.GetVolumeId()]; ok {
|
||||
out.Bindings = append(out.Bindings, b)
|
||||
}
|
||||
@@ -393,7 +401,7 @@ func serveRestoreMaster(t *testing.T) (*restoreMaster, string) {
|
||||
dialChunkFiler = func(string) (chunkstore.Filer, func() error, error) { return store, func() error { return nil }, nil }
|
||||
t.Cleanup(func() { dialChunkFiler = prev })
|
||||
m := &restoreMaster{vols: map[string]*restoreRec{}, ids: map[string]layout.VolumeID{}, cat: cat, src: cliVolume(t, store, "vol-a", "s1"),
|
||||
bound: map[string]*control.WorkspaceBinding{}, placed: map[string]string{}, published: map[string]bool{}}
|
||||
bound: map[string]*control.WorkspaceBinding{}, placed: map[string]string{}, placedHost: map[string]string{}, published: map[string]bool{}}
|
||||
lis, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -501,6 +509,11 @@ func restoreSetup(t *testing.T) (*fakeHost, verbEnv, *restoreMaster, *[]string)
|
||||
env := h.env(t)
|
||||
base := env.Systemctl
|
||||
m, master := serveRestoreMaster(t)
|
||||
// Restore owns a separate RPC master; the source lease fixture is r3,
|
||||
// while the restore target is r9. Start must query the target master.
|
||||
oldQuery := releaseQuery
|
||||
releaseQuery = workspaceQuery
|
||||
t.Cleanup(func() { releaseQuery = oldQuery })
|
||||
// The holder starting publishes the volume's authority line; its stop
|
||||
// ends it (the test stands the lease's expiry in for the real wait).
|
||||
line := func(on bool) {
|
||||
@@ -655,8 +668,11 @@ func TestVolumeBackupRefusals(t *testing.T) {
|
||||
// all done (no second target, the same request).
|
||||
func TestVolumeRestoreCreatesPlacesAndStarts(t *testing.T) {
|
||||
h, env, m, _ := restoreSetup(t)
|
||||
h.lease.set(func(source *fakeLeaseMaster) {
|
||||
source.queryErr = errors.New("source lease fixture must not answer for the restore target")
|
||||
})
|
||||
code, out, errs := runRestore(env, restoreArgs(h)...)
|
||||
if code != 0 || !strings.Contains(out, "vol-r holds vol-a's snapshot s1") || !strings.Contains(out, "nvme connect") {
|
||||
if code != 0 || !strings.Contains(out, "vol-r holds vol-a's snapshot s1") || !strings.Contains(out, "nvme connect") || !strings.Contains(out, "first start: no published authority line") {
|
||||
t.Fatalf("restore: %d\n%s\n%s", code, out, errs)
|
||||
}
|
||||
r := m.vols["vol-r"]
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/authority"
|
||||
"github.com/seaweedfs/seaweed-block/core/host/master"
|
||||
control "github.com/seaweedfs/seaweed-block/core/rpc/control"
|
||||
"github.com/seaweedfs/seaweed-block/core/rpc/wsclient"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
)
|
||||
|
||||
// Missing placement must withhold automatic start/release without hiding the
|
||||
// epoch facts a repair request needs. Force admission itself is unchanged.
|
||||
func TestVolumeUnreadableOwnerKeepsRepairQueryAndShow(t *testing.T) {
|
||||
mh, stop := startDeleteMaster(t, master.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", Detached: true, RemoteLSN: 42}, nil
|
||||
}})
|
||||
defer stop()
|
||||
seedForcedVolumeLease(t, mh, true)
|
||||
if err := mh.Lifecycle().Placements.DeletePlacement("vol-f"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
conn, err := grpc.NewClient(mh.Addr(), grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer conn.Close()
|
||||
rpc := control.NewWorkspaceServiceClient(conn)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
reply, err := rpc.QueryWorkspace(ctx, &control.WorkspaceVolume{VolumeId: "vol-f"})
|
||||
if err != nil || !reply.GetOwnerUnreadable() || reply.GetLease().GetEpoch() != 1 || len(reply.GetBindings()) != 2 {
|
||||
t.Fatalf("full unreadable status=%v %v", reply, err)
|
||||
}
|
||||
h := newFakeHost(t)
|
||||
env := h.env(t)
|
||||
volumeReleaseSetup = 10 * time.Second
|
||||
stubResolve(t, "00112233445566778899aabbccddeeff", nil)
|
||||
oldQ := releaseQuery
|
||||
releaseQuery = func(ctx context.Context, _, v string) (*control.WorkspaceStatus, error) {
|
||||
return rpc.QueryWorkspace(ctx, &control.WorkspaceVolume{VolumeId: v})
|
||||
}
|
||||
t.Cleanup(func() { releaseQuery = oldQ })
|
||||
v := h.spec(true)
|
||||
v.Master, v.VolumeID, v.ServerID, v.ReplicaID = mh.Addr(), "vol-f", "node-a", "r1"
|
||||
if code, _, errs := runStart(env, v, startOpts{Wait: time.Second}); code != 2 || h.called("enable") != 0 || !strings.Contains(errs, "volume_start_owner_unknown") {
|
||||
t.Fatalf("start=%d %s", code, errs)
|
||||
}
|
||||
var out, errs bytes.Buffer
|
||||
recorder := &startMoveRecorder{WorkspaceServiceClient: rpc}
|
||||
oldDial := workspaceDial
|
||||
workspaceDial = func(string) (*wsclient.Client, error) { return wsclient.New(recorder), nil }
|
||||
t.Cleanup(func() { workspaceDial = oldDial })
|
||||
if code := runWorkspaceShow([]string{"--master", mh.Addr(), "--volume", "vol-f"}, &out, &errs); code != 0 || !strings.Contains(out.String(), "owner observation: unreadable") || !strings.Contains(out.String(), "replica: r1") || !strings.Contains(out.String(), "epoch: 1") || !strings.Contains(out.String(), "binding: host=node-b") {
|
||||
t.Fatalf("show=%d %s %s", code, out.String(), errs.String())
|
||||
}
|
||||
_, err = wsclient.New(recorder).ForceMove(ctx, wsclient.ForcedMove{VolumeID: "vol-f", RequestID: "unreadable-repair", TargetHost: "node-b", TargetDataAddr: "127.0.0.1:29200", TargetCtrlAddr: "127.0.0.1:29100", Confirm: "vol-f@1"})
|
||||
// The lease barrier or missing source can refuse. The assertion is only that
|
||||
// Query succeeded and the confirmed request reached the unchanged move RPC.
|
||||
if len(recorder.ids) != 1 || recorder.ids[0] != "unreadable-repair" {
|
||||
t.Fatalf("repair query blocked before move: ids=%v err=%v", recorder.ids, err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"time"
|
||||
|
||||
control "github.com/seaweedfs/seaweed-block/core/rpc/control"
|
||||
"github.com/seaweedfs/seaweed-block/core/rpc/link"
|
||||
)
|
||||
|
||||
// workspaceRevoke is the master's RevokeWorkspace.
|
||||
var workspaceRevoke = func(ctx context.Context, master string, id *control.WorkspaceIdentity) (*control.WorkspaceLeaseFact, error) {
|
||||
conn, err := link.DialMasterFromEnv(master)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer conn.Close()
|
||||
return control.NewWorkspaceServiceClient(conn).RevokeWorkspace(ctx, id)
|
||||
}
|
||||
|
||||
// releaseQuery reads the master's lease record for stop and start (the
|
||||
// master's QueryWorkspace; a test replaces it).
|
||||
var releaseQuery = func(ctx context.Context, master, volume string) (*control.WorkspaceStatus, error) {
|
||||
return workspaceQuery(ctx, master, volume)
|
||||
}
|
||||
|
||||
// volumeReleaseSetup bounds start's lease/move setup and the stop reads/revoke before the release
|
||||
// wait (a test shortens it).
|
||||
var volumeReleaseSetup = 10 * time.Second
|
||||
|
||||
// volumeReleaseSlack is added to one lease validity before a release that
|
||||
// has not been recorded is reported not released (a test shortens it).
|
||||
var volumeReleaseSlack = 5 * time.Second
|
||||
|
||||
// releaseResult is a stop's answer about the volume's lease. Released is
|
||||
// exactly what cluster status reads as stopped: the master recorded this
|
||||
// host's clean release (its revocation ACK) for the current line.
|
||||
type releaseResult struct {
|
||||
Legacy bool // no binding: use the v1.1.0 cut-and-unit-stop path, without revoke
|
||||
Released bool
|
||||
Final bool // no later run changes the answer (moved, or the lease ended without a release)
|
||||
Message string // the line printed
|
||||
}
|
||||
|
||||
// leaseVerdict reads the master's lease record for this host's volume.
|
||||
// holderEpoch is the running holder's own epoch (0 when it is not running).
|
||||
func leaseVerdict(ws *control.WorkspaceStatus, volume, replica, server string, holderEpoch uint64) (releaseResult, bool) {
|
||||
l, a := ws.GetLease(), ws.GetRevocationAck().GetIdentity()
|
||||
if l == nil {
|
||||
return releaseResult{Final: true, Message: "not released: the master holds no lease for " + volume + " (it moved or was deleted)"}, true
|
||||
}
|
||||
if a != nil && a.GetVolumeId() == volume && a.GetReplicaId() == replica && a.GetServerId() == server && a.GetEpoch() == l.GetEpoch() && l.GetReplicaId() == replica {
|
||||
return releaseResult{Released: true, Final: true, Message: fmt.Sprintf("released: the master recorded %s/%s@%d's clean release; cluster status reads %s stopped; volume start obtains epoch+1 through a same-host clean move before starting the unit", server, replica, l.GetEpoch(), volume)}, true
|
||||
}
|
||||
if l.GetReplicaId() != replica || (holderEpoch != 0 && l.GetEpoch() != holderEpoch) {
|
||||
return releaseResult{Final: true, Message: fmt.Sprintf("not released: %s moved (the master's line is %s@%d); nothing to release here", volume, l.GetReplicaId(), l.GetEpoch())}, true
|
||||
}
|
||||
if l.GetRevoking() && l.GetValidForNs() <= 0 {
|
||||
return releaseResult{Final: true, Message: fmt.Sprintf("not released: %s@%d's lease ended without a clean release; volume start checks the current owner and refuses this revoked epoch; force advice is given only for a proven local owner", replica, l.GetEpoch())}, true
|
||||
}
|
||||
return releaseResult{}, false
|
||||
}
|
||||
|
||||
// releaseLease ends a stop of a lease-holding (walstore-chunk) volume: it
|
||||
// revokes the running holder's own epoch and waits, bounded by one lease
|
||||
// validity, until the master records the holder's clean release (the holder
|
||||
// drains, detaches HEAD and acknowledges at its next renewal). Only the
|
||||
// master's recorded ACK counts as released; the holder's exit status does
|
||||
// not. With the unit stopped (holderRunning false) it never reads the
|
||||
// holder or revokes; it only reads the master's record, so a
|
||||
// rerun converges: released, moved, or ended without a release.
|
||||
func releaseLease(ctx context.Context, env verbEnv, e map[string]string, holderRunning bool, out io.Writer) releaseResult {
|
||||
master, volume, replica, server := e["SWB_MASTER_ADDR"], e["SWB_VOLUME_ID"], e["SWB_REPLICA_ID"], e["SWB_SERVER_ID"]
|
||||
// Every call is bounded: the reads before the wait by volumeReleaseSetup,
|
||||
// and the whole wait (each call in it) by one lease validity plus slack.
|
||||
// A stalled master ends the release unconfirmed; the unit still stops.
|
||||
setup, cancelSetup := context.WithTimeout(ctx, volumeReleaseSetup)
|
||||
defer cancelSetup()
|
||||
ws, err := releaseQuery(setup, master, volume)
|
||||
if err != nil {
|
||||
return releaseResult{Message: fmt.Sprintf("release not confirmed: the master's lease record could not be read (%v); whether it holds a release is unknown", err)}
|
||||
}
|
||||
if ws.GetOwnerUnreadable() {
|
||||
return releaseResult{Final: true, Message: "not released: owner unknown; the master cannot prove the current authority holder; no revoke was sent"}
|
||||
}
|
||||
if legacyWorkspaceMaster(ws) {
|
||||
return releaseResult{Legacy: true, Final: true, Message: "legacy stop: master predates owner observation; cut and unit stop, no revoke; volume start uses the existing authority path"}
|
||||
}
|
||||
if volumeHostBinding(ws, volume, server) == nil {
|
||||
return releaseResult{Legacy: true, Final: true, Message: "legacy stop: no binding for this host; cut and unit stop, no revoke; volume start uses the existing line"}
|
||||
}
|
||||
fmt.Fprintln(out, "clean-release mode: this host holds the volume binding; release retains it for the next same-host start")
|
||||
var holderEpoch uint64
|
||||
if holderRunning {
|
||||
var h struct {
|
||||
VolumeID, ReplicaID string
|
||||
Epoch uint64
|
||||
}
|
||||
err := getJSON(setup, env, "http://"+e["SWB_STATUS_ADDR"]+"/status?volume="+volume, &h)
|
||||
if err == nil && (h.VolumeID != volume || h.ReplicaID != replica || h.Epoch == 0) {
|
||||
err = fmt.Errorf("its status names %s/%s@%d", h.VolumeID, h.ReplicaID, h.Epoch)
|
||||
}
|
||||
if err != nil {
|
||||
return releaseResult{Message: fmt.Sprintf("release not confirmed: the running holder's status could not be read (%v), so its epoch to revoke is unknown; whether the lease is released is unknown", err)}
|
||||
}
|
||||
holderEpoch = h.Epoch
|
||||
}
|
||||
if r, done := leaseVerdict(ws, volume, replica, server, holderEpoch); done {
|
||||
return r
|
||||
}
|
||||
if !holderRunning {
|
||||
next := "the line was never revoked; volume start uses the existing line"
|
||||
if ws.GetLease().GetRevoking() {
|
||||
next = "the line is revoked without a recorded release; volume start checks ownership and refuses, with no force advice for an unknown or different owner"
|
||||
}
|
||||
return releaseResult{Final: true, Message: fmt.Sprintf("not released: the unit is stopped and its holder did not release %s's lease; %s", volume, next)}
|
||||
}
|
||||
fmt.Fprintln(out, fmt.Sprintf("+ release %s/%s@%d's lease (revoke, then wait for the holder's recorded release)", server, replica, holderEpoch))
|
||||
lease := ws.GetLease()
|
||||
if !lease.GetRevoking() {
|
||||
lease, err = workspaceRevoke(setup, master, &control.WorkspaceIdentity{VolumeId: volume, ReplicaId: replica, Epoch: holderEpoch, ServerId: server})
|
||||
if err != nil {
|
||||
return releaseResult{Message: fmt.Sprintf("release not confirmed: the revoke was refused or not answered (%v); a later volume stop reads the master's record", err)}
|
||||
}
|
||||
}
|
||||
bound := time.Duration(lease.GetValidForNs()) + volumeReleaseSlack
|
||||
wait, cancelWait := context.WithTimeout(ctx, bound)
|
||||
defer cancelWait()
|
||||
for {
|
||||
ws, err = releaseQuery(wait, master, volume)
|
||||
if err == nil {
|
||||
if r, done := leaseVerdict(ws, volume, replica, server, holderEpoch); done {
|
||||
return r
|
||||
}
|
||||
}
|
||||
if wait.Err() != nil {
|
||||
return releaseResult{Message: fmt.Sprintf("release not confirmed: the master showed no recorded release of %s@%d within one lease (%s); a later volume stop reads the record again", replica, holderEpoch, bound)}
|
||||
}
|
||||
select {
|
||||
case <-wait.Done():
|
||||
case <-time.After(env.Poll):
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A binding selects the CLI stop mode, never the current authority owner.
|
||||
func volumeHostBinding(ws *control.WorkspaceStatus, volume, server string) *control.WorkspaceBinding {
|
||||
for _, b := range ws.GetBindings() {
|
||||
if b.GetVolumeId() == volume && b.GetServerId() == server && !b.GetRetired() {
|
||||
return b
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Modern masters return a holder, positive first-launch proof, or an
|
||||
// unreadable-owner marker. Absence of all three identifies the old protocol.
|
||||
func legacyWorkspaceMaster(ws *control.WorkspaceStatus) bool {
|
||||
return ws != nil && ws.GetCurrentHolder() == nil && !ws.GetNeverPublished() && !ws.GetOwnerUnreadable()
|
||||
}
|
||||
@@ -0,0 +1,259 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/authority"
|
||||
"github.com/seaweedfs/seaweed-block/core/host/master"
|
||||
control "github.com/seaweedfs/seaweed-block/core/rpc/control"
|
||||
)
|
||||
|
||||
// fakeLeaseMaster is the master's lease record for vol-a (replica r3 of
|
||||
// server s7 at epoch 3) and a holder behind it. ack: "renewal" records the
|
||||
// holder's clean release when the revoke lands (its next renewal); "never"
|
||||
// leaves the revocation unanswered.
|
||||
type fakeLeaseMaster struct {
|
||||
mu sync.Mutex
|
||||
epoch uint64
|
||||
replica string
|
||||
revoking bool
|
||||
acked bool
|
||||
validNs int64
|
||||
ack string
|
||||
revokeErr error
|
||||
queryErr error
|
||||
revokes []string
|
||||
noBinding bool
|
||||
noLease bool
|
||||
// stall: "query" (every read), "revoke", or "poll" (reads after the
|
||||
// revoke): the call blocks until its context ends.
|
||||
stall string
|
||||
}
|
||||
|
||||
func newFakeLeaseMaster(t *testing.T) *fakeLeaseMaster {
|
||||
m := &fakeLeaseMaster{epoch: 3, replica: "r3", validNs: int64(time.Second), ack: "renewal"}
|
||||
oldQ, oldR, oldS, oldSetup := releaseQuery, workspaceRevoke, volumeReleaseSlack, volumeReleaseSetup
|
||||
releaseQuery = func(ctx context.Context, _ string, volume string) (*control.WorkspaceStatus, error) {
|
||||
m.mu.Lock()
|
||||
if m.stall == "query" || (m.stall == "poll" && len(m.revokes) > 0) {
|
||||
m.mu.Unlock()
|
||||
<-ctx.Done()
|
||||
return nil, ctx.Err()
|
||||
}
|
||||
defer m.mu.Unlock()
|
||||
if m.queryErr != nil {
|
||||
return nil, m.queryErr
|
||||
}
|
||||
if m.noLease {
|
||||
return &control.WorkspaceStatus{}, nil
|
||||
}
|
||||
ws := &control.WorkspaceStatus{Lease: &control.WorkspaceLeaseFact{VolumeId: volume, ReplicaId: m.replica, Epoch: m.epoch, ValidForNs: m.validNs, Revoking: m.revoking}}
|
||||
ws.CurrentHolder = &control.WorkspaceIdentity{VolumeId: volume, ServerId: "s7", ReplicaId: m.replica, Epoch: m.epoch}
|
||||
ws.Bindings = []*control.WorkspaceBinding{{VolumeId: volume, ServerId: "s7", DataAddr: "10.0.0.7:9201", CtrlAddr: "10.0.0.7:9202"}}
|
||||
if m.noBinding {
|
||||
ws.Bindings = nil
|
||||
}
|
||||
if m.acked {
|
||||
// The master's own projection of the ACK its holder recorded
|
||||
// (AckWorkspaceRevoked keeps Holder as "<server>/<replica>").
|
||||
ws.RevocationAck = master.RevocationAckFact(volume, &authority.WorkspaceRevokeAck{ReplicaID: m.replica, Epoch: m.epoch, Holder: "s7/" + m.replica})
|
||||
}
|
||||
return ws, nil
|
||||
}
|
||||
workspaceRevoke = func(ctx context.Context, _ string, id *control.WorkspaceIdentity) (*control.WorkspaceLeaseFact, error) {
|
||||
m.mu.Lock()
|
||||
if m.stall == "revoke" {
|
||||
m.mu.Unlock()
|
||||
<-ctx.Done()
|
||||
return nil, ctx.Err()
|
||||
}
|
||||
defer m.mu.Unlock()
|
||||
m.revokes = append(m.revokes, id.GetServerId()+"/"+id.GetReplicaId()+"@"+itoa(id.GetEpoch()))
|
||||
if m.revokeErr != nil {
|
||||
return nil, m.revokeErr
|
||||
}
|
||||
m.revoking = true
|
||||
if m.ack == "renewal" {
|
||||
m.acked = true
|
||||
}
|
||||
return &control.WorkspaceLeaseFact{VolumeId: id.GetVolumeId(), ReplicaId: m.replica, Epoch: m.epoch, ValidForNs: m.validNs, Revoking: true}, nil
|
||||
}
|
||||
volumeReleaseSlack, volumeReleaseSetup = 50*time.Millisecond, 200*time.Millisecond
|
||||
t.Cleanup(func() {
|
||||
releaseQuery, workspaceRevoke, volumeReleaseSlack, volumeReleaseSetup = oldQ, oldR, oldS, oldSetup
|
||||
})
|
||||
return m
|
||||
}
|
||||
|
||||
func itoa(n uint64) string { return strconv.FormatUint(n, 10) }
|
||||
|
||||
// saysReleased reports whether the stop printed the released line.
|
||||
func saysReleased(out string) bool {
|
||||
for _, l := range strings.Split(out, "\n") {
|
||||
if strings.HasPrefix(l, "released:") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (m *fakeLeaseMaster) set(f func(m *fakeLeaseMaster)) {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
f(m)
|
||||
}
|
||||
|
||||
func (m *fakeLeaseMaster) revoked() []string {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
return append([]string(nil), m.revokes...)
|
||||
}
|
||||
|
||||
// A stop of a walstore-chunk volume revokes the running holder's own epoch
|
||||
// after its cut and waits for the master's recorded release before the
|
||||
// unit stops; only then it says released (what cluster status reads as
|
||||
// stopped). A rerun reads the record and answers released again.
|
||||
func TestVolumeStopReleasesTheLeaseBeforeTheUnitStops(t *testing.T) {
|
||||
h, env := startedHost(t, true)
|
||||
code, out, errs := runStop(env, stopOpts{Volume: "vol-a", Timeout: time.Second})
|
||||
if code != 0 {
|
||||
t.Fatalf("stop: %d %s %s", code, out, errs)
|
||||
}
|
||||
if got := h.lease.revoked(); len(got) != 1 || got[0] != "s7/r3@3" {
|
||||
t.Fatalf("revokes %v, want the holder's own s7/r3@3", got)
|
||||
}
|
||||
for _, want := range []string{"+ cut", "+ release s7/r3@3", "released: the master recorded s7/r3@3's clean release", "+ systemctl stop"} {
|
||||
if !strings.Contains(out, want) {
|
||||
t.Fatalf("stop output lacks %q:\n%s", want, out)
|
||||
}
|
||||
}
|
||||
if !(strings.Index(out, "+ cut") < strings.Index(out, "+ release") && strings.Index(out, "released:") < strings.Index(out, "+ systemctl stop")) {
|
||||
t.Fatalf("not cut, release, then unit stop:\n%s", out)
|
||||
}
|
||||
code, out, _ = runStop(env, stopOpts{Volume: "vol-a", Timeout: time.Second})
|
||||
if code != 0 || !strings.Contains(out, "not running") || !saysReleased(out) || len(h.lease.revoked()) != 1 {
|
||||
t.Fatalf("rerun after the release: %d %s (revokes %v)", code, out, h.lease.revoked())
|
||||
}
|
||||
}
|
||||
|
||||
// Released is only the master's recorded ACK. A revocation the holder never
|
||||
// acknowledges (whatever the unit's exit status: 0, or 75 then 79 at its
|
||||
// restart) is "not released", the unit still stops, and the exit is not 0.
|
||||
// A rerun with the holder gone reads the record and gives a final answer,
|
||||
// never "run again".
|
||||
func TestVolumeStopNeverSaysReleasedWithoutTheRecordedAck(t *testing.T) {
|
||||
h, env := startedHost(t, true)
|
||||
h.lease.set(func(m *fakeLeaseMaster) { m.ack, m.validNs = "never", int64(50*time.Millisecond) })
|
||||
code, out, _ := runStop(env, stopOpts{Volume: "vol-a", Timeout: time.Second})
|
||||
if code == 0 || saysReleased(out) || !strings.Contains(out, "release not confirmed: the master showed no recorded release of r3@3 within one lease") {
|
||||
t.Fatalf("an unacknowledged revocation: %d\n%s", code, out)
|
||||
}
|
||||
if h.called("stop sw-blockvolume@vol-a.service") != 1 {
|
||||
t.Fatalf("the unit was not stopped: %v", h.calls)
|
||||
}
|
||||
// The holder is gone; the lease is still valid: it ends at its barrier.
|
||||
code, out, _ = runStop(env, stopOpts{Volume: "vol-a", Timeout: time.Second})
|
||||
if code == 0 || !strings.Contains(out, "not released: the unit is stopped and its holder did not release vol-a's lease") || strings.Contains(out, "run again") {
|
||||
t.Fatalf("rerun, lease valid: %d\n%s", code, out)
|
||||
}
|
||||
// The lease ran out while revoking: no release can be recorded at this epoch.
|
||||
h.lease.set(func(m *fakeLeaseMaster) { m.validNs = 0 })
|
||||
code, out, _ = runStop(env, stopOpts{Volume: "vol-a", Timeout: time.Second})
|
||||
if code == 0 || !strings.Contains(out, "lease ended without a clean release; volume start checks the current owner and refuses this revoked epoch") || strings.Contains(out, "run again") {
|
||||
t.Fatalf("rerun, lease ended: %d\n%s", code, out)
|
||||
}
|
||||
if got := h.lease.revoked(); len(got) != 1 {
|
||||
t.Fatalf("a rerun with the holder gone revoked again: %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
// A volume whose line moved (another epoch than the running holder's) is
|
||||
// not revoked; a refused revoke or an unreadable record is "not released";
|
||||
// a walstore volume (no lease) is stopped as before, without the master.
|
||||
func TestVolumeStopReleaseRefusalsAndWalstore(t *testing.T) {
|
||||
t.Run("moved", func(t *testing.T) {
|
||||
h, env := startedHost(t, true)
|
||||
h.lease.set(func(m *fakeLeaseMaster) { m.epoch = 4 })
|
||||
code, out, _ := runStop(env, stopOpts{Volume: "vol-a", Timeout: time.Second})
|
||||
if code == 0 || !strings.Contains(out, "not released: vol-a moved (the master's line is r3@4)") || len(h.lease.revoked()) != 0 {
|
||||
t.Fatalf("moved: %d %s (revokes %v)", code, out, h.lease.revoked())
|
||||
}
|
||||
})
|
||||
t.Run("revoke refused", func(t *testing.T) {
|
||||
h, env := startedHost(t, true)
|
||||
h.lease.set(func(m *fakeLeaseMaster) { m.revokeErr = errors.New("workspace revoke: no matching lease") })
|
||||
code, out, _ := runStop(env, stopOpts{Volume: "vol-a", Timeout: time.Second})
|
||||
if code == 0 || !strings.Contains(out, "release not confirmed: the revoke was refused or not answered") || saysReleased(out) {
|
||||
t.Fatalf("refused: %d %s", code, out)
|
||||
}
|
||||
})
|
||||
t.Run("record unreadable", func(t *testing.T) {
|
||||
h, env := startedHost(t, true)
|
||||
h.lease.set(func(m *fakeLeaseMaster) { m.queryErr = errors.New("connection refused") })
|
||||
code, out, _ := runStop(env, stopOpts{Volume: "vol-a", Timeout: time.Second})
|
||||
if code == 0 || !strings.Contains(out, "release not confirmed: the master's lease record could not be read") || len(h.lease.revoked()) != 0 {
|
||||
t.Fatalf("unreadable: %d %s", code, out)
|
||||
}
|
||||
})
|
||||
t.Run("walstore", func(t *testing.T) {
|
||||
h, env := startedHost(t, false)
|
||||
h.lease.set(func(m *fakeLeaseMaster) { m.queryErr = errors.New("must not be asked") })
|
||||
code, out, _ := runStop(env, stopOpts{Volume: "vol-a", Timeout: time.Second})
|
||||
if code != 0 || strings.Contains(out, "release") || len(h.lease.revoked()) != 0 {
|
||||
t.Fatalf("walstore: %d %s", code, out)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Every release call is bounded: a master that stalls the first read, the
|
||||
// revoke or a later read ends the release unconfirmed within its bound
|
||||
// (never released), and the unit still stops.
|
||||
func TestVolumeStopReleaseIsBoundedWhenTheMasterStalls(t *testing.T) {
|
||||
for stall, want := range map[string]string{
|
||||
"query": "release not confirmed: the master's lease record could not be read",
|
||||
"revoke": "release not confirmed: the revoke was refused or not answered",
|
||||
"poll": "release not confirmed: the master showed no recorded release of r3@3 within one lease",
|
||||
} {
|
||||
t.Run(stall, func(t *testing.T) {
|
||||
h, env := startedHost(t, true)
|
||||
h.lease.set(func(m *fakeLeaseMaster) { m.stall, m.ack, m.validNs = stall, "never", int64(100*time.Millisecond) })
|
||||
start := time.Now()
|
||||
code, out, _ := runStop(env, stopOpts{Volume: "vol-a", Timeout: time.Second})
|
||||
if took := time.Since(start); took > 5*time.Second {
|
||||
t.Fatalf("stall %s held the stop %s", stall, took)
|
||||
}
|
||||
if code == 0 || saysReleased(out) || !strings.Contains(out, want) || h.called("stop sw-blockvolume@vol-a.service") != 1 {
|
||||
t.Fatalf("stall %s: %d %s (calls %v)", stall, code, out, h.calls)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// A running unit whose holder's status cannot be read is not reported as an
|
||||
// absent holder: the release is unknown, and nothing is revoked.
|
||||
func TestVolumeStopUnreadableHolderStatusIsUnknown(t *testing.T) {
|
||||
h, env := startedHost(t, true)
|
||||
h.name = "vol-other" // /status names another volume
|
||||
code, out, _ := runStop(env, stopOpts{Volume: "vol-a", Timeout: time.Second, NoCut: true})
|
||||
if code == 0 || !strings.Contains(out, "release not confirmed: the running holder's status could not be read") || strings.Contains(out, "is not running") || len(h.lease.revoked()) != 0 {
|
||||
t.Fatalf("unreadable holder status: %d %s (revokes %v)", code, out, h.lease.revoked())
|
||||
}
|
||||
}
|
||||
|
||||
func TestVolumeStopWithoutBindingKeepsTheLegacyMode(t *testing.T) {
|
||||
h, env := startedHost(t, true)
|
||||
h.lease.set(func(m *fakeLeaseMaster) { m.noBinding = true })
|
||||
code, out, errs := runStop(env, stopOpts{Volume: "vol-a", Timeout: time.Second})
|
||||
if code != 0 || len(h.lease.revoked()) != 0 || saysReleased(out) || !strings.Contains(out, "legacy stop: no binding for this host; cut and unit stop, no revoke") || h.called("stop sw-blockvolume@vol-a.service") != 1 {
|
||||
t.Fatalf("stop=%d revokes=%v %s %s", code, h.lease.revoked(), out, errs)
|
||||
}
|
||||
if code, out, errs = runStop(env, stopOpts{Volume: "vol-a", Timeout: time.Second}); code != 0 || len(h.lease.revoked()) != 0 || !strings.Contains(out, "legacy stop") {
|
||||
t.Fatalf("rerun=%d %s %s", code, out, errs)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/seaweedfs/seaweed-block/core/auth"
|
||||
"github.com/seaweedfs/seaweed-block/core/auth/authtest"
|
||||
"github.com/seaweedfs/seaweed-block/core/authority"
|
||||
"github.com/seaweedfs/seaweed-block/core/host/master"
|
||||
"github.com/seaweedfs/seaweed-block/core/lifecycle"
|
||||
control "github.com/seaweedfs/seaweed-block/core/rpc/control"
|
||||
"github.com/seaweedfs/seaweed-block/core/rpc/link"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Real role checks: the operator cannot prepare bindings; its START must
|
||||
// retain the existing target across release; the second START must not read HEAD.
|
||||
func TestVolumeStartWithOperatorMutualTLS(t *testing.T) {
|
||||
ca := authtest.NewCA(t, "start-ca")
|
||||
dir := t.TempDir()
|
||||
caFile := ca.WriteCA(t, dir)
|
||||
cert, key := ca.Issue(t, "master", time.Now().Add(time.Hour)).WriteFiles(t, dir, "master")
|
||||
files := map[string]link.TLSFiles{}
|
||||
var lines []string
|
||||
for who, role := range map[string]string{"admin": "admin", "operator": "operator", "node-a": "node"} {
|
||||
leaf := ca.Issue(t, who, time.Now().Add(time.Hour))
|
||||
c, k := leaf.WriteFiles(t, dir, who)
|
||||
files[who] = link.TLSFiles{Cert: c, Key: k, CA: caFile}
|
||||
lines = append(lines, leaf.Fingerprint+" "+role+" "+who)
|
||||
}
|
||||
roles, e := auth.ParseRoleFile(strings.NewReader(strings.Join(lines, "\n")))
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
a := auth.NewAuthenticator(roles, nil)
|
||||
a.SetAudit(auth.NewAuditLog(io.Discard, nil))
|
||||
creds, e := link.ServerCredentials(link.TLSFiles{Cert: cert, Key: key, CA: caFile})
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
var reads atomic.Int32
|
||||
mh, stop := startDeleteMaster(t, master.Config{Listen: "127.0.0.1:0", AuthorityStoreDir: t.TempDir(), LifecycleStoreDir: t.TempDir(), WorkspaceRPC: true, Auth: a, ServerOptions: []grpc.ServerOption{creds}, WorkspaceHeadReader: func(context.Context, string) (authority.WorkspaceHead, error) {
|
||||
reads.Add(1)
|
||||
return authority.WorkspaceHead{Gen: 9, Epoch: 1, Holder: "node-a/r1", Detached: true, RemoteLSN: 42}, nil
|
||||
}})
|
||||
defer stop()
|
||||
dial := func(who string) *grpc.ClientConn {
|
||||
c, e := link.ClientCredentials(files[who], "")
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
conn, e := link.DialMaster(mh.Addr(), c)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
t.Cleanup(func() { conn.Close() })
|
||||
return conn
|
||||
}
|
||||
ac, nc, oc := dial("admin"), dial("node-a"), dial("operator")
|
||||
admin, node, operator := control.NewWorkspaceServiceClient(ac), control.NewWorkspaceServiceClient(nc), control.NewWorkspaceServiceClient(oc)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
if _, e = mh.Lifecycle().Nodes.RegisterNode(lifecycle.NodeRegistration{ServerID: "node-a", DataAddr: "127.0.0.1:9200", CtrlAddr: "127.0.0.1:9100"}); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if _, e = control.NewLifecycleServiceClient(ac).CreateVolume(ctx, &control.CreateVolumeRequest{VolumeId: "vol-f", SizeBytes: 1 << 20, ReplicationFactor: 1}); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
b := &control.WorkspaceBinding{VolumeId: "vol-f", ServerId: "node-a", DataAddr: "127.0.0.1:19200", CtrlAddr: "127.0.0.1:19100"}
|
||||
if _, e = admin.RegisterWorkspaceBinding(ctx, b); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if _, e = admin.PlaceWorkspace(ctx, &control.WorkspacePlacement{VolumeId: "vol-f", ServerId: "node-a", ReplicaId: "r1"}); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if _, e = control.NewObservationServiceClient(nc).ReportHeartbeat(ctx, &control.HeartbeatReport{ReadsLevel: 1, ServerId: "node-a", SentAt: timestamppb.Now(), Reachable: true, Eligible: true, Slots: []*control.HeartbeatSlot{{VolumeId: "vol-f", ReplicaId: "r1", DataAddr: b.DataAddr, CtrlAddr: b.CtrlAddr}}}); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if _, e = mh.RunLifecycleProductTick(); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
for deadline := time.Now().Add(3 * time.Second); ; time.Sleep(10 * time.Millisecond) {
|
||||
if line, ok := mh.Publisher().VolumeAuthorityLine("vol-f"); ok && line.Epoch == 1 {
|
||||
break
|
||||
}
|
||||
if time.Now().After(deadline) {
|
||||
t.Fatal("no first authority line")
|
||||
}
|
||||
}
|
||||
id := &control.WorkspaceIdentity{VolumeId: "vol-f", ReplicaId: "r1", ServerId: "node-a", Epoch: 1}
|
||||
if _, e = node.RenewWorkspaceLease(ctx, id); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if _, e = operator.RevokeWorkspace(ctx, id); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if _, e = node.AckWorkspaceRevoked(ctx, &control.WorkspaceRevocationAck{Identity: id, HeadGen: 9}); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
h := newFakeHost(t)
|
||||
env := h.env(t)
|
||||
volumeReleaseSetup = 10 * time.Second // Real disk-backed master uses the production setup budget.
|
||||
stubResolve(t, "00112233445566778899aabbccddeeff", nil)
|
||||
old := releaseQuery
|
||||
releaseQuery = func(ctx context.Context, _, v string) (*control.WorkspaceStatus, error) {
|
||||
return operator.QueryWorkspace(ctx, &control.WorkspaceVolume{VolumeId: v})
|
||||
}
|
||||
defer func() { releaseQuery = old }()
|
||||
t.Setenv(link.EnvTLSCert, files["operator"].Cert)
|
||||
t.Setenv(link.EnvTLSKey, files["operator"].Key)
|
||||
t.Setenv(link.EnvTLSCA, caFile)
|
||||
v := h.spec(true)
|
||||
v.Master = mh.Addr()
|
||||
v.VolumeID = "vol-f"
|
||||
v.ServerID = "node-a"
|
||||
v.ReplicaID = "r1"
|
||||
v.DataAddr = b.DataAddr
|
||||
v.CtrlAddr = b.CtrlAddr
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
ws, e := operator.QueryWorkspace(r.Context(), &control.WorkspaceVolume{VolumeId: "vol-f"})
|
||||
if e != nil {
|
||||
http.Error(w, e.Error(), 500)
|
||||
return
|
||||
}
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{"VolumeID": "vol-f", "ReplicaID": "r1", "Epoch": ws.GetLease().GetEpoch(), "Healthy": h.healthy.Load(), "FrontendPrimaryReady": h.healthy.Load()})
|
||||
}))
|
||||
defer srv.Close()
|
||||
v.StatusAddr = strings.TrimPrefix(srv.URL, "http://")
|
||||
if _, e = operator.RegisterWorkspaceBinding(ctx, b); status.Code(e) != codes.PermissionDenied {
|
||||
t.Fatalf("operator binding call=%v", e)
|
||||
}
|
||||
wsBefore, e := operator.QueryWorkspace(ctx, &control.WorkspaceVolume{VolumeId: "vol-f"})
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if volumeHostBinding(wsBefore, "vol-f", "node-a") == nil {
|
||||
t.Fatal("clean stop ACK retired the restart binding; an admin would be needed")
|
||||
}
|
||||
if code, _, errs := runStart(env, v, startOpts{Wait: time.Second}); code != 0 {
|
||||
t.Fatalf("operator start=%d %s", code, errs)
|
||||
}
|
||||
n := reads.Load()
|
||||
if code, _, errs := runStart(env, v, startOpts{Wait: time.Second}); code != 0 || reads.Load() != n {
|
||||
t.Fatalf("second start=%d HEAD reads %d->%d %s", code, n, reads.Load(), errs)
|
||||
}
|
||||
ws, e := operator.QueryWorkspace(ctx, &control.WorkspaceVolume{VolumeId: "vol-f"})
|
||||
if e != nil || ws.GetLease().GetEpoch() != 2 || len(ws.GetMoves()) != 1 {
|
||||
t.Fatalf("grant=%v err=%v", ws, e)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/seaweedfs/seaweed-block/core/authority"
|
||||
"github.com/seaweedfs/seaweed-block/core/host/master"
|
||||
"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"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Registering B as a prepared target does not move the legacy line from A.
|
||||
// This history uses the real placement, registration and revocation producers.
|
||||
func TestVolumeStartPreparedTargetNeverBecomesTheLineOwner(t *testing.T) {
|
||||
for name, revoke := range map[string]bool{"revoked": true, "unrevoked": false} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
mh, stop := startDeleteMaster(t, master.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 }})
|
||||
defer stop()
|
||||
conn, e := grpc.NewClient(mh.Addr(), grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
defer conn.Close()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
rpc := control.NewWorkspaceServiceClient(conn)
|
||||
for _, host := range []string{"s7", "host-b"} {
|
||||
if _, e = mh.Lifecycle().Nodes.RegisterNode(lifecycle.NodeRegistration{ServerID: host, DataAddr: "127.0.0.1:9200", CtrlAddr: "127.0.0.1:9100"}); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
}
|
||||
if _, e = control.NewLifecycleServiceClient(conn).CreateVolume(ctx, &control.CreateVolumeRequest{VolumeId: "vol-a", SizeBytes: 1 << 20, ReplicationFactor: 1}); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
// A committed legacy placement has no explicit workspace binding.
|
||||
if _, e = mh.Lifecycle().Placements.ApplyPlan(lifecycle.PlacementPlan{VolumeID: "vol-a", DesiredRF: 1, Candidates: []lifecycle.PlacementCandidate{{VolumeID: "vol-a", ServerID: "s7", ReplicaID: "r3", Source: lifecycle.PlacementSourceExistingReplica}}}); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if _, e = control.NewObservationServiceClient(conn).ReportHeartbeat(ctx, &control.HeartbeatReport{ReadsLevel: 1, ServerId: "s7", SentAt: timestamppb.Now(), Reachable: true, Eligible: true, Slots: []*control.HeartbeatSlot{{VolumeId: "vol-a", ReplicaId: "r3", DataAddr: "127.0.0.1:19200", CtrlAddr: "127.0.0.1:19100"}}}); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if _, e = mh.RunLifecycleProductTick(); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
for deadline := time.Now().Add(3 * time.Second); ; time.Sleep(10 * time.Millisecond) {
|
||||
if line, ok := mh.Publisher().VolumeAuthorityLine("vol-a"); ok && line.Epoch == 1 {
|
||||
break
|
||||
}
|
||||
if time.Now().After(deadline) {
|
||||
t.Fatal("no legacy line")
|
||||
}
|
||||
}
|
||||
id := &control.WorkspaceIdentity{VolumeId: "vol-a", ReplicaId: "r3", ServerId: "s7", Epoch: 1}
|
||||
if _, e = rpc.RenewWorkspaceLease(ctx, id); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if _, e = rpc.RegisterWorkspaceBinding(ctx, &control.WorkspaceBinding{VolumeId: "vol-a", ServerId: "host-b", DataAddr: "127.0.0.1:29200", CtrlAddr: "127.0.0.1:29100"}); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if revoke {
|
||||
if _, e = rpc.RevokeWorkspace(ctx, id); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
}
|
||||
ws, e := rpc.QueryWorkspace(ctx, &control.WorkspaceVolume{VolumeId: "vol-a"})
|
||||
if e != nil || len(ws.GetBindings()) != 1 || len(ws.GetMoves()) != 0 || ws.GetRevocationAck() != nil {
|
||||
t.Fatalf("history=%v err=%v", ws, e)
|
||||
}
|
||||
for _, host := range []string{"s7", "host-b"} {
|
||||
t.Run(host, func(t *testing.T) {
|
||||
h := newFakeHost(t)
|
||||
env := h.env(t)
|
||||
volumeReleaseSetup = 10 * time.Second // Real disk-backed master uses the production setup budget.
|
||||
stubResolve(t, "00112233445566778899aabbccddeeff", nil)
|
||||
old := releaseQuery
|
||||
releaseQuery = func(ctx context.Context, _, v string) (*control.WorkspaceStatus, error) {
|
||||
return rpc.QueryWorkspace(ctx, &control.WorkspaceVolume{VolumeId: v})
|
||||
}
|
||||
defer func() { releaseQuery = old }()
|
||||
v := h.spec(true)
|
||||
v.Master = mh.Addr()
|
||||
v.ServerID = host
|
||||
v.DataAddr, v.CtrlAddr = "127.0.0.1:19200", "127.0.0.1:19100"
|
||||
if host == "host-b" {
|
||||
v.DataAddr = "127.0.0.1:29200"
|
||||
v.CtrlAddr = "127.0.0.1:29100"
|
||||
}
|
||||
code, _, errs := runStart(env, v, startOpts{Wait: time.Second})
|
||||
if host == "s7" {
|
||||
if code != 0 || h.called("enable") != 1 || strings.Contains(errs, "served by host-b") || strings.Contains(errs, "sw-block ops workspace force-move") {
|
||||
t.Fatalf("source A: code=%d enable=%d %s", code, h.called("enable"), errs)
|
||||
}
|
||||
if !revoke {
|
||||
if c, out, er := runStop(env, stopOpts{Volume: "vol-a", NoCut: true, Timeout: time.Second}); c != 0 || !strings.Contains(out, "legacy stop") {
|
||||
t.Fatalf("legacy stop=%d %s %s", c, out, er)
|
||||
}
|
||||
if c, out, er := runStart(env, v, startOpts{Wait: time.Second}); c != 0 || h.called("enable") != 2 {
|
||||
t.Fatalf("legacy restart=%d %s %s", c, out, er)
|
||||
}
|
||||
}
|
||||
} else if code != 2 || h.called("enable") != 0 || !strings.Contains(errs, "served by s7") || strings.Contains(errs, "sw-block ops workspace force-move") {
|
||||
t.Fatalf("prepared B: code=%d enable=%d %s", code, h.called("enable"), errs)
|
||||
}
|
||||
after, e := rpc.QueryWorkspace(ctx, &control.WorkspaceVolume{VolumeId: "vol-a"})
|
||||
if e != nil || len(after.GetMoves()) != 0 {
|
||||
t.Fatalf("START issued move: %v %v", after, e)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Creating a spec precedes the holder's first report and authority publication.
|
||||
func TestVolumeStartFreshSpecBeforeAnyPublishedLine(t *testing.T) {
|
||||
mh, stop := startDeleteMaster(t, master.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 }})
|
||||
defer stop()
|
||||
conn, err := grpc.NewClient(mh.Addr(), grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer conn.Close()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
if _, err = control.NewLifecycleServiceClient(conn).CreateVolume(ctx, &control.CreateVolumeRequest{VolumeId: "vol-a", SizeBytes: 1 << 20, ReplicationFactor: 1}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
rpc := control.NewWorkspaceServiceClient(conn)
|
||||
ws, err := rpc.QueryWorkspace(ctx, &control.WorkspaceVolume{VolumeId: "vol-a"})
|
||||
if err != nil || !ws.GetNeverPublished() || ws.GetCurrentHolder() != nil || ws.GetLease() != nil || ws.GetRevocationAck() != nil || len(ws.GetMoves()) != 0 {
|
||||
t.Fatalf("fresh reply=%v err=%v", ws, err)
|
||||
}
|
||||
h := newFakeHost(t)
|
||||
env := h.env(t)
|
||||
volumeReleaseSetup = 10 * time.Second
|
||||
stubResolve(t, "00112233445566778899aabbccddeeff", nil)
|
||||
old := releaseQuery
|
||||
releaseQuery = func(ctx context.Context, _, v string) (*control.WorkspaceStatus, error) {
|
||||
return rpc.QueryWorkspace(ctx, &control.WorkspaceVolume{VolumeId: v})
|
||||
}
|
||||
t.Cleanup(func() { releaseQuery = old })
|
||||
v := h.spec(true)
|
||||
v.Master = mh.Addr()
|
||||
if code, _, errs := runStart(env, v, startOpts{Wait: time.Second}); code != 0 || h.called("enable") != 1 {
|
||||
t.Fatalf("fresh start: code=%d enable=%d %s", code, h.called("enable"), errs)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
control "github.com/seaweedfs/seaweed-block/core/rpc/control"
|
||||
"github.com/seaweedfs/seaweed-block/core/rpc/wsclient"
|
||||
)
|
||||
|
||||
const unknownStartOwnerCost = "The master could not prove the current authority holder. START refuses rather than guessing from issued moves, ACKs or prepared bindings. An operator who independently knows the correct host can use the force-move operation's --target-host option; START cannot choose or print that target."
|
||||
|
||||
// A recorded release is final at its old epoch. Only the existing clean
|
||||
// move path can issue a new epoch; start never renews the released epoch.
|
||||
func prepareVolumeStart(ctx context.Context, v volumeSpec, stdout, stderr io.Writer) int {
|
||||
setup, cancel := context.WithTimeout(ctx, volumeReleaseSetup)
|
||||
defer cancel()
|
||||
ws, err := releaseQuery(setup, v.Master, v.VolumeID)
|
||||
if err != nil {
|
||||
fmt.Fprintf(stderr, "sw-block volume start: volume_start_owner_unknown: %v; the unit was not started\n", err)
|
||||
fmt.Fprintln(stderr, unknownStartOwnerCost)
|
||||
return wsExitRefusedLocally
|
||||
}
|
||||
// Modern masters answer with a holder, first-launch proof or an
|
||||
// unreadable-owner marker. Older replies omit all three.
|
||||
if legacyWorkspaceMaster(ws) {
|
||||
fmt.Fprintln(stdout, "legacy start: master predates owner observation; use the existing authority path")
|
||||
return 0
|
||||
}
|
||||
if !ws.GetOwnerUnreadable() && ws.GetNeverPublished() && ws.GetCurrentHolder() == nil && ws.GetLease() == nil && ws.GetRevocationAck() == nil && len(ws.GetMoves()) == 0 {
|
||||
fmt.Fprintln(stdout, "first start: no published authority line or workspace history")
|
||||
return 0
|
||||
}
|
||||
owner := startLineOwner(ws, v)
|
||||
if owner == "" {
|
||||
fmt.Fprintln(stderr, "sw-block volume start: volume_start_owner_unknown: the current authority holder is unknown or inconsistent; the unit was not started")
|
||||
fmt.Fprintln(stderr, unknownStartOwnerCost)
|
||||
return wsExitRefusedLocally
|
||||
}
|
||||
if owner != v.ServerID || ws.GetCurrentHolder().GetReplicaId() != v.ReplicaID {
|
||||
fmt.Fprintf(stderr, "sw-block volume start: volume_start_served_elsewhere: served by %s; the unit was not started\n", owner)
|
||||
return wsExitRefusedLocally
|
||||
}
|
||||
binding := volumeHostBinding(ws, v.VolumeID, v.ServerID)
|
||||
if binding == nil {
|
||||
fmt.Fprintln(stdout, "legacy start: no binding for this host; use the existing authority line")
|
||||
return 0
|
||||
}
|
||||
if binding.GetDataAddr() != v.DataAddr || binding.GetCtrlAddr() != v.CtrlAddr {
|
||||
fmt.Fprintln(stderr, "sw-block volume start: volume_start_binding_mismatch: settings do not match this host's binding; the unit was not started")
|
||||
return wsExitRefusedLocally
|
||||
}
|
||||
released, _ := leaseVerdict(ws, v.VolumeID, v.ReplicaID, v.ServerID, 0)
|
||||
epoch := ws.GetLease().GetEpoch()
|
||||
if !released.Released {
|
||||
if ws.GetLease().GetRevoking() {
|
||||
fmt.Fprintf(stderr, "sw-block volume start: volume_start_revoked_without_release: %s@%d has no recorded clean release for %s; the unit was not started\n", v.ReplicaID, epoch, v.ServerID)
|
||||
fmt.Fprintln(stderr, "An explicit forced move may lose writes after the last published HEAD. It moves authority only; then rerun volume start:")
|
||||
fmt.Fprintln(stderr, shellCommand("sw-block", "ops", "workspace", "force-move", "--master", v.Master, "--volume", v.VolumeID,
|
||||
"--target-host", v.ServerID, "--target-data", v.DataAddr, "--target-ctrl", v.CtrlAddr,
|
||||
"--request-id", fmt.Sprintf("volume-start-force:%s@%d", v.VolumeID, epoch), "--confirm-forced", fmt.Sprintf("%s@%d", v.VolumeID, epoch)))
|
||||
return wsExitRefusedLocally
|
||||
}
|
||||
// QueryWorkspace already proves the current issued move. Starting does
|
||||
// not resend it (which would read HEAD again) or mint another epoch.
|
||||
return 0
|
||||
}
|
||||
q := &control.WorkspaceMove{RequestId: volumeStartMoveID(v.VolumeID, epoch),
|
||||
VolumeId: v.VolumeID, ExpectedReplicaId: v.ReplicaID, ExpectedEpoch: epoch,
|
||||
TargetReplicaId: v.ReplicaID, TargetServerId: v.ServerID, TargetDataAddr: v.DataAddr, TargetCtrlAddr: v.CtrlAddr, Kind: "clean"}
|
||||
fmt.Fprintf(stdout, "+ clean same-host move %s/%s@%d (request %s)\n", v.ServerID, v.ReplicaID, epoch, q.RequestId)
|
||||
client, err := workspaceDial(v.Master)
|
||||
if err != nil {
|
||||
fmt.Fprintf(stderr, "sw-block volume start: volume_start_move_not_sent: %v\n", err)
|
||||
return 1
|
||||
}
|
||||
defer client.Close()
|
||||
grant, err := client.CleanMove(setup, q)
|
||||
if err != nil {
|
||||
fmt.Fprintf(stderr, "sw-block volume start: volume_start_move: %v; rerun the same volume start (request %s)\n", err, q.RequestId)
|
||||
return workspaceExit(wsclient.OutcomeOf(err))
|
||||
}
|
||||
if grant.GetNewEpoch() != epoch+1 || grant.GetOldHost() != v.ServerID {
|
||||
fmt.Fprintln(stderr, "sw-block volume start: volume_start_move_outcome_unknown: grant is not epoch+1; the unit was not started")
|
||||
return wsExitUnknown
|
||||
}
|
||||
fmt.Fprintf(stdout, "clean move granted: %s/%s@%d; start the unit\n", v.ServerID, v.ReplicaID, grant.GetNewEpoch())
|
||||
return 0
|
||||
}
|
||||
|
||||
func volumeStartMoveID(volume string, epoch uint64) string {
|
||||
return fmt.Sprintf("volume-start:%s@%d", volume, epoch)
|
||||
}
|
||||
|
||||
// Only the master's authority-line/placement projection identifies an owner.
|
||||
// Prepared targets never prove current membership. Conflicting epoch facts
|
||||
// cannot authorize a unit start or a forced-move recommendation.
|
||||
func startLineOwner(ws *control.WorkspaceStatus, v volumeSpec) string {
|
||||
if ws.GetOwnerUnreadable() {
|
||||
return ""
|
||||
}
|
||||
h := ws.GetCurrentHolder()
|
||||
if h.GetVolumeId() != v.VolumeID || h.GetServerId() == "" || h.GetReplicaId() == "" || h.GetEpoch() == 0 {
|
||||
return ""
|
||||
}
|
||||
if l := ws.GetLease(); l != nil && (l.GetEpoch() != h.GetEpoch() || l.GetReplicaId() != h.GetReplicaId()) {
|
||||
return ""
|
||||
}
|
||||
for _, g := range ws.GetMoves() {
|
||||
if g.GetIssued() && g.GetVolumeId() == v.VolumeID && g.GetNewEpoch() == h.GetEpoch() && (g.GetNewHost() != h.GetServerId() || g.GetNewReplicaId() != h.GetReplicaId()) {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
return h.GetServerId()
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/authority"
|
||||
"github.com/seaweedfs/seaweed-block/core/host/master"
|
||||
control "github.com/seaweedfs/seaweed-block/core/rpc/control"
|
||||
"github.com/seaweedfs/seaweed-block/core/rpc/wsclient"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
// The real master issues the move and reports the current holder. Only the unit and holder
|
||||
// process are fixtures: enabling the unit renews the real assigned epoch;
|
||||
// the holder's stop ACK goes through the real detached-HEAD check.
|
||||
func TestVolumeStartReleaseAgainstRealMaster(t *testing.T) {
|
||||
for _, loseAnswer := range []bool{false, true} {
|
||||
t.Run(fmt.Sprintf("lost-answer-%v", loseAnswer), func(t *testing.T) {
|
||||
for _, key := range []string{"SW_BLOCK_TLS_CERT", "SW_BLOCK_TLS_KEY", "SW_BLOCK_TLS_CA"} {
|
||||
t.Setenv(key, "")
|
||||
}
|
||||
cfg := master.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", Detached: true, RemoteLSN: 42}, nil
|
||||
}}
|
||||
mh, stop := startDeleteMaster(t, cfg)
|
||||
defer stop()
|
||||
seedForcedVolumeLease(t, mh, false)
|
||||
conn, err := grpc.NewClient(mh.Addr(), grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer conn.Close()
|
||||
rpc := control.NewWorkspaceServiceClient(conn)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
h := newFakeHost(t)
|
||||
env := h.env(t)
|
||||
volumeReleaseSetup = 10 * time.Second // Real disk-backed master uses the production setup budget.
|
||||
stubResolve(t, "00112233445566778899aabbccddeeff", nil)
|
||||
oldQ, oldR, oldD := releaseQuery, workspaceRevoke, workspaceDial
|
||||
releaseQuery = func(ctx context.Context, _, volume string) (*control.WorkspaceStatus, error) {
|
||||
return rpc.QueryWorkspace(ctx, &control.WorkspaceVolume{VolumeId: volume})
|
||||
}
|
||||
workspaceRevoke = func(ctx context.Context, _ string, id *control.WorkspaceIdentity) (*control.WorkspaceLeaseFact, error) {
|
||||
lease, err := rpc.RevokeWorkspace(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_, err = rpc.AckWorkspaceRevoked(ctx, &control.WorkspaceRevocationAck{Identity: id, HeadGen: 9})
|
||||
return lease, err
|
||||
}
|
||||
recorder := &startMoveRecorder{WorkspaceServiceClient: rpc, lose: loseAnswer}
|
||||
workspaceDial = func(string) (*wsclient.Client, error) { return wsclient.New(recorder), nil }
|
||||
defer func() { releaseQuery, workspaceRevoke, workspaceDial = oldQ, oldR, oldD }()
|
||||
exited79 := false
|
||||
env.Systemctl = func(ctx context.Context, args ...string) (string, error) {
|
||||
if args[0] == "enable" {
|
||||
ws, err := rpc.QueryWorkspace(ctx, &control.WorkspaceVolume{VolumeId: "vol-f"})
|
||||
if err != nil {
|
||||
return "query", err
|
||||
}
|
||||
_, err = rpc.RenewWorkspaceLease(ctx, &control.WorkspaceIdentity{VolumeId: "vol-f", ReplicaId: "r1", ServerId: "node-a", Epoch: ws.GetCurrentHolder().GetEpoch()})
|
||||
if err != nil {
|
||||
exited79 = true
|
||||
return "FINAL", fmt.Errorf("unit exit 79: %w", err)
|
||||
}
|
||||
}
|
||||
return h.systemctl(ctx, args...)
|
||||
}
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.URL.Path {
|
||||
case "/status":
|
||||
ws, err := rpc.QueryWorkspace(r.Context(), &control.WorkspaceVolume{VolumeId: "vol-f"})
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), 500)
|
||||
return
|
||||
}
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{"VolumeID": "vol-f", "ReplicaID": "r1", "Epoch": ws.GetLease().GetEpoch(), "Healthy": h.healthy.Load(), "FrontendPrimaryReady": h.healthy.Load()})
|
||||
case "/status/guests":
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{"connected": 0})
|
||||
case "/status/durable":
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{})
|
||||
default:
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
}))
|
||||
defer srv.Close()
|
||||
v := h.spec(true)
|
||||
v.Master, v.VolumeID, v.ServerID, v.ReplicaID = mh.Addr(), "vol-f", "node-a", "r1"
|
||||
v.DataAddr, v.CtrlAddr, v.StatusAddr = "127.0.0.1:19200", "127.0.0.1:19100", strings.TrimPrefix(srv.URL, "http://")
|
||||
initial, e := rpc.QueryWorkspace(ctx, &control.WorkspaceVolume{VolumeId: v.VolumeID})
|
||||
if e != nil || len(initial.GetMoves()) != 0 || initial.GetRevocationAck() != nil || initial.GetCurrentHolder().GetServerId() != "node-a" {
|
||||
t.Fatalf("first grant owner=%v err=%v", initial, e)
|
||||
}
|
||||
if code, _, errs := runStart(env, v, startOpts{Wait: time.Second}); code != 0 {
|
||||
t.Fatal(errs)
|
||||
}
|
||||
if code, out, errs := runStop(env, stopOpts{Volume: "vol-f", NoCut: true, Timeout: time.Second}); code != 0 {
|
||||
t.Fatalf("stop=%d %s %s", code, out, errs)
|
||||
}
|
||||
code, out, errs := runStart(env, v, startOpts{Wait: time.Second})
|
||||
if loseAnswer {
|
||||
if code != wsExitUnknown || h.called("enable") != 1 {
|
||||
t.Fatalf("lost move=%d %s %s", code, out, errs)
|
||||
}
|
||||
code, out, errs = runStart(env, v, startOpts{Wait: time.Second})
|
||||
}
|
||||
if code != 0 || exited79 {
|
||||
t.Fatalf("restart=%d exit79=%v %s %s", code, exited79, out, errs)
|
||||
}
|
||||
ws, err := rpc.QueryWorkspace(ctx, &control.WorkspaceVolume{VolumeId: "vol-f"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if ws.GetLease().GetEpoch() != 2 || ws.GetRevocationAck() != nil || len(ws.GetMoves()) != 1 {
|
||||
t.Fatalf("master did not issue exactly one epoch: %v", ws)
|
||||
}
|
||||
wantCalls := 1
|
||||
if len(recorder.ids) != wantCalls {
|
||||
t.Fatalf("move calls=%v", recorder.ids)
|
||||
}
|
||||
for _, id := range recorder.ids {
|
||||
if id != "volume-start:vol-f@1" {
|
||||
t.Fatalf("unstable request %q", id)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
type startMoveRecorder struct {
|
||||
control.WorkspaceServiceClient
|
||||
ids []string
|
||||
lose bool
|
||||
}
|
||||
|
||||
func (c *startMoveRecorder) MoveWorkspace(ctx context.Context, q *control.WorkspaceMove, opts ...grpc.CallOption) (*control.WorkspaceGrant, error) {
|
||||
c.ids = append(c.ids, q.GetRequestId())
|
||||
g, err := c.WorkspaceServiceClient.MoveWorkspace(ctx, q, opts...)
|
||||
if err == nil && c.lose {
|
||||
c.lose = false
|
||||
return nil, status.Error(codes.Unavailable, "issued answer lost")
|
||||
}
|
||||
return g, err
|
||||
}
|
||||
@@ -0,0 +1,337 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
control "github.com/seaweedfs/seaweed-block/core/rpc/control"
|
||||
)
|
||||
|
||||
// The unit models the shipped FINAL-lease refusal: enabling it at the ACKed
|
||||
// epoch exits 79. Only a clean move clearing that ACK lets the start serve.
|
||||
func TestVolumeStopThenStartMovesBeforeEnablingTheUnit(t *testing.T) {
|
||||
h := newFakeHost(t)
|
||||
env := h.env(t)
|
||||
stubResolve(t, "00112233445566778899aabbccddeeff", nil)
|
||||
f := &fakeWorkspace{move: func(q *control.WorkspaceMove) (*control.WorkspaceGrant, error) {
|
||||
if q.GetKind() != "clean" || q.GetForce() || q.GetExpectedEpoch() != 3 || q.GetExpectedReplicaId() != "r3" || q.GetTargetServerId() != "s7" {
|
||||
t.Errorf("unexpected start move: %v", q)
|
||||
}
|
||||
g := cleanGrant(q)
|
||||
g.OldHost = "s7"
|
||||
h.lease.set(func(m *fakeLeaseMaster) { m.epoch, m.acked, m.revoking = g.GetNewEpoch(), false, false })
|
||||
return g, nil
|
||||
}}
|
||||
addr, _ := startFakeWorkspace(t, f)
|
||||
v := h.spec(true)
|
||||
v.Master = addr
|
||||
exited79 := false
|
||||
env.Systemctl = func(ctx context.Context, args ...string) (string, error) {
|
||||
if args[0] == "enable" {
|
||||
h.lease.mu.Lock()
|
||||
final := h.lease.acked
|
||||
h.lease.mu.Unlock()
|
||||
if final {
|
||||
exited79 = true
|
||||
return "workspace lease FINAL", fmt.Errorf("exit status 79")
|
||||
}
|
||||
}
|
||||
return h.systemctl(ctx, args...)
|
||||
}
|
||||
if code, _, errs := runStart(env, v, startOpts{Wait: time.Second}); code != 0 {
|
||||
t.Fatal(errs)
|
||||
}
|
||||
if code, out, errs := runStop(env, stopOpts{Volume: v.VolumeID, Timeout: time.Second}); code != 0 {
|
||||
t.Fatalf("stop=%d %s %s", code, out, errs)
|
||||
}
|
||||
if code, out, errs := runStart(env, v, startOpts{Wait: time.Second}); code != 0 || exited79 {
|
||||
t.Fatalf("restart=%d exited79=%v %s %s", code, exited79, out, errs)
|
||||
}
|
||||
if f.n("MoveWorkspace") != 1 {
|
||||
t.Fatalf("moves=%d, want one clean move", f.n("MoveWorkspace"))
|
||||
}
|
||||
h.lease.mu.Lock()
|
||||
epoch := h.lease.epoch
|
||||
h.lease.mu.Unlock()
|
||||
if epoch != 4 {
|
||||
t.Fatalf("epoch=%d, want 4", epoch)
|
||||
}
|
||||
if got := f.moves[0]; got.GetRequestId() == "" || !strings.Contains(got.GetRequestId(), v.VolumeID) || got.GetTargetDataAddr() != v.DataAddr || got.GetTargetCtrlAddr() != v.CtrlAddr {
|
||||
t.Fatalf("request identity/endpoints: %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
// The master issued the move but its answer was lost. The next query has
|
||||
// no ACK: its stored move proves the grant without sending another move.
|
||||
func TestVolumeStartLostMoveAnswerUsesTheVisibleGrant(t *testing.T) {
|
||||
h := newFakeHost(t)
|
||||
env := h.env(t)
|
||||
stubResolve(t, "00112233445566778899aabbccddeeff", nil)
|
||||
h.lease.set(func(m *fakeLeaseMaster) { m.acked, m.revoking = true, true })
|
||||
var mu sync.Mutex
|
||||
var saved *control.WorkspaceGrant
|
||||
f := &fakeWorkspace{move: func(q *control.WorkspaceMove) (*control.WorkspaceGrant, error) {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
if saved != nil {
|
||||
if q.GetRequestId() != saved.GetRequestId() || q.GetExpectedEpoch() != 3 {
|
||||
t.Errorf("replay changed request: %v", q)
|
||||
}
|
||||
return saved, nil
|
||||
}
|
||||
saved = cleanGrant(q)
|
||||
saved.OldHost = "s7"
|
||||
h.lease.set(func(m *fakeLeaseMaster) { m.epoch, m.acked, m.revoking = 4, false, false })
|
||||
return nil, status.Error(codes.Unavailable, "lost issued answer")
|
||||
}}
|
||||
addr, _ := startFakeWorkspace(t, f)
|
||||
oldQuery := releaseQuery
|
||||
releaseQuery = func(ctx context.Context, master, volume string) (*control.WorkspaceStatus, error) {
|
||||
ws, err := oldQuery(ctx, master, volume)
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
if saved != nil {
|
||||
ws.Moves = []*control.WorkspaceGrant{saved}
|
||||
}
|
||||
return ws, err
|
||||
}
|
||||
t.Cleanup(func() { releaseQuery = oldQuery })
|
||||
v := h.spec(true)
|
||||
v.Master = addr
|
||||
if code, _, errs := runStart(env, v, startOpts{Wait: time.Second}); code != wsExitUnknown || h.called("enable") != 0 {
|
||||
t.Fatalf("lost answer start=%d enabled=%d %s", code, h.called("enable"), errs)
|
||||
}
|
||||
if code, out, errs := runStart(env, v, startOpts{Wait: time.Second}); code != 0 {
|
||||
t.Fatalf("rerun=%d %s %s", code, out, errs)
|
||||
}
|
||||
if f.n("MoveWorkspace") != 1 || len(f.moves) != 1 {
|
||||
t.Fatalf("visible grant caused another move: %v", f.moves)
|
||||
}
|
||||
h.lease.mu.Lock()
|
||||
epoch := h.lease.epoch
|
||||
h.lease.mu.Unlock()
|
||||
if epoch != 4 {
|
||||
t.Fatalf("rerun minted epoch %d, want 4", epoch)
|
||||
}
|
||||
}
|
||||
|
||||
func TestVolumeStartRevokedWithoutReleaseRefusesBeforeTheUnit(t *testing.T) {
|
||||
for _, valid := range []int64{int64(time.Second), 0} {
|
||||
t.Run(fmt.Sprintf("valid-%d", valid), func(t *testing.T) {
|
||||
h := newFakeHost(t)
|
||||
env := h.env(t)
|
||||
stubResolve(t, "00112233445566778899aabbccddeeff", nil)
|
||||
h.lease.set(func(m *fakeLeaseMaster) { m.revoking, m.acked, m.validNs = true, false, valid })
|
||||
enables := 0
|
||||
env.Systemctl = func(ctx context.Context, args ...string) (string, error) {
|
||||
if args[0] == "enable" {
|
||||
enables++
|
||||
return "revoked", fmt.Errorf("exit status 79")
|
||||
}
|
||||
return h.systemctl(ctx, args...)
|
||||
}
|
||||
v := h.spec(true)
|
||||
code, _, errs := runStart(env, v, startOpts{Wait: time.Second})
|
||||
want := "sw-block ops workspace force-move --master 10.0.0.1:9180 --volume vol-a --target-host s7 --target-data 10.0.0.7:9201 --target-ctrl 10.0.0.7:9202 --request-id volume-start-force:vol-a@3 --confirm-forced vol-a@3"
|
||||
if code != 2 || enables != 0 || !strings.Contains(errs, "volume_start_revoked_without_release") || !strings.Contains(errs, want) || !strings.Contains(errs, "may lose writes after the last published HEAD") {
|
||||
t.Fatalf("start=%d enables=%d %s", code, enables, errs)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestVolumeStartNeverRegistersBindings(t *testing.T) {
|
||||
for _, retired := range []bool{false, true} {
|
||||
t.Run(fmt.Sprint(retired), func(t *testing.T) {
|
||||
h := newFakeHost(t)
|
||||
env := h.env(t)
|
||||
stubResolve(t, "00112233445566778899aabbccddeeff", nil)
|
||||
h.lease.set(func(m *fakeLeaseMaster) { m.acked, m.revoking = !retired, !retired })
|
||||
f := &fakeWorkspace{move: func(q *control.WorkspaceMove) (*control.WorkspaceGrant, error) {
|
||||
g := cleanGrant(q)
|
||||
g.OldHost = "s7"
|
||||
return g, nil
|
||||
}}
|
||||
addr, _ := startFakeWorkspace(t, f)
|
||||
v := h.spec(true)
|
||||
v.Master = addr
|
||||
old := releaseQuery
|
||||
releaseQuery = func(ctx context.Context, a, b string) (*control.WorkspaceStatus, error) {
|
||||
ws, e := old(ctx, a, b)
|
||||
ws.Bindings = []*control.WorkspaceBinding{{VolumeId: v.VolumeID, ServerId: v.ServerID, DataAddr: v.DataAddr, CtrlAddr: v.CtrlAddr, Retired: retired}}
|
||||
return ws, e
|
||||
}
|
||||
t.Cleanup(func() { releaseQuery = old })
|
||||
code, _, errs := runStart(env, v, startOpts{Wait: time.Second})
|
||||
if f.n("RegisterWorkspaceBinding") != 0 {
|
||||
t.Fatal("start attempted admin binding registration")
|
||||
}
|
||||
wantMoves := 1
|
||||
if retired {
|
||||
wantMoves = 0
|
||||
}
|
||||
if code != 0 || f.n("MoveWorkspace") != wantMoves {
|
||||
t.Fatalf("retired=%v code=%d moves=%d %s", retired, code, f.n("MoveWorkspace"), errs)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestVolumeStartMovedAwayNeverPrintsAForceCommand(t *testing.T) {
|
||||
for _, fromMove := range []bool{false, true} {
|
||||
t.Run(fmt.Sprint(fromMove), func(t *testing.T) {
|
||||
h := newFakeHost(t)
|
||||
env := h.env(t)
|
||||
stubResolve(t, "00112233445566778899aabbccddeeff", nil)
|
||||
h.lease.set(func(m *fakeLeaseMaster) { m.revoking = true; m.acked = false })
|
||||
old := releaseQuery
|
||||
releaseQuery = func(ctx context.Context, a, b string) (*control.WorkspaceStatus, error) {
|
||||
ws, e := old(ctx, a, b)
|
||||
ws.CurrentHolder = nil
|
||||
ws.Moves = nil
|
||||
ws.Bindings = []*control.WorkspaceBinding{{VolumeId: "vol-a", ServerId: "host-b"}}
|
||||
if fromMove {
|
||||
ws.Bindings = append(ws.Bindings, &control.WorkspaceBinding{VolumeId: "vol-a", ServerId: "s7"})
|
||||
ws.CurrentHolder = &control.WorkspaceIdentity{VolumeId: "vol-a", ServerId: "host-b", ReplicaId: "r3", Epoch: 3}
|
||||
ws.Moves = []*control.WorkspaceGrant{{VolumeId: "vol-a", NewReplicaId: "r3", NewEpoch: 3, OldEpoch: 2, Issued: true, NewHost: "host-b"}}
|
||||
}
|
||||
if !fromMove {
|
||||
return nil, status.Error(codes.FailedPrecondition, "workspace_owner_unknown")
|
||||
}
|
||||
return ws, e
|
||||
}
|
||||
t.Cleanup(func() { releaseQuery = old })
|
||||
v := h.spec(true)
|
||||
code, _, errs := runStart(env, v, startOpts{Wait: time.Second})
|
||||
if code != 2 || h.called("enable") != 0 || (fromMove && !strings.Contains(errs, "served by host-b")) || (!fromMove && !strings.Contains(errs, "volume_start_owner_unknown")) || strings.Contains(errs, "sw-block ops workspace force-move") {
|
||||
t.Fatalf("code=%d enable=%d %s", code, h.called("enable"), errs)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestVolumeStartConflictingOwnerFactsNeverSuggestForce(t *testing.T) {
|
||||
h := newFakeHost(t)
|
||||
env := h.env(t)
|
||||
stubResolve(t, "00112233445566778899aabbccddeeff", nil)
|
||||
h.lease.set(func(m *fakeLeaseMaster) { m.revoking, m.acked = true, true })
|
||||
old := releaseQuery
|
||||
releaseQuery = func(ctx context.Context, a, b string) (*control.WorkspaceStatus, error) {
|
||||
ws, e := old(ctx, a, b)
|
||||
ws.Moves = []*control.WorkspaceGrant{{Issued: true, VolumeId: "vol-a", NewEpoch: 3, NewReplicaId: "r3", NewHost: "another-host"}}
|
||||
return ws, e
|
||||
}
|
||||
t.Cleanup(func() { releaseQuery = old })
|
||||
code, _, errs := runStart(env, h.spec(true), startOpts{Wait: time.Second})
|
||||
if code != 2 || h.called("enable") != 0 || !strings.Contains(errs, "volume_start_owner_unknown") || strings.Contains(errs, "sw-block ops workspace force-move") {
|
||||
t.Fatalf("code=%d %s", code, errs)
|
||||
}
|
||||
}
|
||||
|
||||
func TestVolumeStartUnreadableOwnerHasNoForceAdvice(t *testing.T) {
|
||||
h := newFakeHost(t)
|
||||
env := h.env(t)
|
||||
stubResolve(t, "00112233445566778899aabbccddeeff", nil)
|
||||
h.lease.set(func(m *fakeLeaseMaster) { m.queryErr = fmt.Errorf("master unavailable") })
|
||||
code, _, errs := runStart(env, h.spec(true), startOpts{Wait: time.Second})
|
||||
if code != 2 || h.called("enable") != 0 || !strings.Contains(errs, "volume_start_owner_unknown") || strings.Contains(errs, "sw-block ops workspace force-move") {
|
||||
t.Fatalf("code=%d %s", code, errs)
|
||||
}
|
||||
}
|
||||
|
||||
func TestVolumeStartUnknownOwnerRefusesWithoutChoosingAHost(t *testing.T) {
|
||||
h := newFakeHost(t)
|
||||
env := h.env(t)
|
||||
stubResolve(t, "00112233445566778899aabbccddeeff", nil)
|
||||
old := releaseQuery
|
||||
releaseQuery = func(context.Context, string, string) (*control.WorkspaceStatus, error) {
|
||||
return nil, status.Error(codes.FailedPrecondition, "workspace_owner_unknown")
|
||||
}
|
||||
t.Cleanup(func() { releaseQuery = old })
|
||||
code, _, errs := runStart(env, h.spec(true), startOpts{Wait: time.Second})
|
||||
for _, want := range []string{"volume_start_owner_unknown", "could not prove", "operator who independently knows", "--target-host"} {
|
||||
if !strings.Contains(errs, want) {
|
||||
t.Fatalf("missing %q: %d %s", want, code, errs)
|
||||
}
|
||||
}
|
||||
if code != 2 || h.called("enable") != 0 || strings.Contains(errs, "sw-block ops workspace force-move") {
|
||||
t.Fatalf("chose a target: %d %s", code, errs)
|
||||
}
|
||||
}
|
||||
|
||||
func TestVolumeStartOlderMasterUsesLegacyWithoutMoving(t *testing.T) {
|
||||
h := newFakeHost(t)
|
||||
env := h.env(t)
|
||||
stubResolve(t, "00112233445566778899aabbccddeeff", nil)
|
||||
h.lease.set(func(m *fakeLeaseMaster) { m.acked, m.revoking = true, true })
|
||||
f := &fakeWorkspace{move: func(q *control.WorkspaceMove) (*control.WorkspaceGrant, error) {
|
||||
g := cleanGrant(q)
|
||||
g.OldHost = "s7"
|
||||
return g, nil
|
||||
}}
|
||||
addr, _ := startFakeWorkspace(t, f)
|
||||
v := h.spec(true)
|
||||
v.Master = addr
|
||||
old := releaseQuery
|
||||
f.status, _ = old(context.Background(), addr, v.VolumeID)
|
||||
f.status.CurrentHolder = nil
|
||||
f.status.Moves = []*control.WorkspaceGrant{{VolumeId: v.VolumeID, Issued: true, NewEpoch: 3, NewReplicaId: "r3", NewHost: "s7"}}
|
||||
releaseQuery = workspaceQuery // Nil field is omitted by the real gRPC/protobuf reply.
|
||||
t.Cleanup(func() { releaseQuery = old })
|
||||
// An older reply has move and ACK facts but no modern owner observation; no new move is issued.
|
||||
code, _, errs := runStart(env, v, startOpts{Wait: time.Second})
|
||||
if code != 0 || h.called("enable") != 1 || f.n("MoveWorkspace") != 0 || strings.Contains(errs, "sw-block ops workspace force-move") {
|
||||
t.Fatalf("older master: code=%d enable=%d moves=%d %s", code, h.called("enable"), f.n("MoveWorkspace"), errs)
|
||||
}
|
||||
}
|
||||
|
||||
// Modern fresh replies use positive proof; older replies use the legacy path.
|
||||
func TestVolumeStartNewFreshAndOlderMasterUseTheirOwnPaths(t *testing.T) {
|
||||
for _, proof := range []bool{false, true} {
|
||||
t.Run(fmt.Sprintf("proof-%v", proof), func(t *testing.T) {
|
||||
h := newFakeHost(t)
|
||||
env := h.env(t)
|
||||
stubResolve(t, "00112233445566778899aabbccddeeff", nil)
|
||||
old := releaseQuery
|
||||
releaseQuery = func(context.Context, string, string) (*control.WorkspaceStatus, error) {
|
||||
return &control.WorkspaceStatus{NeverPublished: proof}, nil
|
||||
}
|
||||
t.Cleanup(func() { releaseQuery = old })
|
||||
code, out, errs := runStart(env, h.spec(true), startOpts{Wait: time.Second})
|
||||
if proof {
|
||||
if code != 0 || h.called("enable") != 1 || !strings.Contains(out, "first start") {
|
||||
t.Fatalf("first launch: code=%d enable=%d %s", code, h.called("enable"), errs)
|
||||
}
|
||||
} else if code != 0 || h.called("enable") != 1 || !strings.Contains(out, "legacy start") {
|
||||
t.Fatalf("legacy: code=%d enable=%d %s", code, h.called("enable"), errs)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestVolumeStartNeverPublishedCannotOverrideAuthorityHistory(t *testing.T) {
|
||||
for name, ws := range map[string]*control.WorkspaceStatus{
|
||||
"line": {NeverPublished: true, CurrentHolder: &control.WorkspaceIdentity{}},
|
||||
"lease": {NeverPublished: true, Lease: &control.WorkspaceLeaseFact{}},
|
||||
"ack": {NeverPublished: true, RevocationAck: &control.WorkspaceRevocationAck{}},
|
||||
"move": {NeverPublished: true, Moves: []*control.WorkspaceGrant{{}}},
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
h := newFakeHost(t)
|
||||
env := h.env(t)
|
||||
stubResolve(t, "00112233445566778899aabbccddeeff", nil)
|
||||
old := releaseQuery
|
||||
releaseQuery = func(context.Context, string, string) (*control.WorkspaceStatus, error) { return ws, nil }
|
||||
t.Cleanup(func() { releaseQuery = old })
|
||||
if code, _, errs := runStart(env, h.spec(true), startOpts{Wait: time.Second}); code != 2 || h.called("enable") != 0 || !strings.Contains(errs, "volume_start_owner_unknown") {
|
||||
t.Fatalf("contradiction: code=%d enable=%d %s", code, h.called("enable"), errs)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -54,7 +54,10 @@ can create one: add it to blockmaster's cluster spec and restart blockmaster
|
||||
|
||||
stop: refuses while a guest is connected (unless --force), takes a cut,
|
||||
refuses when the cut failed or its outcome is unknown (unless --no-cut),
|
||||
stops the unit, and ends with: "` + stopRecoveryPoint + `".
|
||||
releases a walstore-chunk volume's lease (released only when blockmaster
|
||||
recorded it; otherwise "not released" or "release not confirmed" and exit
|
||||
1), stops and disables the unit so it stays stopped across reboot, and
|
||||
ends with: "` + stopRecoveryPoint + `".
|
||||
|
||||
backup: a named snapshot of a running walstore-chunk volume (--name is
|
||||
required; the same command with the same --name resumes it, never a second).
|
||||
@@ -294,6 +297,11 @@ func volumeStart(ctx context.Context, env verbEnv, v volumeSpec, o startOpts, st
|
||||
return fail("settings", err.Error(), "")
|
||||
}
|
||||
}
|
||||
if v.Chunk {
|
||||
if code := prepareVolumeStart(ctx, v, stdout, stderr); code != 0 {
|
||||
return code
|
||||
}
|
||||
}
|
||||
if err := env.step(stdout, "unit", "systemctl enable --now "+unit); err != nil {
|
||||
return fail("unit", err.Error(), "run the same command again")
|
||||
}
|
||||
@@ -486,7 +494,20 @@ func volumeStop(ctx context.Context, env verbEnv, o stopOpts, stdout, stderr io.
|
||||
case serr != nil:
|
||||
return refuse("unit", "cannot tell whether "+unit+" runs: "+serr.Error()+"; nothing was done")
|
||||
case unitStopped(st):
|
||||
if code := disableStoppedVolumeUnit(ctx, env, unit, stdout, stderr); code != 0 {
|
||||
return code
|
||||
}
|
||||
fmt.Fprintf(stdout, "sw-block volume stop: %s is not running (%s): nothing to cut or stop\n", unit, st)
|
||||
if e["SWB_DURABLE_IMPL"] != "walstore-chunk" {
|
||||
return 0
|
||||
}
|
||||
// A rerun reads the master's lease record: released, moved, or the
|
||||
// lease ended without a release. It never asks for another run.
|
||||
r := releaseLease(ctx, env, e, false, stdout)
|
||||
fmt.Fprintln(stdout, r.Message)
|
||||
if !r.Released && !r.Legacy {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
if st != "active" {
|
||||
@@ -545,10 +566,20 @@ func volumeStop(ctx context.Context, env verbEnv, o stopOpts, stdout, stderr io.
|
||||
}
|
||||
final = fmt.Sprintf(point, cutAt.UTC().Format(time.RFC3339))
|
||||
}
|
||||
return stopUnit(ctx, env, unit, o.Volume, final, stdout, stderr)
|
||||
if !chunk {
|
||||
return stopUnit(ctx, env, unit, o.Volume, final, stdout, stderr)
|
||||
}
|
||||
// The holder releases its lease before the unit stops: a SIGTERM drains
|
||||
// without the recorded release, and only that record reads stopped.
|
||||
r := releaseLease(ctx, env, e, true, stdout)
|
||||
fmt.Fprintln(stdout, r.Message)
|
||||
if code := stopUnit(ctx, env, unit, o.Volume, final, stdout, stderr); code != 0 || r.Released || r.Legacy {
|
||||
return code
|
||||
}
|
||||
return 1
|
||||
}
|
||||
|
||||
// stopUnit is stop's last step: systemctl stop, then the closing lines.
|
||||
// stopUnit stops and disables the unit, then prints the closing lines.
|
||||
func stopUnit(ctx context.Context, env verbEnv, unit, volume, final string, stdout, stderr io.Writer) int {
|
||||
if err := env.step(stdout, "unit", "systemctl stop "+unit); err != nil {
|
||||
fmt.Fprintf(stderr, "sw-block volume stop: unit: %v\n", err)
|
||||
@@ -558,11 +589,24 @@ func stopUnit(ctx context.Context, env verbEnv, unit, volume, final string, stdo
|
||||
fmt.Fprintf(stderr, "sw-block volume stop: unit: %v: %s (see: journalctl -u %s; run the same command again)\n", err, out, unit)
|
||||
return 1
|
||||
}
|
||||
fmt.Fprintf(stdout, "sw-block volume stop: %s stopped; sudo /usr/local/bin/sw-block volume start %s (the same flags) starts it again\n", unit, volume)
|
||||
if code := disableStoppedVolumeUnit(ctx, env, unit, stdout, stderr); code != 0 {
|
||||
return code
|
||||
}
|
||||
fmt.Fprintf(stdout, "sw-block volume stop: %s stopped; restart command: sudo /usr/local/bin/sw-block volume start %s (the same flags; follow the outcome printed above)\n", unit, volume)
|
||||
fmt.Fprintln(stdout, final)
|
||||
return 0
|
||||
}
|
||||
|
||||
// Disabling persists stop across reboot; start's enable --now restores it.
|
||||
func disableStoppedVolumeUnit(ctx context.Context, env verbEnv, unit string, stdout, stderr io.Writer) int {
|
||||
fmt.Fprintf(stdout, "+ systemctl disable %s (stay stopped across reboot)\n", unit)
|
||||
if out, err := env.Systemctl(ctx, "disable", unit); err != nil {
|
||||
fmt.Fprintf(stderr, "sw-block volume stop: unit: stopped but could not disable boot start: %v: %s; rerun volume stop\n", err, out)
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// cutAnswer is the part of POST /chunk/cut's success body volume stop checks.
|
||||
type cutAnswer struct {
|
||||
VolumeID string `json:"volumeID"`
|
||||
|
||||
@@ -154,6 +154,7 @@ type fakeHost struct {
|
||||
lastCutNs atomic.Int64
|
||||
name string // the volume /status names (vol-a unless a test sets it)
|
||||
srv *httptest.Server
|
||||
lease *fakeLeaseMaster
|
||||
}
|
||||
|
||||
func newFakeHost(t *testing.T) *fakeHost {
|
||||
@@ -166,7 +167,7 @@ func newFakeHost(t *testing.T) *fakeHost {
|
||||
if !ready {
|
||||
reason = "durable_admission_refused"
|
||||
}
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{"VolumeID": h.name, "Healthy": h.healthy.Load(), "FrontendPrimaryReady": ready, "NotReadyReason": reason})
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{"VolumeID": h.name, "ReplicaID": "r3", "Epoch": 3, "Healthy": h.healthy.Load(), "FrontendPrimaryReady": ready, "NotReadyReason": reason})
|
||||
})
|
||||
mux.HandleFunc("/status/guests", func(w http.ResponseWriter, r *http.Request) {
|
||||
if h.noGuests.Load() {
|
||||
@@ -266,6 +267,7 @@ func newFakeHost(t *testing.T) *fakeHost {
|
||||
})
|
||||
h.srv = httptest.NewServer(mux)
|
||||
t.Cleanup(h.srv.Close)
|
||||
h.lease = newFakeLeaseMaster(t)
|
||||
return h
|
||||
}
|
||||
|
||||
@@ -686,15 +688,23 @@ func TestVolumeStopKeepsItsChecksForATransitionalUnit(t *testing.T) {
|
||||
if code, _, errs := runStop(denv, stopOpts{Volume: "vol-a", Timeout: time.Second}); code != 2 || d.called("stop ") != 0 {
|
||||
t.Fatalf("%s, holder down: %d %s; want a refusal", st, code, errs)
|
||||
}
|
||||
if code, out, errs := runStop(denv, stopOpts{Volume: "vol-a", Force: true, NoCut: true, Timeout: time.Second}); code != 0 || d.called("stop ") != 1 || !strings.Contains(out, "no cut taken") {
|
||||
// The unit stops, but with the holder down nothing releases the
|
||||
// lease: the stop says so and does not exit 0.
|
||||
if code, out, errs := runStop(denv, stopOpts{Volume: "vol-a", Force: true, NoCut: true, Timeout: time.Second}); code != 1 || d.called("stop ") != 1 || !strings.Contains(out, "no cut taken") || !strings.Contains(out, "release not confirmed: the running holder's status could not be read") {
|
||||
t.Fatalf("%s, holder down, --force --no-cut: %d %s %s", st, code, out, errs)
|
||||
}
|
||||
}
|
||||
for _, st := range []string{"inactive", "failed"} {
|
||||
h, env := startedHost(t, true)
|
||||
_, _ = h.systemctl(context.Background(), "set-state", st)
|
||||
if code, out, _ := runStop(env, stopOpts{Volume: "vol-a", Timeout: time.Second}); code != 0 || h.called("stop ") != 0 || !strings.Contains(out, "nothing to cut or stop") {
|
||||
t.Fatalf("%s: %d %s; want nothing to stop", st, code, out)
|
||||
// Nothing to cut or stop; the lease record decides the answer, and
|
||||
// the stopped unit's holder is never revoked.
|
||||
if code, out, _ := runStop(env, stopOpts{Volume: "vol-a", Timeout: time.Second}); code != 1 || h.called("stop ") != 0 || !strings.Contains(out, "nothing to cut or stop") || !strings.Contains(out, "not released: the unit is stopped") || len(h.lease.revoked()) != 0 {
|
||||
t.Fatalf("%s: %d %s; want nothing to stop, not released", st, code, out)
|
||||
}
|
||||
h.lease.set(func(m *fakeLeaseMaster) { m.revoking, m.acked = true, true })
|
||||
if code, out, _ := runStop(env, stopOpts{Volume: "vol-a", Timeout: time.Second}); code != 0 || !strings.Contains(out, "released: the master recorded") {
|
||||
t.Fatalf("%s, released: %d %s", st, code, out)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -910,3 +920,61 @@ func TestVolumeStopAcceptsOnlyItsOwnCutInItsProtocol(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestVolumeStopDisablesBootStartAndStartEnablesItAgain(t *testing.T) {
|
||||
h := newFakeHost(t)
|
||||
env := h.env(t)
|
||||
stubResolve(t, "00112233445566778899aabbccddeeff", nil)
|
||||
enabled := false
|
||||
env.Systemctl = func(ctx context.Context, args ...string) (string, error) {
|
||||
if args[0] == "enable" {
|
||||
enabled = true
|
||||
}
|
||||
if args[0] == "disable" {
|
||||
enabled = false
|
||||
}
|
||||
return h.systemctl(ctx, args...)
|
||||
}
|
||||
v := h.spec(false)
|
||||
if c, _, er := runStart(env, v, startOpts{Wait: time.Second}); c != 0 || !enabled {
|
||||
t.Fatalf("start=%d enabled=%v %s", c, enabled, er)
|
||||
}
|
||||
if c, _, er := runStop(env, stopOpts{Volume: v.VolumeID, NoCut: true, Timeout: time.Second}); c != 0 || enabled {
|
||||
t.Fatalf("stop=%d enabled=%v %s", c, enabled, er)
|
||||
}
|
||||
enabled = true // An already inactive but enabled unit must also be disabled.
|
||||
if c, _, er := runStop(env, stopOpts{Volume: v.VolumeID, NoCut: true, Timeout: time.Second}); c != 0 || enabled {
|
||||
t.Fatalf("inactive stop=%d enabled=%v %s", c, enabled, er)
|
||||
}
|
||||
// Reboot starts only enabled units. The stop must have removed that setting.
|
||||
if enabled {
|
||||
t.Fatal("stopped unit would restart at boot")
|
||||
}
|
||||
if c, _, er := runStart(env, v, startOpts{Wait: time.Second}); c != 0 || !enabled {
|
||||
t.Fatalf("restart=%d enabled=%v %s", c, enabled, er)
|
||||
}
|
||||
}
|
||||
|
||||
func TestVolumeStopReportsDisableFailureAndRerunRepairsIt(t *testing.T) {
|
||||
h := newFakeHost(t)
|
||||
env := h.env(t)
|
||||
stubResolve(t, "00112233445566778899aabbccddeeff", nil)
|
||||
v := h.spec(false)
|
||||
if c, _, er := runStart(env, v, startOpts{Wait: time.Second}); c != 0 {
|
||||
t.Fatal(c, er)
|
||||
}
|
||||
fail := true
|
||||
env.Systemctl = func(ctx context.Context, args ...string) (string, error) {
|
||||
if args[0] == "disable" && fail {
|
||||
return "denied", errors.New("disable failed")
|
||||
}
|
||||
return h.systemctl(ctx, args...)
|
||||
}
|
||||
if c, _, er := runStop(env, stopOpts{Volume: v.VolumeID, NoCut: true, Timeout: time.Second}); c != 1 || !strings.Contains(er, "stopped but could not disable boot start") {
|
||||
t.Fatalf("disable failure=%d %s", c, er)
|
||||
}
|
||||
fail = false
|
||||
if c, _, er := runStop(env, stopOpts{Volume: v.VolumeID, NoCut: true, Timeout: time.Second}); c != 0 || h.called("disable") != 1 {
|
||||
t.Fatalf("repair=%d %s", c, er)
|
||||
}
|
||||
}
|
||||
@@ -47,6 +47,9 @@ func runWorkspaceShow(args []string, stdout, stderr io.Writer) int {
|
||||
|
||||
func printWorkspaceView(out io.Writer, volume string, view *control.WorkspaceStatus) {
|
||||
fmt.Fprintf(out, "volume: %s (query snapshot, not authority to serve)\n", volume)
|
||||
if view.GetOwnerUnreadable() {
|
||||
fmt.Fprintln(out, "owner observation: unreadable (remaining status facts follow)")
|
||||
}
|
||||
lease := view.GetLease()
|
||||
if lease == nil {
|
||||
fmt.Fprintln(out, "replica: none\nepoch: none\nlease state: none\nholder: none")
|
||||
@@ -66,7 +69,11 @@ func printWorkspaceView(out io.Writer, volume string, view *control.WorkspaceSta
|
||||
id := ack.GetIdentity()
|
||||
fmt.Fprintf(out, "recorded ACK: %s@%d HEAD generation %d\n", id.GetReplicaId(), id.GetEpoch(), ack.GetHeadGen())
|
||||
}
|
||||
fmt.Fprintln(out, "host: unknown (not recorded by the master); issued moves and bindings below are separate facts")
|
||||
if owner := startLineOwner(view, volumeSpec{VolumeID: volume}); owner != "" {
|
||||
fmt.Fprintf(out, "host: %s (master's current authority holder)\n", owner)
|
||||
} else {
|
||||
fmt.Fprintln(out, "host: unknown (not proven by the master's current-holder projection); issued moves and bindings below are separate facts")
|
||||
}
|
||||
for _, g := range view.GetMoves() {
|
||||
fmt.Fprintf(out, "move: request=%s kind=%s issued=%t %s/%s@%d -> %s/%s@%d HEAD generation %d remote LSN %d\n", g.GetRequestId(), g.GetKind(), g.GetIssued(), g.GetOldHost(), g.GetOldReplicaId(), g.GetOldEpoch(), g.GetNewHost(), g.GetNewReplicaId(), g.GetNewEpoch(), g.GetHeadGen(), g.GetRemoteLsn())
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ func TestWorkspaceShowOrdersOperatorIdentityWithoutInventingAHost(t *testing.T)
|
||||
}
|
||||
last = at
|
||||
}
|
||||
if !strings.Contains(out, "host: unknown (not recorded by the master)") {
|
||||
if !strings.Contains(out, "host: unknown (not proven by the master's current-holder projection)") {
|
||||
t.Fatalf("physical host must remain unknown: %q", out)
|
||||
}
|
||||
}
|
||||
@@ -112,3 +112,12 @@ func TestWorkspaceShowRefusesBadUsageAndClassifiesRPCFailure(t *testing.T) {
|
||||
t.Fatalf("exit=%d out=%q err=%q requests=%d", code, out, errOut, len(r.requests))
|
||||
}
|
||||
}
|
||||
|
||||
func TestWorkspaceShowUsesTheRecordedCurrentHolderInsteadOfPreparedTargets(t *testing.T) {
|
||||
r := &workspaceShowRecorder{reply: &control.WorkspaceStatus{Lease: &control.WorkspaceLeaseFact{VolumeId: "vol", ReplicaId: "r1", Epoch: 1}, CurrentHolder: &control.WorkspaceIdentity{VolumeId: "vol", ReplicaId: "r1", Epoch: 1, ServerId: "node-a"}, Bindings: []*control.WorkspaceBinding{{VolumeId: "vol", ServerId: "node-b"}}}}
|
||||
installShowRecorder(t, r)
|
||||
code, out, errs := runCLI([]string{"ops", "workspace", "show", "--master", "master:19090", "--volume", "vol"})
|
||||
if code != 0 || !strings.Contains(out, "host: node-a (master's current authority holder)") || strings.Contains(out, "host: unknown") {
|
||||
t.Fatalf("code=%d %s %s", code, out, errs)
|
||||
}
|
||||
}
|
||||
@@ -56,6 +56,11 @@ func (f *fakeWorkspace) total() int {
|
||||
return n
|
||||
}
|
||||
|
||||
func (f *fakeWorkspace) RegisterWorkspaceBinding(_ context.Context, q *control.WorkspaceBinding) (*control.WorkspaceBinding, error) {
|
||||
f.count("RegisterWorkspaceBinding")
|
||||
return q, nil
|
||||
}
|
||||
|
||||
func (f *fakeWorkspace) QueryWorkspace(context.Context, *control.WorkspaceVolume) (*control.WorkspaceStatus, error) {
|
||||
f.count("QueryWorkspace")
|
||||
return f.status, nil
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package master
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/authority"
|
||||
)
|
||||
|
||||
// QueryWorkspace names the server whose clean release was recorded (the ACK
|
||||
// is accepted only from it, and kept as "<server>/<replica>"), so a client
|
||||
// can tell its own host's release. A holder string not of that form names
|
||||
// no server.
|
||||
func TestRevocationAckFactNamesTheReleasingServer(t *testing.T) {
|
||||
id := RevocationAckFact("v1", &authority.WorkspaceRevokeAck{ReplicaID: "r1", Epoch: 3, HeadGen: 9, Holder: "node-a/r1"})
|
||||
got := id.GetIdentity()
|
||||
if got.GetVolumeId() != "v1" || got.GetReplicaId() != "r1" || got.GetEpoch() != 3 || got.GetServerId() != "node-a" || id.GetHeadGen() != 9 {
|
||||
t.Fatalf("ack fact %+v", id)
|
||||
}
|
||||
if s := RevocationAckFact("v1", &authority.WorkspaceRevokeAck{ReplicaID: "r1", Epoch: 3, Holder: "node-a/r2"}).GetIdentity().GetServerId(); s != "" {
|
||||
t.Fatalf("a holder of another replica named server %q", s)
|
||||
}
|
||||
}
|
||||
@@ -163,7 +163,7 @@ func (h *Host) reconcileWorkspaceCall(volume string) error {
|
||||
}
|
||||
|
||||
// reconcileWorkspaceBinding retires the bindings one volume's moves and ACK
|
||||
// left behind.
|
||||
// left behind. ACKs retain the restart reservation.
|
||||
func (h *Host) reconcileWorkspaceBinding(volume string) error {
|
||||
state := h.Publisher().WorkspaceState(volume)
|
||||
if state == nil {
|
||||
@@ -171,21 +171,17 @@ func (h *Host) reconcileWorkspaceBinding(volume string) error {
|
||||
}
|
||||
for _, m := range state.Moves {
|
||||
// A move must not retire its own target reservation. A same-host
|
||||
// successor reuses it; a later ACK still retires that epoch below.
|
||||
// successor reuses it, including across a later clean-release ACK.
|
||||
if m.Issued && m.OldHost != m.NewHost {
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
// A clean release retains this host's binding for a same-host epoch+1
|
||||
// restart. Only an issued cross-host move (above) relinquishes it; an ACK
|
||||
// alone seals the old epoch without changing placement or reservation.
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ func TestWorkspaceBindingCallReconcilesItsVolumeAndRetries(t *testing.T) {
|
||||
if runtime.GOOS == "windows" {
|
||||
t.Skip("requires the binding store's supported directory fsync")
|
||||
}
|
||||
want := []bindingRetirement{{"recover", "node-a", 1}, {"recover", "node-b", 2}, {"recover", "node-c", 4}}
|
||||
want := []bindingRetirement{{"recover", "node-a", 1}, {"recover", "node-b", 2}}
|
||||
|
||||
h := bindingReconcileHistory(t, false)
|
||||
rec := &interruptedBindingStore{workspaceBindingStore: h.lifecycle.WorkspaceBindings}
|
||||
@@ -55,7 +55,13 @@ func TestWorkspaceBindingCallReconcilesItsVolumeAndRetries(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, b := range got {
|
||||
epoch := map[string]uint64{"node-a": 1, "node-b": 2, "node-c": 4}[b.ServerID]
|
||||
if b.ServerID == "node-c" {
|
||||
if b.Retired {
|
||||
t.Fatalf("ACK retired restart reservation: %+v", b)
|
||||
}
|
||||
continue
|
||||
}
|
||||
epoch := map[string]uint64{"node-a": 1, "node-b": 2}[b.ServerID]
|
||||
if !b.Retired || b.RetiredEpoch != epoch {
|
||||
t.Fatalf("the next call did not finish the interrupted volume's retirements: %+v", got)
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ func bindingReconcileHistory(t *testing.T, legacySource bool) *Host {
|
||||
return head
|
||||
}
|
||||
// Two cross-host moves, then a same-host successor. Only the first two
|
||||
// moves retire their sources; the final ACK retires node-c at epoch 4.
|
||||
// moves retire their sources; the final ACK retains node-c for restart.
|
||||
for i, target := range []lifecycle.WorkspaceBinding{bindings[1], bindings[2], bindings[2]} {
|
||||
epoch := uint64(i + 1)
|
||||
source := []string{"node-a", "node-b", "node-c"}[i]
|
||||
@@ -102,7 +102,7 @@ func TestWorkspaceBindingReconcileInterruptedAtEveryRetireConverges(t *testing.T
|
||||
if runtime.GOOS == "windows" {
|
||||
t.Skip("requires the binding store's supported directory fsync")
|
||||
}
|
||||
want := []bindingRetirement{{"recover", "node-a", 1}, {"recover", "node-b", 2}, {"recover", "node-c", 4}}
|
||||
want := []bindingRetirement{{"recover", "node-a", 1}, {"recover", "node-b", 2}}
|
||||
for _, legacy := range []bool{false, true} {
|
||||
for _, after := range []bool{false, true} {
|
||||
for at := 1; at <= len(want); at++ {
|
||||
@@ -166,7 +166,13 @@ func TestWorkspaceBindingReconcileInterruptedAtEveryRetireConverges(t *testing.T
|
||||
t.Fatalf("wrong binding count after restart: %+v", got)
|
||||
}
|
||||
for _, b := range got {
|
||||
epoch := map[string]uint64{"node-a": 1, "node-b": 2, "node-c": 4}[b.ServerID]
|
||||
if b.ServerID == "node-c" {
|
||||
if b.Retired {
|
||||
t.Fatalf("ACK retired restart reservation: %+v", b)
|
||||
}
|
||||
continue
|
||||
}
|
||||
epoch := map[string]uint64{"node-a": 1, "node-b": 2}[b.ServerID]
|
||||
if !b.Retired || b.RetiredEpoch != epoch {
|
||||
t.Fatalf("restart did not finish retirements: %+v", got)
|
||||
}
|
||||
|
||||
@@ -451,3 +451,23 @@ func TestWorkspaceBindingInFlightPublicationRechecksOwnershipAndLifetime(t *test
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// A modern unreadable owner must not look like a legacy master's absent fields.
|
||||
func TestWorkspaceQueryUnreadablePublishedOwnerRetainsStatus(t *testing.T) {
|
||||
h, c, ctx := reviewBindingHost(t)
|
||||
reviewLegacyBind(t, h, c, ctx, "unreadable")
|
||||
rpc := control.NewWorkspaceServiceClient(c)
|
||||
if _, err := rpc.RenewWorkspaceLease(ctx, &control.WorkspaceIdentity{VolumeId: "unreadable", ServerId: "node-a", ReplicaId: "r1", Epoch: 1}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := h.Lifecycle().Placements.DeletePlacement("unreadable"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, ok := h.Publisher().PublishedAuthorityLine("unreadable"); !ok {
|
||||
t.Fatal("fixture has no published line")
|
||||
}
|
||||
reply, err := control.NewWorkspaceServiceClient(c).QueryWorkspace(ctx, &control.WorkspaceVolume{VolumeId: "unreadable"})
|
||||
if err != nil || !reply.GetOwnerUnreadable() || reply.GetCurrentHolder() != nil || reply.GetNeverPublished() || reply.GetLease().GetEpoch() != 1 || reply.GetLease().GetReplicaId() != "r1" {
|
||||
t.Fatalf("unreadable line looked legacy: %v %v", reply, err)
|
||||
}
|
||||
}
|
||||
@@ -155,7 +155,7 @@ func workspaceBindingsMove(t *testing.T, forced bool) {
|
||||
t.Fatal(e)
|
||||
}
|
||||
for _, b := range before.Bindings {
|
||||
if b.ServerId == "node-a" && b.Retired == forced {
|
||||
if b.ServerId == "node-a" && b.Retired {
|
||||
t.Fatal("source retirement occurred at wrong boundary", b)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
)
|
||||
|
||||
// INV-WS-SAME-HOST-CLEAN-MOVE-001: retirement belongs to an epoch, so the
|
||||
// old epoch's replay cannot retire the re-prepared same-host binding.
|
||||
func TestWorkspaceRPCSameHostCleanMoveKeepsRepreparedBinding(t *testing.T) {
|
||||
// clean release retains the reservation for the same-host successor.
|
||||
func TestWorkspaceRPCSameHostCleanMoveKeepsTheReleasedBinding(t *testing.T) {
|
||||
h, conn, ctx := reviewBindingHost(t)
|
||||
reviewCreate(t, conn, ctx, "v")
|
||||
ws := control.NewWorkspaceServiceClient(conn)
|
||||
@@ -37,16 +37,10 @@ func TestWorkspaceRPCSameHostCleanMoveKeepsRepreparedBinding(t *testing.T) {
|
||||
if _, err := ws.AckWorkspaceRevoked(ctx, &control.WorkspaceRevocationAck{Identity: id, HeadGen: 9}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got, ok, err := h.Lifecycle().WorkspaceBindings.Get("v"); err != nil || !ok || len(got) != 1 || !got[0].Retired {
|
||||
t.Fatal("ACK did not retire the old binding", got, err)
|
||||
if got, ok, err := h.Lifecycle().WorkspaceBindings.Get("v"); err != nil || !ok || len(got) != 1 || got[0].Retired {
|
||||
t.Fatal("ACK retired the binding needed by the successor", got, err)
|
||||
}
|
||||
req := &control.WorkspaceMove{RequestId: "return", VolumeId: "v", ExpectedReplicaId: "r1", ExpectedEpoch: 1, TargetReplicaId: "r1", TargetServerId: "node-a", TargetDataAddr: b.DataAddr, TargetCtrlAddr: b.CtrlAddr, Kind: "clean"}
|
||||
if _, err := ws.MoveWorkspace(ctx, req); err == nil {
|
||||
t.Fatal("same-host move accepted an unprepared retired binding")
|
||||
}
|
||||
if _, err := ws.RegisterWorkspaceBinding(ctx, b); err != nil {
|
||||
t.Fatal("same-host re-prepare refused", err)
|
||||
}
|
||||
forced := proto.Clone(req).(*control.WorkspaceMove)
|
||||
forced.Kind, forced.Force = "forced", true
|
||||
if _, err := ws.MoveWorkspace(ctx, forced); err == nil {
|
||||
@@ -62,6 +56,6 @@ func TestWorkspaceRPCSameHostCleanMoveKeepsRepreparedBinding(t *testing.T) {
|
||||
t.Fatal("same-host move did not publish exactly the next epoch", line)
|
||||
}
|
||||
if got, ok, err := h.Lifecycle().WorkspaceBindings.Get("v"); err != nil || !ok || len(got) != 1 || got[0].Retired {
|
||||
t.Fatal("old epoch retired the re-prepared binding", got, err)
|
||||
t.Fatal("old epoch retired the released binding", got, err)
|
||||
}
|
||||
}
|
||||
@@ -180,7 +180,7 @@ func sameHostForcedRecovery(t *testing.T, pause time.Duration) {
|
||||
if _, err := ws.AckWorkspaceRevoked(ctx, &control.WorkspaceRevocationAck{Identity: id, HeadGen: 10}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if bindings, ok, err := h.Lifecycle().WorkspaceBindings.Get("v"); err != nil || !ok || len(bindings) != 1 || !bindings[0].Retired {
|
||||
t.Fatalf("successor ACK did not retire its same-host binding: %+v %v", bindings, err)
|
||||
if bindings, ok, err := h.Lifecycle().WorkspaceBindings.Get("v"); err != nil || !ok || len(bindings) != 1 || bindings[0].Retired {
|
||||
t.Fatalf("successor ACK retired its restart binding: %+v %v", bindings, err)
|
||||
}
|
||||
}
|
||||
@@ -510,6 +510,12 @@ func (s *services) QueryWorkspace(ctx context.Context, q *control.WorkspaceVolum
|
||||
return nil, err
|
||||
}
|
||||
out := &control.WorkspaceStatus{}
|
||||
line, hasLine := s.host.Publisher().PublishedAuthorityLine(q.GetVolumeId())
|
||||
if hasLine {
|
||||
if owner := s.host.workspaceLineOwner(line, q.GetVolumeId(), line.ReplicaID, line.Epoch); owner != "" {
|
||||
out.CurrentHolder = &control.WorkspaceIdentity{VolumeId: q.GetVolumeId(), ReplicaId: line.ReplicaID, Epoch: line.Epoch, ServerId: owner}
|
||||
}
|
||||
}
|
||||
bindings, _, err := s.host.lifecycle.WorkspaceBindings.Get(q.GetVolumeId())
|
||||
if err != nil {
|
||||
return nil, workspaceError(err)
|
||||
@@ -519,20 +525,40 @@ func (s *services) QueryWorkspace(ctx context.Context, q *control.WorkspaceVolum
|
||||
}
|
||||
state := s.host.Publisher().WorkspaceState(q.GetVolumeId())
|
||||
if state == nil {
|
||||
return out, nil
|
||||
out.NeverPublished = !hasLine
|
||||
return readableWorkspaceStatus(out)
|
||||
}
|
||||
if lease, ok := s.host.Publisher().WorkspaceLeaseReply(q.GetVolumeId()); ok {
|
||||
out.Lease = leaseFact(s.host.Publisher(), q.GetVolumeId(), lease) // granted expiry, not the durable horizon
|
||||
}
|
||||
if state.Ack != nil {
|
||||
out.RevocationAck = &control.WorkspaceRevocationAck{Identity: &control.WorkspaceIdentity{VolumeId: q.GetVolumeId(), ReplicaId: state.Ack.ReplicaID, Epoch: state.Ack.Epoch}, HeadGen: state.Ack.HeadGen}
|
||||
out.RevocationAck = RevocationAckFact(q.GetVolumeId(), state.Ack)
|
||||
}
|
||||
for _, r := range state.Moves {
|
||||
out.Moves = append(out.Moves, s.grantWithLostRange(r))
|
||||
}
|
||||
out.NeverPublished = !hasLine && state.Lease == nil && state.Ack == nil && len(state.Moves) == 0
|
||||
return readableWorkspaceStatus(out)
|
||||
}
|
||||
|
||||
// An unreadable owner is a positive observation; do not hide the remaining
|
||||
// status facts used by repair and read-only clients.
|
||||
func readableWorkspaceStatus(out *control.WorkspaceStatus) (*control.WorkspaceStatus, error) {
|
||||
out.OwnerUnreadable = out.GetCurrentHolder() == nil && !out.GetNeverPublished()
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// RevocationAckFact is the recorded clean release as QueryWorkspace answers
|
||||
// it: the holder's identity at its epoch, including its server (the ACK was
|
||||
// accepted only from that server: Holder is "<server>/<replica>").
|
||||
func RevocationAckFact(volume string, a *authority.WorkspaceRevokeAck) *control.WorkspaceRevocationAck {
|
||||
server, ok := strings.CutSuffix(a.Holder, "/"+a.ReplicaID)
|
||||
if !ok {
|
||||
server = "" // not this replica's holder form: no server is claimed
|
||||
}
|
||||
return &control.WorkspaceRevocationAck{Identity: &control.WorkspaceIdentity{VolumeId: volume, ReplicaId: a.ReplicaID, Epoch: a.Epoch, ServerId: server}, HeadGen: a.HeadGen}
|
||||
}
|
||||
|
||||
// QueryWorkspaceLostRange returns the stored lost ranges of the volume's
|
||||
// issued forced moves in issue order, or the one of request_id. A forced
|
||||
// move whose range is missing or failed its checks fails the call with
|
||||
|
||||
@@ -1086,8 +1086,17 @@ type WorkspaceStatus struct {
|
||||
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
|
||||
// Read-only owner of the current authority line, resolved from its issued
|
||||
// move or committed placement. A prepared binding never selects this owner.
|
||||
// Absent when the master cannot prove the current holder.
|
||||
CurrentHolder *WorkspaceIdentity `protobuf:"bytes,5,opt,name=current_holder,json=currentHolder,proto3" json:"current_holder,omitempty"`
|
||||
// Positive first-launch proof: no published line or workspace history.
|
||||
// Missing on older masters, which cannot prove this exception.
|
||||
NeverPublished bool `protobuf:"varint,6,opt,name=never_published,json=neverPublished,proto3" json:"never_published,omitempty"`
|
||||
// Owner proof is unavailable; lease/move/ACK/binding facts remain readable.
|
||||
OwnerUnreadable bool `protobuf:"varint,7,opt,name=owner_unreadable,json=ownerUnreadable,proto3" json:"owner_unreadable,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *WorkspaceStatus) Reset() {
|
||||
@@ -1148,6 +1157,27 @@ func (x *WorkspaceStatus) GetBindings() []*WorkspaceBinding {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *WorkspaceStatus) GetCurrentHolder() *WorkspaceIdentity {
|
||||
if x != nil {
|
||||
return x.CurrentHolder
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *WorkspaceStatus) GetNeverPublished() bool {
|
||||
if x != nil {
|
||||
return x.NeverPublished
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (x *WorkspaceStatus) GetOwnerUnreadable() bool {
|
||||
if x != nil {
|
||||
return x.OwnerUnreadable
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
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"`
|
||||
@@ -1394,12 +1424,15 @@ const file_workspace_proto_rawDesc = "" +
|
||||
"\x0fhead_time_known\x18\f \x01(\bR\rheadTimeKnown\x12\x12\n" +
|
||||
"\x04code\x18\r \x01(\tR\x04code\x12\x1f\n" +
|
||||
"\vreason_code\x18\x0e \x01(\tR\n" +
|
||||
"reasonCode\"\xb2\x02\n" +
|
||||
"reasonCode\"\xd9\x03\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\x05moves\x12E\n" +
|
||||
"\bbindings\x18\x04 \x03(\v2).seaweedfs.block.control.WorkspaceBindingR\bbindings\"\xa0\x01\n" +
|
||||
"\bbindings\x18\x04 \x03(\v2).seaweedfs.block.control.WorkspaceBindingR\bbindings\x12Q\n" +
|
||||
"\x0ecurrent_holder\x18\x05 \x01(\v2*.seaweedfs.block.control.WorkspaceIdentityR\rcurrentHolder\x12'\n" +
|
||||
"\x0fnever_published\x18\x06 \x01(\bR\x0eneverPublished\x12)\n" +
|
||||
"\x10owner_unreadable\x18\a \x01(\bR\x0fownerUnreadable\"\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" +
|
||||
@@ -1463,29 +1496,30 @@ var file_workspace_proto_depIdxs = []int32{
|
||||
6, // 5: seaweedfs.block.control.WorkspaceStatus.revocation_ack:type_name -> seaweedfs.block.control.WorkspaceRevocationAck
|
||||
8, // 6: seaweedfs.block.control.WorkspaceStatus.moves:type_name -> seaweedfs.block.control.WorkspaceGrant
|
||||
14, // 7: seaweedfs.block.control.WorkspaceStatus.bindings:type_name -> seaweedfs.block.control.WorkspaceBinding
|
||||
14, // 8: seaweedfs.block.control.WorkspaceService.RegisterWorkspaceBinding:input_type -> seaweedfs.block.control.WorkspaceBinding
|
||||
15, // 9: seaweedfs.block.control.WorkspaceService.PlaceWorkspace:input_type -> seaweedfs.block.control.WorkspacePlacement
|
||||
1, // 10: seaweedfs.block.control.WorkspaceService.RenewWorkspaceLease:input_type -> seaweedfs.block.control.WorkspaceIdentity
|
||||
1, // 11: seaweedfs.block.control.WorkspaceService.RevokeWorkspace:input_type -> seaweedfs.block.control.WorkspaceIdentity
|
||||
6, // 12: seaweedfs.block.control.WorkspaceService.AckWorkspaceRevoked:input_type -> seaweedfs.block.control.WorkspaceRevocationAck
|
||||
7, // 13: seaweedfs.block.control.WorkspaceService.MoveWorkspace:input_type -> seaweedfs.block.control.WorkspaceMove
|
||||
2, // 14: seaweedfs.block.control.WorkspaceService.QueryWorkspace:input_type -> seaweedfs.block.control.WorkspaceVolume
|
||||
10, // 15: seaweedfs.block.control.WorkspaceService.QueryWorkspaceLostRange:input_type -> seaweedfs.block.control.WorkspaceLostRangeQuery
|
||||
7, // 16: seaweedfs.block.control.WorkspaceService.PreviewWorkspaceMove:input_type -> seaweedfs.block.control.WorkspaceMove
|
||||
14, // 17: seaweedfs.block.control.WorkspaceService.RegisterWorkspaceBinding:output_type -> seaweedfs.block.control.WorkspaceBinding
|
||||
3, // 18: seaweedfs.block.control.WorkspaceService.PlaceWorkspace:output_type -> seaweedfs.block.control.WorkspaceEmpty
|
||||
4, // 19: seaweedfs.block.control.WorkspaceService.RenewWorkspaceLease:output_type -> seaweedfs.block.control.WorkspaceLeaseFact
|
||||
4, // 20: seaweedfs.block.control.WorkspaceService.RevokeWorkspace:output_type -> seaweedfs.block.control.WorkspaceLeaseFact
|
||||
3, // 21: seaweedfs.block.control.WorkspaceService.AckWorkspaceRevoked:output_type -> seaweedfs.block.control.WorkspaceEmpty
|
||||
8, // 22: seaweedfs.block.control.WorkspaceService.MoveWorkspace:output_type -> seaweedfs.block.control.WorkspaceGrant
|
||||
13, // 23: seaweedfs.block.control.WorkspaceService.QueryWorkspace:output_type -> seaweedfs.block.control.WorkspaceStatus
|
||||
11, // 24: seaweedfs.block.control.WorkspaceService.QueryWorkspaceLostRange:output_type -> seaweedfs.block.control.WorkspaceLostRanges
|
||||
12, // 25: seaweedfs.block.control.WorkspaceService.PreviewWorkspaceMove:output_type -> seaweedfs.block.control.WorkspaceMovePreview
|
||||
17, // [17:26] is the sub-list for method output_type
|
||||
8, // [8:17] is the sub-list for method input_type
|
||||
8, // [8:8] is the sub-list for extension type_name
|
||||
8, // [8:8] is the sub-list for extension extendee
|
||||
0, // [0:8] is the sub-list for field type_name
|
||||
1, // 8: seaweedfs.block.control.WorkspaceStatus.current_holder:type_name -> seaweedfs.block.control.WorkspaceIdentity
|
||||
14, // 9: seaweedfs.block.control.WorkspaceService.RegisterWorkspaceBinding:input_type -> seaweedfs.block.control.WorkspaceBinding
|
||||
15, // 10: seaweedfs.block.control.WorkspaceService.PlaceWorkspace:input_type -> seaweedfs.block.control.WorkspacePlacement
|
||||
1, // 11: seaweedfs.block.control.WorkspaceService.RenewWorkspaceLease:input_type -> seaweedfs.block.control.WorkspaceIdentity
|
||||
1, // 12: seaweedfs.block.control.WorkspaceService.RevokeWorkspace:input_type -> seaweedfs.block.control.WorkspaceIdentity
|
||||
6, // 13: seaweedfs.block.control.WorkspaceService.AckWorkspaceRevoked:input_type -> seaweedfs.block.control.WorkspaceRevocationAck
|
||||
7, // 14: seaweedfs.block.control.WorkspaceService.MoveWorkspace:input_type -> seaweedfs.block.control.WorkspaceMove
|
||||
2, // 15: seaweedfs.block.control.WorkspaceService.QueryWorkspace:input_type -> seaweedfs.block.control.WorkspaceVolume
|
||||
10, // 16: seaweedfs.block.control.WorkspaceService.QueryWorkspaceLostRange:input_type -> seaweedfs.block.control.WorkspaceLostRangeQuery
|
||||
7, // 17: seaweedfs.block.control.WorkspaceService.PreviewWorkspaceMove:input_type -> seaweedfs.block.control.WorkspaceMove
|
||||
14, // 18: seaweedfs.block.control.WorkspaceService.RegisterWorkspaceBinding:output_type -> seaweedfs.block.control.WorkspaceBinding
|
||||
3, // 19: seaweedfs.block.control.WorkspaceService.PlaceWorkspace:output_type -> seaweedfs.block.control.WorkspaceEmpty
|
||||
4, // 20: seaweedfs.block.control.WorkspaceService.RenewWorkspaceLease:output_type -> seaweedfs.block.control.WorkspaceLeaseFact
|
||||
4, // 21: seaweedfs.block.control.WorkspaceService.RevokeWorkspace:output_type -> seaweedfs.block.control.WorkspaceLeaseFact
|
||||
3, // 22: seaweedfs.block.control.WorkspaceService.AckWorkspaceRevoked:output_type -> seaweedfs.block.control.WorkspaceEmpty
|
||||
8, // 23: seaweedfs.block.control.WorkspaceService.MoveWorkspace:output_type -> seaweedfs.block.control.WorkspaceGrant
|
||||
13, // 24: seaweedfs.block.control.WorkspaceService.QueryWorkspace:output_type -> seaweedfs.block.control.WorkspaceStatus
|
||||
11, // 25: seaweedfs.block.control.WorkspaceService.QueryWorkspaceLostRange:output_type -> seaweedfs.block.control.WorkspaceLostRanges
|
||||
12, // 26: seaweedfs.block.control.WorkspaceService.PreviewWorkspaceMove:output_type -> seaweedfs.block.control.WorkspaceMovePreview
|
||||
18, // [18:27] is the sub-list for method output_type
|
||||
9, // [9:18] is the sub-list for method input_type
|
||||
9, // [9:9] is the sub-list for extension type_name
|
||||
9, // [9:9] is the sub-list for extension extendee
|
||||
0, // [0:9] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_workspace_proto_init() }
|
||||
|
||||
@@ -97,6 +97,15 @@ message WorkspaceStatus {
|
||||
WorkspaceLeaseFact lease = 1; WorkspaceRevocationAck revocation_ack = 2;
|
||||
repeated WorkspaceGrant moves = 3;
|
||||
repeated WorkspaceBinding bindings = 4;
|
||||
// Read-only owner of the current authority line, resolved from its issued
|
||||
// move or committed placement. A prepared binding never selects this owner.
|
||||
// Absent when the master cannot prove the current holder.
|
||||
WorkspaceIdentity current_holder = 5;
|
||||
// Positive first-launch proof: no published line or workspace history.
|
||||
// Missing on older masters, which cannot prove this exception.
|
||||
bool never_published = 6;
|
||||
// Owner proof is unavailable; lease/move/ACK/binding facts remain readable.
|
||||
bool owner_unreadable = 7;
|
||||
}
|
||||
message WorkspaceBinding {
|
||||
string volume_id = 1; string server_id = 2;
|
||||
|
||||
@@ -1047,12 +1047,12 @@ Notes:
|
||||
| `INV-WS-REVOKE-ACK-001` | A host acknowledges a revocation only after its frontend and cuts have stopped; a cancelled or expired drain sends no acknowledgement. | M4 lease guard: Revoking → Acked | `core/host/volume/workspace_lease.go` `drain` | `TestWorkspaceRevocationAckOnlyAfterFrontendAndCutsStop` (`core/host/volume/workspace_lease_test.go`); `TestWorkspaceHostCancelOrExpiryDuringRevokeDrainNeverACKs` (`core/host/volume/workspace_runtime_test.go`); `TestWorkspaceRevocationAckOutlastsTheMastersBoundedSteps`, `TestWorkspaceRevocationAckIsCutAtTheLeaseDeadline` (`core/host/volume/workspace_ack_budget_test.go`); `TestWorkspaceRevocationAckIsAskedAgainAfterALostAnswer`, `TestWorkspaceCloseoutFitsTheUnitsStopBudget` (`cmd/blockvolume/process_exit_ack_retry_test.go`) | `WorkspaceTakeover` `CleanNoLoss` | ACTIVE |
|
||||
| `INV-WS-REVOKE-ACK-RETRY-001` | A holder's revocation ACK is asked again only after a call that got no answer (`DeadlineExceeded`, `Unavailable`), within its lease deadline and the units' stop budget (19 s closeout); the master answers a repeat of a recorded ACK as recorded while the line is revoking. | M4 lease guard: Revoking → Acked; M2 Revoking → Revoked | `core/host/volume/workspace_lease.go` `drain`, `retryableAckError`; `cmd/blockvolume/process_exit.go` `workspaceLeaseCloseoutTimeout`; `core/authority/workspace.go` `AckWorkspaceRevocation` (a repeat returns nil) | `TestWorkspaceRevocationAckIsAskedAgainAfterALostAnswer`, `TestWorkspaceCloseoutFitsTheUnitsStopBudget` (`cmd/blockvolume/process_exit_ack_retry_test.go`); `TestWorkspaceRevocationAckIsCutAtTheLeaseDeadline` (`core/host/volume/workspace_ack_budget_test.go`); `TestWorkspaceRevocationAckRetryAgainstTheRealMaster` (`core/host/master/workspace_ack_retry_test.go`) | — | ACTIVE |
|
||||
| `INV-WS-STOP-PENDING-001` | From when the detach hook of a chunk detach runs until the lease guard fences, or until that detach's resume clears stop-pending, each sleep of the guard after a completed renewal is at most 250 ms on the local monotonic clock. | M4 lease guard: Valid → StopPending → Valid \| Fenced | `core/host/volume/workspace_lease.go` `StopPending`, `ClearStopPending`, `renewDelay`, `Run`; `core/host/volume/workspace_runtime.go` `WorkspaceStopPending`, `WorkspaceStopResumed`; `core/frontend/durable/provider_chunk.go` `DetachVolume`, `detachVolume`, `resumeAfterDetach`; `cmd/blockvolume/main.go` `run` (wiring) | `TestWorkspaceLeaseStopPendingSchedule`, `TestWorkspaceHostStopResumedClearsOnlyTheLatestAttempt`, `TestWorkspaceHostFailedDetachStopPendingByOutcome`, `TestWorkspaceHostDetachHookFencesWithinPoll`, `TestWorkspaceLeaseStopPendingNeverBlocks` (`core/host/volume/workspace_lease_stop_pending_test.go`); `TestWALStoreChunk_DetachHookPrecedesDrain`, `TestWALStoreChunk_DetachResumeHookOnlyOnProvenAbort`, `TestWALStoreChunk_DetachCallsStopHook` (`core/frontend/durable/provider_chunk_detach_hook_test.go`) | — | ACTIVE |
|
||||
| `INV-WS-BINDING-RECONCILE-001` | After an interruption before or after any binding Retire, startup replay converges to the retirements required by the issued move and ACK history. | M2 restart recovery (existing move/ACK journal replay; no new transition) | `core/host/master/workspace_binding.go` `reconcileWorkspaceBindings`; `Host.New` | `TestWorkspaceBindingReconcileInterruptedAtEveryRetireConverges` (`core/host/master/workspace_binding_reconcile_interrupt_test.go`; supported directory-fsync host required) | - (product restart regression) | ACTIVE |
|
||||
| `INV-WS-BINDING-RECONCILE-001` | After an interruption before or after any binding Retire, startup replay converges to the retirements required by issued cross-host moves; clean-release ACKs retain the same-host restart reservation. | M2 restart recovery (existing move/ACK journal replay; no new transition) | `core/host/master/workspace_binding.go` `reconcileWorkspaceBindings`; `Host.New` | `TestWorkspaceBindingReconcileInterruptedAtEveryRetireConverges` (`core/host/master/workspace_binding_reconcile_interrupt_test.go`; supported directory-fsync host required) | - (product restart regression) | ACTIVE |
|
||||
| `INV-WS-BINDING-AUTHORITY-001` | Replaying binding retirements does not change durable authority history. | M2 restart recovery (existing move/ACK journal replay; no new transition) | `core/host/master/workspace_binding.go` `reconcileWorkspaceBindings` | `TestWorkspaceBindingReconcileInterruptedAtEveryRetireConverges` (`core/host/master/workspace_binding_reconcile_interrupt_test.go`; supported directory-fsync host required) | - (authority history compared across restart) | ACTIVE |
|
||||
| `INV-WS-BINDING-REPLAY-001` | Repeating recorded binding retirements preserves the persisted binding bytes. | M2 restart recovery (existing move/ACK journal replay; no new transition) | `core/lifecycle/workspace_bindings.go` `Retire`, `update` | `TestWorkspaceBindingReconcileInterruptedAtEveryRetireConverges` (`core/host/master/workspace_binding_reconcile_interrupt_test.go`; supported directory-fsync host required) | - (byte-identical replay) | ACTIVE |
|
||||
| `INV-WS-BINDING-WATERMARK-001` | A retirement replay at an already-recorded epoch preserves a re-prepared binding and its watermark. | M2 restart recovery (existing move/ACK journal replay; no new transition) | `core/lifecycle/workspace_bindings.go` `Retire`, `Register` | `TestWorkspaceBindingReconcileInterruptedAtEveryRetireConverges` (`core/host/master/workspace_binding_reconcile_interrupt_test.go`; supported directory-fsync host required) | - (post-recovery watermark protection; hidden legacy prefix not directly observed) | ACTIVE |
|
||||
| `INV-WS-BINDING-SAME-HOST-001` | An issued same-host move does not schedule retirement of its own target reservation. | M2 restart recovery (existing move/ACK journal replay; no new transition) | `core/host/master/workspace_binding.go` `reconcileWorkspaceBindings` | `TestWorkspaceBindingReconcileInterruptedAtEveryRetireConverges` (`core/host/master/workspace_binding_reconcile_interrupt_test.go`; supported directory-fsync host required) | - (call-selection coverage; not an active-successor liveness test) | ACTIVE |
|
||||
| `INV-WS-SAME-HOST-CLEAN-MOVE-001` | A same-host move issues a higher epoch: a clean move needs the current holder's sealed HEAD and its recorded epoch/holder/position ACK, and the successor reads that sealed image; a forced move needs the normal lease barrier and a durable lost-range record. | M2 Acked or Expired → Moved; M9 detached → higher-epoch idle | `core/authority/workspace.go` `validateWorkspaceMoveRequest`, `prepareWorkspaceMoveLocked`; `core/host/master/workspace_service.go` `workspaceMoveCheckLocked`; `core/frontend/chunkstore/layout/start.go` `Start`, `core/frontend/chunkstore/layout/claim.go` `Claim` | `TestWorkspaceSameHostForcedMoveRecordsLostRange` (`core/authority/workspace_same_host_forced_test.go`); `TestWorkspaceRPCSameHostForcedRecoveryRecordsLoss` (`core/host/master/workspace_same_host_forced_test.go`); `TestWorkspaceSameHostCleanMoveUsesOvernightSeal` (`core/authority/workspace_same_host_clean_test.go`); `TestWorkspaceRPCSameHostCleanMoveKeepsRepreparedBinding` (`core/host/master/workspace_same_host_clean_test.go`); `TestLayoutSameHostCleanSuccessorReadsSealedImage` (`core/frontend/durable/provider_layout_same_host_clean_test.go`) | `WorkspaceRegrant` `SameHostLoadsSealed`; `INV-SNAPK-DETACHED-001`. The B provider test performs a real plain detach, same-host higher-epoch fresh-root Start, and reads the sealed bytes. | ACTIVE |
|
||||
| `INV-WS-SAME-HOST-CLEAN-MOVE-001` | A same-host move issues a higher epoch: a clean move needs the current holder's sealed HEAD and its recorded epoch/holder/position ACK, and the successor reads that sealed image; a forced move needs the normal lease barrier and a durable lost-range record. | M2 Acked or Expired → Moved; M9 detached → higher-epoch idle | `core/authority/workspace.go` `validateWorkspaceMoveRequest`, `prepareWorkspaceMoveLocked`; `core/host/master/workspace_service.go` `workspaceMoveCheckLocked`; `core/frontend/chunkstore/layout/start.go` `Start`, `core/frontend/chunkstore/layout/claim.go` `Claim`; `cmd/sw-block/volume_start_release.go` `prepareVolumeStart`, `startLineOwner` | `TestWorkspaceSameHostForcedMoveRecordsLostRange` (`core/authority/workspace_same_host_forced_test.go`); `TestWorkspaceRPCSameHostForcedRecoveryRecordsLoss` (`core/host/master/workspace_same_host_forced_test.go`); `TestWorkspaceSameHostCleanMoveUsesOvernightSeal` (`core/authority/workspace_same_host_clean_test.go`); `TestWorkspaceRPCSameHostCleanMoveKeepsTheReleasedBinding` (`core/host/master/workspace_same_host_clean_test.go`); `TestLayoutSameHostCleanSuccessorReadsSealedImage` (`core/frontend/durable/provider_layout_same_host_clean_test.go`); `TestVolumeStopThenStartMovesBeforeEnablingTheUnit`, `TestVolumeStartLostMoveAnswerUsesTheVisibleGrant`, `TestVolumeStartRevokedWithoutReleaseRefusesBeforeTheUnit` (`cmd/sw-block/volume_start_release_test.go`); `TestVolumeStartReleaseAgainstRealMaster` (`cmd/sw-block/volume_start_release_master_linux_test.go`); `TestVolumeStartWithOperatorMutualTLS` (`cmd/sw-block/volume_start_operator_linux_test.go`); `TestVolumeStartNeverRegistersBindings`, `TestVolumeStartMovedAwayNeverPrintsAForceCommand` (`cmd/sw-block/volume_start_release_test.go`); `TestVolumeStartPreparedTargetNeverBecomesTheLineOwner` (`cmd/sw-block/volume_start_owner_history_linux_test.go`); `TestVolumeStartFreshSpecBeforeAnyPublishedLine` (`cmd/sw-block/volume_start_owner_history_linux_test.go`); `TestVolumeStartNewFreshAndOlderMasterUseTheirOwnPaths`, `TestVolumeStartNeverPublishedCannotOverrideAuthorityHistory` (`cmd/sw-block/volume_start_release_test.go`); `TestVolumeStopWithoutBindingKeepsTheLegacyMode` (`cmd/sw-block/volume_release_test.go`) | `WorkspaceRegrant` `SameHostLoadsSealed`; `INV-SNAPK-DETACHED-001`. The B provider test performs a real plain detach, same-host higher-epoch fresh-root Start, and reads the sealed bytes. | ACTIVE |
|
||||
| `INV-WS-DELETE-NO-LIVE-HOLDER-001` | A workspace volume is marked deleting only with no live holder (`TERM-LIVE-HOLDER-001`): no line, a clean revocation ACK for the line, or HEAD below the line's epoch. A sealed HEAD without an ACK, a live or unreadable one is refused; the HEAD compare-and-swap to deleting fences a later claim. | M2 none/Granted/Revoking/Expired → Deleting | `core/authority/workspace_holder_state.go` `WorkspaceHolderState`; `core/authority/workspace.go` `RecordWorkspaceDeletion`; `core/host/master/services.go` `MarkVolumeDeleting`, `deleteHolderEvidence` | `TestWorkspaceHolderState` (`core/authority/workspace_holder_state_test.go`); `TestDeleteAdmitsANeverStartedLine` (`core/host/master/workspace_delete_never_started_test.go`); `TestDeleteAdmissionVerdicts` (`core/authority/workspace_delete_admission_test.go`); `TestMarkVolumeDeleting_RefusedWhileAssigned` (`core/host/master/volume_deleting_test.go`) | NeverStarted r2 `DeleteNeverStrandsALiveHolder`, `NoServedWriteLost`, re-run can finish, re-run can settle (exhaustive, 21 of 21 configurations as expected). Not modelled: two delete processes at the same instant; the gap between HEAD deleted and the volume marked deleted. Limit (v1): a never-started line that holds a lease is deleted once its lease horizon passed (about 60 s; the reservation refuses a live lease before it); the immediate exit is 1.0.1 | ACTIVE |
|
||||
| `INV-WS-CLEAN-MOVE-001` | A clean move is granted only with a detached HEAD from the expected holder and a revocation ACK matching its epoch, holder and published position; generation is readout only. | M2 lease: Acked → Moved | `core/authority/workspace.go` `prepareWorkspaceMoveLocked`, `AckWorkspaceRevocation`; `core/host/master/workspace_layout_head.go` `NewLayoutWorkspaceHEADReader` | `TestWorkspaceCleanMoveNeedsDetachedHEADAndRevocationAck` (`core/authority/workspace_test.go`); `TestWorkspaceLayoutHEADUsesTheMasterIdentity`, `TestWorkspaceLayoutHEADRefusalsAndStates`, `TestWorkspaceLayoutHEADReaderWiring`; also in `core/host/master/workspace_layout_head_test.go`, `cmd/blockmaster/workspace_layout_head_test.go` | `WorkspaceTakeover` `CleanNoLoss` | ACTIVE |
|
||||
| `INV-WS-FORCED-MOVE-001` | A forced move is admitted only after the granted or restart deadline plus the clock-skew bound has passed for the lease the last move issue started (never a predecessor's; `INV-WS-RESTART-GRACE-001`): see M2 Expired → Moved (forced). | M2 lease: Expired → Moved (forced) | `core/authority/workspace.go` `prepareWorkspaceMoveLocked`, `WorkspaceForcedMoveAdmitted`, `forcedMoveAdmissionLocked`, `forcedMoveBarrierLocked`, `workspaceHeadAdmits`; `core/host/master/workspace_service.go` `MoveWorkspace`, `workspaceMoveCheckLocked` | `TestWorkspaceSkewSeparatesOldServingFromForcedGrant` (`core/host/master/workspace_skew_test.go`); `TestWorkspaceClockSkewPersistsAndProtectsRestart` (`core/authority/workspace_skew_test.go`); `TestWorkspaceForcedMoveRequiresExplicitForceAndLeaseExpiry` (`core/authority/workspace_test.go`); `TestForcedAdmissionIgnoresAPersistedHorizon` (`core/authority/workspace_restart_grace_test.go`); `TestWorkspaceRenewalRPCDuringHeldSameVolumeReservation` (`core/host/master/workspace_lease_horizon_test.go`); `TestWorkspaceUnclaimedGrantForcedReassignAfterExpiry`, `TestWorkspaceUnclaimedGrantHEADRule`, `TestWorkspaceLateClaimThenUnclaimedGrantForcedReassign` (`core/authority/workspace_unclaimed_grant_test.go`); `TestWorkspaceForcedMoveAdmittedMatchesMoveAdmission` (`core/authority/workspace_forced_admission_test.go`); `TestWorkspaceUnclaimedGrantForcedReassignOverRPC` (`core/host/master/workspace_unclaimed_grant_test.go`); `TestWorkspacePausedGranteeRefusedAtAttach` (`core/host/master/workspace_paused_grantee_test.go`); `TestProcedureMasterUnreachableFencesBeforeForcedMove` (`cmd/blockvolume/master_loss_integration_test.go`, tags `subprocess chunkstore_integration`) | — | ACTIVE |
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
# Volume START ownership observation
|
||||
|
||||
Bindings reserve prepared targets. Registration does not change the current authority line or committed placement, so a unique binding is not ownership evidence.
|
||||
|
||||
QueryWorkspace's block-internal `current_holder` field carries a WorkspaceIdentity (volume, replica, epoch and server). The master populates this read-only fact from its current published authority line and existing `workspaceLineOwner` resolver, which uses an issued owner or committed placement/topology. It never selects an owner from prepared bindings. The RPC keeps its existing caller roles and adds no authorization path or stored state.
|
||||
|
||||
Before a line exists, a positive `never_published` reply (no line, lease, ACK or move history) permits the holder's first launch. A master from the previous version omits all three observation markers; its successful replies select legacy start/stop without a new revoke. Bindings do not supply ownership proof.
|
||||
|
||||
For an existing line, START requires `current_holder` and consistency with the current lease/move facts. A modern master with an unreadable owner returns positive `owner_unreadable` together with its full lease, ACK, move and binding facts. Unreadable owners or inconsistent facts cause typed `volume_start_owner_unknown`. START does not fall back to move/ACK/binding inference and does not fill in a forced-move command. The refusal states that an operator who independently knows the host must select any forced move's `--target-host`; it cannot choose that target.
|
||||
|
||||
The authoritative observation also covers a line at its first grant with no move or ACK. It preserves ordinary unrevoked first start and unbound legacy stop/start: no binding means cut and unit stop without revoke, then existing-line start after checking the master-reported owner. A prepared-only B cannot become owner of A's legacy line.
|
||||
|
||||
Projection: `StopAndRestart.ReadClean`, `MoveAdmission.ReadForMove`. Controls cover a real legacy placement A with only a prepared target B, both before and after revocation; ordinary unbound stop/start; and an older reply with move/ACK facts but none of the three observation markers, using the legacy path with no new move or revoke.
|
||||
|
||||
The current-holder observation supplies first-grant ownership directly. Any later protocol relocation must preserve the same authoritative predicate and missing-field refusal.
|
||||
|
||||
A new master marks a successful query with `current_holder`, `never_published`, or `owner_unreadable`. Only absence of all three selects the older protocol. The unreadable marker refuses automatic start/release without hiding facts used by repair and read-only commands. Forced-move admission is unchanged; a missing source can still refuse the move. Stop disables the systemd unit even when already inactive; start enables it. A stopped volume stays stopped across reboot.
|
||||
@@ -348,8 +348,9 @@ first`). Otherwise it:
|
||||
2. stops the unit;
|
||||
3. ends with `recovery point in the object store: the cut at <time>` (exit 0).
|
||||
|
||||
The unit stays enabled and starts again at boot. To start it now, run `sudo /usr/local/bin/sw-block volume start v1 ...`
|
||||
with the same flags.
|
||||
A stop prints its mode. With this host's live binding, it performs a clean release and retains that binding; `sudo /usr/local/bin/sw-block volume start v1 ...` with the same flags obtains epoch+1 through a same-host clean move before enabling the unit. No admin preparation is needed between stop and start. A direct unit restart cannot reuse the released old epoch (exit 79). A lost-answer rerun uses the master's visible grant without resending the move. Without a binding for this host, stop uses the v1.1.0 path (cut, unit stop, no revoke), and start uses the existing line after checking the master-reported owner. START reads the master's current-holder fact, never infers ownership from prepared bindings. An unknown/inconsistent owner or a volume served elsewhere is refused without force advice. A revoked bound line without its recorded ACK is refused with exit 2; only a proven local owner gets an explicit force-move command and the warning that it may lose writes after the last published HEAD. Start never forces automatically. During a CLI-first upgrade, a successful reply from the preceding master version omits the current-holder, never-published and owner-unreadable markers. Start and stop use the legacy path then: cut and unit stop without a new revoke, and start on the existing authority path. A new master sets owner-unreadable when it cannot prove the current owner; automatic start/release refuse, while repair and read-only queries keep the full status. An operator who independently knows the correct host must select any forced move's `--target-host`; START does not select it. See [ownership observation](design/volume-start-ownership.md).
|
||||
|
||||
A successful `volume stop` disables the unit so it stays stopped across reboot. `volume start` enables it again. If disabling fails after the unit stops, stop returns an error and asks for a rerun.
|
||||
|
||||
Running the stop again on a stopped volume answers `not running (inactive): nothing to cut or stop` (exit 0). When
|
||||
you know no guest uses the volume (for example, a killed VM), add `--force`.
|
||||
@@ -748,8 +749,9 @@ says otherwise.
|
||||
request id until it answers. The answer settles what happened. This can take several minutes.
|
||||
- **`ops chunk cut`** has no request id. Repeat the cut: a later cut gives a later durable point. It does not tell you
|
||||
whether the earlier cut committed; for that, check the volume's snapshots and its last cut in status.
|
||||
- **`volume stop`**: run the same `sudo /usr/local/bin/sw-block volume stop <volume>` again. The unit keeps running
|
||||
until a stop succeeds.
|
||||
- **`volume stop`**: run the same `sudo /usr/local/bin/sw-block volume stop <volume>` again. Before its cut succeeds
|
||||
the unit keeps running. A stop that printed `not released` or `release not confirmed` has stopped the unit; running it again reads
|
||||
blockmaster's lease record and gives the final answer (released, moved, or the lease ended without a release).
|
||||
|
||||
Exit codes differ per command, and each command's `--help` states them. Most commands use:
|
||||
|
||||
@@ -806,7 +808,7 @@ already running before this manual (skip step 3's SeaweedFS lines then; that Sea
|
||||
names and run it again; do not go on. `disable` alone does not stop a running holder.
|
||||
|
||||
```sh
|
||||
sudo /usr/local/bin/sw-block volume stop v1 && sudo systemctl disable sw-blockvolume@v1
|
||||
sudo /usr/local/bin/sw-block volume stop v1
|
||||
# iSCSI guests: sudo iscsiadm -m node -T iqn.2026-12.io.seaweedfs:v1 -o delete
|
||||
```
|
||||
|
||||
|
||||
@@ -513,6 +513,7 @@ mini uses the commands of the sections below; the steps there remain the way to
|
||||
- It starts an **existing volume**: one already in blockmaster's cluster spec. Creating a volume from this command comes later; until then, for a new volume add it to the cluster spec and restart blockmaster (see "Required setup" above), then run `volume start`.
|
||||
- It writes `/etc/sw-block/volumes/<volume>.env` (the keys of `deploy/config/blockvolume.env`), resolves the volume's layout id at `--master` (with `--chunk-filer`: walstore-chunk), runs `systemctl enable --now`, waits until `/status` reports the volume Healthy (`--wait`, default 2m), and prints the connect command.
|
||||
- The unit's volume id is its instance name; the local data goes to `/var/lib/sw-block-volume/<volume>` unless `--durable-root` says otherwise.
|
||||
- Before starting a walstore-chunk unit, it reads blockmaster's current-holder fact, resolved from the authority line and committed placement. A successful reply from the preceding master version omits the current-holder, never-published and owner-unreadable markers; start and stop then use the legacy path, with no new revoke or move, preserving CLI-first upgrades. A new master reports an unreadable owner explicitly while preserving the full query status; automatic start/release still refuse. START never guesses ownership from bindings. Bindings reserve targets; they do not prove ownership. An unknown/inconsistent current holder or a volume served elsewhere is refused without force advice. With this host's binding, a clean release (ACK for this server/replica at the current epoch) issues a same-host clean move to epoch+1 using the retained binding, with no admin step. Its request id comes from the volume and released epoch; a lost-answer rerun starts directly once the issued grant is visible. A revoked bound line without that ACK is refused with exit 2, even after expiry; only a proven local owner gets the exact `ops workspace force-move ... --confirm-forced` command and possible-loss warning. Start never forces automatically. Without this host's binding, start follows the existing-line path after checking the master-reported owner, including an unrevoked first-grant line with no move or ACK.
|
||||
- The same command again is safe. Other settings over an existing file are refused unless `--replace`, and `--replace` is refused while the unit runs.
|
||||
- With `--iscsi-listen` on a port other than 3260, label the port for SELinux on each initiator host that logs in (EL9, enforcing): `sudo semanage port -a -t iscsi_port_t -p tcp <port>` (`semanage` is in `policycoreutils-python-utils`). Without it, `iscsiadm` discovery or login fails and the audit log shows an AVC denial for `iscsid` on that port. 3260 is labelled already. Each volume has its own iSCSI port, so label each one.
|
||||
- The unit is ordered after `sw-blockmaster.service` when both run on the host, but does not start it: a master you stopped stays stopped when a volume starts or restarts.
|
||||
@@ -520,7 +521,8 @@ mini uses the commands of the sections below; the steps there remain the way to
|
||||
**`sudo sw-block volume stop <volume> [--force] [--no-cut] [--timeout 2m]`**
|
||||
1. **Guests.** It refuses while a guest is connected (`/status/guests`: NVMe/TCP hosts and iSCSI sessions), unless `--force`. This protects a connected guest from I/O errors; it is not a completeness guarantee. A host that vanished (a killed VM, a partitioned host) still counts until its TCP connection closes: when you know nothing uses the volume, `--force` stops it. ublk and NVMe/RDMA guests are not counted.
|
||||
2. **Cut.** It takes a cut (walstore-chunk). When the cut fails or its outcome is unknown, it refuses and stops nothing: the local data is safe on this host, and the message gives the age of the object store's recovery point (from the holder's last cut; "age unknown (since restart)" after a restart). A cut that timed out keeps what it uploaded, so running the same command again continues from it. `--no-cut` stops without a cut. The time in the closing line is taken before the cut's request, so the cut covers every write before it.
|
||||
3. **Unit.** It runs `systemctl stop`. Only an `inactive` or `failed` unit is "nothing to stop". A unit in a transitional state (`activating`, `deactivating`, `reloading`) may still have a live holder, so the guest read and the cut stay; if the holder is down they refuse, and `--force --no-cut` stops the unit. The unit stays enabled, so it starts again at boot; `volume start` with the same flags starts it now.
|
||||
3. **Release mode.** It reads the master's bindings and prints the selected mode. If this host has no live binding for the volume, it uses the v1.1.0 path: cut, unit stop, no revoke. With this host's binding, it revokes the running holder's own epoch and waits, bounded by one lease, for the recorded clean release. The ACK retains the binding for the next same-host epoch+1 start; no admin preparation is needed. Only the recorded ACK reads `released`, never the unit's exit status. A moved volume prints `not released`; an unreadable record/status, refused or unanswered revoke, or missing ACK prints `release not confirmed`; either way the unit stops and exits 1. A stopped unit's rerun only reads the record. A revoked bound line without an ACK is refused by start; unknown or elsewhere ownership never receives force advice.
|
||||
4. **Unit.** It runs `systemctl stop`. Only an `inactive` or `failed` unit is "nothing to stop". A unit in a transitional state (`activating`, `deactivating`, `reloading`) may still have a live holder, so the guest read and the cut stay; if the holder is down they refuse, and `--force --no-cut` stops the unit. It then disables the unit, including an already inactive unit, so stop persists across reboot. A direct restart of a cleanly released epoch is refused by the holder (exit 79). Use `volume start` with the same flags to obtain the clean epoch+1 grant before starting it again.
|
||||
|
||||
Its output ends with what it promises, and only that:
|
||||
|
||||
@@ -705,7 +707,7 @@ and symptoms: [volume lifecycle](volume-lifecycle.md).
|
||||
|
||||
For an RF1 chunk volume with a workspace lease, inspect the current logical
|
||||
holder with `sw-block ops workspace show --master MASTER --volume V`. Copy the
|
||||
replica and epoch exactly. The view prints the master's lease state, recorded
|
||||
replica and epoch exactly. The view prints the master's current-holder fact, lease state, recorded
|
||||
revocation ACK (including its HEAD generation), move records and bindings. It
|
||||
does not infer a physical holder from the binding list; a binding is not proof
|
||||
of a current assignment. Reported validity is a snapshot, not permission to
|
||||
|
||||
@@ -99,7 +99,11 @@ cmd/sw-block/volume_backup.go observeSnapshotOperation time.After 1 control-time
|
||||
cmd/sw-block/volume_backup.go volumeRestore context.WithTimeout 1 ruled-total RestoreCommand.Abort; RestoreCommand.AbortVerify; RestoreCommand.Run; RestoreCommand.Start docs/releases/v1.1.md: "it took 0.42 s at the 1 TiB cap"
|
||||
cmd/sw-block/volume_backup.go volumeRestoreAbort context.WithTimeout 1 per-call RestoreCommand.Abort; RestoreCommand.AbortVerify; RestoreCommand.Run; RestoreCommand.Start one CLI request (operator --timeout)
|
||||
cmd/sw-block/volume_create.go runOpsVolumeCreate context.WithTimeout 1 per-call NONE: no model row maps this file yet one CLI request (operator --timeout)
|
||||
cmd/sw-block/volume_release.go releaseLease context.WithTimeout 1 per-call NONE: no model row maps this file yet the release's holder status read, lease record read and revoke before its wait (setup bound, 10 s)
|
||||
cmd/sw-block/volume_release.go releaseLease context.WithTimeout 2 availability-contract NONE: no model row maps this file yet the wait for the recorded release: one lease validity plus slack, since the holder acknowledges at its next renewal within the lease
|
||||
cmd/sw-block/volume_release.go releaseLease time.After 1 control-timer NONE: no model row maps this file yet lease record poll during the release wait
|
||||
cmd/sw-block/volume_resolve.go runOpsVolume context.WithTimeout 1 per-call NONE: no model row maps this file yet one CLI request (operator --timeout)
|
||||
cmd/sw-block/volume_start_release.go prepareVolumeStart context.WithTimeout 1 availability-contract StopAndRestart.IssueClean; StopAndRestart.ReadClean; StopAndRestart.SameEpochReopen lease-query/clean-move setup (10 s), before enabling the unit; no volume data is processed
|
||||
cmd/sw-block/volume_verbs.go runVolume http.Client.Timeout 1 per-call CutTime.Poll one HTTP request
|
||||
cmd/sw-block/volume_verbs.go volumeStart time.Now().Add 1 per-call CutTime.Poll volume start: the operator's --wait for it to serve
|
||||
cmd/sw-block/volume_verbs.go volumeStart time.After 1 control-timer CutTime.Poll volume start poll
|
||||
@@ -109,7 +113,7 @@ cmd/sw-block/workspace.go runWorkspaceForceMove context.WithTimeout 1 per-call N
|
||||
cmd/sw-block/workspace.go runWorkspaceLostRange context.WithTimeout 1 per-call NONE: no model row maps this file yet one CLI request (operator --timeout)
|
||||
cmd/sw-block/workspace_clean.go runWorkspaceCleanMove context.WithTimeout 1 per-call NONE: no model row maps this file yet one CLI request (operator --timeout)
|
||||
cmd/sw-block/workspace_revoke.go runWorkspaceRevoke context.WithTimeout 1 per-call NONE: no model row maps this file yet one CLI request (operator --timeout)
|
||||
cmd/sw-block/workspace_show.go runWorkspaceShow context.WithTimeout 1 per-call NONE: no model row maps this file yet one CLI request (operator --timeout)
|
||||
cmd/sw-block/workspace_show.go runWorkspaceShow context.WithTimeout 1 per-call MoveAdmission.ReadForMove one CLI request (operator --timeout)
|
||||
core/adapter/adapter.go VolumeReplicaAdapter.armFenceWatchdog time.AfterFunc 1 availability-contract NONE: no model row maps this file yet fence watchdog: a fence that never answers fails typed
|
||||
core/adapter/adapter.go VolumeReplicaAdapter.armStartWatchdog time.AfterFunc 1 availability-contract NONE: no model row maps this file yet start watchdog: a start that never answers fails typed
|
||||
core/auth/audit.go AuditLog.attempt time.NewTimer 1 per-call NONE: no model row maps this file yet one audit record write
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 49 and column 123.
|
@@ -14,7 +14,8 @@ begins with the same one-sentence cure the command prints, then says what you se
|
||||
for example `-server-id s1 -status-addr 127.0.0.1:9203 -status-addr 127.0.0.1:9213`. A volume whose holder's
|
||||
status address is not given prints `not checked here: no given -status-addr serves <volume>`, never `FAIL`.
|
||||
- A volume whose lease was released (revoked, and the holder's acknowledgement recorded) prints `stopped` in every
|
||||
volume check, never `FAIL`, and does not count against the cluster status. A lease that ran out or was taken by a
|
||||
volume check, never `FAIL`, and does not count against the cluster status. `sw-block volume stop` of a
|
||||
walstore-chunk volume releases its lease this way and prints `released`. A lease that ran out or was taken by a
|
||||
forced move is not a release: its checks still fail.
|
||||
|
||||
This page and the command come from one list; a test keeps them equal.
|
||||
|
||||
Reference in new issue
Block a user