Coverage Report

Created: 2026-07-15 15:08

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