/root/doris/be/src/olap/tablet_meta.h
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 | | #pragma once |
19 | | |
20 | | #include <gen_cpp/AgentService_types.h> |
21 | | #include <gen_cpp/olap_file.pb.h> |
22 | | #include <stdint.h> |
23 | | |
24 | | #include <atomic> |
25 | | #include <cstddef> |
26 | | #include <limits> |
27 | | #include <map> |
28 | | #include <memory> |
29 | | #include <mutex> |
30 | | #include <optional> |
31 | | #include <ostream> |
32 | | #include <roaring/roaring.hh> |
33 | | #include <shared_mutex> |
34 | | #include <string> |
35 | | #include <tuple> |
36 | | #include <unordered_map> |
37 | | #include <utility> |
38 | | #include <vector> |
39 | | |
40 | | #include "common/logging.h" |
41 | | #include "common/status.h" |
42 | | #include "gutil/stringprintf.h" |
43 | | #include "io/fs/file_system.h" |
44 | | #include "olap/binlog_config.h" |
45 | | #include "olap/lru_cache.h" |
46 | | #include "olap/metadata_adder.h" |
47 | | #include "olap/olap_common.h" |
48 | | #include "olap/rowset/rowset_meta.h" |
49 | | #include "olap/tablet_schema.h" |
50 | | #include "runtime/memory/lru_cache_policy.h" |
51 | | #include "util/uid_util.h" |
52 | | |
53 | | namespace json2pb { |
54 | | #include "common/compile_check_begin.h" |
55 | | struct Pb2JsonOptions; |
56 | | } // namespace json2pb |
57 | | |
58 | | namespace doris { |
59 | | class TColumn; |
60 | | |
61 | | // Lifecycle states that a Tablet can be in. Legal state transitions for a |
62 | | // Tablet object: |
63 | | // |
64 | | // NOTREADY -> RUNNING -> TOMBSTONED -> STOPPED -> SHUTDOWN |
65 | | // | | | ^^^ |
66 | | // | | +----------++| |
67 | | // | +------------------------+| |
68 | | // +-------------------------------------+ |
69 | | |
70 | | enum TabletState { |
71 | | // Tablet is under alter table, rollup, clone |
72 | | TABLET_NOTREADY, |
73 | | |
74 | | TABLET_RUNNING, |
75 | | |
76 | | // Tablet integrity has been violated, such as missing versions. |
77 | | // In this state, tablet will not accept any incoming request. |
78 | | // Report this state to FE, scheduling BE to drop tablet. |
79 | | TABLET_TOMBSTONED, |
80 | | |
81 | | // Tablet is shutting down, files in disk still remained. |
82 | | TABLET_STOPPED, |
83 | | |
84 | | // Files have been removed, tablet has been shutdown completely. |
85 | | TABLET_SHUTDOWN |
86 | | }; |
87 | | |
88 | | class DataDir; |
89 | | class TabletMeta; |
90 | | class DeleteBitmap; |
91 | | class TBinlogConfig; |
92 | | |
93 | | // Class encapsulates meta of tablet. |
94 | | // The concurrency control is handled in Tablet Class, not in this class. |
95 | | class TabletMeta : public MetadataAdder<TabletMeta> { |
96 | | public: |
97 | | static TabletMetaSharedPtr create( |
98 | | const TCreateTabletReq& request, const TabletUid& tablet_uid, uint64_t shard_id, |
99 | | uint32_t next_unique_id, |
100 | | const std::unordered_map<uint32_t, uint32_t>& col_ordinal_to_unique_id); |
101 | | |
102 | | TabletMeta(); |
103 | | ~TabletMeta() override; |
104 | | TabletMeta(int64_t table_id, int64_t partition_id, int64_t tablet_id, int64_t replica_id, |
105 | | int32_t schema_hash, int32_t shard_id, const TTabletSchema& tablet_schema, |
106 | | uint32_t next_unique_id, |
107 | | const std::unordered_map<uint32_t, uint32_t>& col_ordinal_to_unique_id, |
108 | | TabletUid tablet_uid, TTabletType::type tabletType, |
109 | | TCompressionType::type compression_type, int64_t storage_policy_id = 0, |
110 | | bool enable_unique_key_merge_on_write = false, |
111 | | std::optional<TBinlogConfig> binlog_config = {}, |
112 | | std::string compaction_policy = "size_based", |
113 | | int64_t time_series_compaction_goal_size_mbytes = 1024, |
114 | | int64_t time_series_compaction_file_count_threshold = 2000, |
115 | | int64_t time_series_compaction_time_threshold_seconds = 3600, |
116 | | int64_t time_series_compaction_empty_rowsets_threshold = 5, |
117 | | int64_t time_series_compaction_level_threshold = 1, |
118 | | TInvertedIndexFileStorageFormat::type inverted_index_file_storage_format = |
119 | | TInvertedIndexFileStorageFormat::V2); |
120 | | // If need add a filed in TableMeta, filed init copy in copy construct function |
121 | | TabletMeta(const TabletMeta& tablet_meta); |
122 | | TabletMeta(TabletMeta&& tablet_meta) = delete; |
123 | | |
124 | | // UT |
125 | | #ifdef BE_TEST |
126 | 25 | TabletMeta(TabletSchemaSPtr tablet_schema) : _schema(tablet_schema) {} |
127 | | #endif |
128 | | |
129 | | // Function create_from_file is used to be compatible with previous tablet_meta. |
130 | | // Previous tablet_meta is a physical file in tablet dir, which is not stored in rocksdb. |
131 | | Status create_from_file(const std::string& file_path); |
132 | | static Status load_from_file(const std::string& file_path, TabletMetaPB* tablet_meta_pb); |
133 | | Status save(const std::string& file_path); |
134 | | Status save_as_json(const string& file_path); |
135 | | static Status save(const std::string& file_path, const TabletMetaPB& tablet_meta_pb); |
136 | | static std::string construct_header_file_path(const std::string& schema_hash_path, |
137 | | int64_t tablet_id); |
138 | | Status save_meta(DataDir* data_dir); |
139 | | |
140 | | void serialize(std::string* meta_binary); |
141 | | Status deserialize(std::string_view meta_binary); |
142 | | void init_from_pb(const TabletMetaPB& tablet_meta_pb); |
143 | | |
144 | | void to_meta_pb(TabletMetaPB* tablet_meta_pb); |
145 | | void to_json(std::string* json_string, json2pb::Pb2JsonOptions& options); |
146 | 559 | size_t tablet_columns_num() const { return _schema->num_columns(); } |
147 | | |
148 | 0 | TabletTypePB tablet_type() const { return _tablet_type; } |
149 | | TabletUid tablet_uid() const; |
150 | 32 | void set_tablet_uid(TabletUid uid) { _tablet_uid = uid; } |
151 | | int64_t table_id() const; |
152 | | int64_t index_id() const; |
153 | | int64_t partition_id() const; |
154 | | int64_t tablet_id() const; |
155 | | int64_t replica_id() const; |
156 | 0 | void set_replica_id(int64_t replica_id) { _replica_id = replica_id; } |
157 | | int32_t schema_hash() const; |
158 | | int32_t shard_id() const; |
159 | | void set_shard_id(int32_t shard_id); |
160 | | int64_t creation_time() const; |
161 | | void set_creation_time(int64_t creation_time); |
162 | | int64_t cumulative_layer_point() const; |
163 | | void set_cumulative_layer_point(int64_t new_point); |
164 | | |
165 | | size_t num_rows() const; |
166 | | // Disk space occupied by tablet, contain local and remote. |
167 | | size_t tablet_footprint() const; |
168 | | // Local disk space occupied by tablet. |
169 | | size_t tablet_local_size() const; |
170 | | // Remote disk space occupied by tablet. |
171 | | size_t tablet_remote_size() const; |
172 | | |
173 | | size_t tablet_local_index_size() const; |
174 | | size_t tablet_local_segment_size() const; |
175 | | size_t tablet_remote_index_size() const; |
176 | | size_t tablet_remote_segment_size() const; |
177 | | |
178 | | size_t version_count() const; |
179 | | size_t stale_version_count() const; |
180 | | size_t version_count_cross_with_range(const Version& range) const; |
181 | | Version max_version() const; |
182 | | |
183 | | TabletState tablet_state() const; |
184 | | void set_tablet_state(TabletState state); |
185 | | |
186 | | bool in_restore_mode() const; |
187 | | void set_in_restore_mode(bool in_restore_mode); |
188 | | |
189 | | const TabletSchemaSPtr& tablet_schema() const; |
190 | | |
191 | | TabletSchema* mutable_tablet_schema(); |
192 | | |
193 | | const std::vector<RowsetMetaSharedPtr>& all_rs_metas() const; |
194 | | std::vector<RowsetMetaSharedPtr>& all_mutable_rs_metas(); |
195 | | Status add_rs_meta(const RowsetMetaSharedPtr& rs_meta); |
196 | | void delete_rs_meta_by_version(const Version& version, |
197 | | std::vector<RowsetMetaSharedPtr>* deleted_rs_metas); |
198 | | // If same_version is true, the rowset in "to_delete" will not be added |
199 | | // to _stale_rs_meta, but to be deleted from rs_meta directly. |
200 | | void modify_rs_metas(const std::vector<RowsetMetaSharedPtr>& to_add, |
201 | | const std::vector<RowsetMetaSharedPtr>& to_delete, |
202 | | bool same_version = false); |
203 | | void revise_rs_metas(std::vector<RowsetMetaSharedPtr>&& rs_metas); |
204 | | void revise_delete_bitmap_unlocked(const DeleteBitmap& delete_bitmap); |
205 | | |
206 | | const std::vector<RowsetMetaSharedPtr>& all_stale_rs_metas() const; |
207 | | RowsetMetaSharedPtr acquire_rs_meta_by_version(const Version& version) const; |
208 | | void delete_stale_rs_meta_by_version(const Version& version); |
209 | | RowsetMetaSharedPtr acquire_stale_rs_meta_by_version(const Version& version) const; |
210 | | |
211 | | Status set_partition_id(int64_t partition_id); |
212 | | |
213 | 385 | RowsetTypePB preferred_rowset_type() const { return _preferred_rowset_type; } |
214 | | |
215 | 52 | void set_preferred_rowset_type(RowsetTypePB preferred_rowset_type) { |
216 | 52 | _preferred_rowset_type = preferred_rowset_type; |
217 | 52 | } |
218 | | |
219 | | // used for after tablet cloned to clear stale rowset |
220 | | void clear_stale_rowset(); |
221 | | |
222 | | void clear_rowsets(); |
223 | | |
224 | | // MUST hold EXCLUSIVE `_meta_lock` in belonged Tablet |
225 | | // `to_add` MUST NOT have overlapped version with `_rs_metas` in tablet meta. |
226 | | void add_rowsets_unchecked(const std::vector<RowsetSharedPtr>& to_add); |
227 | | |
228 | | bool all_beta() const; |
229 | | |
230 | 22 | int64_t storage_policy_id() const { return _storage_policy_id; } |
231 | | |
232 | 4 | void set_storage_policy_id(int64_t id) { |
233 | 4 | VLOG_NOTICE << "set tablet_id : " << _table_id << " storage policy from " |
234 | 0 | << _storage_policy_id << " to " << id; |
235 | 4 | _storage_policy_id = id; |
236 | 4 | } |
237 | | |
238 | 18 | UniqueId cooldown_meta_id() const { return _cooldown_meta_id; } |
239 | 5 | void set_cooldown_meta_id(UniqueId uid) { _cooldown_meta_id = uid; } |
240 | | |
241 | | static void init_column_from_tcolumn(uint32_t unique_id, const TColumn& tcolumn, |
242 | | ColumnPB* column); |
243 | | |
244 | 20 | std::shared_ptr<DeleteBitmap> delete_bitmap() { return _delete_bitmap; } |
245 | | void remove_rowset_delete_bitmap(const RowsetId& rowset_id, const Version& version); |
246 | | |
247 | 1.50k | bool enable_unique_key_merge_on_write() const { return _enable_unique_key_merge_on_write; } |
248 | | |
249 | | // TODO(Drogon): thread safety |
250 | 0 | const BinlogConfig& binlog_config() const { return _binlog_config; } |
251 | 0 | void set_binlog_config(BinlogConfig binlog_config) { |
252 | 0 | _binlog_config = std::move(binlog_config); |
253 | 0 | } |
254 | | |
255 | 12 | void set_compaction_policy(std::string compaction_policy) { |
256 | 12 | _compaction_policy = compaction_policy; |
257 | 12 | } |
258 | 1.63k | std::string compaction_policy() const { return _compaction_policy; } |
259 | 12 | void set_time_series_compaction_goal_size_mbytes(int64_t goal_size_mbytes) { |
260 | 12 | _time_series_compaction_goal_size_mbytes = goal_size_mbytes; |
261 | 12 | } |
262 | 818 | int64_t time_series_compaction_goal_size_mbytes() const { |
263 | 818 | return _time_series_compaction_goal_size_mbytes; |
264 | 818 | } |
265 | 12 | void set_time_series_compaction_file_count_threshold(int64_t file_count_threshold) { |
266 | 12 | _time_series_compaction_file_count_threshold = file_count_threshold; |
267 | 12 | } |
268 | 815 | int64_t time_series_compaction_file_count_threshold() const { |
269 | 815 | return _time_series_compaction_file_count_threshold; |
270 | 815 | } |
271 | 13 | void set_time_series_compaction_time_threshold_seconds(int64_t time_threshold) { |
272 | 13 | _time_series_compaction_time_threshold_seconds = time_threshold; |
273 | 13 | } |
274 | 815 | int64_t time_series_compaction_time_threshold_seconds() const { |
275 | 815 | return _time_series_compaction_time_threshold_seconds; |
276 | 815 | } |
277 | 0 | void set_time_series_compaction_empty_rowsets_threshold(int64_t empty_rowsets_threshold) { |
278 | 0 | _time_series_compaction_empty_rowsets_threshold = empty_rowsets_threshold; |
279 | 0 | } |
280 | 813 | int64_t time_series_compaction_empty_rowsets_threshold() const { |
281 | 813 | return _time_series_compaction_empty_rowsets_threshold; |
282 | 813 | } |
283 | 0 | void set_time_series_compaction_level_threshold(int64_t level_threshold) { |
284 | 0 | _time_series_compaction_level_threshold = level_threshold; |
285 | 0 | } |
286 | 836 | int64_t time_series_compaction_level_threshold() const { |
287 | 836 | return _time_series_compaction_level_threshold; |
288 | 836 | } |
289 | | |
290 | 331 | int64_t ttl_seconds() const { |
291 | 331 | std::shared_lock rlock(_meta_lock); |
292 | 331 | return _ttl_seconds; |
293 | 331 | } |
294 | | |
295 | 0 | void set_ttl_seconds(int64_t ttl_seconds) { |
296 | 0 | std::lock_guard wlock(_meta_lock); |
297 | 0 | _ttl_seconds = ttl_seconds; |
298 | 0 | } |
299 | | |
300 | 28 | int64_t avg_rs_meta_serialize_size() const { return _avg_rs_meta_serialize_size; } |
301 | | |
302 | | private: |
303 | | Status _save_meta(DataDir* data_dir); |
304 | | void _check_mow_rowset_cache_version_size(size_t rowset_cache_version_size); |
305 | | |
306 | | // _del_predicates is ignored to compare. |
307 | | friend bool operator==(const TabletMeta& a, const TabletMeta& b); |
308 | | friend bool operator!=(const TabletMeta& a, const TabletMeta& b); |
309 | | |
310 | | private: |
311 | | int64_t _table_id = 0; |
312 | | int64_t _index_id = 0; |
313 | | int64_t _partition_id = 0; |
314 | | int64_t _tablet_id = 0; |
315 | | int64_t _replica_id = 0; |
316 | | int32_t _schema_hash = 0; |
317 | | int32_t _shard_id = 0; |
318 | | int64_t _creation_time = 0; |
319 | | int64_t _cumulative_layer_point = 0; |
320 | | TabletUid _tablet_uid; |
321 | | TabletTypePB _tablet_type = TabletTypePB::TABLET_TYPE_DISK; |
322 | | |
323 | | TabletState _tablet_state = TABLET_NOTREADY; |
324 | | // the reference of _schema may use in tablet, so here need keep |
325 | | // the lifetime of tablemeta and _schema is same with tablet |
326 | | TabletSchemaSPtr _schema; |
327 | | Cache::Handle* _handle = nullptr; |
328 | | |
329 | | std::vector<RowsetMetaSharedPtr> _rs_metas; |
330 | | // This variable _stale_rs_metas is used to record these rowsets‘ meta which are be compacted. |
331 | | // These stale rowsets meta are been removed when rowsets' pathVersion is expired, |
332 | | // this policy is judged and computed by TimestampedVersionTracker. |
333 | | std::vector<RowsetMetaSharedPtr> _stale_rs_metas; |
334 | | bool _in_restore_mode = false; |
335 | | RowsetTypePB _preferred_rowset_type = BETA_ROWSET; |
336 | | |
337 | | // meta for cooldown |
338 | | int64_t _storage_policy_id = 0; // <= 0 means no storage policy |
339 | | UniqueId _cooldown_meta_id; |
340 | | |
341 | | // For unique key data model, the feature Merge-on-Write will leverage a primary |
342 | | // key index and a delete-bitmap to mark duplicate keys as deleted in load stage, |
343 | | // which can avoid the merging cost in read stage, and accelerate the aggregation |
344 | | // query performance significantly. |
345 | | bool _enable_unique_key_merge_on_write = false; |
346 | | std::shared_ptr<DeleteBitmap> _delete_bitmap; |
347 | | |
348 | | // binlog config |
349 | | BinlogConfig _binlog_config {}; |
350 | | |
351 | | // meta for compaction |
352 | | std::string _compaction_policy; |
353 | | int64_t _time_series_compaction_goal_size_mbytes = 0; |
354 | | int64_t _time_series_compaction_file_count_threshold = 0; |
355 | | int64_t _time_series_compaction_time_threshold_seconds = 0; |
356 | | int64_t _time_series_compaction_empty_rowsets_threshold = 0; |
357 | | int64_t _time_series_compaction_level_threshold = 0; |
358 | | |
359 | | int64_t _avg_rs_meta_serialize_size = 0; |
360 | | |
361 | | // cloud |
362 | | int64_t _ttl_seconds = 0; |
363 | | |
364 | | mutable std::shared_mutex _meta_lock; |
365 | | }; |
366 | | |
367 | | class DeleteBitmapAggCache : public LRUCachePolicy { |
368 | | public: |
369 | | DeleteBitmapAggCache(size_t capacity); |
370 | | |
371 | | static DeleteBitmapAggCache* instance(); |
372 | | |
373 | | static DeleteBitmapAggCache* create_instance(size_t capacity); |
374 | | |
375 | | class Value : public LRUCacheValueBase { |
376 | | public: |
377 | | roaring::Roaring bitmap; |
378 | | }; |
379 | | }; |
380 | | |
381 | | /** |
382 | | * Wraps multiple bitmaps for recording rows (row id) that are deleted or |
383 | | * overwritten. For now, it's only used when unique key merge-on-write property |
384 | | * enabled. |
385 | | * |
386 | | * RowsetId and SegmentId are for locating segment, Version here is a single |
387 | | * uint32_t means that at which "version" of the load causes the delete or |
388 | | * overwrite. |
389 | | * |
390 | | * The start and end version of a load is the same, it's ok and straightforward |
391 | | * to use a single uint32_t. |
392 | | * |
393 | | * e.g. |
394 | | * There is a key "key1" in rowset id 1, version [1,1], segment id 1, row id 1. |
395 | | * A new load also contains "key1", the rowset id 2, version [2,2], segment id 1 |
396 | | * the delete bitmap will be `{1,1,2} -> 1`, which means the "row id 1" in |
397 | | * "rowset id 1, segment id 1" is deleted/overitten by some loads at "version 2" |
398 | | */ |
399 | | class DeleteBitmap { |
400 | | public: |
401 | | mutable std::shared_mutex lock; |
402 | | using SegmentId = uint32_t; |
403 | | using Version = uint64_t; |
404 | | using BitmapKey = std::tuple<RowsetId, SegmentId, Version>; |
405 | | std::map<BitmapKey, roaring::Roaring> delete_bitmap; // Ordered map |
406 | | constexpr static inline uint32_t INVALID_SEGMENT_ID = std::numeric_limits<uint32_t>::max() - 1; |
407 | | constexpr static inline uint32_t ROWSET_SENTINEL_MARK = |
408 | | std::numeric_limits<uint32_t>::max() - 1; |
409 | | |
410 | | // When a delete bitmap is merged into tablet's delete bitmap, the version of entries in the delete bitmap |
411 | | // will be replaced to the correspoding correct version. So before we finally merge a delete bitmap into |
412 | | // tablet's delete bitmap we can use arbitary version number in BitmapKey. Here we define some version numbers |
413 | | // for specific usage during this periods to avoid conflicts |
414 | | constexpr static inline uint64_t TEMP_VERSION_COMMON = 0; |
415 | | |
416 | | /** |
417 | | * |
418 | | * @param tablet_id the tablet which this delete bitmap associates with |
419 | | */ |
420 | | DeleteBitmap(int64_t tablet_id); |
421 | | |
422 | | /** |
423 | | * Copy c-tor for making delete bitmap snapshot on read path |
424 | | */ |
425 | | DeleteBitmap(const DeleteBitmap& r); |
426 | | DeleteBitmap& operator=(const DeleteBitmap& r); |
427 | | /** |
428 | | * Move c-tor for making delete bitmap snapshot on read path |
429 | | */ |
430 | | DeleteBitmap(DeleteBitmap&& r) noexcept; |
431 | | DeleteBitmap& operator=(DeleteBitmap&& r) noexcept; |
432 | | |
433 | | static DeleteBitmap from_pb(const DeleteBitmapPB& pb, int64_t tablet_id); |
434 | | |
435 | | DeleteBitmapPB to_pb(); |
436 | | |
437 | | /** |
438 | | * Makes a snapshot of delete bitmap, read lock will be acquired in this |
439 | | * process |
440 | | */ |
441 | | DeleteBitmap snapshot() const; |
442 | | |
443 | | /** |
444 | | * Makes a snapshot of delete bitmap on given version, read lock will be |
445 | | * acquired temporary in this process |
446 | | */ |
447 | | DeleteBitmap snapshot(Version version) const; |
448 | | |
449 | | /** |
450 | | * Marks the specific row deleted |
451 | | */ |
452 | | void add(const BitmapKey& bmk, uint32_t row_id); |
453 | | |
454 | | /** |
455 | | * Clears the deletetion mark specific row |
456 | | * |
457 | | * @return non-zero if the associated delete bitmap does not exist |
458 | | */ |
459 | | int remove(const BitmapKey& bmk, uint32_t row_id); |
460 | | |
461 | | /** |
462 | | * Clears bitmaps in range [lower_key, upper_key) |
463 | | */ |
464 | | void remove(const BitmapKey& lower_key, const BitmapKey& upper_key); |
465 | | |
466 | | /** |
467 | | * Checks if the given row is marked deleted |
468 | | * |
469 | | * @return true if marked deleted |
470 | | */ |
471 | | bool contains(const BitmapKey& bmk, uint32_t row_id) const; |
472 | | |
473 | | /** |
474 | | * Checks if this delete bitmap is empty |
475 | | * |
476 | | * @return true if empty |
477 | | */ |
478 | | bool empty() const; |
479 | | |
480 | | /** |
481 | | * return the total cardinality of the Delete Bitmap |
482 | | */ |
483 | | uint64_t cardinality() const; |
484 | | |
485 | | /** |
486 | | * return the total size of the Delete Bitmap(after serialized) |
487 | | */ |
488 | | |
489 | | uint64_t get_size() const; |
490 | | |
491 | | /** |
492 | | * Sets the bitmap of specific segment, it's may be insertion or replacement |
493 | | * |
494 | | * @return 1 if the insertion took place, 0 if the assignment took place |
495 | | */ |
496 | | int set(const BitmapKey& bmk, const roaring::Roaring& segment_delete_bitmap); |
497 | | |
498 | | /** |
499 | | * Gets a copy of specific delete bmk |
500 | | * |
501 | | * @param segment_delete_bitmap output param |
502 | | * @return non-zero if the associated delete bitmap does not exist |
503 | | */ |
504 | | int get(const BitmapKey& bmk, roaring::Roaring* segment_delete_bitmap) const; |
505 | | |
506 | | /** |
507 | | * Gets reference to a specific delete map, DO NOT use this function on a |
508 | | * mutable DeleteBitmap object |
509 | | * @return nullptr if the given bitmap does not exist |
510 | | */ |
511 | | const roaring::Roaring* get(const BitmapKey& bmk) const; |
512 | | |
513 | | /** |
514 | | * Gets subset of delete_bitmap with given range [start, end) |
515 | | * |
516 | | * @parma start start |
517 | | * @parma end end |
518 | | * @parma subset_delete_map output param |
519 | | */ |
520 | | void subset(const BitmapKey& start, const BitmapKey& end, |
521 | | DeleteBitmap* subset_delete_map) const; |
522 | | |
523 | | /** |
524 | | * Gets count of delete_bitmap with given range [start, end) |
525 | | * |
526 | | * @parma start start |
527 | | * @parma end end |
528 | | */ |
529 | | size_t get_count_with_range(const BitmapKey& start, const BitmapKey& end) const; |
530 | | |
531 | | /** |
532 | | * Merges the given segment delete bitmap into *this |
533 | | * |
534 | | * @param bmk |
535 | | * @param segment_delete_bitmap |
536 | | */ |
537 | | void merge(const BitmapKey& bmk, const roaring::Roaring& segment_delete_bitmap); |
538 | | |
539 | | /** |
540 | | * Merges the given delete bitmap into *this |
541 | | * |
542 | | * @param other |
543 | | */ |
544 | | void merge(const DeleteBitmap& other); |
545 | | |
546 | | /** |
547 | | * Checks if the given row is marked deleted in bitmap with the condition: |
548 | | * all the bitmaps that |
549 | | * RowsetId and SegmentId are the same as the given ones, |
550 | | * and Version <= the given Version |
551 | | * |
552 | | * Note: aggregation cache may be used. |
553 | | * |
554 | | * @return true if marked deleted |
555 | | */ |
556 | | bool contains_agg(const BitmapKey& bitmap, uint32_t row_id) const; |
557 | | |
558 | | bool contains_agg_without_cache(const BitmapKey& bmk, uint32_t row_id) const; |
559 | | /** |
560 | | * Gets aggregated delete_bitmap on rowset_id and version, the same effect: |
561 | | * `select sum(roaring::Roaring) where RowsetId=rowset_id and SegmentId=seg_id and Version <= version` |
562 | | * |
563 | | * @return shared_ptr to a bitmap, which may be empty |
564 | | */ |
565 | | std::shared_ptr<roaring::Roaring> get_agg(const BitmapKey& bmk) const; |
566 | | std::shared_ptr<roaring::Roaring> get_agg_without_cache(const BitmapKey& bmk) const; |
567 | | |
568 | | void remove_sentinel_marks(); |
569 | | |
570 | | uint64_t get_delete_bitmap_count(); |
571 | | |
572 | | bool has_calculated_for_multi_segments(const RowsetId& rowset_id) const; |
573 | | |
574 | | // return the size of the map |
575 | | size_t remove_rowset_cache_version(const RowsetId& rowset_id); |
576 | | |
577 | | void clear_rowset_cache_version(); |
578 | | |
579 | | std::set<std::string> get_rowset_cache_version(); |
580 | | |
581 | | /** |
582 | | * Calculate diffset with given `key_set`. All entries with keys contained in this delete bitmap but not |
583 | | * in given key_set will be added to the output delete bitmap. |
584 | | * |
585 | | * @return Deletebitmap containning all entries in diffset |
586 | | */ |
587 | | DeleteBitmap diffset(const std::set<BitmapKey>& key_set) const; |
588 | | |
589 | | private: |
590 | | DeleteBitmap::Version _get_rowset_cache_version(const BitmapKey& bmk) const; |
591 | | |
592 | | int64_t _tablet_id; |
593 | | mutable std::shared_mutex _rowset_cache_version_lock; |
594 | | mutable std::map<RowsetId, std::map<SegmentId, Version>> _rowset_cache_version; |
595 | | }; |
596 | | |
597 | | static const std::string SEQUENCE_COL = "__DORIS_SEQUENCE_COL__"; |
598 | | |
599 | 13.4k | inline TabletUid TabletMeta::tablet_uid() const { |
600 | 13.4k | return _tablet_uid; |
601 | 13.4k | } |
602 | | |
603 | 812 | inline int64_t TabletMeta::table_id() const { |
604 | 812 | return _table_id; |
605 | 812 | } |
606 | | |
607 | 809 | inline int64_t TabletMeta::index_id() const { |
608 | 809 | return _index_id; |
609 | 809 | } |
610 | | |
611 | 2.29k | inline int64_t TabletMeta::partition_id() const { |
612 | 2.29k | return _partition_id; |
613 | 2.29k | } |
614 | | |
615 | 19.6k | inline int64_t TabletMeta::tablet_id() const { |
616 | 19.6k | return _tablet_id; |
617 | 19.6k | } |
618 | | |
619 | 1.08k | inline int64_t TabletMeta::replica_id() const { |
620 | 1.08k | return _replica_id; |
621 | 1.08k | } |
622 | | |
623 | 2.86k | inline int32_t TabletMeta::schema_hash() const { |
624 | 2.86k | return _schema_hash; |
625 | 2.86k | } |
626 | | |
627 | 1.52k | inline int32_t TabletMeta::shard_id() const { |
628 | 1.52k | return _shard_id; |
629 | 1.52k | } |
630 | | |
631 | 17 | inline void TabletMeta::set_shard_id(int32_t shard_id) { |
632 | 17 | _shard_id = shard_id; |
633 | 17 | } |
634 | | |
635 | 809 | inline int64_t TabletMeta::creation_time() const { |
636 | 809 | return _creation_time; |
637 | 809 | } |
638 | | |
639 | 0 | inline void TabletMeta::set_creation_time(int64_t creation_time) { |
640 | 0 | _creation_time = creation_time; |
641 | 0 | } |
642 | | |
643 | 809 | inline int64_t TabletMeta::cumulative_layer_point() const { |
644 | 809 | return _cumulative_layer_point; |
645 | 809 | } |
646 | | |
647 | 0 | inline void TabletMeta::set_cumulative_layer_point(int64_t new_point) { |
648 | 0 | _cumulative_layer_point = new_point; |
649 | 0 | } |
650 | | |
651 | 19 | inline size_t TabletMeta::num_rows() const { |
652 | 19 | size_t num_rows = 0; |
653 | 32 | for (auto& rs : _rs_metas) { |
654 | 32 | num_rows += rs->num_rows(); |
655 | 32 | } |
656 | 19 | return num_rows; |
657 | 19 | } |
658 | | |
659 | 8 | inline size_t TabletMeta::tablet_footprint() const { |
660 | 8 | size_t total_size = 0; |
661 | 26 | for (auto& rs : _rs_metas) { |
662 | 26 | total_size += rs->total_disk_size(); |
663 | 26 | } |
664 | 8 | return total_size; |
665 | 8 | } |
666 | | |
667 | 0 | inline size_t TabletMeta::tablet_local_size() const { |
668 | 0 | size_t total_size = 0; |
669 | 0 | for (auto& rs : _rs_metas) { |
670 | 0 | if (rs->is_local()) { |
671 | 0 | total_size += rs->total_disk_size(); |
672 | 0 | } |
673 | 0 | } |
674 | 0 | return total_size; |
675 | 0 | } |
676 | | |
677 | 0 | inline size_t TabletMeta::tablet_remote_size() const { |
678 | 0 | size_t total_size = 0; |
679 | 0 | for (auto& rs : _rs_metas) { |
680 | 0 | if (!rs->is_local()) { |
681 | 0 | total_size += rs->total_disk_size(); |
682 | 0 | } |
683 | 0 | } |
684 | 0 | return total_size; |
685 | 0 | } |
686 | | |
687 | 0 | inline size_t TabletMeta::tablet_local_index_size() const { |
688 | 0 | size_t total_size = 0; |
689 | 0 | for (auto& rs : _rs_metas) { |
690 | 0 | if (rs->is_local()) { |
691 | 0 | total_size += rs->index_disk_size(); |
692 | 0 | } |
693 | 0 | } |
694 | 0 | return total_size; |
695 | 0 | } |
696 | | |
697 | 0 | inline size_t TabletMeta::tablet_local_segment_size() const { |
698 | 0 | size_t total_size = 0; |
699 | 0 | for (auto& rs : _rs_metas) { |
700 | 0 | if (rs->is_local()) { |
701 | 0 | total_size += rs->data_disk_size(); |
702 | 0 | } |
703 | 0 | } |
704 | 0 | return total_size; |
705 | 0 | } |
706 | | |
707 | 0 | inline size_t TabletMeta::tablet_remote_index_size() const { |
708 | 0 | size_t total_size = 0; |
709 | 0 | for (auto& rs : _rs_metas) { |
710 | 0 | if (!rs->is_local()) { |
711 | 0 | total_size += rs->index_disk_size(); |
712 | 0 | } |
713 | 0 | } |
714 | 0 | return total_size; |
715 | 0 | } |
716 | | |
717 | 0 | inline size_t TabletMeta::tablet_remote_segment_size() const { |
718 | 0 | size_t total_size = 0; |
719 | 0 | for (auto& rs : _rs_metas) { |
720 | 0 | if (!rs->is_local()) { |
721 | 0 | total_size += rs->data_disk_size(); |
722 | 0 | } |
723 | 0 | } |
724 | 0 | return total_size; |
725 | 0 | } |
726 | | |
727 | 56 | inline size_t TabletMeta::version_count() const { |
728 | 56 | return _rs_metas.size(); |
729 | 56 | } |
730 | | |
731 | 28 | inline size_t TabletMeta::stale_version_count() const { |
732 | 28 | return _rs_metas.size(); |
733 | 28 | } |
734 | | |
735 | 10.5k | inline TabletState TabletMeta::tablet_state() const { |
736 | 10.5k | return _tablet_state; |
737 | 10.5k | } |
738 | | |
739 | 255 | inline void TabletMeta::set_tablet_state(TabletState state) { |
740 | 255 | _tablet_state = state; |
741 | 255 | } |
742 | | |
743 | 809 | inline bool TabletMeta::in_restore_mode() const { |
744 | 809 | return _in_restore_mode; |
745 | 809 | } |
746 | | |
747 | 0 | inline void TabletMeta::set_in_restore_mode(bool in_restore_mode) { |
748 | 0 | _in_restore_mode = in_restore_mode; |
749 | 0 | } |
750 | | |
751 | 3.13k | inline const TabletSchemaSPtr& TabletMeta::tablet_schema() const { |
752 | 3.13k | return _schema; |
753 | 3.13k | } |
754 | | |
755 | 0 | inline TabletSchema* TabletMeta::mutable_tablet_schema() { |
756 | 0 | return _schema.get(); |
757 | 0 | } |
758 | | |
759 | 2.04k | inline const std::vector<RowsetMetaSharedPtr>& TabletMeta::all_rs_metas() const { |
760 | 2.04k | return _rs_metas; |
761 | 2.04k | } |
762 | | |
763 | 0 | inline std::vector<RowsetMetaSharedPtr>& TabletMeta::all_mutable_rs_metas() { |
764 | 0 | return _rs_metas; |
765 | 0 | } |
766 | | |
767 | 1.07k | inline const std::vector<RowsetMetaSharedPtr>& TabletMeta::all_stale_rs_metas() const { |
768 | 1.07k | return _stale_rs_metas; |
769 | 1.07k | } |
770 | | |
771 | 0 | inline bool TabletMeta::all_beta() const { |
772 | 0 | for (auto& rs : _rs_metas) { |
773 | 0 | if (rs->rowset_type() != RowsetTypePB::BETA_ROWSET) { |
774 | 0 | return false; |
775 | 0 | } |
776 | 0 | } |
777 | 0 | for (auto& rs : _stale_rs_metas) { |
778 | 0 | if (rs->rowset_type() != RowsetTypePB::BETA_ROWSET) { |
779 | 0 | return false; |
780 | 0 | } |
781 | 0 | } |
782 | 0 | return true; |
783 | 0 | } |
784 | | |
785 | | std::string tablet_state_name(TabletState state); |
786 | | |
787 | | // Only for unit test now. |
788 | | bool operator==(const TabletMeta& a, const TabletMeta& b); |
789 | | bool operator!=(const TabletMeta& a, const TabletMeta& b); |
790 | | |
791 | | #include "common/compile_check_end.h" |
792 | | } // namespace doris |