be/src/storage/olap_common.h
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | #pragma once |
19 | | |
20 | | #include <gen_cpp/Types_types.h> |
21 | | #include <netinet/in.h> |
22 | | |
23 | | #include <atomic> |
24 | | #include <charconv> |
25 | | #include <cstdint> |
26 | | #include <functional> |
27 | | #include <list> |
28 | | #include <map> |
29 | | #include <memory> |
30 | | #include <ostream> |
31 | | #include <sstream> |
32 | | #include <string> |
33 | | #include <typeinfo> |
34 | | #include <unordered_map> |
35 | | #include <unordered_set> |
36 | | #include <utility> |
37 | | |
38 | | #include "common/cast_set.h" |
39 | | #include "common/config.h" |
40 | | #include "common/exception.h" |
41 | | #include "core/extended_types.h" |
42 | | #include "io/io_common.h" |
43 | | #include "storage/field_type.h" |
44 | | #include "storage/index/inverted/common/inverted_index_stats.h" |
45 | | #include "storage/index/inverted/common/snii_query_stats.h" |
46 | | #include "storage/olap_define.h" |
47 | | #include "storage/rowset/rowset_fwd.h" |
48 | | #include "storage/rowset_id.h" |
49 | | #include "util/hash_util.hpp" |
50 | | #include "util/time.h" |
51 | | #include "util/uid_util.h" |
52 | | |
53 | | namespace doris { |
54 | | using SchemaHash = int32_t; |
55 | | |
56 | | using TabletUid = UniqueId; |
57 | | |
58 | | enum class CompactionType { |
59 | | BASE_COMPACTION = 1, |
60 | | CUMULATIVE_COMPACTION = 2, |
61 | | FULL_COMPACTION = 3, |
62 | | // Only used by scheduler to route changelog tablets to the changelog thread pool. |
63 | | CHANGELOG_COMPACTION = 4 |
64 | | }; |
65 | | |
66 | | inline constexpr CompactionType BASE_COMPACTION = CompactionType::BASE_COMPACTION; |
67 | | inline constexpr CompactionType CUMULATIVE_COMPACTION = CompactionType::CUMULATIVE_COMPACTION; |
68 | | inline constexpr CompactionType FULL_COMPACTION = CompactionType::FULL_COMPACTION; |
69 | | inline constexpr CompactionType CHANGELOG_COMPACTION = CompactionType::CHANGELOG_COMPACTION; |
70 | | |
71 | 52 | inline std::ostream& operator<<(std::ostream& os, CompactionType type) { |
72 | 52 | return os << static_cast<int>(type); |
73 | 52 | } |
74 | | |
75 | | struct CompactionScoreStats { |
76 | | int64_t max_score = 0; |
77 | | int64_t size_based_max_score = 0; |
78 | | int64_t time_series_max_score = 0; |
79 | | bool scanned = false; |
80 | | }; |
81 | | |
82 | | enum class DataDirType { |
83 | | SPILL_DISK_DIR, |
84 | | OLAP_DATA_DIR, |
85 | | DATA_CACHE_DIR, |
86 | | }; |
87 | | |
88 | | struct DataDirInfo { |
89 | | std::string path; |
90 | | size_t path_hash = 0; |
91 | | int64_t disk_capacity = 1; // actual disk capacity |
92 | | int64_t available = 0; // available space, in bytes unit |
93 | | int64_t local_used_capacity = 0; |
94 | | int64_t remote_used_capacity = 0; |
95 | | int64_t trash_used_capacity = 0; |
96 | | bool is_used = false; // whether available mark |
97 | | TStorageMedium::type storage_medium = TStorageMedium::HDD; // Storage medium type: SSD|HDD |
98 | | DataDirType data_dir_type = DataDirType::OLAP_DATA_DIR; |
99 | | std::string metric_name; |
100 | | }; |
101 | | |
102 | | // Sort DataDirInfo by available space. |
103 | | struct DataDirInfoLessAvailability { |
104 | 23 | bool operator()(const DataDirInfo& left, const DataDirInfo& right) const { |
105 | 23 | return left.available < right.available; |
106 | 23 | } |
107 | | }; |
108 | | |
109 | | struct TabletInfo { |
110 | | TabletInfo(TTabletId in_tablet_id, UniqueId in_uid) |
111 | 1.94M | : tablet_id(in_tablet_id), tablet_uid(in_uid) {} |
112 | | |
113 | 10.7M | bool operator<(const TabletInfo& right) const { |
114 | 10.7M | if (tablet_id != right.tablet_id) { |
115 | 10.7M | return tablet_id < right.tablet_id; |
116 | 10.7M | } else { |
117 | 9.89k | return tablet_uid < right.tablet_uid; |
118 | 9.89k | } |
119 | 10.7M | } |
120 | | |
121 | 69 | std::string to_string() const { |
122 | 69 | std::stringstream ss; |
123 | 69 | ss << tablet_id << "." << tablet_uid.to_string(); |
124 | 69 | return ss.str(); |
125 | 69 | } |
126 | | |
127 | | TTabletId tablet_id; |
128 | | UniqueId tablet_uid; |
129 | | }; |
130 | | |
131 | | struct TabletSize { |
132 | | TabletSize(TTabletId in_tablet_id, size_t in_tablet_size) |
133 | 0 | : tablet_id(in_tablet_id), tablet_size(in_tablet_size) {} |
134 | | |
135 | | TTabletId tablet_id; |
136 | | size_t tablet_size; |
137 | | }; |
138 | | |
139 | | // FieldType moved to storage/field_type.h (included above) so that |
140 | | // data-type headers can name storage cell types without pulling in the |
141 | | // whole of olap_common.h. |
142 | | |
143 | | // Define all aggregation methods supported by TabletColumn |
144 | | // Note that in practice, not all types can use all the following aggregation methods |
145 | | // For example, it is meaningless to use SUM for the string type (but it will not cause the program to crash) |
146 | | // The implementation of the TabletColumn class does not perform such checks, and should be constrained when creating the table |
147 | | enum class FieldAggregationMethod { |
148 | | OLAP_FIELD_AGGREGATION_NONE = 0, |
149 | | OLAP_FIELD_AGGREGATION_SUM = 1, |
150 | | OLAP_FIELD_AGGREGATION_MIN = 2, |
151 | | OLAP_FIELD_AGGREGATION_MAX = 3, |
152 | | OLAP_FIELD_AGGREGATION_REPLACE = 4, |
153 | | OLAP_FIELD_AGGREGATION_HLL_UNION = 5, |
154 | | OLAP_FIELD_AGGREGATION_UNKNOWN = 6, |
155 | | OLAP_FIELD_AGGREGATION_BITMAP_UNION = 7, |
156 | | // Replace if and only if added value is not null |
157 | | OLAP_FIELD_AGGREGATION_REPLACE_IF_NOT_NULL = 8, |
158 | | OLAP_FIELD_AGGREGATION_QUANTILE_UNION = 9, |
159 | | OLAP_FIELD_AGGREGATION_GENERIC = 10 |
160 | | }; |
161 | | |
162 | | enum class PushType { |
163 | | PUSH_NORMAL = 1, // for broker/hadoop load, not used any more |
164 | | PUSH_FOR_DELETE = 2, // for delete |
165 | | PUSH_FOR_LOAD_DELETE = 3, // not used any more |
166 | | PUSH_NORMAL_V2 = 4, // for spark load |
167 | | }; |
168 | | |
169 | | // <start_version_id, end_version_id>, such as <100, 110> |
170 | | //using Version = std::pair<TupleVersion, TupleVersion>; |
171 | | |
172 | | struct Version { |
173 | | int64_t first; |
174 | | int64_t second; |
175 | | |
176 | 85.9M | Version(int64_t first_, int64_t second_) : first(first_), second(second_) {} |
177 | 9.74M | Version() : first(0), second(0) {} |
178 | | |
179 | 7.44k | static Version mock() { |
180 | | // Every time SchemaChange is used for external rowing, some temporary versions (such as 999, 1000, 1001) will be written, in order to avoid Cache conflicts, temporary |
181 | | // The version number takes a BIG NUMBER plus the version number of the current SchemaChange |
182 | 7.44k | return Version(1 << 28, 1 << 29); |
183 | 7.44k | } |
184 | | |
185 | | friend std::ostream& operator<<(std::ostream& os, const Version& version); |
186 | | |
187 | 1.07k | bool operator!=(const Version& rhs) const { return first != rhs.first || second != rhs.second; } |
188 | | |
189 | 7.91M | bool operator==(const Version& rhs) const { return first == rhs.first && second == rhs.second; } |
190 | | |
191 | 177k | bool contains(const Version& other) const { |
192 | 177k | return first <= other.first && second >= other.second; |
193 | 177k | } |
194 | | |
195 | 1.42M | std::string to_string() const { return fmt::format("[{}-{}]", first, second); } |
196 | | }; |
197 | | |
198 | | struct TsoRange : public Version { |
199 | 6.74M | TsoRange() : Version(-1, -1) {} |
200 | 6.57M | TsoRange(int64_t start_tso, int64_t end_tso) : Version(start_tso, end_tso) {} |
201 | | |
202 | 1.19M | int64_t start_tso() const { return first; } |
203 | 1.19M | int64_t end_tso() const { return second; } |
204 | | |
205 | 0 | bool contains(const TsoRange& other) const { return Version::contains(other); } |
206 | | }; |
207 | | |
208 | | using Versions = std::vector<Version>; |
209 | | |
210 | 11.5k | inline std::ostream& operator<<(std::ostream& os, const Version& version) { |
211 | 11.5k | return os << version.to_string(); |
212 | 11.5k | } |
213 | | |
214 | 0 | inline std::ostream& operator<<(std::ostream& os, const Versions& versions) { |
215 | 0 | for (auto& version : versions) { |
216 | 0 | os << version; |
217 | 0 | } |
218 | 0 | return os; |
219 | 0 | } |
220 | | |
221 | | // used for hash-struct of hash_map<Version, Rowset*>. |
222 | | struct HashOfVersion { |
223 | 9.19M | size_t operator()(const Version& version) const { |
224 | 9.19M | size_t seed = 0; |
225 | 9.19M | seed = HashUtil::hash64(&version.first, sizeof(version.first), seed); |
226 | 9.19M | seed = HashUtil::hash64(&version.second, sizeof(version.second), seed); |
227 | 9.19M | return seed; |
228 | 9.19M | } |
229 | | }; |
230 | | |
231 | | // It is used to represent Graph vertex. |
232 | | struct Vertex { |
233 | | int64_t value = 0; |
234 | | std::list<int64_t> edges; |
235 | | |
236 | 1.32M | Vertex(int64_t v) : value(v) {} |
237 | | }; |
238 | | |
239 | | // ReaderStatistics used to collect statistics when scan data from storage |
240 | | struct OlapReaderStatistics { |
241 | | int64_t io_ns = 0; |
242 | | int64_t compressed_bytes_read = 0; |
243 | | |
244 | | int64_t decompress_ns = 0; |
245 | | int64_t uncompressed_bytes_read = 0; |
246 | | |
247 | | // total read bytes in memory |
248 | | int64_t bytes_read = 0; |
249 | | |
250 | | int64_t block_fetch_ns = 0; // time of rowset reader's `next_batch()` call |
251 | | int64_t block_load_ns = 0; |
252 | | int64_t blocks_load = 0; |
253 | | // Not used any more, will be removed after non-vectorized code is removed |
254 | | int64_t block_seek_num = 0; |
255 | | // Not used any more, will be removed after non-vectorized code is removed |
256 | | int64_t block_seek_ns = 0; |
257 | | |
258 | | // block_load_ns |
259 | | // block_init_ns |
260 | | // block_init_seek_ns |
261 | | // generate_row_ranges_ns |
262 | | // predicate_column_read_ns |
263 | | // predicate_column_read_seek_ns |
264 | | // lazy_read_ns |
265 | | // block_lazy_read_seek_ns |
266 | | int64_t block_init_ns = 0; |
267 | | int64_t block_init_seek_num = 0; |
268 | | int64_t block_init_seek_ns = 0; |
269 | | int64_t predicate_column_read_ns = 0; |
270 | | int64_t non_predicate_read_ns = 0; |
271 | | int64_t predicate_column_read_seek_num = 0; |
272 | | int64_t predicate_column_read_seek_ns = 0; |
273 | | int64_t lazy_read_ns = 0; |
274 | | int64_t block_lazy_read_seek_num = 0; |
275 | | int64_t block_lazy_read_seek_ns = 0; |
276 | | int64_t lazy_read_pruned_ns = 0; |
277 | | |
278 | | int64_t raw_rows_read = 0; |
279 | | |
280 | | int64_t rows_vec_cond_filtered = 0; |
281 | | int64_t rows_short_circuit_cond_filtered = 0; |
282 | | int64_t rows_expr_cond_filtered = 0; |
283 | | int64_t vec_cond_input_rows = 0; |
284 | | int64_t short_circuit_cond_input_rows = 0; |
285 | | int64_t expr_cond_input_rows = 0; |
286 | | int64_t rows_vec_del_cond_filtered = 0; |
287 | | int64_t vec_cond_ns = 0; |
288 | | int64_t short_cond_ns = 0; |
289 | | int64_t expr_filter_ns = 0; |
290 | | int64_t output_col_ns = 0; |
291 | | int64_t rows_key_range_filtered = 0; |
292 | | int64_t rows_stats_filtered = 0; |
293 | | int64_t rows_stats_rp_filtered = 0; |
294 | | int64_t expr_zonemap_filtered_segments = 0; |
295 | | int64_t expr_zonemap_filtered_pages = 0; |
296 | | int64_t expr_zonemap_unusable_evals = 0; |
297 | | int64_t in_zonemap_point_check_count = 0; |
298 | | int64_t in_zonemap_range_only_count = 0; |
299 | | int64_t rows_bf_filtered = 0; |
300 | | int64_t segment_dict_filtered = 0; |
301 | | // Including the number of rows filtered out according to the Delete information in the Tablet, |
302 | | // and the number of rows filtered for marked deleted rows under the unique key model. |
303 | | // This metric is mainly used to record the number of rows filtered by the delete condition in Segment V1, |
304 | | // and it is also used to record the replaced rows in the Unique key model in the "Reader" class. |
305 | | // In segmentv2, if you want to get all filtered rows, you need the sum of "rows_del_filtered" and "rows_conditions_filtered". |
306 | | int64_t rows_del_filtered = 0; |
307 | | int64_t rows_del_by_bitmap = 0; |
308 | | // the number of rows filtered by various column indexes. |
309 | | int64_t rows_conditions_filtered = 0; |
310 | | int64_t generate_row_ranges_by_keys_ns = 0; |
311 | | int64_t generate_row_ranges_by_column_conditions_ns = 0; |
312 | | int64_t generate_row_ranges_by_bf_ns = 0; |
313 | | int64_t generate_row_ranges_by_zonemap_ns = 0; |
314 | | int64_t generate_row_ranges_by_dict_ns = 0; |
315 | | |
316 | | int64_t index_load_ns = 0; |
317 | | |
318 | | int64_t total_pages_num = 0; |
319 | | int64_t cached_pages_num = 0; |
320 | | |
321 | | int64_t rows_inverted_index_filtered = 0; |
322 | | int64_t inverted_index_filter_timer = 0; |
323 | | int64_t inverted_index_query_timer = 0; |
324 | | int64_t inverted_index_query_cache_hit = 0; |
325 | | int64_t inverted_index_query_cache_miss = 0; |
326 | | int64_t inverted_index_query_cache_lookup = 0; |
327 | | int64_t inverted_index_query_cache_insert = 0; |
328 | | int64_t inverted_index_query_null_bitmap_timer = 0; |
329 | | int64_t inverted_index_query_bitmap_copy_timer = 0; |
330 | | int64_t inverted_index_searcher_open_timer = 0; |
331 | | int64_t inverted_index_searcher_search_timer = 0; |
332 | | int64_t inverted_index_searcher_search_init_timer = 0; |
333 | | int64_t inverted_index_searcher_search_exec_timer = 0; |
334 | | int64_t inverted_index_searcher_cache_hit = 0; |
335 | | int64_t inverted_index_searcher_cache_miss = 0; |
336 | | int64_t inverted_index_downgrade_count = 0; |
337 | | // Pushed-down conjuncts skipped (never index-evaluated) because the row |
338 | | // bitmap was already empty when their turn came. |
339 | | int64_t inverted_index_conjuncts_short_circuited = 0; |
340 | | // Rows pruned by the approximate (gram) index: rows removed when the candidate bitmap is |
341 | | // intersected with _row_bitmap. |
342 | | int64_t rows_gram_index_filtered = 0; |
343 | | // Candidate rows produced by the approximate (gram) index: rows that still need expression |
344 | | // re-verification after the intersection. |
345 | | int64_t gram_index_candidate_rows = 0; |
346 | | // Query nodes the gram index's cost gate widened to the whole segment rather than read. A |
347 | | // non-zero count is why the two numbers above can show an index that eliminated nothing: it |
348 | | // was not consulted for those nodes, by a cost decision rather than because no gram matched. |
349 | | int64_t gram_index_gate_gave_up = 0; |
350 | | int64_t inverted_index_analyzer_timer = 0; |
351 | | int64_t inverted_index_lookup_timer = 0; |
352 | | // See snii_query_stats.h: one field here instead of one per SNII counter. |
353 | | snii::SniiQueryStats snii_stats; |
354 | | InvertedIndexStatistics inverted_index_stats; |
355 | | |
356 | | int64_t ann_index_load_ns = 0; |
357 | | int64_t ann_topn_search_ns = 0; |
358 | | int64_t ann_index_topn_search_cnt = 0; |
359 | | int64_t ann_ivf_on_disk_load_ns = 0; |
360 | | int64_t ann_ivf_on_disk_cache_hit_cnt = 0; |
361 | | int64_t ann_ivf_on_disk_cache_miss_cnt = 0; |
362 | | int64_t ann_index_cache_hits = 0; |
363 | | |
364 | | // Detailed timing for ANN operations |
365 | | int64_t ann_index_topn_engine_search_ns = 0; // time spent in engine for range search |
366 | | int64_t ann_index_topn_result_process_ns = 0; // time spent processing TopN results |
367 | | int64_t ann_index_topn_engine_convert_ns = 0; // time spent on FAISS-side conversions (TopN) |
368 | | int64_t ann_index_topn_engine_prepare_ns = |
369 | | 0; // time spent preparing before engine search (TopN) |
370 | | int64_t rows_ann_index_topn_filtered = 0; |
371 | | |
372 | | int64_t ann_index_range_search_ns = 0; |
373 | | int64_t ann_index_range_search_cnt = 0; |
374 | | // Detailed timing for ANN Range search |
375 | | int64_t ann_range_engine_search_ns = 0; // time spent in engine for range search |
376 | | int64_t ann_range_pre_process_ns = 0; // time spent preparing before engine search |
377 | | |
378 | | int64_t ann_range_result_convert_ns = 0; // time spent processing range results |
379 | | int64_t ann_range_engine_convert_ns = 0; // time spent on FAISS-side conversions (Range) |
380 | | int64_t rows_ann_index_range_filtered = 0; |
381 | | int64_t ann_index_range_cache_hits = 0; |
382 | | int64_t ann_fall_back_brute_force_cnt = 0; |
383 | | int64_t ann_topn_fallback_by_small_candidate_cnt = 0; |
384 | | int64_t ann_topn_fallback_small_candidate_rows = 0; |
385 | | int64_t ann_range_fallback_by_small_candidate_cnt = 0; |
386 | | int64_t ann_range_fallback_small_candidate_rows = 0; |
387 | | |
388 | | int64_t output_index_result_column_timer = 0; |
389 | | // number of segment filtered by column stat when creating seg iterator |
390 | | int64_t filtered_segment_number = 0; |
391 | | // number of condition cache lookups, including misses |
392 | | int64_t condition_cache_lookup_count = 0; |
393 | | // number of segment with condition cache hit |
394 | | int64_t condition_cache_hit_seg_nums = 0; |
395 | | // number of rows filtered by condition cache hit |
396 | | int64_t condition_cache_filtered_rows = 0; |
397 | | // total number of segment |
398 | | int64_t total_segment_number = 0; |
399 | | |
400 | | io::FileCacheStatistics file_cache_stats; |
401 | | int64_t load_segments_timer = 0; |
402 | | |
403 | | int64_t collect_iterator_merge_next_timer = 0; |
404 | | int64_t collect_iterator_normal_next_timer = 0; |
405 | | int64_t delete_bitmap_get_agg_ns = 0; |
406 | | |
407 | | int64_t tablet_reader_init_timer_ns = 0; |
408 | | int64_t tablet_reader_capture_rs_readers_timer_ns = 0; |
409 | | int64_t tablet_reader_init_keys_param_timer_ns = 0; |
410 | | int64_t tablet_reader_init_orderby_keys_param_timer_ns = 0; |
411 | | int64_t tablet_reader_init_conditions_param_timer_ns = 0; |
412 | | int64_t tablet_reader_init_delete_condition_param_timer_ns = 0; |
413 | | int64_t block_reader_vcollect_iter_init_timer_ns = 0; |
414 | | int64_t block_reader_rs_readers_init_timer_ns = 0; |
415 | | int64_t block_reader_build_heap_init_timer_ns = 0; |
416 | | |
417 | | int64_t rowset_reader_get_segment_iterators_timer_ns = 0; |
418 | | int64_t rowset_reader_create_iterators_timer_ns = 0; |
419 | | int64_t rowset_reader_init_iterators_timer_ns = 0; |
420 | | int64_t rowset_reader_load_segments_timer_ns = 0; |
421 | | |
422 | | int64_t segment_iterator_init_timer_ns = 0; |
423 | | int64_t segment_iterator_init_column_iterators_timer_ns = 0; |
424 | | int64_t segment_iterator_init_index_iterators_timer_ns = 0; |
425 | | int64_t segment_iterator_init_segment_prefetchers_timer_ns = 0; |
426 | | |
427 | | int64_t segment_create_column_readers_timer_ns = 0; |
428 | | int64_t segment_load_index_timer_ns = 0; |
429 | | |
430 | | int64_t adaptive_batch_size_predict_min_rows = INT64_MAX; |
431 | | int64_t adaptive_batch_size_predict_max_rows = 0; |
432 | | |
433 | | int64_t variant_scan_sparse_column_timer_ns = 0; |
434 | | int64_t variant_scan_sparse_column_bytes = 0; |
435 | | int64_t variant_fill_path_from_sparse_column_timer_ns = 0; |
436 | | int64_t variant_subtree_default_iter_count = 0; |
437 | | int64_t variant_subtree_leaf_iter_count = 0; |
438 | | int64_t variant_subtree_hierarchical_iter_count = 0; |
439 | | int64_t variant_subtree_sparse_iter_count = 0; |
440 | | int64_t variant_doc_value_column_iter_count = 0; |
441 | | }; |
442 | | |
443 | | using ColumnId = uint32_t; |
444 | | // Column unique id set |
445 | | using UniqueIdSet = std::set<uint32_t>; |
446 | | // Column unique Id -> column id map |
447 | | using UniqueIdToColumnIdMap = std::map<ColumnId, ColumnId>; |
448 | | |
449 | | // RowsetId moved to storage/rowset_id.h (included above): core/column/column.h |
450 | | // needs the complete type, and this way it gets it without the rest of |
451 | | // olap_common.h. |
452 | | |
453 | | using RowsetIdUnorderedSet = std::unordered_set<RowsetId>; |
454 | | |
455 | | // Extract rowset id from filename, return uninitialized rowset id if filename is invalid |
456 | 82.2k | inline RowsetId extract_rowset_id(std::string_view filename) { |
457 | 82.2k | RowsetId rowset_id; |
458 | 82.2k | if (filename.ends_with(".dat")) { |
459 | | // filename format: {rowset_id}_{segment_num}.dat |
460 | 76.3k | auto end = filename.find('_'); |
461 | 76.3k | if (end == std::string::npos) { |
462 | 0 | return rowset_id; |
463 | 0 | } |
464 | 76.3k | rowset_id.init(filename.substr(0, end)); |
465 | 76.3k | return rowset_id; |
466 | 76.3k | } |
467 | 5.91k | if (filename.ends_with(".idx")) { |
468 | | // filename format: {rowset_id}_{segment_num}_{index_id}.idx |
469 | 5.73k | auto end = filename.find('_'); |
470 | 5.73k | if (end == std::string::npos) { |
471 | 0 | return rowset_id; |
472 | 0 | } |
473 | 5.73k | rowset_id.init(filename.substr(0, end)); |
474 | 5.73k | return rowset_id; |
475 | 5.73k | } |
476 | 184 | return rowset_id; |
477 | 5.91k | } |
478 | | |
479 | | class DeleteBitmap; |
480 | | // merge on write context |
481 | | struct MowContext { |
482 | | MowContext(int64_t version, int64_t txnid, std::shared_ptr<RowsetIdUnorderedSet> ids, |
483 | | std::vector<RowsetSharedPtr> rowset_ptrs, std::shared_ptr<DeleteBitmap> db) |
484 | 61.2k | : max_version(version), |
485 | 61.2k | txn_id(txnid), |
486 | 61.2k | rowset_ids(std::move(ids)), |
487 | 61.2k | rowset_ptrs(std::move(rowset_ptrs)), |
488 | 61.2k | delete_bitmap(std::move(db)) {} |
489 | | int64_t max_version; |
490 | | int64_t txn_id; |
491 | | std::shared_ptr<RowsetIdUnorderedSet> rowset_ids; |
492 | | std::vector<RowsetSharedPtr> rowset_ptrs; |
493 | | std::shared_ptr<DeleteBitmap> delete_bitmap; |
494 | | }; |
495 | | |
496 | | // used for controll compaction |
497 | | struct VersionWithTime { |
498 | | std::atomic<int64_t> version; |
499 | | int64_t update_ts; |
500 | | |
501 | 40.6k | VersionWithTime() : version(0), update_ts(MonotonicMillis()) {} |
502 | | |
503 | 37.9k | void update_version_monoto(int64_t new_version) { |
504 | 37.9k | int64_t cur_version = version.load(std::memory_order_relaxed); |
505 | 37.9k | while (cur_version < new_version) { |
506 | 37.9k | if (version.compare_exchange_strong(cur_version, new_version, std::memory_order_relaxed, |
507 | 37.9k | std::memory_order_relaxed)) { |
508 | 37.9k | update_ts = MonotonicMillis(); |
509 | 37.9k | break; |
510 | 37.9k | } |
511 | 37.9k | } |
512 | 37.9k | } |
513 | | }; |
514 | | } // namespace doris |