mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 10:37:23 +01:00
workspace: fold codex01 review of #320
- S1: a failure after a forced move is issued (binding reconciliation, or a publisher error with the move already issued) is answered as Internal naming the move ISSUED, never FailedPrecondition; the client reports it as unknown with the same-request-id recovery; the issued forced grant is logged before anything after the issue can fail. - S2: the client binds the grant to the request (request, volume, expected holder and epoch, target replica and host, higher epoch) and the range to the grant (volume, request, epochs, old replica, HEAD gen, frontier); lost-range answers must name the asked volume/request. - S3: the exit-4 recovery command carries --master, shell-quoted. - S4: HEAD time labelled "(publishing host clock as recorded in the filer, 1 s resolution)". - T1: master test registers cleanup as soon as the master starts. - Ledger: INV-WS-LOST-RANGE-READOUT-001 statement and tests, M2 issue row. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c1af931b45
commit
a879fff64b
9 files changed
+394
-48
No files matched your search
@@ -5,6 +5,7 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
control "github.com/seaweedfs/seaweed-block/core/rpc/control"
|
||||
@@ -144,7 +145,8 @@ func runWorkspaceForceMove(args []string, stdout, stderr io.Writer) int {
|
||||
printForcedGrant(stdout, g)
|
||||
}
|
||||
fmt.Fprintf(stderr, "%s: %v\n", workspaceForceMoveName, err)
|
||||
fmt.Fprintf(stderr, "%s: the move IS issued; do not assume no loss. Check `sw-block ops workspace lost-range --volume %s --request-id %s` and the master's load errors.\n", workspaceForceMoveName, m.VolumeID, m.RequestID)
|
||||
fmt.Fprintf(stderr, "%s: the move IS issued; do not assume no loss. Check the master's load errors, and read the range with:\n", workspaceForceMoveName)
|
||||
fmt.Fprintf(stderr, "%s%s\n", workspaceRecoveryPrefix, shellCommand("sw-block", "ops", "workspace", "lost-range", "--master", master, "--volume", m.VolumeID, "--request-id", m.RequestID))
|
||||
return wsExitReadoutUnproven
|
||||
case wsclient.OutcomeRefused:
|
||||
fmt.Fprintf(stderr, "%s: refused by the master (nothing moved): %v\n", workspaceForceMoveName, err)
|
||||
@@ -162,6 +164,26 @@ func runWorkspaceForceMove(args []string, stdout, stderr io.Writer) int {
|
||||
}
|
||||
}
|
||||
|
||||
// workspaceRecoveryPrefix starts the line that carries a recovery command.
|
||||
const workspaceRecoveryPrefix = " "
|
||||
|
||||
// shellCommand joins args for a POSIX shell, single-quoting any argument
|
||||
// that is not plainly safe, so a printed command can be pasted as is.
|
||||
func shellCommand(args ...string) string {
|
||||
out := make([]string, len(args))
|
||||
for i, a := range args {
|
||||
out[i] = shellQuote(a)
|
||||
}
|
||||
return strings.Join(out, " ")
|
||||
}
|
||||
|
||||
func shellQuote(a string) string {
|
||||
if a != "" && strings.Trim(a, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@%+=:,./_-") == "" {
|
||||
return a
|
||||
}
|
||||
return "'" + strings.ReplaceAll(a, "'", `'\''`) + "'"
|
||||
}
|
||||
|
||||
func printForcedGrant(w io.Writer, g *control.WorkspaceGrant) {
|
||||
fmt.Fprintf(w, "forced move issued: volume %s request %s: %s@%d on %s -> %s@%d on %s (kept HEAD gen %d, remote LSN %d)\n",
|
||||
g.GetVolumeId(), g.GetRequestId(), g.GetOldReplicaId(), g.GetOldEpoch(), g.GetOldHost(), g.GetNewReplicaId(), g.GetNewEpoch(), g.GetNewHost(), g.GetHeadGen(), g.GetRemoteLsn())
|
||||
@@ -194,7 +216,7 @@ func workspacePreview(ctx context.Context, c *wsclient.Client, m wsclient.Forced
|
||||
if p.GetHeadRead() {
|
||||
at := "unknown"
|
||||
if p.GetHeadTimeKnown() {
|
||||
at = wsclient.FormatTime(p.GetHeadTimeNs()) + ", filer clock"
|
||||
at = wsclient.FormatTime(p.GetHeadTimeNs()) + " " + wsclient.HeadTimeClock
|
||||
}
|
||||
fmt.Fprintf(stdout, "HEAD now: gen %d, epoch %d, holder %s, remote LSN %d, published at %s\n", p.GetHeadGen(), p.GetHeadEpoch(), p.GetHeadHolder(), p.GetHeadRemoteLsn(), at)
|
||||
if p.GetAdmitted() {
|
||||
|
||||
@@ -124,7 +124,7 @@ func TestWorkspaceForceMoveAgainstRealMaster(t *testing.T) {
|
||||
|
||||
code, out, errOut = runCLI(args("--confirm-forced", "vol-f@1"))
|
||||
if code != wsExitOK || !strings.HasPrefix(out, "forced move issued: volume vol-f request force-1: r1@1 on node-a -> r1@2 on node-b (kept HEAD gen 9, remote LSN 42)\n") ||
|
||||
!strings.Contains(out, "volume vol-f restored to the last published image at 2026-11-21T01:02:03Z, filer clock (gen 9, LSN 42): writes with LSN <= 42 are preserved; writes acknowledged by r1@1 after that and before ") {
|
||||
!strings.Contains(out, "volume vol-f restored to the last published image at 2026-11-21T01:02:03Z (publishing host clock as recorded in the filer, 1 s resolution) (gen 9, LSN 42): writes with LSN <= 42 are preserved; writes acknowledged by r1@1 after that and before ") {
|
||||
t.Fatalf("forced move: exit %d stderr %s\n%s", code, errOut, out)
|
||||
}
|
||||
code2, out2, _ := runCLI(args("--confirm-forced", "vol-f@1"))
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/authority"
|
||||
"github.com/seaweedfs/seaweed-block/core/host/master"
|
||||
)
|
||||
|
||||
type lockedLog struct {
|
||||
mu sync.Mutex
|
||||
b bytes.Buffer
|
||||
}
|
||||
|
||||
func (l *lockedLog) Write(p []byte) (int, error) {
|
||||
l.mu.Lock()
|
||||
defer l.mu.Unlock()
|
||||
return l.b.Write(p)
|
||||
}
|
||||
|
||||
func (l *lockedLog) String() string {
|
||||
l.mu.Lock()
|
||||
defer l.mu.Unlock()
|
||||
return l.b.String()
|
||||
}
|
||||
|
||||
// A failure AFTER the forced move is issued (here the binding
|
||||
// reconciliation, made to fail by moving the binding store's directory away)
|
||||
// is reported through the RPC, the client and the CLI as an unknown outcome
|
||||
// with the same-request-id recovery, never as a refusal ("nothing moved")
|
||||
// and never with a fresh request id; the master's audit log records the
|
||||
// issue; a rerun with the same id then returns the stored grant.
|
||||
func TestWorkspaceForceMovePostIssueFailureKeepsTheOutcome(t *testing.T) {
|
||||
logs := &lockedLog{}
|
||||
lifecycleDir := t.TempDir()
|
||||
cfg := master.Config{WorkspaceMaxClockSkew: 100 * time.Millisecond, Listen: "127.0.0.1:0", AuthorityStoreDir: t.TempDir(), LifecycleStoreDir: lifecycleDir, WorkspaceRPC: true,
|
||||
Logger: log.New(logs, "", 0),
|
||||
WorkspaceHeadReader: func(context.Context, string) (authority.WorkspaceHead, error) {
|
||||
return authority.WorkspaceHead{Gen: 9, Epoch: 1, Holder: "node-a/r1", RemoteLSN: 42}, nil
|
||||
}}
|
||||
h, stop := startDeleteMaster(t, cfg)
|
||||
defer stop()
|
||||
seedForcedVolume(t, h)
|
||||
st := h.Publisher().WorkspaceState("vol-f")
|
||||
skew := time.Duration(st.Lease.MaxClockSkewNS)
|
||||
if skew < cfg.WorkspaceMaxClockSkew {
|
||||
skew = cfg.WorkspaceMaxClockSkew
|
||||
}
|
||||
time.Sleep(time.Until(time.Unix(0, st.Lease.ExpiresAtNS).Add(skew)) + 100*time.Millisecond)
|
||||
|
||||
bindings := filepath.Join(lifecycleDir, "workspace-bindings")
|
||||
if err := os.Rename(bindings, bindings+".aside"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
args := []string{"ops", "workspace", "force-move", "--master", h.Addr(), "--volume", "vol-f", "--target-host", "node-b", "--target-data", "127.0.0.1:29200",
|
||||
"--target-ctrl", "127.0.0.1:29100", "--request-id", "force-1", "--confirm-forced", "vol-f@1"}
|
||||
code, out, errOut := runCLI(args)
|
||||
if line, ok := h.Publisher().VolumeAuthorityLine("vol-f"); !ok || line.Epoch != 2 {
|
||||
t.Fatalf("fixture: the forced move was not issued before the failure: %+v", line)
|
||||
}
|
||||
if code != wsExitUnknown || strings.Contains(errOut, "nothing moved") || strings.Contains(out, "nothing moved") ||
|
||||
!strings.Contains(errOut, "rerun with the SAME --request-id force-1") || strings.Contains(strings.ToLower(errOut), "new request id") {
|
||||
t.Fatalf("post-issue failure: exit %d stdout %q stderr %s; want exit 3 with the same-id recovery and no refusal", code, out, errOut)
|
||||
}
|
||||
if !strings.Contains(logs.String(), `forced move issued volume="vol-f" request="force-1"`) {
|
||||
t.Fatalf("issued forced move missing from the audit log:\n%s", logs.String())
|
||||
}
|
||||
if err := os.Rename(bindings+".aside", bindings); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
code, out, errOut = runCLI(args)
|
||||
if code != wsExitOK || !strings.HasPrefix(out, "forced move issued: volume vol-f request force-1: r1@1 on node-a -> r1@2 on node-b") {
|
||||
t.Fatalf("rerun with the same id: exit %d stdout %q stderr %s", code, out, errOut)
|
||||
}
|
||||
}
|
||||
@@ -122,7 +122,7 @@ func wsGrant(q *control.WorkspaceMove) *control.WorkspaceGrant {
|
||||
LostAfterLsn: 42, LostUntilNs: wsLostUntil.UnixNano(), HeadGen: 9, HeadTimeNs: wsHeadTime.UnixNano(), HeadTimeKnown: true}}
|
||||
}
|
||||
|
||||
const wsReadout = "volume vol restored to the last published image at 2026-11-21T01:02:03Z, filer clock (gen 9, LSN 42): writes with LSN <= 42 are preserved; " +
|
||||
const wsReadout = "volume vol restored to the last published image at 2026-11-21T01:02:03Z (publishing host clock as recorded in the filer, 1 s resolution) (gen 9, LSN 42): writes with LSN <= 42 are preserved; " +
|
||||
"writes acknowledged by r1@3 after that and before 2026-11-21T01:05:00Z, master clock, may be lost; the upper bound is a time, not an LSN."
|
||||
|
||||
func forceMoveArgs(addr string, extra ...string) []string {
|
||||
@@ -179,7 +179,7 @@ func TestWorkspaceForceMove_Row2_DryRunPreview(t *testing.T) {
|
||||
HeadRead: true, HeadGen: 9, HeadEpoch: 3, HeadHolder: "node-a/r1", HeadRemoteLsn: 42, HeadTimeNs: wsHeadTime.UnixNano(), HeadTimeKnown: true}
|
||||
code, out, _ = runCLI(forceMoveArgs(addr, "--confirm-forced", "vol@3", "--dry-run"))
|
||||
if code != wsExitOK || f.n("MoveWorkspace") != 0 || strings.Contains(out, "admissible at") ||
|
||||
!strings.Contains(out, "forced move admitted") || !strings.Contains(out, "HEAD now: gen 9, epoch 3, holder node-a/r1, remote LSN 42, published at 2026-11-21T01:02:03Z, filer clock") {
|
||||
!strings.Contains(out, "forced move admitted") || !strings.Contains(out, "HEAD now: gen 9, epoch 3, holder node-a/r1, remote LSN 42, published at 2026-11-21T01:02:03Z (publishing host clock as recorded in the filer, 1 s resolution)") {
|
||||
t.Fatalf("admitted preview: exit %d\n%s", code, out)
|
||||
}
|
||||
}
|
||||
@@ -275,6 +275,112 @@ func TestWorkspaceForceMove_Row7_ReadoutUnproven(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// splitShellWords splits a POSIX shell line of plain words and
|
||||
// single-quoted parts and backslash escapes (the forms shellCommand prints).
|
||||
func splitShellWords(t *testing.T, line string) []string {
|
||||
t.Helper()
|
||||
var words []string
|
||||
var cur strings.Builder
|
||||
in, quoted, inQuote, escaped := false, false, false, false
|
||||
for _, r := range line {
|
||||
switch {
|
||||
case escaped:
|
||||
cur.WriteRune(r)
|
||||
escaped, in = false, true
|
||||
case inQuote && r == '\'':
|
||||
inQuote = false
|
||||
case inQuote:
|
||||
cur.WriteRune(r)
|
||||
case r == '\'':
|
||||
inQuote, in, quoted = true, true, true
|
||||
case r == '\\':
|
||||
escaped = true
|
||||
case r == ' ':
|
||||
if in {
|
||||
words = append(words, cur.String())
|
||||
cur.Reset()
|
||||
in, quoted = false, false
|
||||
}
|
||||
default:
|
||||
cur.WriteRune(r)
|
||||
in = true
|
||||
}
|
||||
}
|
||||
if inQuote {
|
||||
t.Fatalf("unterminated quote in %q", line)
|
||||
}
|
||||
if in || quoted {
|
||||
words = append(words, cur.String())
|
||||
}
|
||||
return words
|
||||
}
|
||||
|
||||
// The exit-4 recovery command carries the master address and survives
|
||||
// arguments that need quoting: the printed words parse back to the same
|
||||
// values and run as a lost-range command against the same master.
|
||||
func TestWorkspaceForceMoveRecoveryCommandRuns(t *testing.T) {
|
||||
const reqID = "req 1'$x"
|
||||
f := &fakeWorkspace{status: wsHolder(), move: func(q *control.WorkspaceMove) (*control.WorkspaceGrant, error) {
|
||||
g := wsGrant(q)
|
||||
g.LostRange, g.LostRangeError = nil, "missing"
|
||||
return g, nil
|
||||
}, ranges: nil}
|
||||
addr, _ := startFakeWorkspace(t, f)
|
||||
args := forceMoveArgs(addr, "--confirm-forced", "vol@3")
|
||||
args[len(args)-3] = reqID // --request-id value
|
||||
code, _, errOut := runCLI(args)
|
||||
if code != wsExitReadoutUnproven {
|
||||
t.Fatalf("exit %d %s", code, errOut)
|
||||
}
|
||||
var line string
|
||||
for _, l := range strings.Split(errOut, "\n") {
|
||||
if strings.HasPrefix(l, workspaceRecoveryPrefix+"sw-block ") {
|
||||
line = strings.TrimPrefix(l, workspaceRecoveryPrefix)
|
||||
}
|
||||
}
|
||||
words := splitShellWords(t, line)
|
||||
want := []string{"sw-block", "ops", "workspace", "lost-range", "--master", addr, "--volume", "vol", "--request-id", reqID}
|
||||
if strings.Join(words, "\x00") != strings.Join(want, "\x00") {
|
||||
t.Fatalf("recovery command %q parses to %q; want %q", line, words, want)
|
||||
}
|
||||
f.ranges = []*control.WorkspaceLostRange{{RequestId: reqID, VolumeId: "vol", NewEpoch: 4, OldReplicaId: "r1", OldEpoch: 3, LostAfterLsn: 42, LostUntilNs: wsLostUntil.UnixNano(), HeadGen: 9}}
|
||||
if code, out, errOut := runCLI(words[1:]); code != wsExitOK || f.lastLR.RequestId != reqID || f.lastLR.VolumeId != "vol" || !strings.Contains(out, "range 1 of 1") {
|
||||
t.Fatalf("recovery command run: exit %d %+v stdout %q stderr %s", code, f.lastLR, out, errOut)
|
||||
}
|
||||
}
|
||||
|
||||
// A successful answer that does not match the request (here the target)
|
||||
// is an unknown outcome, and one whose range disagrees with the kept HEAD
|
||||
// is unproven: neither prints the preservation readout.
|
||||
func TestWorkspaceForceMoveRejectsAMismatchedAnswer(t *testing.T) {
|
||||
for name, tc := range map[string]struct {
|
||||
fault func(*control.WorkspaceGrant)
|
||||
exit int
|
||||
}{
|
||||
"grant target": {func(g *control.WorkspaceGrant) { g.NewHost = "node-c" }, wsExitUnknown},
|
||||
"grant epoch": {func(g *control.WorkspaceGrant) { g.OldEpoch = 2 }, wsExitUnknown},
|
||||
"range volume": {func(g *control.WorkspaceGrant) { g.LostRange.VolumeId = "vol2" }, wsExitReadoutUnproven},
|
||||
"range frontier": {func(g *control.WorkspaceGrant) { g.LostRange.LostAfterLsn = 41 }, wsExitReadoutUnproven},
|
||||
"range head gen": {func(g *control.WorkspaceGrant) { g.LostRange.HeadGen = 8 }, wsExitReadoutUnproven},
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
f := &fakeWorkspace{status: wsHolder(), move: func(q *control.WorkspaceMove) (*control.WorkspaceGrant, error) {
|
||||
g := wsGrant(q)
|
||||
tc.fault(g)
|
||||
return g, nil
|
||||
}}
|
||||
addr, _ := startFakeWorkspace(t, f)
|
||||
code, out, errOut := runCLI(forceMoveArgs(addr, "--confirm-forced", "vol@3"))
|
||||
if code != tc.exit || strings.Contains(out, "restored to") || strings.Contains(out, "next: start") {
|
||||
t.Fatalf("exit %d (want %d) stdout %q stderr %s", code, tc.exit, out, errOut)
|
||||
}
|
||||
if tc.exit == wsExitUnknown && !strings.Contains(errOut, "rerun with the SAME --request-id req-1") {
|
||||
t.Fatalf("no same-id recovery: %s", errOut)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Row Rerun same id -> Granted: the master replays the stored grant, and
|
||||
// the output is the same, from the stored range.
|
||||
func TestWorkspaceForceMove_Row8_RerunSameRequestID(t *testing.T) {
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -39,15 +40,29 @@ func lostRangeFiles(t *testing.T, dir string) []string {
|
||||
return out
|
||||
}
|
||||
|
||||
// forcedMoveHost starts a master whose volume vol-f is held by r1 on node-a
|
||||
// (epoch 1, lease renewed once) with a prepared target binding on node-b.
|
||||
func forcedMoveHost(t *testing.T, cfg Config) (*Host, control.WorkspaceServiceClient, *control.WorkspaceMove) {
|
||||
// startStoppableMaster starts a master and registers its close as cleanup
|
||||
// immediately; the returned stop closes it at most once (an explicit stop
|
||||
// before a restart, then the cleanup, never closes twice).
|
||||
func startStoppableMaster(t *testing.T, cfg Config) (*Host, func()) {
|
||||
t.Helper()
|
||||
h, err := New(cfg)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
h.Start()
|
||||
var once sync.Once
|
||||
stop := func() { once.Do(func() { closeTestMaster(t, h) }) }
|
||||
t.Cleanup(stop)
|
||||
return h, stop
|
||||
}
|
||||
|
||||
// forcedMoveHost starts a master whose volume vol-f is held by r1 on node-a
|
||||
// (epoch 1, lease renewed once) with a prepared target binding on node-b.
|
||||
// The returned stop closes it once; it is also registered as cleanup as soon
|
||||
// as the master starts, so a failing setup step never leaks it.
|
||||
func forcedMoveHost(t *testing.T, cfg Config) (*Host, func(), control.WorkspaceServiceClient, *control.WorkspaceMove) {
|
||||
t.Helper()
|
||||
h, stop := startStoppableMaster(t, cfg)
|
||||
conn, err := grpc.NewClient(h.Addr(), grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -85,7 +100,7 @@ func forcedMoveHost(t *testing.T, cfg Config) (*Host, control.WorkspaceServiceCl
|
||||
if _, err := client.RenewWorkspaceLease(ctx, &control.WorkspaceIdentity{VolumeId: "vol-f", ReplicaId: "r1", Epoch: line.Epoch}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return h, client, &control.WorkspaceMove{RequestId: "force-1", VolumeId: "vol-f", ExpectedReplicaId: "r1", ExpectedEpoch: line.Epoch, TargetReplicaId: "r1",
|
||||
return h, stop, client, &control.WorkspaceMove{RequestId: "force-1", VolumeId: "vol-f", ExpectedReplicaId: "r1", ExpectedEpoch: line.Epoch, TargetReplicaId: "r1",
|
||||
TargetServerId: "node-b", TargetDataAddr: target.DataAddr, TargetCtrlAddr: target.CtrlAddr, Kind: "forced", Force: true}
|
||||
}
|
||||
|
||||
@@ -105,13 +120,7 @@ func TestWorkspaceForcedMoveLostRangeOverRPC(t *testing.T) {
|
||||
WorkspaceHeadReader: func(context.Context, string) (authority.WorkspaceHead, error) {
|
||||
return authority.WorkspaceHead{Gen: 9, Epoch: 1, Holder: "node-a/r1", RemoteLSN: 42, FilerMtimeNS: headTime.UnixNano()}, nil
|
||||
}}
|
||||
h, client, move := forcedMoveHost(t, cfg)
|
||||
closed := false
|
||||
defer func() {
|
||||
if !closed {
|
||||
closeTestMaster(t, h)
|
||||
}
|
||||
}()
|
||||
h, stop, client, move := forcedMoveHost(t, cfg)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 90*time.Second)
|
||||
defer cancel()
|
||||
|
||||
@@ -181,8 +190,7 @@ func TestWorkspaceForcedMoveLostRangeOverRPC(t *testing.T) {
|
||||
t.Fatalf("preview of the issued request: %+v %v", pv3, err)
|
||||
}
|
||||
|
||||
closeTestMaster(t, h)
|
||||
closed = true
|
||||
stop()
|
||||
files := lostRangeFiles(t, authDir)
|
||||
if len(files) != 1 {
|
||||
t.Fatalf("lost range files %v", files)
|
||||
@@ -194,12 +202,7 @@ func TestWorkspaceForcedMoveLostRangeOverRPC(t *testing.T) {
|
||||
if err := os.WriteFile(files[0], []byte(strings.Replace(string(raw), `"LostAfterLSN":42`, `"LostAfterLSN":41`, 1)), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
h2, err := New(cfg)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
h2.Start()
|
||||
defer closeTestMaster(t, h2)
|
||||
h2, _ := startStoppableMaster(t, cfg)
|
||||
conn, err := grpc.NewClient(h2.Addr(), grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -160,7 +160,7 @@ func (s *services) grantWithLostRange(r authority.WorkspaceMoveRecord) *control.
|
||||
}
|
||||
|
||||
// logForcedGrant records an issued forced move (also a replay of one).
|
||||
func (s *services) logForcedGrant(g *control.WorkspaceGrant, replay bool) {
|
||||
func (s *services) logForcedGrant(g *control.WorkspaceGrant, replay bool, postIssue error) {
|
||||
if g == nil || !g.GetIssued() || g.GetKind() != "forced" {
|
||||
return
|
||||
}
|
||||
@@ -173,6 +173,9 @@ func (s *services) logForcedGrant(g *control.WorkspaceGrant, replay bool) {
|
||||
lost = fmt.Sprintf("lost_after_lsn=%d lost_until_ns=%d lost_until=%s head_gen=%d head_filer_time=%s",
|
||||
l.GetLostAfterLsn(), l.GetLostUntilNs(), time.Unix(0, l.GetLostUntilNs()).UTC().Format(time.RFC3339Nano), l.GetHeadGen(), head)
|
||||
}
|
||||
if postIssue != nil {
|
||||
lost += fmt.Sprintf(" answer_failed_after_issue=%q", postIssue.Error())
|
||||
}
|
||||
s.host.log.Printf("blockmaster: MoveWorkspace forced move issued volume=%q request=%q old=%s/%s@%d new=%s/%s@%d replay=%t %s",
|
||||
g.GetVolumeId(), g.GetRequestId(), g.GetOldHost(), g.GetOldReplicaId(), g.GetOldEpoch(), g.GetNewHost(), g.GetNewReplicaId(), g.GetNewEpoch(), replay, lost)
|
||||
}
|
||||
@@ -206,11 +209,12 @@ func (s *services) MoveWorkspace(ctx context.Context, q *control.WorkspaceMove)
|
||||
var refusal string
|
||||
var issued *control.WorkspaceGrant
|
||||
var replay bool
|
||||
var postIssue error
|
||||
defer func() {
|
||||
if refusal != "" {
|
||||
s.host.log.Printf("blockmaster: MoveWorkspace refused volume=%q request=%q: %s", q.GetVolumeId(), q.GetRequestId(), refusal)
|
||||
}
|
||||
s.logForcedGrant(issued, replay)
|
||||
s.logForcedGrant(issued, replay, postIssue)
|
||||
}()
|
||||
s.host.workspaceMu.Lock()
|
||||
defer s.host.workspaceMu.Unlock()
|
||||
@@ -232,15 +236,45 @@ func (s *services) MoveWorkspace(ctx context.Context, q *control.WorkspaceMove)
|
||||
}
|
||||
r, err := s.host.Publisher().MoveWorkspace(ctx, req, head)
|
||||
if err != nil {
|
||||
// A move that is issued in spite of the error (it failed after the
|
||||
// issue) is never a refusal: the caller recovers its grant with the
|
||||
// same request id.
|
||||
if s.host.Publisher().IssuedWorkspaceMove(req) {
|
||||
issued, postIssue = s.issuedRecord(req), err
|
||||
return nil, postIssueError(q, err)
|
||||
}
|
||||
return nil, workspaceError(err)
|
||||
}
|
||||
if err = s.host.reconcileWorkspaceBindings(); err != nil {
|
||||
return nil, workspaceError(err)
|
||||
}
|
||||
// The move is issued from here on: record it for the audit log before
|
||||
// anything else can fail.
|
||||
issued = s.grantWithLostRange(r)
|
||||
if err = s.host.reconcileWorkspaceBindings(); err != nil {
|
||||
postIssue = err
|
||||
return nil, postIssueError(q, err)
|
||||
}
|
||||
return issued, nil
|
||||
}
|
||||
|
||||
// postIssueError reports a failure after q's move was issued: never
|
||||
// FailedPrecondition (a definite refusal); Internal, which clients treat as
|
||||
// an unknown outcome, with the same-request-id recovery.
|
||||
func postIssueError(q *control.WorkspaceMove, err error) error {
|
||||
return status.Errorf(codes.Internal, "workspace move %q of volume %q is ISSUED, but a step after the issue failed: %v; rerun with the same request id to get its grant",
|
||||
q.GetRequestId(), q.GetVolumeId(), err)
|
||||
}
|
||||
|
||||
// issuedRecord is the answer for req's issued journal record, if any.
|
||||
func (s *services) issuedRecord(req authority.WorkspaceMoveRequest) *control.WorkspaceGrant {
|
||||
if st := s.host.Publisher().WorkspaceState(req.VolumeID); st != nil {
|
||||
for _, m := range st.Moves {
|
||||
if m.RequestID == req.RequestID && m.Issued {
|
||||
return s.grantWithLostRange(m)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// workspaceMoveCheckLocked builds the authority request of q and the
|
||||
// blockmaster's own refusal of it ("" when none): endpoints, source host,
|
||||
// target node and binding. It reads and writes nothing else; MoveWorkspace
|
||||
|
||||
@@ -203,8 +203,8 @@ func (c *Client) ForceMove(ctx context.Context, m ForcedMove) (*control.Workspac
|
||||
if err != nil {
|
||||
return nil, classify(op, err)
|
||||
}
|
||||
if !g.GetIssued() || g.GetKind() != "forced" || g.GetRequestId() != m.RequestID || g.GetVolumeId() != m.VolumeID {
|
||||
return g, &Error{Outcome: OutcomeUnknown, Op: op, Err: fmt.Errorf("unexpected grant (issued=%t kind=%q request=%q volume=%q)", g.GetIssued(), g.GetKind(), g.GetRequestId(), g.GetVolumeId())}
|
||||
if err := checkGrant(g, q); err != nil {
|
||||
return g, &Error{Outcome: OutcomeUnknown, Op: op, Err: fmt.Errorf("%v; rerun with the same request id", err)}
|
||||
}
|
||||
if err := checkRange(g.GetLostRange(), g); err != nil {
|
||||
return g, &Error{Outcome: OutcomeReadoutUnproven, Op: op, Err: err}
|
||||
@@ -212,7 +212,22 @@ func (c *Client) ForceMove(ctx context.Context, m ForcedMove) (*control.Workspac
|
||||
return g, nil
|
||||
}
|
||||
|
||||
// checkRange: a forced grant must carry its own stored range.
|
||||
// checkGrant binds a successful answer to the request that was sent: an
|
||||
// issued forced grant for this request id and volume, from the expected
|
||||
// holder at the expected epoch to the requested target, at a higher epoch.
|
||||
// Anything else leaves the outcome unknown.
|
||||
func checkGrant(g *control.WorkspaceGrant, q *control.WorkspaceMove) error {
|
||||
if !g.GetIssued() || g.GetKind() != "forced" || g.GetRequestId() != q.GetRequestId() || g.GetVolumeId() != q.GetVolumeId() ||
|
||||
g.GetOldReplicaId() != q.GetExpectedReplicaId() || g.GetOldEpoch() != q.GetExpectedEpoch() ||
|
||||
g.GetNewReplicaId() != q.GetTargetReplicaId() || g.GetNewHost() != q.GetTargetServerId() || g.GetNewEpoch() <= g.GetOldEpoch() {
|
||||
return fmt.Errorf("the answer does not match the request (issued=%t kind=%q request=%q volume=%q old=%s@%d new=%s@%d on %q)",
|
||||
g.GetIssued(), g.GetKind(), g.GetRequestId(), g.GetVolumeId(), g.GetOldReplicaId(), g.GetOldEpoch(), g.GetNewReplicaId(), g.GetNewEpoch(), g.GetNewHost())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// checkRange: a forced grant must carry its own stored range, naming the
|
||||
// same move and the same kept HEAD (generation and frontier).
|
||||
func checkRange(r *control.WorkspaceLostRange, g *control.WorkspaceGrant) error {
|
||||
if r == nil {
|
||||
why := g.GetLostRangeError()
|
||||
@@ -221,8 +236,11 @@ func checkRange(r *control.WorkspaceLostRange, g *control.WorkspaceGrant) error
|
||||
}
|
||||
return fmt.Errorf("move issued (volume %s epoch %d -> %d) but the lost range is not proven: %s", g.GetVolumeId(), g.GetOldEpoch(), g.GetNewEpoch(), why)
|
||||
}
|
||||
if r.GetRequestId() != g.GetRequestId() || r.GetNewEpoch() != g.GetNewEpoch() || r.GetOldEpoch() != g.GetOldEpoch() || r.GetOldReplicaId() != g.GetOldReplicaId() {
|
||||
return fmt.Errorf("move issued (volume %s epoch %d -> %d) but its lost range names another move (request %q epoch %d)", g.GetVolumeId(), g.GetOldEpoch(), g.GetNewEpoch(), r.GetRequestId(), r.GetNewEpoch())
|
||||
if r.GetRequestId() != g.GetRequestId() || r.GetVolumeId() != g.GetVolumeId() || r.GetNewEpoch() != g.GetNewEpoch() || r.GetOldEpoch() != g.GetOldEpoch() || r.GetOldReplicaId() != g.GetOldReplicaId() {
|
||||
return fmt.Errorf("move issued (volume %s epoch %d -> %d) but its lost range names another move (volume %q request %q epoch %d)", g.GetVolumeId(), g.GetOldEpoch(), g.GetNewEpoch(), r.GetVolumeId(), r.GetRequestId(), r.GetNewEpoch())
|
||||
}
|
||||
if r.GetHeadGen() != g.GetHeadGen() || r.GetLostAfterLsn() != g.GetRemoteLsn() {
|
||||
return fmt.Errorf("move issued (volume %s epoch %d -> %d) but its lost range disagrees with the kept HEAD (range gen %d LSN %d, grant gen %d LSN %d)", g.GetVolumeId(), g.GetOldEpoch(), g.GetNewEpoch(), r.GetHeadGen(), r.GetLostAfterLsn(), g.GetHeadGen(), g.GetRemoteLsn())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -269,9 +287,18 @@ func (c *Client) LostRanges(ctx context.Context, volume, requestID string) ([]*c
|
||||
if err != nil {
|
||||
return nil, classify("lost range", err)
|
||||
}
|
||||
for _, x := range r.GetRanges() {
|
||||
if x.GetVolumeId() != volume || (requestID != "" && x.GetRequestId() != requestID) {
|
||||
return nil, &Error{Outcome: OutcomeReadoutUnproven, Op: "lost range", Err: fmt.Errorf("the answer names another range (volume %q request %q)", x.GetVolumeId(), x.GetRequestId())}
|
||||
}
|
||||
}
|
||||
return r.GetRanges(), nil
|
||||
}
|
||||
|
||||
// HeadTimeClock labels a HEAD time: the filer entry's mtime, which the
|
||||
// host that published the HEAD sets from its own clock.
|
||||
const HeadTimeClock = "(publishing host clock as recorded in the filer, 1 s resolution)"
|
||||
|
||||
// FormatTime prints a master or filer time.
|
||||
func FormatTime(ns int64) string { return time.Unix(0, ns).UTC().Format(time.RFC3339Nano) }
|
||||
|
||||
@@ -283,7 +310,7 @@ func Readout(volume string, r *control.WorkspaceLostRange) string {
|
||||
}
|
||||
at := "an unknown time (no filer time was recorded)"
|
||||
if r.GetHeadTimeKnown() {
|
||||
at = FormatTime(r.GetHeadTimeNs()) + ", filer clock"
|
||||
at = FormatTime(r.GetHeadTimeNs()) + " " + HeadTimeClock
|
||||
}
|
||||
return fmt.Sprintf("volume %s restored to the last published image at %s (gen %d, LSN %d): writes with LSN <= %d are preserved; "+
|
||||
"writes acknowledged by %s after that and before %s, master clock, may be lost; the upper bound is a time, not an LSN.",
|
||||
|
||||
@@ -98,21 +98,92 @@ func TestForceMoveResolvesTheHolder(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// goodGrant is the issued forced grant for testMove with its own range.
|
||||
func goodGrant() *control.WorkspaceGrant {
|
||||
return &control.WorkspaceGrant{RequestId: "req-1", VolumeId: "vol", Kind: "forced", Issued: true, OldReplicaId: "r1", OldEpoch: 3, NewReplicaId: "r1", NewEpoch: 4,
|
||||
OldHost: "node-a", NewHost: "node-b", HeadGen: 9, RemoteLsn: 42,
|
||||
LostRange: &control.WorkspaceLostRange{RequestId: "req-1", VolumeId: "vol", NewEpoch: 4, OldReplicaId: "r1", OldEpoch: 3, LostAfterLsn: 42, LostUntilNs: 1, HeadGen: 9}}
|
||||
}
|
||||
|
||||
func holderAt3() *control.WorkspaceStatus {
|
||||
return &control.WorkspaceStatus{Lease: &control.WorkspaceLeaseFact{ReplicaId: "r1", Epoch: 3}}
|
||||
}
|
||||
|
||||
// A forced grant without its own stored range is issued but unproven.
|
||||
func TestForceMoveGrantWithoutRangeIsUnproven(t *testing.T) {
|
||||
g := &control.WorkspaceGrant{RequestId: "req-1", VolumeId: "vol", Kind: "forced", Issued: true, OldReplicaId: "r1", OldEpoch: 3, NewReplicaId: "r1", NewEpoch: 4}
|
||||
f := &fakeRPC{status: &control.WorkspaceStatus{Lease: &control.WorkspaceLeaseFact{ReplicaId: "r1", Epoch: 3}}, grant: g}
|
||||
got, err := New(f).ForceMove(context.Background(), testMove)
|
||||
g := goodGrant()
|
||||
if _, err := New(&fakeRPC{status: holderAt3(), grant: g}).ForceMove(context.Background(), testMove); err != nil {
|
||||
t.Fatalf("own range: %v", err)
|
||||
}
|
||||
g.LostRange = nil
|
||||
got, err := New(&fakeRPC{status: holderAt3(), grant: g}).ForceMove(context.Background(), testMove)
|
||||
if OutcomeOf(err) != OutcomeReadoutUnproven || got != g {
|
||||
t.Fatalf("no range: %v", err)
|
||||
}
|
||||
g.LostRange = &control.WorkspaceLostRange{RequestId: "other", NewEpoch: 4, OldEpoch: 3, OldReplicaId: "r1"}
|
||||
if _, err := New(f).ForceMove(context.Background(), testMove); OutcomeOf(err) != OutcomeReadoutUnproven {
|
||||
t.Fatalf("another move's range: %v", err)
|
||||
}
|
||||
|
||||
// The answer is bound to the request: each identity field of the grant
|
||||
// corrupted on its own leaves the outcome unknown; each identity or
|
||||
// frontier field of the range corrupted on its own leaves the readout
|
||||
// unproven. Neither ever yields a successful readout.
|
||||
func TestForceMoveBindsGrantAndRange(t *testing.T) {
|
||||
grantFaults := map[string]func(*control.WorkspaceGrant){
|
||||
"not issued": func(g *control.WorkspaceGrant) { g.Issued = false },
|
||||
"kind": func(g *control.WorkspaceGrant) { g.Kind = "clean" },
|
||||
"request": func(g *control.WorkspaceGrant) { g.RequestId = "req-2" },
|
||||
"volume": func(g *control.WorkspaceGrant) { g.VolumeId = "vol2" },
|
||||
"old replica": func(g *control.WorkspaceGrant) { g.OldReplicaId = "r2" },
|
||||
"old epoch": func(g *control.WorkspaceGrant) { g.OldEpoch = 2 },
|
||||
"new replica": func(g *control.WorkspaceGrant) { g.NewReplicaId = "r2" },
|
||||
"target host": func(g *control.WorkspaceGrant) { g.NewHost = "node-c" },
|
||||
"epoch not up": func(g *control.WorkspaceGrant) { g.NewEpoch = 3 },
|
||||
}
|
||||
g.LostRange.RequestId = "req-1"
|
||||
if _, err := New(f).ForceMove(context.Background(), testMove); err != nil {
|
||||
t.Fatalf("own range: %v", err)
|
||||
for name, fault := range grantFaults {
|
||||
g := goodGrant()
|
||||
fault(g)
|
||||
if _, err := New(&fakeRPC{status: holderAt3(), grant: g}).ForceMove(context.Background(), testMove); OutcomeOf(err) != OutcomeUnknown {
|
||||
t.Errorf("grant %s corrupted: %v; want unknown", name, err)
|
||||
}
|
||||
}
|
||||
rangeFaults := map[string]func(*control.WorkspaceLostRange){
|
||||
"request": func(r *control.WorkspaceLostRange) { r.RequestId = "req-2" },
|
||||
"volume": func(r *control.WorkspaceLostRange) { r.VolumeId = "vol2" },
|
||||
"new epoch": func(r *control.WorkspaceLostRange) { r.NewEpoch = 5 },
|
||||
"old epoch": func(r *control.WorkspaceLostRange) { r.OldEpoch = 2 },
|
||||
"old replica": func(r *control.WorkspaceLostRange) { r.OldReplicaId = "r2" },
|
||||
"head gen": func(r *control.WorkspaceLostRange) { r.HeadGen = 8 },
|
||||
"lost after": func(r *control.WorkspaceLostRange) { r.LostAfterLsn = 41 },
|
||||
}
|
||||
for name, fault := range rangeFaults {
|
||||
g := goodGrant()
|
||||
fault(g.LostRange)
|
||||
if _, err := New(&fakeRPC{status: holderAt3(), grant: g}).ForceMove(context.Background(), testMove); OutcomeOf(err) != OutcomeReadoutUnproven {
|
||||
t.Errorf("range %s corrupted: %v; want unproven", name, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// lostRangeRPC answers QueryWorkspaceLostRange with fixed ranges.
|
||||
type lostRangeRPC struct {
|
||||
control.WorkspaceServiceClient
|
||||
ranges []*control.WorkspaceLostRange
|
||||
}
|
||||
|
||||
func (f *lostRangeRPC) QueryWorkspaceLostRange(context.Context, *control.WorkspaceLostRangeQuery, ...grpc.CallOption) (*control.WorkspaceLostRanges, error) {
|
||||
return &control.WorkspaceLostRanges{Ranges: f.ranges}, nil
|
||||
}
|
||||
|
||||
// A lost-range answer that names another volume or request is unproven.
|
||||
func TestLostRangesBindsTheAnswer(t *testing.T) {
|
||||
r := goodGrant().LostRange
|
||||
if got, err := New(&lostRangeRPC{ranges: []*control.WorkspaceLostRange{r}}).LostRanges(context.Background(), "vol", "req-1"); err != nil || len(got) != 1 {
|
||||
t.Fatalf("matching answer: %v", err)
|
||||
}
|
||||
if _, err := New(&lostRangeRPC{ranges: []*control.WorkspaceLostRange{r}}).LostRanges(context.Background(), "other", ""); OutcomeOf(err) != OutcomeReadoutUnproven {
|
||||
t.Fatalf("another volume: %v", err)
|
||||
}
|
||||
if _, err := New(&lostRangeRPC{ranges: []*control.WorkspaceLostRange{r}}).LostRanges(context.Background(), "vol", "req-9"); OutcomeOf(err) != OutcomeReadoutUnproven {
|
||||
t.Fatalf("another request: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,7 +206,7 @@ func TestClassify(t *testing.T) {
|
||||
func TestReadoutWording(t *testing.T) {
|
||||
r := &control.WorkspaceLostRange{OldReplicaId: "r1", OldEpoch: 3, LostAfterLsn: 42, LostUntilNs: time.Date(2026, 11, 21, 1, 5, 0, 5, time.UTC).UnixNano(),
|
||||
HeadGen: 9, HeadTimeNs: time.Date(2026, 11, 21, 1, 2, 3, 0, time.UTC).UnixNano(), HeadTimeKnown: true}
|
||||
want := "volume vol restored to the last published image at 2026-11-21T01:02:03Z, filer clock (gen 9, LSN 42): writes with LSN <= 42 are preserved; " +
|
||||
want := "volume vol restored to the last published image at 2026-11-21T01:02:03Z (publishing host clock as recorded in the filer, 1 s resolution) (gen 9, LSN 42): writes with LSN <= 42 are preserved; " +
|
||||
"writes acknowledged by r1@3 after that and before 2026-11-21T01:05:00.000000005Z, master clock, may be lost; the upper bound is a time, not an LSN."
|
||||
if got := Readout("vol", r); got != want {
|
||||
t.Fatalf("readout\n got %s\nwant %s", got, want)
|
||||
|
||||
@@ -96,7 +96,7 @@ blockmaster's publisher is the only component that mints epochs. Diagrams: the a
|
||||
| Acked or Expired | (move refused, nothing written) | blockmaster admits a move only with valid target endpoints (host:port, port 1..65535, data and ctrl distinct), a known source host, a registered target node other than the source, and target endpoints that either match a live per-volume binding or, for a volume without bindings, lie on the target node's registered hosts (any port) and are not owned by another assignment or binding; each refusal names its condition and is logged | `core/host/master/workspace_service.go` `MoveWorkspace`, `workspaceMoveCheckLocked` | `INV-WS-CLEAN-MOVE-001`, `INV-WS-FORCED-MOVE-001` |
|
||||
| Granted or Revoking | Expired | the durable horizon or the granted deadline passes | `core/authority/workspace_lease_view.go` `RenewWorkspaceLease`; `core/authority/workspace.go` `AckWorkspaceRevocation` | `INV-WS-FORCED-MOVE-001` |
|
||||
| Expired | Moved (forced) | explicit force; the persisted lease horizon (at least every grant) plus the clock-skew bound and the granted or restart deadline plus the bound have both passed, for the lease the last move issue started (never a predecessor's); blockmaster reads HEAD only after this admission; HEAD is the expected holder's at the expected epoch or any HEAD at an older epoch (the holder never claimed it, or an earlier holder's late claim landed; the lost range starts at that HEAD's remote LSN); a HEAD at the expected or a higher epoch that is not the expected holder's is refused; the lost range (the HEAD's remote LSN, the barrier as LostUntil, the HEAD's generation via the move record and the HEAD entry's filer mtime read with HEAD, or unknown) is written before the reservation. The OSS operator client sends the explicit force only with `--confirm-forced <volume>@<expected epoch>`; `PreviewWorkspaceMove` runs this admission (HEAD read only once admitted) and writes nothing | `core/authority/workspace.go` `prepareWorkspaceMoveLocked`, `WorkspaceForcedMoveAdmitted`, `forcedMoveBarrierLocked`, `workspaceHeadAdmits`, `PreviewWorkspaceForcedMove`; `core/authority/workspace_lost_range.go` `recordLostRangeLocked`; `core/host/master/workspace_service.go` `MoveWorkspace`, `PreviewWorkspaceMove`; `core/rpc/wsclient/wsclient.go` `ForceMove` | `INV-WS-FORCED-MOVE-001`, `INV-WS-LEASE-HORIZON-001`, `INV-WS-LOST-RANGE-READOUT-001`, `INV-WS-FORCED-CONFIRM-001` |
|
||||
| Moved | epoch issued | the move journal record is durable first; a retried request id gets the same epoch; the issue write starts the new holder's lease (horizon issue + 1.5·TTL, granted deadline issue + TTL), published with the epoch in one lease-view section and never lowering a deadline a renewal raised; the new holder is then Granted, and one that dies before its first renewal still expires; the answer to an issued forced move (also a replay) carries its stored lost range, or no range and the reason when that record is missing or fails its checks | `core/authority/workspace.go` `prepareWorkspaceMoveLocked`, `issueWorkspaceMove`, `MoveWorkspace`; `core/authority/workspace_lease_view.go` `publishIssuedLeaseLocked`; `core/host/master/workspace_service.go` `grantWithLostRange` | `INV-AUTH-MOVE-JOURNAL-001`, `INV-LEASE-VIEW-001`, `INV-WS-LOST-RANGE-READOUT-001` |
|
||||
| Moved | epoch issued | the move journal record is durable first; a retried request id gets the same epoch; the issue write starts the new holder's lease (horizon issue + 1.5·TTL, granted deadline issue + TTL), published with the epoch in one lease-view section and never lowering a deadline a renewal raised; the new holder is then Granted, and one that dies before its first renewal still expires; the answer to an issued forced move (also a replay) carries its stored lost range, or no range and the reason when that record is missing or fails its checks; a failure after the issue is answered as issued-but-failed (`Internal`, rerun with the same request id), never as a refusal, and the issue is still logged | `core/authority/workspace.go` `prepareWorkspaceMoveLocked`, `issueWorkspaceMove`, `MoveWorkspace`; `core/authority/workspace_lease_view.go` `publishIssuedLeaseLocked`; `core/host/master/workspace_service.go` `grantWithLostRange`, `postIssueError` | `INV-AUTH-MOVE-JOURNAL-001`, `INV-LEASE-VIEW-001`, `INV-WS-LOST-RANGE-READOUT-001` |
|
||||
|
||||
### M3 Replica role and peer state
|
||||
|
||||
@@ -466,7 +466,7 @@ Notes:
|
||||
| `INV-WS-STOP-PENDING-001` | Stop-pending changes only when the lease guard renews, never what it admits or acknowledges: from the start of a chunk detach until the guard fences, its sleep after a completed renewal is at most 250 ms; it returns to the normal renewal delay only when that same (latest) detach attempt provably did not happen and serving resumed. It bounds scheduling, not the time from a revocation to its acknowledgement. | M4 lease guard: Valid → StopPending → Valid \| Fenced | `core/frontend/durable/provider_chunk.go` `DetachVolume`, `resumeAfterDetach`; `core/host/volume/workspace_runtime.go` `WorkspaceStopPending`, `WorkspaceStopResumed`; `core/host/volume/workspace_lease.go` `StopPending`, `ClearStopPending`, `renewDelay` | `TestWorkspaceLeaseStopPendingSchedule`, `TestWorkspaceHostStopResumedClearsOnlyTheLatestAttempt`, `TestWorkspaceHostFailedDetachStopPendingByOutcome`, `TestWorkspaceHostDetachHookFencesWithinPoll` (`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-CLEAN-MOVE-001` | A clean move is granted only with a detached HEAD from the expected holder and a matching revocation acknowledgement at the current epoch. | M2 lease: Acked → Moved | `core/authority/workspace.go` `prepareWorkspaceMoveLocked`, `AckWorkspaceRevocation` | `TestWorkspaceCleanMoveNeedsDetachedHEADAndRevocationAck` (`core/authority/workspace_test.go`) | `WorkspaceTakeover` `CleanNoLoss` | ACTIVE |
|
||||
| `INV-WS-FORCED-MOVE-001` | A forced move is granted only after the persisted lease horizon (at least every grant, `INV-WS-LEASE-HORIZON-001`) and the granted or restart deadline, each plus the clock-skew bound, of the current holder's lease (a move issue starts it; a predecessor's never admits); the lease reported to the host is the grant, never the horizon, and excludes half of the bound. HEAD is read only after that admission; it must be the expected holder's at the expected epoch or be at an older epoch, and the lost range starts at the remote LSN of that HEAD. | M2 lease: Expired → Moved | `core/authority/workspace.go` `prepareWorkspaceMoveLocked`, `WorkspaceForcedMoveAdmitted`, `forcedMoveBarrierLocked`, `workspaceHeadAdmits`; `core/authority/workspace_lease_view.go` `WorkspaceLeaseReply`; `core/host/master/workspace_service.go` `leaseFact`, `MoveWorkspace`, `workspaceMoveCheckLocked` | `TestWorkspaceSkewSeparatesOldServingFromForcedGrant` (`core/host/master/workspace_skew_test.go`); `TestWorkspaceClockSkewPersistsAndProtectsRestart` (`core/authority/workspace_skew_test.go`); `TestWorkspaceForcedMoveRequiresExplicitForceAndLeaseExpiry` (`core/authority/workspace_test.go`); `TestWorkspaceRestartForcedBarrierHonoursHorizon`, `TestWorkspaceAmbiguousExtensionLatchesUncertainty` (`core/authority/workspace_lease_horizon_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`) | — | ACTIVE |
|
||||
| `INV-WS-LOST-RANGE-READOUT-001` | Every issued forced grant the master returns carries its lost range as stored before the issue (the kept HEAD's remote LSN, LostUntil in master time, the kept HEAD's generation and the HEAD entry's filer mtime read with that HEAD, or "unknown"), also on a replay and after a restart; `QueryWorkspaceLostRange` returns the same stored ranges, all of them in issue order or one by request id, never recomputed. A forced move whose range record is missing or fails its checks (the range checksum or the HEAD-time checksum) makes the readout fail (a grant without a range and with the reason; `DataLoss` from the query; CLI exit 4) and is never reported as no loss. `PreviewWorkspaceMove` runs the forced admission and writes nothing. | M2 lease: Expired → Moved (forced); Moved → epoch issued | `core/authority/workspace_lost_range.go` `recordLostRangeLocked`, `WorkspaceLostRangeReadouts`, `encodeLostRangeEnvelope`, `decodeLostRangeHeadTimes`; `core/authority/workspace.go` `prepareWorkspaceMoveLocked`, `PreviewWorkspaceForcedMove`; `core/host/master/workspace_head.go` `headFilerMtimeNS`; `core/host/master/workspace_service.go` `grantWithLostRange`, `QueryWorkspaceLostRange`, `PreviewWorkspaceMove`; `core/rpc/wsclient/wsclient.go` `ForceMove`, `LostRanges`, `Readout`; `cmd/sw-block/workspace.go` `runWorkspaceForceMove`, `runWorkspaceLostRange` | `TestWorkspaceForcedMoveStoresHeadFilerTime`, `TestWorkspaceLostRangeHeadTimeTamperFailsClosed`, `TestWorkspaceLostRangeAccumulatesInIssueOrder`, `TestWorkspaceLostRangeReadoutFailsClosed`, `TestWorkspaceLostRangeSkippedWriteIsDetected`, `TestWorkspaceForcedMovePreviewWritesNothing` (`core/authority/workspace_lost_range_readout_test.go`); `TestWorkspaceForcedMoveRecordsTheLostRange`, `TestWorkspaceForcedMoveLostRangeOrdering`, `TestWorkspaceForcedReservationResumeNeedsItsRange` (`core/authority/workspace_lost_range_test.go`); `TestWorkspaceForcedMoveLostRangeOverRPC`, `TestWorkspaceHEADReadsFilerMtime` (`core/host/master/workspace_lost_range_readout_test.go`); `TestForceMoveGrantWithoutRangeIsUnproven`, `TestReadoutWording` (`core/rpc/wsclient/wsclient_test.go`); `TestWorkspaceForceMove_Row3and4_SentAndGranted`, `TestWorkspaceForceMove_Row7_ReadoutUnproven`, `TestWorkspaceForceMove_Row8_RerunSameRequestID`, `TestWorkspaceLostRangeListsAllInOrder` (`cmd/sw-block/workspace_test.go`); `TestWorkspaceForceMoveAgainstRealMaster` (`cmd/sw-block/workspace_master_test.go`) | — | ACTIVE |
|
||||
| `INV-WS-LOST-RANGE-READOUT-001` | Every issued forced grant the master returns carries its lost range as stored before the issue (the kept HEAD's remote LSN, LostUntil in master time, the kept HEAD's generation and the HEAD entry's filer mtime read with that HEAD, or "unknown"), also on a replay and after a restart; `QueryWorkspaceLostRange` returns the same stored ranges, all of them in issue order or one by request id, never recomputed. A forced move whose range record is missing or fails its checks (the range checksum or the HEAD-time checksum) makes the readout fail (a grant without a range and with the reason; `DataLoss` from the query; CLI exit 4) and is never reported as no loss. A failure after the issue (e.g. the binding reconciliation) is answered as `Internal` naming the move ISSUED, never as a refusal; the client reports it as an unknown outcome with the same-request-id recovery (never a new request id), and the master's audit log records the issued forced move. The client accepts a grant only when it matches the request (request id, volume, expected holder and epoch, target replica and host, a higher epoch; else unknown) and its range only when it names the same move and kept HEAD (volume, request id, epochs, old replica, HEAD generation, frontier = remote LSN; else unproven). `PreviewWorkspaceMove` runs the forced admission and writes nothing. | M2 lease: Expired → Moved (forced); Moved → epoch issued | `core/authority/workspace_lost_range.go` `recordLostRangeLocked`, `WorkspaceLostRangeReadouts`, `encodeLostRangeEnvelope`, `decodeLostRangeHeadTimes`; `core/authority/workspace.go` `prepareWorkspaceMoveLocked`, `PreviewWorkspaceForcedMove`; `core/host/master/workspace_head.go` `headFilerMtimeNS`; `core/host/master/workspace_service.go` `grantWithLostRange`, `postIssueError`, `issuedRecord`, `logForcedGrant`, `QueryWorkspaceLostRange`, `PreviewWorkspaceMove`; `core/rpc/wsclient/wsclient.go` `ForceMove`, `checkGrant`, `checkRange`, `LostRanges`, `Readout`; `cmd/sw-block/workspace.go` `runWorkspaceForceMove`, `runWorkspaceLostRange`, `shellCommand` | `TestWorkspaceForcedMoveStoresHeadFilerTime`, `TestWorkspaceLostRangeHeadTimeTamperFailsClosed`, `TestWorkspaceLostRangeAccumulatesInIssueOrder`, `TestWorkspaceLostRangeReadoutFailsClosed`, `TestWorkspaceLostRangeSkippedWriteIsDetected`, `TestWorkspaceForcedMovePreviewWritesNothing` (`core/authority/workspace_lost_range_readout_test.go`); `TestWorkspaceForcedMoveRecordsTheLostRange`, `TestWorkspaceForcedMoveLostRangeOrdering`, `TestWorkspaceForcedReservationResumeNeedsItsRange` (`core/authority/workspace_lost_range_test.go`); `TestWorkspaceForcedMoveLostRangeOverRPC`, `TestWorkspaceHEADReadsFilerMtime` (`core/host/master/workspace_lost_range_readout_test.go`); `TestForceMoveGrantWithoutRangeIsUnproven`, `TestForceMoveBindsGrantAndRange`, `TestLostRangesBindsTheAnswer`, `TestReadoutWording` (`core/rpc/wsclient/wsclient_test.go`); `TestWorkspaceForceMove_Row3and4_SentAndGranted`, `TestWorkspaceForceMove_Row7_ReadoutUnproven`, `TestWorkspaceForceMove_Row8_RerunSameRequestID`, `TestWorkspaceForceMoveRecoveryCommandRuns`, `TestWorkspaceForceMoveRejectsAMismatchedAnswer`, `TestWorkspaceLostRangeListsAllInOrder` (`cmd/sw-block/workspace_test.go`); `TestWorkspaceForceMoveAgainstRealMaster` (`cmd/sw-block/workspace_master_test.go`); `TestWorkspaceForceMovePostIssueFailureKeepsTheOutcome` (`cmd/sw-block/workspace_postissue_test.go`) | — | ACTIVE |
|
||||
| `INV-WS-FORCED-CONFIRM-001` | The OSS operator client (`sw-block ops workspace force-move`, `wsclient.ForceMove`) sends a move with `force: true` only when `--confirm-forced` is exactly `<volume>@<expected epoch>` (that volume, a positive decimal epoch), and then always as kind forced at that epoch with the operator's request id; anything else is refused before any connection or RPC (exit 2). A confirmation at an epoch the master has no holder for is refused without sending a move. There is no bypass flag, and `--dry-run` is never a confirmation. | M2 lease: Expired → Moved (forced) (the explicit-force guard) | `core/rpc/wsclient/wsclient.go` `ParseConfirmation`, `ForceMove`, `holderAt`; `cmd/sw-block/workspace.go` `runWorkspaceForceMove` | `TestParseConfirmation`, `TestForceMoveSendsForceOnlyWithTheConfirmation`, `TestForceMoveResolvesTheHolder` (`core/rpc/wsclient/wsclient_test.go`); `TestWorkspaceForceMove_Row1_ConfirmationRefusedLocally`, `TestWorkspaceForceMove_Row2_DryRunPreview`, `TestWorkspaceForceMove_Row3and4_SentAndGranted`, `TestWorkspaceForceMove_Row5_MasterRefusal`, `TestWorkspaceForceMove_Row6_OutcomeUnknown`, `TestWorkspaceHelpText` (`cmd/sw-block/workspace_test.go`); `TestWorkspaceForceMoveAgainstRealMaster` (`cmd/sw-block/workspace_master_test.go`) | — | ACTIVE |
|
||||
|
||||
Notes:
|
||||
@@ -474,7 +474,7 @@ Notes:
|
||||
- `INV-WS-HEAD-CAS-001`: The integration test needs build tag `chunkstore_integration` and a pinned `weed` binary.
|
||||
- `INV-WS-CAS-UNKNOWN-001`: An unknown-outcome CAS is not in the TLA+ models (`docs/spec/README.md`, Limits).
|
||||
- `INV-WS-FORCED-MOVE-001`: TLA+: `W4_drift` found the gap before #158; the skew margin itself is not in the model. Extended for a new holder that dies between its grant and its HEAD claim: the move issue starts its lease, admission uses that grant's lease, HEAD is read after admission, an older-epoch HEAD is accepted (its generation and remote LSN may have moved by an earlier holder's late claim), and a returning holder is refused by two fences, its lease-gated attach and the higher HEAD epoch. `WorkspaceTakeover` models one move from A to B and does not cover a second move away from an unclaimed grant; that model check is open and not claimed here.
|
||||
- `INV-WS-LOST-RANGE-READOUT-001`: The HEAD time is the HEAD filer entry's mtime from the filer's `Last-Modified` header on the same read as the HEAD content (1 s resolution). chunkstore writes that mtime from the clock of the host that wrote the entry (the cut), so "filer clock" is the time recorded in the filer, not a master time; there is no HEAD format change. The HEAD times sit beside the v1 ranges in the lost-range file with their own checksum, so a binary that predates them still verifies the file; a record without one reads as unknown. The readout reads the ranges loaded at startup: damage after startup shows at the next load. The no-HEAD form ("no remote image exists") is defensive: the master refuses a forced move without a published HEAD. The header is checked against test HTTP servers only; the `chunkstore_integration` test does not assert it. Not in the TLA+ models.
|
||||
- `INV-WS-LOST-RANGE-READOUT-001`: The HEAD time is the HEAD filer entry's mtime from the filer's `Last-Modified` header on the same read as the HEAD content (1 s resolution). chunkstore writes that mtime from the clock of the host that wrote the entry (the cut); the readout labels it "(publishing host clock as recorded in the filer, 1 s resolution)", and it is not a master time; there is no HEAD format change. The HEAD times sit beside the v1 ranges in the lost-range file with their own checksum, so a binary that predates them still verifies the file; a record without one reads as unknown. The readout reads the ranges loaded at startup: damage after startup shows at the next load. The no-HEAD form ("no remote image exists") is defensive: the master refuses a forced move without a published HEAD. The header is checked against test HTTP servers only; the `chunkstore_integration` test does not assert it. Not in the TLA+ models.
|
||||
- `INV-WS-FORCED-CONFIRM-001`: A client-side rule: the master's own guards (explicit force, admission, expected epoch) are `INV-WS-FORCED-MOVE-001`. The holder's logical replica id is read from `QueryWorkspace` (the lease, or the journal on a rerun).
|
||||
- `INV-WS-STOP-PENDING-001`: `WorkspaceTakeover` has no renewal cadence (a host may renew at any step), so StopPending adds no state to the model and no configuration is re-run; `INV-WS-LEASE-001` and `INV-WS-REVOKE-ACK-001` hold in StopPending unchanged.
|
||||
|
||||
|
||||
Reference in new issue
Block a user