/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 | 47.3M | static CoarseTimePoint NoneValue() { |
27 | 47.3M | return CoarseTimePoint::min(); |
28 | 47.3M | } |
29 | | }; |
30 | | |
31 | | template <> |
32 | | struct LeaseTraits<MicrosTime> { |
33 | 10.6M | static MicrosTime NoneValue() { |
34 | 10.6M | return 0; |
35 | 10.6M | } |
36 | | }; |
37 | | |
38 | | template <class Time> |
39 | | struct LeaseData { |
40 | | typedef LeaseTraits<Time> Traits; |
41 | | |
42 | 58.0M | static Time NoneValue() { |
43 | 58.0M | return Traits::NoneValue(); |
44 | 58.0M | } _ZN2yb9consensus9LeaseDataINSt3__16chrono10time_pointINS_15CoarseMonoClockENS3_8durationIxNS2_5ratioILl1ELl1000000000EEEEEEEE9NoneValueEv Line | Count | Source | 42 | 47.3M | static Time NoneValue() { | 43 | 47.3M | return Traits::NoneValue(); | 44 | 47.3M | } |
_ZN2yb9consensus9LeaseDataIyE9NoneValueEv Line | Count | Source | 42 | 10.6M | static Time NoneValue() { | 43 | 10.6M | return Traits::NoneValue(); | 44 | 10.6M | } |
|
45 | | |
46 | 329k | LeaseData() : expiration(NoneValue()) {} _ZN2yb9consensus9LeaseDataINSt3__16chrono10time_pointINS_15CoarseMonoClockENS3_8durationIxNS2_5ratioILl1ELl1000000000EEEEEEEEC2Ev Line | Count | Source | 46 | 164k | LeaseData() : expiration(NoneValue()) {} |
_ZN2yb9consensus9LeaseDataIyEC2Ev Line | Count | Source | 46 | 164k | LeaseData() : expiration(NoneValue()) {} |
|
47 | | |
48 | | LeaseData(std::string holder_uuid_, const Time& expiration_) |
49 | 20.4M | : holder_uuid(std::move(holder_uuid_)), expiration(expiration_) {} _ZN2yb9consensus9LeaseDataINSt3__16chrono10time_pointINS_15CoarseMonoClockENS3_8durationIxNS2_5ratioILl1ELl1000000000EEEEEEEEC2ENS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEERKSA_ Line | Count | Source | 49 | 10.2M | : holder_uuid(std::move(holder_uuid_)), expiration(expiration_) {} |
_ZN2yb9consensus9LeaseDataIyEC2ENSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEERKy Line | Count | Source | 49 | 10.2M | : 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 | 9.97k | void Reset() { |
57 | 9.97k | expiration = NoneValue(); |
58 | 9.97k | holder_uuid.clear(); |
59 | 9.97k | } _ZN2yb9consensus9LeaseDataINSt3__16chrono10time_pointINS_15CoarseMonoClockENS3_8durationIxNS2_5ratioILl1ELl1000000000EEEEEEEE5ResetEv Line | Count | Source | 56 | 5.11k | void Reset() { | 57 | 5.11k | expiration = NoneValue(); | 58 | 5.11k | holder_uuid.clear(); | 59 | 5.11k | } |
_ZN2yb9consensus9LeaseDataIyE5ResetEv Line | Count | Source | 56 | 4.85k | void Reset() { | 57 | 4.85k | expiration = NoneValue(); | 58 | 4.85k | holder_uuid.clear(); | 59 | 4.85k | } |
|
60 | | |
61 | 20.5M | void TryUpdate(const LeaseData& rhs) { |
62 | 20.5M | if (rhs.expiration > expiration) { |
63 | 20.4M | expiration = rhs.expiration; |
64 | 20.4M | if (rhs.holder_uuid != holder_uuid) { |
65 | 145k | holder_uuid = rhs.holder_uuid; |
66 | 145k | } |
67 | 20.4M | } |
68 | 20.5M | } _ZN2yb9consensus9LeaseDataINSt3__16chrono10time_pointINS_15CoarseMonoClockENS3_8durationIxNS2_5ratioILl1ELl1000000000EEEEEEEE9TryUpdateERKSB_ Line | Count | Source | 61 | 10.2M | void TryUpdate(const LeaseData& rhs) { | 62 | 10.2M | if (rhs.expiration > expiration) { | 63 | 10.2M | expiration = rhs.expiration; | 64 | 10.2M | if (rhs.holder_uuid != holder_uuid) { | 65 | 72.3k | holder_uuid = rhs.holder_uuid; | 66 | 72.3k | } | 67 | 10.2M | } | 68 | 10.2M | } |
_ZN2yb9consensus9LeaseDataIyE9TryUpdateERKS2_ Line | Count | Source | 61 | 10.2M | void TryUpdate(const LeaseData& rhs) { | 62 | 10.2M | if (rhs.expiration > expiration) { | 63 | 10.2M | expiration = rhs.expiration; | 64 | 10.2M | if (rhs.holder_uuid != holder_uuid) { | 65 | 73.1k | holder_uuid = rhs.holder_uuid; | 66 | 73.1k | } | 67 | 10.2M | } | 68 | 10.2M | } |
|
69 | | |
70 | 37.0M | explicit operator bool() const { |
71 | 37.0M | return expiration != NoneValue(); |
72 | 37.0M | } _ZNK2yb9consensus9LeaseDataIyEcvbEv Line | Count | Source | 70 | 122k | explicit operator bool() const { | 71 | 122k | return expiration != NoneValue(); | 72 | 122k | } |
_ZNK2yb9consensus9LeaseDataINSt3__16chrono10time_pointINS_15CoarseMonoClockENS3_8durationIxNS2_5ratioILl1ELl1000000000EEEEEEEEcvbEv Line | Count | Source | 70 | 36.8M | explicit operator bool() const { | 71 | 36.8M | return expiration != NoneValue(); | 72 | 36.8M | } |
|
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 |