Coverage Report

Created: 2026-07-13 21:16

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