/root/doris/be/src/olap/tablet_meta.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | #include "olap/tablet_meta.h" |
19 | | |
20 | | #include <gen_cpp/Descriptors_types.h> |
21 | | #include <gen_cpp/Types_types.h> |
22 | | #include <gen_cpp/olap_common.pb.h> |
23 | | #include <gen_cpp/olap_file.pb.h> |
24 | | #include <gen_cpp/segment_v2.pb.h> |
25 | | #include <gen_cpp/types.pb.h> |
26 | | #include <json2pb/pb_to_json.h> |
27 | | #include <time.h> |
28 | | |
29 | | #include <cstdint> |
30 | | #include <memory> |
31 | | #include <random> |
32 | | #include <ranges> |
33 | | #include <set> |
34 | | #include <utility> |
35 | | |
36 | | #include "cloud/cloud_meta_mgr.h" |
37 | | #include "cloud/cloud_storage_engine.h" |
38 | | #include "cloud/config.h" |
39 | | #include "common/config.h" |
40 | | #include "gutil/integral_types.h" |
41 | | #include "io/fs/file_writer.h" |
42 | | #include "io/fs/local_file_system.h" |
43 | | #include "olap/data_dir.h" |
44 | | #include "olap/file_header.h" |
45 | | #include "olap/olap_common.h" |
46 | | #include "olap/olap_define.h" |
47 | | #include "olap/rowset/rowset.h" |
48 | | #include "olap/rowset/rowset_meta_manager.h" |
49 | | #include "olap/tablet_fwd.h" |
50 | | #include "olap/tablet_meta_manager.h" |
51 | | #include "olap/tablet_schema_cache.h" |
52 | | #include "olap/utils.h" |
53 | | #include "util/debug_points.h" |
54 | | #include "util/mem_info.h" |
55 | | #include "util/parse_util.h" |
56 | | #include "util/string_util.h" |
57 | | #include "util/time.h" |
58 | | #include "util/uid_util.h" |
59 | | |
60 | | using std::string; |
61 | | using std::unordered_map; |
62 | | using std::vector; |
63 | | |
64 | | namespace doris { |
65 | | #include "common/compile_check_begin.h" |
66 | | using namespace ErrorCode; |
67 | | |
68 | | TabletMetaSharedPtr TabletMeta::create( |
69 | | const TCreateTabletReq& request, const TabletUid& tablet_uid, uint64_t shard_id, |
70 | | uint32_t next_unique_id, |
71 | 300 | const unordered_map<uint32_t, uint32_t>& col_ordinal_to_unique_id) { |
72 | 300 | std::optional<TBinlogConfig> binlog_config; |
73 | 300 | if (request.__isset.binlog_config) { Branch (73:9): [True: 0, False: 300]
|
74 | 0 | binlog_config = request.binlog_config; |
75 | 0 | } |
76 | 300 | TInvertedIndexFileStorageFormat::type inverted_index_file_storage_format = |
77 | 300 | request.inverted_index_file_storage_format; |
78 | | |
79 | | // We will discard this format. Don't make any further changes here. |
80 | 300 | if (request.__isset.inverted_index_storage_format) { Branch (80:9): [True: 300, False: 0]
|
81 | 300 | switch (request.inverted_index_storage_format) { |
82 | 0 | case TInvertedIndexStorageFormat::V1: Branch (82:9): [True: 0, False: 300]
|
83 | 0 | inverted_index_file_storage_format = TInvertedIndexFileStorageFormat::V1; |
84 | 0 | break; |
85 | 0 | case TInvertedIndexStorageFormat::V2: Branch (85:9): [True: 0, False: 300]
|
86 | 0 | inverted_index_file_storage_format = TInvertedIndexFileStorageFormat::V2; |
87 | 0 | break; |
88 | 300 | default: Branch (88:9): [True: 300, False: 0]
|
89 | 300 | break; |
90 | 300 | } |
91 | 300 | } |
92 | 300 | return std::make_shared<TabletMeta>( |
93 | 300 | request.table_id, request.partition_id, request.tablet_id, request.replica_id, |
94 | 300 | request.tablet_schema.schema_hash, shard_id, request.tablet_schema, next_unique_id, |
95 | 300 | col_ordinal_to_unique_id, tablet_uid, |
96 | 300 | request.__isset.tablet_type ? request.tablet_type : TTabletType::TABLET_TYPE_DISK, Branch (96:13): [True: 0, False: 300]
|
97 | 300 | request.compression_type, request.storage_policy_id, |
98 | 300 | request.__isset.enable_unique_key_merge_on_write Branch (98:13): [True: 300, False: 0]
|
99 | 300 | ? request.enable_unique_key_merge_on_write |
100 | 300 | : false, |
101 | 300 | std::move(binlog_config), request.compaction_policy, |
102 | 300 | request.time_series_compaction_goal_size_mbytes, |
103 | 300 | request.time_series_compaction_file_count_threshold, |
104 | 300 | request.time_series_compaction_time_threshold_seconds, |
105 | 300 | request.time_series_compaction_empty_rowsets_threshold, |
106 | 300 | request.time_series_compaction_level_threshold, inverted_index_file_storage_format); |
107 | 300 | } |
108 | | |
109 | 1.06k | TabletMeta::~TabletMeta() { |
110 | 1.06k | if (_handle) { Branch (110:9): [True: 964, False: 103]
|
111 | 964 | TabletSchemaCache::instance()->release(_handle); |
112 | 964 | } |
113 | 1.06k | } |
114 | | |
115 | | TabletMeta::TabletMeta() |
116 | | : _tablet_uid(0, 0), |
117 | | _schema(new TabletSchema), |
118 | 548 | _delete_bitmap(new DeleteBitmap(_tablet_id)) {} |
119 | | |
120 | | TabletMeta::TabletMeta(int64_t table_id, int64_t partition_id, int64_t tablet_id, |
121 | | int64_t replica_id, int32_t schema_hash, int32_t shard_id, |
122 | | const TTabletSchema& tablet_schema, uint32_t next_unique_id, |
123 | | const std::unordered_map<uint32_t, uint32_t>& col_ordinal_to_unique_id, |
124 | | TabletUid tablet_uid, TTabletType::type tabletType, |
125 | | TCompressionType::type compression_type, int64_t storage_policy_id, |
126 | | bool enable_unique_key_merge_on_write, |
127 | | std::optional<TBinlogConfig> binlog_config, std::string compaction_policy, |
128 | | int64_t time_series_compaction_goal_size_mbytes, |
129 | | int64_t time_series_compaction_file_count_threshold, |
130 | | int64_t time_series_compaction_time_threshold_seconds, |
131 | | int64_t time_series_compaction_empty_rowsets_threshold, |
132 | | int64_t time_series_compaction_level_threshold, |
133 | | TInvertedIndexFileStorageFormat::type inverted_index_file_storage_format) |
134 | | : _tablet_uid(0, 0), |
135 | | _schema(new TabletSchema), |
136 | 471 | _delete_bitmap(new DeleteBitmap(tablet_id)) { |
137 | 471 | TabletMetaPB tablet_meta_pb; |
138 | 471 | tablet_meta_pb.set_table_id(table_id); |
139 | 471 | tablet_meta_pb.set_partition_id(partition_id); |
140 | 471 | tablet_meta_pb.set_tablet_id(tablet_id); |
141 | 471 | tablet_meta_pb.set_replica_id(replica_id); |
142 | 471 | tablet_meta_pb.set_schema_hash(schema_hash); |
143 | 471 | tablet_meta_pb.set_shard_id(shard_id); |
144 | | // Persist the creation time, but it is not used |
145 | 471 | tablet_meta_pb.set_creation_time(time(nullptr)); |
146 | 471 | tablet_meta_pb.set_cumulative_layer_point(-1); |
147 | 471 | tablet_meta_pb.set_tablet_state(PB_RUNNING); |
148 | 471 | *(tablet_meta_pb.mutable_tablet_uid()) = tablet_uid.to_proto(); |
149 | 471 | tablet_meta_pb.set_tablet_type(tabletType == TTabletType::TABLET_TYPE_DISK Branch (149:36): [True: 471, False: 0]
|
150 | 471 | ? TabletTypePB::TABLET_TYPE_DISK |
151 | 471 | : TabletTypePB::TABLET_TYPE_MEMORY); |
152 | 471 | tablet_meta_pb.set_enable_unique_key_merge_on_write(enable_unique_key_merge_on_write); |
153 | 471 | tablet_meta_pb.set_storage_policy_id(storage_policy_id); |
154 | 471 | tablet_meta_pb.set_compaction_policy(compaction_policy); |
155 | 471 | tablet_meta_pb.set_time_series_compaction_goal_size_mbytes( |
156 | 471 | time_series_compaction_goal_size_mbytes); |
157 | 471 | tablet_meta_pb.set_time_series_compaction_file_count_threshold( |
158 | 471 | time_series_compaction_file_count_threshold); |
159 | 471 | tablet_meta_pb.set_time_series_compaction_time_threshold_seconds( |
160 | 471 | time_series_compaction_time_threshold_seconds); |
161 | 471 | tablet_meta_pb.set_time_series_compaction_empty_rowsets_threshold( |
162 | 471 | time_series_compaction_empty_rowsets_threshold); |
163 | 471 | tablet_meta_pb.set_time_series_compaction_level_threshold( |
164 | 471 | time_series_compaction_level_threshold); |
165 | 471 | TabletSchemaPB* schema = tablet_meta_pb.mutable_schema(); |
166 | 471 | schema->set_num_short_key_columns(tablet_schema.short_key_column_count); |
167 | 471 | schema->set_num_rows_per_row_block(config::default_num_rows_per_column_file_block); |
168 | 471 | schema->set_sequence_col_idx(tablet_schema.sequence_col_idx); |
169 | 471 | switch (tablet_schema.keys_type) { |
170 | 40 | case TKeysType::DUP_KEYS: Branch (170:5): [True: 40, False: 431]
|
171 | 40 | schema->set_keys_type(KeysType::DUP_KEYS); |
172 | 40 | break; |
173 | 301 | case TKeysType::UNIQUE_KEYS: Branch (173:5): [True: 301, False: 170]
|
174 | 301 | schema->set_keys_type(KeysType::UNIQUE_KEYS); |
175 | 301 | break; |
176 | 64 | case TKeysType::AGG_KEYS: Branch (176:5): [True: 64, False: 407]
|
177 | 64 | schema->set_keys_type(KeysType::AGG_KEYS); |
178 | 64 | break; |
179 | 66 | default: Branch (179:5): [True: 66, False: 405]
|
180 | 66 | LOG(WARNING) << "unknown tablet keys type"; |
181 | 66 | break; |
182 | 471 | } |
183 | | // compress_kind used to compress segment files |
184 | 471 | schema->set_compress_kind(COMPRESS_LZ4); |
185 | | |
186 | | // compression_type used to compress segment page |
187 | 471 | switch (compression_type) { |
188 | 0 | case TCompressionType::NO_COMPRESSION: Branch (188:5): [True: 0, False: 471]
|
189 | 0 | schema->set_compression_type(segment_v2::NO_COMPRESSION); |
190 | 0 | break; |
191 | 0 | case TCompressionType::SNAPPY: Branch (191:5): [True: 0, False: 471]
|
192 | 0 | schema->set_compression_type(segment_v2::SNAPPY); |
193 | 0 | break; |
194 | 0 | case TCompressionType::LZ4: Branch (194:5): [True: 0, False: 471]
|
195 | 0 | schema->set_compression_type(segment_v2::LZ4); |
196 | 0 | break; |
197 | 471 | case TCompressionType::LZ4F: Branch (197:5): [True: 471, False: 0]
|
198 | 471 | schema->set_compression_type(segment_v2::LZ4F); |
199 | 471 | break; |
200 | 0 | case TCompressionType::ZLIB: Branch (200:5): [True: 0, False: 471]
|
201 | 0 | schema->set_compression_type(segment_v2::ZLIB); |
202 | 0 | break; |
203 | 0 | case TCompressionType::ZSTD: Branch (203:5): [True: 0, False: 471]
|
204 | 0 | schema->set_compression_type(segment_v2::ZSTD); |
205 | 0 | break; |
206 | 0 | default: Branch (206:5): [True: 0, False: 471]
|
207 | 0 | schema->set_compression_type(segment_v2::LZ4F); |
208 | 0 | break; |
209 | 471 | } |
210 | | |
211 | 471 | switch (inverted_index_file_storage_format) { |
212 | 0 | case TInvertedIndexFileStorageFormat::V1: Branch (212:5): [True: 0, False: 471]
|
213 | 0 | schema->set_inverted_index_storage_format(InvertedIndexStorageFormatPB::V1); |
214 | 0 | break; |
215 | 471 | case TInvertedIndexFileStorageFormat::V2: Branch (215:5): [True: 471, False: 0]
|
216 | 471 | schema->set_inverted_index_storage_format(InvertedIndexStorageFormatPB::V2); |
217 | 471 | break; |
218 | 0 | case TInvertedIndexFileStorageFormat::V3: Branch (218:5): [True: 0, False: 471]
|
219 | 0 | schema->set_inverted_index_storage_format(InvertedIndexStorageFormatPB::V3); |
220 | 0 | break; |
221 | 0 | default: Branch (221:5): [True: 0, False: 471]
|
222 | 0 | schema->set_inverted_index_storage_format(InvertedIndexStorageFormatPB::V2); |
223 | 0 | break; |
224 | 471 | } |
225 | | |
226 | 471 | switch (tablet_schema.sort_type) { |
227 | 0 | case TSortType::type::ZORDER: Branch (227:5): [True: 0, False: 471]
|
228 | 0 | schema->set_sort_type(SortType::ZORDER); |
229 | 0 | break; |
230 | 471 | default: Branch (230:5): [True: 471, False: 0]
|
231 | 471 | schema->set_sort_type(SortType::LEXICAL); |
232 | 471 | } |
233 | 471 | schema->set_sort_col_num(tablet_schema.sort_col_num); |
234 | 471 | for (const auto& i : tablet_schema.cluster_key_idxes) { Branch (234:24): [True: 2, False: 471]
|
235 | 2 | schema->add_cluster_key_idxes(i); |
236 | 2 | } |
237 | 471 | tablet_meta_pb.set_in_restore_mode(false); |
238 | | |
239 | | // set column information |
240 | 471 | uint32_t col_ordinal = 0; |
241 | 471 | bool has_bf_columns = false; |
242 | 2.12k | for (TColumn tcolumn : tablet_schema.columns) { Branch (242:26): [True: 2.12k, False: 471]
|
243 | 2.12k | ColumnPB* column = schema->add_column(); |
244 | 2.12k | uint32_t unique_id = -1; |
245 | 2.12k | if (tcolumn.col_unique_id >= 0) { Branch (245:13): [True: 1, False: 2.12k]
|
246 | 1 | unique_id = tcolumn.col_unique_id; |
247 | 2.12k | } else { |
248 | 2.12k | unique_id = col_ordinal_to_unique_id.at(col_ordinal); |
249 | 2.12k | } |
250 | 2.12k | col_ordinal++; |
251 | 2.12k | init_column_from_tcolumn(unique_id, tcolumn, column); |
252 | | |
253 | 2.12k | if (column->is_bf_column()) { Branch (253:13): [True: 0, False: 2.12k]
|
254 | 0 | has_bf_columns = true; |
255 | 0 | } |
256 | | |
257 | 2.12k | if (tablet_schema.__isset.indexes) { Branch (257:13): [True: 0, False: 2.12k]
|
258 | 0 | for (auto& index : tablet_schema.indexes) { Branch (258:30): [True: 0, False: 0]
|
259 | 0 | if (index.index_type == TIndexType::type::BITMAP) { Branch (259:21): [True: 0, False: 0]
|
260 | 0 | DCHECK_EQ(index.columns.size(), 1); |
261 | 0 | if (iequal(tcolumn.column_name, index.columns[0])) { Branch (261:25): [True: 0, False: 0]
|
262 | 0 | column->set_has_bitmap_index(true); |
263 | 0 | break; |
264 | 0 | } |
265 | 0 | } else if (index.index_type == TIndexType::type::BLOOMFILTER || Branch (265:28): [True: 0, False: 0]
|
266 | 0 | index.index_type == TIndexType::type::NGRAM_BF) { Branch (266:28): [True: 0, False: 0]
|
267 | 0 | DCHECK_EQ(index.columns.size(), 1); |
268 | 0 | if (iequal(tcolumn.column_name, index.columns[0])) { Branch (268:25): [True: 0, False: 0]
|
269 | 0 | column->set_is_bf_column(true); |
270 | 0 | break; |
271 | 0 | } |
272 | 0 | } |
273 | 0 | } |
274 | 0 | } |
275 | 2.12k | } |
276 | | |
277 | | // copy index meta |
278 | 471 | if (tablet_schema.__isset.indexes) { Branch (278:9): [True: 0, False: 471]
|
279 | 0 | for (auto& index : tablet_schema.indexes) { Branch (279:26): [True: 0, False: 0]
|
280 | 0 | TabletIndexPB* index_pb = schema->add_index(); |
281 | 0 | index_pb->set_index_id(index.index_id); |
282 | 0 | index_pb->set_index_name(index.index_name); |
283 | | // init col_unique_id in index at be side, since col_unique_id may be -1 at fe side |
284 | | // get column unique id by name |
285 | 0 | for (auto column_name : index.columns) { Branch (285:35): [True: 0, False: 0]
|
286 | 0 | for (auto column : schema->column()) { Branch (286:34): [True: 0, False: 0]
|
287 | 0 | if (iequal(column.name(), column_name)) { Branch (287:25): [True: 0, False: 0]
|
288 | 0 | index_pb->add_col_unique_id(column.unique_id()); |
289 | 0 | } |
290 | 0 | } |
291 | 0 | } |
292 | 0 | switch (index.index_type) { Branch (292:21): [True: 0, False: 0]
|
293 | 0 | case TIndexType::BITMAP: Branch (293:13): [True: 0, False: 0]
|
294 | 0 | index_pb->set_index_type(IndexType::BITMAP); |
295 | 0 | break; |
296 | 0 | case TIndexType::INVERTED: Branch (296:13): [True: 0, False: 0]
|
297 | 0 | index_pb->set_index_type(IndexType::INVERTED); |
298 | 0 | break; |
299 | 0 | case TIndexType::BLOOMFILTER: Branch (299:13): [True: 0, False: 0]
|
300 | 0 | index_pb->set_index_type(IndexType::BLOOMFILTER); |
301 | 0 | break; |
302 | 0 | case TIndexType::NGRAM_BF: Branch (302:13): [True: 0, False: 0]
|
303 | 0 | index_pb->set_index_type(IndexType::NGRAM_BF); |
304 | 0 | break; |
305 | 0 | } |
306 | | |
307 | 0 | if (index.__isset.properties) { Branch (307:17): [True: 0, False: 0]
|
308 | 0 | auto properties = index_pb->mutable_properties(); |
309 | 0 | for (auto kv : index.properties) { Branch (309:30): [True: 0, False: 0]
|
310 | 0 | (*properties)[kv.first] = kv.second; |
311 | 0 | } |
312 | 0 | } |
313 | 0 | } |
314 | 0 | } |
315 | | |
316 | 471 | schema->set_next_column_unique_id(next_unique_id); |
317 | 471 | if (has_bf_columns && tablet_schema.__isset.bloom_filter_fpp) { Branch (317:9): [True: 0, False: 471]
Branch (317:27): [True: 0, False: 0]
|
318 | 0 | schema->set_bf_fpp(tablet_schema.bloom_filter_fpp); |
319 | 0 | } |
320 | | |
321 | 471 | if (tablet_schema.__isset.is_in_memory) { Branch (321:9): [True: 0, False: 471]
|
322 | 0 | schema->set_is_in_memory(tablet_schema.is_in_memory); |
323 | 0 | } |
324 | | |
325 | 471 | if (tablet_schema.__isset.disable_auto_compaction) { Branch (325:9): [True: 0, False: 471]
|
326 | 0 | schema->set_disable_auto_compaction(tablet_schema.disable_auto_compaction); |
327 | 0 | } |
328 | | |
329 | 471 | if (tablet_schema.__isset.variant_enable_flatten_nested) { Branch (329:9): [True: 471, False: 0]
|
330 | 471 | schema->set_variant_enable_flatten_nested(tablet_schema.variant_enable_flatten_nested); |
331 | 471 | } |
332 | | |
333 | 471 | if (tablet_schema.__isset.enable_single_replica_compaction) { Branch (333:9): [True: 471, False: 0]
|
334 | 471 | schema->set_enable_single_replica_compaction( |
335 | 471 | tablet_schema.enable_single_replica_compaction); |
336 | 471 | } |
337 | | |
338 | 471 | if (tablet_schema.__isset.delete_sign_idx) { Branch (338:9): [True: 471, False: 0]
|
339 | 471 | schema->set_delete_sign_idx(tablet_schema.delete_sign_idx); |
340 | 471 | } |
341 | 471 | if (tablet_schema.__isset.store_row_column) { Branch (341:9): [True: 471, False: 0]
|
342 | 471 | schema->set_store_row_column(tablet_schema.store_row_column); |
343 | 471 | } |
344 | 471 | if (tablet_schema.__isset.row_store_page_size) { Branch (344:9): [True: 471, False: 0]
|
345 | 471 | schema->set_row_store_page_size(tablet_schema.row_store_page_size); |
346 | 471 | } |
347 | 471 | if (tablet_schema.__isset.storage_page_size) { Branch (347:9): [True: 471, False: 0]
|
348 | 471 | schema->set_storage_page_size(tablet_schema.storage_page_size); |
349 | 471 | } |
350 | 471 | if (tablet_schema.__isset.skip_write_index_on_load) { Branch (350:9): [True: 471, False: 0]
|
351 | 471 | schema->set_skip_write_index_on_load(tablet_schema.skip_write_index_on_load); |
352 | 471 | } |
353 | 471 | if (tablet_schema.__isset.row_store_col_cids) { Branch (353:9): [True: 0, False: 471]
|
354 | 0 | schema->mutable_row_store_column_unique_ids()->Add(tablet_schema.row_store_col_cids.begin(), |
355 | 0 | tablet_schema.row_store_col_cids.end()); |
356 | 0 | } |
357 | 471 | if (binlog_config.has_value()) { Branch (357:9): [True: 0, False: 471]
|
358 | 0 | BinlogConfig tmp_binlog_config; |
359 | 0 | tmp_binlog_config = binlog_config.value(); |
360 | 0 | tmp_binlog_config.to_pb(tablet_meta_pb.mutable_binlog_config()); |
361 | 0 | } |
362 | | |
363 | 471 | init_from_pb(tablet_meta_pb); |
364 | 471 | } |
365 | | |
366 | | TabletMeta::TabletMeta(const TabletMeta& b) |
367 | | : MetadataAdder(b), |
368 | | _table_id(b._table_id), |
369 | | _index_id(b._index_id), |
370 | | _partition_id(b._partition_id), |
371 | | _tablet_id(b._tablet_id), |
372 | | _replica_id(b._replica_id), |
373 | | _schema_hash(b._schema_hash), |
374 | | _shard_id(b._shard_id), |
375 | | _creation_time(b._creation_time), |
376 | | _cumulative_layer_point(b._cumulative_layer_point), |
377 | | _tablet_uid(b._tablet_uid), |
378 | | _tablet_type(b._tablet_type), |
379 | | _tablet_state(b._tablet_state), |
380 | | _schema(b._schema), |
381 | | _rs_metas(b._rs_metas), |
382 | | _stale_rs_metas(b._stale_rs_metas), |
383 | | _in_restore_mode(b._in_restore_mode), |
384 | | _preferred_rowset_type(b._preferred_rowset_type), |
385 | | _storage_policy_id(b._storage_policy_id), |
386 | | _cooldown_meta_id(b._cooldown_meta_id), |
387 | | _enable_unique_key_merge_on_write(b._enable_unique_key_merge_on_write), |
388 | | _delete_bitmap(b._delete_bitmap), |
389 | | _binlog_config(b._binlog_config), |
390 | | _compaction_policy(b._compaction_policy), |
391 | | _time_series_compaction_goal_size_mbytes(b._time_series_compaction_goal_size_mbytes), |
392 | | _time_series_compaction_file_count_threshold( |
393 | | b._time_series_compaction_file_count_threshold), |
394 | | _time_series_compaction_time_threshold_seconds( |
395 | | b._time_series_compaction_time_threshold_seconds), |
396 | | _time_series_compaction_empty_rowsets_threshold( |
397 | | b._time_series_compaction_empty_rowsets_threshold), |
398 | 0 | _time_series_compaction_level_threshold(b._time_series_compaction_level_threshold) {}; |
399 | | |
400 | | void TabletMeta::init_column_from_tcolumn(uint32_t unique_id, const TColumn& tcolumn, |
401 | 2.12k | ColumnPB* column) { |
402 | 2.12k | column->set_unique_id(unique_id); |
403 | 2.12k | column->set_name(tcolumn.column_name); |
404 | 2.12k | column->set_has_bitmap_index(tcolumn.has_bitmap_index); |
405 | 2.12k | column->set_is_auto_increment(tcolumn.is_auto_increment); |
406 | 2.12k | if (tcolumn.__isset.is_on_update_current_timestamp) { Branch (406:9): [True: 2.12k, False: 0]
|
407 | 2.12k | column->set_is_on_update_current_timestamp(tcolumn.is_on_update_current_timestamp); |
408 | 2.12k | } |
409 | 2.12k | string data_type; |
410 | 2.12k | EnumToString(TPrimitiveType, tcolumn.column_type.type, data_type); Line | Count | Source | 212 | 2.12k | do { \ | 213 | 2.12k | auto it = _##enum_type##_VALUES_TO_NAMES.find(index); \ | 214 | 2.12k | if (it == _##enum_type##_VALUES_TO_NAMES.end()) { \ Branch (214:13): [True: 0, False: 2.12k]
| 215 | 0 | out = "NULL"; \ | 216 | 2.12k | } else { \ | 217 | 2.12k | out = it->second; \ | 218 | 2.12k | } \ | 219 | 2.12k | } while (0) Branch (219:14): [Folded - Ignored]
|
|
411 | 2.12k | column->set_type(data_type); |
412 | | |
413 | 2.12k | uint32_t length = TabletColumn::get_field_length_by_type(tcolumn.column_type.type, |
414 | 2.12k | tcolumn.column_type.len); |
415 | 2.12k | column->set_length(length); |
416 | 2.12k | column->set_index_length(length); |
417 | 2.12k | column->set_precision(tcolumn.column_type.precision); |
418 | 2.12k | column->set_frac(tcolumn.column_type.scale); |
419 | | |
420 | 2.12k | if (tcolumn.__isset.result_is_nullable) { Branch (420:9): [True: 0, False: 2.12k]
|
421 | 0 | column->set_result_is_nullable(tcolumn.result_is_nullable); |
422 | 0 | } |
423 | | |
424 | 2.12k | if (tcolumn.__isset.be_exec_version) { Branch (424:9): [True: 2.12k, False: 0]
|
425 | 2.12k | column->set_be_exec_version(tcolumn.be_exec_version); |
426 | 2.12k | } |
427 | | |
428 | 2.12k | if (tcolumn.column_type.type == TPrimitiveType::VARCHAR || Branch (428:9): [True: 101, False: 2.02k]
|
429 | 2.12k | tcolumn.column_type.type == TPrimitiveType::STRING) { Branch (429:9): [True: 0, False: 2.02k]
|
430 | 101 | if (!tcolumn.column_type.__isset.index_len) { Branch (430:13): [True: 101, False: 0]
|
431 | 101 | column->set_index_length(10); |
432 | 101 | } else { |
433 | 0 | column->set_index_length(tcolumn.column_type.index_len); |
434 | 0 | } |
435 | 101 | } |
436 | 2.12k | if (!tcolumn.is_key) { Branch (436:9): [True: 1.14k, False: 983]
|
437 | 1.14k | column->set_is_key(false); |
438 | 1.14k | if (tcolumn.__isset.aggregation) { Branch (438:13): [True: 0, False: 1.14k]
|
439 | 0 | column->set_aggregation(tcolumn.aggregation); |
440 | 1.14k | } else { |
441 | 1.14k | string aggregation_type; |
442 | 1.14k | EnumToString(TAggregationType, tcolumn.aggregation_type, aggregation_type); Line | Count | Source | 212 | 1.14k | do { \ | 213 | 1.14k | auto it = _##enum_type##_VALUES_TO_NAMES.find(index); \ | 214 | 1.14k | if (it == _##enum_type##_VALUES_TO_NAMES.end()) { \ Branch (214:13): [True: 0, False: 1.14k]
| 215 | 0 | out = "NULL"; \ | 216 | 1.14k | } else { \ | 217 | 1.14k | out = it->second; \ | 218 | 1.14k | } \ | 219 | 1.14k | } while (0) Branch (219:14): [Folded - Ignored]
|
|
443 | 1.14k | column->set_aggregation(aggregation_type); |
444 | 1.14k | } |
445 | 1.14k | } else { |
446 | 983 | column->set_is_key(true); |
447 | 983 | column->set_aggregation("NONE"); |
448 | 983 | } |
449 | 2.12k | column->set_is_nullable(tcolumn.is_allow_null); |
450 | 2.12k | if (tcolumn.__isset.default_value) { Branch (450:9): [True: 0, False: 2.12k]
|
451 | 0 | column->set_default_value(tcolumn.default_value); |
452 | 0 | } |
453 | 2.12k | if (tcolumn.__isset.is_bloom_filter_column) { Branch (453:9): [True: 0, False: 2.12k]
|
454 | 0 | column->set_is_bf_column(tcolumn.is_bloom_filter_column); |
455 | 0 | } |
456 | 2.12k | for (size_t i = 0; i < tcolumn.children_column.size(); i++) { Branch (456:24): [True: 0, False: 2.12k]
|
457 | 0 | ColumnPB* children_column = column->add_children_columns(); |
458 | 0 | init_column_from_tcolumn(tcolumn.children_column[i].col_unique_id, |
459 | 0 | tcolumn.children_column[i], children_column); |
460 | 0 | } |
461 | 2.12k | if (tcolumn.column_type.__isset.variant_max_subcolumns_count) { Branch (461:9): [True: 2.12k, False: 0]
|
462 | 2.12k | column->set_variant_max_subcolumns_count(tcolumn.column_type.variant_max_subcolumns_count); |
463 | 2.12k | } |
464 | 2.12k | if (tcolumn.__isset.pattern_type) { Branch (464:9): [True: 0, False: 2.12k]
|
465 | 0 | switch (tcolumn.pattern_type) { Branch (465:17): [True: 0, False: 0]
|
466 | 0 | case TPatternType::MATCH_NAME: Branch (466:9): [True: 0, False: 0]
|
467 | 0 | column->set_pattern_type(PatternTypePB::MATCH_NAME); |
468 | 0 | break; |
469 | 0 | case TPatternType::MATCH_NAME_GLOB: Branch (469:9): [True: 0, False: 0]
|
470 | 0 | column->set_pattern_type(PatternTypePB::MATCH_NAME_GLOB); |
471 | 0 | } |
472 | 0 | } |
473 | 2.12k | if (tcolumn.__isset.variant_enable_typed_paths_to_sparse) { Branch (473:9): [True: 2.12k, False: 0]
|
474 | 2.12k | column->set_variant_enable_typed_paths_to_sparse( |
475 | 2.12k | tcolumn.variant_enable_typed_paths_to_sparse); |
476 | 2.12k | } |
477 | 2.12k | } |
478 | | |
479 | 0 | void TabletMeta::remove_rowset_delete_bitmap(const RowsetId& rowset_id, const Version& version) { |
480 | 0 | if (_enable_unique_key_merge_on_write) { Branch (480:9): [True: 0, False: 0]
|
481 | 0 | delete_bitmap()->remove({rowset_id, 0, 0}, {rowset_id, UINT32_MAX, 0}); |
482 | 0 | if (config::enable_mow_verbose_log) { Branch (482:13): [True: 0, False: 0]
|
483 | 0 | LOG_INFO("delete rowset delete bitmap. tablet={}, rowset={}, version={}", tablet_id(), Line | Count | Source | 118 | 0 | #define LOG_INFO TaggableLogger(__FILE__, __LINE__, google::GLOG_INFO) |
|
484 | 0 | rowset_id.to_string(), version.to_string()); |
485 | 0 | } |
486 | 0 | size_t rowset_cache_version_size = delete_bitmap()->remove_rowset_cache_version(rowset_id); |
487 | 0 | _check_mow_rowset_cache_version_size(rowset_cache_version_size); |
488 | 0 | } |
489 | 0 | } |
490 | | |
491 | 4 | Status TabletMeta::create_from_file(const string& file_path) { |
492 | 4 | TabletMetaPB tablet_meta_pb; |
493 | 4 | RETURN_IF_ERROR(load_from_file(file_path, &tablet_meta_pb)); |
494 | 4 | init_from_pb(tablet_meta_pb); |
495 | 4 | return Status::OK(); |
496 | 4 | } |
497 | | |
498 | 10 | Status TabletMeta::load_from_file(const string& file_path, TabletMetaPB* tablet_meta_pb) { |
499 | 10 | FileHeader<TabletMetaPB> file_header(file_path); |
500 | | // In file_header.deserialize(), it validates file length, signature, checksum of protobuf. |
501 | 10 | RETURN_IF_ERROR(file_header.deserialize()); |
502 | 10 | try { |
503 | 10 | tablet_meta_pb->CopyFrom(file_header.message()); |
504 | 10 | } catch (const std::exception& e) { |
505 | 0 | LOG(WARNING) << "Failed to copy protocol buffer object: " << e.what() |
506 | 0 | << ", file=" << file_path; |
507 | 0 | return Status::Error<PARSE_PROTOBUF_ERROR>( |
508 | 0 | "fail to copy protocol buffer object. file={}, error={}", file_path, e.what()); |
509 | 0 | } |
510 | 10 | return Status::OK(); |
511 | 10 | } |
512 | | |
513 | 6 | Status TabletMeta::create_from_buffer(const uint8_t* buffer, size_t buffer_size) { |
514 | 6 | FileHeader<TabletMetaPB> file_header(""); // empty file path |
515 | 6 | RETURN_IF_ERROR(file_header.deserialize_from_memory(buffer, buffer_size)); |
516 | | |
517 | 2 | TabletMetaPB tablet_meta_pb; |
518 | 2 | try { |
519 | 2 | tablet_meta_pb.CopyFrom(file_header.message()); |
520 | 2 | } catch (const std::exception& e) { |
521 | 0 | LOG(WARNING) << "Failed to copy protocol buffer object from buffer: " << e.what(); |
522 | 0 | return Status::Error<ErrorCode::PARSE_PROTOBUF_ERROR>( |
523 | 0 | "fail to copy protocol buffer object from buffer. error={}", e.what()); |
524 | 0 | } |
525 | | |
526 | 2 | init_from_pb(tablet_meta_pb); |
527 | 2 | return Status::OK(); |
528 | 2 | } |
529 | | |
530 | | std::string TabletMeta::construct_header_file_path(const string& schema_hash_path, |
531 | 3 | int64_t tablet_id) { |
532 | 3 | std::stringstream header_name_stream; |
533 | 3 | header_name_stream << schema_hash_path << "/" << tablet_id << ".hdr"; |
534 | 3 | return header_name_stream.str(); |
535 | 3 | } |
536 | | |
537 | 0 | Status TabletMeta::save_as_json(const string& file_path) { |
538 | 0 | std::string json_meta; |
539 | 0 | json2pb::Pb2JsonOptions json_options; |
540 | 0 | json_options.pretty_json = true; |
541 | 0 | json_options.bytes_to_base64 = true; |
542 | 0 | to_json(&json_meta, json_options); |
543 | | // save to file |
544 | 0 | io::FileWriterPtr file_writer; |
545 | 0 | RETURN_IF_ERROR(io::global_local_filesystem()->create_file(file_path, &file_writer)); |
546 | 0 | RETURN_IF_ERROR(file_writer->append(json_meta)); |
547 | 0 | RETURN_IF_ERROR(file_writer->close()); |
548 | 0 | return Status::OK(); |
549 | 0 | } |
550 | | |
551 | 230 | Status TabletMeta::save(const string& file_path) { |
552 | 230 | TabletMetaPB tablet_meta_pb; |
553 | 230 | to_meta_pb(&tablet_meta_pb); |
554 | 230 | return TabletMeta::save(file_path, tablet_meta_pb); |
555 | 230 | } |
556 | | |
557 | 234 | Status TabletMeta::save(const string& file_path, const TabletMetaPB& tablet_meta_pb) { |
558 | 234 | DCHECK(!file_path.empty()); |
559 | 234 | FileHeader<TabletMetaPB> file_header(file_path); |
560 | 234 | try { |
561 | 234 | file_header.mutable_message()->CopyFrom(tablet_meta_pb); |
562 | 234 | } catch (...) { |
563 | 0 | LOG(WARNING) << "fail to copy protocol buffer object. file='" << file_path; |
564 | 0 | return Status::Error<ErrorCode::INTERNAL_ERROR>( |
565 | 0 | "fail to copy protocol buffer object. file={}", file_path); |
566 | 0 | } |
567 | 234 | RETURN_IF_ERROR(file_header.prepare()); |
568 | 234 | RETURN_IF_ERROR(file_header.serialize()); |
569 | 234 | return Status::OK(); |
570 | 234 | } |
571 | | |
572 | 565 | Status TabletMeta::save_meta(DataDir* data_dir) { |
573 | 565 | std::lock_guard<std::shared_mutex> wrlock(_meta_lock); |
574 | 565 | return _save_meta(data_dir); |
575 | 565 | } |
576 | | |
577 | 565 | Status TabletMeta::_save_meta(DataDir* data_dir) { |
578 | | // check if tablet uid is valid |
579 | 565 | if (_tablet_uid.hi == 0 && _tablet_uid.lo == 0) { Branch (579:9): [True: 0, False: 565]
Branch (579:32): [True: 0, False: 0]
|
580 | 0 | LOG(FATAL) << "tablet_uid is invalid" |
581 | 0 | << " tablet=" << tablet_id() << " _tablet_uid=" << _tablet_uid.to_string(); |
582 | 0 | } |
583 | 565 | string meta_binary; |
584 | | |
585 | 565 | auto t1 = MonotonicMicros(); |
586 | 565 | serialize(&meta_binary); |
587 | 565 | auto t2 = MonotonicMicros(); |
588 | 565 | Status status = TabletMetaManager::save(data_dir, tablet_id(), schema_hash(), meta_binary); |
589 | 565 | if (!status.ok()) { Branch (589:9): [True: 0, False: 565]
|
590 | 0 | LOG(FATAL) << "fail to save tablet_meta. status=" << status << ", tablet_id=" << tablet_id() |
591 | 0 | << ", schema_hash=" << schema_hash(); |
592 | 0 | } |
593 | 565 | auto t3 = MonotonicMicros(); |
594 | 565 | auto cost = t3 - t1; |
595 | 565 | if (cost > 1 * 1000 * 1000) { Branch (595:9): [True: 0, False: 565]
|
596 | 0 | LOG(INFO) << "save tablet(" << tablet_id() << ") meta too slow. serialize cost " << t2 - t1 |
597 | 0 | << "(us), serialized binary size: " << meta_binary.length() |
598 | 0 | << "(bytes), write rocksdb cost " << t3 - t2 << "(us)"; |
599 | 0 | } |
600 | 565 | return status; |
601 | 565 | } |
602 | | |
603 | 570 | void TabletMeta::serialize(string* meta_binary) { |
604 | 570 | TabletMetaPB tablet_meta_pb; |
605 | 570 | to_meta_pb(&tablet_meta_pb); |
606 | 570 | if (tablet_meta_pb.partition_id() <= 0) { Branch (606:9): [True: 468, False: 102]
|
607 | 468 | LOG(WARNING) << "invalid partition id " << tablet_meta_pb.partition_id() << " tablet " |
608 | 468 | << tablet_meta_pb.tablet_id(); |
609 | 468 | } |
610 | 570 | DBUG_EXECUTE_IF("TabletMeta::serialize::zero_partition_id", { Line | Count | Source | 37 | 570 | if (UNLIKELY(config::enable_debug_points)) { \ | 38 | 0 | auto dp = DebugPoints::instance()->get_debug_point(debug_point_name); \ | 39 | 0 | if (dp) { \ Branch (39:13): [True: 0, False: 0]
| 40 | 0 | [[maybe_unused]] auto DP_NAME = debug_point_name; \ | 41 | 0 | { code; } \ | 42 | 0 | } \ | 43 | 0 | } |
|
611 | 570 | long partition_id = tablet_meta_pb.partition_id(); |
612 | 570 | tablet_meta_pb.set_partition_id(0); |
613 | 570 | LOG(WARNING) << "set debug point TabletMeta::serialize::zero_partition_id old=" |
614 | 570 | << partition_id << " new=" << tablet_meta_pb.DebugString(); |
615 | 570 | }); |
616 | 570 | bool serialize_success = tablet_meta_pb.SerializeToString(meta_binary); |
617 | 570 | if (!_rs_metas.empty() || !_stale_rs_metas.empty()) { Branch (617:9): [True: 570, False: 0]
Branch (617:31): [True: 0, False: 0]
|
618 | 570 | _avg_rs_meta_serialize_size = |
619 | 570 | meta_binary->length() / (_rs_metas.size() + _stale_rs_metas.size()); |
620 | 570 | if (meta_binary->length() > config::tablet_meta_serialize_size_limit || Branch (620:13): [True: 0, False: 570]
|
621 | 570 | !serialize_success) { Branch (621:13): [True: 0, False: 570]
|
622 | 0 | int64_t origin_meta_size = meta_binary->length(); |
623 | 0 | int64_t stale_rowsets_num = tablet_meta_pb.stale_rs_metas().size(); |
624 | 0 | tablet_meta_pb.clear_stale_rs_metas(); |
625 | 0 | meta_binary->clear(); |
626 | 0 | serialize_success = tablet_meta_pb.SerializeToString(meta_binary); |
627 | 0 | LOG(WARNING) << "tablet meta serialization size exceeds limit: " |
628 | 0 | << config::tablet_meta_serialize_size_limit |
629 | 0 | << " clean up stale rowsets, tablet id: " << tablet_id() |
630 | 0 | << " stale rowset num: " << stale_rowsets_num |
631 | 0 | << " serialization size before clean " << origin_meta_size |
632 | 0 | << " serialization size after clean " << meta_binary->length(); |
633 | 0 | } |
634 | 570 | } |
635 | | |
636 | 570 | if (!serialize_success) { Branch (636:9): [True: 0, False: 570]
|
637 | 0 | LOG(FATAL) << "failed to serialize meta " << tablet_id(); |
638 | 0 | } |
639 | 570 | } |
640 | | |
641 | 461 | Status TabletMeta::deserialize(std::string_view meta_binary) { |
642 | 461 | TabletMetaPB tablet_meta_pb; |
643 | 461 | bool parsed = tablet_meta_pb.ParseFromArray(meta_binary.data(), |
644 | 461 | static_cast<int32_t>(meta_binary.size())); |
645 | 461 | if (!parsed) { Branch (645:9): [True: 0, False: 461]
|
646 | 0 | return Status::Error<INIT_FAILED>("parse tablet meta failed"); |
647 | 0 | } |
648 | 461 | init_from_pb(tablet_meta_pb); |
649 | 461 | return Status::OK(); |
650 | 461 | } |
651 | | |
652 | 967 | void TabletMeta::init_from_pb(const TabletMetaPB& tablet_meta_pb) { |
653 | 967 | _table_id = tablet_meta_pb.table_id(); |
654 | 967 | _index_id = tablet_meta_pb.index_id(); |
655 | 967 | _partition_id = tablet_meta_pb.partition_id(); |
656 | 967 | _tablet_id = tablet_meta_pb.tablet_id(); |
657 | 967 | _replica_id = tablet_meta_pb.replica_id(); |
658 | 967 | _schema_hash = tablet_meta_pb.schema_hash(); |
659 | 967 | _shard_id = tablet_meta_pb.shard_id(); |
660 | 967 | _creation_time = tablet_meta_pb.creation_time(); |
661 | 967 | _cumulative_layer_point = tablet_meta_pb.cumulative_layer_point(); |
662 | 967 | _tablet_uid = TabletUid(tablet_meta_pb.tablet_uid()); |
663 | 967 | _ttl_seconds = tablet_meta_pb.ttl_seconds(); |
664 | 967 | if (tablet_meta_pb.has_tablet_type()) { Branch (664:9): [True: 945, False: 22]
|
665 | 945 | _tablet_type = tablet_meta_pb.tablet_type(); |
666 | 945 | } else { |
667 | 22 | _tablet_type = TabletTypePB::TABLET_TYPE_DISK; |
668 | 22 | } |
669 | | |
670 | | // init _tablet_state |
671 | 967 | switch (tablet_meta_pb.tablet_state()) { |
672 | 28 | case PB_NOTREADY: Branch (672:5): [True: 28, False: 939]
|
673 | 28 | _tablet_state = TabletState::TABLET_NOTREADY; |
674 | 28 | break; |
675 | 714 | case PB_RUNNING: Branch (675:5): [True: 714, False: 253]
|
676 | 714 | _tablet_state = TabletState::TABLET_RUNNING; |
677 | 714 | break; |
678 | 0 | case PB_TOMBSTONED: Branch (678:5): [True: 0, False: 967]
|
679 | 0 | _tablet_state = TabletState::TABLET_TOMBSTONED; |
680 | 0 | break; |
681 | 0 | case PB_STOPPED: Branch (681:5): [True: 0, False: 967]
|
682 | 0 | _tablet_state = TabletState::TABLET_STOPPED; |
683 | 0 | break; |
684 | 225 | case PB_SHUTDOWN: Branch (684:5): [True: 225, False: 742]
|
685 | 225 | _tablet_state = TabletState::TABLET_SHUTDOWN; |
686 | 225 | break; |
687 | 0 | default: Branch (687:5): [True: 0, False: 967]
|
688 | 0 | LOG(WARNING) << "tablet has no state. tablet=" << tablet_id() |
689 | 0 | << ", schema_hash=" << schema_hash(); |
690 | 967 | } |
691 | | |
692 | | // init _schema |
693 | 967 | TabletSchemaSPtr schema = std::make_shared<TabletSchema>(); |
694 | 967 | schema->init_from_pb(tablet_meta_pb.schema()); |
695 | 967 | if (_handle) { Branch (695:9): [True: 3, False: 964]
|
696 | 3 | TabletSchemaCache::instance()->release(_handle); |
697 | 3 | } |
698 | 967 | auto pair = TabletSchemaCache::instance()->insert(schema->to_key()); |
699 | 967 | _handle = pair.first; |
700 | 967 | _schema = pair.second; |
701 | | |
702 | 967 | if (tablet_meta_pb.has_enable_unique_key_merge_on_write()) { Branch (702:9): [True: 945, False: 22]
|
703 | 945 | _enable_unique_key_merge_on_write = tablet_meta_pb.enable_unique_key_merge_on_write(); |
704 | 945 | } |
705 | | |
706 | | // init _rs_metas |
707 | 10.8k | for (auto& it : tablet_meta_pb.rs_metas()) { Branch (707:19): [True: 10.8k, False: 967]
|
708 | 10.8k | RowsetMetaSharedPtr rs_meta(new RowsetMeta()); |
709 | 10.8k | rs_meta->init_from_pb(it); |
710 | 10.8k | _rs_metas.push_back(std::move(rs_meta)); |
711 | 10.8k | } |
712 | | |
713 | | // For mow table, delete bitmap of stale rowsets has not been persisted. |
714 | | // When be restart, query should not read the stale rowset, otherwise duplicate keys |
715 | | // will be read out. Therefore, we don't add them to _stale_rs_meta for mow table. |
716 | 967 | if (!config::skip_loading_stale_rowset_meta && !_enable_unique_key_merge_on_write) { Branch (716:9): [True: 967, False: 0]
Branch (716:52): [True: 932, False: 35]
|
717 | 932 | for (auto& it : tablet_meta_pb.stale_rs_metas()) { Branch (717:23): [True: 0, False: 932]
|
718 | 0 | RowsetMetaSharedPtr rs_meta(new RowsetMeta()); |
719 | 0 | rs_meta->init_from_pb(it); |
720 | 0 | _stale_rs_metas.push_back(std::move(rs_meta)); |
721 | 0 | } |
722 | 932 | } |
723 | | |
724 | 967 | if (tablet_meta_pb.has_in_restore_mode()) { Branch (724:9): [True: 945, False: 22]
|
725 | 945 | _in_restore_mode = tablet_meta_pb.in_restore_mode(); |
726 | 945 | } |
727 | | |
728 | 967 | if (tablet_meta_pb.has_preferred_rowset_type()) { Branch (728:9): [True: 474, False: 493]
|
729 | 474 | _preferred_rowset_type = tablet_meta_pb.preferred_rowset_type(); |
730 | 474 | } |
731 | | |
732 | 967 | _storage_policy_id = tablet_meta_pb.storage_policy_id(); |
733 | 967 | if (tablet_meta_pb.has_cooldown_meta_id()) { Branch (733:9): [True: 0, False: 967]
|
734 | 0 | _cooldown_meta_id = tablet_meta_pb.cooldown_meta_id(); |
735 | 0 | } |
736 | | |
737 | 967 | if (tablet_meta_pb.has_delete_bitmap()) { Branch (737:9): [True: 0, False: 967]
|
738 | 0 | int rst_ids_size = tablet_meta_pb.delete_bitmap().rowset_ids_size(); |
739 | 0 | int seg_ids_size = tablet_meta_pb.delete_bitmap().segment_ids_size(); |
740 | 0 | int versions_size = tablet_meta_pb.delete_bitmap().versions_size(); |
741 | 0 | int seg_maps_size = tablet_meta_pb.delete_bitmap().segment_delete_bitmaps_size(); |
742 | 0 | CHECK(rst_ids_size == seg_ids_size && seg_ids_size == seg_maps_size && |
743 | 0 | seg_maps_size == versions_size); |
744 | 0 | for (int i = 0; i < rst_ids_size; ++i) { Branch (744:25): [True: 0, False: 0]
|
745 | 0 | RowsetId rst_id; |
746 | 0 | rst_id.init(tablet_meta_pb.delete_bitmap().rowset_ids(i)); |
747 | 0 | auto seg_id = tablet_meta_pb.delete_bitmap().segment_ids(i); |
748 | 0 | auto ver = tablet_meta_pb.delete_bitmap().versions(i); |
749 | 0 | auto bitmap = tablet_meta_pb.delete_bitmap().segment_delete_bitmaps(i).data(); |
750 | 0 | delete_bitmap()->delete_bitmap[{rst_id, seg_id, ver}] = roaring::Roaring::read(bitmap); |
751 | 0 | } |
752 | 0 | } |
753 | | |
754 | 967 | if (tablet_meta_pb.has_binlog_config()) { Branch (754:9): [True: 472, False: 495]
|
755 | 472 | _binlog_config = tablet_meta_pb.binlog_config(); |
756 | 472 | } |
757 | 967 | _compaction_policy = tablet_meta_pb.compaction_policy(); |
758 | 967 | _time_series_compaction_goal_size_mbytes = |
759 | 967 | tablet_meta_pb.time_series_compaction_goal_size_mbytes(); |
760 | 967 | _time_series_compaction_file_count_threshold = |
761 | 967 | tablet_meta_pb.time_series_compaction_file_count_threshold(); |
762 | 967 | _time_series_compaction_time_threshold_seconds = |
763 | 967 | tablet_meta_pb.time_series_compaction_time_threshold_seconds(); |
764 | 967 | _time_series_compaction_empty_rowsets_threshold = |
765 | 967 | tablet_meta_pb.time_series_compaction_empty_rowsets_threshold(); |
766 | 967 | _time_series_compaction_level_threshold = |
767 | 967 | tablet_meta_pb.time_series_compaction_level_threshold(); |
768 | 967 | } |
769 | | |
770 | 814 | void TabletMeta::to_meta_pb(TabletMetaPB* tablet_meta_pb) { |
771 | 814 | tablet_meta_pb->set_table_id(table_id()); |
772 | 814 | tablet_meta_pb->set_index_id(index_id()); |
773 | 814 | tablet_meta_pb->set_partition_id(partition_id()); |
774 | 814 | tablet_meta_pb->set_tablet_id(tablet_id()); |
775 | 814 | tablet_meta_pb->set_replica_id(replica_id()); |
776 | 814 | tablet_meta_pb->set_schema_hash(schema_hash()); |
777 | 814 | tablet_meta_pb->set_shard_id(shard_id()); |
778 | 814 | tablet_meta_pb->set_creation_time(creation_time()); |
779 | 814 | tablet_meta_pb->set_cumulative_layer_point(cumulative_layer_point()); |
780 | 814 | *(tablet_meta_pb->mutable_tablet_uid()) = tablet_uid().to_proto(); |
781 | 814 | tablet_meta_pb->set_tablet_type(_tablet_type); |
782 | 814 | tablet_meta_pb->set_ttl_seconds(_ttl_seconds); |
783 | 814 | switch (tablet_state()) { Branch (783:13): [True: 0, False: 814]
|
784 | 8 | case TABLET_NOTREADY: Branch (784:5): [True: 8, False: 806]
|
785 | 8 | tablet_meta_pb->set_tablet_state(PB_NOTREADY); |
786 | 8 | break; |
787 | 328 | case TABLET_RUNNING: Branch (787:5): [True: 328, False: 486]
|
788 | 328 | tablet_meta_pb->set_tablet_state(PB_RUNNING); |
789 | 328 | break; |
790 | 0 | case TABLET_TOMBSTONED: Branch (790:5): [True: 0, False: 814]
|
791 | 0 | tablet_meta_pb->set_tablet_state(PB_TOMBSTONED); |
792 | 0 | break; |
793 | 0 | case TABLET_STOPPED: Branch (793:5): [True: 0, False: 814]
|
794 | 0 | tablet_meta_pb->set_tablet_state(PB_STOPPED); |
795 | 0 | break; |
796 | 478 | case TABLET_SHUTDOWN: Branch (796:5): [True: 478, False: 336]
|
797 | 478 | tablet_meta_pb->set_tablet_state(PB_SHUTDOWN); |
798 | 478 | break; |
799 | 814 | } |
800 | | |
801 | | // RowsetMetaPB is separated from TabletMetaPB |
802 | 814 | if (!config::is_cloud_mode()) { Branch (802:9): [True: 814, False: 0]
|
803 | 21.6k | for (auto& rs : _rs_metas) { Branch (803:23): [True: 21.6k, False: 814]
|
804 | 21.6k | rs->to_rowset_pb(tablet_meta_pb->add_rs_metas()); |
805 | 21.6k | } |
806 | 814 | for (auto rs : _stale_rs_metas) { Branch (806:22): [True: 0, False: 814]
|
807 | 0 | rs->to_rowset_pb(tablet_meta_pb->add_stale_rs_metas()); |
808 | 0 | } |
809 | 814 | } |
810 | | |
811 | 814 | _schema->to_schema_pb(tablet_meta_pb->mutable_schema()); |
812 | | |
813 | 814 | tablet_meta_pb->set_in_restore_mode(in_restore_mode()); |
814 | | |
815 | | // to avoid modify tablet meta to the greatest extend |
816 | 814 | if (_preferred_rowset_type == BETA_ROWSET) { Branch (816:9): [True: 814, False: 0]
|
817 | 814 | tablet_meta_pb->set_preferred_rowset_type(_preferred_rowset_type); |
818 | 814 | } |
819 | 814 | if (_storage_policy_id > 0) { Branch (819:9): [True: 5, False: 809]
|
820 | 5 | tablet_meta_pb->set_storage_policy_id(_storage_policy_id); |
821 | 5 | } |
822 | 814 | if (_cooldown_meta_id.initialized()) { Branch (822:9): [True: 5, False: 809]
|
823 | 5 | tablet_meta_pb->mutable_cooldown_meta_id()->CopyFrom(_cooldown_meta_id.to_proto()); |
824 | 5 | } |
825 | | |
826 | 814 | tablet_meta_pb->set_enable_unique_key_merge_on_write(_enable_unique_key_merge_on_write); |
827 | | |
828 | 814 | if (_enable_unique_key_merge_on_write) { Branch (828:9): [True: 4, False: 810]
|
829 | 4 | std::set<RowsetId> stale_rs_ids; |
830 | 4 | for (const auto& rowset : _stale_rs_metas) { Branch (830:33): [True: 0, False: 4]
|
831 | 0 | stale_rs_ids.insert(rowset->rowset_id()); |
832 | 0 | } |
833 | 4 | DeleteBitmapPB* delete_bitmap_pb = tablet_meta_pb->mutable_delete_bitmap(); |
834 | 4 | for (auto& [id, bitmap] : delete_bitmap()->snapshot().delete_bitmap) { Branch (834:33): [True: 2, False: 4]
|
835 | 2 | auto& [rowset_id, segment_id, ver] = id; |
836 | 2 | if (stale_rs_ids.count(rowset_id) != 0) { Branch (836:17): [True: 0, False: 2]
|
837 | 0 | continue; |
838 | 0 | } |
839 | 2 | delete_bitmap_pb->add_rowset_ids(rowset_id.to_string()); |
840 | 2 | delete_bitmap_pb->add_segment_ids(segment_id); |
841 | 2 | delete_bitmap_pb->add_versions(ver); |
842 | 2 | std::string bitmap_data(bitmap.getSizeInBytes(), '\0'); |
843 | 2 | bitmap.write(bitmap_data.data()); |
844 | 2 | *(delete_bitmap_pb->add_segment_delete_bitmaps()) = std::move(bitmap_data); |
845 | 2 | } |
846 | 4 | } |
847 | 814 | _binlog_config.to_pb(tablet_meta_pb->mutable_binlog_config()); |
848 | 814 | tablet_meta_pb->set_compaction_policy(compaction_policy()); |
849 | 814 | tablet_meta_pb->set_time_series_compaction_goal_size_mbytes( |
850 | 814 | time_series_compaction_goal_size_mbytes()); |
851 | 814 | tablet_meta_pb->set_time_series_compaction_file_count_threshold( |
852 | 814 | time_series_compaction_file_count_threshold()); |
853 | 814 | tablet_meta_pb->set_time_series_compaction_time_threshold_seconds( |
854 | 814 | time_series_compaction_time_threshold_seconds()); |
855 | 814 | tablet_meta_pb->set_time_series_compaction_empty_rowsets_threshold( |
856 | 814 | time_series_compaction_empty_rowsets_threshold()); |
857 | 814 | tablet_meta_pb->set_time_series_compaction_level_threshold( |
858 | 814 | time_series_compaction_level_threshold()); |
859 | 814 | } |
860 | | |
861 | 2 | void TabletMeta::to_json(string* json_string, json2pb::Pb2JsonOptions& options) { |
862 | 2 | TabletMetaPB tablet_meta_pb; |
863 | 2 | to_meta_pb(&tablet_meta_pb); |
864 | 2 | json2pb::ProtoMessageToJson(tablet_meta_pb, json_string, options); |
865 | 2 | } |
866 | | |
867 | 124 | Version TabletMeta::max_version() const { |
868 | 124 | Version max_version = {-1, 0}; |
869 | 187 | for (auto& rs_meta : _rs_metas) { Branch (869:24): [True: 187, False: 124]
|
870 | 187 | if (rs_meta->end_version() > max_version.second) { Branch (870:13): [True: 185, False: 2]
|
871 | 185 | max_version = rs_meta->version(); |
872 | 185 | } |
873 | 187 | } |
874 | 124 | return max_version; |
875 | 124 | } |
876 | | |
877 | 0 | size_t TabletMeta::version_count_cross_with_range(const Version& range) const { |
878 | 0 | size_t count = 0; |
879 | 0 | for (const auto& rs_meta : _rs_metas) { Branch (879:30): [True: 0, False: 0]
|
880 | 0 | if (!(range.first > rs_meta->version().second || range.second < rs_meta->version().first)) { Branch (880:13): [True: 0, False: 0]
Branch (880:15): [True: 0, False: 0]
Branch (880:58): [True: 0, False: 0]
|
881 | 0 | count++; |
882 | 0 | } |
883 | 0 | } |
884 | 0 | return count; |
885 | 0 | } |
886 | | |
887 | 11.1k | Status TabletMeta::add_rs_meta(const RowsetMetaSharedPtr& rs_meta) { |
888 | | // check RowsetMeta is valid |
889 | 357k | for (auto& rs : _rs_metas) { Branch (889:19): [True: 357k, False: 11.1k]
|
890 | 357k | if (rs->version() == rs_meta->version()) { Branch (890:13): [True: 0, False: 357k]
|
891 | 0 | if (rs->rowset_id() != rs_meta->rowset_id()) { Branch (891:17): [True: 0, False: 0]
|
892 | 0 | return Status::Error<PUSH_VERSION_ALREADY_EXIST>( |
893 | 0 | "version already exist. rowset_id={}, version={}, tablet={}", |
894 | 0 | rs->rowset_id().to_string(), rs->version().to_string(), tablet_id()); |
895 | 0 | } else { |
896 | | // rowsetid,version is equal, it is a duplicate req, skip it |
897 | 0 | return Status::OK(); |
898 | 0 | } |
899 | 0 | } |
900 | 357k | } |
901 | 11.1k | _rs_metas.push_back(rs_meta); |
902 | 11.1k | return Status::OK(); |
903 | 11.1k | } |
904 | | |
905 | 0 | void TabletMeta::add_rowsets_unchecked(const std::vector<RowsetSharedPtr>& to_add) { |
906 | 0 | for (const auto& rs : to_add) { Branch (906:25): [True: 0, False: 0]
|
907 | 0 | _rs_metas.push_back(rs->rowset_meta()); |
908 | 0 | } |
909 | 0 | } |
910 | | |
911 | | void TabletMeta::delete_rs_meta_by_version(const Version& version, |
912 | 0 | std::vector<RowsetMetaSharedPtr>* deleted_rs_metas) { |
913 | 0 | size_t rowset_cache_version_size = 0; |
914 | 0 | auto it = _rs_metas.begin(); |
915 | 0 | while (it != _rs_metas.end()) { Branch (915:12): [True: 0, False: 0]
|
916 | 0 | if ((*it)->version() == version) { Branch (916:13): [True: 0, False: 0]
|
917 | 0 | if (deleted_rs_metas != nullptr) { Branch (917:17): [True: 0, False: 0]
|
918 | 0 | deleted_rs_metas->push_back(*it); |
919 | 0 | } |
920 | 0 | _rs_metas.erase(it); |
921 | 0 | if (_enable_unique_key_merge_on_write) { Branch (921:17): [True: 0, False: 0]
|
922 | 0 | rowset_cache_version_size = |
923 | 0 | _delete_bitmap->remove_rowset_cache_version((*it)->rowset_id()); |
924 | 0 | } |
925 | 0 | return; |
926 | 0 | } else { |
927 | 0 | ++it; |
928 | 0 | } |
929 | 0 | } |
930 | 0 | _check_mow_rowset_cache_version_size(rowset_cache_version_size); |
931 | 0 | } |
932 | | |
933 | | void TabletMeta::modify_rs_metas(const std::vector<RowsetMetaSharedPtr>& to_add, |
934 | | const std::vector<RowsetMetaSharedPtr>& to_delete, |
935 | 24 | bool same_version) { |
936 | 24 | size_t rowset_cache_version_size = 0; |
937 | | // Remove to_delete rowsets from _rs_metas |
938 | 24 | for (auto rs_to_del : to_delete) { Branch (938:25): [True: 18, False: 24]
|
939 | 18 | auto it = _rs_metas.begin(); |
940 | 20 | while (it != _rs_metas.end()) { Branch (940:16): [True: 20, False: 0]
|
941 | 20 | if (rs_to_del->version() == (*it)->version()) { Branch (941:17): [True: 18, False: 2]
|
942 | 18 | _rs_metas.erase(it); |
943 | 18 | if (_enable_unique_key_merge_on_write) { Branch (943:21): [True: 1, False: 17]
|
944 | 1 | rowset_cache_version_size = |
945 | 1 | _delete_bitmap->remove_rowset_cache_version((*it)->rowset_id()); |
946 | 1 | } |
947 | | // there should be only one rowset match the version |
948 | 18 | break; |
949 | 18 | } else { |
950 | 2 | ++it; |
951 | 2 | } |
952 | 20 | } |
953 | 18 | } |
954 | 24 | if (!same_version) { Branch (954:9): [True: 6, False: 18]
|
955 | | // put to_delete rowsets in _stale_rs_metas. |
956 | 6 | _stale_rs_metas.insert(_stale_rs_metas.end(), to_delete.begin(), to_delete.end()); |
957 | 6 | } |
958 | | // put to_add rowsets in _rs_metas. |
959 | 24 | _rs_metas.insert(_rs_metas.end(), to_add.begin(), to_add.end()); |
960 | 24 | _check_mow_rowset_cache_version_size(rowset_cache_version_size); |
961 | 24 | } |
962 | | |
963 | | // Use the passing "rs_metas" to replace the rs meta in this tablet meta |
964 | | // Also clear the _stale_rs_metas because this tablet meta maybe copyied from |
965 | | // an existing tablet before. Add after revise, only the passing "rs_metas" |
966 | | // is needed. |
967 | 5 | void TabletMeta::revise_rs_metas(std::vector<RowsetMetaSharedPtr>&& rs_metas) { |
968 | 5 | { |
969 | 5 | std::lock_guard<std::shared_mutex> wrlock(_meta_lock); |
970 | 5 | _rs_metas = std::move(rs_metas); |
971 | 5 | _stale_rs_metas.clear(); |
972 | 5 | } |
973 | 5 | if (_enable_unique_key_merge_on_write) { Branch (973:9): [True: 0, False: 5]
|
974 | 0 | _delete_bitmap->clear_rowset_cache_version(); |
975 | 0 | } |
976 | 5 | } |
977 | | |
978 | | // This method should call after revise_rs_metas, since new rs_metas might be a subset |
979 | | // of original tablet, we should revise the delete_bitmap according to current rowset. |
980 | | // |
981 | | // Delete bitmap is protected by Tablet::_meta_lock, we don't need to acquire the |
982 | | // TabletMeta's _meta_lock |
983 | 1 | void TabletMeta::revise_delete_bitmap_unlocked(const DeleteBitmap& delete_bitmap) { |
984 | 1 | _delete_bitmap = std::make_unique<DeleteBitmap>(tablet_id()); |
985 | 2 | for (auto rs : _rs_metas) { Branch (985:18): [True: 2, False: 1]
|
986 | 2 | DeleteBitmap rs_bm(tablet_id()); |
987 | 2 | delete_bitmap.subset({rs->rowset_id(), 0, 0}, {rs->rowset_id(), UINT32_MAX, INT64_MAX}, |
988 | 2 | &rs_bm); |
989 | 2 | _delete_bitmap->merge(rs_bm); |
990 | 2 | } |
991 | 1 | for (auto rs : _stale_rs_metas) { Branch (991:18): [True: 0, False: 1]
|
992 | 0 | DeleteBitmap rs_bm(tablet_id()); |
993 | 0 | delete_bitmap.subset({rs->rowset_id(), 0, 0}, {rs->rowset_id(), UINT32_MAX, INT64_MAX}, |
994 | 0 | &rs_bm); |
995 | 0 | _delete_bitmap->merge(rs_bm); |
996 | 0 | } |
997 | 1 | } |
998 | | |
999 | 0 | void TabletMeta::delete_stale_rs_meta_by_version(const Version& version) { |
1000 | 0 | auto it = _stale_rs_metas.begin(); |
1001 | 0 | while (it != _stale_rs_metas.end()) { Branch (1001:12): [True: 0, False: 0]
|
1002 | 0 | if ((*it)->version() == version) { Branch (1002:13): [True: 0, False: 0]
|
1003 | 0 | it = _stale_rs_metas.erase(it); |
1004 | 0 | } else { |
1005 | 0 | it++; |
1006 | 0 | } |
1007 | 0 | } |
1008 | 0 | } |
1009 | | |
1010 | 0 | RowsetMetaSharedPtr TabletMeta::acquire_rs_meta_by_version(const Version& version) const { |
1011 | 0 | for (auto it : _rs_metas) { Branch (1011:18): [True: 0, False: 0]
|
1012 | 0 | if (it->version() == version) { Branch (1012:13): [True: 0, False: 0]
|
1013 | 0 | return it; |
1014 | 0 | } |
1015 | 0 | } |
1016 | 0 | return nullptr; |
1017 | 0 | } |
1018 | | |
1019 | 8 | RowsetMetaSharedPtr TabletMeta::acquire_stale_rs_meta_by_version(const Version& version) const { |
1020 | 8 | for (auto it : _stale_rs_metas) { Branch (1020:18): [True: 0, False: 8]
|
1021 | 0 | if (it->version() == version) { Branch (1021:13): [True: 0, False: 0]
|
1022 | 0 | return it; |
1023 | 0 | } |
1024 | 0 | } |
1025 | 8 | return nullptr; |
1026 | 8 | } |
1027 | | |
1028 | 23 | Status TabletMeta::set_partition_id(int64_t partition_id) { |
1029 | 23 | if ((_partition_id > 0 && _partition_id != partition_id) || partition_id < 1) { Branch (1029:10): [True: 0, False: 23]
Branch (1029:31): [True: 0, False: 0]
Branch (1029:65): [True: 0, False: 23]
|
1030 | 0 | LOG(WARNING) << "cur partition id=" << _partition_id << " new partition id=" << partition_id |
1031 | 0 | << " not equal"; |
1032 | 0 | } |
1033 | 23 | _partition_id = partition_id; |
1034 | 23 | return Status::OK(); |
1035 | 23 | } |
1036 | | |
1037 | 0 | void TabletMeta::clear_stale_rowset() { |
1038 | 0 | _stale_rs_metas.clear(); |
1039 | 0 | if (_enable_unique_key_merge_on_write) { Branch (1039:9): [True: 0, False: 0]
|
1040 | 0 | _delete_bitmap->clear_rowset_cache_version(); |
1041 | 0 | } |
1042 | 0 | } |
1043 | | |
1044 | 0 | void TabletMeta::clear_rowsets() { |
1045 | 0 | _rs_metas.clear(); |
1046 | 0 | if (_enable_unique_key_merge_on_write) { Branch (1046:9): [True: 0, False: 0]
|
1047 | 0 | _delete_bitmap->clear_rowset_cache_version(); |
1048 | 0 | } |
1049 | 0 | } |
1050 | | |
1051 | 24 | void TabletMeta::_check_mow_rowset_cache_version_size(size_t rowset_cache_version_size) { |
1052 | 24 | if (_enable_unique_key_merge_on_write && config::enable_mow_verbose_log && Branch (1052:9): [True: 1, False: 23]
Branch (1052:46): [True: 0, False: 1]
|
1053 | 24 | rowset_cache_version_size > _rs_metas.size() + _stale_rs_metas.size()) { Branch (1053:9): [True: 0, False: 0]
|
1054 | 0 | std::stringstream ss; |
1055 | 0 | auto rowset_ids = _delete_bitmap->get_rowset_cache_version(); |
1056 | 0 | for (const auto& rowset_id : rowset_ids) { Branch (1056:36): [True: 0, False: 0]
|
1057 | 0 | bool found = false; |
1058 | 0 | for (auto& rs_meta : _rs_metas) { Branch (1058:32): [True: 0, False: 0]
|
1059 | 0 | if (rs_meta->rowset_id() == rowset_id) { Branch (1059:21): [True: 0, False: 0]
|
1060 | 0 | found = true; |
1061 | 0 | break; |
1062 | 0 | } |
1063 | 0 | } |
1064 | 0 | if (found) { Branch (1064:17): [True: 0, False: 0]
|
1065 | 0 | continue; |
1066 | 0 | } |
1067 | 0 | for (auto& rs_meta : _stale_rs_metas) { Branch (1067:32): [True: 0, False: 0]
|
1068 | 0 | if (rs_meta->rowset_id() == rowset_id) { Branch (1068:21): [True: 0, False: 0]
|
1069 | 0 | found = true; |
1070 | 0 | break; |
1071 | 0 | } |
1072 | 0 | } |
1073 | 0 | if (!found) { Branch (1073:17): [True: 0, False: 0]
|
1074 | 0 | ss << rowset_id.to_string() << ", "; |
1075 | 0 | } |
1076 | 0 | } |
1077 | | // size(rowset_cache_version) <= size(_rs_metas) + size(_stale_rs_metas) + size(_unused_rs) |
1078 | 0 | std::string msg = fmt::format( |
1079 | 0 | "tablet: {}, rowset_cache_version size: {}, " |
1080 | 0 | "_rs_metas size: {}, _stale_rs_metas size: {}, delta: {}. rowset only in cache: {}", |
1081 | 0 | _tablet_id, rowset_cache_version_size, _rs_metas.size(), _stale_rs_metas.size(), |
1082 | 0 | rowset_cache_version_size - _rs_metas.size() - _stale_rs_metas.size(), ss.str()); |
1083 | 0 | LOG(INFO) << msg; |
1084 | 0 | } |
1085 | 24 | } |
1086 | | |
1087 | 3 | bool operator==(const TabletMeta& a, const TabletMeta& b) { |
1088 | 3 | if (a._table_id != b._table_id) return false; Branch (1088:9): [True: 0, False: 3]
|
1089 | 3 | if (a._index_id != b._index_id) return false; Branch (1089:9): [True: 0, False: 3]
|
1090 | 3 | if (a._partition_id != b._partition_id) return false; Branch (1090:9): [True: 0, False: 3]
|
1091 | 3 | if (a._tablet_id != b._tablet_id) return false; Branch (1091:9): [True: 0, False: 3]
|
1092 | 3 | if (a._replica_id != b._replica_id) return false; Branch (1092:9): [True: 0, False: 3]
|
1093 | 3 | if (a._schema_hash != b._schema_hash) return false; Branch (1093:9): [True: 0, False: 3]
|
1094 | 3 | if (a._shard_id != b._shard_id) return false; Branch (1094:9): [True: 0, False: 3]
|
1095 | 3 | if (a._creation_time != b._creation_time) return false; Branch (1095:9): [True: 0, False: 3]
|
1096 | 3 | if (a._cumulative_layer_point != b._cumulative_layer_point) return false; Branch (1096:9): [True: 0, False: 3]
|
1097 | 3 | if (a._tablet_uid != b._tablet_uid) return false; Branch (1097:9): [True: 0, False: 3]
|
1098 | 3 | if (a._tablet_type != b._tablet_type) return false; Branch (1098:9): [True: 0, False: 3]
|
1099 | 3 | if (a._tablet_state != b._tablet_state) return false; Branch (1099:9): [True: 0, False: 3]
|
1100 | 3 | if (*a._schema != *b._schema) return false; Branch (1100:9): [True: 0, False: 3]
|
1101 | 3 | if (a._rs_metas.size() != b._rs_metas.size()) return false; Branch (1101:9): [True: 0, False: 3]
|
1102 | 3 | for (int i = 0; i < a._rs_metas.size(); ++i) { Branch (1102:21): [True: 0, False: 3]
|
1103 | 0 | if (a._rs_metas[i] != b._rs_metas[i]) return false; Branch (1103:13): [True: 0, False: 0]
|
1104 | 0 | } |
1105 | 3 | if (a._in_restore_mode != b._in_restore_mode) return false; Branch (1105:9): [True: 0, False: 3]
|
1106 | 3 | if (a._preferred_rowset_type != b._preferred_rowset_type) return false; Branch (1106:9): [True: 0, False: 3]
|
1107 | 3 | if (a._storage_policy_id != b._storage_policy_id) return false; Branch (1107:9): [True: 0, False: 3]
|
1108 | 3 | if (a._compaction_policy != b._compaction_policy) return false; Branch (1108:9): [True: 0, False: 3]
|
1109 | 3 | if (a._time_series_compaction_goal_size_mbytes != b._time_series_compaction_goal_size_mbytes) Branch (1109:9): [True: 0, False: 3]
|
1110 | 0 | return false; |
1111 | 3 | if (a._time_series_compaction_file_count_threshold != Branch (1111:9): [True: 0, False: 3]
|
1112 | 3 | b._time_series_compaction_file_count_threshold) |
1113 | 0 | return false; |
1114 | 3 | if (a._time_series_compaction_time_threshold_seconds != Branch (1114:9): [True: 0, False: 3]
|
1115 | 3 | b._time_series_compaction_time_threshold_seconds) |
1116 | 0 | return false; |
1117 | 3 | if (a._time_series_compaction_empty_rowsets_threshold != Branch (1117:9): [True: 0, False: 3]
|
1118 | 3 | b._time_series_compaction_empty_rowsets_threshold) |
1119 | 0 | return false; |
1120 | 3 | if (a._time_series_compaction_level_threshold != b._time_series_compaction_level_threshold) Branch (1120:9): [True: 0, False: 3]
|
1121 | 0 | return false; |
1122 | 3 | return true; |
1123 | 3 | } |
1124 | | |
1125 | 0 | bool operator!=(const TabletMeta& a, const TabletMeta& b) { |
1126 | 0 | return !(a == b); |
1127 | 0 | } |
1128 | | |
1129 | | DeleteBitmapAggCache::DeleteBitmapAggCache(size_t capacity) |
1130 | | : LRUCachePolicy(CachePolicy::CacheType::DELETE_BITMAP_AGG_CACHE, capacity, |
1131 | | LRUCacheType::SIZE, config::delete_bitmap_agg_cache_stale_sweep_time_sec, |
1132 | 1 | 256) {} |
1133 | | |
1134 | 135 | DeleteBitmapAggCache* DeleteBitmapAggCache::instance() { |
1135 | 135 | return ExecEnv::GetInstance()->delete_bitmap_agg_cache(); |
1136 | 135 | } |
1137 | | |
1138 | 1 | DeleteBitmapAggCache* DeleteBitmapAggCache::create_instance(size_t capacity) { |
1139 | 1 | return new DeleteBitmapAggCache(capacity); |
1140 | 1 | } |
1141 | | |
1142 | 1.05k | DeleteBitmap::DeleteBitmap(int64_t tablet_id) : _tablet_id(tablet_id) {} |
1143 | | |
1144 | 7 | DeleteBitmap::DeleteBitmap(const DeleteBitmap& o) { |
1145 | 7 | std::shared_lock l1(o.lock); |
1146 | 7 | delete_bitmap = o.delete_bitmap; |
1147 | 7 | _tablet_id = o._tablet_id; |
1148 | 7 | } |
1149 | | |
1150 | 0 | DeleteBitmap& DeleteBitmap::operator=(const DeleteBitmap& o) { |
1151 | 0 | if (this == &o) return *this; Branch (1151:9): [True: 0, False: 0]
|
1152 | 0 | if (this < &o) { Branch (1152:9): [True: 0, False: 0]
|
1153 | 0 | std::unique_lock l1(lock); |
1154 | 0 | std::shared_lock l2(o.lock); |
1155 | 0 | delete_bitmap = o.delete_bitmap; |
1156 | 0 | _tablet_id = o._tablet_id; |
1157 | 0 | } else { |
1158 | 0 | std::shared_lock l2(o.lock); |
1159 | 0 | std::unique_lock l1(lock); |
1160 | 0 | delete_bitmap = o.delete_bitmap; |
1161 | 0 | _tablet_id = o._tablet_id; |
1162 | 0 | } |
1163 | 0 | return *this; |
1164 | 0 | } |
1165 | | |
1166 | 0 | DeleteBitmap::DeleteBitmap(DeleteBitmap&& o) noexcept { |
1167 | 0 | std::scoped_lock l(o.lock, o._rowset_cache_version_lock); |
1168 | 0 | delete_bitmap = std::move(o.delete_bitmap); |
1169 | 0 | _tablet_id = std::move(o._tablet_id); |
1170 | 0 | o._rowset_cache_version.clear(); |
1171 | 0 | } |
1172 | | |
1173 | 0 | DeleteBitmap& DeleteBitmap::operator=(DeleteBitmap&& o) noexcept { |
1174 | 0 | if (this == &o) return *this; Branch (1174:9): [True: 0, False: 0]
|
1175 | 0 | std::scoped_lock l(lock, o.lock, o._rowset_cache_version_lock); |
1176 | 0 | delete_bitmap = std::move(o.delete_bitmap); |
1177 | 0 | _tablet_id = std::move(o._tablet_id); |
1178 | 0 | o._rowset_cache_version.clear(); |
1179 | 0 | return *this; |
1180 | 0 | } |
1181 | | |
1182 | 0 | DeleteBitmap DeleteBitmap::from_pb(const DeleteBitmapPB& pb, int64_t tablet_id) { |
1183 | 0 | size_t len = pb.rowset_ids().size(); |
1184 | 0 | DCHECK_EQ(len, pb.segment_ids().size()); |
1185 | 0 | DCHECK_EQ(len, pb.versions().size()); |
1186 | 0 | DeleteBitmap delete_bitmap(tablet_id); |
1187 | 0 | for (int32_t i = 0; i < len; ++i) { Branch (1187:25): [True: 0, False: 0]
|
1188 | 0 | RowsetId rs_id; |
1189 | 0 | rs_id.init(pb.rowset_ids(i)); |
1190 | 0 | BitmapKey key = {rs_id, pb.segment_ids(i), pb.versions(i)}; |
1191 | 0 | delete_bitmap.delete_bitmap[key] = |
1192 | 0 | roaring::Roaring::read(pb.segment_delete_bitmaps(i).data()); |
1193 | 0 | } |
1194 | 0 | return delete_bitmap; |
1195 | 0 | } |
1196 | | |
1197 | 0 | DeleteBitmapPB DeleteBitmap::to_pb() { |
1198 | 0 | std::shared_lock l(lock); |
1199 | 0 | DeleteBitmapPB ret; |
1200 | 0 | for (const auto& [k, v] : delete_bitmap) { Branch (1200:29): [True: 0, False: 0]
|
1201 | 0 | ret.mutable_rowset_ids()->Add(std::get<0>(k).to_string()); |
1202 | 0 | ret.mutable_segment_ids()->Add(std::get<1>(k)); |
1203 | 0 | ret.mutable_versions()->Add(std::get<2>(k)); |
1204 | 0 | std::string bitmap_data(v.getSizeInBytes(), '\0'); |
1205 | 0 | v.write(bitmap_data.data()); |
1206 | 0 | ret.mutable_segment_delete_bitmaps()->Add(std::move(bitmap_data)); |
1207 | 0 | } |
1208 | 0 | return ret; |
1209 | 0 | } |
1210 | | |
1211 | 7 | DeleteBitmap DeleteBitmap::snapshot() const { |
1212 | 7 | std::shared_lock l(lock); |
1213 | 7 | return DeleteBitmap(*this); |
1214 | 7 | } |
1215 | | |
1216 | 3 | DeleteBitmap DeleteBitmap::snapshot(Version version) const { |
1217 | | // Take snapshot first, then remove keys greater than given version. |
1218 | 3 | DeleteBitmap snapshot = this->snapshot(); |
1219 | 3 | auto it = snapshot.delete_bitmap.begin(); |
1220 | 412 | while (it != snapshot.delete_bitmap.end()) { Branch (1220:12): [True: 409, False: 3]
|
1221 | 409 | if (std::get<2>(it->first) > version) { Branch (1221:13): [True: 4, False: 405]
|
1222 | 4 | it = snapshot.delete_bitmap.erase(it); |
1223 | 405 | } else { |
1224 | 405 | it++; |
1225 | 405 | } |
1226 | 409 | } |
1227 | 3 | return snapshot; |
1228 | 3 | } |
1229 | | |
1230 | 459k | void DeleteBitmap::add(const BitmapKey& bmk, uint32_t row_id) { |
1231 | 459k | std::lock_guard l(lock); |
1232 | 459k | delete_bitmap[bmk].add(row_id); |
1233 | 459k | } |
1234 | | |
1235 | 0 | int DeleteBitmap::remove(const BitmapKey& bmk, uint32_t row_id) { |
1236 | 0 | std::lock_guard l(lock); |
1237 | 0 | auto it = delete_bitmap.find(bmk); |
1238 | 0 | if (it == delete_bitmap.end()) return -1; Branch (1238:9): [True: 0, False: 0]
|
1239 | 0 | it->second.remove(row_id); |
1240 | 0 | return 0; |
1241 | 0 | } |
1242 | | |
1243 | 8 | void DeleteBitmap::remove(const BitmapKey& start, const BitmapKey& end) { |
1244 | 8 | std::lock_guard l(lock); |
1245 | 107 | for (auto it = delete_bitmap.lower_bound(start); it != delete_bitmap.end();) { Branch (1245:54): [True: 101, False: 6]
|
1246 | 101 | auto& [k, _] = *it; |
1247 | 101 | if (k >= end) { Branch (1247:13): [True: 2, False: 99]
|
1248 | 2 | break; |
1249 | 2 | } |
1250 | 99 | it = delete_bitmap.erase(it); |
1251 | 99 | } |
1252 | 8 | } |
1253 | | |
1254 | 0 | void DeleteBitmap::remove(const std::vector<std::tuple<BitmapKey, BitmapKey>>& key_ranges) { |
1255 | 0 | std::lock_guard l(lock); |
1256 | 0 | for (auto& [start, end] : key_ranges) { Branch (1256:29): [True: 0, False: 0]
|
1257 | 0 | for (auto it = delete_bitmap.lower_bound(start); it != delete_bitmap.end();) { Branch (1257:58): [True: 0, False: 0]
|
1258 | 0 | auto& [k, _] = *it; |
1259 | 0 | if (k >= end) { Branch (1259:17): [True: 0, False: 0]
|
1260 | 0 | break; |
1261 | 0 | } |
1262 | 0 | it = delete_bitmap.erase(it); |
1263 | 0 | } |
1264 | 0 | } |
1265 | 0 | } |
1266 | | |
1267 | 6 | bool DeleteBitmap::contains(const BitmapKey& bmk, uint32_t row_id) const { |
1268 | 6 | std::shared_lock l(lock); |
1269 | 6 | auto it = delete_bitmap.find(bmk); |
1270 | 6 | return it != delete_bitmap.end() && it->second.contains(row_id); Branch (1270:12): [True: 4, False: 2]
Branch (1270:41): [True: 3, False: 1]
|
1271 | 6 | } |
1272 | | |
1273 | 2 | bool DeleteBitmap::contains_agg(const BitmapKey& bmk, uint32_t row_id) const { |
1274 | 2 | return get_agg(bmk)->contains(row_id); |
1275 | 2 | } |
1276 | | |
1277 | 0 | bool DeleteBitmap::empty() const { |
1278 | 0 | std::shared_lock l(lock); |
1279 | 0 | return delete_bitmap.empty(); |
1280 | 0 | } |
1281 | | |
1282 | 63 | uint64_t DeleteBitmap::cardinality() const { |
1283 | 63 | std::shared_lock l(lock); |
1284 | 63 | uint64_t res = 0; |
1285 | 314 | for (auto entry : delete_bitmap) { Branch (1285:21): [True: 314, False: 63]
|
1286 | 314 | res += entry.second.cardinality(); |
1287 | 314 | } |
1288 | 63 | return res; |
1289 | 63 | } |
1290 | | |
1291 | 0 | uint64_t DeleteBitmap::get_size() const { |
1292 | 0 | std::shared_lock l(lock); |
1293 | 0 | uint64_t charge = 0; |
1294 | 0 | for (auto& [k, v] : delete_bitmap) { Branch (1294:23): [True: 0, False: 0]
|
1295 | 0 | charge += v.getSizeInBytes(); |
1296 | 0 | } |
1297 | 0 | return charge; |
1298 | 0 | } |
1299 | | |
1300 | 1 | bool DeleteBitmap::contains_agg_without_cache(const BitmapKey& bmk, uint32_t row_id) const { |
1301 | 1 | std::shared_lock l(lock); |
1302 | 1 | DeleteBitmap::BitmapKey start {std::get<0>(bmk), std::get<1>(bmk), 0}; |
1303 | 1 | for (auto it = delete_bitmap.lower_bound(start); it != delete_bitmap.end(); ++it) { Branch (1303:54): [True: 0, False: 1]
|
1304 | 0 | auto& [k, bm] = *it; |
1305 | 0 | if (std::get<0>(k) != std::get<0>(bmk) || std::get<1>(k) != std::get<1>(bmk) || Branch (1305:13): [True: 0, False: 0]
Branch (1305:51): [True: 0, False: 0]
|
1306 | 0 | std::get<2>(k) > std::get<2>(bmk)) { Branch (1306:13): [True: 0, False: 0]
|
1307 | 0 | break; |
1308 | 0 | } |
1309 | 0 | if (bm.contains(row_id)) { Branch (1309:13): [True: 0, False: 0]
|
1310 | 0 | return true; |
1311 | 0 | } |
1312 | 0 | } |
1313 | 1 | return false; |
1314 | 1 | } |
1315 | | |
1316 | 0 | void DeleteBitmap::remove_sentinel_marks() { |
1317 | 0 | std::lock_guard l(lock); |
1318 | 0 | for (auto it = delete_bitmap.begin(), end = delete_bitmap.end(); it != end;) { Branch (1318:70): [True: 0, False: 0]
|
1319 | 0 | if (std::get<1>(it->first) == DeleteBitmap::INVALID_SEGMENT_ID) { Branch (1319:13): [True: 0, False: 0]
|
1320 | 0 | it = delete_bitmap.erase(it); |
1321 | 0 | } else { |
1322 | 0 | ++it; |
1323 | 0 | } |
1324 | 0 | } |
1325 | 0 | } |
1326 | | |
1327 | 38 | int DeleteBitmap::set(const BitmapKey& bmk, const roaring::Roaring& segment_delete_bitmap) { |
1328 | 38 | std::lock_guard l(lock); |
1329 | 38 | auto [_, inserted] = delete_bitmap.insert_or_assign(bmk, segment_delete_bitmap); |
1330 | 38 | return inserted; |
1331 | 38 | } |
1332 | | |
1333 | 3 | int DeleteBitmap::get(const BitmapKey& bmk, roaring::Roaring* segment_delete_bitmap) const { |
1334 | 3 | std::shared_lock l(lock); |
1335 | 3 | auto it = delete_bitmap.find(bmk); |
1336 | 3 | if (it == delete_bitmap.end()) return -1; Branch (1336:9): [True: 0, False: 3]
|
1337 | 3 | *segment_delete_bitmap = it->second; // copy |
1338 | 3 | return 0; |
1339 | 3 | } |
1340 | | |
1341 | 54 | const roaring::Roaring* DeleteBitmap::get(const BitmapKey& bmk) const { |
1342 | 54 | std::shared_lock l(lock); |
1343 | 54 | auto it = delete_bitmap.find(bmk); |
1344 | 54 | if (it == delete_bitmap.end()) return nullptr; Branch (1344:9): [True: 13, False: 41]
|
1345 | 41 | return &(it->second); // get address |
1346 | 54 | } |
1347 | | |
1348 | | void DeleteBitmap::subset(const BitmapKey& start, const BitmapKey& end, |
1349 | 3 | DeleteBitmap* subset_rowset_map) const { |
1350 | 3 | roaring::Roaring roaring; |
1351 | 3 | DCHECK(start < end); |
1352 | 3 | std::shared_lock l(lock); |
1353 | 26 | for (auto it = delete_bitmap.lower_bound(start); it != delete_bitmap.end(); ++it) { Branch (1353:54): [True: 25, False: 1]
|
1354 | 25 | auto& [k, bm] = *it; |
1355 | 25 | if (k >= end) { Branch (1355:13): [True: 2, False: 23]
|
1356 | 2 | break; |
1357 | 2 | } |
1358 | 23 | subset_rowset_map->set(k, bm); |
1359 | 23 | } |
1360 | 3 | } |
1361 | | |
1362 | 0 | size_t DeleteBitmap::get_count_with_range(const BitmapKey& start, const BitmapKey& end) const { |
1363 | 0 | DCHECK(start < end); |
1364 | 0 | size_t count = 0; |
1365 | 0 | std::shared_lock l(lock); |
1366 | 0 | for (auto it = delete_bitmap.lower_bound(start); it != delete_bitmap.end(); ++it) { Branch (1366:54): [True: 0, False: 0]
|
1367 | 0 | auto& [k, bm] = *it; |
1368 | 0 | if (k >= end) { Branch (1368:13): [True: 0, False: 0]
|
1369 | 0 | break; |
1370 | 0 | } |
1371 | 0 | count++; |
1372 | 0 | } |
1373 | 0 | return count; |
1374 | 0 | } |
1375 | | |
1376 | 2 | void DeleteBitmap::merge(const BitmapKey& bmk, const roaring::Roaring& segment_delete_bitmap) { |
1377 | 2 | std::lock_guard l(lock); |
1378 | 2 | auto [iter, succ] = delete_bitmap.emplace(bmk, segment_delete_bitmap); |
1379 | 2 | if (!succ) { Branch (1379:9): [True: 0, False: 2]
|
1380 | 0 | iter->second |= segment_delete_bitmap; |
1381 | 0 | } |
1382 | 2 | } |
1383 | | |
1384 | 9 | void DeleteBitmap::merge(const DeleteBitmap& other) { |
1385 | 9 | std::lock_guard l(lock); |
1386 | 29 | for (auto& i : other.delete_bitmap) { Branch (1386:18): [True: 29, False: 9]
|
1387 | 29 | auto [j, succ] = this->delete_bitmap.insert(i); |
1388 | 29 | if (!succ) j->second |= i.second; Branch (1388:13): [True: 2, False: 27]
|
1389 | 29 | } |
1390 | 9 | } |
1391 | | |
1392 | 63 | uint64_t DeleteBitmap::get_delete_bitmap_count() { |
1393 | 63 | std::shared_lock l(lock); |
1394 | 63 | uint64_t count = 0; |
1395 | 377 | for (auto it = delete_bitmap.begin(); it != delete_bitmap.end(); it++) { Branch (1395:43): [True: 314, False: 63]
|
1396 | 314 | if (std::get<1>(it->first) != DeleteBitmap::INVALID_SEGMENT_ID) { Branch (1396:13): [True: 314, False: 0]
|
1397 | 314 | count++; |
1398 | 314 | } |
1399 | 314 | } |
1400 | 63 | return count; |
1401 | 63 | } |
1402 | | |
1403 | | void DeleteBitmap::traverse_rowset_and_version( |
1404 | 0 | const std::function<int(const RowsetId& rowsetId, int64_t version)>& func) const { |
1405 | 0 | std::shared_lock l(lock); |
1406 | 0 | auto it = delete_bitmap.cbegin(); |
1407 | 0 | while (it != delete_bitmap.cend()) { Branch (1407:12): [True: 0, False: 0]
|
1408 | 0 | RowsetId rowset_id = std::get<0>(it->first); |
1409 | 0 | int64_t version = std::get<2>(it->first); |
1410 | 0 | int result = func(rowset_id, version); |
1411 | 0 | if (result == -2) { Branch (1411:13): [True: 0, False: 0]
|
1412 | | // find next <rowset, version> |
1413 | 0 | it++; |
1414 | 0 | } else { |
1415 | | // find next <rowset> |
1416 | 0 | it = delete_bitmap.upper_bound({rowset_id, std::numeric_limits<SegmentId>::max(), |
1417 | 0 | std::numeric_limits<Version>::max()}); |
1418 | 0 | } |
1419 | 0 | } |
1420 | 0 | } |
1421 | | |
1422 | 0 | bool DeleteBitmap::has_calculated_for_multi_segments(const RowsetId& rowset_id) const { |
1423 | 0 | return contains({rowset_id, INVALID_SEGMENT_ID, TEMP_VERSION_COMMON}, ROWSET_SENTINEL_MARK); |
1424 | 0 | } |
1425 | | |
1426 | 1 | size_t DeleteBitmap::remove_rowset_cache_version(const RowsetId& rowset_id) { |
1427 | 1 | std::lock_guard l(_rowset_cache_version_lock); |
1428 | 1 | _rowset_cache_version.erase(rowset_id); |
1429 | 1 | VLOG_DEBUG << "remove agg cache version for tablet=" << _tablet_id Line | Count | Source | 41 | 0 | #define VLOG_DEBUG VLOG(7) |
|
1430 | 0 | << ", rowset=" << rowset_id.to_string(); |
1431 | 1 | return _rowset_cache_version.size(); |
1432 | 1 | } |
1433 | | |
1434 | 0 | void DeleteBitmap::clear_rowset_cache_version() { |
1435 | 0 | std::lock_guard l(_rowset_cache_version_lock); |
1436 | 0 | _rowset_cache_version.clear(); |
1437 | 0 | VLOG_DEBUG << "clear agg cache version for tablet=" << _tablet_id; Line | Count | Source | 41 | 0 | #define VLOG_DEBUG VLOG(7) |
|
1438 | 0 | } |
1439 | | |
1440 | 0 | std::set<RowsetId> DeleteBitmap::get_rowset_cache_version() { |
1441 | 0 | std::set<RowsetId> set; |
1442 | 0 | std::shared_lock l(_rowset_cache_version_lock); |
1443 | 0 | for (auto& [k, _] : _rowset_cache_version) { Branch (1443:23): [True: 0, False: 0]
|
1444 | 0 | set.insert(k); |
1445 | 0 | } |
1446 | 0 | return set; |
1447 | 0 | } |
1448 | | |
1449 | 38 | DeleteBitmap::Version DeleteBitmap::_get_rowset_cache_version(const BitmapKey& bmk) const { |
1450 | 38 | std::shared_lock l(_rowset_cache_version_lock); |
1451 | 38 | if (auto it = _rowset_cache_version.find(std::get<0>(bmk)); it != _rowset_cache_version.end()) { Branch (1451:65): [True: 30, False: 8]
|
1452 | 30 | auto& segment_cache_version = it->second; |
1453 | 30 | if (auto it1 = segment_cache_version.find(std::get<1>(bmk)); |
1454 | 30 | it1 != segment_cache_version.end()) { Branch (1454:13): [True: 1, False: 29]
|
1455 | 1 | return it1->second; |
1456 | 1 | } |
1457 | 30 | } |
1458 | 37 | return 0; |
1459 | 38 | } |
1460 | | |
1461 | | // We cannot just copy the underlying memory to construct a string |
1462 | | // due to equivalent objects may have different padding bytes. |
1463 | | // Reading padding bytes is undefined behavior, neither copy nor |
1464 | | // placement new will help simplify the code. |
1465 | | // Refer to C11 standards §6.2.6.1/6 and §6.7.9/21 for more info. |
1466 | 45 | static std::string agg_cache_key(int64_t tablet_id, const DeleteBitmap::BitmapKey& bmk) { |
1467 | 45 | std::string ret(sizeof(tablet_id) + sizeof(bmk), '\0'); |
1468 | 45 | *reinterpret_cast<int64_t*>(ret.data()) = tablet_id; |
1469 | 45 | auto t = reinterpret_cast<DeleteBitmap::BitmapKey*>(ret.data() + sizeof(tablet_id)); |
1470 | 45 | std::get<RowsetId>(*t).version = std::get<RowsetId>(bmk).version; |
1471 | 45 | std::get<RowsetId>(*t).hi = std::get<RowsetId>(bmk).hi; |
1472 | 45 | std::get<RowsetId>(*t).mi = std::get<RowsetId>(bmk).mi; |
1473 | 45 | std::get<RowsetId>(*t).lo = std::get<RowsetId>(bmk).lo; |
1474 | 45 | std::get<1>(*t) = std::get<1>(bmk); |
1475 | 45 | std::get<2>(*t) = std::get<2>(bmk); |
1476 | 45 | return ret; |
1477 | 45 | } |
1478 | | |
1479 | 44 | std::shared_ptr<roaring::Roaring> DeleteBitmap::get_agg(const BitmapKey& bmk) const { |
1480 | 44 | std::string key_str = agg_cache_key(_tablet_id, bmk); // Cache key container |
1481 | 44 | CacheKey key(key_str); |
1482 | 44 | Cache::Handle* handle = DeleteBitmapAggCache::instance()->lookup(key); |
1483 | | |
1484 | 44 | DeleteBitmapAggCache::Value* val = |
1485 | 44 | handle == nullptr ? nullptr Branch (1485:13): [True: 38, False: 6]
|
1486 | 44 | : reinterpret_cast<DeleteBitmapAggCache::Value*>( |
1487 | 6 | DeleteBitmapAggCache::instance()->value(handle)); |
1488 | | // FIXME: do we need a mutex here to get rid of duplicated initializations |
1489 | | // of cache entries in some cases? |
1490 | 44 | if (val == nullptr) { // Renew if needed, put a new Value to cache Branch (1490:9): [True: 38, False: 6]
|
1491 | 38 | val = new DeleteBitmapAggCache::Value(); |
1492 | 38 | Version start_version = |
1493 | 38 | config::enable_mow_get_agg_by_cache ? _get_rowset_cache_version(bmk) : 0; Branch (1493:17): [True: 38, False: 0]
|
1494 | 38 | if (start_version > 0) { Branch (1494:13): [True: 1, False: 37]
|
1495 | 1 | Cache::Handle* handle2 = DeleteBitmapAggCache::instance()->lookup( |
1496 | 1 | agg_cache_key(_tablet_id, {std::get<0>(bmk), std::get<1>(bmk), start_version})); |
1497 | | |
1498 | 1 | DBUG_EXECUTE_IF("DeleteBitmap::get_agg.cache_miss", { Line | Count | Source | 37 | 1 | if (UNLIKELY(config::enable_debug_points)) { \ | 38 | 0 | auto dp = DebugPoints::instance()->get_debug_point(debug_point_name); \ | 39 | 0 | if (dp) { \ Branch (39:13): [True: 0, False: 0]
| 40 | 0 | [[maybe_unused]] auto DP_NAME = debug_point_name; \ | 41 | 0 | { code; } \ Branch (41:15): [True: 0, False: 0]
Branch (41:15): [True: 0, False: 0]
| 42 | 0 | } \ | 43 | 0 | } |
|
1499 | 1 | if (handle2 != nullptr) { |
1500 | 1 | auto p = dp->param("percent", 0.3); |
1501 | 1 | std::mt19937 gen {std::random_device {}()}; |
1502 | 1 | std::bernoulli_distribution inject_fault {p}; |
1503 | 1 | if (inject_fault(gen)) { |
1504 | 1 | LOG_INFO("injection DeleteBitmap::get_agg.cache_miss, tablet_id={}", |
1505 | 1 | _tablet_id); |
1506 | 1 | handle2 = nullptr; |
1507 | 1 | } |
1508 | 1 | } |
1509 | 1 | }); |
1510 | 1 | if (handle2 == nullptr || start_version > std::get<2>(bmk)) { Branch (1510:17): [True: 0, False: 1]
Branch (1510:39): [True: 0, False: 1]
|
1511 | 0 | start_version = 0; |
1512 | 1 | } else { |
1513 | 1 | val->bitmap |= reinterpret_cast<DeleteBitmapAggCache::Value*>( |
1514 | 1 | DeleteBitmapAggCache::instance()->value(handle2)) |
1515 | 1 | ->bitmap; |
1516 | 1 | VLOG_DEBUG << "get agg cache version=" << start_version Line | Count | Source | 41 | 0 | #define VLOG_DEBUG VLOG(7) |
|
1517 | 0 | << " for tablet=" << _tablet_id |
1518 | 0 | << ", rowset=" << std::get<0>(bmk).to_string() |
1519 | 0 | << ", segment=" << std::get<1>(bmk); |
1520 | 1 | start_version += 1; |
1521 | 1 | } |
1522 | 1 | if (handle2 != nullptr) { Branch (1522:17): [True: 1, False: 0]
|
1523 | 1 | DeleteBitmapAggCache::instance()->release(handle2); |
1524 | 1 | } |
1525 | 1 | } |
1526 | 38 | { |
1527 | 38 | std::shared_lock l(lock); |
1528 | 38 | DeleteBitmap::BitmapKey start {std::get<0>(bmk), std::get<1>(bmk), start_version}; |
1529 | 66 | for (auto it = delete_bitmap.lower_bound(start); it != delete_bitmap.end(); ++it) { Branch (1529:62): [True: 63, False: 3]
|
1530 | 63 | auto& [k, bm] = *it; |
1531 | 63 | if (std::get<0>(k) != std::get<0>(bmk) || std::get<1>(k) != std::get<1>(bmk) || Branch (1531:21): [True: 1, False: 62]
Branch (1531:59): [True: 34, False: 28]
|
1532 | 63 | std::get<2>(k) > std::get<2>(bmk)) { Branch (1532:21): [True: 0, False: 28]
|
1533 | 35 | break; |
1534 | 35 | } |
1535 | 28 | val->bitmap |= bm; |
1536 | 28 | } |
1537 | 38 | } |
1538 | 38 | size_t charge = val->bitmap.getSizeInBytes() + sizeof(DeleteBitmapAggCache::Value); |
1539 | 38 | handle = DeleteBitmapAggCache::instance()->insert(key, val, charge, charge, |
1540 | 38 | CachePriority::NORMAL); |
1541 | 38 | if (config::enable_mow_get_agg_by_cache && !val->bitmap.isEmpty()) { Branch (1541:13): [True: 38, False: 0]
Branch (1541:52): [True: 27, False: 11]
|
1542 | 27 | std::lock_guard l(_rowset_cache_version_lock); |
1543 | | // this version is already agg |
1544 | 27 | _rowset_cache_version[std::get<0>(bmk)][std::get<1>(bmk)] = std::get<2>(bmk); |
1545 | 27 | VLOG_DEBUG << "set agg cache version=" << std::get<2>(bmk) Line | Count | Source | 41 | 0 | #define VLOG_DEBUG VLOG(7) |
|
1546 | 0 | << " for tablet=" << _tablet_id |
1547 | 0 | << ", rowset=" << std::get<0>(bmk).to_string() |
1548 | 0 | << ", segment=" << std::get<1>(bmk); |
1549 | 27 | } |
1550 | 38 | if (start_version > 0 && config::enable_mow_get_agg_correctness_check_core) { Branch (1550:13): [True: 1, False: 37]
Branch (1550:34): [True: 0, False: 1]
|
1551 | 0 | std::shared_ptr<roaring::Roaring> bitmap = get_agg_without_cache(bmk); |
1552 | 0 | if (val->bitmap != *bitmap) { Branch (1552:17): [True: 0, False: 0]
|
1553 | 0 | CHECK(false) << ". get agg correctness check failed for tablet=" << _tablet_id |
1554 | 0 | << ", rowset=" << std::get<0>(bmk).to_string() |
1555 | 0 | << ", segment=" << std::get<1>(bmk) << ", version=" << std::get<2>(bmk) |
1556 | 0 | << ". start_version from cache=" << start_version |
1557 | 0 | << ", delete_bitmap cardinality with cache=" |
1558 | 0 | << val->bitmap.cardinality() |
1559 | 0 | << ", delete_bitmap cardinality without cache=" |
1560 | 0 | << bitmap->cardinality(); |
1561 | 0 | } |
1562 | 0 | } |
1563 | 38 | } |
1564 | | |
1565 | | // It is natural for the cache to reclaim the underlying memory |
1566 | 44 | return std::shared_ptr<roaring::Roaring>( |
1567 | 44 | &val->bitmap, [handle](...) { DeleteBitmapAggCache::instance()->release(handle); }); |
1568 | 44 | } |
1569 | | |
1570 | | std::shared_ptr<roaring::Roaring> DeleteBitmap::get_agg_without_cache( |
1571 | 0 | const BitmapKey& bmk, const int64_t start_version) const { |
1572 | 0 | std::shared_ptr<roaring::Roaring> bitmap = std::make_shared<roaring::Roaring>(); |
1573 | 0 | std::shared_lock l(lock); |
1574 | 0 | DeleteBitmap::BitmapKey start {std::get<0>(bmk), std::get<1>(bmk), start_version}; |
1575 | 0 | for (auto it = delete_bitmap.lower_bound(start); it != delete_bitmap.end(); ++it) { Branch (1575:54): [True: 0, False: 0]
|
1576 | 0 | auto& [k, bm] = *it; |
1577 | 0 | if (std::get<0>(k) != std::get<0>(bmk) || std::get<1>(k) != std::get<1>(bmk) || Branch (1577:13): [True: 0, False: 0]
Branch (1577:51): [True: 0, False: 0]
|
1578 | 0 | std::get<2>(k) > std::get<2>(bmk)) { Branch (1578:13): [True: 0, False: 0]
|
1579 | 0 | break; |
1580 | 0 | } |
1581 | 0 | *bitmap |= bm; |
1582 | 0 | } |
1583 | 0 | return bitmap; |
1584 | 0 | } |
1585 | | |
1586 | 0 | DeleteBitmap DeleteBitmap::diffset(const std::set<BitmapKey>& key_set) const { |
1587 | 0 | std::shared_lock l(lock); |
1588 | 0 | auto diff_key_set_view = |
1589 | 0 | delete_bitmap | std::ranges::views::transform([](const auto& kv) { return kv.first; }) | |
1590 | 0 | std::ranges::views::filter( |
1591 | 0 | [&key_set](const auto& key) { return !key_set.contains(key); }); |
1592 | |
|
1593 | 0 | DeleteBitmap dbm(_tablet_id); |
1594 | 0 | for (const auto& key : diff_key_set_view) { Branch (1594:26): [True: 0, False: 0]
|
1595 | 0 | const auto* bitmap = get(key); |
1596 | 0 | DCHECK_NE(bitmap, nullptr); |
1597 | 0 | dbm.delete_bitmap[key] = *bitmap; |
1598 | 0 | } |
1599 | 0 | return dbm; |
1600 | 0 | } |
1601 | | |
1602 | 0 | std::string tablet_state_name(TabletState state) { |
1603 | 0 | switch (state) { |
1604 | 0 | case TABLET_NOTREADY: Branch (1604:5): [True: 0, False: 0]
|
1605 | 0 | return "TABLET_NOTREADY"; |
1606 | | |
1607 | 0 | case TABLET_RUNNING: Branch (1607:5): [True: 0, False: 0]
|
1608 | 0 | return "TABLET_RUNNING"; |
1609 | | |
1610 | 0 | case TABLET_TOMBSTONED: Branch (1610:5): [True: 0, False: 0]
|
1611 | 0 | return "TABLET_TOMBSTONED"; |
1612 | | |
1613 | 0 | case TABLET_STOPPED: Branch (1613:5): [True: 0, False: 0]
|
1614 | 0 | return "TABLET_STOPPED"; |
1615 | | |
1616 | 0 | case TABLET_SHUTDOWN: Branch (1616:5): [True: 0, False: 0]
|
1617 | 0 | return "TABLET_SHUTDOWN"; |
1618 | | |
1619 | 0 | default: Branch (1619:5): [True: 0, False: 0]
|
1620 | 0 | return "TabletState(" + std::to_string(state) + ")"; |
1621 | 0 | } |
1622 | 0 | } |
1623 | | |
1624 | | #include "common/compile_check_end.h" |
1625 | | } // namespace doris |