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
impl Watermark
pub const fn new(peer: StoreId, confirmed: SequencePosition) -> Self
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 confirmed(&self) -> SequencePosition
pub const fn confirmed(&self) -> SequencePosition
The first position of the last local write group the far side acknowledged.
pub fn id(&self) -> ProjectionId
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>>
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>>
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.