/Users/deen/code/yugabyte-db/src/yb/tablet/operations/split_operation.h
Line | Count | Source |
1 | | // |
2 | | // Copyright (c) YugaByte, Inc. |
3 | | // |
4 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
5 | | // in compliance with the License. You may obtain a copy of the License at |
6 | | // |
7 | | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
10 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
11 | | // or implied. See the License for the specific language governing permissions and limitations |
12 | | // under the License. |
13 | | // |
14 | | // |
15 | | |
16 | | #ifndef YB_TABLET_OPERATIONS_SPLIT_OPERATION_H |
17 | | #define YB_TABLET_OPERATIONS_SPLIT_OPERATION_H |
18 | | |
19 | | #include <condition_variable> |
20 | | |
21 | | #include "yb/common/entity_ids_types.h" |
22 | | |
23 | | #include "yb/consensus/consensus_round.h" |
24 | | |
25 | | #include "yb/tablet/operation_filter.h" |
26 | | #include "yb/tablet/operations/operation.h" |
27 | | |
28 | | #include "yb/tserver/tserver_admin.pb.h" |
29 | | |
30 | | namespace yb { |
31 | | namespace tablet { |
32 | | |
33 | | class TabletSplitter; |
34 | | |
35 | | // Operation Context for the SplitTablet operation. |
36 | | // Keeps track of the Operation states (request, result, ...). |
37 | | // Executes the SplitTablet operation. |
38 | | class SplitOperation |
39 | | : public OperationBase<OperationType::kSplit, SplitTabletRequestPB>, |
40 | | public OperationFilter { |
41 | | public: |
42 | | SplitOperation( |
43 | | Tablet* tablet, TabletSplitter* tablet_splitter, |
44 | | const SplitTabletRequestPB* request = nullptr) |
45 | 71 | : OperationBase(tablet, request), tablet_splitter_(*CHECK_NOTNULL(tablet_splitter)) {} |
46 | | |
47 | 70 | TabletSplitter& tablet_splitter() const { return tablet_splitter_; } |
48 | | |
49 | | static bool ShouldAllowOpAfterSplitTablet(consensus::OperationType op_type); |
50 | | |
51 | | static CHECKED_STATUS RejectionStatus( |
52 | | OpId split_op_id, OpId rejected_op_id, consensus::OperationType op_type, |
53 | | const TabletId& child1, const TabletId& child2); |
54 | | |
55 | | private: |
56 | | CHECKED_STATUS Prepare() override; |
57 | | CHECKED_STATUS DoReplicated(int64_t leader_term, Status* complete_status) override; |
58 | | CHECKED_STATUS DoAborted(const Status& status) override; |
59 | | void AddedAsPending() override; |
60 | | void RemovedFromPending() override; |
61 | | |
62 | | CHECKED_STATUS CheckOperationAllowed( |
63 | | const OpId& id, consensus::OperationType op_type) const override; |
64 | | |
65 | | TabletSplitter& tablet_splitter_; |
66 | | }; |
67 | | |
68 | | } // namespace tablet |
69 | | } // namespace yb |
70 | | |
71 | | #endif // YB_TABLET_OPERATIONS_SPLIT_OPERATION_H |