YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/common/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/common/clock.h"
15
16
#include <thread>
17
18
#include "yb/util/result.h"
19
#include "yb/util/status_format.h"
20
21
using namespace std::literals;
22
23
DEFINE_uint64(wait_hybrid_time_sleep_interval_us, 10000,
24
              "Sleep interval in microseconds that will be used while waiting for specific "
25
                  "hybrid time.");
26
27
namespace yb {
28
29
33.2M
Result<HybridTime> WaitUntil(ClockBase* clock, HybridTime hybrid_time, CoarseTimePoint deadline) {
30
33.2M
  auto ht_now = clock->Now();
31
33.2M
  while (ht_now < hybrid_time) {
32
501
    if (CoarseMonoClock::now() > deadline) {
33
0
      return STATUS_FORMAT(TimedOut, "Timed out waiting for $0, now $1", deadline, ht_now);
34
0
    }
35
501
    auto delta_micros = hybrid_time.GetPhysicalValueMicros() - ht_now.GetPhysicalValueMicros();
36
501
    std::this_thread::sleep_for(
37
501
        std::max(FLAGS_wait_hybrid_time_sleep_interval_us, delta_micros) * 1us);
38
501
    ht_now = clock->Now();
39
501
  }
40
41
33.2M
  return ht_now;
42
33.2M
}
43
44
} // namespace yb