This is an automated email from the ASF dual-hosted git repository.
wyxxxcat pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 47b0dea0959 [improvement](cloud) Add current-round recycler metrics
and record last-round results (#70225)
47b0dea0959 is described below
commit 47b0dea0959f3071e9f9f00f7ce463376953c29f
Author: Yixuan Wang <[email protected]>
AuthorDate: Tue Nov 24 21:53:24 2026 +0800
[improvement](cloud) Add current-round recycler metrics and record
last-round results (#70225)
### Background
<!-- How the feature or module this PR touches works today, in two to
four plain sentences, for a reviewer who doesn't know it. Link the user
doc if there is one. Leave the problem and the fix to Problem Summary.
-->
### What problem does this PR solve?
Collect `current_round` metrics for the cloud recycler to observe
progress during an ongoing recycling round, and record the round's
results in `last_round` when it finishes.
- Collect and report the numbers of scanned, expired, and recycled KV
entries through `current_round` metrics.
- Update these metrics during recycling to expose the current round's
progress.
- Record the recycled count and bytes in `last_round` at the end of the
round, and clear `current_round` metrics afterward.
<!-- Issue Number: "close #N" if this PR resolves the issue, "#N" if it
only relates to it, "None" if there is none. A Feature needs an issue.
-->
<!-- Related PR: "#N (relation)" for each PR a reviewer should know
about, such as "#123 (introduced the bug)", separated by commas. Write
"None" if no related PR is known. -->
<!-- PR Type: Bugfix, Performance, Feature, Enhancement, Refactor, Test,
Build/CI/Chore, Revert, Release/Dependency, or Other. -->
Issue Number:
Related PR:
PR Type:
Problem Summary:
<!-- Two to five sentences: the problem or need and who is affected; the
approach in one sentence; when the diff is larger than that suggests,
what else it had to handle, or that most of it is tests; and what
existing users see after an upgrade. -->
### Details
<!--
For a diff of more than about 300 changed lines, start with "- **Change
map:**": how many lines are production code, tests, generated files, and
docs, then the code in parts, each with the problem it handles and its
size.
Then answer each field of your PR type on its own line, as "- **Field:**
answer", in this order:
Bugfix: Frequency, Root cause, Why existing tests missed it, Fix, Other
paths and branches
Performance: Why it was slow, Optimization, Results, Applicability and
cost
Feature: Scope, Design, Usage, Default behavior, Compatibility
Enhancement: Before and after, Configs and defaults, Impact on existing
users
Refactor: Moves vs. logic changes, Behavior change, Compatibility,
Performance impact, Rollback
Test, adding tests: Scenarios, What existing tests miss, Fails when
broken
Test, fixing a test: Failure, Cause, Stability evidence
Build/CI/Chore: Affected, Developer and release impact, License and
third-party, Rollback
Revert: Why not fix forward, Original author notified, Follow-up
Release/Dependency: Versions, Upstream changes, Compatibility, Rollback
Other: Why Other
"None" is a valid answer when it is true. Don't restate the diff.
-->
### Testing
<!-- The tests, suites, or commands that ran, what each shows, and where
it ran (locally or in CI). For a fix, the test that fails before it and
passes after. -->
### Notes for Reviewers
<!-- Optional; delete this section if there is nothing to say. Why each
non-obvious edit was made, what you are unsure about, and where to start
reading if Details has no Change map. -->
### Release note
<!-- One paragraph on what users will notice, or None. -->
### Check List (For Author)
<!-- Behavior changed: "No", or "Yes (see Details)" with a Behavior
change field in Details. -->
<!-- Does this need documentation: "No", or "Yes" with the
apache/doris-website PR or the plan. -->
<!-- Pre-submission status: "Ready"; "Partially verified: " and what is
not verified; or "Not ready: " and why, for a Draft PR. -->
- Behavior changed:
- Does this need documentation:
- Pre-submission status:
### AI Disclosure
<!-- Tool: the agent and model, or None. Generated: the parts it wrote
(code, tests, this description), or None. Human review: what you
reviewed of the generated parts, or "Not applicable" without AI tools.
You may add "- Prompts:" to summarize how you directed the agent. -->
- Tool:
- Generated:
- Human review:
---
cloud/src/common/bvars.cpp | 10 +++
cloud/src/common/bvars.h | 3 +
cloud/src/recycler/recycler.cpp | 164 +++++++++++++++++++++++++---------------
cloud/src/recycler/recycler.h | 35 +++++++--
4 files changed, 145 insertions(+), 67 deletions(-)
diff --git a/cloud/src/common/bvars.cpp b/cloud/src/common/bvars.cpp
index 2f5c5d77c50..63fcef02572 100644
--- a/cloud/src/common/bvars.cpp
+++ b/cloud/src/common/bvars.cpp
@@ -171,6 +171,16 @@ mBvarStatus<int64_t>
g_bvar_recycler_instance_last_round_to_recycle_num("recycle
mBvarStatus<int64_t>
g_bvar_recycler_instance_last_round_recycled_bytes("recycler_instance_last_round_recycled_bytes",
{"instance_id", "resource_type"});
mBvarStatus<int64_t>
g_bvar_recycler_instance_last_round_to_recycle_bytes("recycler_instance_last_round_to_recycle_bytes",
{"instance_id", "resource_type"});
mBvarStatus<double>
g_bvar_recycler_instance_last_round_recycle_elpased_ts("recycler_instance_last_round_recycle_elpased_ts",
{"instance_id", "resource_type"});
+// Current round TxnKV statistics.
+mBvarStatus<int64_t> g_bvar_recycler_instance_current_round_kv_scanned(
+ "recycler_instance_current_round_kv_scanned",
+ {"instance_id", "resource_type"});
+mBvarStatus<int64_t> g_bvar_recycler_instance_current_round_kv_expired(
+ "recycler_instance_current_round_kv_expired",
+ {"instance_id", "resource_type"});
+mBvarStatus<int64_t> g_bvar_recycler_instance_current_round_kv_recycled(
+ "recycler_instance_current_round_kv_recycled",
+ {"instance_id", "resource_type"});
// total recycled num and bytes of resources since recycler started
mBvarInt64Adder
g_bvar_recycler_instance_recycle_total_num_since_started("recycler_instance_recycle_total_num_since_started",
{"instance_id", "resource_type"});
mBvarInt64Adder
g_bvar_recycler_instance_recycle_total_bytes_since_started("recycler_instance_recycle_total_bytes_since_started",
{"instance_id", "resource_type"});
diff --git a/cloud/src/common/bvars.h b/cloud/src/common/bvars.h
index 70d23bd1cec..09b35c2775a 100644
--- a/cloud/src/common/bvars.h
+++ b/cloud/src/common/bvars.h
@@ -727,6 +727,9 @@ extern mBvarStatus<int64_t>
g_bvar_recycler_instance_last_round_to_recycle_num;
extern mBvarStatus<int64_t> g_bvar_recycler_instance_last_round_recycled_bytes;
extern mBvarStatus<int64_t>
g_bvar_recycler_instance_last_round_to_recycle_bytes;
extern mBvarStatus<double>
g_bvar_recycler_instance_last_round_recycle_elpased_ts;
+extern mBvarStatus<int64_t> g_bvar_recycler_instance_current_round_kv_scanned;
+extern mBvarStatus<int64_t> g_bvar_recycler_instance_current_round_kv_expired;
+extern mBvarStatus<int64_t> g_bvar_recycler_instance_current_round_kv_recycled;
extern mBvarInt64Adder
g_bvar_recycler_instance_recycle_total_num_since_started;
extern mBvarInt64Adder
g_bvar_recycler_instance_recycle_total_bytes_since_started;
extern mBvarIntAdder g_bvar_recycler_instance_recycle_round;
diff --git a/cloud/src/recycler/recycler.cpp b/cloud/src/recycler/recycler.cpp
index 01d71ac51e0..017b4225ebc 100644
--- a/cloud/src/recycler/recycler.cpp
+++ b/cloud/src/recycler/recycler.cpp
@@ -2560,9 +2560,9 @@ int InstanceRecycler::batch_abort_txn_or_job_for_recycle(
void InstanceRecycler::submit_recycle_prepare_rowsets_job(
SimpleThreadPool& worker_pool, std::vector<std::string>
rowset_keys_to_abort,
- std::atomic_long* num_recycled) {
+ std::atomic_long* num_recycled, RecyclerMetricsContext*
metrics_context) {
int ret = worker_pool.submit([this, rowset_keys_to_abort =
std::move(rowset_keys_to_abort),
- num_recycled]() mutable {
+ num_recycled, metrics_context]() mutable {
std::vector<std::pair<std::string, RelatedTxnOrJobAbortTask>>
keys_to_recheck;
int abort_ret =
batch_abort_txn_or_job_for_recycle<RecycleRowsetPB>(rowset_keys_to_abort,
keys_to_recheck);
@@ -2600,6 +2600,8 @@ void InstanceRecycler::submit_recycle_prepare_rowsets_job(
continue;
}
num_recycled->fetch_add(1, std::memory_order_relaxed);
+ metrics_context->total_recycled_num.fetch_add(1,
std::memory_order_relaxed);
+ metrics_context->report();
}
});
if (ret != 0) {
@@ -2669,6 +2671,9 @@ void
InstanceRecycler::submit_recycle_tmp_rowsets_job(SimpleThreadPool& worker_p
return;
}
num_recycled->fetch_add(keys_to_delete.size(),
std::memory_order_relaxed);
+ metrics_context->total_recycled_num.fetch_add(keys_to_delete.size(),
+
std::memory_order_relaxed);
+ metrics_context->report();
});
}
@@ -2780,17 +2785,19 @@ int
InstanceRecycler::recycle_table_stream_offset_prefix(std::string prefix,
std::string end = prefix;
end.push_back('\xff');
std::vector<std::string_view> keys;
- auto collect_key = [&keys](std::string_view key, std::string_view) -> int {
+ auto collect_key = [&keys, metrics_context](std::string_view key,
std::string_view) -> int {
+ ++metrics_context->total_scanned_num;
keys.push_back(key);
return 0;
};
auto remove_keys = [this, &keys, metrics_context]() -> int {
- if (keys.empty()) {
- return 0;
- }
DORIS_CLOUD_DEFER {
+ metrics_context->report();
keys.clear();
};
+ if (keys.empty()) {
+ return 0;
+ }
const size_t num_keys = keys.size();
if (txn_remove(txn_kv_.get(), keys) != 0) {
LOG_WARNING("failed to delete table stream offsets")
@@ -2799,7 +2806,6 @@ int
InstanceRecycler::recycle_table_stream_offset_prefix(std::string prefix,
return -1;
}
metrics_context->total_recycled_num += num_keys;
- metrics_context->report();
return 0;
};
return scan_and_recycle(std::move(prefix), end, std::move(collect_key),
std::move(remove_keys));
@@ -2972,7 +2978,7 @@ int InstanceRecycler::recycle_indexes() {
// Elements in `index_keys` has the same lifetime as `it` in
`scan_and_recycle`
std::vector<std::string_view> index_keys;
auto recycle_func = [&, this](std::string_view k, std::string_view v) ->
int {
- ++num_scanned;
+ metrics_context.total_scanned_num = ++num_scanned;
RecycleIndexPB index_pb;
if (!index_pb.ParseFromArray(v.data(), v.size())) {
LOG_WARNING("malformed recycle index value").tag("key", hex(k));
@@ -2983,7 +2989,7 @@ int InstanceRecycler::recycle_indexes() {
calculate_index_expired_time(instance_id_, index_pb, &earlest_ts))
{ // not expired
return 0;
}
- ++num_expired;
+ metrics_context.total_expired_num = ++num_expired;
// decode index_id
auto k1 = k;
k1.remove_prefix(1);
@@ -3034,7 +3040,6 @@ int InstanceRecycler::recycle_indexes() {
return -1;
}
metrics_context.total_recycled_num = ++num_recycled;
- metrics_context.report();
check_recycle_task(instance_id_, task_name, num_scanned,
num_recycled, start_time);
return 0;
}
@@ -3068,22 +3073,23 @@ int InstanceRecycler::recycle_indexes() {
}
}
- metrics_context.total_recycled_num = ++num_recycled;
- metrics_context.report();
check_recycle_task(instance_id_, task_name, num_scanned, num_recycled,
start_time);
index_keys.push_back(k);
return 0;
};
- auto loop_done = [&index_keys, this]() -> int {
- if (index_keys.empty()) return 0;
+ auto loop_done = [&index_keys, &metrics_context, &num_recycled, this]() ->
int {
DORIS_CLOUD_DEFER {
+ metrics_context.report();
index_keys.clear();
};
+ if (index_keys.empty()) return 0;
if (0 != txn_remove(txn_kv_.get(), index_keys)) {
LOG(WARNING) << "failed to delete recycle index kv, instance_id="
<< instance_id_;
return -1;
}
+ num_recycled += index_keys.size();
+ metrics_context.total_recycled_num = num_recycled;
return 0;
};
@@ -3218,7 +3224,7 @@ int InstanceRecycler::recycle_partitions() {
std::vector<std::string_view> partition_keys;
std::vector<std::string> partition_version_keys;
auto recycle_func = [&, this](std::string_view k, std::string_view v) ->
int {
- ++num_scanned;
+ metrics_context.total_scanned_num = ++num_scanned;
RecyclePartitionPB part_pb;
if (!part_pb.ParseFromArray(v.data(), v.size())) {
LOG_WARNING("malformed recycle partition value").tag("key",
hex(k));
@@ -3229,7 +3235,7 @@ int InstanceRecycler::recycle_partitions() {
&earlest_ts)) { //
not expired
return 0;
}
- ++num_expired;
+ metrics_context.total_expired_num = ++num_expired;
// decode partition_id
auto k1 = k;
k1.remove_prefix(1);
@@ -3320,25 +3326,24 @@ int InstanceRecycler::recycle_partitions() {
}
if (ret == 0) {
- ++num_recycled;
check_recycle_task(instance_id_, task_name, num_scanned,
num_recycled, start_time);
partition_keys.push_back(k);
if (part_pb.db_id() > 0) {
partition_version_keys.push_back(partition_version_key(
{instance_id_, part_pb.db_id(), part_pb.table_id(),
partition_id}));
}
- metrics_context.total_recycled_num = num_recycled;
- metrics_context.report();
}
return ret;
};
- auto loop_done = [&partition_keys, &partition_version_keys, this]() -> int
{
- if (partition_keys.empty()) return 0;
+ auto loop_done = [&partition_keys, &partition_version_keys, &num_recycled,
&metrics_context,
+ this]() -> int {
DORIS_CLOUD_DEFER {
partition_keys.clear();
partition_version_keys.clear();
+ metrics_context.report();
};
+ if (partition_keys.empty()) return 0;
std::unique_ptr<Transaction> txn;
TxnErrorCode err = txn_kv_->create_txn(&txn);
if (err != TxnErrorCode::TXN_OK) {
@@ -3357,6 +3362,8 @@ int InstanceRecycler::recycle_partitions() {
<< " err=" << err;
return -1;
}
+ num_recycled += partition_keys.size();
+ metrics_context.total_recycled_num = num_recycled;
return 0;
};
@@ -3395,7 +3402,10 @@ int InstanceRecycler::recycle_versions() {
bool is_recycled = false; // Is last scanned kv recycled
auto recycle_func = [&num_scanned, &num_recycled, &last_scanned_table_id,
&is_recycled,
&metrics_context, this](std::string_view k,
std::string_view) {
- ++num_scanned;
+ DORIS_CLOUD_DEFER {
+ metrics_context.report();
+ };
+ metrics_context.total_scanned_num = ++num_scanned;
auto k1 = k;
k1.remove_prefix(1);
// 0x01 "version" ${instance_id} "partition" ${db_id} ${tbl_id}
${partition_id}
@@ -3405,6 +3415,7 @@ int InstanceRecycler::recycle_versions() {
auto table_id = std::get<int64_t>(std::get<0>(out[4]));
if (table_id == last_scanned_table_id) { // Already handle kvs of this
table
num_recycled += is_recycled; // Version kv of this table
has been recycled
+ metrics_context.total_recycled_num = num_recycled;
return 0;
}
last_scanned_table_id = table_id;
@@ -3453,7 +3464,6 @@ int InstanceRecycler::recycle_versions() {
return -1;
}
metrics_context.total_recycled_num = ++num_recycled;
- metrics_context.report();
is_recycled = true;
return 0;
};
@@ -3490,7 +3500,10 @@ int InstanceRecycler::recycle_orphan_partitions() {
auto recycle_func = [&num_scanned, &num_recycled, &metrics_context,
&is_empty_table,
¤t_table_id, &is_table_kvs_recycled,
this](std::string_view k, std::string_view) {
- ++num_scanned;
+ DORIS_CLOUD_DEFER {
+ metrics_context.report();
+ };
+ metrics_context.total_scanned_num = ++num_scanned;
std::string_view k1(k);
int64_t db_id, table_id, partition_id;
@@ -3564,7 +3577,6 @@ int InstanceRecycler::recycle_orphan_partitions() {
return -1;
}
metrics_context.total_recycled_num = ++num_recycled;
- metrics_context.report();
return 0;
};
@@ -4590,7 +4602,6 @@ int InstanceRecycler::delete_rowset_data(
// that marks the entire batch as failed and prevents txn_remove from
// cleaning up recycle KV keys.
if (num_segments <= 0) {
- metrics_context.total_recycled_num++;
metrics_context.total_recycled_data_size += rs.total_disk_size();
continue;
}
@@ -4790,7 +4801,6 @@ int InstanceRecycler::delete_rowset_data(
rs_meta->second.num_segments();
segment_metrics_context_.total_recycled_data_size +=
rs_meta->second.total_disk_size();
- metrics_context.total_recycled_num++;
}
});
}
@@ -4807,7 +4817,6 @@ int InstanceRecycler::delete_rowset_data(
if (!ret) {
auto rs = rowsets.at(rowset_id);
metrics_context.total_recycled_data_size +=
rs.total_disk_size();
- metrics_context.total_recycled_num++;
segment_metrics_context_.total_recycled_data_size +=
rs.total_disk_size();
segment_metrics_context_.total_recycled_num +=
rs.num_segments();
}
@@ -5417,7 +5426,6 @@ int InstanceRecycler::recycle_tablet(int64_t tablet_id,
RecyclerMetricsContext&
recycle_rowsets_data_size + recycle_rowsets_index_size;
tablet_metrics_context_.report();
segment_metrics_context_.report();
- metrics_context.report();
txn.reset();
if (txn_kv_->create_txn(&txn) != TxnErrorCode::TXN_OK) {
@@ -5809,6 +5817,7 @@ int InstanceRecycler::recycle_rowsets() {
unregister_recycle_task(task_name);
int64_t cost =
duration_cast<seconds>(steady_clock::now().time_since_epoch()).count() -
start_time;
+ metrics_context.report();
metrics_context.finish_report();
LOG_WARNING("recycle rowsets finished, cost={}s", cost)
.tag("instance_id", instance_id_)
@@ -5863,6 +5872,9 @@ int InstanceRecycler::recycle_rowsets() {
<< instance_id_;
} else {
num_recycled.fetch_add(keys.size(),
std::memory_order_relaxed);
+
metrics_context.total_recycled_num.fetch_add(keys.size(),
+
std::memory_order_relaxed);
+ metrics_context.report();
check_recycle_task(instance_id_, "recycle_rowsets",
num_scanned,
num_recycled, start_time);
}
@@ -5884,7 +5896,7 @@ int InstanceRecycler::recycle_rowsets() {
int64_t earlest_ts = std::numeric_limits<int64_t>::max();
auto handle_rowset_kv = [&](std::string_view k, std::string_view v) -> int
{
- ++num_scanned;
+ metrics_context.total_scanned_num = ++num_scanned;
total_rowset_key_size += k.size();
total_rowset_value_size += v.size();
RecycleRowsetPB rowset;
@@ -5902,7 +5914,7 @@ int InstanceRecycler::recycle_rowsets() {
if (current_time < expiration) { // not expired
return 0;
}
- ++num_expired;
+ metrics_context.total_expired_num = ++num_expired;
expired_rowset_size += v.size();
if (!rowset.has_type()) { // old version
`RecycleRowsetPB`
@@ -5933,7 +5945,6 @@ int InstanceRecycler::recycle_rowsets() {
return -1;
}
metrics_context.total_recycled_data_size +=
rowset.rowset_meta().total_disk_size();
- metrics_context.total_recycled_num++;
segment_metrics_context_.total_recycled_data_size +=
rowset.rowset_meta().total_disk_size();
segment_metrics_context_.total_recycled_num +=
rowset.rowset_meta().num_segments();
@@ -6004,6 +6015,9 @@ int InstanceRecycler::recycle_rowsets() {
};
auto loop_done = [&]() -> int {
+ DORIS_CLOUD_DEFER {
+ metrics_context.report();
+ };
std::vector<std::string> rowset_keys_to_delete;
// rowset_id -> rowset_meta
// store rowset id and meta for statistics rs size when delete
@@ -6020,7 +6034,7 @@ int InstanceRecycler::recycle_rowsets() {
}
if (!abort_job_keys_to_process.empty()) {
submit_recycle_prepare_rowsets_job(*worker_pool,
std::move(abort_job_keys_to_process),
- &num_recycled);
+ &num_recycled,
&metrics_context);
}
worker_pool->submit([&, rowset_keys_to_delete =
std::move(rowset_keys_to_delete),
rowsets_to_delete =
std::move(rowsets_to_delete)]() mutable {
@@ -6042,6 +6056,9 @@ int InstanceRecycler::recycle_rowsets() {
return;
}
num_recycled.fetch_add(rowset_keys_to_delete.size(),
std::memory_order_relaxed);
+
metrics_context.total_recycled_num.fetch_add(rowset_keys_to_delete.size(),
+
std::memory_order_relaxed);
+ metrics_context.report();
});
return 0;
};
@@ -6061,12 +6078,13 @@ int InstanceRecycler::recycle_rowsets() {
return -1;
} else {
num_recycled.fetch_add(async_recycled_rowset_keys.size(),
std::memory_order_relaxed);
+
metrics_context.total_recycled_num.fetch_add(async_recycled_rowset_keys.size(),
+
std::memory_order_relaxed);
}
}
// Report final metrics after all concurrent tasks completed
segment_metrics_context_.report();
- metrics_context.report();
return ret;
}
@@ -6120,7 +6138,7 @@ int InstanceRecycler::recycle_restore_jobs() {
std::vector<std::string_view> restore_job_keys;
auto recycle_func = [&, this](std::string_view k, std::string_view v) ->
int {
- ++num_scanned;
+ metrics_context.total_scanned_num = ++num_scanned;
RestoreJobCloudPB restore_job_pb;
if (!restore_job_pb.ParseFromArray(v.data(), v.size())) {
LOG_WARNING("malformed recycle partition value").tag("key",
hex(k));
@@ -6137,7 +6155,7 @@ int InstanceRecycler::recycle_restore_jobs() {
if (current_time < expiration) { // not expired
return 0;
}
- ++num_expired;
+ metrics_context.total_expired_num = ++num_expired;
int64_t tablet_id = restore_job_pb.tablet_id();
LOG(INFO) << "begin to recycle expired restore jobs, instance_id=" <<
instance_id_
@@ -6223,8 +6241,6 @@ int InstanceRecycler::recycle_restore_jobs() {
return -1;
}
- metrics_context.total_recycled_num = ++num_recycled;
- metrics_context.report();
check_recycle_task(instance_id_, task_name, num_scanned, num_recycled,
start_time);
restore_job_keys.push_back(k);
@@ -6233,11 +6249,12 @@ int InstanceRecycler::recycle_restore_jobs() {
return 0;
};
- auto loop_done = [&restore_job_keys, this]() -> int {
- if (restore_job_keys.empty()) return 0;
+ auto loop_done = [&restore_job_keys, &num_recycled, &metrics_context,
this]() -> int {
DORIS_CLOUD_DEFER {
restore_job_keys.clear();
+ metrics_context.report();
};
+ if (restore_job_keys.empty()) return 0;
std::unique_ptr<Transaction> txn;
TxnErrorCode err = txn_kv_->create_txn(&txn);
@@ -6259,6 +6276,8 @@ int InstanceRecycler::recycle_restore_jobs() {
.tag("reason", "failed to commit txn");
return -1;
}
+ num_recycled += restore_job_keys.size();
+ metrics_context.total_recycled_num = num_recycled;
return 0;
};
@@ -6346,6 +6365,9 @@ int InstanceRecycler::recycle_versioned_rowsets() {
<< instance_id_;
} else {
num_recycled.fetch_add(keys.size(),
std::memory_order_relaxed);
+
metrics_context.total_recycled_num.fetch_add(keys.size(),
+
std::memory_order_relaxed);
+ metrics_context.report();
check_recycle_task(instance_id_, "recycle_rowsets",
num_scanned,
num_recycled, start_time);
}
@@ -6364,7 +6386,7 @@ int InstanceRecycler::recycle_versioned_rowsets() {
int64_t earlest_ts = std::numeric_limits<int64_t>::max();
auto handle_rowset_kv = [&, this](std::string_view k, std::string_view v)
-> int {
- ++num_scanned;
+ metrics_context.total_scanned_num = ++num_scanned;
total_rowset_key_size += k.size();
total_rowset_value_size += v.size();
RecycleRowsetPB rowset;
@@ -6382,7 +6404,7 @@ int InstanceRecycler::recycle_versioned_rowsets() {
if (current_time < final_expiration) { // not expired
return 0;
}
- ++num_expired;
+ metrics_context.total_expired_num = ++num_expired;
expired_rowset_size += v.size();
if (!rowset.has_type()) { // old version
`RecycleRowsetPB`
if (!rowset.has_resource_id()) [[unlikely]] { // impossible
@@ -6450,8 +6472,10 @@ int InstanceRecycler::recycle_versioned_rowsets() {
if (recycle_rowset_meta_and_data(task) != 0) {
return;
}
- num_compacted += is_compacted;
num_recycled.fetch_add(1, std::memory_order_relaxed);
+ metrics_context.total_recycled_num.fetch_add(1,
std::memory_order_relaxed);
+ metrics_context.report();
+ num_compacted += is_compacted;
if (rowset_meta.num_segments() == 0) {
++num_empty_rowset;
}
@@ -6465,8 +6489,15 @@ int InstanceRecycler::recycle_versioned_rowsets() {
}
auto loop_done = [&]() -> int {
+ DORIS_CLOUD_DEFER {
+ metrics_context.report();
+ };
if (txn_remove(txn_kv_.get(), orphan_rowset_keys)) {
LOG(WARNING) << "failed to delete recycle rowset kv, instance_id="
<< instance_id_;
+ } else {
+ num_recycled.fetch_add(orphan_rowset_keys.size(),
std::memory_order_relaxed);
+
metrics_context.total_recycled_num.fetch_add(orphan_rowset_keys.size(),
+
std::memory_order_relaxed);
}
orphan_rowset_keys.clear();
return 0;
@@ -6484,6 +6515,8 @@ int InstanceRecycler::recycle_versioned_rowsets() {
return -1;
} else {
num_recycled.fetch_add(async_recycled_rowset_keys.size(),
std::memory_order_relaxed);
+
metrics_context.total_recycled_num.fetch_add(async_recycled_rowset_keys.size(),
+
std::memory_order_relaxed);
}
}
@@ -6649,6 +6682,7 @@ int InstanceRecycler::recycle_tmp_rowsets() {
unregister_recycle_task(task_name);
int64_t cost =
duration_cast<seconds>(steady_clock::now().time_since_epoch()).count() -
start_time;
+ metrics_context.report();
metrics_context.finish_report();
LOG_WARNING("recycle tmp rowsets finished, cost={}s", cost)
.tag("instance_id", instance_id_)
@@ -6680,7 +6714,7 @@ int InstanceRecycler::recycle_tmp_rowsets() {
&tmp_rowset_keys_to_mark_recycled,
&tmp_rowset_keys_to_abort, this,
&metrics_context, &tmp_rowsets,
&tmp_rowset_ref_count_keys](
std::string_view k, std::string_view v) ->
int {
- ++num_scanned;
+ metrics_context.total_scanned_num = ++num_scanned;
total_rowset_key_size += k.size();
total_rowset_value_size += v.size();
doris::RowsetMetaCloudPB rowset;
@@ -6697,7 +6731,7 @@ int InstanceRecycler::recycle_tmp_rowsets() {
if (current_time < expiration) { // not expired
return 0;
}
- ++num_expired;
+ metrics_context.total_expired_num = ++num_expired;
expired_rowset_size += v.size();
if (!rowset.has_resource_id()) {
if (rowset.num_segments() > 0) [[unlikely]] { // impossible
@@ -6753,6 +6787,9 @@ int InstanceRecycler::recycle_tmp_rowsets() {
};
auto loop_done = [&]() -> int {
+ DORIS_CLOUD_DEFER {
+ metrics_context.report();
+ };
std::vector<std::string> tmp_rowset_keys_to_delete;
std::vector<std::string> tmp_rowset_ref_count_keys_to_delete;
std::vector<std::string> mark_keys_to_process;
@@ -6804,6 +6841,9 @@ int InstanceRecycler::recycle_tmp_rowsets() {
return;
}
num_recycled += tmp_rowset_keys_to_delete.size();
+
metrics_context.total_recycled_num.fetch_add(tmp_rowset_keys_to_delete.size(),
+
std::memory_order_relaxed);
+ metrics_context.report();
return;
});
return 0;
@@ -6820,7 +6860,6 @@ int InstanceRecycler::recycle_tmp_rowsets() {
// Report final metrics after all concurrent tasks completed
segment_metrics_context_.report();
- metrics_context.report();
return ret;
}
@@ -6952,7 +6991,10 @@ int InstanceRecycler::abort_timeout_txn() {
auto handle_txn_running_kv = [&num_scanned, &num_timeout, &num_abort,
&num_advance,
¤t_time, &metrics_context,
this](std::string_view k, std::string_view
v) -> int {
- ++num_scanned;
+ DORIS_CLOUD_DEFER {
+ metrics_context.report();
+ };
+ metrics_context.total_scanned_num = ++num_scanned;
std::unique_ptr<Transaction> txn;
TxnErrorCode err = txn_kv_->create_txn(&txn);
@@ -7007,7 +7049,7 @@ int InstanceRecycler::abort_timeout_txn() {
if (!config::force_immediate_recycle &&
txn_running_pb.timeout_time() > current_time) {
return 0;
}
- ++num_timeout;
+ metrics_context.total_expired_num = ++num_timeout;
DCHECK(txn_info.status() != TxnStatusPB::TXN_STATUS_VISIBLE);
txn_info.set_status(TxnStatusPB::TXN_STATUS_ABORTED);
@@ -7046,7 +7088,6 @@ int InstanceRecycler::abort_timeout_txn() {
return -1;
}
metrics_context.total_recycled_num = ++num_abort;
- metrics_context.report();
}
return 0;
@@ -7103,7 +7144,7 @@ int InstanceRecycler::recycle_expired_txn_label() {
duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
auto handle_recycle_txn_kv = [&, this](std::string_view k,
std::string_view v) -> int {
- ++num_scanned;
+ metrics_context.total_scanned_num = ++num_scanned;
RecycleTxnPB recycle_txn_pb;
if (!recycle_txn_pb.ParseFromArray(v.data(), v.size())) {
LOG_WARNING("malformed txn_running_pb").tag("key", hex(k));
@@ -7114,7 +7155,7 @@ int InstanceRecycler::recycle_expired_txn_label() {
(calculate_txn_expired_time(instance_id_, recycle_txn_pb,
&earlest_ts) <=
current_time_ms)) {
VLOG_DEBUG << "found recycle txn, key=" << hex(k);
- num_expired++;
+ metrics_context.total_expired_num = ++num_expired;
std::string_view k1 = k;
k1.remove_prefix(1); // Remove key space
@@ -7235,6 +7276,7 @@ int InstanceRecycler::recycle_expired_txn_label() {
auto loop_done = [&]() -> int {
DORIS_CLOUD_DEFER {
recycle_txn_keys_by_label.clear();
+ metrics_context.report();
};
TEST_SYNC_POINT_CALLBACK(
"InstanceRecycler::recycle_expired_txn_label.check_recycle_txn_keys_by_label",
@@ -7292,7 +7334,6 @@ int InstanceRecycler::recycle_expired_txn_label() {
// Update metrics after all concurrent tasks completed
metrics_context.total_recycled_num = num_recycled.load();
- metrics_context.report();
TEST_SYNC_POINT_CALLBACK("InstanceRecycler::recycle_expired_txn_label.failure",
&ret);
@@ -7465,7 +7506,10 @@ int InstanceRecycler::recycle_copy_jobs() {
auto recycle_func = [&start_time, &num_scanned, &num_finished,
&num_expired, &num_recycled,
&batch_count, &stage_accessor_map, &task_name,
&metrics_context,
this](std::string_view k, std::string_view v) -> int {
- ++num_scanned;
+ DORIS_CLOUD_DEFER {
+ metrics_context.report();
+ };
+ metrics_context.total_scanned_num = ++num_scanned;
CopyJobPB copy_job;
if (!copy_job.ParseFromArray(v.data(), v.size())) {
LOG_WARNING("malformed copy job").tag("key", hex(k));
@@ -7540,7 +7584,7 @@ int InstanceRecycler::recycle_copy_jobs() {
if (!config::force_immediate_recycle && current_time <=
copy_job.timeout_time_ms()) {
return 0;
}
- ++num_expired;
+ metrics_context.total_expired_num = ++num_expired;
}
// delete all copy files
@@ -7571,7 +7615,6 @@ int InstanceRecycler::recycle_copy_jobs() {
}
metrics_context.total_recycled_num = ++num_recycled;
- metrics_context.report();
check_recycle_task(instance_id_, task_name, num_scanned, num_recycled,
start_time);
return 0;
};
@@ -7681,7 +7724,7 @@ int InstanceRecycler::recycle_stage() {
std::vector<std::string_view> stage_keys;
auto recycle_func = [&start_time, &num_scanned, &num_recycled,
&stage_keys, &metrics_context,
this](std::string_view k, std::string_view v) -> int {
- ++num_scanned;
+ metrics_context.total_scanned_num = ++num_scanned;
RecycleStagePB recycle_stage;
if (!recycle_stage.ParseFromArray(v.data(), v.size())) {
LOG_WARNING("malformed recycle stage").tag("key", hex(k));
@@ -7735,22 +7778,23 @@ int InstanceRecycler::recycle_stage() {
<< ", ret=" << ret;
return -1;
}
- metrics_context.total_recycled_num = ++num_recycled;
- metrics_context.report();
check_recycle_task(instance_id_, "recycle_stage", num_scanned,
num_recycled, start_time);
stage_keys.push_back(k);
return 0;
};
- auto loop_done = [&stage_keys, this]() -> int {
- if (stage_keys.empty()) return 0;
+ auto loop_done = [&stage_keys, &num_recycled, &metrics_context, this]() ->
int {
DORIS_CLOUD_DEFER {
stage_keys.clear();
+ metrics_context.report();
};
+ if (stage_keys.empty()) return 0;
if (0 != txn_remove(txn_kv_.get(), stage_keys)) {
LOG(WARNING) << "failed to delete recycle partition kv,
instance_id=" << instance_id_;
return -1;
}
+ num_recycled += stage_keys.size();
+ metrics_context.total_recycled_num = num_recycled;
return 0;
};
if (config::enable_recycler_stats_metrics) {
diff --git a/cloud/src/recycler/recycler.h b/cloud/src/recycler/recycler.h
index 46950970a76..142b5646650 100644
--- a/cloud/src/recycler/recycler.h
+++ b/cloud/src/recycler/recycler.h
@@ -160,12 +160,22 @@ public:
start();
}
- ~RecyclerMetricsContext() = default;
+ ~RecyclerMetricsContext() {
+ // Clear the current-round gauges once this round is over. The
tablet/segment contexts use
+ // the shared "global_recycler" label across all instances, so skip
them here to avoid
+ // zeroing values that other instances are still updating.
+ if (instance_id != "global_recycler") {
+ reset();
+ report();
+ }
+ }
std::atomic_ullong total_need_recycle_data_size = 0;
std::atomic_ullong total_need_recycle_num = 0;
std::atomic_ullong total_recycled_data_size = 0;
+ std::atomic_ullong total_scanned_num = 0;
+ std::atomic_ullong total_expired_num = 0;
std::atomic_ullong total_recycled_num = 0;
std::string operation_type;
@@ -190,6 +200,8 @@ public:
total_need_recycle_data_size = 0;
total_need_recycle_num = 0;
total_recycled_data_size = 0;
+ total_scanned_num = 0;
+ total_expired_num = 0;
total_recycled_num = 0;
start_time = duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_since_epoch())
@@ -206,9 +218,15 @@ public:
{instance_id, operation_type},
total_recycled_data_size.load());
g_bvar_recycler_instance_recycle_total_num_since_started.put(
{instance_id, operation_type}, total_recycled_num.load());
+
g_bvar_recycler_instance_last_round_recycled_bytes.put({instance_id,
operation_type},
+
total_recycled_data_size.load());
+ g_bvar_recycler_instance_last_round_recycled_num.put({instance_id,
operation_type},
+
total_recycled_num.load());
LOG(INFO) << "recycle instance: " << instance_id
<< ", operation type: " << operation_type << ", cost: "
<< cost
- << " ms, total recycled num: " <<
total_recycled_num.load()
+ << " ms, total scanned num: " << total_scanned_num.load()
+ << ", total expired num: " << total_expired_num.load()
+ << ", total recycled num: " << total_recycled_num.load()
<< ", total recycled data size: " <<
total_recycled_data_size.load()
<< " bytes";
if (cost != 0) {
@@ -234,10 +252,12 @@ public:
g_bvar_recycler_instance_last_round_to_recycle_num.put(
{instance_id, operation_type}, value);
} else {
- g_bvar_recycler_instance_last_round_recycled_bytes.put(
- {instance_id, operation_type},
total_recycled_data_size.load());
-
g_bvar_recycler_instance_last_round_recycled_num.put({instance_id,
operation_type},
-
total_recycled_num.load());
+
g_bvar_recycler_instance_current_round_kv_scanned.put({instance_id,
operation_type},
+
total_scanned_num.load());
+
g_bvar_recycler_instance_current_round_kv_expired.put({instance_id,
operation_type},
+
total_expired_num.load());
+ g_bvar_recycler_instance_current_round_kv_recycled.put(
+ {instance_id, operation_type},
total_recycled_num.load());
}
}
}
@@ -673,7 +693,8 @@ private:
void submit_recycle_prepare_rowsets_job(SimpleThreadPool& worker_pool,
std::vector<std::string>
rowset_keys_to_abort,
- std::atomic_long* num_recycled);
+ std::atomic_long* num_recycled,
+ RecyclerMetricsContext*
metrics_context);
void submit_recycle_tmp_rowsets_job(SimpleThreadPool& worker_pool,
std::vector<std::string>
rowset_keys_to_abort,
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]