-
Notifications
You must be signed in to change notification settings - Fork 119
[bifrost] Get a CommitToken back from notify_committed()
#3968
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| [package] | ||
| name = "restate-ingestion-client" | ||
| version.workspace = true | ||
| authors.workspace = true | ||
| edition.workspace = true | ||
| rust-version.workspace = true | ||
| license.workspace = true | ||
| publish = false | ||
|
|
||
| [dependencies] | ||
| arc-swap = { workspace = true } | ||
| dashmap = { workspace = true } | ||
| futures = { workspace = true } | ||
| pin-project = { workspace = true } | ||
| thiserror = { workspace = true } | ||
| tokio-stream = { workspace = true } | ||
| tokio-util = { workspace = true } | ||
| tokio = { workspace = true } | ||
| tracing = { workspace = true } | ||
|
|
||
| restate-core = { workspace = true } | ||
| restate-types = { workspace = true } | ||
| restate-workspace-hack = { workspace = true } | ||
|
|
||
| [dev-dependencies] | ||
| bytes = { workspace = true } | ||
| googletest = { workspace = true } | ||
| test-log = { workspace = true } | ||
|
|
||
| restate-core = { workspace = true, features = ["test-util"] } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| // Copyright (c) 2023 - 2025 Restate Software, Inc., Restate GmbH. | ||
| // All rights reserved. | ||
| // | ||
| // Use of this software is governed by the Business Source License | ||
| // included in the LICENSE file. | ||
| // | ||
| // As of the Change Date specified in that file, in accordance with | ||
| // the Business Source License, use of this software will be governed | ||
| // by the Apache License, Version 2.0. | ||
|
|
||
| use tokio_stream::adapters::Fuse; | ||
| use tokio_stream::{Stream, StreamExt}; | ||
|
|
||
| use core::pin::Pin; | ||
| use core::task::{Context, Poll}; | ||
|
|
||
| #[must_use = "streams do nothing unless polled"] | ||
| #[derive(Debug)] | ||
| #[pin_project::pin_project] | ||
| pub struct ChunksSize<F, S: Stream> { | ||
| #[pin] | ||
| stream: Fuse<S>, | ||
| items: Vec<S::Item>, | ||
| size: usize, | ||
| cap: usize, // https://github.com/rust-lang/futures-rs/issues/1475 | ||
| size_fn: F, | ||
| } | ||
|
|
||
| impl<F, S: Stream> ChunksSize<F, S> | ||
| where | ||
| F: Fn(&S::Item) -> usize, | ||
| { | ||
| pub fn new(stream: S, max_size: usize, size_fn: F) -> Self { | ||
| ChunksSize { | ||
| stream: stream.fuse(), | ||
| items: Vec::default(), | ||
| size: 0, | ||
| cap: max_size, | ||
| size_fn, | ||
| } | ||
| } | ||
|
|
||
| /// Drains the buffered items, returning them without waiting for the timeout or capacity limit. | ||
| pub fn into_remainder(self) -> Vec<S::Item> { | ||
| self.items | ||
| } | ||
| } | ||
|
|
||
| impl<F, S: Stream> Stream for ChunksSize<F, S> | ||
| where | ||
| F: Fn(&S::Item) -> usize, | ||
| { | ||
| type Item = Vec<S::Item>; | ||
|
|
||
| fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> { | ||
| let mut me = self.as_mut().project(); | ||
| loop { | ||
| match me.stream.as_mut().poll_next(cx) { | ||
| Poll::Pending if me.items.is_empty() => return Poll::Pending, | ||
| Poll::Pending => { | ||
| *me.size = 0; | ||
| return Poll::Ready(Some(std::mem::take(me.items))); | ||
| } | ||
| Poll::Ready(Some(item)) => { | ||
| let item_size = (me.size_fn)(&item); | ||
|
|
||
| if *me.size + item_size <= *me.cap { | ||
| *me.size += item_size; | ||
| me.items.push(item); | ||
| } else if me.items.is_empty() { | ||
| *me.size = 0; | ||
| return Poll::Ready(Some(vec![item])); | ||
| } else { | ||
| let items = std::mem::replace(me.items, vec![item]); | ||
| *me.size = item_size; | ||
| return Poll::Ready(Some(items)); | ||
| } | ||
| } | ||
| Poll::Ready(None) => { | ||
| // Returning Some here is only correct because we fuse the inner stream. | ||
| let last = if me.items.is_empty() { | ||
| None | ||
| } else { | ||
| Some(std::mem::take(me.items)) | ||
| }; | ||
|
|
||
| return Poll::Ready(last); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fn size_hint(&self) -> (usize, Option<usize>) { | ||
| let chunk_len = if self.items.is_empty() { 0 } else { 1 }; | ||
| let (lower, upper) = self.stream.size_hint(); | ||
| let lower = (lower / self.cap).saturating_add(chunk_len); | ||
| let upper = upper.and_then(|x| x.checked_add(chunk_len)); | ||
| (lower, upper) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use std::task::Poll; | ||
|
|
||
| use futures::{StreamExt, stream::poll_fn}; | ||
| use tokio_stream::iter; | ||
|
|
||
| use super::ChunksSize; | ||
|
|
||
| #[tokio::test] | ||
| async fn splits_into_size_bound_chunks() { | ||
| let stream = iter([2usize, 2, 3, 1]); | ||
| let chunks: Vec<Vec<usize>> = ChunksSize::new(stream, 5, |item| *item).collect().await; | ||
|
|
||
| assert_eq!(chunks, vec![vec![2, 2], vec![3, 1]]); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn emits_item_larger_than_cap_as_its_own_chunk() { | ||
| let stream = iter([10usize, 2]); | ||
| let chunks: Vec<Vec<usize>> = ChunksSize::new(stream, 5, |item| *item).collect().await; | ||
|
|
||
| assert_eq!(chunks, vec![vec![10], vec![2]]); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn flushes_buffer_when_inner_stream_is_pending() { | ||
| let mut state = 0; | ||
| let stream = poll_fn(move |_| { | ||
| state += 1; | ||
| match state { | ||
| 1 => Poll::Ready(Some(1usize)), | ||
| 2 => Poll::Pending, | ||
| 3 => Poll::Ready(Some(2usize)), | ||
| _ => Poll::Ready(None), | ||
| } | ||
| }); | ||
|
|
||
| let chunks: Vec<Vec<usize>> = ChunksSize::new(stream, 10, |item| *item).collect().await; | ||
|
|
||
| assert_eq!(chunks, vec![vec![1], vec![2]]); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe update the docs to reflect the new contract.