-
Notifications
You must be signed in to change notification settings - Fork 8
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
Fulmicoton fsync data #60
Merged
+184
−103
Merged
Changes from all commits
Commits
Show all changes
5 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 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
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
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 |
---|---|---|
@@ -0,0 +1,104 @@ | ||
use std::time::{Duration, Instant}; | ||
|
||
#[derive(Copy, Clone, Debug, PartialEq, Eq)] | ||
pub enum PersistAction { | ||
/// The buffer will be flushed to the OS, but not necessarily to the disk. | ||
Flush, | ||
/// The buffer will be flushed to the OS, and the OS will be asked to flush | ||
/// it to the disk. | ||
FlushAndFsync, | ||
} | ||
|
||
impl PersistAction { | ||
pub fn is_fsync(self) -> bool { | ||
self == PersistAction::FlushAndFsync | ||
} | ||
} | ||
|
||
/// We have two type of operations on the mrecordlog. | ||
/// | ||
/// Critical records are relatively rare and really need to be persisted: | ||
/// - RecordPosition { queue: &'a str, position: u64 }, | ||
/// - DeleteQueue. | ||
/// | ||
/// For these operations, we want to always flush and fsync. | ||
/// | ||
/// On the other hand, | ||
/// - Truncate | ||
/// - AppendRecords | ||
/// are considered are more frequent and one might want to sacrifice | ||
/// persistence guarantees for performance. | ||
/// | ||
/// The `PersistPolicy` defines the trade-off applied for the second kind of | ||
/// operations. | ||
#[derive(Clone, Debug)] | ||
pub enum PersistPolicy { | ||
/// Only ensure data is persisted when critical records are written. | ||
/// | ||
/// With this policy, the timing after which the data reaches the disk | ||
/// is up to the OS. | ||
DoNothing, | ||
/// Pesiste data once every interval, and when critical records are written | ||
OnDelay { | ||
interval: Duration, | ||
action: PersistAction, | ||
}, | ||
/// Persist data after each action | ||
Always(PersistAction), | ||
} | ||
|
||
#[derive(Debug)] | ||
pub(crate) enum PersistState { | ||
OnAppend(PersistAction), | ||
OnDelay { | ||
next_persist: Instant, | ||
interval: Duration, | ||
action: PersistAction, | ||
}, | ||
NoOp, | ||
} | ||
|
||
impl PersistState { | ||
pub fn should_persist(&self) -> Option<PersistAction> { | ||
match self { | ||
PersistState::OnAppend(action) => Some(*action), | ||
PersistState::OnDelay { | ||
action, | ||
next_persist, | ||
.. | ||
} => { | ||
if *next_persist < Instant::now() { | ||
Some(*action) | ||
} else { | ||
None | ||
} | ||
} | ||
PersistState::NoOp => None, | ||
} | ||
} | ||
|
||
pub fn update_persisted(&mut self) { | ||
match self { | ||
PersistState::OnAppend(_) | PersistState::NoOp => (), | ||
PersistState::OnDelay { | ||
ref mut next_persist, | ||
interval, | ||
.. | ||
} => *next_persist = Instant::now() + *interval, | ||
} | ||
} | ||
} | ||
|
||
impl From<PersistPolicy> for PersistState { | ||
fn from(val: PersistPolicy) -> PersistState { | ||
match val { | ||
PersistPolicy::Always(action) => PersistState::OnAppend(action), | ||
PersistPolicy::OnDelay { interval, action } => PersistState::OnDelay { | ||
next_persist: Instant::now() + interval, | ||
interval, | ||
action, | ||
}, | ||
PersistPolicy::DoNothing => PersistState::NoOp, | ||
} | ||
} | ||
} |
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.
CreateQueue is a bit of a virtual operation, but I think it's worth putting it in that list
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.
It is not that virtual but yeah, it should not be consequential for Quickwit.