diff --git a/seaweed-block/core/ops/authority_executor_controller_test.go b/seaweed-block/core/ops/authority_executor_controller_test.go index 1f4681c905..f8f91e75b7 100644 --- a/seaweed-block/core/ops/authority_executor_controller_test.go +++ b/seaweed-block/core/ops/authority_executor_controller_test.go @@ -234,7 +234,7 @@ func authorityExecutorReadyVolume() SwBlockVolumeObject { PreflightReason: ReturnedReplicaExecutorPreflightReasonSatisfied, AllowedMutationClass: []string{AuthorityExecutorAllowedMutationAckEligibility}, ForbiddenMutationClass: []string{"frontend_publication", "rebuild_traffic", "failback"}, - TerminalEvidenceRequired: returnedReplicaTerminalEvidenceRequired(), + TerminalEvidenceRequired: returnedReplicaTerminalEvidenceRequired(ManagedVolumeActionReintegrateReturned), EvidenceRefs: []string{"contract.txt"}, }}, }, diff --git a/seaweed-block/core/ops/operator_status_controller_test.go b/seaweed-block/core/ops/operator_status_controller_test.go index 54a5283200..fad5d1f70a 100644 --- a/seaweed-block/core/ops/operator_status_controller_test.go +++ b/seaweed-block/core/ops/operator_status_controller_test.go @@ -221,6 +221,92 @@ func TestOperatorStatusReconcilerWritesReturnedReplicaExecutorPreflight(t *testi } } +func TestOperatorStatusReconcilerWritesReturnedReplicaRebuildContract(t *testing.T) { + capturedAt := time.Date(2026, 6, 23, 12, 0, 0, 0, time.UTC) + source := fakeOperatorStatusSource{cluster: ClusterEvidence{ + SchemaVersion: ObservationSchemaVersion, + CapturedAt: capturedAt, + Status: ObservationStatusRecovering, + ManagedVolumes: []ManagedVolumeProjection{ProjectManagedVolume(ManagedVolumeFacts{ + VolumeID: "pvc-behind", + PVCName: "behind-pvc", + Authority: &AuthorityFact{ + PrimaryReplica: "r2", + PreviousPrimary: "r1", + RequiredFrontierKnown: true, + RequiredFrontierLSN: 52, + }, + Replicas: []ReplicaFact{{ + ReplicaID: "r1", + Observed: true, + Role: "previous_primary", + DurableFrontierKnown: true, + DurableFrontierLSN: 51, + FrontendPrimaryReady: false, + AckEligibilityKnown: true, + AckEligible: false, + StalePrimaryFenced: true, + }, { + ReplicaID: "r2", + Observed: true, + Role: "primary", + DurableFrontierKnown: true, + DurableFrontierLSN: 52, + }}, + EvidenceRefs: []string{"returned-replica-summary.txt"}, + })}, + }} + writer := &fakeOperatorStatusWriter{} + + _, err := (OperatorStatusReconciler{ + Namespace: "kube-system", + Source: source, + Writer: writer, + }).Reconcile(context.Background()) + if err != nil { + t.Fatalf("reconcile: %v", err) + } + if len(writer.volumes) != 1 { + t.Fatalf("volume writes=%+v", writer.volumes) + } + status := writer.volumes[0].status + if len(status.ExecutorPreflights) != 1 { + t.Fatalf("executor preflights=%+v", status.ExecutorPreflights) + } + preflight := status.ExecutorPreflights[0] + if preflight.ActionType != ManagedVolumeActionRebuildReturned || + preflight.Decision != ReturnedReplicaExecutorPreflightReady || + preflight.Reason != ReturnedReplicaExecutorPreflightReasonSatisfied || + preflight.DurableFrontierLSN != 51 || + preflight.RequiredFrontierLSN != 52 || + preflight.MutationAllowed { + t.Fatalf("rebuild preflight=%+v", preflight) + } + if len(status.ExecutorContracts) != 1 { + t.Fatalf("executor contracts=%+v", status.ExecutorContracts) + } + contract := status.ExecutorContracts[0] + if contract.ActionType != ManagedVolumeActionRebuildReturned || + contract.Decision != ReturnedReplicaExecutorContractDisabled || + contract.Reason != ReturnedReplicaExecutorContractReasonExecutorDisabled || + contract.ExecutionEnabled || + contract.MutationAllowed || + !containsActionFact(contract.AllowedMutationClass, "rebuild_traffic") || + !containsActionFact(contract.ForbiddenMutationClass, "frontend_publication") || + !containsActionFact(contract.TerminalEvidenceRequired, "durable_frontier_caught_up") { + t.Fatalf("rebuild contract=%+v", contract) + } + raw, err := json.Marshal(status) + if err != nil { + t.Fatalf("marshal status: %v", err) + } + for _, want := range []string{`"actionType":"authority.rebuild_returned_replica"`, `"allowedMutationClass":["rebuild_traffic"]`, `"executionEnabled":false`} { + if !strings.Contains(string(raw), want) { + t.Fatalf("CRD status missing %s: %s", want, string(raw)) + } + } +} + func TestOperatorStatusReconcilerProjectsNodeReadiness(t *testing.T) { heartbeat := time.Date(2026, 6, 5, 16, 0, 0, 0, time.UTC) source := fakeOperatorStatusSource{cluster: ClusterEvidence{ diff --git a/seaweed-block/core/ops/returned_replica_executor_contract.go b/seaweed-block/core/ops/returned_replica_executor_contract.go index 1ece492ea7..804ceae3d7 100644 --- a/seaweed-block/core/ops/returned_replica_executor_contract.go +++ b/seaweed-block/core/ops/returned_replica_executor_contract.go @@ -47,21 +47,36 @@ func ReturnedReplicaExecutorContracts(projection ManagedVolumeProjection) []Retu PreflightDecision: preflight.Decision, PreflightReason: preflight.Reason, ForbiddenMutationClass: append([]string(nil), preflight.ForbiddenMutationClass...), - TerminalEvidenceRequired: returnedReplicaTerminalEvidenceRequired(), + TerminalEvidenceRequired: returnedReplicaTerminalEvidenceRequired(preflight.ActionType), EvidenceRefs: append([]string(nil), preflight.EvidenceRefs...), } if preflight.Decision == ReturnedReplicaExecutorPreflightReady { contract.Decision = ReturnedReplicaExecutorContractDisabled contract.Reason = ReturnedReplicaExecutorContractReasonExecutorDisabled - contract.AllowedMutationClass = []string{"ack_eligibility"} - contract.ForbiddenMutationClass = []string{"frontend_publication", "rebuild_traffic", "failback"} + switch preflight.ActionType { + case ManagedVolumeActionRebuildReturned: + contract.AllowedMutationClass = []string{"rebuild_traffic"} + contract.ForbiddenMutationClass = []string{"ack_eligibility", "frontend_publication", "failback"} + default: + contract.AllowedMutationClass = []string{"ack_eligibility"} + contract.ForbiddenMutationClass = []string{"frontend_publication", "rebuild_traffic", "failback"} + } } out = append(out, contract) } return out } -func returnedReplicaTerminalEvidenceRequired() []string { +func returnedReplicaTerminalEvidenceRequired(actionType string) []string { + if actionType == ManagedVolumeActionRebuildReturned { + return []string{ + "frontend_fenced_before_rebuild", + "primary_unchanged", + "durable_frontier_caught_up", + "no_frontend_publication", + "no_cross_volume_identity_change", + } + } return []string{ "ack_eligibility_known", "ack_eligible_true", diff --git a/seaweed-block/core/ops/returned_replica_executor_contract_test.go b/seaweed-block/core/ops/returned_replica_executor_contract_test.go index fcdbb92d7e..49e75b066a 100644 --- a/seaweed-block/core/ops/returned_replica_executor_contract_test.go +++ b/seaweed-block/core/ops/returned_replica_executor_contract_test.go @@ -59,6 +59,42 @@ func TestReturnedReplicaExecutorContract_BlockedWhenPreflightHolds(t *testing.T) } } +func TestReturnedReplicaExecutorContract_DisablesRebuildTrafficWhenFrontierBehind(t *testing.T) { + projection := returnedReplicaPreflightProjection(t, func(facts *ManagedVolumeFacts) { + facts.Replicas[0].DurableFrontierLSN = 51 + }) + + contract := onlyReturnedReplicaExecutorContract(t, projection) + if contract.ActionType != ManagedVolumeActionRebuildReturned { + t.Fatalf("action_type=%s want %s", contract.ActionType, ManagedVolumeActionRebuildReturned) + } + if contract.Decision != ReturnedReplicaExecutorContractDisabled || + contract.Reason != ReturnedReplicaExecutorContractReasonExecutorDisabled || + contract.ExecutionEnabled || + contract.MutationAllowed { + t.Fatalf("executor contract=%+v", contract) + } + if !containsActionFact(contract.AllowedMutationClass, "rebuild_traffic") { + t.Fatalf("rebuild contract should name rebuild_traffic as future envelope: %+v", contract.AllowedMutationClass) + } + for _, want := range []string{"ack_eligibility", "frontend_publication", "failback"} { + if !containsActionFact(contract.ForbiddenMutationClass, want) { + t.Fatalf("forbidden mutation classes missing %s: %+v", want, contract.ForbiddenMutationClass) + } + } + for _, want := range []string{ + "frontend_fenced_before_rebuild", + "primary_unchanged", + "durable_frontier_caught_up", + "no_frontend_publication", + "no_cross_volume_identity_change", + } { + if !containsActionFact(contract.TerminalEvidenceRequired, want) { + t.Fatalf("terminal evidence missing %s: %+v", want, contract.TerminalEvidenceRequired) + } + } +} + func onlyReturnedReplicaExecutorContract(t *testing.T, projection ManagedVolumeProjection) ReturnedReplicaExecutorContract { t.Helper() contracts := ReturnedReplicaExecutorContracts(projection) diff --git a/seaweed-block/core/ops/returned_replica_executor_preflight.go b/seaweed-block/core/ops/returned_replica_executor_preflight.go index 1d530415f7..49942dbdbd 100644 --- a/seaweed-block/core/ops/returned_replica_executor_preflight.go +++ b/seaweed-block/core/ops/returned_replica_executor_preflight.go @@ -14,6 +14,7 @@ const ( ReturnedReplicaExecutorPreflightReasonMissingFrontier = "required_frontier_missing" ReturnedReplicaExecutorPreflightReasonDurableMissing = "durable_frontier_missing" ReturnedReplicaExecutorPreflightReasonFrontierBehind = "returned_replica_frontier_behind" + ReturnedReplicaExecutorPreflightReasonRebuildNotRequired = "returned_replica_rebuild_not_required" ReturnedReplicaExecutorPreflightReasonWrongExecutor = "wrong_owner_executor" ReturnedReplicaExecutorPreflightReasonUnsupportedMode = "unsupported_action_mode" ReturnedReplicaExecutorPreflightReasonUnsupportedMutation = "unexpected_mutation_permission" @@ -46,6 +47,13 @@ type ReturnedReplicaExecutorPreflight struct { } func ReturnedReplicaExecutorPreflights(projection ManagedVolumeProjection) []ReturnedReplicaExecutorPreflight { + if action := returnedReplicaRebuildAction(projection.Actions); action != nil || len(returnedReplicaRebuildCandidates(projection.ReplicaReintegrations)) > 0 { + return []ReturnedReplicaExecutorPreflight{returnedReplicaRebuildPreflight(projection, action)} + } + return returnedReplicaReintegratePreflights(projection) +} + +func returnedReplicaReintegratePreflights(projection ManagedVolumeProjection) []ReturnedReplicaExecutorPreflight { action := returnedReplicaReintegrateAction(projection.Actions) if len(projection.ReplicaReintegrations) == 0 && action == nil { return nil @@ -125,6 +133,66 @@ func ReturnedReplicaExecutorPreflights(projection ManagedVolumeProjection) []Ret return []ReturnedReplicaExecutorPreflight{preflight} } +func returnedReplicaRebuildPreflight(projection ManagedVolumeProjection, action *ManagedVolumeAction) ReturnedReplicaExecutorPreflight { + preflight := ReturnedReplicaExecutorPreflight{ + ActionType: ManagedVolumeActionRebuildReturned, + VolumeID: projection.VolumeID, + Decision: ReturnedReplicaExecutorPreflightHold, + Reason: ReturnedReplicaExecutorPreflightReasonActionNotAllowed, + Mode: ManagedVolumeActionModeDryRun, + SideEffectClass: ManagedVolumeSideEffectAuthorityMutating, + OwnerExecutor: "authority_recovery_executor", + MutationAllowed: false, + EvidenceRequired: "returned_replica_rebuild_evidence", + ForbiddenMutationClass: []string{"ack_eligibility", "frontend_publication", "rebuild_traffic", "failback"}, + } + target := "" + if action != nil { + target = action.Target + preflight.Mode = action.Mode + preflight.SideEffectClass = action.SideEffectClass + preflight.OwnerExecutor = action.OwnerExecutor + preflight.EvidenceRequired = action.EvidenceRequired + preflight.EvidenceRefs = append([]string(nil), action.EvidenceRefs...) + if action.Mode != ManagedVolumeActionModeDryRun { + preflight.Reason = ReturnedReplicaExecutorPreflightReasonUnsupportedMode + return preflight + } + if action.SideEffectClass != ManagedVolumeSideEffectAuthorityMutating || action.OwnerExecutor != "authority_recovery_executor" { + preflight.Reason = ReturnedReplicaExecutorPreflightReasonWrongExecutor + return preflight + } + } + returned, reason := returnedReplicaForExecutorPreflight(returnedReplicaRebuildCandidates(projection.ReplicaReintegrations), target) + if reason != "" { + preflight.Reason = reason + return preflight + } + populateReturnedReplicaPreflight(&preflight, returned) + if len(preflight.EvidenceRefs) == 0 { + preflight.EvidenceRefs = append([]string(nil), returned.EvidenceRefs...) + } + if !returned.FrontendFenced || returned.FrontendPrimaryReady { + preflight.Reason = ReturnedReplicaExecutorPreflightReasonFrontendNotFenced + return preflight + } + if !returned.RequiredFrontierKnown { + preflight.Reason = ReturnedReplicaExecutorPreflightReasonMissingFrontier + return preflight + } + if !returned.DurableFrontierKnown { + preflight.Reason = ReturnedReplicaExecutorPreflightReasonDurableMissing + return preflight + } + if returned.DurableFrontierLSN >= returned.RequiredFrontierLSN { + preflight.Reason = ReturnedReplicaExecutorPreflightReasonRebuildNotRequired + return preflight + } + preflight.Decision = ReturnedReplicaExecutorPreflightReady + preflight.Reason = ReturnedReplicaExecutorPreflightReasonSatisfied + return preflight +} + func populateReturnedReplicaPreflight(preflight *ReturnedReplicaExecutorPreflight, returned ReturnedReplicaProjection) { preflight.ReplicaID = returned.ReplicaID preflight.FrontendFenced = returned.FrontendFenced @@ -167,6 +235,25 @@ func returnedReplicaReintegrateAction(actions []ManagedVolumeAction) *ManagedVol return nil } +func returnedReplicaRebuildAction(actions []ManagedVolumeAction) *ManagedVolumeAction { + for i := range actions { + if actions[i].Type == ManagedVolumeActionRebuildReturned { + return &actions[i] + } + } + return nil +} + +func returnedReplicaRebuildCandidates(returned []ReturnedReplicaProjection) []ReturnedReplicaProjection { + var candidates []ReturnedReplicaProjection + for _, replica := range returned { + if replica.State == ReturnedReplicaStateRecovering || replica.ReasonCode == ReasonCandidateFrontierBehind || replica.ReasonCode == ReasonDurableFrontierMissing { + candidates = append(candidates, replica) + } + } + return candidates +} + func returnedReplicaForExecutorPreflight(returned []ReturnedReplicaProjection, target string) (ReturnedReplicaProjection, string) { if len(returned) == 0 { return ReturnedReplicaProjection{}, ReturnedReplicaExecutorPreflightReasonNoReturnedReplica diff --git a/seaweed-block/core/ops/returned_replica_executor_preflight_test.go b/seaweed-block/core/ops/returned_replica_executor_preflight_test.go index f8a7cb6de2..837ad53696 100644 --- a/seaweed-block/core/ops/returned_replica_executor_preflight_test.go +++ b/seaweed-block/core/ops/returned_replica_executor_preflight_test.go @@ -64,13 +64,36 @@ func TestReturnedReplicaExecutorPreflight_HoldsUnknownAckEligibility(t *testing. } } -func TestReturnedReplicaExecutorPreflight_HoldsFrontierBehind(t *testing.T) { +func TestReturnedReplicaExecutorPreflight_RebuildReadyWhenFrontierBehind(t *testing.T) { projection := returnedReplicaPreflightProjection(t, func(facts *ManagedVolumeFacts) { facts.Replicas[0].DurableFrontierLSN = 51 }) preflight := onlyReturnedReplicaPreflight(t, projection) - if preflight.Decision != ReturnedReplicaExecutorPreflightHold || preflight.Reason != ReturnedReplicaExecutorPreflightReasonFrontierBehind { + if preflight.ActionType != ManagedVolumeActionRebuildReturned { + t.Fatalf("action_type=%s want %s", preflight.ActionType, ManagedVolumeActionRebuildReturned) + } + if preflight.Decision != ReturnedReplicaExecutorPreflightReady || preflight.Reason != ReturnedReplicaExecutorPreflightReasonSatisfied { + t.Fatalf("preflight=%+v", preflight) + } + if preflight.DurableFrontierLSN != 51 || preflight.RequiredFrontierLSN != 52 { + t.Fatalf("frontiers=%+v", preflight) + } + if preflight.MutationAllowed { + t.Fatalf("rebuild preflight must stay non-mutating: %+v", preflight) + } +} + +func TestReturnedReplicaExecutorPreflight_RebuildHoldsWhenDurableFrontierMissing(t *testing.T) { + projection := returnedReplicaPreflightProjection(t, func(facts *ManagedVolumeFacts) { + facts.Replicas[0].DurableFrontierKnown = false + facts.Replicas[0].DurableFrontierLSN = 0 + }) + + preflight := onlyReturnedReplicaPreflight(t, projection) + if preflight.ActionType != ManagedVolumeActionRebuildReturned || + preflight.Decision != ReturnedReplicaExecutorPreflightHold || + preflight.Reason != ReturnedReplicaExecutorPreflightReasonDurableMissing { t.Fatalf("preflight=%+v", preflight) } } diff --git a/seaweed-block/internal/docs/current-plan.md b/seaweed-block/internal/docs/current-plan.md index 5a5253b60d..29e388e085 100644 --- a/seaweed-block/internal/docs/current-plan.md +++ b/seaweed-block/internal/docs/current-plan.md @@ -1,101 +1,123 @@ -# Current Plan: Phase 55 Release And Documentation Hardening +# Current Plan: Phase 56 Returned Replica Rebuild/Catch-up Contract -Status: complete. +Status: in progress. Branch target: `phase54-returned-replica-reintegration-executor` ## Goal -Close the documentation and release-claim gap after Phase 54. +Move from Phase 54's narrow ACK-eligibility executor to the next returned +replica milestone without starting release work. -Phase 54 proved the first bounded returned-replica authority executor mutation: +Phase 54 proved this bounded mutation: ```text SwBlockReplicaEligibility.status ACK eligibility ``` -Phase 55 is intentionally not a new storage feature. It makes the public and -developer-facing documents precise enough that a release reviewer does not -mistake ACK eligibility recording for rebuild, frontend publication, or -failback. +Phase 56 defines the next executor boundary for a returned replica whose durable +frontier is behind the required frontier. The product must say, in machine +readable status: + +```text +this replica needs rebuild/catch-up traffic, +the future executor envelope is rebuild_traffic, +execution is still disabled, +no frontend publication/failback/ACK mutation is allowed by this contract. +``` ## Scope In scope: -- README capability and non-claim alignment. -- Release note for the v0.6 beta candidate. -- User-capability page update. -- Wiki/deep-dive update for returned-replica and read-write control-plane - roadmap. -- Roadmap wording audit after Phase 54 close. -- Release smoke checklist for future published images. +- Action/preflight/contract split between: + - `authority.reintegrate_returned_replica` for ACK-eligible fenced replicas + with frontier coverage. + - `authority.rebuild_returned_replica` for fenced replicas whose durable + frontier is behind the required frontier. +- SwBlockVolume status projection through existing `executorPreflights[]` and + `executorContracts[]`. +- Report/explain/dashboard compatibility through the existing managed-volume + rendering path. +- Unit and status-writer tests that prove the contract reaches CRD-shaped + status without widening mutation authority. Out of scope: -- No product code changes. -- No new executor mutation. -- No release-image publish. -- No QA re-run unless docs expose a missing gate. +- No rebuild data movement. +- No frontend publication. +- No failback. +- No broad `SwBlockVolume.status` rewrite by the authority executor. +- No release smoke or published-image work before the next feature milestone. ## Deliverables -### D1: Public Docs Alignment +### D1: Rebuild/Catch-up Contract Projection -Status: implemented. +Status: implemented locally. -Update README and user capability docs so they say: +When a returned replica is fenced but its durable frontier is behind the +required frontier: -- returned-replica ACK eligibility executor is a beta-candidate gated - capability, -- rebuild/failback/frontend publication remain non-claims, -- published quickstart image tags do not validate Phase 54 until matching - release images are published. +- project `authority.rebuild_returned_replica`; +- mark executor preflight `ready` only when the frontier gap is known; +- keep `execution_enabled=false` and `mutation_allowed=false`; +- name future allowed mutation class as `rebuild_traffic`; +- forbid `ack_eligibility`, `frontend_publication`, and `failback`; +- require terminal evidence: + - `frontend_fenced_before_rebuild`; + - `primary_unchanged`; + - `durable_frontier_caught_up`; + - `no_frontend_publication`; + - `no_cross_volume_identity_change`. -### D2: Release Note +Durable frontier missing remains a hold state, because the product cannot +classify the gap precisely enough to hand off rebuild execution. -Status: implemented. +### D2: Surface And CRD Status Gate -Add `docs/releases/v0.6-beta-candidate.md` and link it from release notes. +Status: pending. -The note must include: +Prove the D1 contract reaches all user-visible status surfaces: -- narrow claim, -- Phase 54 live close evidence, -- pending image-publish warning, -- release checklist. +- `summary.txt`; +- `ops explain`; +- dashboard/operator-snapshot; +- SwBlockVolume `.status.executorPreflights[]`; +- SwBlockVolume `.status.executorContracts[]`. -### D3: Developer Wiki Alignment +### D3: Executor Non-Execution Gate -Status: implemented. +Status: pending. -Update returned-replica and read-write control-plane wiki pages so future -developers see the current boundary: +Prove the existing authority executor does not act on +`authority.rebuild_returned_replica` yet: + +- no `SwBlockReplicaEligibility.status` ACK mutation for rebuild actions; +- no rebuild traffic; +- no frontend publication; +- no failback; +- no cross-volume mutation. + +## Verification + +Current local checks: ```text -ACK eligibility target status is proven -rebuild/catch-up/failback still need their own executor and gates +go test ./core/ops +go test ./cmd/sw-block ``` -### D4: Verification - -Minimum checks: +Before Phase 56 close: ```text go test ./core/ops ./cmd/sw-block helm lint charts/seaweed-block -swblock validate testops/scenarios/authority-executor-live-close-chain.yaml -swblock validate testops/scenarios/authority-executor-multivolume-chain.yaml +swblock validate ``` -Docs are complete only if all checks pass and the diff does not introduce a -broader product claim than Phase 54 proved. - ## Exit -Phase 55 is closed when docs are committed and the next step is clear: - -```text -either release smoke on published images, -or start the next executor milestone with the same evidence/action boundary. -``` +Phase 56 closes when rebuild/catch-up is represented as a precise disabled +executor contract with status-surface agreement and a gate proving no rebuild +execution occurs yet.