Coverage Report

Created: 2026-04-11 00:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/cloud/cloud_committed_rs_mgr.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 <map>
21
#include <memory>
22
#include <shared_mutex>
23
24
#include "common/status.h"
25
#include "storage/rowset/rowset_fwd.h"
26
#include "util/countdown_latch.h"
27
28
namespace doris {
29
class Thread;
30
31
// Manages temporary rowset meta for cloud storage transactions in memory.
32
// This cache stores rowset meta produced during import operations after they
33
// are committed to MS. After the load txn was committed in MS finally, FE/BE will
34
// notifies the final version/visible_ts, BE can update and promote these
35
// temporary rowsets to the tablet meta without fetching from MS in later sync_rowsets().
36
class CloudCommittedRSMgr {
37
public:
38
    CloudCommittedRSMgr();
39
    ~CloudCommittedRSMgr();
40
41
    Status init();
42
43
    void add_committed_rowset(int64_t txn_id, int64_t tablet_id, RowsetMetaSharedPtr rowset_meta,
44
                              int64_t expiration_time);
45
46
    Result<std::pair<RowsetMetaSharedPtr, int64_t>> get_committed_rowset(int64_t txn_id,
47
                                                                         int64_t tablet_id);
48
49
    void remove_committed_rowset(int64_t txn_id, int64_t tablet_id);
50
51
    void remove_expired_committed_rowsets();
52
53
    void mark_empty_rowset(int64_t txn_id, int64_t tablet_id, int64_t txn_expiration);
54
55
private:
56
    void _clean_thread_callback();
57
58
    struct TxnTabletKey {
59
        int64_t txn_id;
60
        int64_t tablet_id;
61
62
        TxnTabletKey(int64_t txn_id_, int64_t tablet_id_)
63
87
                : txn_id(txn_id_), tablet_id(tablet_id_) {}
64
65
490
        auto operator<=>(const TxnTabletKey&) const = default;
66
    };
67
68
    struct CommittedRowsetValue {
69
        RowsetMetaSharedPtr rowset_meta;
70
        int64_t expiration_time; // seconds since epoch
71
72
        CommittedRowsetValue(RowsetMetaSharedPtr rowset_meta_, int64_t expiration_time_)
73
29
                : rowset_meta(std::move(rowset_meta_)), expiration_time(expiration_time_) {}
74
    };
75
76
    // Map: <txn_id, tablet_id> -> <rowset_meta, expiration_time>
77
    std::map<TxnTabletKey, CommittedRowsetValue> _committed_rs_map;
78
    // Multimap for efficient expiration cleanup: expiration_time -> <txn_id, tablet_id>
79
    std::multimap<int64_t, TxnTabletKey> _expiration_map;
80
    std::map<TxnTabletKey, int64_t /* expiration_time */> _empty_rowset_markers;
81
    std::shared_mutex _rwlock;
82
    std::shared_ptr<Thread> _clean_thread;
83
    CountDownLatch _stop_latch;
84
};
85
} // namespace doris