gavinchou commented on code in PR #52523:
URL: https://github.com/apache/doris/pull/52523#discussion_r2182263486


##########
cloud/src/recycler/recycler_service.cpp:
##########
@@ -52,6 +58,215 @@ 
RecyclerServiceImpl::RecyclerServiceImpl(std::shared_ptr<TxnKv> txn_kv, Recycler
 
 RecyclerServiceImpl::~RecyclerServiceImpl() = default;
 
+void RecyclerServiceImpl::statistics_recycle(
+        ::google::protobuf::RpcController* controller,
+        const ::doris::cloud::StatisticsRecycleRequest* request,
+        ::doris::cloud::StatisticsRecycleResponse* response, 
::google::protobuf::Closure* done) {
+    auto* ctrl = static_cast<brpc::Controller*>(controller);
+    LOG(INFO) << "rpc from " << ctrl->remote_side() << " request=" << 
request->ShortDebugString();
+    brpc::ClosureGuard closure_guard(done);
+    MetaServiceCode code = MetaServiceCode::OK;
+    std::string msg;
+    DORIS_CLOUD_DEFER {
+        response->mutable_status()->set_code(code);
+        response->mutable_status()->set_msg(msg);
+        LOG(INFO) << (code == MetaServiceCode::OK ? "succ to " : "failed to ")
+                  << "statistics_recycle"
+                  << " " << ctrl->remote_side() << " " << msg;
+    };
+
+    std::unique_ptr<Transaction> txn;
+    TxnErrorCode err = txn_kv_->create_txn(&txn);
+    if (err != TxnErrorCode::TXN_OK) {
+        code = MetaServiceCode::KV_TXN_CREATE_ERR;
+        msg = "failed to create txn";
+        return;
+    }
+
+    static std::map<std::string, std::function<void(InstanceRecycler&)>> 
resource_handlers = {
+            {"index",
+             [](InstanceRecycler& instance_recycler) {
+                 instance_recycler.scan_and_statistics_indexes();
+             }},
+            {"partition",
+             [](InstanceRecycler& instance_recycler) {
+                 instance_recycler.scan_and_statistics_partitions();
+             }},
+            {"tmp_rowset",
+             [](InstanceRecycler& instance_recycler) {
+                 instance_recycler.scan_and_statistics_tmp_rowsets();
+             }},
+            {"rowset",
+             [](InstanceRecycler& instance_recycler) {
+                 instance_recycler.scan_and_statistics_rowsets();
+             }},
+            {"abort_timeout_txn",
+             [](InstanceRecycler& instance_recycler) {
+                 instance_recycler.scan_and_statistics_abort_timeout_txn();
+             }},
+            {"expired_txn_label",
+             [](InstanceRecycler& instance_recycler) {
+                 instance_recycler.scan_and_statistics_expired_txn_label();
+             }},
+            {"version",
+             [](InstanceRecycler& instance_recycler) {
+                 instance_recycler.scan_and_statistics_versions();
+             }},
+            {"copy_job",
+             [](InstanceRecycler& instance_recycler) {
+                 instance_recycler.scan_and_statistics_copy_jobs();
+             }},
+            {"stage",
+             [](InstanceRecycler& instance_recycler) {
+                 instance_recycler.scan_and_statistics_stage();
+             }},
+            {"expired_stage_object", [](InstanceRecycler& instance_recycler) {
+                 instance_recycler.scan_and_statistics_expired_stage_objects();
+             }}};
+
+    std::vector<std::string> invalid_resource_types;
+    // check invalid resource type
+    std::for_each(request->resource_type().begin(), 
request->resource_type().end(),
+                  [&](const std::string& resource_type) {
+                      if (!resource_handlers.contains(resource_type)) {
+                          invalid_resource_types.emplace_back(resource_type);
+                      }
+                  });
+    if (!invalid_resource_types.empty()) {
+        code = MetaServiceCode::INVALID_ARGUMENT;
+        msg = fmt::format(
+                "invalid resource type(s): {}, valid resource_type have [{}]",
+                fmt::join(invalid_resource_types, ", "),
+                std::accumulate(resource_handlers.begin(), 
resource_handlers.end(), std::string(),
+                                [&](const std::string& acc, const auto& pair) {
+                                    return acc.empty() ? pair.first : acc + ", 
" + pair.first;
+                                }));
+        LOG_WARNING(msg);
+        return;
+    }
+
+    std::set<std::string> instance_ids;
+    std::vector<InstanceInfoPB> instances;
+    get_all_instances(txn_kv_.get(), instances);
+
+    // check if a string matches a pattern with '*' and '?' wildcards.
+    auto isMatch = [&](const std::string& targetString, const std::string& 
patternString) {

Review Comment:
   `isMatch` -> is_match
   check other occurrences 



-- 
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]

Reply via email to