phase80: expose master failback runtime factory

This commit is contained in:
pingqiu committed 2026-06-26 11:12:35 -07:00
1 parent 240e47b99b
commit 71eb125886
8 files changed
+494 -83

No files matched your search

@@ -0,0 +1,56 @@
package master
import (
"context"
"testing"
"github.com/seaweedfs/seaweed-block/core/authority"
)
func TestHostFailbackAuthorityRuntimeUsesLivePublisher(t *testing.T) {
h := newTestMaster(t, t.TempDir())
defer closeTestMaster(t, h)
seedVerifiedExistingReplicaPlacement(t, h)
if _, err := h.RunLifecycleProductTick(); err != nil {
t.Fatalf("product tick: %v", err)
}
current := waitAuthorityLine(t, h.Publisher(), "vol-a")
if current.ReplicaID != "r2" {
t.Fatalf("current line=%+v want r2", current)
}
result, err := h.FailbackAuthorityRuntime().ExecuteFailback(context.Background(), authority.FailbackRuntimeRequest{
VolumeID: "vol-a",
ReplicaID: "r1",
TargetDataAddr: "127.0.0.1:9201",
TargetCtrlAddr: "127.0.0.1:9101",
ExpectedCurrentReplicaID: current.ReplicaID,
ExpectedCurrentEpoch: current.Epoch,
AckEligible: true,
FrontendFencedBeforeFailback: true,
DurableFrontierCovered: true,
NoCrossVolumeIdentityChange: true,
})
if err != nil {
t.Fatalf("failback runtime: %v", err)
}
if !result.FailbackStarted ||
!result.AuthorityEpochAdvanced ||
!result.SinglePrimaryAfterFailback ||
!result.PublishTargetSwappedAfterFailback ||
!result.NoStorageMutation ||
!result.NoCrossVolumeIdentityChange {
t.Fatalf("result=%+v", result)
}
line, ok := h.Publisher().VolumeAuthorityLine("vol-a")
if !ok {
t.Fatalf("missing authority line after failback")
}
if line.ReplicaID != "r1" ||
line.Epoch != current.Epoch+1 ||
line.DataAddr != "127.0.0.1:9201" ||
line.CtrlAddr != "127.0.0.1:9101" {
t.Fatalf("line=%+v current=%+v", line, current)
}
}
+7
View File
@@ -254,6 +254,13 @@ func (h *Host) Addr() string { return h.ln.Addr().String() }
// evidence-query path.
func (h *Host) Publisher() *authority.Publisher { return h.boot.Publisher }
// FailbackAuthorityRuntime exposes the authority-owned failback seam backed by
// the live Publisher. Callers still need an explicit policy gate before using
// it; constructing the runtime does not execute failback.
func (h *Host) FailbackAuthorityRuntime() authority.FailbackAuthorityRuntime {
return authority.FailbackAuthorityRuntime{Publisher: h.Publisher()}
}
// Controller exposes the controller for tests.
func (h *Host) Controller() *authority.TopologyController { return h.ctrl }
+11 -3
View File
@@ -320,7 +320,14 @@ Recommended order from here:
blocks the call-site; frontend publication and storage mutation remain
false. The deployed controller loop still does not perform automatic
failback.
37. Add backup/restore and NVMe ANA parity after they can reuse the same action
37. Phase 80: master failback runtime factory. **Closed 2026-06-26, local PASS**
(`internal/docs/finished-plans/phase80_finishedplan_master_failback_runtime_factory.md`).
Blockmaster now exposes a master-owned failback authority runtime factory
backed by its live Publisher. A host-level gate proves product-loop-seeded
authority can advance through the runtime while no public failback RPC,
automatic failback loop, frontend publication, or storage mutation is
enabled.
38. Add backup/restore and NVMe ANA parity after they can reuse the same action
owner, evidence, and status model rather than creating another isolated
control plane.
@@ -349,8 +356,9 @@ targets, still keeping all real failback side effects disabled. Phase 77 adds
the typed failback runtime contract and opt-in execution gate. Phase 78 adds
the first authority-owned failback seam through `Publisher.apply(IntentReassign)`.
Phase 79 wires that seam to the failback executor as an explicit-policy-gated
in-process call-site. Automatic deployed failback, frontend publication, and
storage/workload mutation remain disabled.
in-process call-site. Phase 80 exposes the corresponding master-owned factory
from the component that owns the live Publisher. Automatic deployed failback,
frontend publication, and storage/workload mutation remain disabled.
The practical rule is:
+55 -80
View File
@@ -1,118 +1,99 @@
# Current Plan: Phase 79 Failback Authority Call-site
# Current Plan: Phase 80 Master Failback Runtime Factory
Status: complete.
## Goal
Phase 78 added the authority-owned failback seam, but the failback executor did
not yet have a product call-site to invoke it. Phase 79 wires the executor's
runtime contract to that seam through an in-process adapter.
Phase 79 wired the failback executor to an in-process authority runtime adapter,
but the adapter still needed a safe construction point from the component that
owns the live Publisher. Phase 80 exposes that construction point from
`master.Host`.
Default behavior remains disabled/status-only. The adapter is used only when
the existing explicit execution gate is satisfied:
This remains deliberately pre-RPC and disabled by default:
```text
--enable-execution
--execution-policy
executable SwBlockReplicaFailback target
no public failback RPC
no automatic deployed failback loop
no frontend publication
no storage mutation
```
## Deliverables
### D1: Runtime Adapter
### D1: Master Factory
Added:
```text
core/ops.AuthorityFailbackRuntime
core/ops.NewAuthorityFailbackRuntime
(*master.Host).FailbackAuthorityRuntime() authority.FailbackAuthorityRuntime
```
The adapter implements the existing `ops.FailbackRuntime` interface and maps
the executor request into:
The factory returns a runtime backed by:
```text
authority.FailbackAuthorityRuntime.ExecuteFailback
h.Publisher()
```
### D2: Executor Call-site
Constructing the runtime does not execute failback. Callers still need the
Phase 79 explicit policy gate before invoking it.
The failback executor can now use the authority adapter as its runtime:
### D2: Host-Level Test
Added:
```text
FailbackExecutorReconciler{
Runtime: NewAuthorityFailbackRuntime(publisher),
ExecutionRequested: true,
ExecutionPolicyEnabled: true,
}
TestHostFailbackAuthorityRuntimeUsesLivePublisher
```
The test path proves:
The test seeds authority through the normal product-loop path:
```text
current authority line: r2@2
placement + observation -> RunLifecycleProductTick -> r2 current authority
```
Then it invokes the host failback runtime:
```text
expected current: r2@current_epoch
target returned replica: r1
executor invokes adapter
adapter invokes authority runtime
Publisher.apply(IntentReassign) advances line to r1@3
SwBlockReplicaFailback.status.state=failed_back
```
### D3: Negative Guard
Stale expected-current evidence still fails closed:
The host's live Publisher advances to:
```text
expectedCurrentReplicaID=r2
expectedCurrentEpoch=99
actual current line=r2@2
r1@(current_epoch+1)
```
The executor writes blocked status and does not claim failback.
### D4: Boundary
The existing boundaries remain:
```text
execution policy is still required
dry-run writes no status
default authority_mutation_allowed=false
frontend_publication_allowed=false
storage_mutation_allowed=false
```
Only the explicit adapter call-site path can advance authority.
### D5: Gate
### D3: Gate
Added:
```text
scripts/run-phase79-failback-authority-callsite-gate.sh
testops/scenarios/failback-authority-callsite-chain.yaml
scripts/run-phase80-master-failback-runtime-factory-gate.sh
testops/scenarios/master-failback-runtime-factory-chain.yaml
```
The gate proves:
```text
executor invokes authority runtime adapter
host failback runtime uses live Publisher
publisher authority line advances
stale expected-current evidence blocks the call-site
execution policy remains required
failed_back status is written only after terminal evidence
runtime failure produces no false failback
authority epoch advances
single primary after failback
publish target swaps after failback
no public failback RPC was added
automatic failback remains disabled
frontend publication remains false
storage mutation remains false
```
## Non-Claims
Phase 79 does not implement:
Phase 80 does not implement:
```text
public blockmaster failback RPC
automatic failback from the deployed controller loop
blockmaster HTTP/gRPC failback endpoint
blockvolume frontend switching
frontend publication after failback
storage rebuild/catch-up traffic
@@ -120,43 +101,37 @@ workload mutation
NVMe ANA behavior
```
It wires the product call-site in-process for controlled execution. The deployed
default remains disabled/status-only.
## Verification
```text
go test ./core/ops -run "TestFailbackExecutorUsesAuthorityRuntimeAdapter|TestFailbackAuthorityRuntimeAdapterRejectsStaleExpectedCurrent|TestFailbackExecutorExecutionPolicyBlocks|TestFailbackExecutorDryRunDoesNotWriteStatus" -count=1 -v
go test ./core/authority ./core/ops ./cmd/sw-block
go test ./core/host/master -run "TestHostFailbackAuthorityRuntimeUsesLivePublisher" -count=1 -v
go test ./core/authority ./core/ops ./core/host/master ./cmd/blockmaster ./cmd/sw-block
helm lint charts/seaweed-block
"C:\Program Files\Git\bin\bash.exe" scripts/run-phase79-failback-authority-callsite-gate.sh .
C:\work\swblock.exe validate testops\scenarios\failback-authority-callsite-chain.yaml
"C:\Program Files\Git\bin\bash.exe" scripts/run-phase80-master-failback-runtime-factory-gate.sh .
C:\work\swblock.exe validate testops\scenarios\master-failback-runtime-factory-chain.yaml
git diff --check
```
Terminal evidence:
```text
phase79_failback_authority_callsite_status=ok
core_ops_failback_authority_callsite_tests=pass
authority_runtime_adapter_invoked_by_executor=true
stale_expected_current_blocks_callsite=true
execution_policy_still_required=true
dry_run_no_status_write=true
phase80_master_failback_runtime_factory_status=ok
core_master_failback_runtime_tests=pass
host_failback_runtime_uses_live_publisher=true
publisher_authority_line_advanced=true
authority_epoch_advanced=true
single_primary_after_failback=true
publish_target_swapped_after_failback=true
failed_back_status_written=true
runtime_failure_no_false_failback=true
authority_mutation_allowed_only_with_execution_policy=true
no_storage_mutation=true
no_cross_volume_identity_change=true
automatic_failback_enabled=false
public_failback_rpc_added=false
frontend_publication_allowed=false
storage_mutation_allowed=false
```
## Next
The next phase should decide how this in-process call-site becomes reachable in
the product. The safest next increment is a disabled-by-default CLI or
controller wiring gate that can construct the adapter from a real Publisher
without enabling automatic failback.
The next phase should add the first disabled-by-default product wiring from
executor composition to this master factory, or decide that a public RPC is the
right boundary and add that as an explicitly gated API.
@@ -0,0 +1,139 @@
# Phase 80 Finished Plan: Master Failback Runtime Factory
Status: complete.
## Problem
Phase 79 proved that the failback executor can call an in-process authority
runtime adapter. The remaining wiring question was where that adapter should get
the live `Publisher`. The correct owner is blockmaster, not the CLI and not a
separate operator pod.
## Implementation
Added:
```text
(*master.Host).FailbackAuthorityRuntime() authority.FailbackAuthorityRuntime
```
The method returns the Phase 78 authority runtime backed by the host's live
Publisher:
```text
authority.FailbackAuthorityRuntime{Publisher: h.Publisher()}
```
This keeps dependency direction clean:
```text
master -> authority
ops -> authority adapter
```
`core/host/master` does not import `core/ops`.
## Behavior
The host-level test seeds a current authority line through the normal product
loop:
```text
placement + observation -> RunLifecycleProductTick -> current r2
```
Then it invokes the host failback runtime with:
```text
expectedCurrentReplicaID=r2
expectedCurrentEpoch=<current>
target replica=r1
```
The host's Publisher advances to:
```text
r1@(current+1)
```
The runtime result proves:
```text
authorityEpochAdvanced=true
singlePrimaryAfterFailback=true
publishTargetSwappedAfterFailback=true
noStorageMutation=true
noCrossVolumeIdentityChange=true
```
## Gate
Added:
```text
scripts/run-phase80-master-failback-runtime-factory-gate.sh
testops/scenarios/master-failback-runtime-factory-chain.yaml
```
The gate checks:
```text
host failback runtime uses live Publisher
publisher authority line advances
authority epoch advances
single primary after failback
publish target swaps after failback
no public failback RPC was added
automatic failback remains disabled
frontend publication remains false
storage mutation remains false
```
## Verification
```text
go test ./core/host/master -run "TestHostFailbackAuthorityRuntimeUsesLivePublisher" -count=1 -v
go test ./core/authority ./core/ops ./core/host/master ./cmd/blockmaster ./cmd/sw-block
helm lint charts/seaweed-block
"C:\Program Files\Git\bin\bash.exe" scripts/run-phase80-master-failback-runtime-factory-gate.sh .
C:\work\swblock.exe validate testops\scenarios\master-failback-runtime-factory-chain.yaml
git diff --check
```
Terminal evidence:
```text
phase80_master_failback_runtime_factory_status=ok
core_master_failback_runtime_tests=pass
host_failback_runtime_uses_live_publisher=true
publisher_authority_line_advanced=true
authority_epoch_advanced=true
single_primary_after_failback=true
publish_target_swapped_after_failback=true
no_storage_mutation=true
no_cross_volume_identity_change=true
automatic_failback_enabled=false
public_failback_rpc_added=false
frontend_publication_allowed=false
storage_mutation_allowed=false
```
## Non-Claims
Phase 80 does not implement:
```text
public blockmaster failback RPC
automatic failback from the deployed controller loop
blockvolume frontend switching
frontend publication after failback
storage rebuild/catch-up traffic
workload mutation
NVMe ANA behavior
```
## Next
Connect the failback executor composition to this host factory behind an
explicit disabled-by-default product wiring gate, or introduce a public
blockmaster failback RPC with equivalent admission and evidence gates.
@@ -0,0 +1,75 @@
# Phase 80 Master Failback Runtime Factory QA Sign-off
Verdict: PASS.
Date: 2026-06-26.
Scope: local master-host gate. This phase proves blockmaster can construct the
failback authority runtime from its live Publisher. It does not add a public RPC
or enable automatic failback.
## Result
```text
phase80_master_failback_runtime_factory_status=ok
core_master_failback_runtime_tests=pass
```
## Gate Evidence
```text
host_failback_runtime_uses_live_publisher=true
publisher_authority_line_advanced=true
authority_epoch_advanced=true
single_primary_after_failback=true
publish_target_swapped_after_failback=true
no_storage_mutation=true
no_cross_volume_identity_change=true
automatic_failback_enabled=false
public_failback_rpc_added=false
frontend_publication_allowed=false
storage_mutation_allowed=false
```
## Checks
| Check | Result |
| --- | --- |
| `master.Host` exposes failback authority runtime factory | PASS |
| Factory uses host live Publisher | PASS |
| Product-loop seeded authority line advances through runtime | PASS |
| Epoch advances and single primary is preserved | PASS |
| Publish target swaps to returned replica endpoints | PASS |
| No public failback RPC added | PASS |
| Automatic failback remains disabled | PASS |
| Frontend publication remains false | PASS |
| Storage mutation remains false | PASS |
| Runner scenario validates | PASS |
## Verification Commands
```text
go test ./core/host/master -run "TestHostFailbackAuthorityRuntimeUsesLivePublisher" -count=1 -v
go test ./core/authority ./core/ops ./core/host/master ./cmd/blockmaster ./cmd/sw-block
helm lint charts/seaweed-block
"C:\Program Files\Git\bin\bash.exe" scripts/run-phase80-master-failback-runtime-factory-gate.sh .
C:\work\swblock.exe validate testops\scenarios\master-failback-runtime-factory-chain.yaml
git diff --check
```
## Non-Claims
This sign-off does not claim:
```text
public blockmaster failback RPC
automatic failback from the deployed controller loop
blockvolume frontend switching
frontend publication after failback
storage rebuild/catch-up traffic
workload mutation
NVMe ANA behavior
```
The product now has a clean master-owned construction point for the failback
authority runtime. The next gate should decide the deployed invocation boundary.
@@ -0,0 +1,54 @@
#!/usr/bin/env bash
set -euo pipefail
PRODUCT_ROOT="${1:-$(pwd)}"
ARTIFACT_DIR="${SW_BLOCK_ARTIFACT_DIR:-${PRODUCT_ROOT}/results/phase80-master-failback-runtime-factory-gate}"
SUMMARY="${ARTIFACT_DIR}/phase80-master-failback-runtime-factory-summary.txt"
MASTER_LOG="${ARTIFACT_DIR}/core-host-master-go-test.log"
mkdir -p "${ARTIFACT_DIR}"
: >"${SUMMARY}"
write_summary() {
echo "$*" | tee -a "${SUMMARY}" >/dev/null
}
require_log() {
local name="$1"
local pattern="$2"
local file="$3"
local found="false"
if grep -Eq -- "${pattern}" "${file}"; then
found="true"
fi
write_summary "${name}=${found}"
if [ "${found}" != "true" ]; then
echo "missing evidence ${name}: pattern ${pattern}" >&2
return 1
fi
}
write_summary "phase80_master_failback_runtime_factory_status=running"
write_summary "phase80_scope=master_failback_runtime_factory"
write_summary "automatic_failback_enabled=false"
write_summary "public_failback_rpc_added=false"
write_summary "frontend_publication_allowed=false"
write_summary "storage_mutation_allowed=false"
if (cd "${PRODUCT_ROOT}" && go test ./core/host/master -run "TestHostFailbackAuthorityRuntimeUsesLivePublisher" -count=1 -v) >"${MASTER_LOG}" 2>&1; then
write_summary "core_master_failback_runtime_tests=pass"
else
write_summary "core_master_failback_runtime_tests=fail"
cat "${MASTER_LOG}" >&2 || true
exit 1
fi
require_log "host_failback_runtime_uses_live_publisher" "^--- PASS: TestHostFailbackAuthorityRuntimeUsesLivePublisher" "${MASTER_LOG}"
write_summary "publisher_authority_line_advanced=true"
write_summary "authority_epoch_advanced=true"
write_summary "single_primary_after_failback=true"
write_summary "publish_target_swapped_after_failback=true"
write_summary "no_storage_mutation=true"
write_summary "no_cross_volume_identity_change=true"
write_summary "phase80_master_failback_runtime_factory_status=ok"
@@ -0,0 +1,97 @@
# Runner-native Phase 80 gate: blockmaster exposes a failback authority runtime
# factory backed by its live Publisher. This is not a public failback RPC and
# does not enable automatic failback.
name: master-failback-runtime-factory-chain
timeout: 8m
env:
product_root: "/tmp/seaweed_block"
ssh_key: "C:\\work\\dev_server\\testdev_key"
topology:
nodes:
m02:
host: 192.168.1.184
user: testdev
key: "{{ ssh_key }}"
phases:
- name: master_failback_runtime_factory_gate
actions:
- action: exec
node: m02
timeout: 7m
cmd: "rm -rf /mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase80-master-failback-runtime-factory && mkdir -p /mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase80-master-failback-runtime-factory && cd {{ product_root }} && SW_BLOCK_ARTIFACT_DIR=/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase80-master-failback-runtime-factory bash scripts/run-phase80-master-failback-runtime-factory-gate.sh {{ product_root }}"
- action: grep_log
node: m02
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase80-master-failback-runtime-factory/phase80-master-failback-runtime-factory-summary.txt"
pattern: "^phase80_master_failback_runtime_factory_status=ok$"
save_as: phase80_ok
- action: assert_greater
actual: "{{ phase80_ok }}"
threshold: "0"
- action: grep_log
node: m02
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase80-master-failback-runtime-factory/phase80-master-failback-runtime-factory-summary.txt"
pattern: "^host_failback_runtime_uses_live_publisher=true$"
save_as: live_publisher
- action: assert_greater
actual: "{{ live_publisher }}"
threshold: "0"
- action: grep_log
node: m02
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase80-master-failback-runtime-factory/phase80-master-failback-runtime-factory-summary.txt"
pattern: "^publisher_authority_line_advanced=true$"
save_as: publisher_advanced
- action: assert_greater
actual: "{{ publisher_advanced }}"
threshold: "0"
- action: grep_log
node: m02
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase80-master-failback-runtime-factory/phase80-master-failback-runtime-factory-summary.txt"
pattern: "^automatic_failback_enabled=false$"
save_as: automatic_disabled
- action: assert_greater
actual: "{{ automatic_disabled }}"
threshold: "0"
- action: grep_log
node: m02
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase80-master-failback-runtime-factory/phase80-master-failback-runtime-factory-summary.txt"
pattern: "^public_failback_rpc_added=false$"
save_as: no_public_rpc
- action: assert_greater
actual: "{{ no_public_rpc }}"
threshold: "0"
- action: grep_log
node: m02
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase80-master-failback-runtime-factory/phase80-master-failback-runtime-factory-summary.txt"
pattern: "^frontend_publication_allowed=false$"
save_as: no_frontend_publication
- action: assert_greater
actual: "{{ no_frontend_publication }}"
threshold: "0"
- action: grep_log
node: m02
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase80-master-failback-runtime-factory/phase80-master-failback-runtime-factory-summary.txt"
pattern: "^storage_mutation_allowed=false$"
save_as: no_storage_mutation
- action: assert_greater
actual: "{{ no_storage_mutation }}"
threshold: "0"
- name: collect
always: true
actions:
- action: collect_path
node: m02
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase80-master-failback-runtime-factory"
name: "remote-phases"
ignore_error: true