Skip to content

feat(hash agg): do state cleaning by watermarks in hash agg #6330

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 2 commits into from
Dec 5, 2022
Merged
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
26 changes: 21 additions & 5 deletions src/stream/src/executor/hash_agg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,13 +396,17 @@ impl<K: HashKey, S: StateStore> HashAggExecutor<K, S> {
ref total_lookup_count,
ref metrics,
ref chunk_size,
buffered_watermarks: ref _buffered_watermarks,
ref buffered_watermarks,
..
}: &'a mut HashAggExecutorExtra<K, S>,
agg_groups: &'a mut AggGroupMap<K, S>,
epoch: EpochPair,
) {
// TODO("https://github.com/risingwavelabs/risingwave/issues/6112"): use buffered_watermarks[0] do some state cleaning
let state_clean_watermark = buffered_watermarks
.first()
.and_then(|opt_watermark| opt_watermark.as_ref())
.map(|watermark| watermark.val.clone());

let actor_id_str = ctx.id.to_string();
metrics
.agg_lookup_miss_count
Expand Down Expand Up @@ -483,10 +487,16 @@ impl<K: HashKey, S: StateStore> HashAggExecutor<K, S> {
}

// Commit all state tables.
futures::future::try_join_all(
iter_table_storage(storages).map(|state_table| state_table.commit(epoch)),
)
futures::future::try_join_all(iter_table_storage(storages).map(|state_table| async {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

if let Some(watermark) = state_clean_watermark.as_ref() {
state_table.update_watermark(watermark.clone())
};
state_table.commit(epoch).await
}))
.await?;
if let Some(watermark) = state_clean_watermark.as_ref() {
result_table.update_watermark(watermark.clone());
};
result_table.commit(epoch).await?;

// Evict cache to target capacity.
Expand All @@ -495,8 +505,14 @@ impl<K: HashKey, S: StateStore> HashAggExecutor<K, S> {
// Nothing to flush.
// Call commit on state table to increment the epoch.
iter_table_storage(storages).for_each(|state_table| {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can only apply on MaterializedInput but not on AggStateStorage::Table?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can only apply on MaterializedInput but not on AggStateStorage::Table?

why? register state table also starts with group key

if let Some(watermark) = state_clean_watermark.as_ref() {
state_table.update_watermark(watermark.clone())
};
state_table.commit_no_data_expected(epoch);
});
if let Some(watermark) = state_clean_watermark.as_ref() {
result_table.update_watermark(watermark.clone());
};
result_table.commit_no_data_expected(epoch);
return Ok(());
}
Expand Down