YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/server/skewed_clock.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_SERVER_SKEWED_CLOCK_H
15
#define YB_SERVER_SKEWED_CLOCK_H
16
17
#include <atomic>
18
#include <chrono>
19
20
#include "yb/util/physical_time.h"
21
22
namespace yb {
23
namespace server {
24
25
class SkewedClock : public PhysicalClock {
26
 public:
27
  typedef std::chrono::microseconds DeltaTime;
28
29
  static const std::string kName;
30
31
  explicit SkewedClock(PhysicalClockPtr clock);
32
33
  template <class Duration>
34
2
  DeltaTime SetDelta(Duration duration) {
35
2
    return SetDelta(std::chrono::duration_cast<DeltaTime>(duration));
36
2
  }
37
38
  DeltaTime SetDelta(DeltaTime new_delta);
39
40
  static void Register();
41
42
 private:
43
  Result<PhysicalTime> Now() override;
44
  MicrosTime MaxGlobalTime(PhysicalTime time) override;
45
46
  PhysicalClockPtr impl_;
47
  std::atomic<DeltaTime> delta_{DeltaTime()};
48
};
49
50
typedef std::shared_ptr<SkewedClock> SkewedClockPtr;
51
52
class SkewedClockDeltaChanger {
53
 public:
54
  template <class Delta>
55
  SkewedClockDeltaChanger(Delta new_delta, SkewedClockPtr skewed_clock)
56
0
      : skewed_clock_(skewed_clock), old_delta_(skewed_clock->SetDelta(new_delta)) {
57
0
  }
58
59
  SkewedClockDeltaChanger(SkewedClockDeltaChanger&& rhs);
60
61
  SkewedClockDeltaChanger(const SkewedClockDeltaChanger&) = delete;
62
  void operator=(const SkewedClockDeltaChanger&) = delete;
63
64
  ~SkewedClockDeltaChanger();
65
66
 private:
67
  SkewedClockPtr skewed_clock_;
68
  SkewedClock::DeltaTime old_delta_;
69
};
70
71
} // namespace server
72
} // namespace yb
73
74
#endif // YB_SERVER_SKEWED_CLOCK_H