-
Notifications
You must be signed in to change notification settings - Fork 45
feat(compaction): support universal & force level0 compaction strategy for pk table #152
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
95a8f6e
feat(compaction): support universal compaction strategy
lxy-9602 4c5799b
fix0642
lxy-9602 5e5f9f4
fix
lxy-9602 25a401c
Apply suggestion from @Copilot
lxy-9602 39e5cb6
add test
lxy-9602 a140840
fix
lxy-9602 7e16d39
fix
lxy-9602 d2dcd8e
add ForceUpLevel0Compaction
lxy-9602 63d6d8f
fix
lxy-9602 6e14d95
fix
lxy-9602 f458bd4
fix
lxy-9602 64c2baf
fix
lxy-9602 815468c
Merge branch 'main' into add-compact-strategy
lxy-9602 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /* | ||
| * Copyright 2026-present Alibaba Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "paimon/core/io/data_file_meta.h" | ||
| #include "paimon/core/mergetree/level_sorted_run.h" | ||
| namespace paimon { | ||
| /// A files unit for compaction. | ||
| struct CompactUnit { | ||
| static CompactUnit FromLevelRuns(int32_t output_level, | ||
| const std::vector<LevelSortedRun>& runs) { | ||
| std::vector<std::shared_ptr<DataFileMeta>> files; | ||
| for (const auto& run : runs) { | ||
| const auto& files_in_run = run.run.Files(); | ||
| files.insert(files.end(), files_in_run.begin(), files_in_run.end()); | ||
| } | ||
| return FromFiles(output_level, files, /*file_rewrite=*/false); | ||
| } | ||
|
|
||
| static CompactUnit FromFiles(int32_t output_level, | ||
| const std::vector<std::shared_ptr<DataFileMeta>>& files, | ||
| bool file_rewrite) { | ||
| return CompactUnit(output_level, files, file_rewrite); | ||
| } | ||
|
|
||
| CompactUnit(int32_t _output_level, const std::vector<std::shared_ptr<DataFileMeta>>& _files, | ||
| bool _file_rewrite) | ||
| : output_level(_output_level), files(_files), file_rewrite(_file_rewrite) {} | ||
|
|
||
| int32_t output_level; | ||
| std::vector<std::shared_ptr<DataFileMeta>> files; | ||
| bool file_rewrite; | ||
| }; | ||
| } // namespace paimon | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| /* | ||
| * Copyright 2026-present Alibaba Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "paimon/core/compact/compact_unit.h" | ||
| #include "paimon/core/io/data_file_meta.h" | ||
| #include "paimon/core/mergetree/level_sorted_run.h" | ||
| namespace paimon { | ||
| /// Compact strategy to decide which files to select for compaction. | ||
| class CompactStrategy { | ||
| public: | ||
| virtual ~CompactStrategy() = default; | ||
|
|
||
| /// Pick compaction unit from runs. | ||
| /// @note Compaction is runs-based, not file-based. | ||
| /// Level 0 is special, one run per file; all other levels are one run per level. | ||
| /// Compaction is sequential from small level to large level. | ||
| virtual Result<std::optional<CompactUnit>> Pick(int32_t num_levels, | ||
| const std::vector<LevelSortedRun>& runs) = 0; | ||
| /// Pick a compaction unit consisting of all existing files. | ||
| // TODO(xinyu.lxy): support RecordLevelExpire and BucketedDvMaintainer | ||
| static std::optional<CompactUnit> PickFullCompaction(int32_t num_levels, | ||
| const std::vector<LevelSortedRun>& runs, | ||
| bool force_rewrite_all_files) { | ||
| int32_t max_level = num_levels - 1; | ||
|
lxy-9602 marked this conversation as resolved.
|
||
| if (runs.empty()) { | ||
| // no sorted run, no need to compact | ||
| return std::nullopt; | ||
| } | ||
| // only max level files | ||
| if (runs.size() == 1 && runs[0].level == max_level) { | ||
| std::vector<std::shared_ptr<DataFileMeta>> files_to_be_compacted; | ||
| const auto& run = runs[0]; | ||
| for (const auto& file : run.run.Files()) { | ||
| if (force_rewrite_all_files) { | ||
| // add all files when force compacted | ||
| files_to_be_compacted.push_back(file); | ||
| } | ||
| // TODO(xinyu.lxy): support RecordLevelExpire and BucketedDvMaintainer | ||
| } | ||
| if (files_to_be_compacted.empty()) { | ||
| return std::nullopt; | ||
| } | ||
| return CompactUnit::FromFiles(max_level, files_to_be_compacted, /*file_rewrite=*/true); | ||
| } | ||
| // full compaction | ||
| return CompactUnit::FromLevelRuns(max_level, runs); | ||
| } | ||
| }; | ||
| } // namespace paimon | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.