/Users/deen/code/yugabyte-db/src/yb/tablet/apply_intents_task.h
Line | Count | Source |
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 | | #ifndef YB_TABLET_APPLY_INTENTS_TASK_H |
15 | | #define YB_TABLET_APPLY_INTENTS_TASK_H |
16 | | |
17 | | #include "yb/rpc/strand.h" |
18 | | |
19 | | #include "yb/tablet/running_transaction_context.h" |
20 | | |
21 | | #include "yb/util/operation_counter.h" |
22 | | |
23 | | namespace yb { |
24 | | namespace tablet { |
25 | | |
26 | | // Used by RunningTransaction to apply its intents. |
27 | | class ApplyIntentsTask : public rpc::StrandTask { |
28 | | public: |
29 | | ApplyIntentsTask(TransactionIntentApplier* applier, |
30 | | RunningTransactionContext* running_transaction_context, |
31 | | const TransactionApplyData* apply_data); |
32 | | |
33 | | // Returns true if task was successfully prepared and could be submitted to the thread pool. |
34 | | bool Prepare(RunningTransactionPtr transaction, ScopedRWOperation* operation); |
35 | | void Run() override; |
36 | | void Done(const Status& status) override; |
37 | | |
38 | 1.67M | virtual ~ApplyIntentsTask() = default; |
39 | | |
40 | | private: |
41 | | std::string LogPrefix() const; |
42 | | |
43 | | TransactionIntentApplier& applier_; |
44 | | RunningTransactionContext& running_transaction_context_; |
45 | | const TransactionApplyData& apply_data_; |
46 | | ScopedRWOperation operation_; |
47 | | |
48 | | // Whether this task was already in use or not. |
49 | | // Helps to avoid multiple submissions of the same task. |
50 | | // The task can be submitted only once, so this flag never reverts its state to false. |
51 | | std::atomic<bool> used_{false}; |
52 | | RunningTransactionPtr transaction_; |
53 | | }; |
54 | | |
55 | | } // namespace tablet |
56 | | } // namespace yb |
57 | | |
58 | | #endif // YB_TABLET_APPLY_INTENTS_TASK_H |