Coverage Report

Created: 2026-09-17 20:05

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