/Users/deen/code/yugabyte-db/src/yb/consensus/leader_lease.h
Line | Count | Source |
1 | | // Copyright (c) YugaByte, Inc. |
2 | | |
3 | | #ifndef YB_CONSENSUS_LEADER_LEASE_H |
4 | | #define YB_CONSENSUS_LEADER_LEASE_H |
5 | | |
6 | | #include <gflags/gflags_declare.h> |
7 | | |
8 | | #include "yb/util/enums.h" |
9 | | #include "yb/util/math_util.h" |
10 | | #include "yb/util/monotime.h" |
11 | | #include "yb/util/physical_time.h" |
12 | | |
13 | | DECLARE_int32(leader_lease_duration_ms); |
14 | | DECLARE_int32(ht_lease_duration_ms); |
15 | | |
16 | | namespace yb { |
17 | | namespace consensus { |
18 | | |
19 | | YB_DEFINE_ENUM(LeaderLeaseCheckMode, (NEED_LEASE)(DONT_NEED_LEASE)) |
20 | | |
21 | | template <class Time> |
22 | | struct LeaseTraits; |
23 | | |
24 | | template <> |
25 | | struct LeaseTraits<CoarseTimePoint> { |
26 | 108M | static CoarseTimePoint NoneValue() { |
27 | 108M | return CoarseTimePoint::min(); |
28 | 108M | } |
29 | | }; |
30 | | |
31 | | template <> |
32 | | struct LeaseTraits<MicrosTime> { |
33 | 27.6M | static MicrosTime NoneValue() { |
34 | 27.6M | return 0; |
35 | 27.6M | } |
36 | | }; |
37 | | |
38 | | template <class Time> |
39 | | struct LeaseData { |
40 | | typedef LeaseTraits<Time> Traits; |
41 | | |
42 | 136M | static Time NoneValue() { |
43 | 136M | return Traits::NoneValue(); |
44 | 136M | } yb::consensus::LeaseData<std::__1::chrono::time_point<yb::CoarseMonoClock, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000000l> > > >::NoneValue() Line | Count | Source | 42 | 108M | static Time NoneValue() { | 43 | 108M | return Traits::NoneValue(); | 44 | 108M | } |
yb::consensus::LeaseData<unsigned long long>::NoneValue() Line | Count | Source | 42 | 27.6M | static Time NoneValue() { | 43 | 27.6M | return Traits::NoneValue(); | 44 | 27.6M | } |
|
45 | | |
46 | 1.77M | LeaseData() : expiration(NoneValue()) {} yb::consensus::LeaseData<std::__1::chrono::time_point<yb::CoarseMonoClock, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000000l> > > >::LeaseData() Line | Count | Source | 46 | 887k | LeaseData() : expiration(NoneValue()) {} |
yb::consensus::LeaseData<unsigned long long>::LeaseData() Line | Count | Source | 46 | 887k | LeaseData() : expiration(NoneValue()) {} |
|
47 | | |
48 | | LeaseData(std::string holder_uuid_, const Time& expiration_) |
49 | 51.3M | : holder_uuid(std::move(holder_uuid_)), expiration(expiration_) {} yb::consensus::LeaseData<std::__1::chrono::time_point<yb::CoarseMonoClock, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000000l> > > >::LeaseData(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::chrono::time_point<yb::CoarseMonoClock, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000000l> > > const&) Line | Count | Source | 49 | 25.4M | : holder_uuid(std::move(holder_uuid_)), expiration(expiration_) {} |
yb::consensus::LeaseData<unsigned long long>::LeaseData(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, unsigned long long const&) Line | Count | Source | 49 | 25.8M | : holder_uuid(std::move(holder_uuid_)), expiration(expiration_) {} |
|
50 | | |
51 | | // UUID of node that holds leader lease. |
52 | | std::string holder_uuid; |
53 | | |
54 | | Time expiration; |
55 | | |
56 | 23.1k | void Reset() { |
57 | 23.1k | expiration = NoneValue(); |
58 | 23.1k | holder_uuid.clear(); |
59 | 23.1k | } yb::consensus::LeaseData<std::__1::chrono::time_point<yb::CoarseMonoClock, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000000l> > > >::Reset() Line | Count | Source | 56 | 12.4k | void Reset() { | 57 | 12.4k | expiration = NoneValue(); | 58 | 12.4k | holder_uuid.clear(); | 59 | 12.4k | } |
yb::consensus::LeaseData<unsigned long long>::Reset() Line | Count | Source | 56 | 10.7k | void Reset() { | 57 | 10.7k | expiration = NoneValue(); | 58 | 10.7k | holder_uuid.clear(); | 59 | 10.7k | } |
|
60 | | |
61 | 51.3M | void TryUpdate(const LeaseData& rhs) { |
62 | 51.3M | if (rhs.expiration > expiration) { |
63 | 51.2M | expiration = rhs.expiration; |
64 | 51.2M | if (rhs.holder_uuid != holder_uuid) { |
65 | 674k | holder_uuid = rhs.holder_uuid; |
66 | 674k | } |
67 | 51.2M | } |
68 | 51.3M | } yb::consensus::LeaseData<std::__1::chrono::time_point<yb::CoarseMonoClock, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000000l> > > >::TryUpdate(yb::consensus::LeaseData<std::__1::chrono::time_point<yb::CoarseMonoClock, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000000l> > > > const&) Line | Count | Source | 61 | 25.4M | void TryUpdate(const LeaseData& rhs) { | 62 | 25.4M | if (rhs.expiration > expiration) { | 63 | 25.4M | expiration = rhs.expiration; | 64 | 25.4M | if (rhs.holder_uuid != holder_uuid) { | 65 | 130k | holder_uuid = rhs.holder_uuid; | 66 | 130k | } | 67 | 25.4M | } | 68 | 25.4M | } |
yb::consensus::LeaseData<unsigned long long>::TryUpdate(yb::consensus::LeaseData<unsigned long long> const&) Line | Count | Source | 61 | 25.9M | void TryUpdate(const LeaseData& rhs) { | 62 | 25.9M | if (rhs.expiration > expiration) { | 63 | 25.8M | expiration = rhs.expiration; | 64 | 25.8M | if (rhs.holder_uuid != holder_uuid) { | 65 | 544k | holder_uuid = rhs.holder_uuid; | 66 | 544k | } | 67 | 25.8M | } | 68 | 25.9M | } |
|
69 | | |
70 | 83.0M | explicit operator bool() const { |
71 | 83.0M | return expiration != NoneValue(); |
72 | 83.0M | } yb::consensus::LeaseData<unsigned long long>::operator bool() const Line | Count | Source | 70 | 1.13M | explicit operator bool() const { | 71 | 1.13M | return expiration != NoneValue(); | 72 | 1.13M | } |
yb::consensus::LeaseData<std::__1::chrono::time_point<yb::CoarseMonoClock, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000000l> > > >::operator bool() const Line | Count | Source | 70 | 81.9M | explicit operator bool() const { | 71 | 81.9M | return expiration != NoneValue(); | 72 | 81.9M | } |
|
73 | | }; |
74 | | |
75 | | typedef LeaseData<CoarseTimePoint> CoarseTimeLease; |
76 | | |
77 | | typedef LeaseData<MicrosTime> PhysicalComponentLease; |
78 | | |
79 | | } // namespace consensus |
80 | | } // namespace yb |
81 | | |
82 | | #endif // YB_CONSENSUS_LEADER_LEASE_H |