pub struct OffsetManager<B: StateBackend, S: OffsetStore> { /* private fields */ }Expand description
Main offset manager
Coordinates offset tracking, committing, and recovery for Kafka consumers.
§Features
- Per-partition offset tracking
- Watermark-based commit strategies
- Checkpoint integration
- Offset lag monitoring
- Automatic and manual commit modes
Implementations§
Source§impl<B: StateBackend, S: OffsetStore> OffsetManager<B, S>
impl<B: StateBackend, S: OffsetStore> OffsetManager<B, S>
Sourcepub fn new(
consumer_group: String,
backend: Arc<B>,
store: Arc<S>,
strategy: OffsetCommitStrategy,
) -> Self
pub fn new( consumer_group: String, backend: Arc<B>, store: Arc<S>, strategy: OffsetCommitStrategy, ) -> Self
Create a new offset manager
§Arguments
consumer_group- Consumer group IDbackend- State backend for checkpointingstore- Offset storage implementationstrategy- Commit strategy
Sourcepub async fn update_offset(
&mut self,
topic: &str,
partition: u32,
offset: i64,
) -> StateResult<()>
pub async fn update_offset( &mut self, topic: &str, partition: u32, offset: i64, ) -> StateResult<()>
Sourcepub async fn update_offset_with_watermark(
&mut self,
topic: &str,
partition: u32,
offset: i64,
high_watermark: i64,
) -> StateResult<()>
pub async fn update_offset_with_watermark( &mut self, topic: &str, partition: u32, offset: i64, high_watermark: i64, ) -> StateResult<()>
Update offset with high watermark
Sourcepub async fn get_offset(
&self,
topic: &str,
partition: u32,
) -> StateResult<Option<i64>>
pub async fn get_offset( &self, topic: &str, partition: u32, ) -> StateResult<Option<i64>>
Get current offset for a partition
Returns the committed offset, or None if no offset has been committed.
Sourcepub async fn get_offset_info(
&self,
topic: &str,
partition: u32,
) -> StateResult<Option<OffsetInfo>>
pub async fn get_offset_info( &self, topic: &str, partition: u32, ) -> StateResult<Option<OffsetInfo>>
Get offset info (includes metadata and watermarks)
Sourcepub async fn commit(&mut self) -> StateResult<usize>
pub async fn commit(&mut self) -> StateResult<usize>
Commit all pending offsets
§Returns
Ok(committed_count)- Number of offsets committedErr(StateError)- Commit failed
Sourcepub async fn lag(
&self,
topic: &str,
partition: u32,
high_watermark: i64,
) -> StateResult<i64>
pub async fn lag( &self, topic: &str, partition: u32, high_watermark: i64, ) -> StateResult<i64>
Sourcepub async fn total_lag(&self) -> StateResult<i64>
pub async fn total_lag(&self) -> StateResult<i64>
Get total lag across all partitions
Sourcepub async fn restore(&mut self) -> StateResult<usize>
pub async fn restore(&mut self) -> StateResult<usize>
Restore offsets from storage
Loads all committed offsets for the consumer group from the offset store.
§Returns
Ok(restored_count)- Number of offsets restoredErr(StateError)- Restore failed
Sourcepub async fn reset_offset(
&mut self,
topic: &str,
partition: u32,
strategy: OffsetResetStrategy,
partition_high_watermark: Option<i64>,
) -> StateResult<i64>
pub async fn reset_offset( &mut self, topic: &str, partition: u32, strategy: OffsetResetStrategy, partition_high_watermark: Option<i64>, ) -> StateResult<i64>
Reset offset for a partition
§Arguments
topic- Kafka topicpartition- Partition numberstrategy- Reset strategy (earliest, latest, specific offset, etc.)partition_high_watermark- Current high watermark for the partition
§Returns
Ok(new_offset)- The new offset valueErr(StateError)- Reset failed
Sourcepub async fn notify_watermark(
&mut self,
watermark: Watermark,
) -> StateResult<bool>
pub async fn notify_watermark( &mut self, watermark: Watermark, ) -> StateResult<bool>
Sourcepub async fn stats(&self) -> OffsetStats
pub async fn stats(&self) -> OffsetStats
Get statistics
Sourcepub async fn get_all_committed(&self) -> HashMap<TopicPartition, OffsetInfo>
pub async fn get_all_committed(&self) -> HashMap<TopicPartition, OffsetInfo>
Get all committed offsets
Sourcepub async fn get_all_pending(&self) -> HashMap<TopicPartition, OffsetInfo>
pub async fn get_all_pending(&self) -> HashMap<TopicPartition, OffsetInfo>
Get all pending offsets (not yet committed)
Sourcepub async fn clear(&mut self) -> StateResult<()>
pub async fn clear(&mut self) -> StateResult<()>
Clear all offsets for this consumer group
Auto Trait Implementations§
impl<B, S> !RefUnwindSafe for OffsetManager<B, S>
impl<B, S> !UnwindSafe for OffsetManager<B, S>
impl<B, S> Freeze for OffsetManager<B, S>
impl<B, S> Send for OffsetManager<B, S>
impl<B, S> Sync for OffsetManager<B, S>
impl<B, S> Unpin for OffsetManager<B, S>
impl<B, S> UnsafeUnpin for OffsetManager<B, S>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::RequestSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.