/Users/deen/code/yugabyte-db/src/yb/tablet/transaction_status_resolver.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_TRANSACTION_STATUS_RESOLVER_H |
15 | | #define YB_TABLET_TRANSACTION_STATUS_RESOLVER_H |
16 | | |
17 | | #include <stdint.h> |
18 | | |
19 | | #include <memory> |
20 | | #include <type_traits> |
21 | | |
22 | | #include "yb/rpc/rpc_fwd.h" |
23 | | |
24 | | #include "yb/tablet/transaction_participant.h" |
25 | | |
26 | | #include "yb/util/status_fwd.h" |
27 | | |
28 | | namespace yb { |
29 | | namespace tablet { |
30 | | |
31 | | struct TransactionStatusInfo { |
32 | | TransactionId transaction_id = TransactionId::Nil(); |
33 | | TransactionStatus status; |
34 | | AbortedSubTransactionSet aborted_subtxn_set; |
35 | | HybridTime status_ht; |
36 | | HybridTime coordinator_safe_time; |
37 | | |
38 | 0 | std::string ToString() const { |
39 | 0 | return YB_STRUCT_TO_STRING(transaction_id, status, status_ht, coordinator_safe_time); |
40 | 0 | } |
41 | | }; |
42 | | |
43 | | using TransactionStatusResolverCallback = |
44 | | std::function<void(const std::vector<TransactionStatusInfo>&)>; |
45 | | |
46 | | // Utility class to resolve status of multiple transactions. |
47 | | // It sends one request at a time to avoid generating too much load for transaction status |
48 | | // resolution. |
49 | | class TransactionStatusResolver { |
50 | | public: |
51 | | // If max_transactions_per_request is zero then resolution is skipped. |
52 | | TransactionStatusResolver( |
53 | | TransactionParticipantContext* participant_context, rpc::Rpcs* rpcs, |
54 | | int max_transactions_per_request, |
55 | | TransactionStatusResolverCallback callback); |
56 | | ~TransactionStatusResolver(); |
57 | | |
58 | | // Shutdown this resolver. |
59 | | void Shutdown(); |
60 | | |
61 | | // Add transaction id with its status tablet to the set of transactions to resolve. |
62 | | // Cannot be called after Start. |
63 | | void Add(const TabletId& status_tablet, const TransactionId& transaction_id); |
64 | | |
65 | | // Starts transaction resolution, no more adds are allowed after this point. |
66 | | void Start(CoarseTimePoint deadline); |
67 | | |
68 | | // Returns future for resolution status. |
69 | | std::future<Status> ResultFuture(); |
70 | | |
71 | | bool Running() const; |
72 | | |
73 | | private: |
74 | | class Impl; |
75 | | |
76 | | std::unique_ptr<Impl> impl_; |
77 | | }; |
78 | | |
79 | | } // namespace tablet |
80 | | } // namespace yb |
81 | | |
82 | | #endif // YB_TABLET_TRANSACTION_STATUS_RESOLVER_H |