/Users/deen/code/yugabyte-db/src/yb/tablet/operations/update_txn_operation.cc
Line | Count | Source (jump to first uncovered line) |
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 | | #include "yb/tablet/operations/update_txn_operation.h" |
17 | | |
18 | | #include "yb/consensus/consensus.pb.h" |
19 | | |
20 | | #include "yb/tablet/tablet.h" |
21 | | #include "yb/tablet/transaction_coordinator.h" |
22 | | #include "yb/tablet/transaction_participant.h" |
23 | | |
24 | | #include "yb/util/logging.h" |
25 | | |
26 | | using namespace std::literals; |
27 | | |
28 | | namespace yb { |
29 | | namespace tablet { |
30 | | |
31 | | template <> |
32 | | void RequestTraits<TransactionStatePB>::SetAllocatedRequest( |
33 | 239k | consensus::ReplicateMsg* replicate, TransactionStatePB* request) { |
34 | 239k | replicate->set_allocated_transaction_state(request); |
35 | 239k | } |
36 | | |
37 | | template <> |
38 | | TransactionStatePB* RequestTraits<TransactionStatePB>::MutableRequest( |
39 | 3.24M | consensus::ReplicateMsg* replicate) { |
40 | 3.24M | return replicate->mutable_transaction_state(); |
41 | 3.24M | } |
42 | | |
43 | 2.61M | Status UpdateTxnOperation::Prepare() { |
44 | 18.4E | VLOG_WITH_PREFIX(2) << "Prepare"; |
45 | 2.61M | return Status::OK(); |
46 | 2.61M | } |
47 | | |
48 | 1.87M | TransactionCoordinator& UpdateTxnOperation::transaction_coordinator() const { |
49 | 1.87M | return *tablet()->transaction_coordinator(); |
50 | 1.87M | } |
51 | | |
52 | 2.60M | Status UpdateTxnOperation::DoReplicated(int64_t leader_term, Status* complete_status) { |
53 | 569 | VLOG_WITH_PREFIX(2) << "Replicated"; |
54 | | |
55 | 2.60M | auto transaction_participant = tablet()->transaction_participant(); |
56 | 2.60M | if (transaction_participant) { |
57 | 737k | TransactionParticipant::ReplicatedData data = { |
58 | 737k | .leader_term = leader_term, |
59 | 737k | .state = *request(), |
60 | 737k | .op_id = op_id(), |
61 | 737k | .hybrid_time = hybrid_time(), |
62 | 737k | .sealed = request()->sealed(), |
63 | 737k | .already_applied_to_regular_db = AlreadyAppliedToRegularDB::kFalse |
64 | 737k | }; |
65 | 737k | return transaction_participant->ProcessReplicated(data); |
66 | 1.87M | } else { |
67 | 1.87M | TransactionCoordinator::ReplicatedData data = { |
68 | 1.87M | leader_term, |
69 | 1.87M | *request(), |
70 | 1.87M | op_id(), |
71 | 1.87M | hybrid_time() |
72 | 1.87M | }; |
73 | 1.87M | return transaction_coordinator().ProcessReplicated(data); |
74 | 1.87M | } |
75 | 2.60M | } |
76 | | |
77 | 63 | Status UpdateTxnOperation::DoAborted(const Status& status) { |
78 | 63 | if (tablet()->transaction_coordinator()) { |
79 | 0 | LOG_WITH_PREFIX(INFO) << "Aborted: " << status; |
80 | 0 | TransactionCoordinator::AbortedData data = { |
81 | 0 | .state = *request(), |
82 | 0 | .op_id = op_id(), |
83 | 0 | }; |
84 | 0 | transaction_coordinator().ProcessAborted(data); |
85 | 0 | } |
86 | | |
87 | 63 | return status; |
88 | 63 | } |
89 | | |
90 | | } // namespace tablet |
91 | | } // namespace yb |