@@ -57,18 +57,55 @@ TabletHotspot::~TabletHotspot() {
5757 }
5858}
5959
60- struct MapKeyHash {
61- int64_t operator ()(const std::pair<int64_t , int64_t >& key) const {
62- return std::hash<int64_t > {}(key.first ) + std::hash<int64_t > {}(key.second );
60+ void get_return_partitions (
61+ const std::unordered_map<TabletHotspotMapKey,
62+ std::unordered_map<int64_t , TabletHotspotMapValue>, MapKeyHash>&
63+ hot_partition,
64+ const std::unordered_map<TabletHotspotMapKey,
65+ std::unordered_map<int64_t , TabletHotspotMapValue>, MapKeyHash>&
66+ last_hot_partition,
67+ std::vector<THotTableMessage>* hot_tables, int & return_partitions, int N) {
68+ for (const auto & [key, partition_to_value] : hot_partition) {
69+ THotTableMessage msg;
70+ msg.table_id = key.first ;
71+ msg.index_id = key.second ;
72+ for (const auto & [partition_id, value] : partition_to_value) {
73+ if (return_partitions > N) {
74+ return ;
75+ }
76+ auto last_value_iter = last_hot_partition.find (key);
77+ if (last_value_iter != last_hot_partition.end ()) {
78+ auto last_partition_iter = last_value_iter->second .find (partition_id);
79+ if (last_partition_iter != last_value_iter->second .end ()) {
80+ const auto & last_value = last_partition_iter->second ;
81+ if (std::abs (static_cast <int64_t >(value.qpd ) -
82+ static_cast <int64_t >(last_value.qpd )) < 5 &&
83+ std::abs (static_cast <int64_t >(value.qpw ) -
84+ static_cast <int64_t >(last_value.qpw )) < 10 &&
85+ std::abs (static_cast <int64_t >(value.last_access_time ) -
86+ static_cast <int64_t >(last_value.last_access_time )) < 60 ) {
87+ LOG (INFO) << " skip partition_id=" << partition_id << " qpd=" << value.qpd
88+ << " qpw=" << value.qpw
89+ << " last_access_time=" << value.last_access_time
90+ << " last_qpd=" << last_value.qpd
91+ << " last_qpw=" << last_value.qpw
92+ << " last_access_time=" << last_value.last_access_time ;
93+ continue ;
94+ }
95+ }
96+ }
97+ THotPartition hot_partition;
98+ hot_partition.__set_partition_id (partition_id);
99+ hot_partition.__set_query_per_day (value.qpd );
100+ hot_partition.__set_query_per_week (value.qpw );
101+ hot_partition.__set_last_access_time (value.last_access_time );
102+ msg.hot_partitions .push_back (hot_partition);
103+ return_partitions++;
104+ }
105+ msg.__isset .hot_partitions = !msg.hot_partitions .empty ();
106+ hot_tables->push_back (std::move (msg));
63107 }
64- };
65- struct TabletHotspotMapValue {
66- uint64_t qpd = 0 ; // query per day
67- uint64_t qpw = 0 ; // query per week
68- int64_t last_access_time;
69- };
70-
71- using TabletHotspotMapKey = std::pair<int64_t , int64_t >;
108+ }
72109
73110void TabletHotspot::get_top_n_hot_partition (std::vector<THotTableMessage>* hot_tables) {
74111 // map<pair<table_id, index_id>, map<partition_id, value>> for day
@@ -108,33 +145,14 @@ void TabletHotspot::get_top_n_hot_partition(std::vector<THotTableMessage>* hot_t
108145 });
109146 constexpr int N = 50 ;
110147 int return_partitions = 0 ;
111- auto get_return_partitions =
112- [=, &return_partitions](
113- const std::unordered_map<TabletHotspotMapKey,
114- std::unordered_map<int64_t , TabletHotspotMapValue>,
115- MapKeyHash>& hot_partition) {
116- for (const auto & [key, partition_to_value] : hot_partition) {
117- THotTableMessage msg;
118- msg.table_id = key.first ;
119- msg.index_id = key.second ;
120- for (const auto & [partition_id, value] : partition_to_value) {
121- if (return_partitions > N) {
122- return ;
123- }
124- THotPartition hot_partition;
125- hot_partition.__set_partition_id (partition_id);
126- hot_partition.__set_query_per_day (value.qpd );
127- hot_partition.__set_query_per_week (value.qpw );
128- hot_partition.__set_last_access_time (value.last_access_time );
129- msg.hot_partitions .push_back (hot_partition);
130- return_partitions++;
131- }
132- msg.__isset .hot_partitions = !msg.hot_partitions .empty ();
133- hot_tables->push_back (std::move (msg));
134- }
135- };
136- get_return_partitions (day_hot_partitions);
137- get_return_partitions (week_hot_partitions);
148+
149+ get_return_partitions (day_hot_partitions, _last_day_hot_partitions, hot_tables,
150+ return_partitions, N);
151+ get_return_partitions (week_hot_partitions, _last_week_hot_partitions, hot_tables,
152+ return_partitions, N);
153+
154+ _last_day_hot_partitions = std::move (day_hot_partitions);
155+ _last_week_hot_partitions = std::move (week_hot_partitions);
138156}
139157
140158void HotspotCounter::make_dot_point () {
0 commit comments