/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 | | Status submit_calc_delete_bitmap_task(); |
65 | | |
66 | | Status wait_calc_delete_bitmap(); |
67 | | |
68 | | Status cancel(); |
69 | | |
70 | 25 | const std::shared_ptr<RowsetWriter>& rowset_writer() const { return _rowset_writer; } |
71 | | |
72 | 69 | const BaseTabletSPtr& tablet() const { return _tablet; } |
73 | | |
74 | 0 | const RowsetSharedPtr& rowset() const { return _rowset; } |
75 | | |
76 | 12 | const TabletSchemaSPtr& tablet_schema() const { return _tablet_schema; } |
77 | | |
78 | | // For UT |
79 | 1 | const DeleteBitmapPtr& get_delete_bitmap() { return _delete_bitmap; } |
80 | | |
81 | 12 | const std::shared_ptr<PartialUpdateInfo>& get_partial_update_info() const { |
82 | 12 | return _partial_update_info; |
83 | 12 | } |
84 | | |
85 | | Status init_mow_context(std::shared_ptr<MowContext>& mow_context); |
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 | | virtual void _init_profile(RuntimeProfile* profile); |
93 | | |
94 | | bool _is_init = false; |
95 | | bool _is_cancelled = false; |
96 | | WriteRequest _req; |
97 | | BaseTabletSPtr _tablet; |
98 | | RowsetSharedPtr _rowset; |
99 | | std::shared_ptr<RowsetWriter> _rowset_writer; |
100 | | PendingRowsetGuard _pending_rs_guard; |
101 | | TabletSchemaSPtr _tablet_schema; |
102 | | |
103 | | std::mutex _lock; |
104 | | |
105 | | DeleteBitmapPtr _delete_bitmap; |
106 | | std::unique_ptr<CalcDeleteBitmapToken> _calc_delete_bitmap_token; |
107 | | // current rowset_ids, used to do diff in publish_version |
108 | | RowsetIdUnorderedSet _rowset_ids; |
109 | | int64_t _max_version_in_flush_phase {-1}; |
110 | | |
111 | | std::shared_ptr<PartialUpdateInfo> _partial_update_info; |
112 | | |
113 | | RuntimeProfile* _profile = nullptr; |
114 | | RuntimeProfile::Counter* _build_rowset_timer = nullptr; |
115 | | RuntimeProfile::Counter* _submit_delete_bitmap_timer = nullptr; |
116 | | RuntimeProfile::Counter* _wait_delete_bitmap_timer = nullptr; |
117 | | }; |
118 | | |
119 | | // `StorageEngine` mixin for `BaseRowsetBuilder` |
120 | | class RowsetBuilder final : public BaseRowsetBuilder { |
121 | | public: |
122 | | RowsetBuilder(StorageEngine& engine, const WriteRequest& req, RuntimeProfile* profile); |
123 | | |
124 | | ~RowsetBuilder() override; |
125 | | |
126 | | Status init() override; |
127 | | |
128 | | Status commit_txn(); |
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 | | // Cast `BaseTablet` to `Tablet` |
140 | | Tablet* tablet(); |
141 | | TabletSharedPtr tablet_sptr(); |
142 | | |
143 | | StorageEngine& _engine; |
144 | | RuntimeProfile::Counter* _commit_txn_timer = nullptr; |
145 | | bool _is_committed = false; |
146 | | }; |
147 | | |
148 | | } // namespace doris |