Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIXED] Fix install stream snapshots on graceful shutdown #5809

Merged
merged 2 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions server/jetstream_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -2261,7 +2261,12 @@ func (js *jetStream) monitorStream(mset *stream, sa *streamAssignment, sendSnaps
// Make sure to stop the raft group on exit to prevent accidental memory bloat.
// This should be below the checkInMonitor call though to avoid stopping it out
// from underneath the one that is running since it will be the same raft node.
defer n.Stop()
defer func() {
// We might be closing during shutdown, don't pre-emptively stop here since we'll still want to install snapshots.
if !mset.closed.Load() {
derekcollison marked this conversation as resolved.
Show resolved Hide resolved
n.Stop()
}
}()

qch, mqch, lch, aq, uch, ourPeerId := n.QuitC(), mset.monitorQuitC(), n.LeadChangeC(), n.ApplyQ(), mset.updateC(), meta.ID()

Expand Down Expand Up @@ -3133,13 +3138,10 @@ func (js *jetStream) applyStreamEntries(mset *stream, ce *CommittedEntry, isReco
}
}

if !isRecovering && !mset.IsLeader() {
if isRecovering || !mset.IsLeader() {
if err := mset.processSnapshot(ss); err != nil {
derekcollison marked this conversation as resolved.
Show resolved Hide resolved
return err
}
} else if isRecovering {
// On recovery, reset CLFS/FAILED.
mset.setCLFS(ss.Failed)
}
} else if e.Type == EntryRemovePeer {
js.mu.RLock()
Expand Down
7 changes: 4 additions & 3 deletions server/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -5340,6 +5340,10 @@ func (mset *stream) stop(deleteFlag, advisory bool) error {

// Kick monitor and collect consumers first.
mset.mu.Lock()

// Mark closed.
mset.closed.Store(true)

// Signal to the monitor loop.
// Can't use qch here.
if mset.mqch != nil {
Expand Down Expand Up @@ -5400,9 +5404,6 @@ func (mset *stream) stop(deleteFlag, advisory bool) error {
mset.sendDeleteAdvisoryLocked()
}

// Mark closed.
mset.closed.Store(true)

// Quit channel, do this after sending the delete advisory
if mset.qch != nil {
close(mset.qch)
Expand Down