/Users/deen/code/yugabyte-db/src/yb/server/clock.h
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | // |
18 | | // The following only applies to changes made to this file as part of YugaByte development. |
19 | | // |
20 | | // Portions Copyright (c) YugaByte, Inc. |
21 | | // |
22 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
23 | | // in compliance with the License. You may obtain a copy of the License at |
24 | | // |
25 | | // http://www.apache.org/licenses/LICENSE-2.0 |
26 | | // |
27 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
28 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
29 | | // or implied. See the License for the specific language governing permissions and limitations |
30 | | // under the License. |
31 | | // |
32 | | |
33 | | #ifndef YB_SERVER_CLOCK_H_ |
34 | | #define YB_SERVER_CLOCK_H_ |
35 | | |
36 | | #include <functional> |
37 | | #include <string> |
38 | | |
39 | | #include "yb/common/clock.h" |
40 | | #include "yb/common/hybrid_time.h" |
41 | | |
42 | | #include "yb/gutil/ref_counted.h" |
43 | | |
44 | | #include "yb/util/status_fwd.h" |
45 | | #include "yb/util/monotime.h" |
46 | | |
47 | | namespace yb { |
48 | | class faststring; |
49 | | class MetricEntity; |
50 | | class MonoDelta; |
51 | | class Slice; |
52 | | class Status; |
53 | | namespace server { |
54 | | |
55 | | // An interface for a clock that can be used to assign timestamps to operations. |
56 | | // Implementations must respect the following assumptions: |
57 | | // 1 - Now() must return monotonically increasing numbers |
58 | | // i.e. for any two calls, i.e. Now returns timestamp1 and timestamp2, it must |
59 | | // hold that timestamp1 < timestamp2. |
60 | | // 2 - Update() must never set the clock backwards (corollary of 1). |
61 | | class Clock : public ClockBase { |
62 | | public: |
63 | | |
64 | | // Initializes the clock. |
65 | | virtual CHECKED_STATUS Init() = 0; |
66 | | |
67 | | // Update the clock with a transaction timestamp originating from |
68 | | // another server. For instance replicas can call this so that, |
69 | | // if elected leader, they are guaranteed to generate timestamps |
70 | | // higher than the timestamp of the last transaction accepted from the |
71 | | // leader. |
72 | | virtual void Update(const HybridTime& to_update) = 0; |
73 | | |
74 | | // Register the clock metrics in the given entity. |
75 | | virtual void RegisterMetrics(const scoped_refptr<MetricEntity>& metric_entity) = 0; |
76 | | |
77 | 2.47k | virtual ~Clock() {} |
78 | | }; |
79 | | |
80 | | typedef scoped_refptr<Clock> ClockPtr; |
81 | | |
82 | | template <class Request> |
83 | 8.05M | void UpdateClock(const Request& request, Clock* clock) { |
84 | 8.05M | auto propagated_hybrid_time = HybridTime::FromPB(request.propagated_hybrid_time()); |
85 | | // If the client sent us a hybrid_time, decode it and update the clock so that all future |
86 | | // hybrid_times are greater than the passed hybrid_time. |
87 | 8.05M | if (!propagated_hybrid_time) { |
88 | 207k | return; |
89 | 207k | } |
90 | 7.84M | clock->Update(propagated_hybrid_time); |
91 | 7.84M | } _ZN2yb6server11UpdateClockINS_7tserver22FlushTabletsResponsePBEEEvRKT_PNS0_5ClockE Line | Count | Source | 83 | 20 | void UpdateClock(const Request& request, Clock* clock) { | 84 | 20 | auto propagated_hybrid_time = HybridTime::FromPB(request.propagated_hybrid_time()); | 85 | | // If the client sent us a hybrid_time, decode it and update the clock so that all future | 86 | | // hybrid_times are greater than the passed hybrid_time. | 87 | 21 | if (!propagated_hybrid_time) { | 88 | 21 | return; | 89 | 21 | } | 90 | 18.4E | clock->Update(propagated_hybrid_time); | 91 | 18.4E | } |
_ZN2yb6server11UpdateClockINS_7tserver24ChangeMetadataResponsePBEEEvRKT_PNS0_5ClockE Line | Count | Source | 83 | 20.7k | void UpdateClock(const Request& request, Clock* clock) { | 84 | 20.7k | auto propagated_hybrid_time = HybridTime::FromPB(request.propagated_hybrid_time()); | 85 | | // If the client sent us a hybrid_time, decode it and update the clock so that all future | 86 | | // hybrid_times are greater than the passed hybrid_time. | 87 | 20.7k | if (!propagated_hybrid_time) { | 88 | 87 | return; | 89 | 87 | } | 90 | 20.6k | clock->Update(propagated_hybrid_time); | 91 | 20.6k | } |
_ZN2yb6server11UpdateClockINS_7tserver18TruncateResponsePBEEEvRKT_PNS0_5ClockE Line | Count | Source | 83 | 53.5k | void UpdateClock(const Request& request, Clock* clock) { | 84 | 53.5k | auto propagated_hybrid_time = HybridTime::FromPB(request.propagated_hybrid_time()); | 85 | | // If the client sent us a hybrid_time, decode it and update the clock so that all future | 86 | | // hybrid_times are greater than the passed hybrid_time. | 87 | 53.5k | if (!propagated_hybrid_time) { | 88 | 9 | return; | 89 | 9 | } | 90 | 53.5k | clock->Update(propagated_hybrid_time); | 91 | 53.5k | } |
_ZN2yb6server11UpdateClockINS_7tserver21GetSplitKeyResponsePBEEEvRKT_PNS0_5ClockE Line | Count | Source | 83 | 44 | void UpdateClock(const Request& request, Clock* clock) { | 84 | 44 | auto propagated_hybrid_time = HybridTime::FromPB(request.propagated_hybrid_time()); | 85 | | // If the client sent us a hybrid_time, decode it and update the clock so that all future | 86 | | // hybrid_times are greater than the passed hybrid_time. | 87 | 44 | if (!propagated_hybrid_time) { | 88 | 0 | return; | 89 | 0 | } | 90 | 44 | clock->Update(propagated_hybrid_time); | 91 | 44 | } |
_ZN2yb6server11UpdateClockINS_7tserver21SplitTabletResponsePBEEEvRKT_PNS0_5ClockE Line | Count | Source | 83 | 42 | void UpdateClock(const Request& request, Clock* clock) { | 84 | 42 | auto propagated_hybrid_time = HybridTime::FromPB(request.propagated_hybrid_time()); | 85 | | // If the client sent us a hybrid_time, decode it and update the clock so that all future | 86 | | // hybrid_times are greater than the passed hybrid_time. | 87 | 42 | if (!propagated_hybrid_time) { | 88 | 25 | return; | 89 | 25 | } | 90 | 17 | clock->Update(propagated_hybrid_time); | 91 | 17 | } |
_ZN2yb6server11UpdateClockINS_7tserver21GetSafeTimeResponsePBEEEvRKT_PNS0_5ClockE Line | Count | Source | 83 | 2.65k | void UpdateClock(const Request& request, Clock* clock) { | 84 | 2.65k | auto propagated_hybrid_time = HybridTime::FromPB(request.propagated_hybrid_time()); | 85 | | // If the client sent us a hybrid_time, decode it and update the clock so that all future | 86 | | // hybrid_times are greater than the passed hybrid_time. | 87 | 2.65k | if (!propagated_hybrid_time) { | 88 | 5 | return; | 89 | 5 | } | 90 | 2.65k | clock->Update(propagated_hybrid_time); | 91 | 2.65k | } |
_ZN2yb6server11UpdateClockINS_7tserver23BackfillIndexResponsePBEEEvRKT_PNS0_5ClockE Line | Count | Source | 83 | 2.62k | void UpdateClock(const Request& request, Clock* clock) { | 84 | 2.62k | auto propagated_hybrid_time = HybridTime::FromPB(request.propagated_hybrid_time()); | 85 | | // If the client sent us a hybrid_time, decode it and update the clock so that all future | 86 | | // hybrid_times are greater than the passed hybrid_time. | 87 | 2.62k | if (!propagated_hybrid_time) { | 88 | 0 | return; | 89 | 0 | } | 90 | 2.62k | clock->Update(propagated_hybrid_time); | 91 | 2.62k | } |
Unexecuted instantiation: _ZN2yb6server11UpdateClockINS_7tserver26TabletSnapshotOpResponsePBEEEvRKT_PNS0_5ClockE _ZN2yb6server11UpdateClockINS_7tserver13ReadRequestPBEEEvRKT_PNS0_5ClockE Line | Count | Source | 83 | 4.68M | void UpdateClock(const Request& request, Clock* clock) { | 84 | 4.68M | auto propagated_hybrid_time = HybridTime::FromPB(request.propagated_hybrid_time()); | 85 | | // If the client sent us a hybrid_time, decode it and update the clock so that all future | 86 | | // hybrid_times are greater than the passed hybrid_time. | 87 | 4.68M | if (!propagated_hybrid_time) { | 88 | 44.5k | return; | 89 | 44.5k | } | 90 | 4.63M | clock->Update(propagated_hybrid_time); | 91 | 4.63M | } |
_ZN2yb6server11UpdateClockINS_6tablet23ChangeMetadataRequestPBEEEvRKT_PNS0_5ClockE Line | Count | Source | 83 | 20.5k | void UpdateClock(const Request& request, Clock* clock) { | 84 | 20.5k | auto propagated_hybrid_time = HybridTime::FromPB(request.propagated_hybrid_time()); | 85 | | // If the client sent us a hybrid_time, decode it and update the clock so that all future | 86 | | // hybrid_times are greater than the passed hybrid_time. | 87 | 20.5k | if (!propagated_hybrid_time) { | 88 | 0 | return; | 89 | 0 | } | 90 | 20.5k | clock->Update(propagated_hybrid_time); | 91 | 20.5k | } |
_ZN2yb6server11UpdateClockINS_7tserver20GetSafeTimeRequestPBEEEvRKT_PNS0_5ClockE Line | Count | Source | 83 | 2.65k | void UpdateClock(const Request& request, Clock* clock) { | 84 | 2.65k | auto propagated_hybrid_time = HybridTime::FromPB(request.propagated_hybrid_time()); | 85 | | // If the client sent us a hybrid_time, decode it and update the clock so that all future | 86 | | // hybrid_times are greater than the passed hybrid_time. | 87 | 2.65k | if (!propagated_hybrid_time) { | 88 | 0 | return; | 89 | 0 | } | 90 | 2.65k | clock->Update(propagated_hybrid_time); | 91 | 2.65k | } |
_ZN2yb6server11UpdateClockINS_7tserver22BackfillIndexRequestPBEEEvRKT_PNS0_5ClockE Line | Count | Source | 83 | 2.70k | void UpdateClock(const Request& request, Clock* clock) { | 84 | 2.70k | auto propagated_hybrid_time = HybridTime::FromPB(request.propagated_hybrid_time()); | 85 | | // If the client sent us a hybrid_time, decode it and update the clock so that all future | 86 | | // hybrid_times are greater than the passed hybrid_time. | 87 | 2.70k | if (!propagated_hybrid_time) { | 88 | 0 | return; | 89 | 0 | } | 90 | 2.70k | clock->Update(propagated_hybrid_time); | 91 | 2.70k | } |
Unexecuted instantiation: _ZN2yb6server11UpdateClockINS_7tserver28VerifyTableRowRangeRequestPBEEEvRKT_PNS0_5ClockE _ZN2yb6server11UpdateClockINS_7tserver26UpdateTransactionRequestPBEEEvRKT_PNS0_5ClockE Line | Count | Source | 83 | 1.48M | void UpdateClock(const Request& request, Clock* clock) { | 84 | 1.48M | auto propagated_hybrid_time = HybridTime::FromPB(request.propagated_hybrid_time()); | 85 | | // If the client sent us a hybrid_time, decode it and update the clock so that all future | 86 | | // hybrid_times are greater than the passed hybrid_time. | 87 | 1.48M | if (!propagated_hybrid_time) { | 88 | 0 | return; | 89 | 0 | } | 90 | 1.48M | clock->Update(propagated_hybrid_time); | 91 | 1.48M | } |
_ZN2yb6server11UpdateClockINS_7tserver29GetTransactionStatusRequestPBEEEvRKT_PNS0_5ClockE Line | Count | Source | 83 | 208k | void UpdateClock(const Request& request, Clock* clock) { | 84 | 208k | auto propagated_hybrid_time = HybridTime::FromPB(request.propagated_hybrid_time()); | 85 | | // If the client sent us a hybrid_time, decode it and update the clock so that all future | 86 | | // hybrid_times are greater than the passed hybrid_time. | 87 | 208k | if (!propagated_hybrid_time) { | 88 | 5.64k | return; | 89 | 5.64k | } | 90 | 202k | clock->Update(propagated_hybrid_time); | 91 | 202k | } |
Unexecuted instantiation: _ZN2yb6server11UpdateClockINS_7tserver42GetTransactionStatusAtParticipantRequestPBEEEvRKT_PNS0_5ClockE _ZN2yb6server11UpdateClockINS_7tserver25AbortTransactionRequestPBEEEvRKT_PNS0_5ClockE Line | Count | Source | 83 | 126k | void UpdateClock(const Request& request, Clock* clock) { | 84 | 126k | auto propagated_hybrid_time = HybridTime::FromPB(request.propagated_hybrid_time()); | 85 | | // If the client sent us a hybrid_time, decode it and update the clock so that all future | 86 | | // hybrid_times are greater than the passed hybrid_time. | 87 | 126k | if (!propagated_hybrid_time) { | 88 | 0 | return; | 89 | 0 | } | 90 | 126k | clock->Update(propagated_hybrid_time); | 91 | 126k | } |
_ZN2yb6server11UpdateClockINS_7tserver17TruncateRequestPBEEEvRKT_PNS0_5ClockE Line | Count | Source | 83 | 53.5k | void UpdateClock(const Request& request, Clock* clock) { | 84 | 53.5k | auto propagated_hybrid_time = HybridTime::FromPB(request.propagated_hybrid_time()); | 85 | | // If the client sent us a hybrid_time, decode it and update the clock so that all future | 86 | | // hybrid_times are greater than the passed hybrid_time. | 87 | 53.5k | if (!propagated_hybrid_time) { | 88 | 0 | return; | 89 | 0 | } | 90 | 53.5k | clock->Update(propagated_hybrid_time); | 91 | 53.5k | } |
_ZN2yb6server11UpdateClockINS_7tserver21FlushTabletsRequestPBEEEvRKT_PNS0_5ClockE Line | Count | Source | 83 | 30 | void UpdateClock(const Request& request, Clock* clock) { | 84 | 30 | auto propagated_hybrid_time = HybridTime::FromPB(request.propagated_hybrid_time()); | 85 | | // If the client sent us a hybrid_time, decode it and update the clock so that all future | 86 | | // hybrid_times are greater than the passed hybrid_time. | 87 | 30 | if (!propagated_hybrid_time) { | 88 | 9 | return; | 89 | 9 | } | 90 | 21 | clock->Update(propagated_hybrid_time); | 91 | 21 | } |
_ZN2yb6server11UpdateClockINS_6tablet20SplitTabletRequestPBEEEvRKT_PNS0_5ClockE Line | Count | Source | 83 | 44 | void UpdateClock(const Request& request, Clock* clock) { | 84 | 44 | auto propagated_hybrid_time = HybridTime::FromPB(request.propagated_hybrid_time()); | 85 | | // If the client sent us a hybrid_time, decode it and update the clock so that all future | 86 | | // hybrid_times are greater than the passed hybrid_time. | 87 | 44 | if (!propagated_hybrid_time) { | 88 | 1 | return; | 89 | 1 | } | 90 | 43 | clock->Update(propagated_hybrid_time); | 91 | 43 | } |
_ZN2yb6server11UpdateClockINS_7tserver14WriteRequestPBEEEvRKT_PNS0_5ClockE Line | Count | Source | 83 | 1.39M | void UpdateClock(const Request& request, Clock* clock) { | 84 | 1.39M | auto propagated_hybrid_time = HybridTime::FromPB(request.propagated_hybrid_time()); | 85 | | // If the client sent us a hybrid_time, decode it and update the clock so that all future | 86 | | // hybrid_times are greater than the passed hybrid_time. | 87 | 1.39M | if (!propagated_hybrid_time) { | 88 | 157k | return; | 89 | 157k | } | 90 | 1.23M | clock->Update(propagated_hybrid_time); | 91 | 1.23M | } |
_ZN2yb6server11UpdateClockINS_7tserver20GetSplitKeyRequestPBEEEvRKT_PNS0_5ClockE Line | Count | Source | 83 | 49 | void UpdateClock(const Request& request, Clock* clock) { | 84 | 49 | auto propagated_hybrid_time = HybridTime::FromPB(request.propagated_hybrid_time()); | 85 | | // If the client sent us a hybrid_time, decode it and update the clock so that all future | 86 | | // hybrid_times are greater than the passed hybrid_time. | 87 | 49 | if (!propagated_hybrid_time) { | 88 | 3 | return; | 89 | 3 | } | 90 | 46 | clock->Update(propagated_hybrid_time); | 91 | 46 | } |
_ZN2yb6server11UpdateClockINS_7tserver25TabletSnapshotOpRequestPBEEEvRKT_PNS0_5ClockE Line | Count | Source | 83 | 3 | void UpdateClock(const Request& request, Clock* clock) { | 84 | 3 | auto propagated_hybrid_time = HybridTime::FromPB(request.propagated_hybrid_time()); | 85 | | // If the client sent us a hybrid_time, decode it and update the clock so that all future | 86 | | // hybrid_times are greater than the passed hybrid_time. | 87 | 3 | if (!propagated_hybrid_time) { | 88 | 3 | return; | 89 | 3 | } | 90 | 0 | clock->Update(propagated_hybrid_time); | 91 | 0 | } |
|
92 | | |
93 | | } // namespace server |
94 | | } // namespace yb |
95 | | |
96 | | #endif /* YB_SERVER_CLOCK_H_ */ |