Coverage Report

Created: 2024-11-20 21:05

/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
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(int64_t table_id, int64_t partition_id, int64_t tablet_id, int64_t replica_id,
103
               int32_t schema_hash, uint64_t shard_id, const TTabletSchema& tablet_schema,
104
               uint32_t next_unique_id,
105
               const std::unordered_map<uint32_t, uint32_t>& col_ordinal_to_unique_id,
106
               TabletUid tablet_uid, TTabletType::type tabletType,
107
               TCompressionType::type compression_type, int64_t storage_policy_id = 0,
108
               bool enable_unique_key_merge_on_write = false,
109
               std::optional<TBinlogConfig> binlog_config = {},
110
               std::string compaction_policy = "size_based",
111
               int64_t time_series_compaction_goal_size_mbytes = 1024,
112
               int64_t time_series_compaction_file_count_threshold = 2000,
113
               int64_t time_series_compaction_time_threshold_seconds = 3600,
114
               int64_t time_series_compaction_empty_rowsets_threshold = 5,
115
               int64_t time_series_compaction_level_threshold = 1,
116
               TInvertedIndexFileStorageFormat::type inverted_index_file_storage_format =
117
                       TInvertedIndexFileStorageFormat::V2);
118
    // If need add a filed in TableMeta, filed init copy in copy construct function
119
    TabletMeta(const TabletMeta& tablet_meta);
120
    TabletMeta(TabletMeta&& tablet_meta) = delete;
121
122
// UT
123
#ifdef BE_TEST
124
3
    TabletMeta(TabletSchemaSPtr tablet_schema) : _schema(tablet_schema) {}
125
#endif
126
127
    // Function create_from_file is used to be compatible with previous tablet_meta.
128
    // Previous tablet_meta is a physical file in tablet dir, which is not stored in rocksdb.
129
    Status create_from_file(const std::string& file_path);
130
    Status save(const std::string& file_path);
131
    Status save_as_json(const string& file_path);
132
    static Status save(const std::string& file_path, const TabletMetaPB& tablet_meta_pb);
133
    static std::string construct_header_file_path(const std::string& schema_hash_path,
134
                                                  int64_t tablet_id);
135
    Status save_meta(DataDir* data_dir);
136
137
    void serialize(std::string* meta_binary);
138
    Status deserialize(std::string_view meta_binary);
139
    void init_from_pb(const TabletMetaPB& tablet_meta_pb);
140
141
    void to_meta_pb(TabletMetaPB* tablet_meta_pb);
142
    void to_json(std::string* json_string, json2pb::Pb2JsonOptions& options);
143
    // Don't use.
144
    // TODO: memory size of TabletSchema cannot be accurately tracked.
145
    // In some places, temporarily use num_columns() as TabletSchema size.
146
    int64_t mem_size() const;
147
139
    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
28
    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
    int16_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
    size_t version_count() const;
174
    size_t stale_version_count() const;
175
    size_t version_count_cross_with_range(const Version& range) const;
176
    Version max_version() const;
177
178
    TabletState tablet_state() const;
179
    void set_tablet_state(TabletState state);
180
181
    bool in_restore_mode() const;
182
    void set_in_restore_mode(bool in_restore_mode);
183
184
    const TabletSchemaSPtr& tablet_schema() const;
185
186
    TabletSchema* mutable_tablet_schema();
187
188
    const std::vector<RowsetMetaSharedPtr>& all_rs_metas() const;
189
    std::vector<RowsetMetaSharedPtr>& all_mutable_rs_metas();
190
    Status add_rs_meta(const RowsetMetaSharedPtr& rs_meta);
191
    void delete_rs_meta_by_version(const Version& version,
192
                                   std::vector<RowsetMetaSharedPtr>* deleted_rs_metas);
193
    // If same_version is true, the rowset in "to_delete" will not be added
194
    // to _stale_rs_meta, but to be deleted from rs_meta directly.
195
    void modify_rs_metas(const std::vector<RowsetMetaSharedPtr>& to_add,
196
                         const std::vector<RowsetMetaSharedPtr>& to_delete,
197
                         bool same_version = false);
198
    void revise_rs_metas(std::vector<RowsetMetaSharedPtr>&& rs_metas);
199
    void revise_delete_bitmap_unlocked(const DeleteBitmap& delete_bitmap);
200
201
    const std::vector<RowsetMetaSharedPtr>& all_stale_rs_metas() const;
