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): support non_pk_prefix_watermark state cleaning #19889

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

Li0k
Copy link
Contributor

@Li0k Li0k commented Dec 23, 2024

I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.

What's changed and what's your intention?

related to #18802

This PR supports non_pk_prefix_watermark state cleaning for Hummock.

Since non_pk_prefix_watermark relies on catalogs, this introduces additional overhead. Therefore, this PR does not guarantee read filtering for non_pk_prefix_watermark and only handles expired data.

The changes are as follows:

  1. watermarks of type non_pk_prefix_watermark are not added to ReadWatermarkIndex.

  2. state table support to write non_pk_prefix_watermark and serialize.

  3. compaction catalog agent support to get watermark serde

  4. skip watermark iterator supports filtering non_pk_prefix_watermark.

Checklist

  • I have written necessary rustdoc comments.
  • I have added necessary unit tests and integration tests.
  • I have added test labels as necessary.
  • I have added fuzzing tests or opened an issue to track them.
  • My PR contains breaking changes.
  • My PR changes performance-critical code, so I will run (micro) benchmarks and present the results.
  • My PR contains critical fixes that are necessary to be merged into the latest release.

Documentation

  • My PR needs documentation updates.
Release note

@Li0k Li0k changed the title feat(storage): non_pk_watermark state clean WIP: feat(storage): non_pk_watermark state clean Dec 23, 2024
@Li0k Li0k marked this pull request as ready for review December 23, 2024 07:28
@graphite-app graphite-app bot requested a review from a team December 23, 2024 08:18
@Li0k Li0k requested a review from a team as a code owner December 25, 2024 12:20
@Li0k Li0k requested a review from xxchan December 25, 2024 12:20
@Li0k Li0k changed the title WIP: feat(storage): non_pk_watermark state clean feat(storage): support non_pk_prefix_watermark state cleaning Dec 30, 2024
@Li0k Li0k requested review from hzxa21, st1page and chenzl25 December 30, 2024 07:32
.committed_epoch,
)),

WatermarkSerdeType::NonPkPrefix => None, /* do not fill the non-pk prefix watermark to index */
Copy link
Collaborator

Choose a reason for hiding this comment

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

Given that non pk prefix watermark will never be used in CN, should we exclude it in meta-CN version delta notification? We can add sanity check in the CN side to make sure this assumption holds.

.filter_map(|table| {
// pk prefix watermark.
if table.clean_watermark_index_in_pk.is_none()
|| table.clean_watermark_index_in_pk.unwrap() == 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this assume the pk prefix watermark can only be a single column? Do we have a sanity check somewhere to make sure this assumption holds?

.table_watermarks
.iter()
.filter_map(|(table_id, table_watermarks)| {
if table_id_with_pk_prefix_watermark.contains(table_id) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We already have a WaterMarkType define in the version, why don't we just use that to filter out table with non pk prefix watermark?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, if we filter out non pk prefix watermark here, how can compactor retrieve the non pk prefix watermark? Based on the logic here, it seems that we rely on the fact that non pk prefix watermark is present in the compact task.

@@ -114,6 +115,48 @@ impl CompactTask {
}
}

impl CompactTask {
// The compact task may need to reclaim key with TTL
pub fn is_contains_ttl(&self) -> bool {
Copy link
Collaborator

Choose a reason for hiding this comment

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

rename: contains_ttl

}

// The compact task may need to reclaim key with range tombstone
pub fn is_contains_range_tombstone(&self) -> bool {
Copy link
Collaborator

Choose a reason for hiding this comment

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

rename: contains_range_tombstone

@@ -301,6 +308,26 @@ impl WatermarkDirection {
}
}

pub fn filter_by_watermark_datum(
Copy link
Collaborator

Choose a reason for hiding this comment

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

minor: datum_filter_by_watermark

@@ -19,11 +19,14 @@ use std::mem::size_of;
use std::ops::Bound::{Excluded, Included, Unbounded};
use std::sync::Arc;

use bincode::{Decode, Encode};
Copy link
Collaborator

Choose a reason for hiding this comment

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

We need this because we define Decode Encode on WatermarkSerdeType. Is this neccessary?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the reason why we need it is because we need it for hummock trace. Like other trace related struct, let's not leak encode/decode outside of hummock trace and handle it here because we can just use a bool to do the encode and decode in hummock trace.

@@ -8,6 +8,7 @@ license = { workspace = true }
repository = { workspace = true }

[dependencies]
bincode = { version = "=2.0.0-rc.3", features = ["serde"] }
Copy link
Collaborator

Choose a reason for hiding this comment

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

ditto. See comments above.

@@ -42,10 +47,14 @@ pub struct SkipWatermarkIterator<I> {
}

impl<I: HummockIterator<Direction = Forward>> SkipWatermarkIterator<I> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nits: since SkipWatermarkIterator is only used by compactor, how about moving skip_watermark.rs into src/hummock/compactor?

});
let watermark_col_in_pk =
row.datum_at(*watermark_col_idx_in_pk);
cmp_datum(
Copy link
Collaborator

Choose a reason for hiding this comment

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

IIUC, if cmp_datum returns Euqal | Greater, based on the logic in L360, the watermark will be advanced. I think this is incorrect for non pk prefix watermark because the non pk prefix watermark and the pk doesn't have the same ordering.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants