Skip to main content

ReplayState

Struct ReplayState 

Source
pub(crate) struct ReplayState {
    pub(crate) guard: ReplayGuard,
    pub(crate) path: Option<PathBuf>,
    pub(crate) stream: String,
    pub(crate) stream_created_unix_ns: i64,
    pub(crate) subject: String,
    pub(crate) saved: u64,
    pub(crate) last_refresh: Instant,
}
Expand description

Replay protection for one channel writer.

JetStream can lose a durable consumer’s progress (an empty or missing consumer state file after a power cut) and then deliver the whole stream again. This keeps the archiver’s own checkpoint of the consumer’s ack floor per stream and subject (see replay_guard) and acks messages at or below it without writing them.

Fields§

§guard: ReplayGuard

Skips messages at or below the trusted checkpoint.

§path: Option<PathBuf>

Checkpoint file; None when the guard is off.

§stream: String

Stream name, stored in the checkpoint.

§stream_created_unix_ns: i64

Stream creation time in Unix nanoseconds, stored in the checkpoint.

§subject: String

Channel subject, stored in the checkpoint.

§saved: u64

Floor last written to the checkpoint file.

§last_refresh: Instant

When the checkpoint was last refreshed.

Implementations§

Source§

impl ReplayState

Source

pub(crate) fn attach( state_dir: Option<&Path>, stream: &Info, subject: &str, consumer_name: &str, consumer_ack_floor: u64, ) -> Self

Loads the checkpoint for a channel and compares it with the consumer.

A checkpoint that does not match the stream as it is now is ignored with a log line (see replay_guard::trusted_floor). If the consumer’s ack floor is below a trusted checkpoint, JetStream has lost the consumer’s progress; that is logged and the messages up to the checkpoint will be skipped.

§Arguments
  • state_dir - Checkpoint directory, or None when the guard is off.
  • stream - Stream info as fetched when the channel started.
  • subject - Channel subject.
  • consumer_name - Durable consumer name, for log lines.
  • consumer_ack_floor - The consumer’s ack floor stream sequence.
Source

pub(crate) fn note_skip(&self, channel: u8, stream_seq: u64)

Logs the first skipped message of a run and then every SKIP_LOG_EVERY.

Source

pub(crate) fn end_skip_run(&mut self, channel: u8)

Logs the end of a run of skipped messages, if one was in progress.

Source

pub(crate) async fn checkpoint( &mut self, consumer: &mut PullConsumer, channel: u8, force: bool, )

Saves the consumer’s ack floor as the new checkpoint if it has moved up.

Without force this runs at most once per CHECKPOINT_INTERVAL. Failures are logged; the old checkpoint stays valid, only less recent.

§Arguments
  • consumer - The channel’s durable consumer.
  • channel - Channel number, for log lines.
  • force - Refresh now, regardless of the interval.

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

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
§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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