-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Make snapshot timing and trailing logs hot-reloadable in raft #444
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -164,19 +164,23 @@ type Config struct { | |
// we can become a leader of a cluster containing only this node. | ||
ShutdownOnRemove bool | ||
|
||
// TrailingLogs controls how many logs we leave after a snapshot. This is | ||
// used so that we can quickly replay logs on a follower instead of being | ||
// forced to send an entire snapshot. | ||
// TrailingLogs controls how many logs we leave after a snapshot. This is used | ||
// so that we can quickly replay logs on a follower instead of being forced to | ||
// send an entire snapshot. The value passed here is the initial setting used. | ||
// This can be tuned during operation using ReloadConfig. | ||
TrailingLogs uint64 | ||
|
||
// SnapshotInterval controls how often we check if we should perform a snapshot. | ||
// We randomly stagger between this value and 2x this value to avoid the entire | ||
// cluster from performing a snapshot at once. | ||
// SnapshotInterval controls how often we check if we should perform a | ||
// snapshot. We randomly stagger between this value and 2x this value to avoid | ||
// the entire cluster from performing a snapshot at once. The value passed | ||
// here is the initial setting used. This can be tuned during operation using | ||
// ReloadConfig. | ||
SnapshotInterval time.Duration | ||
|
||
// SnapshotThreshold controls how many outstanding logs there must be before | ||
// we perform a snapshot. This is to prevent excessive snapshots when we can | ||
// just replay a small set of logs. | ||
// just replay a small set of logs. The value passed here is the initial | ||
// setting used. This can be tuned during operation using ReloadConfig. | ||
SnapshotThreshold uint64 | ||
|
||
// LeaderLeaseTimeout is used to control how long the "lease" lasts | ||
|
@@ -218,6 +222,39 @@ type Config struct { | |
skipStartup bool | ||
} | ||
|
||
// ReloadableConfig is the subset of Config that may be reconfigured during | ||
// runtime using raft.ReloadConfig. We choose to duplicate fields over embedding | ||
// or accepting a Config but only using specific fields to keep the API clear. | ||
// Reconfiguring some fields is potentially dangerous so we should only | ||
// selectively enable it for fields where that is allowed. | ||
type ReloadableConfig struct { | ||
// TrailingLogs controls how many logs we leave after a snapshot. This is used | ||
// so that we can quickly replay logs on a follower instead of being forced to | ||
// send an entire snapshot. The value passed here is the initial setting used. | ||
// This can be tuned during operation using | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like this isn't finished here, but I may be misunderstanding it! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope, good catch. I thought I'd fixed this but only in one of the places!
banks marked this conversation as resolved.
Show resolved
Hide resolved
|
||
TrailingLogs uint64 | ||
|
||
// SnapshotInterval controls how often we check if we should perform a snapshot. | ||
// We randomly stagger between this value and 2x this value to avoid the entire | ||
// cluster from performing a snapshot at once. | ||
SnapshotInterval time.Duration | ||
|
||
// SnapshotThreshold controls how many outstanding logs there must be before | ||
// we perform a snapshot. This is to prevent excessive snapshots when we can | ||
// just replay a small set of logs. | ||
SnapshotThreshold uint64 | ||
} | ||
|
||
// apply sets the reloadable fields on the passed Config to the values in | ||
// `ReloadableConfig`. It returns a copy of Config with the fields from this | ||
// ReloadableConfig set. | ||
func (rc *ReloadableConfig) apply(to Config) Config { | ||
to.TrailingLogs = rc.TrailingLogs | ||
to.SnapshotInterval = rc.SnapshotInterval | ||
to.SnapshotThreshold = rc.SnapshotThreshold | ||
return to | ||
} | ||
|
||
// DefaultConfig returns a Config with usable defaults. | ||
func DefaultConfig() *Config { | ||
return &Config{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of duplicating these fields here and in ReloadableConfig can we embed ReloadableConfig?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stated below,
" We choose to duplicate fields over embedding or accepting a Config but only using specific fields to keep the API clear."
I'm not entirely sold on the idea of embedding the ReloadableConfig into the "regular" Config because the separation of "this changes, and this doesn't" is clear and "feels safer" (which is probably not a good reason, I admit)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was on the fence there - I wasn't sure if it was technically binary compatible to embed which tipped the balance although in practice most reasonable usages would probably have been unaffected. I tend to agree with Sarah though - the separation ends up being kind of OK with me in the end for keeping things clearly delineated?