pub struct HandoffWriter<T> { /* private fields */ }Expand description
Writes locator handoff records to block storage.
Each publish call bumps the generation,
updates the locator, and checkpoints the state to the underlying
BlockLease.
§Example
use grafos_locator::handoff::{HandoffWriter, HandoffState};
use grafos_locator::locator::QueueLocator;
use grafos_fence::FenceEpoch;
use grafos_std::block::BlockBuilder;
let lease = BlockBuilder::new().acquire().unwrap();
let initial = QueueLocator::new(1, 0, 0);
let mut writer = HandoffWriter::new(
HandoffState { stage_id: 0, generation: FenceEpoch::zero(), locator: initial },
lease,
);
let new_loc = QueueLocator::new(2, 512, 1);
let gen = writer.publish(new_loc).unwrap();
assert_eq!(gen.value(), 1);Implementations§
Source§impl<T: Serialize + DeserializeOwned> HandoffWriter<T>
impl<T: Serialize + DeserializeOwned> HandoffWriter<T>
Sourcepub fn new(state: HandoffState<T>, block_lease: BlockLease) -> Self
pub fn new(state: HandoffState<T>, block_lease: BlockLease) -> Self
Create a new handoff writer with the given initial state.
Does not checkpoint the initial state to disk. Call
publish to persist.
Sourcepub fn publish(&mut self, new_locator: T) -> Result<FenceEpoch>
pub fn publish(&mut self, new_locator: T) -> Result<FenceEpoch>
Publish a new locator, bumping the generation and checkpointing to block storage.
Returns the new FenceEpoch after the bump.
§Errors
Propagates block I/O or serialization errors.
Sourcepub fn generation(&self) -> FenceEpoch
pub fn generation(&self) -> FenceEpoch
Returns the current generation.
Sourcepub fn current_locator(&self) -> &T
pub fn current_locator(&self) -> &T
Returns a reference to the current locator.
Sourcepub fn into_block_lease(self) -> BlockLease
pub fn into_block_lease(self) -> BlockLease
Consume the writer and return the underlying block lease.
This allows transferring the lease to a HandoffReader so that
both sides access the same underlying block storage.
Auto Trait Implementations§
impl<T> Freeze for HandoffWriter<T>where
T: Freeze,
impl<T> !RefUnwindSafe for HandoffWriter<T>
impl<T> !Send for HandoffWriter<T>
impl<T> !Sync for HandoffWriter<T>
impl<T> Unpin for HandoffWriter<T>where
T: Unpin,
impl<T> !UnwindSafe for HandoffWriter<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more