/Users/deen/code/yugabyte-db/src/yb/server/skewed_clock.cc
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 | | #include "yb/server/skewed_clock.h" |
15 | | |
16 | | #include "yb/server/hybrid_clock.h" |
17 | | |
18 | | #include "yb/util/stol_utils.h" |
19 | | |
20 | | namespace yb { |
21 | | namespace server { |
22 | | |
23 | | const std::string SkewedClock::kName = "skewed"; |
24 | | |
25 | 638 | SkewedClock::SkewedClock(PhysicalClockPtr clock) : impl_(std::move(clock)) {} |
26 | | |
27 | 2 | SkewedClock::DeltaTime SkewedClock::SetDelta(DeltaTime new_delta) { |
28 | 2 | return delta_.exchange(new_delta); |
29 | 2 | } |
30 | | |
31 | 10.5k | void SkewedClock::Register() { |
32 | 493 | HybridClock::RegisterProvider(kName, [](const std::string& options) { |
33 | 493 | auto result = std::make_shared<SkewedClock>(WallClock()); |
34 | 493 | if (!options.empty()) { |
35 | 2 | result->SetDelta(std::chrono::milliseconds(CHECK_RESULT(CheckedStoll(options)))); |
36 | 2 | } |
37 | 493 | return result; |
38 | 493 | }); |
39 | 10.5k | } |
40 | | |
41 | 28.2k | Result<PhysicalTime> SkewedClock::Now() { |
42 | 28.2k | auto result = VERIFY_RESULT(impl_->Now()); |
43 | 28.2k | result.time_point += delta_.load(std::memory_order_acquire).count(); |
44 | 28.2k | return result; |
45 | 28.2k | } |
46 | | |
47 | 28.1k | MicrosTime SkewedClock::MaxGlobalTime(PhysicalTime time) { |
48 | 28.1k | return impl_->MaxGlobalTime(time); |
49 | 28.1k | } |
50 | | |
51 | | SkewedClockDeltaChanger::SkewedClockDeltaChanger(SkewedClockDeltaChanger&& rhs) |
52 | | : skewed_clock_(std::move(rhs.skewed_clock_)), |
53 | 0 | old_delta_(rhs.old_delta_) { |
54 | 0 | } |
55 | | |
56 | 0 | SkewedClockDeltaChanger::~SkewedClockDeltaChanger() { |
57 | 0 | if (skewed_clock_) { |
58 | 0 | skewed_clock_->SetDelta(old_delta_); |
59 | 0 | } |
60 | 0 | } |
61 | | |
62 | | } // namespace server |
63 | | } // namespace yb |