pub struct SyncState { /* private fields */ }Expand description
The client-side reconciliation state: the per-album sync_seq high-water
marks, the max-known protocol version, and the opaque cursor. Pure and
network-free — SyncState::apply_page is the whole anti-rewind /
forward-version contract in one testable function.
Implementations§
Source§impl SyncState
impl SyncState
Sourcepub fn new(max_known_protocol: impl Into<String>) -> Self
pub fn new(max_known_protocol: impl Into<String>) -> Self
A fresh state pinned to the client’s max-known protocol version.
Sourcepub fn restore(
max_known_protocol: impl Into<String>,
cursor: SyncCursor,
high_water: impl IntoIterator<Item = (Vec<u8>, u64)>,
) -> Self
pub fn restore( max_known_protocol: impl Into<String>, cursor: SyncCursor, high_water: impl IntoIterator<Item = (Vec<u8>, u64)>, ) -> Self
Rehydrate a state from a durably-persisted cursor and per-album high-water
marks (the client’s store loaded at startup), pinned to the client’s
current max-known protocol. The inverse of SyncState::cursor +
SyncState::high_water_marks: a client persists those two after every
apply_page and restores here on the next run so
the anti-rewind high-water mark survives process restarts (the CLI’s
capsule sync). max_known_protocol is intentionally not
persisted — it is the running build’s own ceiling, so a client that
upgraded raises it here rather than restoring a stale one.
Sourcepub fn high_water_marks(&self) -> impl Iterator<Item = (&[u8], u64)>
pub fn high_water_marks(&self) -> impl Iterator<Item = (&[u8], u64)>
Every applied per-album high-water mark, for persistence across restarts.
Pair with SyncState::cursor and reload through SyncState::restore.
Sourcepub fn reset_for_resync(&mut self)
pub fn reset_for_resync(&mut self)
Start over after the server moved the library to a new sync epoch
(SyncError::is_stale_cursor): the cursor goes back to the start and every
high-water mark is dropped.
The marks go too, unlike a --force re-drain, because the rebuilt numbering may sit
below them, and a floor the server can no longer honour would refuse every entry as a
rewind. The anti-rewind layer is re-established from the first page of the new epoch.
Only the reconciliation state is reset: nothing the client holds is discarded.
Sourcepub fn cursor(&self) -> &SyncCursor
pub fn cursor(&self) -> &SyncCursor
The cursor to hand to the next pull (round-tripped verbatim).
Sourcepub fn high_water(&self, album_id: &[u8]) -> Option<u64>
pub fn high_water(&self, album_id: &[u8]) -> Option<u64>
The applied per-album high-water mark, if the album has been seen.
Sourcepub fn apply_page(&mut self, page: &SyncPage) -> Result<(), SyncError>
pub fn apply_page(&mut self, page: &SyncPage) -> Result<(), SyncError>
Validate and apply a page: check every entry (forward-version, then
per-album sync_seq monotonicity against the high-water mark) before
mutating any state, then advance the high-water marks and the cursor.
On any rejection nothing is applied — no high-water mark moves and the cursor does not advance — so a poisoned page can never partially land.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SyncState
impl RefUnwindSafe for SyncState
impl Send for SyncState
impl Sync for SyncState
impl Unpin for SyncState
impl UnsafeUnpin for SyncState
impl UnwindSafe for SyncState
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> CompatExt for T
impl<T> CompatExt for T
§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
§fn new_handle(value: Arc<T>) -> Handle
fn new_handle(value: Arc<T>) -> Handle
§unsafe fn clone_handle(handle: Handle) -> Handle
unsafe fn clone_handle(handle: Handle) -> Handle
§unsafe fn consume_handle(handle: Handle) -> Arc<T> ⓘ
unsafe fn consume_handle(handle: Handle) -> Arc<T> ⓘ
Arc<> Read more§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more