HandoffWriter

Struct HandoffWriter 

Source
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>

Source

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.

Source

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.

Source

pub fn generation(&self) -> FenceEpoch

Returns the current generation.

Source

pub fn current_locator(&self) -> &T

Returns a reference to the current locator.

Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.