wyxxxcat commented on code in PR #63377:
URL: https://github.com/apache/doris/pull/63377#discussion_r3331563906
##########
cloud/src/recycler/recycler.cpp:
##########
@@ -2906,108 +2905,110 @@ int InstanceRecycler::recycle_tablets(int64_t
table_id, int64_t index_id,
}
int64_t tablet_id = tablet_meta_pb.tablet_id();
- if (!check_lazy_txn_finished(txn_kv_, instance_id_,
tablet_meta_pb.tablet_id())) {
+ if (config::enable_recycler_check_lazy_txn_finished &&
+ !check_lazy_txn_finished(txn_kv_, instance_id_,
tablet_meta_pb.tablet_id())) {
LOG(WARNING) << "lazy txn not finished tablet_id=" <<
tablet_meta_pb.tablet_id();
return -1;
}
- tablet_idx_keys.push_back(meta_tablet_idx_key({instance_id_,
tablet_id}));
- restore_job_keys.push_back(job_restore_tablet_key({instance_id_,
tablet_id}));
- if (is_multi_version) {
- // The tablet index/inverted index are recycled in
recycle_versioned_tablet.
- tablet_compact_stats_keys.push_back(
- versioned::tablet_compact_stats_key({instance_id_,
tablet_id}));
- tablet_load_stats_keys.push_back(
- versioned::tablet_load_stats_key({instance_id_,
tablet_id}));
- versioned_meta_tablet_keys.push_back(
- versioned::meta_tablet_key({instance_id_, tablet_id}));
- }
TEST_SYNC_POINT_RETURN_WITH_VALUE("recycle_tablet::bypass_check",
false);
sync_executor.add([this, &num_recycled, tid = tablet_id, range_move =
use_range_remove,
- &metrics_context, k]() mutable -> TabletKeyPair {
+ &metrics_context, k]() mutable -> TabletInfo {
if (recycle_tablet(tid, metrics_context) != 0) {
LOG_WARNING("failed to recycle tablet")
.tag("instance_id", instance_id_)
.tag("tablet_id", tid);
range_move = false;
- return {std::string_view(), range_move};
+ return {.tablet_meta_key = std::string_view(),
+ .tablet_id = tid,
+ .range_move = range_move};
}
++num_recycled;
LOG(INFO) << "recycle_tablets scan, key=" << (k.empty() ?
"(empty)" : hex(k));
- return {k, range_move};
+ return {.tablet_meta_key = k, .tablet_id = tid, .range_move =
range_move};
});
return 0;
};
// TODO(AlexYue): Add one ut to cover use_range_remove = false
auto loop_done = [&, this]() -> int {
+ int ret = 0;
bool finished = true;
- auto tablet_keys = sync_executor.when_all(&finished);
+ bool has_empty_key = false;
+ auto tablets_info = sync_executor.when_all(&finished);
if (!finished) {
LOG_WARNING("failed to recycle tablet").tag("instance_id",
instance_id_);
return -1;
}
- if (tablet_keys.empty() && tablet_idx_keys.empty()) return 0;
- if (!tablet_keys.empty() &&
- std::ranges::all_of(tablet_keys, [](const auto& k) { return
k.first.empty(); })) {
- return -1;
+
+ size_t size_before_erase = tablets_info.size();
+ std::erase_if(tablets_info, [](const TabletInfo& t) { return
t.tablet_meta_key.empty(); });
+ if (tablets_info.empty()) {
+ return size_before_erase == 0 ? 0 : -1;
+ } else if (size_before_erase != tablets_info.size()) {
+ has_empty_key = true;
}
+
+ ret = has_empty_key ? -1 : 0;
// sort the vector using key's order
- std::sort(tablet_keys.begin(), tablet_keys.end(),
- [](const auto& prev, const auto& last) { return prev.first <
last.first; });
+ std::ranges::sort(tablets_info, [](const auto& prev, const auto& last)
{
+ return prev.tablet_meta_key < last.tablet_meta_key;
+ });
bool use_range_remove = true;
- for (auto& [_, remove] : tablet_keys) {
- if (!remove) {
- use_range_remove = remove;
+ for (auto& tablet_info : tablets_info) {
+ if (!has_empty_key && !tablet_info.range_move) {
+ use_range_remove = tablet_info.range_move;
break;
}
}
DORIS_CLOUD_DEFER {
- tablet_idx_keys.clear();
- restore_job_keys.clear();
init_rs_keys.clear();
- tablet_compact_stats_keys.clear();
- tablet_load_stats_keys.clear();
- versioned_meta_tablet_keys.clear();
};
std::unique_ptr<Transaction> txn;
if (txn_kv_->create_txn(&txn) != TxnErrorCode::TXN_OK) {
LOG(WARNING) << "failed to delete tablet meta kv, instance_id=" <<
instance_id_;
return -1;
}
std::string tablet_key_end;
- if (!tablet_keys.empty()) {
+ if (!tablets_info.empty()) {
if (use_range_remove) {
- tablet_key_end = std::string(tablet_keys.back().first) +
'\x00';
- txn->remove(tablet_keys.front().first, tablet_key_end);
+ tablet_key_end =
std::string(tablets_info.back().tablet_meta_key) + '\x00';
+ txn->remove(tablets_info.front().tablet_meta_key,
tablet_key_end);
} else {
- for (auto& [k, _] : tablet_keys) {
- txn->remove(k);
+ for (auto& tablet_info : tablets_info) {
+ txn->remove(tablet_info.tablet_meta_key);
}
}
}
if (is_multi_version) {
Review Comment:
@gavinchou here
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]