Coverage Report

Created: 2026-06-02 12:18

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/root/doris/be/src/cloud/cloud_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 <memory>
21
22
#include "olap/base_tablet.h"
23
#include "olap/partial_update_info.h"
24
#include "olap/rowset/rowset.h"
25
26
namespace doris {
27
28
class CloudStorageEngine;
29
30
enum class WarmUpTriggerSource : int { NONE, SYNC_ROWSET, EVENT_DRIVEN, JOB };
31
32
enum class WarmUpProgress : int { NONE, DOING, DONE };
33
34
struct WarmUpState {
35
    WarmUpTriggerSource trigger_source {WarmUpTriggerSource::NONE};
36
    WarmUpProgress progress {WarmUpProgress::NONE};
37
38
56
    bool operator==(const WarmUpState& other) const {
39
56
        return trigger_source == other.trigger_source && progress == other.progress;
40
56
    }
41
};
42
43
struct SyncRowsetStats {
44
    int64_t get_remote_rowsets_num {0};
45
    int64_t get_remote_rowsets_rpc_ns {0};
46
47
    int64_t get_local_delete_bitmap_rowsets_num {0};
48
    int64_t get_remote_delete_bitmap_rowsets_num {0};
49
    int64_t get_remote_delete_bitmap_key_count {0};
50
    int64_t get_remote_delete_bitmap_bytes {0};
51
    int64_t get_remote_delete_bitmap_rpc_ns {0};
52
53
    int64_t get_remote_tablet_meta_rpc_ns {0};
54
    int64_t tablet_meta_cache_hit {0};
55
    int64_t tablet_meta_cache_miss {0};
56
57
    int64_t bthread_schedule_delay_ns {0};
58
    int64_t meta_lock_wait_ns {0}; // _meta_lock (std::shared_mutex) wait across all acquisitions
59
    int64_t sync_meta_lock_wait_ns {
60
            0}; // _sync_meta_lock (bthread::Mutex) wait across all acquisitions
61
};
62
63
struct SyncOptions {
64
    bool warmup_delta_data = false;
65
    bool sync_delete_bitmap = true;
66
    bool full_sync = false;
67
    bool merge_schema = false;
68
    int64_t query_version = -1;
69
};
70
71
struct RecycledRowsets {
72
    RowsetId rowset_id;
73
    int64_t num_segments;
74
    std::vector<std::string> index_file_names;
75
};
76
77
class CloudTablet final : public BaseTablet {
78
public:
79
    CloudTablet(CloudStorageEngine& engine, TabletMetaSharedPtr tablet_meta);
80
81
    ~CloudTablet() override;
82
83
    bool exceed_version_limit(int32_t limit) override;
84
85
    Result<std::unique_ptr<RowsetWriter>> create_rowset_writer(RowsetWriterContext& context,
86
                                                               bool vertical) override;
87
88
    Status capture_rs_readers(const Version& spec_version, std::vector<RowSetSplits>* rs_splits,
89
                              const CaptureRowsetOps& opts) override;
90
91
    [[nodiscard]] Result<std::vector<Version>> capture_consistent_versions_unlocked(
92
            const Version& version_range, const CaptureRowsetOps& options) const override;
93
94
    // Capture versions with cache preference optimization.
95
    // This method prioritizes using cached/warmed-up rowsets when building version paths,
96
    // avoiding cold data reads when possible. It uses capture_consistent_versions_prefer_cache
97
    // to find a consistent version path that prefers already warmed-up rowsets.
98
    Result<std::vector<Version>> capture_versions_prefer_cache(const Version& spec_version) const;
99
100
    // Capture versions with query freshness tolerance.
101
    // This method finds a consistent version path where all rowsets are warmed up,
102
    // but allows fallback to normal capture if there are newer rowsets that should be
103
    // visible (based on freshness tolerance) but haven't been warmed up yet.
104
    // For merge-on-write tables, uses special validation to ensure data correctness.
105
    //
106
    // IMPORTANT: The returned version may be smaller than the requested version if newer
107
    // data hasn't been warmed up yet. This can cause different tablets in the same query
108
    // to read from different versions, potentially leading to inconsistent query results.
109
    //
110
    // @param options.query_freshness_tolerance_ms: Time tolerance in milliseconds. Rowsets that
111
    //        became visible within this time range (after current_time - query_freshness_tolerance_ms)
112
    //        can be skipped if not warmed up. However, if older rowsets (before this time point)
113
    //        are not warmed up, the method will fallback to normal capture.
114
    Result<std::vector<Version>> capture_versions_with_freshness_tolerance(
115
            const Version& spec_version, const CaptureRowsetOps& options) const;
116
117
0
    size_t tablet_footprint() override {
118
0
        return _approximate_data_size.load(std::memory_order_relaxed);
119
0
    }
120
121
    std::string tablet_path() const override;
122
123
    // clang-format off
124
14
    int64_t fetch_add_approximate_num_rowsets (int64_t x) { return _approximate_num_rowsets .fetch_add(x, std::memory_order_relaxed); }
125
0
    int64_t fetch_add_approximate_num_segments(int64_t x) { return _approximate_num_segments.fetch_add(x, std::memory_order_relaxed); }
126
0
    int64_t fetch_add_approximate_num_rows    (int64_t x) { return _approximate_num_rows    .fetch_add(x, std::memory_order_relaxed); }
127
0
    int64_t fetch_add_approximate_data_size   (int64_t x) { return _approximate_data_size   .fetch_add(x, std::memory_order_relaxed); }
128
2
    int64_t fetch_add_approximate_cumu_num_rowsets (int64_t x) { return _approximate_cumu_num_rowsets.fetch_add(x, std::memory_order_relaxed); }
129
0
    int64_t fetch_add_approximate_cumu_num_deltas   (int64_t x) { return _approximate_cumu_num_deltas.fetch_add(x, std::memory_order_relaxed); }
130
    // clang-format on
131
132
    // meta lock must be held when calling this function
133
    void reset_approximate_stats(int64_t num_rowsets, int64_t num_segments, int64_t num_rows,
134
                                 int64_t data_size);
135
136
    // return a json string to show the compaction status of this tablet
137
    void get_compaction_status(std::string* json_result);
138
139
    // Synchronize the rowsets from meta service.
140
    // If tablet state is not `TABLET_RUNNING`, sync tablet meta and all visible rowsets.
141
    // If `query_version` > 0 and local max_version of the tablet >= `query_version`, do nothing.
142
    // If 'need_download_data_async' is true, it means that we need to download the new version
143
    // rowsets datum async.
144
    Status sync_rowsets(const SyncOptions& options = {}, SyncRowsetStats* stats = nullptr);
145
146
    // Synchronize the tablet meta from meta service.
147
    Status sync_meta();
148
149
    // If `version_overlap` is true, function will delete rowsets with overlapped version in this tablet.
150
    // If 'warmup_delta_data' is true, download the new version rowset data in background.
151
    // MUST hold EXCLUSIVE `_meta_lock`.
152
    // If 'need_download_data_async' is true, it means that we need to download the new version
153
    // rowsets datum async.
154
    void add_rowsets(std::vector<RowsetSharedPtr> to_add, bool version_overlap,
155
                     std::unique_lock<std::shared_mutex>& meta_lock,
156
                     bool warmup_delta_data = false);
157
158
    // MUST hold EXCLUSIVE `_meta_lock`.
159
    void delete_rowsets(const std::vector<RowsetSharedPtr>& to_delete,
160
                        std::unique_lock<std::shared_mutex>& meta_lock);
161
162
    // Like delete_rowsets, but also removes edges from the version graph.
163
    // Used by schema change to prevent the greedy capture algorithm from
164
    // preferring stale compaction rowsets over individual SC output rowsets.
165
    // MUST hold EXCLUSIVE `_meta_lock`.
166
    void delete_rowsets_for_schema_change(const std::vector<RowsetSharedPtr>& to_delete,
167
                                          std::unique_lock<std::shared_mutex>& meta_lock,
168
                                          bool recycle_deleted_rowsets = true);
169
170
    // Replace local rowsets in [2, alter_version] with schema change output rowsets.
171
    // Existing SC output rowsets are kept; other local/double-write/compaction rowsets
172
    // in this version range are removed from both _rs_version_map and version graph.
173
    // recycle_deleted_rowsets should only be true for the real tablet; temporary
174
    // schema-change delete-bitmap tablets only need to normalize their local graph.
175
    // MUST hold EXCLUSIVE `_meta_lock`.
176
    void replace_rowsets_with_schema_change_output(
177
            const std::vector<RowsetSharedPtr>& output_rowsets, int64_t alter_version,
178
            std::unique_lock<std::shared_mutex>& meta_lock, const char* stage,
179
            bool recycle_deleted_rowsets);
180
181
    // When the tablet is dropped, we need to recycle cached data:
182
    // 1. The data in file cache
183
    // 2. The memory in tablet cache
184
    void clear_cache() override;
185
186
    // Return number of deleted stale rowsets
187
    uint64_t delete_expired_stale_rowsets();
188
189
5
    bool has_stale_rowsets() const { return !_stale_rs_version_map.empty(); }
190
191
    int64_t get_cloud_base_compaction_score() const;
192
    int64_t get_cloud_cumu_compaction_score() const;
193
194
8
    int64_t max_version_unlocked() const override { return _max_version; }
195
3
    int64_t base_compaction_cnt() const { return _base_compaction_cnt; }
196
3
    int64_t cumulative_compaction_cnt() const { return _cumulative_compaction_cnt; }
197
0
    int64_t full_compaction_cnt() const { return _full_compaction_cnt; }
198
10
    int64_t cumulative_layer_point() const {
199
10
        return _cumulative_point.load(std::memory_order_relaxed);
200
10
    }
201
202
0
    void set_base_compaction_cnt(int64_t cnt) { _base_compaction_cnt = cnt; }
203
0
    void set_cumulative_compaction_cnt(int64_t cnt) { _cumulative_compaction_cnt = cnt; }
204
0
    void set_full_compaction_cnt(int64_t cnt) { _full_compaction_cnt = cnt; }
205
    void set_cumulative_layer_point(int64_t new_point);
206
207
1
    int64_t last_cumu_compaction_failure_time() { return _last_cumu_compaction_failure_millis; }
208
3
    void set_last_cumu_compaction_failure_time(int64_t millis) {
209
3
        _last_cumu_compaction_failure_millis = millis;
210
3
    }
211
212
2
    int64_t last_base_compaction_failure_time() { return _last_base_compaction_failure_millis; }
213
3
    void set_last_base_compaction_failure_time(int64_t millis) {
214
3
        _last_base_compaction_failure_millis = millis;
215
3
    }
216
217
0
    int64_t last_full_compaction_failure_time() { return _last_full_compaction_failure_millis; }
218
0
    void set_last_full_compaction_failure_time(int64_t millis) {
219
0
        _last_full_compaction_failure_millis = millis;
220
0
    }
221
222
0
    int64_t last_cumu_compaction_success_time() { return _last_cumu_compaction_success_millis; }
223
0
    void set_last_cumu_compaction_success_time(int64_t millis) {
224
0
        _last_cumu_compaction_success_millis = millis;
225
0
    }
226
227
0
    int64_t last_base_compaction_success_time() { return _last_base_compaction_success_millis; }
228
0
    void set_last_base_compaction_success_time(int64_t millis) {
229
0
        _last_base_compaction_success_millis = millis;
230
0
    }
231
232
0
    int64_t last_full_compaction_success_time() { return _last_full_compaction_success_millis; }
233
0
    void set_last_full_compaction_success_time(int64_t millis) {
234
0
        _last_full_compaction_success_millis = millis;
235
0
    }
236
237
0
    int64_t last_cumu_compaction_schedule_time() { return _last_cumu_compaction_schedule_millis; }
238
0
    void set_last_cumu_compaction_schedule_time(int64_t millis) {
239
0
        _last_cumu_compaction_schedule_millis = millis;
240
0
    }
241
242
0
    int64_t last_base_compaction_schedule_time() { return _last_base_compaction_schedule_millis; }
243
0
    void set_last_base_compaction_schedule_time(int64_t millis) {
244
0
        _last_base_compaction_schedule_millis = millis;
245
0
    }
246
247
0
    int64_t last_full_compaction_schedule_time() { return _last_full_compaction_schedule_millis; }
248
0
    void set_last_full_compaction_schedule_time(int64_t millis) {
249
0
        _last_full_compaction_schedule_millis = millis;
250
0
    }
251
252
0
    void set_last_cumu_compaction_status(std::string status) {
253
0
        _last_cumu_compaction_status = std::move(status);
254
0
    }
255
256
0
    std::string get_last_cumu_compaction_status() { return _last_cumu_compaction_status; }
257
258
0
    void set_last_base_compaction_status(std::string status) {
259
0
        _last_base_compaction_status = std::move(status);
260
0
    }
261
262
0
    std::string get_last_base_compaction_status() { return _last_base_compaction_status; }
263
264
0
    void set_last_full_compaction_status(std::string status) {
265
0
        _last_full_compaction_status = std::move(status);
266
0
    }
267
268
0
    std::string get_last_full_compaction_status() { return _last_full_compaction_status; }
269
270
9
    int64_t alter_version() const { return _alter_version; }
271
7
    void set_alter_version(int64_t alter_version) { _alter_version = alter_version; }
272
273
    // Last active cluster info for compaction read-write separation
274
16
    std::string last_active_cluster_id() const {
275
16
        std::shared_lock lock(_cluster_info_mutex);
276
16
        return _last_active_cluster_id;
277
16
    }
278
3
    int64_t last_active_time_ms() const {
279
3
        std::shared_lock lock(_cluster_info_mutex);
280
3
        return _last_active_time_ms;
281
3
    }
282
11
    void set_last_active_cluster_info(const std::string& cluster_id, int64_t time_ms) {
283
11
        std::unique_lock lock(_cluster_info_mutex);
284
11
        _last_active_cluster_id = cluster_id;
285
11
        _last_active_time_ms = time_ms;
286
11
    }
287
288
    std::vector<RowsetSharedPtr> pick_candidate_rowsets_to_base_compaction();
289
290
9
    inline Version max_version() const {
291
9
        std::shared_lock rdlock(_meta_lock);
292
9
        return _tablet_meta->max_version();
293
9
    }
294
295
9
    int64_t base_size() const { return _base_size; }
296
297
    std::vector<RowsetSharedPtr> pick_candidate_rowsets_to_full_compaction();
298
    Result<RowsetSharedPtr> pick_a_rowset_for_index_change(int schema_version,
299
                                                           bool& is_base_rowset);
300
    Status check_rowset_schema_for_build_index(std::vector<TColumn>& columns, int schema_version);
301
302
0
    std::mutex& get_base_compaction_lock() { return _base_compaction_lock; }
303
0
    std::mutex& get_cumulative_compaction_lock() { return _cumulative_compaction_lock; }
304
305
    Result<std::unique_ptr<RowsetWriter>> create_transient_rowset_writer(
306
            const Rowset& rowset, std::shared_ptr<PartialUpdateInfo> partial_update_info,
307
            int64_t txn_expiration = 0) override;
308
309
    CalcDeleteBitmapExecutor* calc_delete_bitmap_executor() override;
310
311
    Status save_delete_bitmap(const TabletTxnInfo* txn_info, int64_t txn_id,
312
                              DeleteBitmapPtr delete_bitmap, RowsetWriter* rowset_writer,
313
                              const RowsetIdUnorderedSet& cur_rowset_ids, int64_t lock_id = -1,
314
                              int64_t next_visible_version = -1) override;
315
316
    Status save_delete_bitmap_to_ms(int64_t cur_version, int64_t txn_id,
317
                                    DeleteBitmapPtr delete_bitmap, int64_t lock_id,
318
                                    int64_t next_visible_version, RowsetSharedPtr rowset);
319
320
    Status calc_delete_bitmap_for_compaction(const std::vector<RowsetSharedPtr>& input_rowsets,
321
                                             const RowsetSharedPtr& output_rowset,
322
                                             const RowIdConversion& rowid_conversion,
323
                                             ReaderType compaction_type, int64_t merged_rows,
324
                                             int64_t filtered_rows, int64_t initiator,
325
                                             DeleteBitmapPtr& output_rowset_delete_bitmap,
326
                                             bool allow_delete_in_cumu_compaction,
327
                                             int64_t& get_delete_bitmap_lock_start_time);
328
329
    // Find the missed versions until the spec_version.
330
    //
331
    // for example:
332
    //     [0-4][5-5][8-8][9-9][14-14]
333
    // if spec_version = 12, it will return [6-7],[10-12]
334
    Versions calc_missed_versions(int64_t spec_version, Versions existing_versions) const override;
335
336
0
    std::mutex& get_rowset_update_lock() { return _rowset_update_lock; }
337
338
9
    bthread::Mutex& get_sync_meta_lock() { return _sync_meta_lock; }
339
340
150
    const auto& rowset_map() const { return _rs_version_map; }
341
342
    int64_t last_sync_time_s = 0;
343
    int64_t last_load_time_ms = 0;
344
    int64_t last_base_compaction_success_time_ms = 0;
345
    int64_t last_cumu_compaction_success_time_ms = 0;
346
    int64_t last_cumu_no_suitable_version_ms = 0;
347
    int64_t last_access_time_ms = 0;
348
349
    std::atomic<int64_t> local_read_time_us = 0;
350
    std::atomic<int64_t> remote_read_time_us = 0;
351
    std::atomic<int64_t> exec_compaction_time_us = 0;
352
353
    void build_tablet_report_info(TTabletInfo* tablet_info);
354
355
    // check that if the delete bitmap in delete bitmap cache has the same cardinality with the expected_delete_bitmap's
356
    Status check_delete_bitmap_cache(int64_t txn_id, DeleteBitmap* expected_delete_bitmap) override;
357
358
    void agg_delete_bitmap_for_compaction(int64_t start_version, int64_t end_version,
359
                                          const std::vector<RowsetSharedPtr>& pre_rowsets,
360
                                          DeleteBitmapPtr& new_delete_bitmap,
361
                                          std::map<std::string, int64_t>& pre_rowset_to_versions);
362
363
    bool need_remove_unused_rowsets();
364
365
    void add_unused_rowsets(const std::vector<RowsetSharedPtr>& rowsets);
366
    void remove_unused_rowsets();
367
368
    // For each given rowset not in active use, clears its file cache and returns its
369
    // ID, segment count, and index file names as RecycledRowsets entries.
370
    static std::vector<RecycledRowsets> recycle_cached_data(
371
            const std::vector<RowsetSharedPtr>& rowsets);
372
373
    // Add warmup state management
374
    WarmUpState get_rowset_warmup_state(RowsetId rowset_id);
375
    bool add_rowset_warmup_state(
376
            const RowsetMeta& rowset, WarmUpTriggerSource source,
377
            std::chrono::steady_clock::time_point start_tp = std::chrono::steady_clock::now());
378
    bool update_rowset_warmup_state_inverted_idx_num(WarmUpTriggerSource source, RowsetId rowset_id,
379
                                                     int64_t delta);
380
    bool update_rowset_warmup_state_inverted_idx_num_unlocked(WarmUpTriggerSource source,
381
                                                              RowsetId rowset_id, int64_t delta);
382
    WarmUpState complete_rowset_segment_warmup(WarmUpTriggerSource trigger_source,
383
                                               RowsetId rowset_id, Status status,
384
                                               int64_t segment_num, int64_t inverted_idx_num);
385
386
    bool is_rowset_warmed_up(const RowsetId& rowset_id) const;
387
388
    void add_warmed_up_rowset(const RowsetId& rowset_id);
389
    // Test helper: add a rowset to the warmup state map with DOING progress,
390
    // so that is_rowset_warmed_up() returns false for it.
391
    void add_not_warmed_up_rowset(const RowsetId& rowset_id);
392
393
5
    std::string rowset_warmup_digest() const {
394
5
        std::string res;
395
104
        auto add_log = [&](const RowsetSharedPtr& rs) {
396
104
            auto tmp = fmt::format("{}{}", rs->rowset_id().to_string(), rs->version().to_string());
397
104
            if (_rowset_warm_up_states.contains(rs->rowset_id())) {
398
104
                tmp += fmt::format(
399
104
                        ", progress={}, segments_warmed_up={}/{}, inverted_idx_warmed_up={}/{}",
400
104
                        _rowset_warm_up_states.at(rs->rowset_id()).state.progress,
401
104
                        _rowset_warm_up_states.at(rs->rowset_id()).num_segments_warmed_up,
402
104
                        _rowset_warm_up_states.at(rs->rowset_id()).num_segments,
403
104
                        _rowset_warm_up_states.at(rs->rowset_id()).num_inverted_idx_warmed_up,
404
104
                        _rowset_warm_up_states.at(rs->rowset_id()).num_inverted_idx);
405
104
            }
406
104
            res += fmt::format("[{}],", tmp);
407
104
        };
408
5
        traverse_rowsets_unlocked(add_log, true);
409
5
        return res;
410
5
    }
411
412
private:
413
    // FIXME(plat1ko): No need to record base size if rowsets are ordered by version
414
    void update_base_size(const Rowset& rs);
415
416
    Status sync_if_not_running(SyncRowsetStats* stats = nullptr);
417
418
    bool add_rowset_warmup_state_unlocked(
419
            const RowsetMeta& rowset, WarmUpTriggerSource source,
420
            std::chrono::steady_clock::time_point start_tp = std::chrono::steady_clock::now());
421
422
    // used by capture_rs_reader_xxx functions
423
    bool rowset_is_warmed_up_unlocked(int64_t start_version, int64_t end_version) const;
424
425
    CloudStorageEngine& _engine;
426
427
    // this mutex MUST ONLY be used when sync meta
428
    bthread::Mutex _sync_meta_lock;
429
    // ATTENTION: lock order should be: _sync_meta_lock -> _meta_lock
430
431
    std::atomic<int64_t> _cumulative_point {-1};
432
    std::atomic<int64_t> _approximate_num_rowsets {-1};
433
    std::atomic<int64_t> _approximate_num_segments {-1};
434
    std::atomic<int64_t> _approximate_num_rows {-1};
435
    std::atomic<int64_t> _approximate_data_size {-1};
436
    std::atomic<int64_t> _approximate_cumu_num_rowsets {-1};
437
    // Number of sorted arrays (e.g. for rowset with N segments, if rowset is overlapping, delta is N, otherwise 1) after cumu point
438
    std::atomic<int64_t> _approximate_cumu_num_deltas {-1};
439
440
    // timestamp of last cumu compaction failure
441
    std::atomic<int64_t> _last_cumu_compaction_failure_millis;
442
    // timestamp of last base compaction failure
443
    std::atomic<int64_t> _last_base_compaction_failure_millis;
444
    // timestamp of last full compaction failure
445
    std::atomic<int64_t> _last_full_compaction_failure_millis;
446
    // timestamp of last cumu compaction success
447
    std::atomic<int64_t> _last_cumu_compaction_success_millis;
448
    // timestamp of last base compaction success
449
    std::atomic<int64_t> _last_base_compaction_success_millis;
450
    // timestamp of last full compaction success
451
    std::atomic<int64_t> _last_full_compaction_success_millis;
452
    // timestamp of last cumu compaction schedule time
453
    std::atomic<int64_t> _last_cumu_compaction_schedule_millis;
454
    // timestamp of last base compaction schedule time
455
    std::atomic<int64_t> _last_base_compaction_schedule_millis;
456
    // timestamp of last full compaction schedule time
457
    std::atomic<int64_t> _last_full_compaction_schedule_millis;
458
459
    std::string _last_cumu_compaction_status;
460
    std::string _last_base_compaction_status;
461
    std::string _last_full_compaction_status;
462
463
    int64_t _base_compaction_cnt = 0;
464
    int64_t _cumulative_compaction_cnt = 0;
465
    int64_t _full_compaction_cnt = 0;
466
    int64_t _max_version = -1;
467
    int64_t _base_size = 0;
468
    int64_t _alter_version = -1;
469
470
    std::mutex _base_compaction_lock;
471
    std::mutex _cumulative_compaction_lock;
472
473
    // To avoid multiple calc delete bitmap tasks on same (txn_id, tablet_id) with different
474
    // signatures being executed concurrently, we use _rowset_update_lock to serialize them
475
    mutable std::mutex _rowset_update_lock;
476
477
    // unused_rowsets, [start_version, end_version]
478
    std::mutex _gc_mutex;
479
    std::unordered_map<RowsetId, RowsetSharedPtr> _unused_rowsets;
480
    std::vector<std::pair<std::vector<RowsetId>, DeleteBitmapKeyRanges>> _unused_delete_bitmap;
481
482
    // for warm up states management
483
    struct RowsetWarmUpInfo {
484
        WarmUpState state;
485
        int64_t num_segments = 0;
486
        int64_t num_inverted_idx = 0;
487
        int64_t num_segments_warmed_up = 0;
488
        int64_t num_inverted_idx_warmed_up = 0;
489
        std::chrono::steady_clock::time_point start_tp;
490
491
18
        void done(int64_t num_segments, int64_t num_inverted_idx) {
492
18
            num_segments_warmed_up += num_segments;
493
18
            num_inverted_idx_warmed_up += num_inverted_idx;
494
18
            update_state();
495
18
        }
496
497
52
        bool has_finished() const {
498
52
            return (num_segments_warmed_up >= num_segments) &&
499
52
                   (num_inverted_idx_warmed_up >= num_inverted_idx);
500
52
        }
501
502
        void update_state();
503
    };
504
    std::unordered_map<RowsetId, RowsetWarmUpInfo> _rowset_warm_up_states;
505
506
    mutable std::shared_mutex _warmed_up_rowsets_mutex;
507
    std::unordered_set<RowsetId> _warmed_up_rowsets;
508
509
    // Cluster info for compaction read-write separation
510
    mutable std::shared_mutex _cluster_info_mutex;
511
    std::string _last_active_cluster_id;
512
    int64_t _last_active_time_ms {0};
513
};
514
515
using CloudTabletSPtr = std::shared_ptr<CloudTablet>;
516
517
} // namespace doris