Skip to main content

SwapDb

Struct SwapDb 

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

Source

pub fn new(data: D) -> SwapDb<D>

Install data as the initial dataset. The node starts not re-bootstrapping — it is serving normally.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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>
where D: Sync + Send,

§

impl<D> Sync for SwapDb<D>
where D: Sync + Send,

§

impl<D> Unpin for SwapDb<D>

§

impl<D> UnsafeUnpin for SwapDb<D>

§

impl<D> UnwindSafe for SwapDb<D>

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more