diff --git a/cloud/src/common/config.h b/cloud/src/common/config.h index 43a426a89593d54..155294ed05e0887 100644 --- a/cloud/src/common/config.h +++ b/cloud/src/common/config.h @@ -225,4 +225,5 @@ CONF_Int32(max_tablet_index_num_per_batch, "1000"); CONF_mInt64(max_num_aborted_txn, "100"); CONF_Bool(enable_check_instance_id, "true"); +CONF_Bool(enable_concurrency_get_tablet_stats, "false"); } // namespace doris::cloud::config diff --git a/cloud/src/meta-service/meta_service.cpp b/cloud/src/meta-service/meta_service.cpp index 4f374832925dd75..b398de8a4345b1c 100644 --- a/cloud/src/meta-service/meta_service.cpp +++ b/cloud/src/meta-service/meta_service.cpp @@ -1618,31 +1618,45 @@ void MetaServiceImpl::get_tablet_stats(::google::protobuf::RpcController* contro } RPC_RATE_LIMIT(get_tablet_stats) - std::unique_ptr txn; - for (auto& i : request->tablet_idx()) { - TabletIndexPB idx(i); - // FIXME(plat1ko): Get all tablet stats in one txn + if (!config::enable_concurrency_get_tablet_stats) { + std::unique_ptr txn; + for (auto& i : request->tablet_idx()) { + TabletIndexPB idx(i); + // FIXME(plat1ko): Get all tablet stats in one txn + TxnErrorCode err = txn_kv_->create_txn(&txn); + if (err != TxnErrorCode::TXN_OK) { + code = cast_as(err); + msg = fmt::format("failed to create txn, tablet_id={}", idx.tablet_id()); + return; + } + if (!(/* idx.has_db_id() && */ idx.has_table_id() && idx.has_index_id() && + idx.has_partition_id() && i.has_tablet_id())) { + get_tablet_idx(code, msg, txn.get(), instance_id, idx.tablet_id(), idx); + if (code != MetaServiceCode::OK) return; + } + auto tablet_stats = response->add_tablet_stats(); + internal_get_tablet_stats(code, msg, txn.get(), instance_id, idx, *tablet_stats, true); + if (code != MetaServiceCode::OK) { + response->clear_tablet_stats(); + break; + } +#ifdef NDEBUG + // Force data size >= 0 to reduce the losses caused by bugs + if (tablet_stats->data_size() < 0) tablet_stats->set_data_size(0); +#endif + } + } else { + std::unique_ptr txn; TxnErrorCode err = txn_kv_->create_txn(&txn); if (err != TxnErrorCode::TXN_OK) { code = cast_as(err); msg = fmt::format("failed to create txn, tablet_id={}", idx.tablet_id()); return; } - if (!(/* idx.has_db_id() && */ idx.has_table_id() && idx.has_index_id() && - idx.has_partition_id() && i.has_tablet_id())) { - get_tablet_idx(code, msg, txn.get(), instance_id, idx.tablet_id(), idx); - if (code != MetaServiceCode::OK) return; + for (auto& i : request->tablet_idx()) { } - auto tablet_stats = response->add_tablet_stats(); - internal_get_tablet_stats(code, msg, txn.get(), instance_id, idx, *tablet_stats, true); - if (code != MetaServiceCode::OK) { - response->clear_tablet_stats(); - break; - } -#ifdef NDEBUG - // Force data size >= 0 to reduce the losses caused by bugs - if (tablet_stats->data_size() < 0) tablet_stats->set_data_size(0); -#endif + get_batch_tablet_idx(); + internal_get_batch_tablet_stats(); } }