volume, replication: a node taking the primary role moves its ship order to its store

A replica applies entries through replication, so its store's next LSN
moves while the write observer's ship cursor stays where the observer was
installed. Promoted, its first local write waited in the LSN resequencer
for an entry that never comes as a local write, and every write after a
failover failed at its deadline. On a transition into the primary role
(listener fenced as primary, frontend not serving yet) the host moves the
ship cursor to the store's next LSN.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Opus 5.5 committed 2026-11-25 06:51:32 -08:00
1 parent f35678dece
commit aa074bc05f
2 files changed
+22

No files matched your search

+16
View File
@@ -933,6 +933,9 @@ func (h *Host) applyFact(fact *control.AssignmentFact) {
// Step (2c): identity install only after replication is live.
// SOLE permitted decode path. See subscribe.go.
info := decodeAssignmentFact(fact)
h.selfFenceMu.Lock()
wasPrimary := h.selfRole == selfRolePrimary
h.selfFenceMu.Unlock()
// G2: fence our own replica listener at this epoch before the adapter
// can turn Healthy and the frontend serves IO, so a deposed primary that
// still reaches us cannot get its writes applied (or counted) here.
@@ -943,6 +946,19 @@ func (h *Host) applyFact(fact *control.AssignmentFact) {
h.cfg.VolumeID, info.Epoch, err)
return
}
// A node taking the primary role from another role holds entries it
// applied as a replica, which never passed its own ship order: move the
// ship cursor to the store's next LSN before it serves, or its first
// write waits for an LSN that never comes. Its listener is fenced as
// primary now (no replicated entry lands any more) and the frontend is
// not serving yet (no local write is pending).
if r, ok := rv.(interface{ RebaseShipToStore() error }); ok && rv != nil && !wasPrimary {
if err := r.RebaseShipToStore(); err != nil {
h.log.Printf("blockvolume: volume %s could not move its ship order to the store at epoch %d: %v — NOT applying to adapter (fail-closed)",
h.cfg.VolumeID, info.Epoch, err)
return
}
}
if h.cfg.RF1Only != "" && !h.admitRF1(fact.Epoch) {
h.log.Printf("blockvolume: volume %s RF1 assignment at epoch %d overtaken by a newer refusal — NOT applying to adapter",
h.cfg.VolumeID, fact.Epoch)
+6
View File
@@ -734,6 +734,12 @@ func (v *ReplicationVolume) enqueueLocalWrite(w LocalWrite) (*orderedLocalWrite,
return req, nil
}
// RebaseShipToStore moves the ship order to the store's next LSN, for a
// node taking the primary role after applying entries as a replica.
func (v *ReplicationVolume) RebaseShipToStore() error {
return v.RebaseShipLSN(v.store.NextLSN())
}
// RebaseShipLSN moves the next LSN to ship forward to lsn. The volume
// orders writes from the store's next LSN, captured when it was built; a
// restored host's frontier seed (its WAL continues at HEAD.remote_lsn+1)