202
    RowsetMetaSharedPtr acquire_rs_meta_by_version(const Version& version) const;
203
    void delete_stale_rs_meta_by_version(const Version& version);
204
    RowsetMetaSharedPtr acquire_stale_rs_meta_by_version(const Version& version) const;
205
206
    Status set_partition_id(int64_t partition_id);
207
208
121
    RowsetTypePB preferred_rowset_type() const { return _preferred_rowset_type; }
209
210
52
    void set_preferred_rowset_type(RowsetTypePB preferred_rowset_type) {
211
52
        _preferred_rowset_type = preferred_rowset_type;
212
52
    }
213
214
    // used for after tablet cloned to clear stale rowset
215
0
    void clear_stale_rowset() { _stale_rs_metas.clear(); }
216
217
0
    void clear_rowsets() { _rs_metas.clear(); }
218
219
    // MUST hold EXCLUSIVE `_meta_lock` in belonged Tablet
220
    // `to_add` MUST NOT have overlapped version with `_rs_metas` in tablet meta.
221
    void add_rowsets_unchecked(const std::vector<RowsetSharedPtr>& to_add);
222
223
    bool all_beta() const;
224
225
22
    int64_t storage_policy_id() const { return _storage_policy_id; }
226
227
4
    void set_storage_policy_id(int64_t id) {
228
4
        VLOG_NOTICE << "set tablet_id : " << _table_id << " storage policy from "
229
0
                    << _storage_policy_id << " to " << id;
230
4
        _storage_policy_id = id;
231
4
    }
232
233
14
    UniqueId cooldown_meta_id() const { return _cooldown_meta_id; }
234
5
    void set_cooldown_meta_id(UniqueId uid) { _cooldown_meta_id = uid; }
235
236
    static void init_column_from_tcolumn(uint32_t unique_id, const TColumn& tcolumn,
237
                                         ColumnPB* column);
238
239
18
    DeleteBitmap& delete_bitmap() { return *_delete_bitmap; }
240
241
607
    bool enable_unique_key_merge_on_write() const { return _enable_unique_key_merge_on_write; }
242
243
    // TODO(Drogon): thread safety
244
0
    const BinlogConfig& binlog_config() const { return _binlog_config; }
245
0
    void set_binlog_config(BinlogConfig binlog_config) {
246
0
        _binlog_config = std::move(binlog_config);
247
0
    }
248
249
12
    void set_compaction_policy(std::string compaction_policy) {
250
12
        _compaction_policy = compaction_policy;
251
12
    }
252
479
    std::string compaction_policy() const { return _compaction_policy; }
253
12
    void set_time_series_compaction_goal_size_mbytes(int64_t goal_size_mbytes) {
254
12
        _time_series_compaction_goal_size_mbytes = goal_size_mbytes;
255
12
    }
256
186
    int64_t time_series_compaction_goal_size_mbytes() const {
257
186
        return _time_series_compaction_goal_size_mbytes;
258
186
    }
259
12
    void set_time_series_compaction_file_count_threshold(int64_t file_count_threshold) {
260
12
        _time_series_compaction_file_count_threshold = file_count_threshold;
261
12
    }
262
184
    int64_t time_series_compaction_file_count_threshold() const {
263
184
        return _time_series_compaction_file_count_threshold;
264
184
    }
265
12
    void set_time_series_compaction_time_threshold_seconds(int64_t time_threshold) {
266
12
        _time_series_compaction_time_threshold_seconds = time_threshold;
267
12
    }
268
182
    int64_t time_series_compaction_time_threshold_seconds() const {
269
182
        return _time_series_compaction_time_threshold_seconds;
270
182
    }
271
0
    void set_time_series_compaction_empty_rowsets_threshold(int64_t empty_rowsets_threshold) {
272
0
        _time_series_compaction_empty_rowsets_threshold = empty_rowsets_threshold;
273
0
    }
274
183
    int64_t time_series_compaction_empty_rowsets_threshold() const {
275
183
        return _time_series_compaction_empty_rowsets_threshold;
276
183
    }
277
0
    void set_time_series_compaction_level_threshold(int64_t level_threshold) {
278
0
        _time_series_compaction_level_threshold = level_threshold;
279
0
    }
280
205
    int64_t time_series_compaction_level_threshold() const {
281
205
        return _time_series_compaction_level_threshold;
282
205
    }
