Coverage Report

Created: 2026-03-13 03:47

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/storage/rowset_builder.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 <atomic>
21
#include <memory>
22
#include <mutex>
23
#include <shared_mutex>
24
#include <unordered_set>
25
#include <vector>
26
27
#include "common/status.h"
28
#include "load/delta_writer/delta_writer_context.h"
29
#include "runtime/runtime_profile.h"
30
#include "storage/olap_common.h"
31
#include "storage/partial_update_info.h"
32
#include "storage/rowset/pending_rowset_helper.h"
33
#include "storage/rowset/rowset.h"
34
#include "storage/tablet/tablet_fwd.h"
35
36
namespace doris {
37
38
class CalcDeleteBitmapToken;
39
class FlushToken;
40
class MemTable;
41
class StorageEngine;
42
class TupleDescriptor;
43
class SlotDescriptor;
44
class OlapTableSchemaParam;
45
class RowsetWriter;
46
47
class Block;
48
49
// Writer for a particular (load, index, tablet).
50
// This class is NOT thread-safe, external synchronization is required.
51
class BaseRowsetBuilder {
52
public:
53
    BaseRowsetBuilder(const WriteRequest& req, RuntimeProfile* profile);
54
55
    virtual ~BaseRowsetBuilder();
56
57
    virtual Status init() = 0;
58
59
    Status build_rowset();
60
61
    Status submit_calc_delete_bitmap_task();
62
63
    Status wait_calc_delete_bitmap();
64
65
    Status cancel();
66
67
369k
    const std::shared_ptr<RowsetWriter>& rowset_writer() const { return _rowset_writer; }
68
69
1.37M
    const BaseTabletSPtr& tablet() const { return _tablet; }
70
71
0
    const RowsetSharedPtr& rowset() const { return _rowset; }
72
73
180k
    const TabletSchemaSPtr& tablet_schema() const { return _tablet_schema; }
74
75
    // For UT
76
    const DeleteBitmapPtr& get_delete_bitmap() { return _delete_bitmap; }
77
78
181k
    const std::shared_ptr<PartialUpdateInfo>& get_partial_update_info() const {
79
181k
        return _partial_update_info;
80
181k
    }
81
82
    Status init_mow_context(std::shared_ptr<MowContext>& mow_context);
83
84
protected:
85
    Status _build_current_tablet_schema(int64_t index_id,
86
                                        const OlapTableSchemaParam* table_schema_param,
87
                                        const TabletSchema& ori_tablet_schema);
88
89
    virtual void _init_profile(RuntimeProfile* profile);
90
91
    bool _is_init = false;
92
    bool _is_cancelled = false;
93
    WriteRequest _req;
94
    BaseTabletSPtr _tablet;
95
    RowsetSharedPtr _rowset;
96
    std::shared_ptr<RowsetWriter> _rowset_writer;
97
    PendingRowsetGuard _pending_rs_guard;
98
    TabletSchemaSPtr _tablet_schema;
99
100
    std::mutex _lock;
101
102
    DeleteBitmapPtr _delete_bitmap;
103
    std::unique_ptr<CalcDeleteBitmapToken> _calc_delete_bitmap_token;
104
    // current rowset_ids, used to do diff in publish_version
105
    std::shared_ptr<RowsetIdUnorderedSet> _rowset_ids {std::make_shared<RowsetIdUnorderedSet>()};
106
    int64_t _max_version_in_flush_phase {-1};
107
108
    std::shared_ptr<PartialUpdateInfo> _partial_update_info;
109
110
    RuntimeProfile* _profile = nullptr;
111
    RuntimeProfile::Counter* _build_rowset_timer = nullptr;
112
    RuntimeProfile::Counter* _submit_delete_bitmap_timer = nullptr;
113
    RuntimeProfile::Counter* _wait_delete_bitmap_timer = nullptr;
114
};
115
116
// `StorageEngine` mixin for `BaseRowsetBuilder`
117
class RowsetBuilder final : public BaseRowsetBuilder {
118
public:
119
    RowsetBuilder(StorageEngine& engine, const WriteRequest& req, RuntimeProfile* profile);
120
121
    ~RowsetBuilder() override;
122
123
    Status init() override;
124
125
    Status commit_txn();
126
127
    // Cast `BaseTablet` to `Tablet`
128
    Tablet* tablet();
129
130
private:
131
    void _init_profile(RuntimeProfile* profile) override;
132
133
    Status check_tablet_version_count();
134
135
    Status prepare_txn();
136
137
    void _garbage_collection();
138
139
    TabletSharedPtr tablet_sptr();
140
141
    StorageEngine& _engine;
142
    RuntimeProfile::Counter* _commit_txn_timer = nullptr;
143
    bool _is_committed = false;
144
};
145
146
} // namespace doris