-
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
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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. | ||
Comment on lines
+20
to
+22
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. 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 commentThe 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. |
||
/// | ||
/// 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, | ||
} | ||
} | ||
} |
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.
typo