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