YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/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
6.95k
  virtual ~Clock() {}
78
};
79
80
typedef scoped_refptr<Clock> ClockPtr;
81
82
template <class Request>
83
15.3M
void UpdateClock(const Request& request, Clock* clock) {
84
15.3M
  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
15.3M
  if (!propagated_hybrid_time) {
88
326k
    return;
89
326k
  }
90
15.0M
  clock->Update(propagated_hybrid_time);
91
15.0M
}
void yb::server::UpdateClock<yb::tserver::ReadRequestPB>(yb::tserver::ReadRequestPB const&, yb::server::Clock*)
Line
Count
Source
83
9.53M
void UpdateClock(const Request& request, Clock* clock) {
84
9.53M
  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
9.53M
  if (!propagated_hybrid_time) {
88
86.0k
    return;
89
86.0k
  }
90
9.44M
  clock->Update(propagated_hybrid_time);
91
9.44M
}
void yb::server::UpdateClock<yb::tablet::ChangeMetadataRequestPB>(yb::tablet::ChangeMetadataRequestPB const&, yb::server::Clock*)
Line
Count
Source
83
32.0k
void UpdateClock(const Request& request, Clock* clock) {
84
32.0k
  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
32.0k
  if (!propagated_hybrid_time) {
88
0
    return;
89
0
  }
90
32.0k
  clock->Update(propagated_hybrid_time);
91
32.0k
}
void yb::server::UpdateClock<yb::tserver::GetSafeTimeRequestPB>(yb::tserver::GetSafeTimeRequestPB const&, yb::server::Clock*)
Line
Count
Source
83
4.38k
void UpdateClock(const Request& request, Clock* clock) {
84
4.38k
  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.38k
  if (!propagated_hybrid_time) {
88
0
    return;
89
0
  }
90
4.38k
  clock->Update(propagated_hybrid_time);
91
4.38k
}
void yb::server::UpdateClock<yb::tserver::BackfillIndexRequestPB>(yb::tserver::BackfillIndexRequestPB const&, yb::server::Clock*)
Line
Count
Source
83
4.50k
void UpdateClock(const Request& request, Clock* clock) {
84
4.50k
  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.50k
  if (!propagated_hybrid_time) {
88
0
    return;
89
0
  }
90
4.50k
  clock->Update(propagated_hybrid_time);
91
4.50k
}
Unexecuted instantiation: void yb::server::UpdateClock<yb::tserver::VerifyTableRowRangeRequestPB>(yb::tserver::VerifyTableRowRangeRequestPB const&, yb::server::Clock*)
void yb::server::UpdateClock<yb::tserver::UpdateTransactionRequestPB>(yb::tserver::UpdateTransactionRequestPB const&, yb::server::Clock*)
Line
Count
Source
83
2.52M
void UpdateClock(const Request& request, Clock* clock) {
84
2.52M
  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.52M
  if (!propagated_hybrid_time) {
88
0
    return;
89
0
  }
90
2.52M
  clock->Update(propagated_hybrid_time);
91
2.52M
}
void yb::server::UpdateClock<yb::tserver::GetTransactionStatusRequestPB>(yb::tserver::GetTransactionStatusRequestPB const&, yb::server::Clock*)
Line
Count
Source
83
296k
void UpdateClock(const Request& request, Clock* clock) {
84
296k
  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
296k
  if (!propagated_hybrid_time) {
88
20.5k
    return;
89
20.5k
  }
90
275k
  clock->Update(propagated_hybrid_time);
91
275k
}
Unexecuted instantiation: void yb::server::UpdateClock<yb::tserver::GetTransactionStatusAtParticipantRequestPB>(yb::tserver::GetTransactionStatusAtParticipantRequestPB const&, yb::server::Clock*)
void yb::server::UpdateClock<yb::tserver::AbortTransactionRequestPB>(yb::tserver::AbortTransactionRequestPB const&, yb::server::Clock*)
Line
Count
Source
83
193k
void UpdateClock(const Request& request, Clock* clock) {
84
193k
  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
193k
  if (!propagated_hybrid_time) {
88
0
    return;
89
0
  }
90
193k
  clock->Update(propagated_hybrid_time);
91
193k
}
void yb::server::UpdateClock<yb::tserver::TruncateRequestPB>(yb::tserver::TruncateRequestPB const&, yb::server::Clock*)
Line
Count
Source
83
57.2k
void UpdateClock(const Request& request, Clock* clock) {
84
57.2k
  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
57.2k
  if (!propagated_hybrid_time) {
88
0
    return;
89
0
  }
90
57.2k
  clock->Update(propagated_hybrid_time);
91
57.2k
}
void yb::server::UpdateClock<yb::tserver::FlushTabletsRequestPB>(yb::tserver::FlushTabletsRequestPB const&, yb::server::Clock*)
Line
Count
Source
83
43
void UpdateClock(const Request& request, Clock* clock) {
84
43
  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
43
  if (!propagated_hybrid_time) {
88
13
    return;
89
13
  }
90
30
  clock->Update(propagated_hybrid_time);
91
30
}
void yb::server::UpdateClock<yb::tablet::SplitTabletRequestPB>(yb::tablet::SplitTabletRequestPB const&, yb::server::Clock*)
Line
Count
Source
83
141
void UpdateClock(const Request& request, Clock* clock) {
84
141
  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
141
  if (!propagated_hybrid_time) {
88
1
    return;
89
1
  }
90
140
  clock->Update(propagated_hybrid_time);
91
140
}
void yb::server::UpdateClock<yb::tserver::WriteRequestPB>(yb::tserver::WriteRequestPB const&, yb::server::Clock*)
Line
Count
Source
83
2.61M
void UpdateClock(const Request& request, Clock* clock) {
84
2.61M
  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.61M
  if (!propagated_hybrid_time) {
88
218k
    return;
89
218k
  }
90
2.39M
  clock->Update(propagated_hybrid_time);
91
2.39M
}
void yb::server::UpdateClock<yb::tserver::GetSplitKeyRequestPB>(yb::tserver::GetSplitKeyRequestPB const&, yb::server::Clock*)
Line
Count
Source
83
144
void UpdateClock(const Request& request, Clock* clock) {
84
144
  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
144
  if (!propagated_hybrid_time) {
88
1
    return;
89
1
  }
90
143
  clock->Update(propagated_hybrid_time);
91
143
}
void yb::server::UpdateClock<yb::tserver::TabletSnapshotOpRequestPB>(yb::tserver::TabletSnapshotOpRequestPB const&, yb::server::Clock*)
Line
Count
Source
83
54
void UpdateClock(const Request& request, Clock* clock) {
84
54
  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
54
  if (!propagated_hybrid_time) {
88
3
    return;
89
3
  }
90
51
  clock->Update(propagated_hybrid_time);
91
51
}
void yb::server::UpdateClock<yb::tserver::FlushTabletsResponsePB>(yb::tserver::FlushTabletsResponsePB const&, yb::server::Clock*)
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
30
    return;
