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

feat(storage): change the prefix_hint to dist_key_hint for bloom_filter #6575

Merged
merged 59 commits into from
Dec 8, 2022

Conversation

wcy-fdu
Copy link
Contributor

@wcy-fdu wcy-fdu commented Nov 24, 2022

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

Background

After the watermark design:

  1. we currently only use the bloom filter when the distribution key is a prefix of pk and the state store needs a prefix_hint which supposed to be the distribution key
  2. the time column might not be a part of the distribution_key because it might be a hotspot
  3. we need time col as pk prefix to do fast state cleaning

2 and 3 means the distribution key will not be the prefix of pkpkwhich is conflict with 1.

Proposal

Bloom filter always uses distribution key, so distribution key do not need to be the prefix of pk.

After we break the assumption and distribution key will may not be the prefix of pk, there will be the following changes:

  1. In StateTable/StorageTable, previous we check bloom filter only when key_indices==dist_key_indices, now we only need to judge whether distribution_key is the subset of pk.
  2. Previously, as distribution_key is prefix, the bloom filter key is also the prefix of FullKey, which means the bloom filter key contains TablePrefix and VnodePrefix(For convenience slice. In new design, bloom filter key is no need to contains TablePrefix and VnodePrefix. So in a word, bloom filter key is distribution_key.
    Note that we may implement per table bloom filter after storage: improve SST builder with FullKey struct #6391
  3. Based on 2,
  • we need to remove table_id and vnode in prefix_hint, which is named dist_key_hint in this PR. vnode is connected in relational table layer, table_id is connected in hummock.
  • we can not do such assertions:
    let next_key = next_key(prefix_hint);
    // learn more detail about start_bound with storage_table.rs.
    match key_range.start_bound() {
    // it guarantees that the start bound must be included (some different case)
    // 1. Include(pk + col_bound) => prefix_hint <= start_bound <
    // next_key(prefix_hint)
    //
    // for case2, frontend need to reject this, avoid excluded start_bound and
    // transform it to included(next_key), without this case we can just guarantee
    // that start_bound < next_key
    //
    // 2. Include(next_key(pk +
    // col_bound)) => prefix_hint <= start_bound <= next_key(prefix_hint)
    //
    // 3. Include(pk) => prefix_hint <= start_bound < next_key(prefix_hint)
    Included(range_start) | Excluded(range_start) => {
    assert!(range_start.as_slice() >= prefix_hint.as_slice());
    assert!(range_start.as_slice() < next_key.as_slice() || next_key.is_empty());
    }
    _ => unreachable!(),
    }
    match key_range.end_bound() {
    Included(range_end) => {
    assert!(range_end.as_slice() >= prefix_hint.as_slice());
    assert!(range_end.as_slice() < next_key.as_slice() || next_key.is_empty());
    }
    // 1. Excluded(end_bound_of_prefix(pk + col)) => prefix_hint < end_bound <=
    // next_key(prefix_hint)
    //
    // 2. Excluded(pk + bound) => prefix_hint < end_bound <=
    // next_key(prefix_hint)
    Excluded(range_end) => {
    assert!(range_end.as_slice() > prefix_hint.as_slice());
    assert!(range_end.as_slice() <= next_key.as_slice() || next_key.is_empty());
    }
    std::ops::Bound::Unbounded => {
    assert!(next_key.is_empty());
    }

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)

close #6288

src/stream/src/common/table/state_table.rs Show resolved Hide resolved
src/stream/src/common/table/state_table.rs Outdated Show resolved Hide resolved
src/storage/src/hummock/state_store.rs Outdated Show resolved Hide resolved
src/storage/src/hummock/state_store_v1.rs Outdated Show resolved Hide resolved
src/frontend/src/optimizer/plan_node/stream_materialize.rs Outdated Show resolved Hide resolved
src/storage/hummock_sdk/src/filter_key_extractor.rs Outdated Show resolved Hide resolved
@hzxa21 hzxa21 requested a review from Li0k November 25, 2022 06:24
@wcy-fdu
Copy link
Contributor Author

wcy-fdu commented Nov 25, 2022

Just found it a little hard to verify whether these changes are correct, so I opened this PR, hoping to detect it through CI. Sorry forgot to draft it...
I will check the comments later and invite review after all CI tests have passed😊.

@wcy-fdu wcy-fdu marked this pull request as draft November 25, 2022 13:32
@codecov
Copy link

codecov bot commented Nov 28, 2022

Codecov Report

Merging #6575 (e524946) into main (0439b74) will increase coverage by 0.01%.
The diff coverage is 79.10%.

@@            Coverage Diff             @@
##             main    #6575      +/-   ##
==========================================
+ Coverage   73.22%   73.23%   +0.01%     
==========================================
  Files        1024     1024              
  Lines      163823   163891      +68     
==========================================
+ Hits       119960   120033      +73     
+ Misses      43863    43858       -5     
Flag Coverage Δ
rust 73.23% <79.10%> (+0.01%) ⬆️

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

Impacted Files Coverage Δ
src/ctl/src/cmd_impl/hummock/list_kv.rs 0.00% <0.00%> (ø)
src/storage/hummock_test/src/failpoint_tests.rs 0.00% <0.00%> (ø)
src/storage/hummock_test/src/snapshot_tests.rs 65.10% <ø> (ø)
src/storage/src/hummock/state_store.rs 76.92% <ø> (+0.20%) ⬆️
src/storage/src/store.rs 69.64% <ø> (ø)
src/storage/src/table/batch_table/storage_table.rs 82.18% <31.81%> (-2.32%) ⬇️
src/stream/src/common/table/state_table.rs 82.57% <48.64%> (-0.60%) ⬇️
src/common/src/catalog/internal_table.rs 83.33% <72.41%> (-16.67%) ⬇️
src/storage/hummock_test/src/state_store_tests.rs 80.16% <76.66%> (ø)
...rc/storage/hummock_sdk/src/filter_key_extractor.rs 90.48% <91.42%> (-0.49%) ⬇️
... and 19 more

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

@wcy-fdu wcy-fdu marked this pull request as ready for review November 30, 2022 06:09
@wcy-fdu
Copy link
Contributor Author

wcy-fdu commented Nov 30, 2022

Hi guys, this PR can be reviewed now, welcome to leave your comments. cc @hzxa21 @Li0k @st1page

@@ -80,6 +80,7 @@ tokio-stream = "0.1"
tonic = { version = "0.2", package = "madsim-tonic" }
tracing = "0.1"
twox-hash = "1"
xxhash-rust = { version = "0.8.5", features = ["xxh32"] }
Copy link
Collaborator

Choose a reason for hiding this comment

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

twox-hash and xxhash-rust are both used to calculate xxhash. Let's pick one and only use one lib for xxhash.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's replace twox-hash with xxhash-rust it in next PR.

src/common/src/catalog/internal_table.rs Outdated Show resolved Hide resolved
src/common/src/catalog/internal_table.rs Outdated Show resolved Hide resolved
src/storage/hummock_sdk/src/filter_key_extractor.rs Outdated Show resolved Hide resolved
/// or continuous.
/// Note that `dist_key_in_pk_indices` may be shuffled, the start index should be the
/// minimum value.
pub fn get_dist_key_start_index_in_pk(dist_key_in_pk_indices: &[usize]) -> Option<usize> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

get_min_dist_key_start_index_if_continuous?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

start_index is always min

src/storage/hummock_sdk/src/filter_key_extractor.rs Outdated Show resolved Hide resolved
src/storage/hummock_sdk/src/filter_key_extractor.rs Outdated Show resolved Hide resolved
src/storage/src/table/batch_table/storage_table.rs Outdated Show resolved Hide resolved
src/storage/src/hummock/mod.rs Show resolved Hide resolved
Copy link
Collaborator

@hzxa21 hzxa21 left a comment

Choose a reason for hiding this comment

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

Rest LGTM. Good job! Thanks for the PR!

src/common/src/catalog/internal_table.rs Outdated Show resolved Hide resolved
src/storage/src/hummock/mod.rs Show resolved Hide resolved
@mergify mergify bot merged commit 62e49bf into main Dec 8, 2022
@mergify mergify bot deleted the wcy/prefix-bloom-filter branch December 8, 2022 15:51
mergify bot pushed a commit that referenced this pull request Dec 15, 2022
…_key (#6871)

Perviously, we use `distribution_key` as our bloom filter key, and  `distribution_key`  is always the prefix of pk. After watermark design,  we can not ensure the distribution key be the prefix of pk(#6288), so #6575 has changed the `prefix_hint` to `dist_key_hint` for bloom_filter.
However, using distribution key as bloom filter key will make things more complex, for example: we need to handle many corner cases, such as shuffled distribution key and discontinuous distribution key. And we need to intercept distribution key from pk, and do many judgement in `StateTable`/`StorageTable`/`FilterKeyExtract`.

After some discussion, we can decouple bloom filter key and distribution key, just use pk prefix as the bloom filter key, this makes things easier and bloom filter will be used in more places.


Approved-By: hzxa21

Co-Authored-By: congyi <15605187270@163.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat(state store): Change the prefix_hint to dist_key_hint for bloom_filter
3 participants