Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.9k
[fix](checker) Avoid false-positive leaked delete bitmaps for unexpired job tmp rowsets#64313
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
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1227,6 +1227,11 @@ int InstanceChecker::do_delete_bitmap_inverted_check() { | ||
| std::unordered_set<std::string> pending_delete_bitmaps {}; | ||
| } tablet_rowsets_cache {}; | ||
| std::unordered_map<int64_t, std::unordered_set<std::string>> unexpired_tmp_rowsets; | ||
| if (int ret = collect_unexpired_job_tmp_rowsets(unexpired_tmp_rowsets); ret < 0) { | ||
| return ret; | ||
| } | ||
| std::unique_ptr<RangeGetIterator> it; | ||
| auto begin = meta_delete_bitmap_key({instance_id_, 0, "", 0, 0}); | ||
| auto end = | ||
| @@ -1267,6 +1272,9 @@ int InstanceChecker::do_delete_bitmap_inverted_check() { | ||
| if (tablet_rowsets_cache.tablet_id == -1 || | ||
| tablet_rowsets_cache.tablet_id != tablet_id) { | ||
| if (tablet_rowsets_cache.tablet_id != -1) { | ||
| unexpired_tmp_rowsets.erase(tablet_rowsets_cache.tablet_id); | ||
| } | ||
| TabletMetaCloudPB tablet_meta; | ||
| int ret = get_tablet_meta(txn_kv_.get(), instance_id_, tablet_id, tablet_meta); | ||
| if (ret < 0) { | ||
| @@ -1319,8 +1327,15 @@ int InstanceChecker::do_delete_bitmap_inverted_check() { | ||
| continue; | ||
| } | ||
| bool belongs_to_unexpired_tmp_rowset = false; | ||
| auto tmp_rowsets_it = unexpired_tmp_rowsets.find(tablet_id); | ||
| if (tmp_rowsets_it != unexpired_tmp_rowsets.end()) { | ||
| belongs_to_unexpired_tmp_rowset = tmp_rowsets_it->second.contains(rowset_id); | ||
| } | ||
| if (!tablet_rowsets_cache.rowsets.contains(rowset_id) && | ||
| !tablet_rowsets_cache.pending_delete_bitmaps.contains(std::string(k))) { | ||
| !tablet_rowsets_cache.pending_delete_bitmaps.contains(std::string(k)) && | ||
| !belongs_to_unexpired_tmp_rowset) { | ||
| TEST_SYNC_POINT_CALLBACK( | ||
| "InstanceChecker::do_delete_bitmap_inverted_check.get_leaked_delete_bitmap", | ||
| &tablet_id, &rowset_id, &version, &segment_id); | ||
| @@ -1338,6 +1353,116 @@ int InstanceChecker::do_delete_bitmap_inverted_check() { | ||
| return (leaked_delete_bitmaps > 0 || abnormal_delete_bitmaps > 0) ? 1 : 0; | ||
| } | ||
| int InstanceChecker::collect_unexpired_job_tmp_rowsets( | ||
| std::unordered_map<int64_t, std::unordered_set<std::string>>& tmp_rowsets) { | ||
| static constexpr int64_t max_unexpired_tmp_rowsets = 1000; | ||
| auto begin = meta_rowset_tmp_key({instance_id_, 0, 0}); | ||
| auto end = meta_rowset_tmp_key({instance_id_, INT64_MAX, 0}); | ||
| std::unique_ptr<RangeGetIterator> it; | ||
| int64_t num_scanned = 0; | ||
| int64_t num_non_job = 0; | ||
| int64_t num_skipped_non_job_txns = 0; | ||
| int64_t num_unexpired = 0; | ||
| int64_t num_expired = 0; | ||
| int64_t last_txn_id = -1; | ||
| int64_t current_time = duration_cast<seconds>(system_clock::now().time_since_epoch()).count(); | ||
| while (it == nullptr /* may be not init */ || (it->more() && !stopped())) { | ||
| std::unique_ptr<Transaction> txn; | ||
| TxnErrorCode err = txn_kv_->create_txn(&txn); | ||
| if (err != TxnErrorCode::TXN_OK) { | ||
| LOG(WARNING) << "failed to create txn"; | ||
| return -1; | ||
| } | ||
| err = txn->get(begin, end, &it); | ||
| if (err != TxnErrorCode::TXN_OK) { | ||
| LOG(WARNING) << "failed to get tmp rowset kv, err=" << err; | ||
| return -1; | ||
| } | ||
| if (!it->has_next()) { | ||
| break; | ||
| } | ||
| while (it->has_next() && !stopped()) { | ||
| auto [k, v] = it->next(); | ||
| ++num_scanned; | ||
| std::string_view k1 = k; | ||
| k1.remove_prefix(1); | ||
| std::vector<std::tuple<std::variant<int64_t, std::string>, int, int>> out; | ||
| if (decode_key(&k1, &out) != 0 || out.size() < 5) { | ||
| LOG(WARNING) << "malformed tmp rowset key, key=" << hex(k); | ||
| return -1; | ||
| } | ||
| // 0x01 "meta" ${instance_id} "rowset_tmp" ${txn_id} ${tablet_id} -> RowsetMetaCloudPB | ||
| auto txn_id = std::get<int64_t>(std::get<0>(out[3])); | ||
| bool is_first_rowset_of_txn = last_txn_id != txn_id; | ||
| last_txn_id = txn_id; | ||
| doris::RowsetMetaCloudPB rowset; | ||
| if (!rowset.ParseFromArray(v.data(), v.size())) { | ||
| LOG(WARNING) << "malformed tmp rowset meta, key=" << hex(k); | ||
| return -1; | ||
| } | ||
| if (!rowset.has_job_id() || rowset.job_id().empty()) { | ||
| ++num_non_job; | ||
| if (is_first_rowset_of_txn) { | ||
| ++num_skipped_non_job_txns; | ||
| if (txn_id == INT64_MAX) { | ||
| begin = end; | ||
| } else { | ||
| begin = meta_rowset_tmp_key({instance_id_, txn_id + 1, 0}); | ||
| } | ||
| it.reset(); | ||
| break; | ||
| } | ||
| if (!it->has_next()) { | ||
| begin = k; | ||
| begin.push_back('\x00'); | ||
| } | ||
| continue; | ||
| } | ||
| // Must use the same threshold as the recycler so that a delete bitmap is never | ||
| // reported as leaked while its tmp rowset is still alive from the recycler's view. | ||
| // `earlest_ts` is a local sentinel initialized to 0 on purpose: it keeps the value | ||
| // below any real expiration so the helper never updates the recycler's | ||
| // earliest-ts bvar (the checker must not touch the recycler's metrics). | ||
| int64_t earlest_ts = 0; | ||
| int64_t expiration = | ||
| calculate_tmp_rowset_expired_time(instance_id_, rowset, &earlest_ts); | ||
| if (current_time < expiration) { | ||
| tmp_rowsets[rowset.tablet_id()].insert(rowset.rowset_id_v2()); | ||
| ++num_unexpired; | ||
| if (num_unexpired >= max_unexpired_tmp_rowsets) { | ||
| LOG(WARNING) | ||
| << "collect unexpired tmp rowsets for delete bitmap checker reached " | ||
| << "limit, remaining tmp rowsets will not be considered and may cause " | ||
| << "false positives, instance_id=" << instance_id_ | ||
| << ", num_scanned=" << num_scanned << ", num_non_job=" << num_non_job | ||
| << ", num_skipped_non_job_txns=" << num_skipped_non_job_txns | ||
| << ", num_unexpired=" << num_unexpired | ||
| << ", num_expired=" << num_expired | ||
| << ", limit=" << max_unexpired_tmp_rowsets; | ||
| return 0; | ||
| } | ||
mymeiyi marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } else { | ||
| ++num_expired; | ||
| } | ||
| if (!it->has_next()) { | ||
| begin = k; | ||
| begin.push_back('\x00'); | ||
| } | ||
| } | ||
| } | ||
| LOG(INFO) << "collect unexpired tmp rowsets for delete bitmap checker finished, instance_id=" | ||
| << instance_id_ << ", num_scanned=" << num_scanned << ", num_non_job=" << num_non_job | ||
| << ", num_skipped_non_job_txns=" << num_skipped_non_job_txns | ||
| << ", num_unexpired=" << num_unexpired << ", num_expired=" << num_expired; | ||
| return 0; | ||
| } | ||
| int InstanceChecker::get_pending_delete_bitmap_keys( | ||
| int64_t tablet_id, std::unordered_set<std::string>& pending_delete_bitmaps) { | ||
| std::unique_ptr<Transaction> txn; | ||
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 |
|---|---|---|
| @@ -57,6 +57,11 @@ class SimpleThreadPool; | ||
| class RecyclerMetricsContext; | ||
| class TabletRecyclerMetricsContext; | ||
| class SegmentRecyclerMetricsContext; | ||
| int64_t calculate_tmp_rowset_expired_time( | ||
| const std::string& instance_id_, const doris::RowsetMetaCloudPB& tmp_rowset_meta_pb, | ||
| int64_t* earlest_ts /* tmp_rowset earliest expiration ts */); | ||
mymeiyi marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| struct RecyclerThreadPoolGroup { | ||
| RecyclerThreadPoolGroup() = default; | ||
| RecyclerThreadPoolGroup(std::shared_ptr<SimpleThreadPool> s3_producer_pool, | ||
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
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.