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

fix(batch): release epoch at the end of the distributed query if it contains lookup join #6997

Merged
merged 4 commits into from
Dec 21, 2022

Conversation

chenzl25
Copy link
Contributor

I hereby agree to the terms of the Singularity Data, Inc. Contributor License Agreement.

What's changed and what's your intention?

This section will be used as the commit message. Please do not leave this empty!

Please explain IN DETAIL what the changes are in this PR and why they are needed:

  • As title.

Checklist

  • I have written necessary rustdoc comments
  • I have added necessary unit tests and integration tests
  • All checks passed in ./risedev check (or alias, ./risedev c)

Documentation

If your pull request contains user-facing changes, please specify the types of the changes, and create a release note. Otherwise, please feel free to remove this section.

Types of user-facing changes

Please keep the types that apply to your changes, and remove those that do not apply.

  • Installation and deployment
  • Connector (sources & sinks)
  • SQL commands, functions, and operators
  • RisingWave cluster configuration changes
  • Other (please specify in the release note below)

Release note

Please create a release note for your changes. In the release note, focus on the impact on users, and mention the environment or conditions where the impact may occur.

Refer to a related PR or issue link (optional)

#6979

@chenzl25 chenzl25 marked this pull request as ready for review December 21, 2022 04:01
@github-actions github-actions bot added the type/fix Bug fix label Dec 21, 2022
@codecov
Copy link

codecov bot commented Dec 21, 2022

Codecov Report

Merging #6997 (4ab9958) into main (94d508a) will decrease coverage by 0.00%.
The diff coverage is 78.94%.

@@            Coverage Diff             @@
##             main    #6997      +/-   ##
==========================================
- Coverage   72.89%   72.89%   -0.01%     
==========================================
  Files        1040     1040              
  Lines      167014   167032      +18     
==========================================
+ Hits       121745   121758      +13     
- Misses      45269    45274       +5     
Flag Coverage Δ
rust 72.89% <78.94%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/frontend/src/scheduler/distributed/query.rs 75.30% <25.00%> (-0.32%) ⬇️
src/frontend/src/scheduler/plan_fragmenter.rs 69.35% <93.33%> (+0.64%) ⬆️
src/meta/src/hummock/mock_hummock_meta_client.rs 64.21% <0.00%> (-1.06%) ⬇️
src/meta/src/hummock/manager/mod.rs 77.71% <0.00%> (-0.12%) ⬇️
src/stream/src/executor/aggregation/minput.rs 96.39% <0.00%> (-0.11%) ⬇️
src/storage/src/hummock/compactor/mod.rs 83.25% <0.00%> (ø)
src/common/src/cache.rs 97.54% <0.00%> (+0.22%) ⬆️
...frontend/src/scheduler/hummock_snapshot_manager.rs 59.06% <0.00%> (+0.46%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Member

@BugenZhao BugenZhao left a comment

Choose a reason for hiding this comment

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

This seems to be a workable fix, however, it will definitely defer the release of the pinned snapshot. 🤔 Is it possible to also record the stages with lookup join?

@chenzl25
Copy link
Contributor Author

This seems to be a workable fix, however, it will definitely defer the release of the pinned snapshot. 🤔 Is it possible to also record the stages with lookup join?

Even if we find out the stage of the lookup join, we can't release the pinned snapshot right after it gets scheduled. Previously we tried to release the pinned snapshot right after all scan iterators were created. I think as long as we hold the iterators, the storage can't release its corresponding epoch which is almost equivalent with releasing the epoch at the end of the query, because in most cases scan iterators end with the same time as the whole query.

@BugenZhao
Copy link
Member

Makes sense. I've recalled it wrong since long ago, the table scan did not pin a specific version, and it's the frontend's responsibility to pin the snapshot for the whole process. 🤣

Copy link
Member

@BugenZhao BugenZhao left a comment

Choose a reason for hiding this comment

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

BTW, is it possible to still eagerly unpin the snapshot if there's no lookup join? Anyway, let's get this fix merged now.

@@ -247,14 +244,6 @@ impl QueryRunner {
stage_id
);
self.scheduled_stages_count += 1;
stages_with_table_scan.remove(&stage_id);
if stages_with_table_scan.is_empty() {
// We can be sure here that all the Hummock iterators have been created,
Copy link
Member

Choose a reason for hiding this comment

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

Will there be race cases previously?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks fine. I can't tell.

@chenzl25
Copy link
Contributor Author

BTW, is it possible to still eagerly unpin the snapshot if there's no lookup join? Anyway, let's get this fix merged now.

It is still possible to unpin the snapshot if there's no lookup join.

@hzxa21
Copy link
Collaborator

hzxa21 commented Dec 21, 2022

Discussed with @chenzl25 offline. Lookup join will create storage iterators during its exeuction, not during scheduling. Based on the current interface, I cannot think of a way to do early epoch unpin in this case. To do that, we may need to do either of the following:

  1. Expose the seek interface for storage table iterator. Lookup join can create the iterator during scheduling and call seek during its execution. However, since we use stream for storage table iterator, seek is counter-intuitive.
  2. Expose the concept of storage version and allow upper layer to create multiple iterators on top of a version. This needs a bigger refactor and adds burden on the upper layer to unpin version.

IMO, we can delay epoch unpin if the query has lookup join for now, given that we don't expect batch query to run for a long time in the serving use cases. We can optimize it when we do see long running batch queries in the future.

@BowenXiao1999 BowenXiao1999 requested a review from lmatz December 21, 2022 08:00
Copy link
Contributor

@BowenXiao1999 BowenXiao1999 left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -247,14 +244,6 @@ impl QueryRunner {
stage_id
);
self.scheduled_stages_count += 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest to add some comments for why remove the early unpin.

@chenzl25
Copy link
Contributor Author

chenzl25 commented Dec 21, 2022

I have reimplemented in this way, only delay epoch unpin for lookup join. Please take a look again. @BugenZhao @BowenXiao1999

@chenzl25 chenzl25 changed the title fix(batch): release epoch at the end of the distributed query fix(batch): release epoch at the end of the distributed query if it contains lookup join Dec 21, 2022
@lmatz
Copy link
Contributor

lmatz commented Dec 21, 2022

@BowenXiao1999
I forget the intention of the old implementation,
We probably wanted to make sure that compaction can still happen -> new version, but the version/snapshot held by the iterator cannot be vacuumed.
Can't remember exactly......

@mergify mergify bot merged commit fd0c81e into main Dec 21, 2022
@mergify mergify bot deleted the dylan/release_epoch_at_the_end_of_distributed_query branch December 21, 2022 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/fix Bug fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants