Skip to main content

SnapshotOutcome

Enum SnapshotOutcome 

Source
pub enum SnapshotOutcome {
    Available(Snapshot),
    Unavailable(LogicalReplicationStream),
}
Expand description

The result of asking for an initial snapshot.

Unavailable is not an error: ensure_replication_slot treats an existing slot as success, and a pre-existing slot exported no snapshot. That is the normal “resume an existing subscription” path, so the stream is handed straight back, ready for start().

Both variants own the replication stream, and Available additionally owns the reader connection and the table list, so the variants differ sharply in size. Boxing is not worth it: one of these exists per snapshot, it is destructured immediately, and boxing would push an allocation onto an API whose whole job is to be hard to misuse.

Deliberately not #[non_exhaustive], against the usual advice for a new public enum. Every variant owns the replication stream, and getting it back is the only reason this type exists — so a forced _ => arm would have nothing correct to do with a variant it cannot name, and unreachable!() in every caller’s match is worse than the theoretical break. The binary “exported or not” has no third case to add; callers who do not want to match at all have skip.

Variants§

§

Available(Snapshot)

The slot was created and a snapshot exported.

§

Unavailable(LogicalReplicationStream)

No snapshot exists — the slot already existed.

§This arm is where a silent data gap gets in

Normally this is the ordinary “resume an existing subscription” path, so handing the stream back and calling start() is exactly right.

But it cannot distinguish that from a slot left behind by an attempt that failed seconds ago. A failed snapshot discards its slot, yet DROP_REPLICATION_SLOT is best-effort — and the failure most likely to kill a snapshot, losing the connection, is also the one that stops the cleanup from reaching the server. The slot survives, the retry lands here, and a caller who writes

ⓘ
SnapshotOutcome::Unavailable(stream) => stream,   // resume

streams with no baseline at all, with no error anywhere.

If you are bootstrapping and “resume” is never a correct answer, fail in this arm instead:

ⓘ
SnapshotOutcome::Unavailable(_) => {
    return Err("bootstrap requires a fresh slot; drop the existing one".into())
}

Implementations§

Source§

impl SnapshotOutcome

Source

pub fn is_available(&self) -> bool

Whether a snapshot is available to read.

Source

pub async fn skip(self) -> Result<LogicalReplicationStream>

Take the replication stream back, skipping the snapshot if there is one.

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> 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> 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 = !

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