volume: the per-peer engine gets this primary's frontier at the add as its start position

With the degraded-peer probe loop on, a peer the seed barrier degraded for a
divergent tail would otherwise be probed, classified caught up (R >= H) and
fenced back into healthy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Opus 5.5 committed 2026-11-24 22:26:47 -08:00
1 parent bca75dc945
commit 028351bcdc
4 files changed
+66

No files matched your search

+1
View File
@@ -979,6 +979,7 @@ func runVolume(f flags, exits *processExit) int {
// ProductionProbeFn routes per-peer via this registry so
// engine.checkReplicaID accepts the events.
peerRegistry := volume.NewPeerAdapterRegistry(f.volumeID, f.replicaID)
peerRegistry.SetFrontier(store.Sync)
if err := replVolume.ConfigurePeerLifecycleHook(peerRegistry.OnPeerAdded, peerRegistry.OnPeerRemoved); err != nil {
fmt.Fprintln(os.Stderr, "blockvolume: peer lifecycle hook:", err)
_ = replVolume.Close()
+2
View File
@@ -33,6 +33,7 @@ type AssignmentInfo struct {
EndpointVersion uint64
DataAddr string
CtrlAddr string
PrimaryStartLSN uint64 // see engine.AssignmentObserved.PrimaryStartLSN; 0 = not known
}
// ProbeResult is the outcome of a transport probe.
@@ -110,6 +111,7 @@ func NormalizeAssignment(a AssignmentInfo) engine.Event {
EndpointVersion: a.EndpointVersion,
DataAddr: a.DataAddr,
CtrlAddr: a.CtrlAddr,
PrimaryStartLSN: a.PrimaryStartLSN,
}
}
@@ -0,0 +1,40 @@
package volume
import (
"errors"
"strings"
"testing"
"github.com/seaweedfs/seaweed-block/core/adapter"
)
// The registry hands each added peer's engine this primary's frontier at the
// add as its start position, so a probe that finds the peer above it pins a
// rebuild instead of fencing it into healthy on length.
func TestPeerAdapterRegistry_DivergentTailAboveTheFrontierAtAddIsRebuilt(t *testing.T) {
for _, c := range []struct {
name string
frontier func() (uint64, error)
want string
}{
{"frontier known", func() (uint64, error) { return 90, nil }, "StartRebuild"},
{"frontier unknown", func() (uint64, error) { return 0, errors.New("sync failed") }, "FenceAtEpoch"},
} {
t.Run(c.name, func(t *testing.T) {
reg := NewPeerAdapterRegistry("vol1", "r1")
reg.SetFrontier(c.frontier)
reg.OnPeerAdded(newPeerForRegistryTest(t, "r2", 2, 1))
adpt := reg.AdapterFor("r2")
if adpt == nil {
t.Fatal("no adapter for r2")
}
adpt.OnProbeResult(adapter.ProbeResult{
ReplicaID: "r2", Success: true, EndpointVersion: 1, TransportEpoch: 2,
ReplicaFlushedLSN: 100, PrimaryTailLSN: 10, PrimaryHeadLSN: 95,
})
if log := strings.Join(adpt.CommandLog(), " "); !strings.Contains(log, c.want) {
t.Fatalf("commands %q; want %s", log, c.want)
}
})
}
}
@@ -30,11 +30,25 @@ type PeerAdapterRegistry struct {
volumeID string
selfReplicaID string // sanity guard: never register the host's own slot
// frontier is this primary's local durable frontier (nil = not known).
// A peer added here has received nothing from this primary at its
// lineage, so the frontier at the add is the start position above
// which anything the peer holds is a divergent old-epoch tail.
frontier func() (uint64, error)
mu sync.Mutex
adapters map[string]*adapter.VolumeReplicaAdapter // keyed by ReplicaID
closed bool
}
// SetFrontier installs the local durable frontier read at each peer add
// (the store's Sync). Call before peers are added.
func (r *PeerAdapterRegistry) SetFrontier(fn func() (uint64, error)) {
if r != nil {
r.frontier = fn
}
}
// NewPeerAdapterRegistry constructs an empty registry for the given
// volume. selfReplicaID is the host's own slot — used as a sanity
// guard so we never accidentally register the host's own slot
@@ -91,6 +105,14 @@ func (r *PeerAdapterRegistry) OnPeerAdded(peer *replication.ReplicaPeer) {
// apply.go: "Engine not yet initialized — accept"), but having
// AssignmentObserved fire first matches the production master-
// driven path semantics: identity comes BEFORE probe.
var start uint64
if r.frontier != nil {
if lsn, err := r.frontier(); err == nil {
start = lsn
} else {
log.Printf("PeerAdapterRegistry: peer=%s frontier unknown (%v): no divergent-tail check", target.ReplicaID, err)
}
}
adpt.OnAssignment(adapter.AssignmentInfo{
VolumeID: r.volumeID,
ReplicaID: target.ReplicaID,
@@ -98,6 +120,7 @@ func (r *PeerAdapterRegistry) OnPeerAdded(peer *replication.ReplicaPeer) {
EndpointVersion: target.EndpointVersion,
DataAddr: target.DataAddr,
CtrlAddr: target.ControlAddr,
PrimaryStartLSN: start,
})
r.adapters[target.ReplicaID] = adpt