@@ -74,27 +74,26 @@ void FileCacheProfile::update(int64_t table_id, int64_t partition_id, OlapReader
74
74
return ;
75
75
}
76
76
std::shared_ptr<AtomicStatistics> count;
77
- bool need_register_p = false ;
78
- bool need_register_t = false ;
77
+ std::shared_ptr<FileCacheMetric> partition_metric ;
78
+ std::shared_ptr<FileCacheMetric> table_metric ;
79
79
{
80
80
std::lock_guard lock (_mtx);
81
81
if (_profile.count (table_id) < 1 || _profile[table_id].count (partition_id) < 1 ) {
82
82
_profile[table_id][partition_id] = std::make_shared<AtomicStatistics>();
83
- _partition_metrics[table_id][partition_id] =
84
- std::make_shared<FileCacheMetric>(table_id, partition_id, this );
85
- need_register_p = true ;
83
+ partition_metric = std::make_shared<FileCacheMetric>(table_id, partition_id, this );
84
+ _partition_metrics[table_id][partition_id] = partition_metric;
86
85
if (_table_metrics.count (table_id) < 1 ) {
87
- _table_metrics[table_id] = std::make_shared<FileCacheMetric>(table_id, this );
88
- need_register_t = true ;
86
+ table_metric = std::make_shared<FileCacheMetric>(table_id, this );
87
+ _table_metrics[table_id] = table_metric ;
89
88
}
90
89
}
91
90
count = _profile[table_id][partition_id];
92
91
}
93
- if (need_register_p ) [[unlikely]] {
94
- _partition_metrics[table_id][partition_id] ->register_entity ();
92
+ if (partition_metric ) [[unlikely]] {
93
+ partition_metric ->register_entity ();
95
94
}
96
- if (need_register_t ) [[unlikely]] {
97
- _table_metrics[table_id] ->register_entity ();
95
+ if (table_metric ) [[unlikely]] {
96
+ table_metric ->register_entity ();
98
97
}
99
98
count->num_io_total .fetch_add (stats->file_cache_stats .num_io_total , std::memory_order_relaxed);
100
99
count->num_io_hit_cache .fetch_add (stats->file_cache_stats .num_io_hit_cache ,
@@ -115,19 +114,25 @@ void FileCacheProfile::deregister_metric(int64_t table_id, int64_t partition_id)
115
114
if (!s_enable_profile.load (std::memory_order_acquire)) {
116
115
return ;
117
116
}
118
- _partition_metrics[table_id][partition_id]->deregister_entity ();
119
- if (_partition_metrics[table_id].size () == 1 ) {
120
- _table_metrics[table_id]->deregister_entity ();
121
- }
122
- std::lock_guard lock (_mtx);
123
- _partition_metrics[table_id].erase (partition_id);
124
- if (_partition_metrics[table_id].empty ()) {
125
- _partition_metrics.erase (table_id);
126
- _table_metrics.erase (table_id);
117
+ std::shared_ptr<FileCacheMetric> partition_metric;
118
+ std::shared_ptr<FileCacheMetric> table_metric;
119
+ {
120
+ std::lock_guard lock (_mtx);
121
+ partition_metric = _partition_metrics[table_id][partition_id];
122
+ _partition_metrics[table_id].erase (partition_id);
123
+ if (_partition_metrics[table_id].empty ()) {
124
+ _partition_metrics.erase (table_id);
125
+ table_metric = _table_metrics[table_id];
126
+ _table_metrics.erase (table_id);
127
+ }
128
+ _profile[table_id].erase (partition_id);
129
+ if (_profile[table_id].empty ()) {
130
+ _profile.erase (table_id);
131
+ }
127
132
}
128
- _profile[table_id]. erase (partition_id );
129
- if (_profile[table_id]. empty () ) {
130
- _profile. erase (table_id );
133
+ partition_metric-> deregister_entity ( );
134
+ if (table_metric ) {
135
+ table_metric-> deregister_entity ( );
131
136
}
132
137
}
133
138
0 commit comments