Coverage Report

Created: 2025-06-16 12:20

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