-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use batch aggregation in flow recovering
- Loading branch information
1 parent
bb9af2a
commit c4de068
Showing
5 changed files
with
61 additions
and
30 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
45 changes: 45 additions & 0 deletions
45
src/domain/flow-system/services/src/flow/flow_state_helper.rs
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,45 @@ | ||
// Copyright Kamu Data, Inc. and contributors. 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 std::sync::Arc; | ||
|
||
use dill::component; | ||
use internal_error::ResultIntoInternal; | ||
use kamu_flow_system::{Flow, FlowEventStore, FlowID, FlowStateStream}; | ||
|
||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
pub struct FlowStateHelper { | ||
flow_event_store: Arc<dyn FlowEventStore>, | ||
} | ||
|
||
#[component(pub)] | ||
impl FlowStateHelper { | ||
pub(crate) fn new(flow_event_store: Arc<dyn FlowEventStore>) -> Self { | ||
Self { flow_event_store } | ||
} | ||
|
||
pub fn get_stream(&self, flow_ids: Vec<FlowID>) -> FlowStateStream { | ||
Box::pin(async_stream::try_stream! { | ||
// 32-items batching will give a performance boost, | ||
// but queries for long-lived datasets should not bee too heavy. | ||
// This number was chosen without any performance measurements. Subject of change. | ||
let chunk_size = 32; | ||
for chunk in flow_ids.chunks(chunk_size) { | ||
let flows = Flow::load_multi( | ||
chunk.to_vec(), | ||
self.flow_event_store.as_ref() | ||
).await.int_err()?; | ||
for flow in flows { | ||
yield flow.int_err()?.into(); | ||
} | ||
} | ||
}) | ||
} | ||
} |
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