/Users/deen/code/yugabyte-db/src/yb/tablet/operations/write_operation.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 | | // The following only applies to changes made to this file as part of YugaByte development. |
19 | | // |
20 | | // Portions Copyright (c) YugaByte, Inc. |
21 | | // |
22 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
23 | | // in compliance with the License. You may obtain a copy of the License at |
24 | | // |
25 | | // http://www.apache.org/licenses/LICENSE-2.0 |
26 | | // |
27 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
28 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
29 | | // or implied. See the License for the specific language governing permissions and limitations |
30 | | // under the License. |
31 | | // |
32 | | |
33 | | #ifndef YB_TABLET_OPERATIONS_WRITE_OPERATION_H |
34 | | #define YB_TABLET_OPERATIONS_WRITE_OPERATION_H |
35 | | |
36 | | #include <mutex> |
37 | | #include <string> |
38 | | #include <vector> |
39 | | |
40 | | #include "yb/tablet/operations/operation.h" |
41 | | #include "yb/tablet/operations.pb.h" |
42 | | |
43 | | namespace yb { |
44 | | |
45 | | namespace tserver { |
46 | | class WriteRequestPB; |
47 | | class WriteResponsePB; |
48 | | } |
49 | | |
50 | | namespace tablet { |
51 | | |
52 | | // An operation for a batch of inserts/mutates. This class holds and |
53 | | // owns most everything related to a transaction, including the Replicate and Commit PB messages |
54 | | // |
55 | | // All the transaction related pointers are owned by this class |
56 | | // and destroyed on Reset() or by the destructor. |
57 | | // |
58 | | // IMPORTANT: All the acquired locks will not be released unless the OperationState |
59 | | // is either destroyed or Reset() or release_locks() is called. Beware of this |
60 | | // or else there will be lock leaks. |
61 | | // |
62 | | // Used when logging to WAL in that we keep track of where inserts/updates |
63 | | // were applied and add that information to the commit message that is stored |
64 | | // on the WAL. |
65 | | // |
66 | | // NOTE: this class isn't thread safe. |
67 | | class WriteOperation : public OperationBase<OperationType::kWrite, WritePB> { |
68 | | public: |
69 | | template <class... Args> |
70 | | explicit WriteOperation(Args&&... args) |
71 | 4.92M | : OperationBase(std::forward<Args>(args)...) {} _ZN2yb6tablet14WriteOperationC2IJPNS0_6TabletERPNS0_7WritePBEEEEDpOT_ Line | Count | Source | 71 | 245k | : OperationBase(std::forward<Args>(args)...) {} |
_ZN2yb6tablet14WriteOperationC2IJPNS0_6TabletEEEEDpOT_ Line | Count | Source | 71 | 2.92M | : OperationBase(std::forward<Args>(args)...) {} |
_ZN2yb6tablet14WriteOperationC2IJRPNS0_6TabletEEEEDpOT_ Line | Count | Source | 71 | 1.74M | : OperationBase(std::forward<Args>(args)...) {} |
|
72 | | |
73 | 8.95M | bool use_mvcc() const override { |
74 | 8.95M | return true; |
75 | 8.95M | } |
76 | | |
77 | | private: |
78 | | // Executes a Prepare for a write transaction |
79 | | // |
80 | | // Decodes the operations in the request PB and acquires row locks for each of the |
81 | | // affected rows. |
82 | | CHECKED_STATUS Prepare() override; |
83 | | |
84 | | // Executes an Apply for a write transaction. |
85 | | // |
86 | | // Actually applies inserts/mutates into the tablet. After these start being |
87 | | // applied, the transaction must run to completion as there is currently no |
88 | | // means of undoing an update. |
89 | | // |
90 | | // After completing the inserts/mutates, the row locks and the mvcc transaction |
91 | | // can be released, allowing other transactions to update the same rows. |
92 | | // However the component lock must not be released until the commit msg, which |
93 | | // indicates where each of the inserts/mutates were applied, is persisted to |
94 | | // stable storage. Because of this ApplyTask must enqueue a CommitTask before |
95 | | // releasing both the row locks and deleting the MvccTransaction as we need to |
96 | | // make sure that Commits that touch the same set of rows are persisted in |
97 | | // order, for recovery. |
98 | | // This, of course, assumes that commits are executed in the same order they |
99 | | // are placed in the queue (but not necessarily in the same order of the |
100 | | // original requests) which is already a requirement of the consensus |
101 | | // algorithm. |
102 | | // Commits the mvcc transaction and updates the metrics. |
103 | | CHECKED_STATUS DoReplicated(int64_t leader_term, Status* complete_status) override; |
104 | | |
105 | | // Aborts the mvcc transaction. |
106 | | CHECKED_STATUS DoAborted(const Status& status) override; |
107 | | |
108 | | HybridTime WriteHybridTime() const override; |
109 | | }; |
110 | | |
111 | | } // namespace tablet |
112 | | } // namespace yb |
113 | | |
114 | | #endif // YB_TABLET_OPERATIONS_WRITE_OPERATION_H |