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(frontend): create mview on singleton upstream mview #4153

Merged
merged 13 commits into from
Jul 26, 2022

Conversation

BugenZhao
Copy link
Member

@BugenZhao BugenZhao commented Jul 25, 2022

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

What's changed and what's your intention?

This PR fixes that we cannot create an mview on a singleton upstream mview. There're several reasons.

  • StreamTableScan does not check whether the distribution key of upstream mview is empty, and always use HashShard distribution.
  • If there's no exchange in the stream graph of new mview, we'll use the default is_singleton = false regardless of the distribution.
  • The scheduler currently assume that the downstream chain actors lie on the same parallel unit of the upstream materializes, which makes it fail to resolve the upstream actor id of singleton mview.
  • We won't broadcast the downstream chain actor infos to the upstream worker. When it creates a Output, it needs the downstream address to decide whether we need a RemoteOutput.

This PR also includes some style refinement of the stream manager. 💦

image

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)

Refer to a related PR or issue link (optional)

Signed-off-by: Bugen Zhao <i@bugenzhao.com>
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
Copy link
Contributor

@st1page st1page left a comment

Choose a reason for hiding this comment

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

LGTM

Signed-off-by: Bugen Zhao <i@bugenzhao.com>
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
@BugenZhao BugenZhao marked this pull request as ready for review July 26, 2022 04:06
@BugenZhao BugenZhao requested review from xxchan and skyzh July 26, 2022 04:07
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
@@ -78,6 +79,11 @@ impl BatchSeqScan {
Distribution::Single
} else {
match self.logical.distribution_key() {
// FIXME: Should be `Single` if no distribution key.
Copy link
Member Author

Choose a reason for hiding this comment

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

Opened #4164 for this.

Comment on lines +105 to +108
assert!(
!key.is_empty(),
"hash key should not be empty, use `Single` instead"
);
Copy link
Member Author

Choose a reason for hiding this comment

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

Opened #4165 for this.

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

Comment on lines +264 to +265
// fragment in the downstream mview. Remove this when we refactor the fragmenter.
bool is_singleton = 6;
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the desired way?

Copy link
Member Author

@BugenZhao BugenZhao Jul 26, 2022

Choose a reason for hiding this comment

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

We may directly operate on the Fragment struct in the frontend instead of the protobuf struct, so that we may be able to directly find whether a fragment is a singleton or not instead of checking the dispatcher type.

Currently, we cannot check whether is_singleton for the most upstream fragment since there's no exchange before it. That's why we need hacking for TopN and Chain. 😢

cc @st1page

// memorize table id for later use
state
.dependent_table_ids
.insert(TableId::new(node.table_id));
current_fragment.is_singleton = node.is_singleton;
Copy link
Contributor

Choose a reason for hiding this comment

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

IIUC, the flag node.is_singleton for chain_node is alwasy true? Or it depends on the whether the upstream mview is singleton or not.

Copy link
Member Author

Choose a reason for hiding this comment

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

Or it depends on the whether the upstream mview is singleton or not.

✔️

@@ -467,6 +467,7 @@ where
for fragment in fragment_graph.fragments.values_mut() {
mview_count += fill_mview_id(fragment.node.as_mut().unwrap(), mview_id);
}
let fragment_graph = fragment_graph;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let fragment_graph = fragment_graph;

Copy link
Member Author

Choose a reason for hiding this comment

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

This's for making it immutable, so we won't fear that the variable will unexpectedly change after this line. 🥺

Signed-off-by: Bugen Zhao <i@bugenzhao.com>
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
@codecov
Copy link

codecov bot commented Jul 26, 2022

Codecov Report

Merging #4153 (99832bf) into main (27d203c) will increase coverage by 0.03%.
The diff coverage is 69.33%.

@@            Coverage Diff             @@
##             main    #4153      +/-   ##
==========================================
+ Coverage   73.92%   73.96%   +0.03%     
==========================================
  Files         839      839              
  Lines      119199   119202       +3     
==========================================
+ Hits        88121    88165      +44     
+ Misses      31078    31037      -41     
Flag Coverage Δ
rust 73.96% <69.33%> (+0.03%) ⬆️

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

Impacted Files Coverage Δ
...c/frontend/src/optimizer/plan_node/logical_scan.rs 88.57% <ø> (ø)
src/frontend/src/scheduler/local.rs 0.00% <0.00%> (ø)
src/meta/src/rpc/service/ddl_service.rs 3.71% <0.00%> (+0.02%) ⬆️
src/stream/src/task/stream_manager.rs 2.98% <0.00%> (+0.01%) ⬆️
src/frontend/src/stream_fragmenter/mod.rs 91.53% <40.00%> (+0.76%) ⬆️
...ntend/src/optimizer/plan_node/stream_index_scan.rs 27.27% <50.00%> (-0.26%) ⬇️
src/meta/src/stream/scheduler.rs 91.57% <50.00%> (-0.33%) ⬇️
src/meta/src/stream/stream_manager.rs 76.81% <61.81%> (+0.53%) ⬆️
src/stream/src/executor/exchange/output.rs 50.87% <75.00%> (-0.04%) ⬇️
...frontend/src/optimizer/plan_node/batch_seq_scan.rs 93.10% <81.25%> (-0.74%) ⬇️
... and 17 more

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@mergify mergify bot merged commit ea29596 into main Jul 26, 2022
@mergify mergify bot deleted the bz/fix-create-mview-on-singleton branch July 26, 2022 07:35
nasnoisaac pushed a commit to nasnoisaac/risingwave that referenced this pull request Aug 9, 2022
…bs#4153)

* use singleton distribution on stream scan

Signed-off-by: Bugen Zhao <i@bugenzhao.com>

* refine parallelism allocation

Signed-off-by: Bugen Zhao <i@bugenzhao.com>

* fix the bug

Signed-off-by: Bugen Zhao <i@bugenzhao.com>

* fix local mode

Signed-off-by: Bugen Zhao <i@bugenzhao.com>

* refine docs

Signed-off-by: Bugen Zhao <i@bugenzhao.com>

* disable batch fix

Signed-off-by: Bugen Zhao <i@bugenzhao.com>

* add tests

Signed-off-by: Bugen Zhao <i@bugenzhao.com>

* fix tests

Signed-off-by: Bugen Zhao <i@bugenzhao.com>

* fix distributed e2e

Signed-off-by: Bugen Zhao <i@bugenzhao.com>

* remove logging

Signed-off-by: Bugen Zhao <i@bugenzhao.com>

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
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.

cannot create MV over simple agg MV
3 participants