YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/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
6.97M
  explicit MinRunningNotifier(TransactionIntentApplier* applier) : applier_(applier) {}
44
45
26
  void Satisfied() {
46
26
    satisfied_ = true;
47
26
  }
48
49
6.96M
  ~MinRunningNotifier() {
50
6.96M
    if (satisfied_ && applier_) {
51
26
      applier_->MinRunningHybridTimeSatisfied();
52
26
    }
53
6.96M
  }
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
25.8k
      : participant_context_(*participant_context), applier_(*applier) {
71
25.8k
  }
72
73
19.2k
  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
3.56M
  int64_t NextRequestIdUnlocked() {
82
3.56M
    return ++request_serial_;
83
3.56M
  }
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