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