Skip to main content

Checkpointer

Struct Checkpointer 

Source
pub struct Checkpointer { /* private fields */ }
Expand description

Aggregates batch resolutions into per-partition committable watermarks.

use spate_core::checkpoint::{AckStatus, Checkpointer};
use spate_core::record::PartitionId;

let mut cp = Checkpointer::new();
let p = PartitionId(0);
cp.begin_epoch(&[p], 1);
let mut issuer = cp.handle();

let ack = issuer.issue(p, 99); // batch covering offsets ..=99
drop(ack); // all records delivered

cp.drain();
assert_eq!(cp.take_watermarks(), vec![(p, 100)]);
assert_eq!(cp.take_watermarks(), vec![]); // idempotent until new acks

Implementations§

Source§

impl Checkpointer

Source

pub fn new() -> Self

A checkpointer with no assignment. Call begin_epoch when the source reports its first assignment.

Source

pub fn handle(&self) -> AckIssuer

An issuer handle for a pipeline thread.

Source

pub fn begin_epoch(&mut self, partitions: &[PartitionId], epoch: u32)

Start a new assignment epoch covering exactly partitions. Every rebalance bumps the epoch; in-flight batches from earlier epochs resolve as stale and their offsets are re-delivered by the source (at-least-once). Epochs must be strictly increasing.

Ordering contract: the runtime calls this before distributing the new assignment’s lanes to pipeline threads, so issuers observe the new epoch before issuing for it.

Source

pub fn extend_epoch( &mut self, partitions: &[PartitionId], ) -> Result<(), FatalError>

Add partitions to the current epoch without disturbing existing trackers (additive lane gains, SourceEvent::LanesAdded). The epoch does not change, so in-flight batches for existing partitions keep resolving. Only new partitions may be added. A partition revoked mid-epoch can only return in a new epoch, and re-adding a live partition would discard its ack state.

Ordering contract: as with Checkpointer::begin_epoch, call this before distributing the new lanes to pipeline threads.

§Errors

Returns a FatalError if a partition was already admitted to this epoch, whether it is still live or has since been revoked. Both are source bugs. The revoked case is the dangerous one. Its tracker is gone, so it looks fresh, while issuers keep their sequence counters until the epoch changes. Admitting it would pair a mid-sequence registration with a tracker expecting zero, and PartitionTracker::register would panic on the controller thread, taking down the pipeline with a message naming neither this method nor the contract that was broken.

Source

pub fn revoke(&mut self, partitions: &[PartitionId])

Drop tracking for revoked partitions mid-epoch (partial revocation or shutdown). Later resolutions for them are discarded as stale. A partition revoked this way can only return in a new epoch.

Source

pub fn drain(&mut self) -> DrainStats

Apply all pending registrations and resolutions.

Two passes exploit the causal order guaranteed by AckIssuer (registration is sent before the batch’s AckRef exists). A resolution whose registration has not been drained yet is retried once after re-draining registrations; if it is still unknown, the driver is buggy and the resolution is counted and dropped.

Source

pub fn take_watermarks(&mut self) -> Vec<(PartitionId, i64)>

Watermarks that advanced since the last call: (partition, committable offset) pairs ready for Source::commit. Empty when nothing moved, so callers skip the commit entirely.

Source

pub fn pending(&self, partition: PartitionId) -> usize

Unadvanced batches for one partition (backpressure trigger).

Source

pub fn max_pending(&self) -> usize

The largest per-partition pending count.

Source

pub fn stalled_partitions(&self) -> Vec<(PartitionId, Instant)>

Partitions whose watermark is permanently stalled behind a failed batch, with the stall start (health-probe input).

Trait Implementations§

Source§

impl Debug for Checkpointer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Checkpointer

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

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> 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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