Repository navigation
feat(config): make startup bounds configurable #412
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
Open
EnRaiha
wants to merge
3
commits into
NodeDB-Lab:main
Choose a base branch
from
EnRaiha:drill/issue354
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| //! Startup tuning: boot-time bounds applied by the readiness gates. | ||
|
|
||
| use std::time::Duration; | ||
|
|
||
| use serde::{Deserialize, Serialize}; | ||
|
|
||
| /// Default bound for the metadata-group readiness stall. | ||
| /// | ||
| /// A node with a large metadata apply backlog (tens of thousands of entries | ||
| /// from a burst of cross-shard writes) needs minutes of replay before the | ||
| /// metadata group applies its first entry. A tighter bound turns a slow boot | ||
| /// into a restart loop. | ||
| pub const DEFAULT_RAFT_READY_TIMEOUT_MS: u64 = 300_000; | ||
|
|
||
| /// Default bound for the local data raft groups' replay. | ||
| /// | ||
| /// Sized for a cold restart on a data dir that has been running for weeks: the | ||
| /// backlog of committed entries takes minutes to apply, not seconds. | ||
| pub const DEFAULT_DATA_GROUP_RECOVERY_TIMEOUT_MS: u64 = 600_000; | ||
|
|
||
| /// Metadata-group readiness stall bound, in the type system. | ||
| /// | ||
| /// Two adjacent `Duration` arguments transpose without a compile error. This | ||
| /// newtype pins the bound where it is chosen and handed to a gate; a helper | ||
| /// that takes plain `Duration` values converts at its own boundary. | ||
| #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| pub struct RaftReadyTimeout(pub Duration); | ||
|
|
||
| /// Local data-group replay bound, in the type system. See [`RaftReadyTimeout`]. | ||
| /// | ||
| /// A separate type, not a shared one: the two bounds measure different waits | ||
| /// and are passed by different call sites, so making them interchangeable buys | ||
| /// nothing and costs a class of silent mix-ups. | ||
| #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| pub struct DataGroupRecoveryTimeout(pub Duration); | ||
|
|
||
| impl From<Duration> for RaftReadyTimeout { | ||
| fn from(value: Duration) -> Self { | ||
| Self(value) | ||
| } | ||
| } | ||
|
|
||
| impl From<Duration> for DataGroupRecoveryTimeout { | ||
| fn from(value: Duration) -> Self { | ||
| Self(value) | ||
| } | ||
| } | ||
|
|
||
| fn default_raft_ready_timeout_ms() -> u64 { | ||
| DEFAULT_RAFT_READY_TIMEOUT_MS | ||
| } | ||
|
|
||
| fn default_data_group_recovery_timeout_ms() -> u64 { | ||
| DEFAULT_DATA_GROUP_RECOVERY_TIMEOUT_MS | ||
| } | ||
|
|
||
| /// Boot-time bounds for the readiness gates in `bootstrap::cluster_ready`. | ||
| /// | ||
| /// Both are range-checked where the config is loaded: below 1 ms the wait is | ||
| /// over before the group it waits for can answer, and above a day it stops | ||
| /// bounding anything while the instant it is added to is still finite. | ||
| #[derive(Debug, Clone, Serialize, Deserialize)] | ||
| pub struct StartupTuning { | ||
| /// How long the metadata raft group may go without applying an entry | ||
| /// before the readiness gate fails startup. Every applied-index advance | ||
| /// resets the clock, so a large replay finishes; only a stuck group fails. | ||
| /// Default: 300_000 (5 minutes). | ||
| #[serde(default = "default_raft_ready_timeout_ms")] | ||
| pub raft_ready_timeout_ms: u64, | ||
|
|
||
| /// How long the locally hosted data raft groups have to replay their | ||
| /// retained logs before startup fails. Default: 600_000 (10 minutes). | ||
| #[serde(default = "default_data_group_recovery_timeout_ms")] | ||
| pub data_group_recovery_timeout_ms: u64, | ||
| } | ||
|
|
||
| impl Default for StartupTuning { | ||
| fn default() -> Self { | ||
| Self { | ||
| raft_ready_timeout_ms: default_raft_ready_timeout_ms(), | ||
| data_group_recovery_timeout_ms: default_data_group_recovery_timeout_ms(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl StartupTuning { | ||
| /// Metadata-group readiness stall bound. | ||
| pub fn raft_ready_timeout(&self) -> RaftReadyTimeout { | ||
| RaftReadyTimeout(Duration::from_millis(self.raft_ready_timeout_ms)) | ||
| } | ||
|
|
||
| /// Data-group recovery bound. | ||
| pub fn data_group_recovery_timeout(&self) -> DataGroupRecoveryTimeout { | ||
| DataGroupRecoveryTimeout(Duration::from_millis(self.data_group_recovery_timeout_ms)) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn defaults_are_the_backlogged_recovery_bounds() { | ||
| let cfg = StartupTuning::default(); | ||
| assert_eq!(cfg.raft_ready_timeout_ms, 300_000); | ||
| assert_eq!(cfg.data_group_recovery_timeout_ms, 600_000); | ||
| assert_eq!( | ||
| cfg.raft_ready_timeout(), | ||
| RaftReadyTimeout(Duration::from_secs(300)) | ||
| ); | ||
| assert_eq!( | ||
| cfg.data_group_recovery_timeout(), | ||
| DataGroupRecoveryTimeout(Duration::from_secs(600)) | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn one_bound_set_leaves_the_other_at_its_default() { | ||
| let cfg: StartupTuning = | ||
| toml::from_str("raft_ready_timeout_ms = 1234").expect("deserialize"); | ||
| assert_eq!(cfg.raft_ready_timeout_ms, 1234); | ||
| assert_eq!(cfg.data_group_recovery_timeout_ms, 600_000); | ||
| } | ||
| } | ||
This file contains hidden or 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.
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.
Nothing checks either bound.
0andu64::MAXboth deserialize, and both break the boot (see the note ondata_group_recovery.rs:185). Add a range check at config load that names the key, the value, and the valid range.