pub struct Completion { /* private fields */ }Expand description
A shared durability acknowledgement state used for issuing AckTicket
The completion state tracks following things,
- The latest assigned epoch
- The latest durable epoch
- Waiters blocked on durability advancement
- Durability errors (if any) blocking durability progress
§Example
let completion = frozen_core::ack::Completion::default();
assert_eq!(completion.read_current_epoch(), 0);
assert_eq!(completion.read_durable_epoch(), 0);Implementations§
Source§impl Completion
impl Completion
Sourcepub fn increment_current_epoch(&self) -> TEpoch
pub fn increment_current_epoch(&self) -> TEpoch
Advance current and return next durability epoch
§Epoch
Epoch value is monotonically increasing and used to identify unique write operations
§Example
let completion = frozen_core::ack::Completion::default();
assert_eq!(completion.increment_current_epoch(), 1);
assert_eq!(completion.increment_current_epoch(), 2);
assert_eq!(completion.increment_current_epoch(), 3);Sourcepub fn mark_epoch_as_durable(&self, epoch: TEpoch)
pub fn mark_epoch_as_durable(&self, epoch: TEpoch)
Mark given TEpoch as durable
§Monotonic Epoch
Once an epoch is marked durable, all earlier epochs are implicitly understood to be durable
§Example
use frozen_core::ack::Completion;
let completion = Completion::default();
completion.mark_epoch_as_durable(0x0A);
assert_eq!(completion.read_durable_epoch(), 0x0A);Sourcepub fn get_err(&self) -> Option<FrozenError>
pub fn get_err(&self) -> Option<FrozenError>
Fetch the acknowledgement error (if any)
§Example
use frozen_core::ack::Completion;
let completion = Completion::default();
assert_eq!(completion.get_err(), None);Sourcepub fn set_err(&self, new_error: FrozenError)
pub fn set_err(&self, new_error: FrozenError)
Update
(i.e. replace) current acknowledgement error w/ a new FrozenError
§Example
use frozen_core::{ack::Completion, error::{FrozenError, ErrCode}};
let completion = Completion::default();
let new_error = FrozenError::new(0x10, 0x20, ErrCode::new(0x30, "io"), "failed to read file");
completion.set_err(new_error.clone());
assert_eq!(completion.get_err(), Some(new_error));Sourcepub fn del_err(&self)
pub fn del_err(&self)
Clear acknowledgement error by replacing the underlying error w/ None
§Example
use frozen_core::{ack::Completion, error::{FrozenError, ErrCode}};
let completion = Completion::default();
let new_error = FrozenError::new(0x10, 0x20, ErrCode::new(0x30, "io"), "failed to read file");
completion.set_err(new_error.clone());
assert!(completion.get_err().is_some());
completion.del_err();
assert!(completion.get_err().is_none());Sourcepub fn read_current_epoch(&self) -> TEpoch
pub fn read_current_epoch(&self) -> TEpoch
Read the latest assigned epoch
§Example
use frozen_core::ack::Completion;
let completion = Completion::default();
completion.increment_current_epoch();
assert_eq!(completion.read_current_epoch(), 1);Sourcepub fn read_durable_epoch(&self) -> TEpoch
pub fn read_durable_epoch(&self) -> TEpoch
Read the latest durable epoch
§Example
use frozen_core::ack::Completion;
let completion = Completion::default();
completion.mark_epoch_as_durable(0x3A);
assert_eq!(completion.read_durable_epoch(), 0x3A);Sourcepub fn notify_all_listeners(&self)
pub fn notify_all_listeners(&self)
Wake all listeners currently waiting for durability progress
Waking listeners does not modify any durable state and is typically called after advancing the durable epoch or setting an error
§Example
use frozen_core::ack::Completion;
let completion = Completion::default();
completion.notify_all_listeners();Sourcepub fn set_sync_trigger(&self, trigger: Weak<dyn SyncTrigger>)
pub fn set_sync_trigger(&self, trigger: Weak<dyn SyncTrigger>)
Register a SyncTrigger implementation for triggering syncs
Sourcepub fn trigger_sync(&self) -> FrozenResult<()>
pub fn trigger_sync(&self) -> FrozenResult<()>
Trigger synchronization using the registered SyncTrigger
Sourcepub fn wait_for_epoch(&self, epoch: TEpoch) -> FrozenResult<TEpoch>
pub fn wait_for_epoch(&self, epoch: TEpoch) -> FrozenResult<TEpoch>
Blocks the current thread until the specified epoch becomes durable or an error is
reported