blockvolume: block healthy publication on recovery fault

This commit is contained in:
pingqiu committed 2026-05-30 22:48:58 -07:00
1 parent ea1faf6a0a
commit 90d2dbe1a5
3 files changed
+139

No files matched your search

+28
View File
@@ -412,6 +412,9 @@ func run(f flags) int {
fmt.Fprintln(os.Stderr, "blockvolume:", err)
return 1
}
if f.durableRoot != "" {
h.BlockLocalReadiness("awaiting durable recovery")
}
h.Start()
var status *volume.StatusServer
@@ -495,8 +498,11 @@ func run(f flags) int {
recCancel()
if recErr != nil {
fmt.Fprintln(os.Stderr, "blockvolume: durable recovery failed:", report.Evidence)
h.BlockLocalReadiness(report.Evidence)
return waitFaultedDurableRecovery(h, status, durableProv, report.Evidence)
} else {
fmt.Fprintln(os.Stderr, "blockvolume: durable recovered:", report.Evidence)
h.ClearLocalReadinessBlock()
}
} else {
// memback fallback — wraps the volume's AdapterProjectionView
@@ -925,6 +931,28 @@ func run(f flags) int {
return 0
}
func waitFaultedDurableRecovery(h *volume.Host, status *volume.StatusServer, durableProv *durable.DurableProvider, evidence string) int {
fmt.Fprintln(os.Stderr, "blockvolume: durable recovery faulted; status endpoint remains available and local readiness remains blocked:", evidence)
sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
<-sig
signal.Stop(sig)
if durableProv != nil {
_ = durableProv.Close()
}
if status != nil {
shutCtx, shutCancel := context.WithTimeout(context.Background(), 2*time.Second)
_ = status.Close(shutCtx)
shutCancel()
}
if err := h.Close(); err != nil {
fmt.Fprintln(os.Stderr, "blockvolume: close:", err)
return 1
}
return 0
}
// deriveDualLaneAddr maps "host:port" → "host:port+1". Per
// docs/recovery-wiring-plan.md §4 Option A: dual-lane traffic uses a
// separate port from the legacy data port via this fixed convention.
@@ -205,6 +205,74 @@ func TestHost_ApplyFact_Self_UpdateReplicaSetFailure_SkipsOnAssignment(t *testin
}
}
func TestHost_ApplyFact_Self_LocalReadinessBlocked_SkipsReplicationAndAdapter(t *testing.T) {
rec := &orderingRecorder{}
h, a, r := newStubbedHost(t, "vol1", "r1", rec)
readyCh := make(chan adapter.AssignmentInfo, 1)
h.cfg.ReadyMarker = readyCh
h.BlockLocalReadiness("durable recovery failed: wal_integrity_fault")
fact := &control.AssignmentFact{
VolumeId: "vol1",
ReplicaId: "r1",
Epoch: 2,
EndpointVersion: 1,
PeerSetGeneration: 7,
Peers: []*control.ReplicaDescriptor{
{ReplicaId: "r1", DataAddr: "d1", CtrlAddr: "c1", Epoch: 2, EndpointVersion: 1},
},
}
h.applyFact(fact)
if got := r.callCount.Load(); got != 0 {
t.Fatalf("local readiness block must skip UpdateReplicaSet: got %d calls", got)
}
if got := a.callCount.Load(); got != 0 {
t.Fatalf("local readiness block must skip OnAssignment: got %d calls", got)
}
if seq := rec.snapshot(); len(seq) != 0 {
t.Fatalf("local readiness block sequence=%v want empty", seq)
}
select {
case got := <-readyCh:
t.Fatalf("local readiness block must not emit ready marker: %+v", got)
default:
}
}
func TestHost_ApplyFact_SupportingReplica_LocalReadinessBlocked_SkipsAdapter(t *testing.T) {
rec := &orderingRecorder{}
h, a, _ := newStubbedHost(t, "vol1", "r2", rec)
readyCh := make(chan adapter.AssignmentInfo, 1)
h.cfg.ReadyMarker = readyCh
h.BlockLocalReadiness("awaiting durable recovery")
fact := &control.AssignmentFact{
VolumeId: "vol1",
ReplicaId: "r1",
Epoch: 5,
EndpointVersion: 2,
Peers: []*control.ReplicaDescriptor{
{ReplicaId: "r2", DataAddr: "d2", CtrlAddr: "c2", Epoch: 5, EndpointVersion: 2},
},
}
h.applyFact(fact)
if got := a.callCount.Load(); got != 0 {
t.Fatalf("local readiness block must skip supporting OnAssignment: got %d calls", got)
}
if seq := rec.snapshot(); len(seq) != 0 {
t.Fatalf("local readiness block sequence=%v want empty", seq)
}
select {
case got := <-readyCh:
t.Fatalf("local readiness block must not emit supporting ready marker: %+v", got)
default:
}
}
// --- Test 3: supersede branch unaffected ---
// TestHost_ApplyFact_Supersede_NeverCallsAdapterOrReplication —
+43
View File
@@ -123,6 +123,9 @@ type Host struct {
readyMarkerMu sync.Mutex
supportingReadyMarks map[string]struct{}
localReadinessBlocked atomic.Bool
localReadinessReason atomic.Value // string
// lastOtherLine captures the most recent AssignmentFact that
// named a REPLICA OTHER than self for this host's VolumeID.
// Populated when the master's volume-scoped subscription
@@ -229,6 +232,35 @@ func New(cfg Config) (*Host, error) {
return h, nil
}
// BlockLocalReadiness prevents assignment facts from entering the local
// adapter while preserving heartbeat/status serving. Use this when local
// storage evidence says this replica must not publish Healthy.
func (h *Host) BlockLocalReadiness(reason string) {
if reason == "" {
reason = "local readiness blocked"
}
h.localReadinessReason.Store(reason)
h.localReadinessBlocked.Store(true)
}
// ClearLocalReadinessBlock allows future assignment stream replays to enter
// the adapter after local startup/recovery evidence is clean.
func (h *Host) ClearLocalReadinessBlock() {
h.localReadinessReason.Store("")
h.localReadinessBlocked.Store(false)
}
func (h *Host) localReadinessBlock() (bool, string) {
if !h.localReadinessBlocked.Load() {
return false, ""
}
reason, _ := h.localReadinessReason.Load().(string)
if reason == "" {
reason = "local readiness blocked"
}
return true, reason
}
// SetReplicationVolume installs (or replaces) the per-volume
// replication fan-out coordinator AFTER Host.New. Used by the
// production binary path: storage isn't available until the durable
@@ -539,6 +571,11 @@ func (h *Host) applyFact(fact *control.AssignmentFact) {
// unhealthy even if its local engine is otherwise caught up.
h.recordOtherLine(fact)
if info, ok := decodeSelfPeerAssignment(fact, h.cfg.ReplicaID); ok {
if blocked, reason := h.localReadinessBlock(); blocked {
h.log.Printf("blockvolume: volume %s local readiness blocked (%s); NOT admitting supporting replica %s at epoch=%d EV=%d",
h.cfg.VolumeID, reason, info.ReplicaID, info.Epoch, info.EndpointVersion)
return
}
h.adpt.OnAssignment(info)
h.log.Printf("blockvolume: volume %s admitted as SUPPORTING replica %s at epoch=%d EV=%d behind primary %s; frontend remains gated",
h.cfg.VolumeID, info.ReplicaID, info.Epoch, info.EndpointVersion, fact.ReplicaId)
@@ -553,6 +590,12 @@ func (h *Host) applyFact(fact *control.AssignmentFact) {
return
}
if blocked, reason := h.localReadinessBlock(); blocked {
h.log.Printf("blockvolume: volume %s local readiness blocked (%s); NOT applying primary assignment %s@%d to adapter",
h.cfg.VolumeID, reason, fact.ReplicaId, fact.Epoch)
return
}
// Step (2a): install replication peer set first. Decoded via
// the separate host-only decodeReplicaTargets path (not through
// AssignmentInfo), so the TestNoOtherAssignmentInfoConstruction