-
Notifications
You must be signed in to change notification settings - Fork 590
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(streaming): retrieve epoch from task local storage (#9488)
Signed-off-by: Bugen Zhao <[email protected]>
- Loading branch information
Showing
7 changed files
with
139 additions
and
86 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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,42 @@ | ||
// Copyright 2023 RisingWave Labs | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use futures::{pin_mut, TryStreamExt}; | ||
use futures_async_stream::try_stream; | ||
use risingwave_common::util::epoch; | ||
|
||
use crate::executor::error::StreamExecutorError; | ||
use crate::executor::{Message, MessageStream}; | ||
|
||
/// Streams wrapped by `epoch_provide` is able to retrieve the current epoch pair from the functions | ||
/// from [`epoch::task_local`]. | ||
#[try_stream(ok = Message, error = StreamExecutorError)] | ||
pub async fn epoch_provide(input: impl MessageStream) { | ||
pin_mut!(input); | ||
|
||
let mut epoch = None; | ||
|
||
while let Some(message) = if let Some(epoch) = epoch { | ||
epoch::task_local::scope(epoch, input.try_next()).await? | ||
} else { | ||
input.try_next().await? | ||
} { | ||
// The inner executor has yielded a new barrier message. In next polls, we will provide the | ||
// updated epoch pair. | ||
if let Message::Barrier(b) = &message { | ||
epoch = Some(b.epoch); | ||
} | ||
yield message; | ||
} | ||
} |