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

Conversation

MauriceVanVeen
Copy link
Member

Upon graceful shutdown, stream snapshots aren't installed:
stream.go

} else {
	// Always attempt snapshot on clean exit.
	n.InstallSnapshot(mset.stateSnapshotLocked())
	n.Stop()
}

But raft.go exits immediately since it's in Closed state

if n.State() == Closed {
        return errNodeClosed
}

This turns out to be because of calling either of close(mset.mqch) or close(mset.qch). Which then calls the following upon leaving monitorStream:

	// 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()

This PR proposes to skip running n.Stop() from monitorStream when we know we're closing / have called mset.stop(). Which will already take care of calling either n.Stop() or n.Delete() so there's no need in stopping from monitorStream in that case.

TLDR; this ensures stream snapshots are installed upon shutdown.

Signed-off-by: Maurice van Veen github@mauricevanveen.com

Signed-off-by: Maurice van Veen <github@mauricevanveen.com>
@MauriceVanVeen MauriceVanVeen marked this pull request as ready for review August 20, 2024 16:19
@MauriceVanVeen MauriceVanVeen requested a review from a team as a code owner August 20, 2024 16:19
@wallyqs
Copy link
Member

wallyqs commented Aug 20, 2024

Need to fix this one:

=== RUN   TestJetStreamClusterStreamResetPreacks
    jetstream_cluster_3_test.go:6071: Not correct state yet: {Msgs:0 Bytes:0 FirstSeq:0 FirstTime:0001-01-01 00:00:00 +0000 UTC LastSeq:0 LastTime:0001-01-01 00:00:00 +0000 UTC NumSubjects:0 Subjects:map[] NumDeleted:0 Deleted:[] Lost:<nil> Consumers:1}
--- FAIL: TestJetStreamClusterStreamResetPreacks (13.54s)

Signed-off-by: Maurice van Veen <github@mauricevanveen.com>
@MauriceVanVeen MauriceVanVeen force-pushed the fix/stream-snapshots-not-installed-on-shutdown branch from 2007a25 to 420a121 Compare August 20, 2024 20:34
@derekcollison derekcollison self-requested a review August 20, 2024 21:04
Copy link
Member

@derekcollison derekcollison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@derekcollison derekcollison merged commit 276e289 into main Aug 20, 2024
5 checks passed
@derekcollison derekcollison deleted the fix/stream-snapshots-not-installed-on-shutdown branch August 20, 2024 21:04
wallyqs pushed a commit that referenced this pull request Aug 23, 2024
Upon graceful shutdown, stream snapshots aren't installed:
stream.go
```go
} else {
	// Always attempt snapshot on clean exit.
	n.InstallSnapshot(mset.stateSnapshotLocked())
	n.Stop()
}
```

But raft.go exits immediately since it's in Closed state
```go
if n.State() == Closed {
        return errNodeClosed
}
```

This turns out to be because of calling either of `close(mset.mqch)` or
`close(mset.qch)`. Which then calls the following upon leaving
`monitorStream`:
```go
	// 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()
```

This PR proposes to skip running `n.Stop()` from `monitorStream` when we
know we're closing / have called `mset.stop()`. Which will already take
care of calling either `n.Stop()` or `n.Delete()` so there's no need in
stopping from `monitorStream` in that case.

TLDR; this ensures stream snapshots are installed upon shutdown.

Signed-off-by: Maurice van Veen <github@mauricevanveen.com>

---------

Signed-off-by: Maurice van Veen <github@mauricevanveen.com>
wallyqs pushed a commit that referenced this pull request Aug 23, 2024
Upon graceful shutdown, stream snapshots aren't installed:
stream.go
```go
} else {
	// Always attempt snapshot on clean exit.
	n.InstallSnapshot(mset.stateSnapshotLocked())
	n.Stop()
}
```

But raft.go exits immediately since it's in Closed state
```go
if n.State() == Closed {
        return errNodeClosed
}
```

This turns out to be because of calling either of `close(mset.mqch)` or
`close(mset.qch)`. Which then calls the following upon leaving
`monitorStream`:
```go
	// 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()
```

This PR proposes to skip running `n.Stop()` from `monitorStream` when we
know we're closing / have called `mset.stop()`. Which will already take
care of calling either `n.Stop()` or `n.Delete()` so there's no need in
stopping from `monitorStream` in that case.

TLDR; this ensures stream snapshots are installed upon shutdown.

Signed-off-by: Maurice van Veen <github@mauricevanveen.com>

---------

Signed-off-by: Maurice van Veen <github@mauricevanveen.com>
@wallyqs wallyqs changed the title Fix install stream snapshots on graceful shutdown [FIXED] Fix install stream snapshots on graceful shutdown Aug 23, 2024
wallyqs added a commit that referenced this pull request Aug 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants