diff --git a/src/sql/engine/px/ob_px_rpc_processor.cpp b/src/sql/engine/px/ob_px_rpc_processor.cpp index 48b674247b..5edd159651 100644 --- a/src/sql/engine/px/ob_px_rpc_processor.cpp +++ b/src/sql/engine/px/ob_px_rpc_processor.cpp @@ -634,16 +634,9 @@ int ObPxTenantTargetMonitorP::process() LOG_INFO("reset statistics succeed", K(tenant_id), K(leader_version)); } } else { - const hash::ObHashMap *global_target_usage = NULL; - if (OB_FAIL(OB_PX_TARGET_MGR.get_global_target_usage(tenant_id, global_target_usage))) { + ObPxGlobalResGather gather(result_); + if (OB_FAIL(OB_PX_TARGET_MGR.gather_global_target_usage(tenant_id, gather))) { LOG_WARN("get global thread count failed", K(ret), K(tenant_id)); - } else { - for (hash::ObHashMap::const_iterator it = global_target_usage->begin(); - OB_SUCC(ret) && it != global_target_usage->end(); ++it) { - if (OB_FAIL(result_.push_peer_target_usage(it->first, it->second.get_peer_used()))) { - COMMON_LOG(WARN, "push_back peer_used failed", K(ret)); - } - } } } } diff --git a/src/sql/engine/px/ob_px_target_mgr.cpp b/src/sql/engine/px/ob_px_target_mgr.cpp index 9b4ad5a9d0..afaa5b39b9 100644 --- a/src/sql/engine/px/ob_px_target_mgr.cpp +++ b/src/sql/engine/px/ob_px_target_mgr.cpp @@ -320,15 +320,18 @@ int ObPxTargetMgr::rollback_local_report_target_used(uint64_t tenant_id, const O return ret; } -int ObPxTargetMgr::get_global_target_usage(uint64_t tenant_id, const hash::ObHashMap *&global_target_usage) +int ObPxTargetMgr::gather_global_target_usage(uint64_t tenant_id, ObPxGlobalResGather &gather) { int ret = OB_SUCCESS; + const hash::ObHashMap *global_target_usage = NULL; GET_TARGET_MONITOR(tenant_id, { if (OB_FAIL(target_monitor->get_global_target_usage(global_target_usage))) { LOG_WARN("get global target usage failed", K(ret), K(tenant_id)); } else if (OB_ISNULL(global_target_usage)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("global_target_usage is null", K(ret), K(tenant_id)); + } else if (OB_FAIL(global_target_usage->foreach_refactored(gather))) { + LOG_WARN("gather global px resource usage failed", K(ret)); } }); return ret; diff --git a/src/sql/engine/px/ob_px_target_mgr.h b/src/sql/engine/px/ob_px_target_mgr.h index 2f6e964886..1a532f44b1 100644 --- a/src/sql/engine/px/ob_px_target_mgr.h +++ b/src/sql/engine/px/ob_px_target_mgr.h @@ -71,6 +71,22 @@ public: typedef common::ObLinkHashMap ObPxInfoMap; +class ObPxGlobalResGather +{ +public: + ObPxGlobalResGather(ObPxRpcFetchStatResponse &result) : result_(result) {} + ~ObPxGlobalResGather() {} + int operator()(hash::HashMapPair &entry) + { + int ret = common::OB_SUCCESS; + if (OB_FAIL(result_.push_peer_target_usage(entry.first, entry.second.get_peer_used()))) { + COMMON_LOG(WARN, "push_back peer_used failed", K(ret)); + } + return ret; + } + ObPxRpcFetchStatResponse &result_; +}; + class ObPxTargetMgr : public share::ObThreadPool { @@ -104,7 +120,7 @@ public: int get_version(uint64_t tenant_id, uint64_t &version); int update_peer_target_used(uint64_t tenant_id, const ObAddr &server, int64_t peer_used); int rollback_local_report_target_used(uint64_t tenant_id, const ObAddr &server, int64_t local_report); - int get_global_target_usage(uint64_t tenant_id, const hash::ObHashMap *&global_target_usage); + int gather_global_target_usage(uint64_t tenant_id, ObPxGlobalResGather &gather); int reset_leader_statistics(uint64_t tenant_id); // for px_admission