YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/server/logical_clock.cc
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
#include "yb/server/logical_clock.h"
34
35
#include "yb/gutil/bind.h"
36
#include "yb/util/metrics.h"
37
#include "yb/util/monotime.h"
38
#include "yb/util/status.h"
39
#include "yb/util/atomic.h"
40
41
namespace yb {
42
namespace server {
43
44
METRIC_DEFINE_gauge_uint64(server, logical_clock_hybrid_time,
45
                           "Logical Clock Hybrid Time",
46
                           yb::MetricUnit::kUnits,
47
                           "Logical clock hybrid time.");
48
49
using base::subtle::Atomic64;
50
using base::subtle::Barrier_AtomicIncrement;
51
using base::subtle::NoBarrier_CompareAndSwap;
52
53
76
Status LogicalClock::Init() {
54
76
  return Status::OK();
55
76
}
56
57
248k
HybridTimeRange LogicalClock::NowRange() {
58
248k
  auto result = HybridTime(++now_);
59
248k
  return std::make_pair(result, result);
60
248k
}
61
62
42.8k
HybridTime LogicalClock::Peek() {
63
42.8k
  return HybridTime(now_.load(std::memory_order_acquire));
64
42.8k
}
65
66
347k
void LogicalClock::Update(const HybridTime& to_update) {
67
347k
  if (to_update.is_valid()) {
68
347k
    UpdateAtomicMax(&now_, to_update.value());
69
347k
  }
70
347k
}
71
72
581
LogicalClock* LogicalClock::CreateStartingAt(const HybridTime& hybrid_time) {
73
  // initialize at 'hybrid_time' - 1 so that the  first output value is 'hybrid_time'.
74
581
  return new LogicalClock(hybrid_time.value() - 1);
75
581
}
76
77
11
uint64_t LogicalClock::NowForMetrics() {
78
  // We don't want reading metrics to change the clock.
79
11
  return now_.load(std::memory_order_acquire);
80
11
}
81
82
83
72
void LogicalClock::RegisterMetrics(const scoped_refptr<MetricEntity>& metric_entity) {
84
72
  METRIC_logical_clock_hybrid_time.InstantiateFunctionGauge(
85
72
      metric_entity,
86
72
      Bind(&LogicalClock::NowForMetrics, Unretained(this)))
87
72
    ->AutoDetachToLastValue(&metric_detacher_);
88
72
}
89
90
}  // namespace server
91
}  // namespace yb
92