Coverage Report

Created: 2025-07-30 14:45

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