Coverage Report

Created: 2026-09-18 18:11

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/storage/tablet/base_tablet.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/olap_common.pb.h>
21
22
#include <memory>
23
#include <mutex>
24
#include <shared_mutex>
25
#include <string>
26
27
#include "common/metrics/metrics.h"
28
#include "common/status.h"
29
#include "io/io_common.h"
30
#include "storage/iterators.h"
31
#include "storage/olap_common.h"
32
#include "storage/partial_update_info.h"
33
#include "storage/segment/segment.h"
34
#include "storage/tablet/tablet_fwd.h"
35
#include "storage/tablet/tablet_meta.h"
36
#include "storage/tablet/tablet_schema.h"
37
#include "storage/version_graph.h"
38
#include "util/bthread_shared_mutex.h"
39
40
namespace doris {
41
struct RowSetSplits;
42
struct RowsetWriterContext;
43
class RowsetWriter;
44
class CalcDeleteBitmapToken;
45
class SegmentCacheHandle;
46
class RowIdConversion;
47
struct PartialUpdateInfo;
48
class PartialUpdateReadPlan;
49
struct CaptureRowsetOps;
50
struct CaptureRowsetResult;
51
struct TabletReadSource;
52
class FixedReadPlan;
53
54
struct TabletWithVersion {
55
    BaseTabletSPtr tablet;
56
    int64_t version;
57
};
58
59
enum class CompactionStage { NOT_SCHEDULED, PENDING, EXECUTING };
60
61
// Base class for all tablet classes
62
class BaseTablet : public std::enable_shared_from_this<BaseTablet> {
63
public:
64
    explicit BaseTablet(TabletMetaSharedPtr tablet_meta);
65
    virtual ~BaseTablet();
66
    BaseTablet(const BaseTablet&) = delete;
67
    BaseTablet& operator=(const BaseTablet&) = delete;
68
69
11.3k
    TabletState tablet_state() const { return _tablet_meta->tablet_state(); }
70
    Status set_tablet_state(TabletState state);
71
45
    int64_t table_id() const { return _tablet_meta->table_id(); }
72
0
    size_t row_size() const { return _tablet_meta->tablet_schema()->row_size(); }
73
58
    int64_t index_id() const { return _tablet_meta->index_id(); }
74
998
    int64_t partition_id() const { return _tablet_meta->partition_id(); }
75
77.0k
    int64_t tablet_id() const { return _tablet_meta->tablet_id(); }
76
1.54k
    int32_t schema_hash() const { return _tablet_meta->schema_hash(); }
77
0
    CompressKind compress_kind() const { return _tablet_meta->tablet_schema()->compress_kind(); }
78
1.05k
    KeysType keys_type() const { return _tablet_meta->tablet_schema()->keys_type(); }
79
0
    size_t num_key_columns() const { return _tablet_meta->tablet_schema()->num_key_columns(); }
80
0
    int64_t ttl_seconds() const { return _tablet_meta->ttl_seconds(); }
81
    // See TabletMeta::file_cache_ttl_expiration_time().
82
437
    int64_t file_cache_ttl_expiration_time() const {
83
437
        return _tablet_meta->file_cache_ttl_expiration_time();
84
437
    }
85
    // currently used by schema change, inverted index building, and cooldown
86
39
    std::timed_mutex& get_schema_change_lock() { return _schema_change_lock; }
87
1.46k
    bool enable_unique_key_merge_on_write() const {
88
1.46k
#ifdef BE_TEST
89
1.46k
        if (_tablet_meta == nullptr) {
90
0
            return false;
91
0
        }
92
1.46k
#endif
93
1.46k
        return _tablet_meta->enable_unique_key_merge_on_write();
94
1.46k
    }
95
96
73
    bool need_read_delete_bitmap() const {
97
73
        return _tablet_meta->enable_unique_key_merge_on_write() ||
98
73
               _tablet_meta->is_row_binlog_tablet();
99
73
    }
100
101
1.55k
    bool is_row_binlog_tablet() const { return _tablet_meta->is_row_binlog_tablet(); }
102
103
    // Property encapsulated in TabletMeta
104
3.97k
    const TabletMetaSharedPtr& tablet_meta() const { return _tablet_meta; }
105
106
6
    BinlogConfig binlog_config() const {
107
6
        std::shared_lock rlock(_meta_lock);
108
6
        return _tablet_meta->binlog_config();
109
6
    }
110
111
    int32_t max_version_config();
112
113
    // FIXME(plat1ko): It is not appropriate to expose this lock
114
616
    BthreadSharedMutex& get_header_lock() { return _meta_lock; }
115
116
    void update_max_version_schema(const TabletSchemaSPtr& tablet_schema);
117
118
6.78k
    TabletSchemaSPtr tablet_schema() const {
119
6.78k
        std::shared_lock rlock(_meta_lock);
120
6.78k
        return _max_version_schema;
121
6.78k
    }
122
123
9
    void set_alter_failed(bool alter_failed) { _alter_failed = alter_failed; }
124
0
    bool is_alter_failed() { return _alter_failed; }
125
126
    virtual std::string tablet_path() const = 0;
127
128
    virtual bool exceed_version_limit(int32_t limit) = 0;
129
130
    virtual Result<std::unique_ptr<RowsetWriter>> create_rowset_writer(RowsetWriterContext& context,
131
                                                                       bool vertical) = 0;
132
133
    virtual Status capture_rs_readers(const Version& spec_version,
134
                                      std::vector<RowSetSplits>* rs_splits,
135
                                      const CaptureRowsetOps& opts) = 0;
136
137
    virtual size_t tablet_footprint() = 0;
138
139
    // this method just return the compaction sum on each rowset
140
    // note(tsy): we should unify the compaction score calculation finally
141
    uint32_t get_real_compaction_score() const;
142
    // MUST hold shared `_meta_lock`. Use this variant when the caller already
143
    // holds the header lock to avoid recursively re-acquiring the (now
144
    // writer-preferring) `_meta_lock`, which would self-deadlock.
145
    uint32_t get_real_compaction_score_unlocked() const;
146
147
    // MUST hold shared meta lock
148
    Status capture_rs_readers_unlocked(const Versions& version_path,
149
                                       std::vector<RowSetSplits>* rs_splits) const;
150
151
    // _rs_version_map and _stale_rs_version_map should be protected by _meta_lock
152
    // The caller must call hold _meta_lock when call this three function.
153
    RowsetSharedPtr get_rowset_by_version(const Version& version, bool find_is_stale = false) const;
154
    RowsetSharedPtr get_stale_rowset_by_version(const Version& version) const;
155
    RowsetSharedPtr get_rowset_with_max_version() const;
156
157
    Status get_all_rs_id(int64_t max_version, RowsetIdUnorderedSet* rowset_ids) const;
158
    Status get_all_rs_id_unlocked(int64_t max_version, RowsetIdUnorderedSet* rowset_ids) const;
159
160
    // Get the missed versions until the spec_version.
161
    Versions get_missed_versions(int64_t spec_version) const;
162
    Versions get_missed_versions_unlocked(int64_t spec_version) const;
163
164
    void generate_tablet_meta_copy(TabletMeta& new_tablet_meta, bool cloud_get_rowset_meta) const;
165
    void generate_tablet_meta_copy_unlocked(TabletMeta& new_tablet_meta,
166
                                            bool cloud_get_rowset_meta) const;
167
168
74
    virtual int64_t max_version_unlocked() const { return _tablet_meta->max_version().second; }
169
170
    static TabletSchemaSPtr tablet_schema_with_merged_max_schema_version(
171
            const std::vector<RowsetMetaSharedPtr>& rowset_metas);
172
173
    ////////////////////////////////////////////////////////////////////////////
174
    // begin MoW functions
175
    ////////////////////////////////////////////////////////////////////////////
176
    std::vector<RowsetSharedPtr> get_rowset_by_ids(
177
            const RowsetIdUnorderedSet* specified_rowset_ids);
178
179
    // Lookup a row with TupleDescriptor and fill Block
180
    Status lookup_row_data(const Slice& encoded_key, const RowLocation& row_location,
181
                           RowsetSharedPtr rowset, OlapReaderStatistics& stats, std::string& values,
182
                           bool write_to_cache = false, const io::IOContext* io_ctx = nullptr);
183
    // Lookup the row location of `encoded_key`, the function sets `row_location` on success.
184
    // NOTE: the method only works in unique key model with primary key index, you will got a
185
    //       not supported error in other data model.
186
    Status lookup_row_key(const Slice& encoded_key, TabletSchema* latest_schema, bool with_seq_col,
187
                          const std::vector<RowsetSharedPtr>& specified_rowsets,
188
                          RowLocation* row_location, int64_t version,
189
                          std::vector<std::unique_ptr<SegmentCacheHandle>>& segment_caches,
190
                          RowsetSharedPtr* rowset = nullptr, bool with_rowid = true,
191
                          std::string* encoded_seq_value = nullptr,
192
                          OlapReaderStatistics* stats = nullptr,
193
                          DeleteBitmapPtr tablet_delete_bitmap = nullptr,
194
                          const io::IOContext* io_ctx = nullptr);
195
196
    // calc delete bitmap when flush memtable, use a fake version to calc
197
    // For example, cur max version is 5, and we use version 6 to calc but
198
    // finally this rowset publish version with 8, we should make up data
199
    // for rowset 6-7. Also, if a compaction happens between commit_txn and
200
    // publish_txn, we should remove compaction input rowsets' delete_bitmap
201
    // and build newly generated rowset's delete_bitmap
202
    static Status calc_delete_bitmap(const BaseTabletSPtr& tablet, RowsetSharedPtr rowset,
203
                                     const std::vector<segment_v2::SegmentSharedPtr>& segments,
204
                                     const std::vector<RowsetSharedPtr>& specified_rowsets,
205
                                     DeleteBitmapPtr delete_bitmap, int64_t version,
206
                                     CalcDeleteBitmapToken* token,
207
                                     RowsetWriter* rowset_writer = nullptr,
208
                                     DeleteBitmapPtr tablet_delete_bitmap = nullptr);
209
210
    Status calc_segment_delete_bitmap(RowsetSharedPtr rowset,
211
                                      const segment_v2::SegmentSharedPtr& seg,
212
                                      const std::vector<RowsetSharedPtr>& specified_rowsets,
213
                                      DeleteBitmapPtr delete_bitmap, int64_t end_version,
214
                                      RowsetWriter* rowset_writer,
215
                                      DeleteBitmapPtr tablet_delete_bitmap = nullptr,
216
                                      int64_t queue_time_us = 0);
217
218
    Status calc_delete_bitmap_between_segments(
219
            TabletSchemaSPtr schema, RowsetId rowset_id,
220
            const std::vector<segment_v2::SegmentSharedPtr>& segments,
221
            DeleteBitmapPtr delete_bitmap, int64_t queue_time_us = 0);
222
223
    static Status commit_phase_update_delete_bitmap(
224
            const BaseTabletSPtr& tablet, const RowsetSharedPtr& rowset,
225
            RowsetIdUnorderedSet& pre_rowset_ids, DeleteBitmapPtr delete_bitmap,
226
            const std::vector<segment_v2::SegmentSharedPtr>& segments, int64_t txn_id,
227
            CalcDeleteBitmapToken* token, RowsetWriter* rowset_writer = nullptr);
228
229
    static void add_sentinel_mark_to_delete_bitmap(DeleteBitmap* delete_bitmap,
230
                                                   const RowsetIdUnorderedSet& rowsetids);
231
232
    Status check_delete_bitmap_correctness(DeleteBitmapPtr delete_bitmap, int64_t max_version,
233
                                           int64_t txn_id, const RowsetIdUnorderedSet& rowset_ids,
234
                                           std::vector<RowsetSharedPtr>* rowsets = nullptr);
235
236
    static const signed char* get_delete_sign_column_data(const Block& block,
237
                                                          size_t rows_at_least = 0);
238
239
    static Status generate_default_value_block(const TabletSchema& schema,
240
                                               const std::vector<uint32_t>& cids,
241
                                               const std::vector<std::string>& default_values,
242
                                               const Block& ref_block, Block& default_value_block);
243
244
    static Status generate_new_block_for_partial_update(
245
            TabletSchemaSPtr rowset_schema, const PartialUpdateInfo* partial_update_info,
246
            const FixedReadPlan& read_plan_ori, const FixedReadPlan& read_plan_update,
247
            const std::map<RowsetId, RowsetSharedPtr>& rsid_to_rowset, Block* output_block);
248
249
    static Status generate_new_block_for_flexible_partial_update(
250
            TabletSchemaSPtr rowset_schema, const PartialUpdateInfo* partial_update_info,
251
            std::set<uint32_t>& rids_be_overwritten, const FixedReadPlan& read_plan_ori,
252
            const FixedReadPlan& read_plan_update,
253
            const std::map<RowsetId, RowsetSharedPtr>& rsid_to_rowset, Block* output_block);
254
255
    // We use the TabletSchema from the caller because the TabletSchema in the rowset'meta
256
    // may be outdated due to schema change. Also note that the the cids should indicate the indexes
257
    // of the columns in the TabletSchema passed in.
258
    static Status fetch_value_through_row_column(RowsetSharedPtr input_rowset,
259
                                                 const TabletSchema& tablet_schema, uint32_t segid,
260
                                                 const std::vector<uint32_t>& rowids,
261
                                                 const std::vector<uint32_t>& cids, Block& block);
262
263
    static Status fetch_values_by_rowids(RowsetSharedPtr input_rowset,
264
                                         const TabletSchema& tablet_schema, uint32_t segid,
265
                                         const std::vector<uint32_t>& rowids,
266
                                         const std::vector<uint32_t>& cids,
267
                                         MutableColumns& dst_columns);
268
269
    static Status fetch_value_by_rowids(RowsetSharedPtr input_rowset, uint32_t segid,
270
                                        const std::vector<uint32_t>& rowids,
271
                                        const TabletColumn& tablet_column, MutableColumnPtr& dst);
272
273
    virtual Result<std::unique_ptr<RowsetWriter>> create_transient_rowset_writer(
274
            const Rowset& rowset, std::shared_ptr<PartialUpdateInfo> partial_update_info,
275
            int64_t txn_expiration = 0) = 0;
276
277
    static Status update_delete_bitmap(const BaseTabletSPtr& self, TabletTxnInfo* txn_info,
278
                                       int64_t txn_id, int64_t txn_expiration = 0,
279
                                       DeleteBitmapPtr tablet_delete_bitmap = nullptr);
280
    virtual Status save_delete_bitmap(const TabletTxnInfo* txn_info, int64_t txn_id,
281
                                      DeleteBitmapPtr delete_bitmap, RowsetWriter* rowset_writer,
282
                                      const RowsetIdUnorderedSet& cur_rowset_ids,
283
                                      int64_t lock_id = -1, int64_t next_visible_version = -1) = 0;
284
    virtual CalcDeleteBitmapExecutor* calc_delete_bitmap_executor() = 0;
285
286
    void calc_compaction_output_rowset_delete_bitmap(
287
            const std::vector<RowsetSharedPtr>& input_rowsets, const RowsetSharedPtr& output_rowset,
288
            const RowIdConversion& rowid_conversion, uint64_t start_version, uint64_t end_version,
289
            std::set<RowLocation>* missed_rows,
290
            std::map<RowsetSharedPtr, std::list<std::pair<RowLocation, RowLocation>>>* location_map,
291
            const DeleteBitmap& input_delete_bitmap, DeleteBitmap* output_rowset_delete_bitmap);
292
293
    Status check_rowid_conversion(
294
            RowsetSharedPtr dst_rowset,
295
            const std::map<RowsetSharedPtr, std::list<std::pair<RowLocation, RowLocation>>>&
296
                    location_map);
297
298
    static Status update_delete_bitmap_without_lock(
299
            const BaseTabletSPtr& self, const RowsetSharedPtr& rowset,
300
            const std::vector<RowsetSharedPtr>* specified_base_rowsets = nullptr);
301
302
    using DeleteBitmapKeyRanges =
303
            std::vector<std::tuple<DeleteBitmap::BitmapKey, DeleteBitmap::BitmapKey>>;
304
    void agg_delete_bitmap_for_stale_rowsets(
305
            Version version, DeleteBitmapKeyRanges& remove_delete_bitmap_key_ranges);
306
    void check_agg_delete_bitmap_for_stale_rowsets(int64_t& useless_rowset_count,
307
                                                   int64_t& useless_rowset_version_count);
308
    ////////////////////////////////////////////////////////////////////////////
309
    // end MoW functions
310
    ////////////////////////////////////////////////////////////////////////////
311
312
    RowsetSharedPtr get_rowset(const RowsetId& rowset_id);
313
314
    std::vector<RowsetSharedPtr> get_snapshot_rowset(bool include_stale_rowset = false) const;
315
316
    virtual void clear_cache() = 0;
317
318
    // Find the first consecutive empty rowsets. output->size() >= limit
319
    void calc_consecutive_empty_rowsets(std::vector<RowsetSharedPtr>* empty_rowsets,
320
                                        const std::vector<RowsetSharedPtr>& candidate_rowsets,
321
                                        int64_t limit);
322
323
    void traverse_rowsets(std::function<void(const RowsetSharedPtr&)> visitor,
324
10
                          bool include_stale = false) {
325
10
        std::shared_lock rlock(_meta_lock);
326
10
        traverse_rowsets_unlocked(visitor, include_stale);
327
10
    }
328
329
    void traverse_rowsets_unlocked(std::function<void(const RowsetSharedPtr&)> visitor,
330
36
                                   bool include_stale = false) const {
331
204
        for (auto& [v, rs] : _rs_version_map) {
332
204
            visitor(rs);
333
204
        }
334
36
        if (!include_stale) return;
335
81
        for (auto& [v, rs] : _stale_rs_version_map) {
336
81
            visitor(rs);
337
81
        }
338
15
    }
339
340
    Status calc_file_crc(uint32_t* crc_value, int64_t start_version, int64_t end_version,
341
                         uint32_t* rowset_count, int64_t* file_count);
342
343
    Status show_nested_index_file(std::string* json_meta);
344
345
7.30k
    TabletUid tablet_uid() const { return _tablet_meta->tablet_uid(); }
346
481
    TabletInfo get_tablet_info() const { return TabletInfo(tablet_id(), tablet_uid()); }
347
348
    void get_base_rowset_delete_bitmap_count(
349
            uint64_t* max_base_rowset_delete_bitmap_score,
350
            int64_t* max_base_rowset_delete_bitmap_score_tablet_id);
351
352
4
    virtual Status check_delete_bitmap_cache(int64_t txn_id, DeleteBitmap* expected_delete_bitmap) {
353
4
        return Status::OK();
354
4
    }
355
356
    void prefill_dbm_agg_cache(const RowsetSharedPtr& rowset, int64_t version);
357
    void prefill_dbm_agg_cache_after_compaction(const RowsetSharedPtr& output_rowset);
358
359
    [[nodiscard]] Result<CaptureRowsetResult> capture_consistent_rowsets_unlocked(
360
            const Version& version_range, const CaptureRowsetOps& options) const;
361
362
    [[nodiscard]] virtual Result<std::vector<Version>> capture_consistent_versions_unlocked(
363
            const Version& version_range, const CaptureRowsetOps& options) const;
364
365
    [[nodiscard]] Result<std::vector<RowSetSplits>> capture_rs_readers_unlocked(
366
            const Version& version_range, const CaptureRowsetOps& options) const;
367
368
    [[nodiscard]] Result<TabletReadSource> capture_read_source(const Version& version_range,
369
                                                               const CaptureRowsetOps& options);
370
371
protected:
372
    // Find the missed versions until the spec_version.
373
    //
374
    // for example:
375
    //     [0-4][5-5][8-8][9-9][14-14]
376
    // for cloud, if spec_version = 12, it will return [6-7],[10-12]
377
    // for local, if spec_version = 12, it will return [6, 6], [7, 7], [10, 10], [11, 11], [12, 12]
378
    virtual Versions calc_missed_versions(int64_t spec_version,
379
                                          Versions existing_versions) const = 0;
380
381
    void _print_missed_versions(const Versions& missed_versions) const;
382
    bool _reconstruct_version_tracker_if_necessary();
383
384
    static void _rowset_ids_difference(const RowsetIdUnorderedSet& cur,
385
                                       const RowsetIdUnorderedSet& pre,
386
                                       RowsetIdUnorderedSet* to_add, RowsetIdUnorderedSet* to_del);
387
388
    // We can only know if a key is excluded from the segment
389
    // based on strictly order compare result with segments key bounds
390
    static bool _key_is_not_in_segment(Slice key, const KeyBoundsPB& segment_key_bounds,
391
                                       bool is_segments_key_bounds_truncated);
392
393
    Status sort_block(Block& in_block, Block& output_block,
394
                      std::vector<uint32_t>* permutation = nullptr);
395
396
    Result<CaptureRowsetResult> _remote_capture_rowsets(const Version& version_range) const;
397
398
    mutable BthreadSharedMutex _meta_lock;
399
    TimestampedVersionTracker _timestamped_version_tracker;
400
401
    // After version 0.13, all newly created rowsets are saved in _rs_version_map.
402
    // And if rowset being compacted, the old rowsets will be saved in _stale_rs_version_map;
403
    std::unordered_map<Version, RowsetSharedPtr, HashOfVersion> _rs_version_map;
404
    // This variable _stale_rs_version_map is used to record these rowsets which are be compacted.
405
    // These _stale rowsets are been removed when rowsets' pathVersion is expired,
406
    // this policy is judged and computed by TimestampedVersionTracker.
407
    std::unordered_map<Version, RowsetSharedPtr, HashOfVersion> _stale_rs_version_map;
408
    const TabletMetaSharedPtr _tablet_meta;
409
    TabletSchemaSPtr _max_version_schema;
410
411
    // `_alter_failed` is used to indicate whether the tablet failed to perform a schema change
412
    std::atomic<bool> _alter_failed = false;
413
414
    // metrics of this tablet
415
    std::shared_ptr<MetricEntity> _metric_entity;
416
417
protected:
418
    std::timed_mutex _schema_change_lock;
419
420
public:
421
    IntCounter* query_scan_bytes = nullptr;
422
    IntCounter* query_scan_rows = nullptr;
423
    IntCounter* query_scan_count = nullptr;
424
    IntCounter* flush_bytes = nullptr;
425
    IntCounter* flush_finish_count = nullptr;
426
    std::atomic<int64_t> published_count = 0;
427
    std::atomic<int64_t> read_block_count = 0;
428
    std::atomic<int64_t> write_count = 0;
429
    std::atomic<int64_t> compaction_count = 0;
430
431
    CompactionStage compaction_stage = CompactionStage::NOT_SCHEDULED;
432
    // Separate sample_infos for each compaction type to avoid race condition
433
    // when different types of compaction run concurrently on the same tablet
434
    std::mutex cumu_sample_info_lock;
435
    std::mutex base_sample_info_lock;
436
    std::mutex full_sample_info_lock;
437
    std::vector<CompactionSampleInfo> cumu_sample_infos;
438
    std::vector<CompactionSampleInfo> base_sample_infos;
439
    std::vector<CompactionSampleInfo> full_sample_infos;
440
    Status last_compaction_status = Status::OK();
441
442
4.56k
    std::mutex& get_sample_info_lock(ReaderType reader_type) {
443
4.56k
        switch (reader_type) {
444
1.58k
        case ReaderType::READER_CUMULATIVE_COMPACTION:
445
1.58k
            return cumu_sample_info_lock;
446
1.70k
        case ReaderType::READER_BASE_COMPACTION:
447
1.70k
            return base_sample_info_lock;
448
1.50k
        case ReaderType::READER_FULL_COMPACTION:
449
1.50k
            return full_sample_info_lock;
450
0
        default:
451
            // For other compaction types, use base_sample_info_lock as default
452
0
            return base_sample_info_lock;
453
4.56k
        }
454
4.56k
    }
455
456
4.42k
    std::vector<CompactionSampleInfo>& get_sample_infos(ReaderType reader_type) {
457
4.42k
        switch (reader_type) {
458
1.59k
        case ReaderType::READER_CUMULATIVE_COMPACTION:
459
1.59k
            return cumu_sample_infos;
460
1.70k
        case ReaderType::READER_BASE_COMPACTION:
461
1.70k
            return base_sample_infos;
462
1.50k
        case ReaderType::READER_FULL_COMPACTION:
463
1.50k
            return full_sample_infos;
464
3
        default:
465
            // For other compaction types, use base_sample_infos as default
466
3
            return base_sample_infos;
467
4.42k
        }
468
4.42k
    }
469
470
    // Density ratio for sparse optimization (non_null_cells / total_cells)
471
    // Value range: [0.0, 1.0], smaller value means more sparse
472
    // Default 1.0 means no history data, will not enable sparse optimization initially
473
    std::atomic<double> compaction_density {1.0};
474
};
475
476
struct CaptureRowsetOps {
477
    bool skip_missing_versions = false;
478
    bool quiet = false;
479
    bool include_stale_rowsets = true;
480
    bool enable_fetch_rowsets_from_peers = false;
481
482
    // ======== only take effect in cloud mode ========
483
484
    // Enable preference for cached/warmed-up rowsets when building version paths.
485
    // When enabled, the capture process will prioritize already cached rowsets
486
    // to avoid cold data reads and improve query performance.
487
    bool enable_prefer_cached_rowset {false};
488
489
    // Query freshness tolerance in milliseconds.
490
    // Defines the time window for considering data as "fresh enough".
491
    // Rowsets that became visible within this time range can be skipped if not warmed up,
492
    // but older rowsets (before current_time - query_freshness_tolerance_ms) that are
493
    // not warmed up will trigger fallback to normal capture.
494
    // Set to -1 to disable freshness tolerance checking.
495
    int64_t query_freshness_tolerance_ms {-1};
496
};
497
498
struct CaptureRowsetResult {
499
    std::vector<RowsetSharedPtr> rowsets;
500
    std::shared_ptr<DeleteBitmap> delete_bitmap;
501
};
502
503
struct TabletReadSource {
504
    std::vector<RowSetSplits> rs_splits;
505
    std::vector<RowsetMetaSharedPtr> delete_predicates;
506
    std::shared_ptr<DeleteBitmap> delete_bitmap;
507
    // Fill delete predicates with `rs_splits`
508
    void fill_delete_predicates();
509
};
510
511
} /* namespace doris */