koarz commented on code in PR #52430:
URL: https://github.com/apache/doris/pull/52430#discussion_r2181444778
##########
cloud/src/common/metric.cpp:
##########
@@ -228,10 +230,91 @@ static void export_fdb_status_details(const std::string&
status_str) {
}
}
+void get_partition_boundaries_count(std::vector<std::string>&
partition_boundaries,
+ std::unordered_map<std::string, size_t>&
partition_count) {
+ size_t prefix_size = FdbTxnKv::fdb_partition_key_prefix().size();
+ for (auto&& boundary : partition_boundaries) {
+ if (boundary.size() < prefix_size + 1 || boundary[prefix_size] !=
CLOUD_USER_KEY_SPACE01) {
+ continue;
+ }
+
+ std::string_view user_key(boundary);
+ user_key.remove_prefix(prefix_size + 1); // Skip the KEY_SPACE prefix.
+ std::vector<std::tuple<std::variant<int64_t, std::string>, int, int>>
out;
+ decode_key(&user_key, &out); // ignore any error, since the boundary
key might be truncated.
+
+ auto visitor = [](auto&& arg) -> std::string {
+ using T = std::decay_t<decltype(arg)>;
+ if constexpr (std::is_same_v<T, std::string>) {
+ return arg;
+ } else {
+ return std::to_string(arg);
+ }
+ };
+
+ if (!out.empty()) {
+ std::string key;
+ for (size_t i = 0; i < 3 && i < out.size(); ++i) {
+ key += std::visit(visitor, std::get<0>(out[i])) + '|';
+ }
+ key.pop_back();
+ partition_count[key]++;
+ }
+ }
+}
+
+static void export_meta_ranges_details(TxnKv* kv) {
+ auto* txn_kv = dynamic_cast<FdbTxnKv*>(kv);
+ if (!txn_kv) {
+ LOG(WARNING) << "this method only support fdb txn kv";
+ return;
+ }
+
+ std::vector<std::string> partition_boundaries;
+ TxnErrorCode code =
txn_kv->get_partition_boundaries(&partition_boundaries);
+ if (code != TxnErrorCode::TXN_OK) {
+ auto msg = fmt::format("failed to get boundaries, code={}", code);
+ return;
+ }
+
+ std::unordered_map<std::string, size_t> partition_count;
+ get_partition_boundaries_count(partition_boundaries, partition_count);
+
+ int64_t txn_count {}, meta_count {}, recycle_count {};
+ for (auto&& [key, count] : partition_count) {
+ std::vector<std::string> keys;
+ size_t pos {};
+ // split key with '|'
+ do {
+ size_t p = std::min(key.size(), key.find('|', pos));
+ keys.emplace_back(key.substr(pos, p - pos));
+ pos = p + 1;
+ } while (pos < key.size());
+ keys.resize(3);
+ if (keys[0] == "txn") {
+ txn_count += count;
+ g_bvar_meta_ranges_txn_instance_tag_count.put({keys[1], keys[2]},
count);
+ } else if (keys[0] == "meta") {
+ meta_count += count;
+ g_bvar_meta_ranges_meta_instance_tag_count.put({keys[1], keys[2]},
count);
+ } else if (keys[0] == "recycle") {
+ recycle_count += count;
+ g_bvar_meta_ranges_recycle_instance_tag_count.put({keys[1],
keys[2]}, count);
+ } else {
Review Comment:
delete bitmap belongs to metadata
##########
cloud/src/common/metric.cpp:
##########
@@ -228,10 +230,91 @@ static void export_fdb_status_details(const std::string&
status_str) {
}
}
+void get_partition_boundaries_count(std::vector<std::string>&
partition_boundaries,
+ std::unordered_map<std::string, size_t>&
partition_count) {
+ size_t prefix_size = FdbTxnKv::fdb_partition_key_prefix().size();
+ for (auto&& boundary : partition_boundaries) {
+ if (boundary.size() < prefix_size + 1 || boundary[prefix_size] !=
CLOUD_USER_KEY_SPACE01) {
+ continue;
+ }
+
+ std::string_view user_key(boundary);
+ user_key.remove_prefix(prefix_size + 1); // Skip the KEY_SPACE prefix.
+ std::vector<std::tuple<std::variant<int64_t, std::string>, int, int>>
out;
+ decode_key(&user_key, &out); // ignore any error, since the boundary
key might be truncated.
+
+ auto visitor = [](auto&& arg) -> std::string {
+ using T = std::decay_t<decltype(arg)>;
+ if constexpr (std::is_same_v<T, std::string>) {
+ return arg;
+ } else {
+ return std::to_string(arg);
+ }
+ };
+
+ if (!out.empty()) {
+ std::string key;
+ for (size_t i = 0; i < 3 && i < out.size(); ++i) {
+ key += std::visit(visitor, std::get<0>(out[i])) + '|';
+ }
+ key.pop_back();
+ partition_count[key]++;
+ }
+ }
+}
+
+static void export_meta_ranges_details(TxnKv* kv) {
+ auto* txn_kv = dynamic_cast<FdbTxnKv*>(kv);
+ if (!txn_kv) {
+ LOG(WARNING) << "this method only support fdb txn kv";
+ return;
+ }
+
+ std::vector<std::string> partition_boundaries;
+ TxnErrorCode code =
txn_kv->get_partition_boundaries(&partition_boundaries);
+ if (code != TxnErrorCode::TXN_OK) {
+ auto msg = fmt::format("failed to get boundaries, code={}", code);
+ return;
+ }
+
+ std::unordered_map<std::string, size_t> partition_count;
+ get_partition_boundaries_count(partition_boundaries, partition_count);
+
+ int64_t txn_count {}, meta_count {}, recycle_count {};
+ for (auto&& [key, count] : partition_count) {
+ std::vector<std::string> keys;
+ size_t pos {};
+ // split key with '|'
+ do {
+ size_t p = std::min(key.size(), key.find('|', pos));
+ keys.emplace_back(key.substr(pos, p - pos));
+ pos = p + 1;
+ } while (pos < key.size());
+ keys.resize(3);
+ if (keys[0] == "txn") {
+ txn_count += count;
+ g_bvar_meta_ranges_txn_instance_tag_count.put({keys[1], keys[2]},
count);
+ } else if (keys[0] == "meta") {
+ meta_count += count;
+ g_bvar_meta_ranges_meta_instance_tag_count.put({keys[1], keys[2]},
count);
+ } else if (keys[0] == "recycle") {
+ recycle_count += count;
+ g_bvar_meta_ranges_recycle_instance_tag_count.put({keys[1],
keys[2]}, count);
+ } else {
Review Comment:
delete bitmap belongs to meta
--
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]