8000 [Feature] Support marking data files as shared in tablet metadata and skipping to delete shared data files in vacuum, leaving them for full gc to clean up by xiangguangyxg · Pull Request #60140 · StarRocks/starrocks · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[Feature] Support marking data files as shared in tablet metadata and skipping to delete shared data files in vacuum, leaving them for full gc to clean up #60140

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

xiangguangyxg
Copy link
Contributor

Why I'm doing:

This is a preliminary work for tablet splitting and merging.
When an old tablet is split to two new tablets, the two new tablets will share all the data files (segment files, delvec files, cloud-native pk index files). These shared data files need to be marked as shared in tablet metadata and skipped to delete them in vacuum, leaving them for full gc to clean up.

What I'm doing:

Support marking data files as shared in tablet metadata and skipping to delete shared data files in vacuum, leaving them for full gc to clean up.

Fixes #59134

What type of PR is this:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

Does this PR entail a change in behavior?

  • Yes, this PR will result in a change in behavior.
  • No, this PR will not result in a change in behavior.

If yes, please specify the type of change:

  • Interface/UI changes: syntax, type conversion, expression evaluation, display information
  • Parameter changes: default values, similar parameters but with different default values
  • Policy changes: use new policy to replace old one, functionality automatically enabled
  • Feature removed
  • Miscellaneous: upgrade & downgrade compatibility, etc.

Checklist:

  • I have added test cases for my bug fix or my new feature
  • This pr needs user documentation (for new or modified features or behaviors)
    • I have added documentation for my new feature or new function
  • This is a backport pr

Bugfix cherry-pick branch check:

  • I have checked the version labels which the pr will be auto-backported to the target branch
    • 3.5
    • 3.4
    • 3.3

@xiangguangyxg xiangguangyxg requested a review from a team as a code owner June 20, 2025 09:13
@wanpengfei-git wanpengfei-git requested a review from a team June 20, 2025 09:14
@@ -510,6 +528,7 @@ void MetaFileBuilder::_sstable_meta_clean_after_alter_type() {
FileMetaPB file_meta;
file_meta.set_name(sstable.filename());
file_meta.set_size(sstable.filesize());
file_meta.set_shared(sstable.shared());
_tablet_meta->mutable_orphan_files()->Add(std::move(file_meta));
}
// Clear the SSTable metadata.
Copy link

Choose a reason for hiding this comment

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

The most risky bug in this code is:
Incorrect index usage for shared_segments.

You can modify the code like this:

@@ -94,12 +94,15 @@ void MetaFileBuilder::apply_column_mode_partial_update(const TxnLogPB_OpWrite& op_write) {
     for (int i = 0; i < op_write.rowset().segments_size(); ++i) {
         FileMetaPB file_meta;
         file_meta.set_name(op_write.rowset().segments(i));
-        if (op_write.rowset().shared_segments_size() > 0) {
-            file_meta.set_shared(op_write.rowset().shared_segments(i));
+        if (op_write.rowset().shared_segments_size() > i) { // Ensure index does not go out of bounds
+            file_meta.set_shared(op_write.rowset().shared_segments(i)); 
         }
         _tablet_meta->mutable_orphan_files()->Add(std::move(file_meta));
     }
 }

This correction ensures you do not access indices outside the bounds of shared_segments, which would cause runtime errors.

RETURN_IF_ERROR(deleter.delete_file(join_path(data_dir, f.name())));
}
}
if (latest_metadata->sstable_meta().sstables_size() > 0) {
for (const auto& sst : latest_metadata->sstable_meta().sstables()) {
if (sst.shared()) {
continue;
}
RETURN_IF_ERROR(deleter.delete_file(join_path(data_dir, sst.filename())));
}
}
Copy link

Choose a reason for hiding this comment

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

The most risky bug in this code is:
Not correctly checking if a segment index exists in shared_segments causing possible undefined behavior or segmentation fault.

You can modify the code like this:

for (int i = 0; i < rowset.segments_size(); ++i) {
    bool is_shared_segment = false;
    if (rowset.shared_segments_size() > i) {
        is_shared_segment = rowset.shared_segments(i);
    }
    if (is_shared_segment) {
		continue;
	}
    RETURN_IF_ERROR(deleter.delete_file(join_path(data_dir, rowset.segments(i))));
}

@xiangguangyxg xiangguangyxg force-pushed the shared_file b 8000 ranch 2 times, most recently from 9f08e92 to d953ec0 Compare June 20, 2025 12:40
… skipping to delete shared data files in vacuum, leaving them for full gc to clean up

Signed-off-by: xiangguangyxg <xiangguangyxg@gmail.com>
Copy link

Copy link

[Java-Extensions Incremental Coverage Report]

pass : 0 / 0 (0%)

Copy link

[FE Incremental Coverage Report]

pass : 0 / 0 (0%)

Copy link

[BE Incremental Coverage Report]

fail : 38 / 54 (70.37%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 be/src/storage/lake/vacuum.cpp 10 17 58.82% [326, 337, 338, 348, 818, 826, 834]
🔵 be/src/storage/lake/rowset.cpp 4 6 66.67% [132, 174]
🔵 be/src/storage/lake/meta_file.cpp 18 24 75.00% [100, 170, 259, 260, 337, 412]
🔵 be/src/storage/lake/rowset_update_state.cpp 4 5 80.00% [572]
🔵 be/src/storage/lake/update_manager.cpp 1 1 100.00% []
🔵 be/src/storage/lake/txn_log_applier.cpp 1 1 100.00% []

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.

Dynamic tablet splitting and merging
2 participants
0