283
284
141
    int64_t ttl_seconds() const {
285
141
        std::shared_lock rlock(_meta_lock);
286
141
        return _ttl_seconds;
287
141
    }
288
289
0
    void set_ttl_seconds(int64_t ttl_seconds) {
290
0
        std::lock_guard wlock(_meta_lock);
291
0
        _ttl_seconds = ttl_seconds;
292
0
    }
293
294
25
    int64_t avg_rs_meta_serialize_size() const { return _avg_rs_meta_serialize_size; }
295
296
private:
297
    Status _save_meta(DataDir* data_dir);
298
299
    // _del_predicates is ignored to compare.
300
    friend bool operator==(const TabletMeta& a, const TabletMeta& b);
301
    friend bool operator!=(const TabletMeta& a, const TabletMeta& b);
302
303
private:
304
    int64_t _table_id = 0;
305
    int64_t _index_id = 0;
306
    int64_t _partition_id = 0;
307
    int64_t _tablet_id = 0;
308
    int64_t _replica_id = 0;
309
    int32_t _schema_hash = 0;
310
    int32_t _shard_id = 0;
311
    int64_t _creation_time = 0;
312
    int64_t _cumulative_layer_point = 0;
313
    TabletUid _tablet_uid;
314
    TabletTypePB _tablet_type = TabletTypePB::TABLET_TYPE_DISK;
315
316
    TabletState _tablet_state = TABLET_NOTREADY;
317
    // the reference of _schema may use in tablet, so here need keep
318
    // the lifetime of tablemeta and _schema is same with tablet
319
    TabletSchemaSPtr _schema;
320
321
    std::vector<RowsetMetaSharedPtr> _rs_metas;
322
    // This variable _stale_rs_metas is used to record these rowsets‘ meta which are be compacted.
323
    // These stale rowsets meta are been removed when rowsets' pathVersion is expired,
324
    // this policy is judged and computed by TimestampedVersionTracker.
325
    std::vector<RowsetMetaSharedPtr> _stale_rs_metas;
326
    bool _in_restore_mode = false;
327
    RowsetTypePB _preferred_rowset_type = BETA_ROWSET;
328
329
    // meta for cooldown
330
    int64_t _storage_policy_id = 0; // <= 0 means no storage policy
331
    UniqueId _cooldown_meta_id;
332
333
    // For unique key data model, the feature Merge-on-Write will leverage a primary
334
    // key index and a delete-bitmap to mark duplicate keys as deleted in load stage,
335
    // which can avoid the merging cost in read stage, and accelerate the aggregation
336
    // query performance significantly.
337
    bool _enable_unique_key_merge_on_write = false;
338
    std::shared_ptr<DeleteBitmap> _delete_bitmap;
339
340
    // binlog config
341
    BinlogConfig _binlog_config {};
342
343
    // meta for compaction
344
    std::string _compaction_policy;
345
    int64_t _time_series_compaction_goal_size_mbytes = 0;
346
    int64_t _time_series_compaction_file_count_threshold = 0;
347
    int64_t _time_series_compaction_time_threshold_seconds = 0;
348
    int64_t _time_series_compaction_empty_rowsets_threshold = 0;
349
    int64_t _time_series_compaction_level_threshold = 0;
350
351
    int64_t _avg_rs_meta_serialize_size = 0;
352
353
    // cloud
354
    int64_t _ttl_seconds = 0;
355
356
    mutable std::shared_mutex _meta_lock;
357
};
358
359
/**
360
 * Wraps multiple bitmaps for recording rows (row id) that are deleted or
361
 * overwritten. For now, it's only used when unique key merge-on-write property
362
 * enabled.
363
 *
364
 * RowsetId and SegmentId are for locating segment, Version here is a single
365
 * uint32_t means that at which "version" of the load causes the delete or
366
 * overwrite.
367
 *
368
 * The start and end version of a load is the same, it's ok and straightforward
369
 * to use a single uint32_t.
370
 *
371
 * e.g.
372
 * There is a key "key1" in rowset id 1, version [1,1], segment id 1, row id 1.
373
 * A new load also contains "key1", the rowset id 2, version [2,2], segment id 1
374
 * the delete bitmap will be `{1,1,2} -> 1`, which means the "row id 1" in
375
 * "rowset id 1, segment id 1" is deleted/overitten by some loads at "version 2"
376
 */
