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(pageserver): support partial gc-compaction for delta layers #9611

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

Conversation

skyzh
Copy link
Member

@skyzh skyzh commented Nov 1, 2024

Problem

The final patch for partial compaction, part of #9114, close #8921 (note that we didn't implement parallel compaction or compaction scheduler for partial compaction -- currently this needs to be scheduled by using a Python script to split the keyspace, and in the future, automatically split based on the key partitioning when the pageserver wants to trigger a gc-compaction)

Summary of changes

  • Update the layer selection algorithm to use the same selection as full compaction (everything intersect/below gc horizon)
  • Update the layer selection algorithm to also generate a list of delta layers that need to be rewritten
  • Add the logic to rewrite delta layers and add them back to the layer map
  • Update test case to do partial compaction on deltas

Checklist before requesting a review

  • I have performed a self-review of my code.
  • If it is a core feature, I have added thorough tests.
  • Do we need to implement analytics? if so did you add the relevant metrics to the dashboard?
  • If this PR requires public announcement, mark it with /release-notes label and add several sentences in this section.

Checklist before merging

  • Do not forget to reformat commit message to not include the above checklist

@skyzh skyzh requested a review from a team as a code owner November 1, 2024 19:50
Copy link

github-actions bot commented Nov 1, 2024

No tests were run or test report is not available

Test coverage report is not available

The comment gets automatically updated with the latest test results
647fe84 at 2024-11-07T16:46:55.267Z :recycle:

Copy link
Contributor

@problame problame left a comment

Choose a reason for hiding this comment

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

The final patch for partial compaction,

Hm, is this truly the final piece of work in partial bottommost compaction? We don't support partial bottommost compaction yet.


We should not have a not-partial-bottommost-compact going forward, to reduce the amount of potential code paths that need to be kept in mind / reviewed.

Hence, can we please switch the API to take the compaction_key_range a Range<Key> instead of Option<Range<Key>>.

Full bottommost compaction unit tests can pass Key::MIN..Key::MAX. Or should it be just .. ? Or Key::Min..=Key::MAX.

Anyway, hope you get the point.

pageserver/src/tenant/timeline/compaction.rs Outdated Show resolved Hide resolved
if let Some(err) = check_valid_layermap(&layer_names) {
bail!("cannot run gc-compaction because {}", err);
warn!("gc-compaction layer map check failed because {}, this is normal if partial compaction is not finished yet", err);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought a week or two ago you said that you wanted to relax the definition of what a valid layer map is towards "as long as no layers overlap it's valid".

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, but doing that check would be O(n^2) and I don't want to implement it that way, so let's warn here first.

false
};
let last_key: &mut Key = last_key.as_mut().unwrap();
stat.on_unique_key_visited(); // TODO: adjust statistics for partial compaction
Copy link
Contributor

Choose a reason for hiding this comment

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

Tracking this in a follow-up task already? I'm not sure I understand what needs to be done.

Copy link
Member Author

Choose a reason for hiding this comment

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

It depends on whether we want to include keys not in the partial compaction range into the statistics. Currently I use the statistics to know how much space is saved by running the compaction.

Comment on lines 2104 to 2103
if let Some(compaction_key_range) = &job_desc.partial_key_range {
for layer in job_desc.rewrite_layers {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be nice to encode in the type system that rewrite_layers is only meaningful if partial_key_range is some.
Maybe by using a custom enum instead of Option for partial_key_range.

Eventually, partial compaction should be the only thing we do (not in this PR, branches are not yet supported)

Comment on lines 2107 to 2106
// This download should be no-op b/c it's included in selected_layer and has been downloaded before
let resident_layer = layer.download_and_keep_resident().await?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not store ResidentLayers in rewrite_layers and selected_layers then?

pageserver/src/tenant/timeline/compaction.rs Outdated Show resolved Hide resolved
@skyzh skyzh force-pushed the skyzh/partial-compaction-delta branch from 24cd910 to 4896c0b Compare November 6, 2024 20:39
skyzh and others added 2 commits November 7, 2024 11:36
Signed-off-by: Alex Chi Z <[email protected]>

partial address comments

Signed-off-by: Alex Chi Z <[email protected]>
@skyzh skyzh force-pushed the skyzh/partial-compaction-delta branch from 16cc56f to 647fe84 Compare November 7, 2024 16:36
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.

gc-compaction: split compaction jobs across keyspace
2 participants