pub struct AckTicket { /* private fields */ }Expand description
Durability handle associated with a write operation
§Epoch
Every ticket is assigned a monotonically increasing epoch to monitor durability
§Durability Guarantee
The ticket can be queried via is_durable, waited on via
wait, or forced via force
Once an epoch is confirmed durable, all writes assigned to earlier epochs are also guaranteed to be durable
Callers that only require fire-and-forget semantics may simply discard the returned ticket
Implementations§
Source§impl AckTicket
impl AckTicket
Sourcepub const fn new(epoch: TEpoch, completion: Arc<Completion>) -> Self
pub const fn new(epoch: TEpoch, completion: Arc<Completion>) -> Self
Sourcepub fn is_durable(&self) -> bool
pub fn is_durable(&self) -> bool
Check if the AckTicket is already durable w/o blocking
§Example
use frozen_core::ack::{AckTicket, Completion};
use std::sync::Arc;
let completion = Arc::new(Completion::default());
let ticket = AckTicket::new(10, completion.clone());
assert!(!ticket.is_durable());
completion.mark_epoch_as_durable(10);
assert!(ticket.is_durable());Sourcepub fn wait(&self) -> FrozenResult<TEpoch>
pub fn wait(&self) -> FrozenResult<TEpoch>
Blocks the current thread until the AckTicket becomes durable
§Error Propagation
If a durability error is reported before the epoch becomes durable, the corresponding
FrozenError is returned instead
§Example
use frozen_core::ack::{AckTicket, Completion};
use std::{sync::Arc, thread, time};
let completion = Arc::new(Completion::default());
let epoch = completion.increment_current_epoch();
let ticket = AckTicket::new(epoch, completion.clone());
thread::spawn({
let completion = completion.clone();
move || {
thread::sleep(time::Duration::from_millis(10));
completion.mark_epoch_as_durable(epoch);
completion.notify_all_listeners();
}
});
assert_eq!(ticket.wait().unwrap(), epoch);Sourcepub fn force(&self) -> FrozenResult<TEpoch>
pub fn force(&self) -> FrozenResult<TEpoch>
Forces synchronization for this ticket and blocks until it becomes durable
If a background sync thread is running, signals the worker to sync immediately; otherwise executes the sync synchronously under the lock
§Example
use frozen_core::ack::{AckTicket, Completion};
use std::sync::Arc;
let completion = Arc::new(Completion::default());
completion.mark_epoch_as_durable(5);
let ticket = AckTicket::new(5, completion);
assert_eq!(ticket.force().unwrap(), 5);Sourcepub fn completion(&self) -> &Arc<Completion> ⓘ
pub fn completion(&self) -> &Arc<Completion> ⓘ
Reference to the underlying shared Completion