Skip to content

Commit

Permalink
Wait for recovery to complete before sending snapshot on stream scale…
Browse files Browse the repository at this point in the history
…-up from R1 (#5001)

This PR ensures that we don't try to generate and send a snapshot to
catch up followers on a stream scale-up from an R1 until recovery has
completed.

Signed-off-by: Neil Twigg <neil@nats.io>
  • Loading branch information
derekcollison committed Jan 26, 2024
2 parents b85068a + c356bc8 commit 98b4e22
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions server/jetstream_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -2313,7 +2313,7 @@ func (js *jetStream) monitorStream(mset *stream, sa *streamAssignment, sendSnaps
// We can arrive here NOT being the leader, so we send the snapshot only if we are, and in this case
// reset the notion that we need to send the snapshot. If we are not, then the first time the server
// will switch to leader (in the loop below), we will send the snapshot.
if sendSnapshot && isLeader && mset != nil && n != nil {
if sendSnapshot && isLeader && mset != nil && n != nil && !isRecovering {
n.SendSnapshot(mset.stateSnapshot())
sendSnapshot = false
}
Expand All @@ -2337,6 +2337,12 @@ func (js *jetStream) monitorStream(mset *stream, sa *streamAssignment, sendSnaps
if _, b := n.Size(); b > compactSizeMin || n.NeedSnapshot() {
doSnapshot()
}
// If we became leader during this time and we need to send a snapshot to our
// followers, i.e. as a result of a scale-up from R1, do it now.
if sendSnapshot && isLeader && mset != nil && n != nil {
n.SendSnapshot(mset.stateSnapshot())
sendSnapshot = false
}
continue
}
// Apply our entries.
Expand Down Expand Up @@ -2376,7 +2382,9 @@ func (js *jetStream) monitorStream(mset *stream, sa *streamAssignment, sendSnaps

case isLeader = <-lch:
if isLeader {
if mset != nil && n != nil && sendSnapshot {
if mset != nil && n != nil && sendSnapshot && !isRecovering {
// If we *are* recovering at the time then this will get done when the apply queue
// handles the nil guard to show the catchup ended.
n.SendSnapshot(mset.stateSnapshot())
sendSnapshot = false
}
Expand Down

0 comments on commit 98b4e22

Please sign in to comment.