@@ -56,26 +56,36 @@ void RuntimeQueryStatisticsMgr::report_runtime_query_statistics() {
56
56
std::lock_guard<std::shared_mutex> write_lock (_qs_ctx_map_lock);
57
57
int64_t current_time = MonotonicMillis ();
58
58
int64_t conf_qs_timeout = config::query_statistics_reserve_timeout_ms;
59
- for (auto & [query_id, qs_ctx_ptr] : _query_statistics_ctx_map) {
60
- if (qs_ctx_ptr->_query_type == TQueryType::EXTERNAL) {
61
- continue ;
62
- }
63
- if (fe_qs_map.find (qs_ctx_ptr->_fe_addr ) == fe_qs_map.end ()) {
64
- std::map<std::string, TQueryStatistics> tmp_map;
65
- fe_qs_map[qs_ctx_ptr->_fe_addr ] = std::move (tmp_map);
66
- }
67
-
68
- TQueryStatistics ret_t_qs;
69
- qs_ctx_ptr->collect_query_statistics (&ret_t_qs);
70
- fe_qs_map.at (qs_ctx_ptr->_fe_addr )[query_id] = ret_t_qs;
71
-
59
+ for (auto iter = _query_statistics_ctx_map.begin ();
60
+ iter != _query_statistics_ctx_map.end ();) {
61
+ std::string query_id = iter->first ;
62
+ auto & qs_ctx_ptr = iter->second ;
72
63
bool is_query_finished = qs_ctx_ptr->_is_query_finished ;
73
64
bool is_timeout_after_finish = false ;
74
65
if (is_query_finished) {
75
66
is_timeout_after_finish =
76
67
(current_time - qs_ctx_ptr->_query_finish_time ) > conf_qs_timeout;
77
68
}
78
- qs_status[query_id] = std::make_pair (is_query_finished, is_timeout_after_finish);
69
+
70
+ // external query not need to report to FE, so we can remove it directly.
71
+ if (qs_ctx_ptr->_query_type == TQueryType::EXTERNAL && is_query_finished) {
72
+ iter = _query_statistics_ctx_map.erase (iter);
73
+ } else {
74
+ if (qs_ctx_ptr->_query_type != TQueryType::EXTERNAL) {
75
+ if (fe_qs_map.find (qs_ctx_ptr->_fe_addr ) == fe_qs_map.end ()) {
76
+ std::map<std::string, TQueryStatistics> tmp_map;
77
+ fe_qs_map[qs_ctx_ptr->_fe_addr ] = std::move (tmp_map);
78
+ }
79
+
80
+ TQueryStatistics ret_t_qs;
81
+ qs_ctx_ptr->collect_query_statistics (&ret_t_qs);
82
+ fe_qs_map.at (qs_ctx_ptr->_fe_addr )[query_id] = ret_t_qs;
83
+ qs_status[query_id] =
84
+ std::make_pair (is_query_finished, is_timeout_after_finish);
85
+ }
86
+
87
+ iter++;
88
+ }
79
89
}
80
90
}
81
91
@@ -86,7 +96,7 @@ void RuntimeQueryStatisticsMgr::report_runtime_query_statistics() {
86
96
// 2.1 get client
87
97
Status coord_status;
88
98
FrontendServiceConnection coord (ExecEnv::GetInstance ()->frontend_client_cache (), addr,
89
- &coord_status);
99
+ config::thrift_rpc_timeout_ms, &coord_status);
90
100
std::string add_str = PrintThriftNetworkAddress (addr);
91
101
if (!coord_status.ok ()) {
92
102
std::stringstream ss;
@@ -116,7 +126,7 @@ void RuntimeQueryStatisticsMgr::report_runtime_query_statistics() {
116
126
} catch (apache::thrift::transport::TTransportException& e) {
117
127
LOG (WARNING) << " [report_query_statistics]report workload runtime statistics to "
118
128
<< add_str << " failed, reason: " << e.what ();
119
- rpc_status = coord.reopen ();
129
+ rpc_status = coord.reopen (config::thrift_rpc_timeout_ms );
120
130
if (!rpc_status.ok ()) {
121
131
LOG (WARNING) << " [report_query_statistics]reopen thrift client failed when report "
122
132
" workload runtime statistics to"
0 commit comments