89
30
  }
90
0
  clock->Update(propagated_hybrid_time);
91
0
}
void yb::server::UpdateClock<yb::tserver::ChangeMetadataResponsePB>(yb::tserver::ChangeMetadataResponsePB const&, yb::server::Clock*)
Line
Count
Source
83
32.3k
void UpdateClock(const Request& request, Clock* clock) {
84
32.3k
  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
32.3k
  if (!propagated_hybrid_time) {
88
1.00k
    return;
89
1.00k
  }
90
31.2k
  clock->Update(propagated_hybrid_time);
91
31.2k
}
void yb::server::UpdateClock<yb::tserver::TruncateResponsePB>(yb::tserver::TruncateResponsePB const&, yb::server::Clock*)
Line
Count
Source
83
57.1k
void UpdateClock(const Request& request, Clock* clock) {
84
57.1k
  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
57.1k
  if (!propagated_hybrid_time) {
88
5
    return;
89
5
  }
90
57.1k
  clock->Update(propagated_hybrid_time);
91
57.1k
}
void yb::server::UpdateClock<yb::tserver::GetSplitKeyResponsePB>(yb::tserver::GetSplitKeyResponsePB const&, yb::server::Clock*)
Line
Count
Source
83
141
void UpdateClock(const Request& request, Clock* clock) {
84
141
  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
141
  if (!propagated_hybrid_time) {
88
0
    return;
89
0
  }
90
141
  clock->Update(propagated_hybrid_time);
91
141
}
void yb::server::UpdateClock<yb::tserver::SplitTabletResponsePB>(yb::tserver::SplitTabletResponsePB const&, yb::server::Clock*)
Line
Count
Source
83
140
void UpdateClock(const Request& request, Clock* clock) {
84
140
  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
140
  if (!propagated_hybrid_time) {
88
96
    return;
89
96
  }
90
44
  clock->Update(propagated_hybrid_time);
91
44
}
void yb::server::UpdateClock<yb::tserver::GetSafeTimeResponsePB>(yb::tserver::GetSafeTimeResponsePB const&, yb::server::Clock*)
Line
Count
Source
83
4.38k
void UpdateClock(const Request& request, Clock* clock) {
84
4.38k
  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.38k
  if (!propagated_hybrid_time) {
88
3
    return;
89
3
  }
90
4.38k
  clock->Update(propagated_hybrid_time);
91
4.38k
}
void yb::server::UpdateClock<yb::tserver::BackfillIndexResponsePB>(yb::tserver::BackfillIndexResponsePB const&, yb::server::Clock*)
Line
Count
Source
83
4.36k
void UpdateClock(const Request& request, Clock* clock) {
84
4.36k
  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.36k
  if (!propagated_hybrid_time) {
88
17
    return;
89
17
  }
90
4.34k
  clock->Update(propagated_hybrid_time);
91
4.34k
}
void yb::server::UpdateClock<yb::tserver::TabletSnapshotOpResponsePB>(yb::tserver::TabletSnapshotOpResponsePB const&, yb::server::Clock*)
Line
Count
Source
83
51
void UpdateClock(const Request& request, Clock* clock) {
84
51
  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
51
  if (!propagated_hybrid_time) {
88
6
    return;
89
6
  }
90
45
  clock->Update(propagated_hybrid_time);
91
45
}
92
93
} // namespace server
94
} // namespace yb
95
96
#endif /* YB_SERVER_CLOCK_H_ */