Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: wrap offset_flush return in pin<box<_>> #4306

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 9 additions & 6 deletions crates/fluvio/src/consumer/stream.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::pin::Pin;
use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::Arc;
use std::time::{Duration, SystemTime};
Expand All @@ -12,14 +13,16 @@ use tracing::{info, warn};
use super::config::OffsetManagementStrategy;
use super::{offset::OffsetLocalStore, StreamToServer};

type OffsetFlushFuture<'a> = Pin<Box<dyn Future<Output = Result<(), ErrorCode>> + Send + 'a>>;

/// Extension of [`Stream`] trait with offset management capabilities.
pub trait ConsumerStream: Stream<Item = Result<Record, ErrorCode>> + Unpin {
/// Mark the offset of the last yelded record as committed. Depending on [`OffsetManagementStrategy`]
/// it may require a subsequent `offset_flush()` call to take any effect.
fn offset_commit(&mut self) -> Result<(), ErrorCode>;

/// Send the committed offset to the server. The method waits for the server's acknowledgment before it finishes.
fn offset_flush(&mut self) -> impl Future<Output = Result<(), ErrorCode>> + Send;
fn offset_flush(&mut self) -> OffsetFlushFuture<'_>;
}

pub struct MultiplePartitionConsumerStream<T> {
Expand Down Expand Up @@ -117,7 +120,7 @@ where
self.get_mut().offset_commit()
}

fn offset_flush(&mut self) -> impl Future<Output = Result<(), ErrorCode>> + Send {
fn offset_flush(&mut self) -> OffsetFlushFuture<'_> {
self.get_mut().offset_flush()
}
}
Expand All @@ -129,8 +132,8 @@ impl<T: Stream<Item = Result<Record, ErrorCode>> + Unpin> ConsumerStream
self.offset_mngt.commit()
}

fn offset_flush(&mut self) -> impl Future<Output = Result<(), ErrorCode>> + Send {
self.offset_mngt.flush()
fn offset_flush(&mut self) -> OffsetFlushFuture<'_> {
Box::pin(self.offset_mngt.flush())
}
}

Expand All @@ -144,9 +147,9 @@ impl<T: Stream<Item = Result<Record, ErrorCode>> + Unpin> ConsumerStream
Ok(())
}

fn offset_flush(&mut self) -> impl Future<Output = Result<(), ErrorCode>> + Send {
fn offset_flush(&mut self) -> OffsetFlushFuture<'_> {
let futures: Vec<_> = self.offset_mgnts.iter().map(|p| p.flush()).collect();
try_join_all(futures).map(|r| r.map(|_| ()))
Box::pin(try_join_all(futures).map(|r| r.map(|_| ())))
}
}

Expand Down
Loading