/Users/deen/code/yugabyte-db/src/yb/tablet/remove_intents_task.cc
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright (c) YugaByte, Inc. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
4 | | // in compliance with the License. You may obtain a copy of the License at |
5 | | // |
6 | | // http://www.apache.org/licenses/LICENSE-2.0 |
7 | | // |
8 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
9 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
10 | | // or implied. See the License for the specific language governing permissions and limitations |
11 | | // under the License. |
12 | | // |
13 | | |
14 | | #include "yb/tablet/remove_intents_task.h" |
15 | | |
16 | | #include "yb/tablet/running_transaction.h" |
17 | | #include "yb/tablet/transaction_participant_context.h" |
18 | | #include "yb/util/logging.h" |
19 | | |
20 | | namespace yb { |
21 | | namespace tablet { |
22 | | |
23 | | RemoveIntentsTask::RemoveIntentsTask(TransactionIntentApplier* applier, |
24 | | TransactionParticipantContext* participant_context, |
25 | | RunningTransactionContext* running_transaction_context, |
26 | | const TransactionId& id) |
27 | | : applier_(*applier), participant_context_(*participant_context), |
28 | 1.67M | running_transaction_context_(*running_transaction_context), id_(id) {} |
29 | | |
30 | 1.67M | bool RemoveIntentsTask::Prepare(RunningTransactionPtr transaction) { |
31 | 1.67M | bool expected = false; |
32 | 1.67M | if (!used_.compare_exchange_strong(expected, true, std::memory_order_acq_rel)) { |
33 | 0 | return false; |
34 | 0 | } |
35 | | |
36 | 1.67M | transaction_ = std::move(transaction); |
37 | 1.67M | LOG_IF_WITH_PREFIX1.48k (DFATAL, transaction_->ProcessingApply()) |
38 | 1.48k | << "Remove intents for transaction that is processing apply"; |
39 | 1.67M | return true; |
40 | 1.67M | } |
41 | | |
42 | 1.67M | void RemoveIntentsTask::Run() { |
43 | 1.67M | VLOG_WITH_PREFIX84 (2) << "Remove intents"84 ; |
44 | | |
45 | 1.67M | RemoveIntentsData data; |
46 | 1.67M | auto status = participant_context_.GetLastReplicatedData(&data); |
47 | 1.67M | if (status.ok()) { |
48 | 1.67M | status = applier_.RemoveIntents(data, id_); |
49 | 1.67M | } |
50 | 1.67M | LOG_IF_WITH_PREFIX414 (WARNING, !status.ok()) |
51 | 414 | << "Failed to remove intents of aborted transaction: " << status; |
52 | 1.67M | VLOG_WITH_PREFIX501 (2) << "Removed intents"501 ; |
53 | 1.67M | } |
54 | | |
55 | 1.67M | void RemoveIntentsTask::Done(const Status& status) { |
56 | 1.67M | if (!status.ok()) { |
57 | 7 | YB_LOG_EVERY_N_SECS(WARNING, 1) << "Remove intents task failed: " << status4 ; |
58 | 7 | } |
59 | 1.67M | transaction_.reset(); |
60 | 1.67M | } |
61 | | |
62 | 0 | std::string RemoveIntentsTask::LogPrefix() const { |
63 | 0 | return transaction_ ? transaction_->LogPrefix() : running_transaction_context_.LogPrefix(); |
64 | 0 | } |
65 | | |
66 | | } // namespace tablet |
67 | | } // namespace yb |