be/src/storage/rowset/pending_rowset_helper.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 <mutex> |
21 | | |
22 | | #include "storage/olap_common.h" |
23 | | |
24 | | namespace doris { |
25 | | |
26 | | class PendingRowsetSet; |
27 | | |
28 | | class [[nodiscard]] PendingRowsetGuard { |
29 | | public: |
30 | 171 | PendingRowsetGuard() = default; |
31 | | |
32 | | // Remove guarded rowset id from `PendingRowsetSet` if it's initialized |
33 | | ~PendingRowsetGuard(); |
34 | | |
35 | | PendingRowsetGuard(const PendingRowsetGuard&) = delete; |
36 | | PendingRowsetGuard& operator=(const PendingRowsetGuard&) = delete; |
37 | | |
38 | | PendingRowsetGuard(PendingRowsetGuard&& other) noexcept; |
39 | | PendingRowsetGuard& operator=(PendingRowsetGuard&& other) noexcept; |
40 | | |
41 | | // Remove guarded rowset id from `PendingRowsetSet` if it's initialized and reset the guard to |
42 | | // uninitialized state. This be used to manually release the pending rowset, ensure that the |
43 | | // guarded rowset is indeed no longer in use. |
44 | | void drop(); |
45 | | |
46 | | private: |
47 | | friend class PendingRowsetSet; |
48 | | explicit PendingRowsetGuard(const RowsetId& rowset_id, PendingRowsetSet* set); |
49 | | |
50 | | RowsetId _rowset_id; |
51 | | PendingRowsetSet* _pending_rowset_set = nullptr; |
52 | | }; |
53 | | |
54 | | // Pending rowsets refer to those rowsets that are under construction, and have not been added to |
55 | | // the tablet. BE storage engine will skip these pending rowsets during garbage collection. |
56 | | class PendingRowsetSet { |
57 | | public: |
58 | | bool contains(const RowsetId& rowset_id); |
59 | | |
60 | | // Developers MUST add the rowset id to `PendingRowsetSet` before writing first row data to a |
61 | | // local rowset, and hold returned `PendingRowsetGuard` during rowset construction before |
62 | | // adding the rowset to tablet. rowset id will be removed from `PendingRowsetSet` eventually |
63 | | // when `PendingRowsetGuard` is destroyed. |
64 | | PendingRowsetGuard add(const RowsetId& rowset_id); |
65 | | |
66 | | private: |
67 | | friend class PendingRowsetGuard; |
68 | | void remove(const RowsetId& rowset_id); |
69 | | |
70 | | // TODO(plat1ko): Use high concurrency data structure |
71 | | std::mutex _mtx; |
72 | | RowsetIdUnorderedSet _set; |
73 | | }; |
74 | | |
75 | | } // namespace doris |