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.
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, // resumestreams 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
impl SnapshotOutcome
Sourcepub fn is_available(&self) -> bool
pub fn is_available(&self) -> bool
Whether a snapshot is available to read.
Sourcepub async fn skip(self) -> Result<LogicalReplicationStream>
pub async fn skip(self) -> Result<LogicalReplicationStream>
Take the replication stream back, skipping the snapshot if there is one.