Skip to main content

Watermark

Struct Watermark 

pub struct Watermark { /* private fields */ }
Expand description

One edge’s confirmation watermark: the far side, and the first position of the last local write group it acknowledged.

Built from an edge by Edge::watermark, read back by load, and turned back into an edge by Edge::restored.

§Examples

The watermark lands in the batch that carries the caller’s read model:

use happenstance_core::{MemoryProjectionStore, SequencePosition, StoreId};
use happenstance_sync::runner::Watermark;

let hub = StoreId::from_bytes([2; 16]);
let store = MemoryProjectionStore::new();
let watermark = Watermark::new(hub, SequencePosition::FIRST);

let mut batch = store.open();
batch.write("schedule:confirmed", 1);
watermark.commit(&store, batch).await?;

assert_eq!(Watermark::load(&store, hub).await?, Some(watermark));
assert_eq!(store.get("schedule:confirmed"), Some(1));

Implementations§

§

impl Watermark

pub const fn new(peer: StoreId, confirmed: SequencePosition) -> Self

The watermark of the edge with peer, at confirmed.

confirmed is a local position, as SyncStatus::confirmed reports it.

pub const fn peer(&self) -> StoreId

The far side’s store identity.

pub const fn confirmed(&self) -> SequencePosition

The first position of the last local write group the far side acknowledged.

pub fn id(&self) -> ProjectionId

The projection id the watermark is kept under: ProjectionId::sync_watermark of the far side.

pub async fn commit<P: ProjectionStore>( &self, store: &P, batch: P::Batch, ) -> Result<(), CommitError<P::Error>>

Commits batch, with whatever the caller wrote into it, and moves this watermark’s checkpoint to confirmed, as one unit.

The checkpoint is committed Authority::Live: a watermark has no rebuild.

§Errors

What ProjectionStore::commit returns, unchanged: CommitError::CheckpointRegression if a later watermark is already kept for this peer, CommitError::ForeignBatch if batch came from another store, and CommitError::Store if the adapter failed. Either way neither the rows nor the watermark changed.

pub async fn load<P: ProjectionStore>( store: &P, peer: StoreId, ) -> Result<Option<Self>, LoadWatermarkError<P::Error>>

The watermark kept for peer, or None if none was ever committed or it was reset.

§Errors

LoadWatermarkError::Store if the checkpoint cannot be read, and LoadWatermarkError::NotLive if what is kept under the id is not a live checkpoint, which commit never writes.

Trait Implementations§

§

impl Clone for Watermark

§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Copy for Watermark

§

impl Debug for Watermark

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
§

impl Eq for Watermark

§

impl Hash for Watermark

§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
§

impl PartialEq for Watermark

§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
§

impl StructuralPartialEq for Watermark

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.