377
class DeleteBitmap {
378
public:
379
    mutable std::shared_mutex lock;
380
    mutable std::shared_mutex stale_delete_bitmap_lock;
381
    using SegmentId = uint32_t;
382
    using Version = uint64_t;
383
    using BitmapKey = std::tuple<RowsetId, SegmentId, Version>;
384
    std::map<BitmapKey, roaring::Roaring> delete_bitmap; // Ordered map
385
    constexpr static inline uint32_t INVALID_SEGMENT_ID = std::numeric_limits<uint32_t>::max() - 1;
386
    constexpr static inline uint32_t ROWSET_SENTINEL_MARK =
387
            std::numeric_limits<uint32_t>::max() - 1;
388
389
    // When a delete bitmap is merged into tablet's delete bitmap, the version of entries in the delete bitmap
390
    // will be replaced to the correspoding correct version. So before we finally merge a delete bitmap into
391
    // tablet's delete bitmap we can use arbitary version number in BitmapKey. Here we define some version numbers
392
    // for specific usage during this periods to avoid conflicts
393
    constexpr static inline uint64_t TEMP_VERSION_COMMON = 0;
394
395
    /**
396
     * 
397
     * @param tablet_id the tablet which this delete bitmap associates with
398
     */
399
    DeleteBitmap(int64_t tablet_id);
400
401
    /**
402
     * Copy c-tor for making delete bitmap snapshot on read path
403
     */
404
    DeleteBitmap(const DeleteBitmap& r);
405
    DeleteBitmap& operator=(const DeleteBitmap& r);
406
    /**
407
     * Move c-tor for making delete bitmap snapshot on read path
408
     */
409
    DeleteBitmap(DeleteBitmap&& r);
410
    DeleteBitmap& operator=(DeleteBitmap&& r);
411
412
    /**
413
     * Makes a snapshot of delete bitmap, read lock will be acquired in this
414
     * process
415
     */
416
    DeleteBitmap snapshot() const;
417
418
    /**
419
     * Makes a snapshot of delete bitmap on given version, read lock will be
420
     * acquired temporary in this process
421
     */
422
    DeleteBitmap snapshot(Version version) const;
423
424
    /**
425
     * Marks the specific row deleted
426
     */
427
    void add(const BitmapKey& bmk, uint32_t row_id);
428
429
    /**
430
     * Clears the deletetion mark specific row
431
     *
432
     * @return non-zero if the associated delete bitmap does not exist
433
     */
434
    int remove(const BitmapKey& bmk, uint32_t row_id);
435
436
    /**
437
     * Clears bitmaps in range [lower_key, upper_key)
438
     */
439
    void remove(const BitmapKey& lower_key, const BitmapKey& upper_key);
440
441
    /**
442
     * Checks if the given row is marked deleted
443
     *
444
     * @return true if marked deleted
445
     */
446
    bool contains(const BitmapKey& bmk, uint32_t row_id) const;
447
448
    /**
449
     * Checks if this delete bitmap is empty
450
     *
451
     * @return true if empty
452
     */
453
    bool empty() const;
454
455
    /**
456
     * return the total cardinality of the Delete Bitmap
457
     */
458
    uint64_t cardinality() const;
459
460
    /**
461
     * return the total size of the Delete Bitmap(after serialized)
462
     */
463
464
    uint64_t get_size() const;
465
466
    /**
467
     * Sets the bitmap of specific segment, it's may be insertion or replacement
468
     *
469
     * @return 1 if the insertion took place, 0 if the assignment took place
470
     */
471
    int set(const BitmapKey& bmk, const roaring::Roaring& segment_delete_bitmap);
472
473
    /**
474
     * Gets a copy of specific delete bmk
475
     *
476
     * @param segment_delete_bitmap output param
477
     * @return non-zero if the associated delete bitmap does not exist
478
     */
479
    int get(const BitmapKey& bmk, roaring::Roaring* segment_delete_bitmap) const;
480
481
    /**
482
     * Gets reference to a specific delete map, DO NOT use this function on a
483
     * mutable DeleteBitmap object
484
     * @return nullptr if the given bitmap does not exist
485
     */
486
    const roaring::Roaring* get(const BitmapKey& bmk) const;
487
488
    /**
489
     * Gets subset of delete_bitmap with given range [start, end)
490
     *
491
     * @parma start start
492
     * @parma end end
493
     * @parma subset_delete_map output param
494
     */
495
    void subset(const BitmapKey& start, const BitmapKey& end,
496
                DeleteBitmap* subset_delete_map) const;
497
498
    /**
499
     * Merges the given segment delete bitmap into *this
500
     *
501
     * @param bmk
502
     * @param segment_delete_bitmap
503
     */
504
    void merge(const BitmapKey& bmk, const roaring::Roaring& segment_delete_bitmap);
505
506
    /**
507
     * Merges the given delete bitmap into *this
508
     *
509
     * @param other
510
     */
511
    void merge(const DeleteBitmap& other);
512
513
    /**
514
     * Checks if the given row is marked deleted in bitmap with the condition:
515
     * all the bitmaps that
516
     * RowsetId and SegmentId are the same as the given ones,
517
     * and Version <= the given Version
518
     *
519
     * Note: aggregation cache may be used.
520
     *
521
     * @return true if marked deleted
522
     */
523
    bool contains_agg(const BitmapKey& bitmap, uint32_t row_id) const;
524
525
    bool contains_agg_without_cache(const BitmapKey& bmk, uint32_t row_id) const;
526
    /**
527
     * Gets aggregated delete_bitmap on rowset_id and version, the same effect:
528
     * `select sum(roaring::Roaring) where RowsetId=rowset_id and SegmentId=seg_id and Version <= version`
529
     *
530
     * @return shared_ptr to a bitmap, which may be empty
531
     */
532
    std::shared_ptr<roaring::Roaring> get_agg(const BitmapKey& bmk) const;
533
534
    void remove_sentinel_marks();
535
536
    void add_to_remove_queue(const std::string& version_str,
537
                             const std::vector<std::tuple<int64_t, DeleteBitmap::BitmapKey,
538
                                                          DeleteBitmap::BitmapKey>>& vector);
539
    void remove_stale_delete_bitmap_from_queue(const std::vector<std::string>& vector);
540
541
    uint64_t get_delete_bitmap_count();
542
543
    class AggCachePolicy : public LRUCachePolicy {
544
    public:
545
        AggCachePolicy(size_t capacity)
546
                : LRUCachePolicy(CachePolicy::CacheType::DELETE_BITMAP_AGG_CACHE, capacity,
547
                                 LRUCacheType::SIZE,
548
1
                                 config::delete_bitmap_agg_cache_stale_sweep_time_sec, 256) {}
549
    };
550
551
    class AggCache {
552
    public:
553
        class Value : public LRUCacheValueBase {
554
        public:
555
            roaring::Roaring bitmap;
556
        };
557
558
371
        AggCache(size_t size_in_bytes) {
559
371
            static std::once_flag once;
560
371
            std::call_once(once, [size_in_bytes] {
561
1
                auto* tmp = new AggCachePolicy(size_in_bytes);
562
1
                AggCache::s_repr.store(tmp, std::memory_order_release);
563
1
            });
564
565
371
            while (!s_repr.load(std::memory_order_acquire)) {
566
0
            }
567
371
        }
568
569
132
        static LRUCachePolicy* repr() { return s_repr.load(std::memory_order_acquire); }
570
        static std::atomic<AggCachePolicy*> s_repr;
571
    };
572
573
private:
574
    mutable std::shared_ptr<AggCache> _agg_cache;
575
    int64_t _tablet_id;
576
    // <version, <tablet_id, BitmapKeyStart, BitmapKeyEnd>>
577
    std::map<std::string,
578
             std::vector<std::tuple<int64_t, DeleteBitmap::BitmapKey, DeleteBitmap::BitmapKey>>>
579
            _stale_delete_bitmap;
580
};
581
582
1.18k
inline TabletUid TabletMeta::tablet_uid() const {
583
1.18k
    return _tablet_uid;
584
1.18k
}
585
586
182
inline int64_t TabletMeta::table_id() const {
587
182
    return _table_id;
588
182
}
589
590
180
inline int64_t TabletMeta::index_id() const {
591
180
    return _index_id;
592
180
}
593
594
562
inline int64_t TabletMeta::partition_id() const {
595
562
    return _partition_id;
596
562
}
597
598
4.65k
inline int64_t TabletMeta::tablet_id() const {
599
4.65k
    return _tablet_id;
600
4.65k
}
601
602
243
inline int64_t TabletMeta::replica_id() const {
603
243
    return _replica_id;
604
243
}
605
606
662
inline int32_t TabletMeta::schema_hash() const {
607
662
    return _schema_hash;
608
662
}
609
610
410
inline int16_t TabletMeta::shard_id() const {
611
410
    return _shard_id;
612
410
}
613
614
16
inline void TabletMeta::set_shard_id(int32_t shard_id) {
615
16
    _shard_id = shard_id;
616
16
}
617
618
180
inline int64_t TabletMeta::creation_time() const {
619
180
    return _creation_time;
620
180
}
621
622
0
inline void TabletMeta::set_creation_time(int64_t creation_time) {
623
0
    _creation_time = creation_time;
624
0
}
625
626
180
inline int64_t TabletMeta::cumulative_layer_point() const {
627
180
    return _cumulative_layer_point;
628
180
}
629
630
0
inline void TabletMeta::set_cumulative_layer_point(int64_t new_point) {
631
0
    _cumulative_layer_point = new_point;
632
0
}
633
634
16
inline size_t TabletMeta::num_rows() const {
635
16
    size_t num_rows = 0;
636
28
    for (auto& rs : _rs_metas) {
637
28
        num_rows += rs->num_rows();
638
28
    }
639
16
    return num_rows;
640
16
}
641
642
8
inline size_t TabletMeta::tablet_footprint() const {
643
8
    size_t total_size = 0;
644
26
    for (auto& rs : _rs_metas) {
645
26
        total_size += rs->total_disk_size();
646
26
    }
647
8
    return total_size;
648
8
}
649
650
0
inline size_t TabletMeta::tablet_local_size() const {
651
0
    size_t total_size = 0;
652
0
    for (auto& rs : _rs_metas) {
653
0
        if (rs->is_local()) {
654
0
            total_size += rs->total_disk_size();
655
0
        }
656
0
    }
657
0
    return total_size;
658
0
}
659
660
0
inline size_t TabletMeta::tablet_remote_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
50
inline size_t TabletMeta::version_count() const {
671
50
    return _rs_metas.size();
672
50
}
673
674
25
inline size_t TabletMeta::stale_version_count() const {
675
25
    return _rs_metas.size();
676
25
}
677
678
8.82k
inline TabletState TabletMeta::tablet_state() const {
679
8.82k
    return _tablet_state;
680
8.82k
}
681
682
46
inline void TabletMeta::set_tablet_state(TabletState state) {
683
46
    _tablet_state = state;
684
46
}
685
686
180
inline bool TabletMeta::in_restore_mode() const {
687
180
    return _in_restore_mode;
688
180
}
689
690
0
inline void TabletMeta::set_in_restore_mode(bool in_restore_mode) {
691
0
    _in_restore_mode = in_restore_mode;
692
0
}
693
694
1.56k
inline const TabletSchemaSPtr& TabletMeta::tablet_schema() const {
695
1.56k
    return _schema;
696
1.56k
}
697
698
0
inline TabletSchema* TabletMeta::mutable_tablet_schema() {
699
0
    return _schema.get();
700
0
}
701
702
943
inline const std::vector<RowsetMetaSharedPtr>& TabletMeta::all_rs_metas() const {
703
943
    return _rs_metas;
704
943
}
705
706
0
inline std::vector<RowsetMetaSharedPtr>& TabletMeta::all_mutable_rs_metas() {
707
0
    return _rs_metas;
708
0
}
709
710
515
inline const std::vector<RowsetMetaSharedPtr>& TabletMeta::all_stale_rs_metas() const {
711
515
    return _stale_rs_metas;
712
515
}
713
714
0
inline bool TabletMeta::all_beta() const {
715
0
    for (auto& rs : _rs_metas) {
716
0
        if (rs->rowset_type() != RowsetTypePB::BETA_ROWSET) {
717
0
            return false;
718
0
        }
719
0
    }
720
0
    for (auto& rs : _stale_rs_metas) {
721
0
        if (rs->rowset_type() != RowsetTypePB::BETA_ROWSET) {
722
0
            return false;
723
0
        }
724
0
    }
725
0
    return true;
726
0
}
727
728
std::string tablet_state_name(TabletState state);
729
730
// Only for unit test now.
731
bool operator==(const TabletMeta& a, const TabletMeta& b);
732
bool operator!=(const TabletMeta& a, const TabletMeta& b);
733
734
} // namespace doris