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

Don't allow stream or consumer snapshots before recovery completed #4927

Merged
merged 1 commit into from
Jan 8, 2024
Merged
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
14 changes: 10 additions & 4 deletions server/jetstream_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -2197,9 +2197,13 @@ func (js *jetStream) monitorStream(mset *stream, sa *streamAssignment, sendSnaps
var lastState SimpleState
var lastSnapTime time.Time

// Don't allow the upper layer to install snapshots until we have
// fully recovered from disk.
isRecovering := true

// Should only to be called from leader.
doSnapshot := func() {
if mset == nil || isRestore || time.Since(lastSnapTime) < minSnapDelta {
if mset == nil || isRecovering || isRestore || time.Since(lastSnapTime) < minSnapDelta {
return
}

Expand All @@ -2226,7 +2230,6 @@ func (js *jetStream) monitorStream(mset *stream, sa *streamAssignment, sendSnaps
// We will establish a restoreDoneCh no matter what. Will never be triggered unless
// we replace with the restore chan.
restoreDoneCh := make(<-chan error)
isRecovering := true

// For migration tracking.
var mmt *time.Ticker
Expand Down Expand Up @@ -4552,9 +4555,13 @@ func (js *jetStream) monitorConsumer(o *consumer, ca *consumerAssignment) {
var lastSnap []byte
var lastSnapTime time.Time

// Don't allow the upper layer to install snapshots until we have
// fully recovered from disk.
recovering := true

doSnapshot := func(force bool) {
// Bail if trying too fast and not in a forced situation.
if !force && time.Since(lastSnapTime) < minSnapDelta {
if recovering || (!force && time.Since(lastSnapTime) < minSnapDelta) {
return
}

Expand Down Expand Up @@ -4605,7 +4612,6 @@ func (js *jetStream) monitorConsumer(o *consumer, ca *consumerAssignment) {

// Track if we are leader.
var isLeader bool
recovering := true

for {
select {
Expand Down
Loading