gavinchou commented on code in PR #41782: URL: https://github.com/apache/doris/pull/41782#discussion_r1803022583
########## cloud/src/meta-service/meta_service.cpp: ########## @@ -2188,4 +2188,93 @@ std::pair<MetaServiceCode, std::string> MetaServiceImpl::get_instance_info( return {code, std::move(msg)}; } +void MetaServiceImpl::fix_tablet_stats(::google::protobuf::RpcController* controller, + const FixTabletStatsRequest* request, + FixTabletStatsResponse* response, + ::google::protobuf::Closure* done) { + RPC_PREPROCESS(fix_tablet_stats); + instance_id = get_instance_id(resource_mgr_, request->cloud_unique_id()); + if (instance_id.empty()) { + code = MetaServiceCode::INVALID_ARGUMENT; + msg = "empty instance_id"; + LOG(INFO) << msg << ", cloud_unique_id=" << request->cloud_unique_id(); + return; + } + RPC_RATE_LIMIT(fix_tablet_stats) + + std::unique_ptr<Transaction> txn; + TxnErrorCode err = txn_kv_->create_txn(&txn); + if (err != TxnErrorCode::TXN_OK) { + code = cast_as<ErrCategory::CREATE>(err); + msg = fmt::format("failed to create txn"); + return; + } + for (const auto& i : request->table_id()) { + int64_t table_id = i; + std::string key, val; + int64_t start = 0; + int64_t end = std::numeric_limits<int64_t>::max() - 1; + auto begin_key = stats_tablet_key({instance_id, table_id, start, start, start}); + auto end_key = stats_tablet_key({instance_id, table_id, end, end, end}); + std::vector<std::pair<std::string, std::string>> stats_kvs; + + std::unique_ptr<RangeGetIterator> it; + do { + TxnErrorCode err = txn->get(begin_key, end_key, &it, true); + if (err != TxnErrorCode::TXN_OK) { + code = cast_as<ErrCategory::READ>(err); + msg = fmt::format("failed to get tablet stats, err={} table_id={}", err, table_id); + return; + } + while (it->has_next()) { + auto [k, v] = it->next(); + auto k1 = k; + k1.remove_prefix(1); + std::vector<std::tuple<std::variant<int64_t, std::string>, int, int>> out; + decode_key(&k1, &out); + // 0x01 "stats" ${instance_id} "tablet" ${table_id} + // ${index_id} ${partition_id} ${tablet_id} -> TabletStatsPB + if (out.size() == 7) { + auto tablet_id = std::get<int64_t>(std::get<0>(out[6])); + TabletStatsPB tablet_stat; + tablet_stat.ParseFromArray(v.data(), v.size()); + + GetRowsetResponse resp; + internal_get_rowset(txn.get(), start, end, instance_id, tablet_id, code, msg, + &resp); + if (code != MetaServiceCode::OK) { + return; + } + int64_t total_disk_size = 0; + for (const auto& rs_meta : resp.rowset_meta()) { + total_disk_size += rs_meta.total_disk_size(); + } + tablet_stat.set_data_size(total_disk_size); + + std::string key; + std::string val; + key = stats_tablet_key({instance_id, table_id, tablet_stat.idx().index_id(), + tablet_stat.idx().partition_id(), + tablet_stat.idx().tablet_id()}); + if (!tablet_stat.SerializeToString(&val)) { + code = MetaServiceCode::PROTOBUF_SERIALIZE_ERR; + msg = "failed to serialize tablet stat"; + return; + } + txn->put(key, val); Review Comment: there are other keys not processed correctly num_rowsets, num_segs, num_rows, data_size -- 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: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org