mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 02:57:37 +01:00
fix, replication: route peer session exchanges through one queue
This commit is contained in:
1 parent
51f5c6806d
commit
e6a8aa021a
6 files changed
+272
-17
No files matched your search
@@ -149,6 +149,7 @@ type ReplicaPeer struct {
|
||||
mu sync.Mutex
|
||||
state ReplicaState
|
||||
closed bool
|
||||
queue *peerWorkQueue
|
||||
// storeID is the store the peer's last successful barrier reported,
|
||||
// cleared whenever the peer leaves Healthy: a store is attested only
|
||||
// by a barrier it answered while counting toward write ACKs.
|
||||
@@ -206,6 +207,10 @@ type ReplicaPeerStatus struct {
|
||||
// is responsible for executor lifecycle. Peer does not close the
|
||||
// executor.
|
||||
func NewReplicaPeer(target ReplicaTarget, executor *transport.BlockExecutor) (*ReplicaPeer, error) {
|
||||
return newReplicaPeer(target, executor, defaultPeerWorkQueueDepth)
|
||||
}
|
||||
|
||||
func newReplicaPeer(target ReplicaTarget, executor *transport.BlockExecutor, depth int) (*ReplicaPeer, error) {
|
||||
if executor == nil {
|
||||
return nil, fmt.Errorf("replication: NewReplicaPeer: executor is nil")
|
||||
}
|
||||
@@ -224,7 +229,7 @@ func NewReplicaPeer(target ReplicaTarget, executor *transport.BlockExecutor) (*R
|
||||
if err := executor.RegisterLiveShipSession(lineage); err != nil {
|
||||
return nil, fmt.Errorf("replication: NewReplicaPeer: register session: %w", err)
|
||||
}
|
||||
return &ReplicaPeer{
|
||||
p := &ReplicaPeer{
|
||||
target: target,
|
||||
executor: executor,
|
||||
sessionID: sessionID,
|
||||
@@ -232,7 +237,9 @@ func NewReplicaPeer(target ReplicaTarget, executor *transport.BlockExecutor) (*R
|
||||
state: ReplicaHealthy,
|
||||
cooldownCfg: DefaultPeerProbeCooldown(),
|
||||
expected: target.StoreID,
|
||||
}, nil
|
||||
}
|
||||
p.queue = newPeerWorkQueue(p, depth)
|
||||
return p, nil
|
||||
}
|
||||
|
||||
// RefreshLiveShipSessionAfter rotates the peer's steady live-ship
|
||||
@@ -580,6 +587,32 @@ func (p *ReplicaPeer) Status() ReplicaPeerStatus {
|
||||
// Borrows: data slice — caller retains, ShipEntry does not mutate
|
||||
// and does not retain past return.
|
||||
func (p *ReplicaPeer) ShipEntry(ctx context.Context, lineage transport.RecoveryLineage, lba uint32, lsn uint64, data []byte) error {
|
||||
_ = lineage // the peer owns its live lineage
|
||||
if err := ctx.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
// The caller may stop waiting on cancellation; the worker must then have
|
||||
// its own immutable copy until the exchange completes.
|
||||
data = append([]byte(nil), data...)
|
||||
p.mu.Lock()
|
||||
q, closed := p.queue, p.closed
|
||||
p.mu.Unlock()
|
||||
if closed {
|
||||
return ErrPeerQueueClosed
|
||||
}
|
||||
result := make(chan peerWorkResult, 1)
|
||||
if _, err := q.enqueueWrite(LocalWrite{LBA: lba, LSN: lsn, Data: data}, result); err != nil {
|
||||
return err
|
||||
}
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
case r := <-result:
|
||||
return r.err
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ReplicaPeer) shipEntry(ctx context.Context, lineage transport.RecoveryLineage, lba uint32, lsn uint64, data []byte) error {
|
||||
_ = lineage // peer-owned lineage; caller param is informational.
|
||||
if err := ctx.Err(); err != nil {
|
||||
return err
|
||||
@@ -639,12 +672,30 @@ func (p *ReplicaPeer) ShipEntry(ctx context.Context, lineage transport.RecoveryL
|
||||
// Caller uses targetLSN at the coordinator layer (comparing against
|
||||
// ack.AchievedLSN) to decide per-mode durability arithmetic.
|
||||
//
|
||||
// Called by: peerWorkQueue for the production ordered barrier path, and by
|
||||
// DurabilityCoordinator.SyncLocalAndReplicas in synchronous contract tests.
|
||||
// Called by: reconciliation, promotion seeding and the durability coordinator.
|
||||
// All callers use the peer's one worker; the ordered durability queue invokes
|
||||
// barrier directly from that worker, never recursively queues itself.
|
||||
// Owns: the error → Invalidate translation (peer state mutation).
|
||||
// Borrows: ctx + targetLSN from caller; lineage is read from peer's
|
||||
// own registered state.
|
||||
func (p *ReplicaPeer) Barrier(ctx context.Context, targetLSN uint64) (transport.BarrierAck, error) {
|
||||
return p.exchange(ctx, func(ctx context.Context) (transport.BarrierAck, error) {
|
||||
return p.barrier(ctx, targetLSN)
|
||||
})
|
||||
}
|
||||
|
||||
func (p *ReplicaPeer) exchange(ctx context.Context, fn func(context.Context) (transport.BarrierAck, error)) (transport.BarrierAck, error) {
|
||||
p.mu.Lock()
|
||||
q := p.queue
|
||||
closed := p.closed
|
||||
p.mu.Unlock()
|
||||
if closed {
|
||||
return transport.BarrierAck{}, ErrPeerQueueClosed
|
||||
}
|
||||
return q.exchange(ctx, fn)
|
||||
}
|
||||
|
||||
func (p *ReplicaPeer) barrier(ctx context.Context, targetLSN uint64) (transport.BarrierAck, error) {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return transport.BarrierAck{}, err
|
||||
}
|
||||
@@ -723,6 +774,13 @@ func (p *ReplicaPeer) learningStore() bool {
|
||||
// Owns: error → Invalidate translation on failure.
|
||||
// Borrows: ctx + lineage from caller.
|
||||
func (p *ReplicaPeer) Fence(ctx context.Context, lineage transport.RecoveryLineage) error {
|
||||
_, err := p.exchange(ctx, func(ctx context.Context) (transport.BarrierAck, error) {
|
||||
return transport.BarrierAck{}, p.fence(ctx, lineage)
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *ReplicaPeer) fence(ctx context.Context, lineage transport.RecoveryLineage) error {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -950,10 +1008,12 @@ func (p *ReplicaPeer) Close() error {
|
||||
return nil
|
||||
}
|
||||
p.closed = true
|
||||
queue := p.queue
|
||||
sessionID := p.sessionID
|
||||
replicaID := p.target.ReplicaID
|
||||
p.state = ReplicaUnknown
|
||||
p.mu.Unlock()
|
||||
p.executor.InvalidateSession(replicaID, sessionID, "replica peer closed")
|
||||
queue.closeAndWait()
|
||||
return nil
|
||||
}
|
||||
@@ -28,6 +28,7 @@ const (
|
||||
// that never degrades it). It runs on the queue's one worker, so it
|
||||
// never overlaps a ship or a data barrier on the peer's connection.
|
||||
peerWorkLearnStore
|
||||
peerWorkExchange
|
||||
)
|
||||
|
||||
type peerWorkResult struct {
|
||||
@@ -35,6 +36,7 @@ type peerWorkResult struct {
|
||||
eligible bool
|
||||
ackLSN uint64
|
||||
err error
|
||||
ack transport.BarrierAck
|
||||
}
|
||||
|
||||
type peerWork struct {
|
||||
@@ -42,6 +44,8 @@ type peerWork struct {
|
||||
write LocalWrite
|
||||
targetLSN uint64
|
||||
result chan<- peerWorkResult
|
||||
ctx context.Context
|
||||
exchange func(context.Context) (transport.BarrierAck, error)
|
||||
}
|
||||
|
||||
type peerWorkQueueOps struct {
|
||||
@@ -57,10 +61,12 @@ type peerWorkQueue struct {
|
||||
peerID string
|
||||
ops peerWorkQueueOps
|
||||
|
||||
ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
jobs chan peerWork
|
||||
done chan struct{}
|
||||
ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
jobs chan peerWork
|
||||
done chan struct{}
|
||||
stop chan struct{}
|
||||
stopping bool
|
||||
|
||||
mu sync.Mutex
|
||||
closed bool
|
||||
@@ -71,7 +77,7 @@ func newPeerWorkQueue(peer *ReplicaPeer, depth int) *peerWorkQueue {
|
||||
return newPeerWorkQueueWithOps(peer.Target().ReplicaID, depth, peerWorkQueueOps{
|
||||
ship: func(ctx context.Context, write LocalWrite) (bool, error) {
|
||||
eligible := peer.countsTowardAcks()
|
||||
err := peer.ShipEntry(ctx, transport.RecoveryLineage{}, write.LBA, write.LSN, write.Data)
|
||||
err := peer.shipEntry(ctx, transport.RecoveryLineage{}, write.LBA, write.LSN, write.Data)
|
||||
return eligible, err
|
||||
},
|
||||
barrier: func(ctx context.Context, targetLSN uint64) (uint64, error) {
|
||||
@@ -79,7 +85,7 @@ func newPeerWorkQueue(peer *ReplicaPeer, depth int) *peerWorkQueue {
|
||||
if s := peer.State(); s != ReplicaHealthy {
|
||||
return 0, fmt.Errorf("%w: peer %s is %s", ErrPeerNotInSync, peer.Target().ReplicaID, s)
|
||||
}
|
||||
ack, err := peer.Barrier(ctx, targetLSN)
|
||||
ack, err := peer.barrier(ctx, targetLSN)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -113,6 +119,7 @@ func newPeerWorkQueueWithOps(peerID string, depth int, ops peerWorkQueueOps) *pe
|
||||
cancel: cancel,
|
||||
jobs: make(chan peerWork, depth),
|
||||
done: make(chan struct{}),
|
||||
stop: make(chan struct{}),
|
||||
}
|
||||
go q.run()
|
||||
return q
|
||||
@@ -170,6 +177,10 @@ func (q *peerWorkQueue) enqueue(work peerWork) (int, error) {
|
||||
|
||||
func (q *peerWorkQueue) closeAndWait() {
|
||||
q.mu.Lock()
|
||||
if !q.stopping {
|
||||
q.stopping = true
|
||||
close(q.stop)
|
||||
}
|
||||
if !q.closed {
|
||||
q.closed = true
|
||||
q.terminalErr = fmt.Errorf("%w: peer %s", ErrPeerQueueClosed, q.peerID)
|
||||
@@ -179,6 +190,29 @@ func (q *peerWorkQueue) closeAndWait() {
|
||||
<-q.done
|
||||
}
|
||||
|
||||
// exchange admits a reconciliation even after steady-work saturation: healing
|
||||
// must use the same worker before the volume can reopen steady admission.
|
||||
// It waits for capacity rather than saturating the steady-write queue.
|
||||
func (q *peerWorkQueue) exchange(ctx context.Context, fn func(context.Context) (transport.BarrierAck, error)) (transport.BarrierAck, error) {
|
||||
result := make(chan peerWorkResult, 1)
|
||||
work := peerWork{kind: peerWorkExchange, ctx: ctx, exchange: fn, result: result}
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return transport.BarrierAck{}, ctx.Err()
|
||||
case <-q.stop:
|
||||
return transport.BarrierAck{}, q.closedError()
|
||||
case q.jobs <- work:
|
||||
}
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return transport.BarrierAck{}, ctx.Err()
|
||||
case <-q.done:
|
||||
return transport.BarrierAck{}, q.closedError()
|
||||
case r := <-result:
|
||||
return r.ack, r.err
|
||||
}
|
||||
}
|
||||
|
||||
func (q *peerWorkQueue) isTerminal() bool {
|
||||
q.mu.Lock()
|
||||
defer q.mu.Unlock()
|
||||
@@ -190,21 +224,27 @@ func (q *peerWorkQueue) run() {
|
||||
defer q.failPending()
|
||||
for {
|
||||
select {
|
||||
case <-q.ctx.Done():
|
||||
case <-q.stop:
|
||||
return
|
||||
default:
|
||||
}
|
||||
|
||||
select {
|
||||
case <-q.ctx.Done():
|
||||
case <-q.stop:
|
||||
return
|
||||
case work := <-q.jobs:
|
||||
if err := q.ctx.Err(); err != nil {
|
||||
if err := q.ctx.Err(); err != nil && work.kind != peerWorkExchange {
|
||||
q.complete(work, peerWorkResult{peerID: q.peerID, err: q.closedError()})
|
||||
return
|
||||
continue
|
||||
}
|
||||
result := peerWorkResult{peerID: q.peerID}
|
||||
switch work.kind {
|
||||
case peerWorkExchange:
|
||||
if err := work.ctx.Err(); err != nil {
|
||||
result.err = err
|
||||
} else {
|
||||
result.ack, result.err = work.exchange(work.ctx)
|
||||
}
|
||||
case peerWorkWrite:
|
||||
result.eligible, result.err = q.ops.ship(q.ctx, work.write)
|
||||
case peerWorkBarrier:
|
||||
|
||||
@@ -5,8 +5,50 @@ import (
|
||||
"errors"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/transport"
|
||||
)
|
||||
|
||||
func TestSaturatedPeerQueueStillOwnsTheHealingExchange(t *testing.T) {
|
||||
started, release := make(chan struct{}), make(chan struct{})
|
||||
q := newPeerWorkQueueWithOps("r2", 1, peerWorkQueueOps{
|
||||
ship: func(context.Context, LocalWrite) (bool, error) {
|
||||
close(started)
|
||||
<-release
|
||||
return false, nil
|
||||
},
|
||||
})
|
||||
defer q.closeAndWait()
|
||||
results := make(chan peerWorkResult, 2)
|
||||
if _, err := q.enqueueWrite(LocalWrite{LSN: 1}, results); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
<-started
|
||||
if _, err := q.enqueueWrite(LocalWrite{LSN: 2}, results); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := q.enqueueWrite(LocalWrite{LSN: 3}, results); !errors.Is(err, ErrPeerQueueSaturated) {
|
||||
t.Fatalf("saturation: %v", err)
|
||||
}
|
||||
close(release)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||
defer cancel()
|
||||
ack, err := q.exchange(ctx, func(context.Context) (transport.BarrierAck, error) {
|
||||
return transport.BarrierAck{AchievedLSN: 7}, nil
|
||||
})
|
||||
if err != nil || ack.AchievedLSN != 7 {
|
||||
t.Fatalf("healing exchange: ack=%+v err=%v", ack, err)
|
||||
}
|
||||
<-results
|
||||
if r := <-results; !errors.Is(r.err, ErrPeerQueueSaturated) {
|
||||
t.Fatalf("pending steady work escaped terminal gate: %v", r.err)
|
||||
}
|
||||
if _, err := q.enqueueWrite(LocalWrite{LSN: 4}, results); !errors.Is(err, ErrPeerQueueSaturated) {
|
||||
t.Fatalf("healing exchange reopened steady admission: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPeerWorkQueue_PreservesWriteBarrierOrder(t *testing.T) {
|
||||
var (
|
||||
mu sync.Mutex
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
package replication
|
||||
|
||||
import (
|
||||
"go/ast"
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// These are the steady-session wire operations, their worker-only bodies and
|
||||
// their public queue doors. A new caller must declare its ownership here.
|
||||
func TestPeerSessionExchangesHaveOnlyQueuedOwners(t *testing.T) {
|
||||
want := []string{
|
||||
"peer.go:Barrier:exchange", "peer.go:Fence:exchange",
|
||||
"peer.go:Barrier:barrier", "peer.go:Fence:fence",
|
||||
"peer.go:barrier:Barrier", "peer.go:fence:FenceSync", "peer.go:learnStore:Barrier",
|
||||
"peer.go:shipEntry:FeedLiveWrite",
|
||||
"peer_work_queue.go:newPeerWorkQueue:barrier", "peer_work_queue.go:newPeerWorkQueue:shipEntry",
|
||||
"peer_work_queue.go:newPeerWorkQueue:learnStore",
|
||||
"peer_work_queue.go:run:barrier", "peer_work_queue.go:run:learnStore", "peer_work_queue.go:run:learnStore",
|
||||
"peer.go:exchange:exchange", "peer_work_queue.go:run:exchange",
|
||||
"volume.go:reconcilePeer:Barrier", "volume.go:seedNewPeerLiveCursorsLocked:Barrier",
|
||||
"durability.go:SyncLocalAndReplicas:Barrier",
|
||||
}
|
||||
var got []string
|
||||
entries, err := os.ReadDir(".")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, entry := range entries {
|
||||
name := entry.Name()
|
||||
if entry.IsDir() || !strings.HasSuffix(name, ".go") || strings.HasSuffix(name, "_test.go") {
|
||||
continue
|
||||
}
|
||||
source, err := os.ReadFile(name)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
rows, err := sessionExchangeSites(name, source)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got = append(got, rows...)
|
||||
}
|
||||
sort.Strings(got)
|
||||
sort.Strings(want)
|
||||
if !reflect.DeepEqual(got, want) {
|
||||
t.Fatalf("session exchange owners changed:\n got %v\nwant %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func sessionExchangeSites(name string, source []byte) ([]string, error) {
|
||||
f, err := parser.ParseFile(token.NewFileSet(), name, source, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var rows []string
|
||||
for _, decl := range f.Decls {
|
||||
fn, ok := decl.(*ast.FuncDecl)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
ast.Inspect(fn, func(n ast.Node) bool {
|
||||
sel, ok := n.(*ast.SelectorExpr)
|
||||
if !ok {
|
||||
return true
|
||||
}
|
||||
tracked := false
|
||||
switch sel.Sel.Name {
|
||||
case "barrier", "shipEntry", "learnStore", "fence", "FeedLiveWrite", "FenceSync":
|
||||
tracked = true
|
||||
case "exchange":
|
||||
tracked = true
|
||||
case "Barrier":
|
||||
// Public ReplicaPeer.Barrier is a queue door; a transport
|
||||
// executor call belongs only in the two worker bodies.
|
||||
tracked = true
|
||||
}
|
||||
if tracked {
|
||||
rows = append(rows, filepath.Base(name)+":"+fn.Name.Name+":"+sel.Sel.Name)
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
return rows, nil
|
||||
}
|
||||
|
||||
func TestPeerSessionOwnerScanFindsABypass(t *testing.T) {
|
||||
rows, err := sessionExchangeSites("bypass.go", []byte(`package replication
|
||||
func bypass(p *ReplicaPeer) { p.executor.Barrier("r2", lineage, 0) }`))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !reflect.DeepEqual(rows, []string{"bypass.go:bypass:Barrier"}) {
|
||||
t.Fatalf("missed bypass: %v", rows)
|
||||
}
|
||||
}
|
||||
@@ -506,7 +506,7 @@ func (v *ReplicationVolume) UpdateReplicaSet(generation uint64, targets []Replic
|
||||
v.sessionIDs[id] = ids
|
||||
}
|
||||
executor.UseSessionIDs(ids)
|
||||
peer, err := NewReplicaPeer(t, executor)
|
||||
peer, err := newReplicaPeer(t, executor, v.peerQueueDepth)
|
||||
if err != nil {
|
||||
v.mu.Unlock()
|
||||
executor.Stop()
|
||||
@@ -536,7 +536,7 @@ func (v *ReplicationVolume) UpdateReplicaSet(generation uint64, targets []Replic
|
||||
}
|
||||
v.peers[id] = peer
|
||||
v.executors[id] = executor
|
||||
v.peerQueues[id] = newPeerWorkQueue(peer, v.peerQueueDepth)
|
||||
v.peerQueues[id] = peer.queue
|
||||
// Notify peer-lifecycle hook AFTER the peer is installed in
|
||||
// the map so the host's registry can construct the per-peer
|
||||
// adapter and prime it with the peer's identity.
|
||||
@@ -669,6 +669,9 @@ func (v *ReplicationVolume) replaceTerminalPeerQueueLocked(id string, old *peerW
|
||||
}
|
||||
old.closeAndWait()
|
||||
replacement := newPeerWorkQueue(peer, v.peerQueueDepth)
|
||||
peer.mu.Lock()
|
||||
peer.queue = replacement
|
||||
peer.mu.Unlock()
|
||||
v.peerQueues[id] = replacement
|
||||
return replacement
|
||||
}
|
||||
|
||||
@@ -259,10 +259,18 @@ RF2 qualification limitation until ordered-live certification is wired (#297). S
|
||||
|
||||
**Peer state, as the primary sees each replica** (type `ReplicaState` in `core/replication/peer.go`). A new peer starts `Healthy` (`NewReplicaPeer`).
|
||||
|
||||
The peer queue owns steady-session exchanges, including reconciliation,
|
||||
promotion seed barriers and durability-coordinator barriers. Only its worker
|
||||
invokes the raw ship, barrier, store-learning and fence bodies. Saturation
|
||||
closes steady admission; reconciliation still uses that same worker so a
|
||||
successful heal can reopen admission. Closing the peer stops the worker.
|
||||
See `INV-REPL-SESSION-ONE-EXCHANGE-001` (`SessionOrder`).
|
||||
|
||||
| From | To | Event and guard | Enforced in | Protects |
|
||||
|---|---|---|---|---|
|
||||
| `Healthy`, `Unknown` | `Degraded` or `CatchingUp` | ship, barrier or fence failure; or a probe that needs catch-up | `core/replication/peer.go` `ReplicaPeer.SetState`, `replicaStateTransitionAllowed` | `INV-REPL-PEER-TRANSITIONS-001` |
|
||||
| `Healthy` | `Degraded`, then `NeedsRebuild` | the promotion seed barrier, or a heal (engine healthy verdict, recovery session done), reconciles the peer by (last data epoch, end) against the epoch table and finds it diverged; a sync barrier counts only a `Healthy` peer | `core/replication/volume.go` `seedNewPeerLiveCursorsLocked`, `reconcilePeer`; `core/replication/peer.go` `HealIfInSync`; `core/replication/peer_work_queue.go` | `INV-REPL-DIVERGENT-TAIL-001`, `INV-REPL-EPOCH-TABLE-001` |
|
||||
| `Healthy` | `Degraded`, then `NeedsRebuild` | the promotion seed barrier, or a heal (engine healthy verdict, recovery session done), reconciles the peer by (last data epoch, end) against the epoch table and finds it diverged; a sync barrier counts only a `Healthy` peer | `core/replication/volume.go` `seedNewPeerLiveCursorsLocked`, `reconcilePeer`; `core/replication/peer.go` `HealIfInSync`; `core/replication/peer_work_queue.go` | `INV-REPL-SESSION-ONE-EXCHANGE-001` | At most one steady-session exchange is in flight per peer: the peer queue owns ship, barrier, store learning and fence; reconciliation and promotion seeding use it too. Saturation refuses steady work while healing stays on the same worker. | M3 peer session exchange ordering | `core/replication/peer.go`; `core/replication/peer_work_queue.go` | `TestPublishHealthyDoesNotRaceStoreAttestation` (`core/host/volume/peer_reconcile_attestation_test.go`); `TestPeerSessionExchangesHaveOnlyQueuedOwners`, `TestPeerSessionOwnerScanFindsABypass` (`core/replication/session_queue_guard_test.go`); `TestSaturatedPeerQueueStillOwnsTheHealingExchange` (`core/replication/peer_work_queue_test.go`) | `SessionOrder` one exchange in flight per session | ACTIVE |
|
||||
| `INV-REPL-DIVERGENT-TAIL-001`, `INV-REPL-EPOCH-TABLE-001` |
|
||||
| `Degraded` | `CatchingUp` or `NeedsRebuild` | the engine decides catch-up when the gap is in the primary WAL, rebuild when it is not | `core/engine/apply.go` `decide` | `INV-REPL-CATCHUP-REBUILD-001`, `INV-REPL-RECOVERY-SESSION-UNIQUE-001` |
|
||||
| `CatchingUp` | `Healthy`, `Degraded` or `NeedsRebuild` | done-acknowledgement; failure; WAL recycled or retries exhausted | `core/replication/peer.go` `ReplicaPeer.SetState` | `INV-REPL-PEER-TRANSITIONS-001` |
|
||||
| any but `NeedsRebuild` | `Healthy` | recovered | `core/replication/peer.go` `replicaStateTransitionAllowed` | `INV-REPL-PEER-TRANSITIONS-001` |
|
||||
|
||||
Reference in new issue
Block a user