Merge pull request #791 from seaweedfs/feat/force-move-json-identity

feat: include target identity in issued force-move JSON
This commit is contained in:
Ping Qiu authored and GitHub committed 2026-11-29 14:27:49 -08:00
commit 8acddaaf2d
4 files changed
+20 -14

No files matched your search

+12 -7
View File
@@ -124,13 +124,16 @@ func workspaceExit(o wsclient.Outcome) int {
// workspaceForceMoveAnswer is output only; admission and exit policy stay in
// the existing client/master paths. A preview never supplies a move id.
type workspaceForceMoveAnswer struct {
Admitted bool `json:"admitted"`
Until string `json:"until"`
Code string `json:"code"`
MoveID string `json:"move_id,omitempty"`
KeptGen *uint64 `json:"kept_gen,omitempty"`
KeptLSN *uint64 `json:"kept_lsn,omitempty"`
LostRange *workspaceForceMoveLoss `json:"lost_range,omitempty"`
Admitted bool `json:"admitted"`
Until string `json:"until"`
Code string `json:"code"`
MoveID string `json:"move_id,omitempty"`
NewEpoch *uint64 `json:"new_epoch,omitempty"`
NewHost string `json:"new_host,omitempty"`
NewReplica string `json:"new_replica,omitempty"`
KeptGen *uint64 `json:"kept_gen,omitempty"`
KeptLSN *uint64 `json:"kept_lsn,omitempty"`
LostRange *workspaceForceMoveLoss `json:"lost_range,omitempty"`
}
type workspaceForceMoveLoss struct {
@@ -141,6 +144,8 @@ type workspaceForceMoveLoss struct {
func (a *workspaceForceMoveAnswer) issued(g *control.WorkspaceGrant, rangeProven bool) {
a.Admitted, a.MoveID = true, g.GetRequestId()
epoch := g.GetNewEpoch()
a.NewEpoch, a.NewHost, a.NewReplica = &epoch, g.GetNewHost(), g.GetNewReplicaId()
gen, lsn := g.GetHeadGen(), g.GetRemoteLsn()
a.KeptGen, a.KeptLSN = &gen, &lsn
a.LostRange = &workspaceForceMoveLoss{Proven: rangeProven}
@@ -19,7 +19,7 @@ func TestWorkspaceForceMoveJSONGoldenAnswers(t *testing.T) {
{"preview-refused", true, false, `{"admitted":false,"until":"2026-11-21T01:05:00Z","code":"FailedPrecondition"}` + "\n", 0},
{"preview-admitted", true, true, `{"admitted":true,"until":"","code":""}` + "\n", 0},
{"move-refused", false, false, `{"admitted":false,"until":"2026-11-21T01:05:00Z","code":"FailedPrecondition"}` + "\n", 1},
{"move-issued", false, true, `{"admitted":true,"until":"","code":"","move_id":"req-1","kept_gen":9,"kept_lsn":42,"lost_range":{"proven":true,"after_lsn":42,"until":"2026-11-21T01:05:00Z"}}` + "\n", 0},
{"move-issued", false, true, `{"admitted":true,"until":"","code":"","move_id":"req-1","new_epoch":4,"new_host":"node-b","new_replica":"r1","kept_gen":9,"kept_lsn":42,"lost_range":{"proven":true,"after_lsn":42,"until":"2026-11-21T01:05:00Z"}}` + "\n", 0},
} {
t.Run(tc.name, func(t *testing.T) {
preview := &control.WorkspaceMovePreview{Admitted: tc.admitted, MasterTimeNs: wsLostUntil.Add(-time.Minute).UnixNano(), LostUntilNs: wsLostUntil.UnixNano(), Reason: "this reason is not a machine-readable verdict"}
@@ -93,7 +93,7 @@ func TestWorkspaceForceMoveJSONKeepsLocalConfirmationAndIssuedReadoutExits(t *te
t.Fatalf("local confirmation: %d %q dials=%d calls=%d", code, out, *dials, f.total())
}
code, out, _ = runCLI(forceMoveArgs(addr, "--json", "--confirm-forced", "vol@3"))
if code != 4 || out != `{"admitted":true,"until":"","code":"DataLoss","move_id":"req-1","kept_gen":9,"kept_lsn":42,"lost_range":{"proven":false}}`+"\n" {
if code != 4 || out != `{"admitted":true,"until":"","code":"DataLoss","move_id":"req-1","new_epoch":4,"new_host":"node-b","new_replica":"r1","kept_gen":9,"kept_lsn":42,"lost_range":{"proven":false}}`+"\n" {
t.Fatalf("issued but unproven readout: %d %q", code, out)
}
}
@@ -106,9 +106,9 @@ func TestWorkspaceForceMoveJSONBindsLossEvidenceToTheValidatedGrant(t *testing.T
exit int
want string
}{
{"zero-frontier", 17, 0, false, false, 0, `{"admitted":true,"until":"","code":"","move_id":"req-1","kept_gen":17,"kept_lsn":0,"lost_range":{"proven":true,"after_lsn":0,"until":"2026-11-21T01:05:00Z"}}` + "\n"},
{"large-frontier", 19, 9007199254740993, false, false, 0, `{"admitted":true,"until":"","code":"","move_id":"req-1","kept_gen":19,"kept_lsn":9007199254740993,"lost_range":{"proven":true,"after_lsn":9007199254740993,"until":"2026-11-21T01:05:00Z"}}` + "\n"},
{"mismatched-range", 23, 71, true, false, 4, `{"admitted":true,"until":"","code":"DataLoss","move_id":"req-1","kept_gen":23,"kept_lsn":71,"lost_range":{"proven":false}}` + "\n"},
{"zero-frontier", 17, 0, false, false, 0, `{"admitted":true,"until":"","code":"","move_id":"req-1","new_epoch":4,"new_host":"node-b","new_replica":"r1","kept_gen":17,"kept_lsn":0,"lost_range":{"proven":true,"after_lsn":0,"until":"2026-11-21T01:05:00Z"}}` + "\n"},
{"large-frontier", 19, 9007199254740993, false, false, 0, `{"admitted":true,"until":"","code":"","move_id":"req-1","new_epoch":4,"new_host":"node-b","new_replica":"r1","kept_gen":19,"kept_lsn":9007199254740993,"lost_range":{"proven":true,"after_lsn":9007199254740993,"until":"2026-11-21T01:05:00Z"}}` + "\n"},
{"mismatched-range", 23, 71, true, false, 4, `{"admitted":true,"until":"","code":"DataLoss","move_id":"req-1","new_epoch":4,"new_host":"node-b","new_replica":"r1","kept_gen":23,"kept_lsn":71,"lost_range":{"proven":false}}` + "\n"},
{"mismatched-grant", 23, 71, false, true, 3, `{"admitted":false,"until":"","code":"Unknown"}` + "\n"},
} {
t.Run(tc.name, func(t *testing.T) {
+1 -1
View File
@@ -850,7 +850,7 @@ Notes:
| `INV-WS-LOST-RANGE-CLIENT-GRANT-001` | The operator client accepts a forced grant only if it is issued, of kind forced, and matches the request's id, volume, expected holder and epoch, target replica and host, with a higher new epoch; otherwise the outcome is unknown. | M2 lease: Moved → epoch issued (client side) | `core/rpc/wsclient/wsclient.go` `checkGrant`, `ForceMove` | `TestForceMoveBindsGrantAndRange` (`core/rpc/wsclient/wsclient_test.go`); `TestWorkspaceForceMoveRejectsAMismatchedAnswer` (`cmd/sw-block/workspace_test.go`) | — | ACTIVE |
| `INV-WS-LOST-RANGE-CLIENT-RANGE-001` | The operator client accepts a grant's lost range only if it names the grant's volume, request id, old and new epochs, old replica and HEAD generation, and starts at the grant's remote LSN; otherwise the readout is unproven. | M2 lease: Moved → epoch issued (client side) | `core/rpc/wsclient/wsclient.go` `checkRange`, `ForceMove` | `TestForceMoveBindsGrantAndRange`, `TestForceMoveGrantWithoutRangeIsUnproven` (`core/rpc/wsclient/wsclient_test.go`) | — | ACTIVE |
| `INV-CLI-FORCED-LOSS-001` | An issued forced-move JSON answer retains the kept HEAD generation and LSN; proven lost ranges carry their kept-through LSN and time bound, while unproven ranges are explicit and supply no guessed bounds. | M2 forced move readout, output only | `cmd/sw-block/workspace.go` `workspaceForceMoveAnswer.issued` | `TestWorkspaceForceMoveJSONGoldenAnswers`, `TestWorkspaceForceMoveJSONKeepsLocalConfirmationAndIssuedReadoutExits` | MoveAdmission.ReadForMove; no transition change | ACTIVE |
| `INV-CLI-FORCED-JSON-001` | Force-move JSON reports typed admission, barrier and refusal code; only a validated issued grant supplies a move id. Text output and exit codes keep their existing meanings. | M2 Expired → Moved (forced), output only | `cmd/sw-block/workspace.go`; `core/rpc/wsclient/wsclient.go`; `core/host/master/workspace_service.go` | `TestWorkspaceForceMoveJSONGoldenAnswers`, `TestWorkspaceForceMoveJSONDoesNotGuessAdmission`, `TestWorkspaceForceMoveJSONKeepsLocalConfirmationAndIssuedReadoutExits`, `TestWorkspaceForcedMoveLostRangeOverRPC` | MoveAdmission.ReadForMove; no transition change | ACTIVE |
| `INV-CLI-FORCED-JSON-001` | Force-move JSON reports typed admission, barrier and refusal code; only a validated issued grant supplies a move id and target epoch, host and replica. Text output and exit codes keep their existing meanings. | M2 Expired → Moved (forced), output only | `cmd/sw-block/workspace.go`; `core/rpc/wsclient/wsclient.go`; `core/host/master/workspace_service.go` | `TestWorkspaceForceMoveJSONGoldenAnswers`, `TestWorkspaceForceMoveJSONDoesNotGuessAdmission`, `TestWorkspaceForceMoveJSONKeepsLocalConfirmationAndIssuedReadoutExits`, `TestWorkspaceForcedMoveLostRangeOverRPC` | MoveAdmission.ReadForMove; no transition change | ACTIVE |
| `INV-WS-FORCED-CONFIRM-001` | The OSS operator client (`sw-block ops workspace force-move`, `wsclient.ForceMove`) sends `force: true` only when `--confirm-forced` is exactly `<volume>@<expected epoch>` (that volume, a positive decimal epoch), and then as kind forced at that epoch with the operator's request id. | M2 lease: Expired → Moved (forced) (the explicit-force guard) | `core/rpc/wsclient/wsclient.go` `ParseConfirmation`, `request`, `ForceMove`; `cmd/sw-block/workspace.go` `runWorkspaceForceMove` | `TestParseConfirmation`, `TestForceMoveSendsForceOnlyWithTheConfirmation` (`core/rpc/wsclient/wsclient_test.go`); `TestWorkspaceForceMove_Row3and4_SentAndGranted` (`cmd/sw-block/workspace_test.go`); `TestWorkspaceForceMoveAgainstRealMaster` (`cmd/sw-block/workspace_master_test.go`) | — | ACTIVE |
| `INV-WS-FORCED-CONFIRM-LOCAL-001` | A missing or malformed `--confirm-forced` is refused before any connection or RPC, with exit 2. | M2 lease: Expired → Moved (forced) (the explicit-force guard) | `cmd/sw-block/workspace.go` `runWorkspaceForceMove`; `core/rpc/wsclient/wsclient.go` `ParseConfirmation`, `request` | `TestWorkspaceForceMove_Row1_ConfirmationRefusedLocally` (`cmd/sw-block/workspace_test.go`); `TestParseConfirmation` (`core/rpc/wsclient/wsclient_test.go`) | — | ACTIVE |
| `INV-WS-FORCED-CONFIRM-HOLDER-001` | A confirmation at an epoch the master reports no holder for, in its lease or its move journal, is refused without sending a move. | M2 lease: Expired → Moved (forced) (the explicit-force guard) | `core/rpc/wsclient/wsclient.go` `holderAt`, `request` | `TestForceMoveResolvesTheHolder` (`core/rpc/wsclient/wsclient_test.go`) | — | ACTIVE |
+2 -1
View File
@@ -411,7 +411,8 @@ applies; there is no bypass. Add `--json` to either the dry-run or real command
answer: `admitted` (boolean), `until` (UTC RFC3339Nano barrier time when known
and not admitted, otherwise `""`), `code` (gRPC refusal code name such as
`FailedPrecondition`, or `""` on success), and `move_id` once a matching issued
move is known. An issued answer also carries `kept_gen`, `kept_lsn` and
move is known. An issued answer also carries `new_epoch`, `new_host` and
`new_replica` from that same validated grant, plus `kept_gen`, `kept_lsn` and
`lost_range: {proven, after_lsn, until}`: writes through `after_lsn` are kept;
acknowledged writes after it and before `until` (master clock) may be lost.
A preview never supplies a move id and remains advisory.