pub struct SwapDb<D> { /* private fields */ }Expand description
A dataset that stays readable across an atomic re-bootstrap swap.
Generic over the installed dataset D so the replication engine,
the integration tests, and any future caller share one swap
discipline rather than re-implementing the lock dance. D is held
behind an Arc, so a “swap” is a single pointer write and old
readers keep their snapshot alive.
Implementations§
Source§impl<D> SwapDb<D>
impl<D> SwapDb<D>
Sourcepub fn new(data: D) -> Self
pub fn new(data: D) -> Self
Install data as the initial dataset. The node starts not
re-bootstrapping — it is serving normally.
Sourcepub fn is_rebootstrapping(&self) -> bool
pub fn is_rebootstrapping(&self) -> bool
true while a re-bootstrap is in flight. This is exactly the
value the topology advertiser surfaces as
ReplicaInfo::rebootstrapping.
Sourcepub fn snapshot(&self) -> Arc<D> ⓘ
pub fn snapshot(&self) -> Arc<D> ⓘ
The currently-installed dataset, cloned as an Arc. Always
available — this is the stay-readable path. During a rebuild it
returns the old data; after Self::complete_rebootstrap it
returns the new data.
Sourcepub fn read_noncausal(&self) -> Arc<D> ⓘ
pub fn read_noncausal(&self) -> Arc<D> ⓘ
Serve a non-causal read: always the currently-installed
dataset, rebuild in flight or not. Never blocks on the rebuild,
never fails. Identical to Self::snapshot; named for intent
at the call site.
Sourcepub fn read_causal(&self) -> Result<Arc<D>, RebootstrapInProgress>
pub fn read_causal(&self) -> Result<Arc<D>, RebootstrapInProgress>
Serve a causal (bookmark) read.
Returns the installed dataset only when the node is not
re-bootstrapping. While a rebuild is in flight it returns
RebootstrapInProgress so the caller bounces the read to a
caught-up peer — never serving a bookmark from data the node is
about to discard.
Sourcepub fn begin_rebootstrap(&self)
pub fn begin_rebootstrap(&self)
Enter the re-bootstrap state. Idempotent: calling it while already rebuilding is a no-op. The installed dataset is left untouched, so non-causal reads keep flowing from the old data while the fresh snapshot loads in the background.
Sourcepub fn complete_rebootstrap(&self, fresh: D) -> Arc<D> ⓘ
pub fn complete_rebootstrap(&self, fresh: D) -> Arc<D> ⓘ
Atomically install fresh as the new dataset and leave the
re-bootstrap state.
The pointer swap happens under the write lock; the
rebootstrapping flag is cleared only after the new dataset
is published, so there is no instant at which the node both
claims to be caught up and still serves the old data to a
causal reader. Returns the previously-installed dataset (the
old Arc) so the caller can keep or drop it; outstanding
readers that already cloned it stay valid regardless.
Auto Trait Implementations§
impl<D> !Freeze for SwapDb<D>
impl<D> RefUnwindSafe for SwapDb<D>
impl<D> Send for SwapDb<D>
impl<D> Sync for SwapDb<D>
impl<D> Unpin for SwapDb<D>
impl<D> UnsafeUnpin for SwapDb<D>
impl<D> UnwindSafe for SwapDb<D>
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request