/Users/deen/code/yugabyte-db/src/yb/tablet/running_transaction_context.h
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 | | #ifndef YB_TABLET_RUNNING_TRANSACTION_CONTEXT_H |
15 | | #define YB_TABLET_RUNNING_TRANSACTION_CONTEXT_H |
16 | | |
17 | | #include <stdint.h> |
18 | | |
19 | | #include <functional> |
20 | | #include <mutex> |
21 | | #include <type_traits> |
22 | | |
23 | | #include <gflags/gflags_declare.h> |
24 | | |
25 | | #include "yb/gutil/callback.h" |
26 | | #include "yb/gutil/integral_types.h" |
27 | | |
28 | | #include "yb/rpc/rpc.h" |
29 | | |
30 | | #include "yb/tablet/transaction_intent_applier.h" |
31 | | #include "yb/tablet/transaction_participant.h" |
32 | | |
33 | | #include "yb/util/delayer.h" |
34 | | #include "yb/util/math_util.h" |
35 | | #include "yb/util/shared_lock.h" |
36 | | #include "yb/util/status_callback.h" |
37 | | |
38 | | namespace yb { |
39 | | namespace tablet { |
40 | | |
41 | | class MinRunningNotifier { |
42 | | public: |
43 | 21.2M | explicit MinRunningNotifier(TransactionIntentApplier* applier) : applier_(applier) {} |
44 | | |
45 | 85 | void Satisfied() { |
46 | 85 | satisfied_ = true; |
47 | 85 | } |
48 | | |
49 | 21.2M | ~MinRunningNotifier() { |
50 | 21.2M | if (satisfied_ && applier_85 ) { |
51 | 74 | applier_->MinRunningHybridTimeSatisfied(); |
52 | 74 | } |
53 | 21.2M | } |
54 | | private: |
55 | | bool satisfied_ = false; |
56 | | TransactionIntentApplier* applier_; |
57 | | }; |
58 | | |
59 | | class RunningTransaction; |
60 | | |
61 | | typedef std::shared_ptr<RunningTransaction> RunningTransactionPtr; |
62 | | |
63 | | YB_DEFINE_ENUM(RemoveReason, |
64 | | (kApplied)(kLargeApplied)(kProcessCleanup)(kStatusReceived)(kAbortReceived)); |
65 | | |
66 | | class RunningTransactionContext { |
67 | | public: |
68 | | RunningTransactionContext(TransactionParticipantContext* participant_context, |
69 | | TransactionIntentApplier* applier) |
70 | 56.8k | : participant_context_(*participant_context), applier_(*applier) { |
71 | 56.8k | } |
72 | | |
73 | 44.6k | virtual ~RunningTransactionContext() {} |
74 | | |
75 | | virtual bool RemoveUnlocked( |
76 | | const TransactionId& id, RemoveReason reason, MinRunningNotifier* min_running_notifier) = 0; |
77 | | |
78 | | virtual void EnqueueRemoveUnlocked( |
79 | | const TransactionId& id, RemoveReason reason, MinRunningNotifier* min_running_notifier) = 0; |
80 | | |
81 | 6.98M | int64_t NextRequestIdUnlocked() { |
82 | 6.98M | return ++request_serial_; |
83 | 6.98M | } |
84 | | |
85 | | virtual const std::string& LogPrefix() const = 0; |
86 | | |
87 | 0 | Delayer& delayer() { |
88 | 0 | return delayer_; |
89 | 0 | } |
90 | | |
91 | | virtual bool Closing() const = 0; |
92 | | |
93 | | protected: |
94 | | friend class RunningTransaction; |
95 | | |
96 | | rpc::Rpcs rpcs_; |
97 | | TransactionParticipantContext& participant_context_; |
98 | | TransactionIntentApplier& applier_; |
99 | | int64_t request_serial_ = 0; |
100 | | std::mutex mutex_; |
101 | | |
102 | | // Used only in tests. |
103 | | Delayer delayer_; |
104 | | }; |
105 | | |
106 | | } // namespace tablet |
107 | | } // namespace yb |
108 | | |
109 | | #endif // YB_TABLET_RUNNING_TRANSACTION_CONTEXT_H |