You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by al...@apache.org on 2020/02/24 21:17:04 UTC
[kudu] 03/05: [clock] safer handling of metrics-related endpoints
This is an automated email from the ASF dual-hosted git repository.
alexey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git
commit bdb991a6b3ed2c989248dbbcfda983bda4d488bf
Author: Alexey Serbin <al...@apache.org>
AuthorDate: Fri Feb 21 18:52:34 2020 -0800
[clock] safer handling of metrics-related endpoints
Re-worked the way of retrieving hybrid clock metrics:
* in case of 'system' time source, do not crash if clock is not
synchronized when serving /metrics Web server endpoint
* in general, register function gauges only after HybridClock
is initialized
In addition, this patch contains a new test scenario to exercise the
control path mentioned above.
This patch also contains a sub-scenario to check for the presence of
metrics introduced in the context of KUDU-3048.
This is a follow-up for 8808b041c, 6371ffdb5, and 7d9d7009a.
Change-Id: Ic172635a7c7b019e5f4394c6107345820d408a68
Reviewed-on: http://gerrit.cloudera.org:8080/15273
Tested-by: Kudu Jenkins
Reviewed-by: Adar Dembo <ad...@cloudera.com>
---
src/kudu/clock/CMakeLists.txt | 4 +-
src/kudu/clock/hybrid_clock-test.cc | 135 +++++++++++++++++----
src/kudu/clock/hybrid_clock.cc | 106 ++++++++++------
src/kudu/clock/hybrid_clock.h | 18 +--
.../integration-tests/webserver-stress-itest.cc | 14 +--
src/kudu/tserver/tablet_server-test.cc | 4 +-
6 files changed, 201 insertions(+), 80 deletions(-)
diff --git a/src/kudu/clock/CMakeLists.txt b/src/kudu/clock/CMakeLists.txt
index 3ed2665..b57d30f 100644
--- a/src/kudu/clock/CMakeLists.txt
+++ b/src/kudu/clock/CMakeLists.txt
@@ -69,7 +69,6 @@ if (NOT NO_CHRONY)
endif() # (NOT NO_CHRONY)
SET_KUDU_TEST_LINK_LIBS(clock)
-ADD_KUDU_TEST(hybrid_clock-test PROCESSORS 3)
ADD_KUDU_TEST(logical_clock-test)
if (NO_CHRONY)
@@ -79,3 +78,6 @@ else()
ADD_KUDU_TEST(test/mini_chronyd-test)
endif()
ADD_KUDU_TEST(ntp-test)
+
+SET_KUDU_TEST_LINK_LIBS(clock mini_cluster)
+ADD_KUDU_TEST(hybrid_clock-test PROCESSORS 3)
diff --git a/src/kudu/clock/hybrid_clock-test.cc b/src/kudu/clock/hybrid_clock-test.cc
index 0a022eb..c857002 100644
--- a/src/kudu/clock/hybrid_clock-test.cc
+++ b/src/kudu/clock/hybrid_clock-test.cc
@@ -20,6 +20,7 @@
#include <algorithm>
#include <cstdint>
#include <string>
+#include <thread>
#include <vector>
#include <gflags/gflags.h>
@@ -27,14 +28,21 @@
#include <gtest/gtest.h>
#include "kudu/clock/mock_ntp.h"
+#include "kudu/clock/test/mini_chronyd.h"
#include "kudu/clock/time_service.h"
#include "kudu/common/timestamp.h"
#include "kudu/gutil/casts.h"
#include "kudu/gutil/ref_counted.h"
#include "kudu/gutil/strings/join.h"
+#include "kudu/gutil/strings/substitute.h"
+#include "kudu/mini-cluster/external_mini_cluster.h"
+#include "kudu/mini-cluster/webui_checker.h"
#include "kudu/util/atomic.h"
+#include "kudu/util/curl_util.h"
+#include "kudu/util/faststring.h"
#include "kudu/util/metrics.h"
#include "kudu/util/monotime.h"
+#include "kudu/util/net/net_util.h"
#include "kudu/util/random.h"
#include "kudu/util/random_util.h"
#include "kudu/util/scoped_cleanup.h"
@@ -47,7 +55,10 @@ DECLARE_bool(inject_unsync_time_errors);
DECLARE_string(time_source);
METRIC_DECLARE_entity(server);
+using kudu::cluster::ExternalMiniCluster;
+using kudu::cluster::ExternalMiniClusterOptions;
using std::string;
+using std::thread;
using std::vector;
namespace kudu {
@@ -79,23 +90,23 @@ TEST_F(MockHybridClockTest, TestMockedSystemClock) {
ASSERT_OK(clock.Init());
Timestamp timestamp;
uint64_t max_error_usec;
- clock.NowWithError(×tamp, &max_error_usec);
+ ASSERT_OK(clock.NowWithError(×tamp, &max_error_usec));
ASSERT_EQ(timestamp.ToUint64(), 0);
ASSERT_EQ(max_error_usec, 0);
// If we read the clock again we should see the logical component be incremented.
- clock.NowWithError(×tamp, &max_error_usec);
+ ASSERT_OK(clock.NowWithError(×tamp, &max_error_usec));
ASSERT_EQ(timestamp.ToUint64(), 1);
// Now set an arbitrary time and check that is the time returned by the clock.
uint64_t time = 1234 * 1000;
uint64_t error = 100 * 1000;
mock_ntp(clock)->SetMockClockWallTimeForTests(time);
mock_ntp(clock)->SetMockMaxClockErrorForTests(error);
- clock.NowWithError(×tamp, &max_error_usec);
+ ASSERT_OK(clock.NowWithError(×tamp, &max_error_usec));
ASSERT_EQ(timestamp.ToUint64(),
HybridClock::TimestampFromMicrosecondsAndLogicalValue(time, 0).ToUint64());
ASSERT_EQ(max_error_usec, error);
// Perform another read, we should observe the logical component increment, again.
- clock.NowWithError(×tamp, &max_error_usec);
+ ASSERT_OK(clock.NowWithError(×tamp, &max_error_usec));
ASSERT_EQ(timestamp.ToUint64(),
HybridClock::TimestampFromMicrosecondsAndLogicalValue(time, 1).ToUint64());
}
@@ -202,7 +213,7 @@ TEST_F(HybridClockTest, WaitUntilAfterCase1) {
Timestamp past_ts;
uint64_t max_error;
- clock_.NowWithError(&past_ts, &max_error);
+ ASSERT_OK(clock_.NowWithError(&past_ts, &max_error));
// make the event 3 * the max. possible error in the past
Timestamp past_ts_changed = HybridClock::AddPhysicalTimeToTimestamp(
@@ -226,7 +237,7 @@ TEST_F(HybridClockTest, WaitUntilAfterCase2) {
// error interval
Timestamp past_ts;
uint64_t past_max_error;
- clock_.NowWithError(&past_ts, &past_max_error);
+ ASSERT_OK(clock_.NowWithError(&past_ts, &past_max_error));
// Make sure the error is at least a small number of microseconds, to ensure
// that we always have to wait.
past_max_error = std::max(past_max_error, static_cast<uint64_t>(2000));
@@ -236,7 +247,7 @@ TEST_F(HybridClockTest, WaitUntilAfterCase2) {
Timestamp current_ts;
uint64_t current_max_error;
- clock_.NowWithError(¤t_ts, ¤t_max_error);
+ ASSERT_OK(clock_.NowWithError(¤t_ts, ¤t_max_error));
// Check waiting with a deadline which already expired.
{
@@ -335,13 +346,13 @@ TEST_F(HybridClockTest, TestRideOverNtpInterruption) {
uint64_t max_error_usec[3];
// Get the clock once, with a working NTP.
- clock_.NowWithError(×tamps[0], &max_error_usec[0]);
+ ASSERT_OK(clock_.NowWithError(×tamps[0], &max_error_usec[0]));
// Try to read the clock again a second later, but with an error
// injected. It should extrapolate from the first read.
SleepFor(MonoDelta::FromSeconds(1));
FLAGS_inject_unsync_time_errors = true;
- clock_.NowWithError(×tamps[1], &max_error_usec[1]);
+ ASSERT_OK(clock_.NowWithError(×tamps[1], &max_error_usec[1]));
// The new clock reading should be a second or longer from the
// first one, since SleepFor guarantees sleeping at least as long
@@ -359,26 +370,87 @@ TEST_F(HybridClockTest, TestRideOverNtpInterruption) {
// Now restore the ability to read the system clock, and
// read it again.
FLAGS_inject_unsync_time_errors = false;
- clock_.NowWithError(×tamps[2], &max_error_usec[2]);
+ ASSERT_OK(clock_.NowWithError(×tamps[2], &max_error_usec[2]));
ASSERT_LT(timestamps[0].ToUint64(), timestamps[1].ToUint64());
ASSERT_LT(timestamps[1].ToUint64(), timestamps[2].ToUint64());
}
-#if defined(KUDU_HAS_SYSTEM_TIME_SOURCE)
-TEST_F(HybridClockTest, TestNtpDiagnostics) {
- FLAGS_time_source = "system";
- HybridClock clock(metric_entity_);
- ASSERT_OK(clock.Init());
+TEST_F(HybridClockTest, SlowClockInitialisation) {
+ SKIP_IF_SLOW_NOT_ALLOWED();
+
+ const vector<string> kExtraFlags =
+ { "--hybrid_clock_inject_init_delay_ms=100" };
+
+ ExternalMiniClusterOptions opts;
+ opts.num_masters = 3;
+ opts.num_ntp_servers = 1;
+ opts.extra_master_flags = kExtraFlags;
+ opts.extra_tserver_flags = kExtraFlags;
+
+ // The PeriodicWebUIChecker needs to know the addresses which master and
+ // tserver embedded web servers are bound to. So, first start all the
+ // processes, then stop them, and then instantiate the PeriodicWebUIChecker.
+ // This way there will be requests coming to the webservers while Kudu masters
+ // and tablet servers are bootstrapping.
+ ExternalMiniCluster cluster(opts);
+ ASSERT_OK(cluster.Start());
+ cluster.Shutdown();
+
+ auto ntp_servers = cluster.ntp_servers();
+ ASSERT_EQ(1, ntp_servers.size());
+ auto* ntp_server = ntp_servers.front();
+ ASSERT_OK(ntp_server->Pause());
+ Status ntp_server_resumer_status;
+ thread ntp_server_resumer([&] {
+ SleepFor(MonoDelta::FromMilliseconds(500));
+ ntp_server_resumer_status = ntp_server->Resume();
+ });
+ SCOPED_CLEANUP({
+ ntp_server_resumer.join();
+ });
- vector<string> log;
- clock.time_service()->DumpDiagnostics(&log);
- string s = JoinStrings(log, "\n");
- SCOPED_TRACE(s);
- ASSERT_STR_MATCHES(s, "(ntp_gettime\\(\\) returns code |chronyc -n tracking)");
- ASSERT_STR_MATCHES(s, "(ntpq -n |chronyc -n sources)");
+ // Start pounding the master and tserver's web UIs.
+ PeriodicWebUIChecker checker(cluster, MonoDelta::FromMilliseconds(1),
+ "", { "/metrics" }, { "/metrics" });
+
+ // Start bootstrapping masters and tablet servers.
+ ASSERT_OK(cluster.Restart());
+ SleepFor(MonoDelta::FromSeconds(1));
+ NO_FATALS(cluster.AssertNoCrashes());
+ cluster.Shutdown();
+ ASSERT_OK(cluster.Restart());
+ SleepFor(MonoDelta::FromSeconds(1));
+ NO_FATALS(cluster.AssertNoCrashes());
+ ASSERT_OK(ntp_server_resumer_status);
+
+ // Check for the presence of clock-related metrics.
+ vector<string> addresses;
+ addresses.reserve(cluster.num_masters() + cluster.num_tablet_servers());
+ for (auto idx = 0; idx < cluster.num_masters(); ++idx) {
+ addresses.emplace_back(
+ cluster.master(idx)->bound_http_hostport().ToString());
+ }
+ for (auto idx = 0; idx < cluster.num_tablet_servers(); ++idx) {
+ addresses.emplace_back(
+ cluster.tablet_server(idx)->bound_http_hostport().ToString());
+ }
+
+ EasyCurl c;
+ for (const auto& addr : addresses) {
+ faststring buf;
+ ASSERT_OK(c.FetchURL(strings::Substitute("http://$0/metrics", addr), &buf));
+ const auto str = buf.ToString();
+ ASSERT_STR_CONTAINS(str, "builtin_ntp_local_clock_delta");
+ ASSERT_STR_CONTAINS(str, "builtin_ntp_max_errors");
+ ASSERT_STR_CONTAINS(str, "builtin_ntp_walltime");
+ ASSERT_STR_CONTAINS(str, "hybrid_clock_max_errors");
+ ASSERT_STR_CONTAINS(str, "hybrid_clock_error");
+ ASSERT_STR_CONTAINS(str, "hybrid_clock_extrapolating");
+ ASSERT_STR_CONTAINS(str, "hybrid_clock_extrapolation_intervals");
+ ASSERT_STR_CONTAINS(str, "hybrid_clock_timestamp");
+ }
}
-#endif // #if defined(KUDU_HAS_SYSTEM_TIME_SOURCE) ...
// A simple scenario to verify that 'auto' is recognized as one of the possible
// time sources: the auto-selection works and the resulting hybrid clock
@@ -389,10 +461,25 @@ TEST_F(HybridClockTest, TimeSourceAutoSelection) {
ASSERT_OK(clock.Init());
Timestamp timestamp[2];
uint64_t max_error_usec[2];
- clock.NowWithError(×tamp[0], &max_error_usec[0]);
- clock.NowWithError(×tamp[1], &max_error_usec[1]);
+ ASSERT_OK(clock.NowWithError(×tamp[0], &max_error_usec[0]));
+ ASSERT_OK(clock.NowWithError(×tamp[1], &max_error_usec[1]));
ASSERT_LE(timestamp[0].value(), timestamp[1].value());
}
+#if defined(KUDU_HAS_SYSTEM_TIME_SOURCE)
+TEST_F(HybridClockTest, TestNtpDiagnostics) {
+ FLAGS_time_source = "system";
+ HybridClock clock(metric_entity_);
+ ASSERT_OK(clock.Init());
+
+ vector<string> log;
+ clock.time_service()->DumpDiagnostics(&log);
+ string s = JoinStrings(log, "\n");
+ SCOPED_TRACE(s);
+ ASSERT_STR_MATCHES(s, "(ntp_gettime\\(\\) returns code |chronyc -n tracking)");
+ ASSERT_STR_MATCHES(s, "(ntpq -n |chronyc -n sources)");
+}
+#endif // #if defined(KUDU_HAS_SYSTEM_TIME_SOURCE) ...
+
} // namespace clock
} // namespace kudu
diff --git a/src/kudu/clock/hybrid_clock.cc b/src/kudu/clock/hybrid_clock.cc
index a3188f8..0c369fc 100644
--- a/src/kudu/clock/hybrid_clock.cc
+++ b/src/kudu/clock/hybrid_clock.cc
@@ -18,6 +18,7 @@
#include "kudu/clock/hybrid_clock.h"
#include <algorithm>
+#include <limits>
#include <memory>
#include <mutex>
#include <ostream>
@@ -74,6 +75,12 @@ DEFINE_bool(use_hybrid_clock, true,
"implementation. This should be disabled for testing purposes only.");
TAG_FLAG(use_hybrid_clock, hidden);
+DEFINE_int32(hybrid_clock_inject_init_delay_ms, 0,
+ "If enabled, injects the given number of milliseconds delay into "
+ "HybridClock::Init(). For testing only!");
+TAG_FLAG(hybrid_clock_inject_init_delay_ms, hidden);
+TAG_FLAG(hybrid_clock_inject_init_delay_ms, unsafe);
+
// Use the 'system' time source by default in standard (non-test) environment.
// This requires local machine clock to be NTP-synchronized.
DEFINE_string(time_source,
@@ -165,13 +172,15 @@ METRIC_DEFINE_gauge_bool(server, hybrid_clock_extrapolating,
METRIC_DEFINE_gauge_uint64(server, hybrid_clock_error,
"Hybrid Clock Error",
kudu::MetricUnit::kMicroseconds,
- "Server clock maximum error",
+ "Server clock maximum error; returns 2^64-1 when "
+ "unable to read the underlying clock",
kudu::MetricLevel::kInfo);
METRIC_DEFINE_gauge_uint64(server, hybrid_clock_timestamp,
"Hybrid Clock Timestamp",
kudu::MetricUnit::kMicroseconds,
- "Hybrid clock timestamp",
+ "Hybrid clock timestamp; returns 2^64-1 when "
+ "unable to read the underlying clock",
kudu::MetricLevel::kInfo);
METRIC_DEFINE_histogram(server, hybrid_clock_max_errors,
@@ -223,14 +232,6 @@ HybridClock::HybridClock(const scoped_refptr<MetricEntity>& metric_entity)
METRIC_hybrid_clock_extrapolation_intervals.Instantiate(metric_entity_);
extrapolating_ = metric_entity_->FindOrCreateGauge(
&METRIC_hybrid_clock_extrapolating, false, MergeType::kMax);
- METRIC_hybrid_clock_timestamp.InstantiateFunctionGauge(
- metric_entity_,
- Bind(&HybridClock::NowForMetrics, Unretained(this)))->
- AutoDetachToLastValue(&metric_detacher_);
- METRIC_hybrid_clock_error.InstantiateFunctionGauge(
- metric_entity_,
- Bind(&HybridClock::ErrorForMetrics, Unretained(this)))->
- AutoDetachToLastValue(&metric_detacher_);
}
Status HybridClock::Init() {
@@ -245,15 +246,15 @@ Status HybridClock::Init() {
Timestamp HybridClock::Now() {
Timestamp now;
- uint64_t error;
- NowWithError(&now, &error);
+ uint64_t error_ignored;
+ NowWithErrorOrDie(&now, &error_ignored);
return now;
}
Timestamp HybridClock::NowLatest() {
Timestamp now;
uint64_t error;
- NowWithError(&now, &error);
+ NowWithErrorOrDie(&now, &error);
uint64_t now_latest = GetPhysicalValueMicros(now) + error;
uint64_t now_logical = GetLogicalValue(now);
@@ -269,16 +270,16 @@ Status HybridClock::GetGlobalLatest(Timestamp* t) {
return Status::OK();
}
-void HybridClock::NowWithError(Timestamp* timestamp, uint64_t* max_error_usec) {
+Status HybridClock::NowWithError(Timestamp* timestamp, uint64_t* max_error_usec) {
std::lock_guard<decltype(lock_)> lock(lock_);
- NowWithErrorUnlocked(timestamp, max_error_usec);
+ return NowWithErrorUnlocked(timestamp, max_error_usec);
}
Status HybridClock::Update(const Timestamp& to_update) {
Timestamp now;
uint64_t error_ignored;
std::lock_guard<decltype(lock_)> lock(lock_);
- NowWithErrorUnlocked(&now, &error_ignored);
+ RETURN_NOT_OK(NowWithErrorUnlocked(&now, &error_ignored));
// If the incoming message is in the past relative to our current
// physical clock, there's nothing to do.
@@ -316,7 +317,7 @@ Status HybridClock::WaitUntilAfter(const Timestamp& then,
TRACE_EVENT0("clock", "HybridClock::WaitUntilAfter");
Timestamp now;
uint64_t error;
- NowWithError(&now, &error);
+ RETURN_NOT_OK(NowWithError(&now, &error));
// "unshift" the timestamps so that we can measure actual time
uint64_t now_usec = GetPhysicalValueMicros(now);
@@ -353,7 +354,7 @@ Status HybridClock::WaitUntilAfterLocally(const Timestamp& then,
const MonoTime& deadline) {
Timestamp now;
uint64_t error;
- NowWithError(&now, &error);
+ RETURN_NOT_OK(NowWithError(&now, &error));
if (now > then) {
return Status::OK();
}
@@ -371,8 +372,12 @@ bool HybridClock::IsAfter(Timestamp t) {
// Manually get the time, rather than using Now(), so we don't end up causing
// a time update.
uint64_t now_usec;
- uint64_t error_usec;
- WalltimeWithErrorOrDie(&now_usec, &error_usec);
+ uint64_t error_usec_unused;
+ Status s = WalltimeWithError(&now_usec, &error_usec_unused);
+ if (PREDICT_FALSE(!s.ok())) {
+ time_service_->DumpDiagnostics(/*log=*/nullptr);
+ CHECK_OK_PREPEND(s, "unable to get current time with error bound");
+ }
Timestamp now;
{
@@ -382,14 +387,14 @@ bool HybridClock::IsAfter(Timestamp t) {
return t.value() < now.value();
}
-void HybridClock::NowWithErrorUnlocked(Timestamp *timestamp,
- uint64_t *max_error_usec) {
+Status HybridClock::NowWithErrorUnlocked(Timestamp *timestamp,
+ uint64_t *max_error_usec) {
DCHECK(lock_.is_locked());
DCHECK_EQ(state_, kInitialized) << "Clock not initialized. Must call Init() first.";
uint64_t now_usec;
uint64_t error_usec;
- WalltimeWithErrorOrDie(&now_usec, &error_usec);
+ RETURN_NOT_OK(WalltimeWithError(&now_usec, &error_usec));
// If the physical time from the system clock is higher than our last-returned
// time, we should use the physical timestamp.
@@ -402,7 +407,7 @@ void HybridClock::NowWithErrorUnlocked(Timestamp *timestamp,
"Resetting logical values. Physical Value: $0 usec "
"Logical Value: 0 Error: $1",
now_usec, error_usec);
- return;
+ return Status::OK();
}
// We don't have the last time read max error since it might have originated
@@ -429,6 +434,16 @@ void HybridClock::NowWithErrorUnlocked(Timestamp *timestamp,
"last read and incrementing logical values. "
"Clock: $0 Error: $1",
Stringify(*timestamp), *max_error_usec);
+ return Status::OK();
+}
+
+void HybridClock::NowWithErrorOrDie(Timestamp* timestamp,
+ uint64_t* max_error_usec) {
+ auto s = NowWithError(timestamp, max_error_usec);
+ if (PREDICT_FALSE(!s.ok())) {
+ time_service_->DumpDiagnostics(/*log=*/nullptr);
+ CHECK_OK_PREPEND(s, "unable to get current timestamp with error bound");
+ }
}
Status HybridClock::SelectTimeSource(const string& time_source_str,
@@ -511,6 +526,11 @@ Status HybridClock::InitWithTimeSource(TimeSource time_source,
return Status::InvalidArgument("invalid time source for hybrid clock",
TimeSourceToString(time_source));
}
+ if (FLAGS_hybrid_clock_inject_init_delay_ms > 0) {
+ LOG(WARNING) << "Injecting " << FLAGS_hybrid_clock_inject_init_delay_ms
+ << "ms delay in HybridClock initialization process";
+ SleepFor(MonoDelta::FromMilliseconds(FLAGS_hybrid_clock_inject_init_delay_ms));
+ }
RETURN_NOT_OK(time_service_->Init());
// Make sure the underlying clock service is available (e.g., for NTP-based
@@ -552,7 +572,6 @@ Status HybridClock::InitWithTimeSource(TimeSource time_source,
LOG(INFO) << Substitute("HybridClock initialized: "
"now $0 us; error $1 us; skew $2 ppm",
now_usec, error_usec, time_service_->skew_ppm());
-
{
// We typically don't expect other threads to access an object until after
// its Init() is called, but there is nothing preventing some other thread
@@ -561,6 +580,20 @@ Status HybridClock::InitWithTimeSource(TimeSource time_source,
std::lock_guard<decltype(lock_)> lock(lock_);
state_ = kInitialized;
}
+
+ // Once the hybrid clock is initialized, it's safe to register/instantiate
+ // function gauges. Otherwise, there might be an attempt to read the gauges'
+ // values when the object is not ready for that yet. Gauges produce special
+ // values for corresponding metrics, but there is no value in that anyways.
+ METRIC_hybrid_clock_timestamp.InstantiateFunctionGauge(
+ metric_entity_,
+ Bind(&HybridClock::NowForMetrics, Unretained(this)))->
+ AutoDetachToLastValue(&metric_detacher_);
+ METRIC_hybrid_clock_error.InstantiateFunctionGauge(
+ metric_entity_,
+ Bind(&HybridClock::ErrorForMetrics, Unretained(this)))->
+ AutoDetachToLastValue(&metric_detacher_);
+
return Status::OK();
}
@@ -645,24 +678,25 @@ Status HybridClock::WalltimeWithError(uint64_t* now_usec, uint64_t* error_usec)
return kudu::Status::OK();
}
-void HybridClock::WalltimeWithErrorOrDie(uint64_t* now_usec, uint64_t* error_usec) {
- Status s = WalltimeWithError(now_usec, error_usec);
- if (PREDICT_FALSE(!s.ok())) {
- time_service_->DumpDiagnostics(/*log=*/nullptr);
- CHECK_OK_PREPEND(s, "unable to get current time with error bound");
- }
-}
-
// Used to get the timestamp for metrics.
uint64_t HybridClock::NowForMetrics() {
- return Now().ToUint64();
+ Timestamp now;
+ uint64_t error_unused;
+ auto s = NowWithError(&now, &error_unused);
+ if (PREDICT_FALSE(!s.ok())) {
+ return std::numeric_limits<uint64_t>::max();
+ }
+ return now.ToUint64();
}
// Used to get the current error, for metrics.
uint64_t HybridClock::ErrorForMetrics() {
- Timestamp now;
+ Timestamp now_unused;
uint64_t error;
- NowWithError(&now, &error);
+ auto s = NowWithError(&now_unused, &error);
+ if (PREDICT_FALSE(!s.ok())) {
+ return std::numeric_limits<uint64_t>::max();
+ }
return error;
}
diff --git a/src/kudu/clock/hybrid_clock.h b/src/kudu/clock/hybrid_clock.h
index 545ba0a..beeb365 100644
--- a/src/kudu/clock/hybrid_clock.h
+++ b/src/kudu/clock/hybrid_clock.h
@@ -25,6 +25,7 @@
#include "kudu/clock/time_service.h"
#include "kudu/common/common.pb.h"
#include "kudu/common/timestamp.h"
+#include "kudu/gutil/port.h"
#include "kudu/gutil/ref_counted.h"
#include "kudu/util/locks.h"
#include "kudu/util/metrics.h"
@@ -132,10 +133,10 @@ class HybridClock : public Clock {
std::string Stringify(Timestamp timestamp) override;
// Obtains the timestamp corresponding to the current time and the associated
- // error in micros. This may fail if the clock is unsynchronized or synchronized
- // but the error is too high and, since we can't do anything about it,
- // LOG(FATAL)'s in that case.
- void NowWithError(Timestamp* timestamp, uint64_t* max_error_usec);
+ // error in micros. If the clock is unsynchronized or synchronized but the
+ // error is too high, a non-OK status is returned.
+ Status NowWithError(Timestamp* timestamp, uint64_t* max_error_usec)
+ WARN_UNUSED_RESULT;
// Static encoding/decoding methods for timestamps. Public mostly
// for testing/debugging purposes.
@@ -212,7 +213,11 @@ class HybridClock : public Clock {
std::vector<HostPort> builtin_ntp_servers);
// Variant of NowWithError() that requires 'lock_' to be held already.
- void NowWithErrorUnlocked(Timestamp* timestamp, uint64_t* max_error_usec);
+ Status NowWithErrorUnlocked(Timestamp* timestamp, uint64_t* max_error_usec);
+
+ // Variant of NowWithError() that calls LOG(FATAL) if the clock is
+ // unsynchronized or synchronized but the error is too high.
+ void NowWithErrorOrDie(Timestamp* timestamp, uint64_t* max_error_usec);
// Obtains the current wallclock time and maximum error in microseconds,
// and checks if the clock is synchronized.
@@ -220,9 +225,6 @@ class HybridClock : public Clock {
// On OS X, the error will always be 0.
Status WalltimeWithError(uint64_t* now_usec, uint64_t* error_usec);
- // Same as above, but exits with a FATAL if there is an error.
- void WalltimeWithErrorOrDie(uint64_t* now_usec, uint64_t* error_usec);
-
// Used to get the timestamp for metrics.
uint64_t NowForMetrics();
diff --git a/src/kudu/integration-tests/webserver-stress-itest.cc b/src/kudu/integration-tests/webserver-stress-itest.cc
index 74fa5ee..8b51e92 100644
--- a/src/kudu/integration-tests/webserver-stress-itest.cc
+++ b/src/kudu/integration-tests/webserver-stress-itest.cc
@@ -16,7 +16,6 @@
// under the License.
#include <memory>
-#include <ostream>
#include <string>
#include <vector>
@@ -30,20 +29,17 @@
#include "kudu/util/test_macros.h"
#include "kudu/util/test_util.h"
-namespace kudu {
-
-using cluster::ExternalMiniCluster;
-using cluster::ExternalMiniClusterOptions;
+using kudu::cluster::ExternalMiniCluster;
+using kudu::cluster::ExternalMiniClusterOptions;
using std::string;
using std::unique_ptr;
using std::vector;
+namespace kudu {
+
// Tests that pounding the web UI doesn't cause any crashes.
TEST_F(KuduTest, TestWebUIDoesNotCrashCluster) {
- if (!AllowSlowTests()) {
- LOG(WARNING) << "test is skipped; set KUDU_ALLOW_SLOW_TESTS=1 to run";
- return;
- }
+ SKIP_IF_SLOW_NOT_ALLOWED();
#if defined(THREAD_SANITIZER) || defined(ADDRESS_SANITIZER)
// When using a sanitizer, checkers place a lot of load on the cluster.
diff --git a/src/kudu/tserver/tablet_server-test.cc b/src/kudu/tserver/tablet_server-test.cc
index f71974f..8f5c64b 100644
--- a/src/kudu/tserver/tablet_server-test.cc
+++ b/src/kudu/tserver/tablet_server-test.cc
@@ -1167,7 +1167,7 @@ TEST_F(TabletServerTest, TestExternalConsistencyModes_CommitWait) {
// get current time, with and without error
Timestamp now_before;
uint64_t error_before;
- hclock->NowWithError(&now_before, &error_before);
+ ASSERT_OK(hclock->NowWithError(&now_before, &error_before));
uint64_t now_before_usec = HybridClock::GetPhysicalValueMicros(now_before);
LOG(INFO) << "Submitting write with commit wait at: " << now_before_usec << " us +- "
@@ -1195,7 +1195,7 @@ TEST_F(TabletServerTest, TestExternalConsistencyModes_CommitWait) {
Timestamp now_after;
uint64_t error_after;
- hclock->NowWithError(&now_after, &error_after);
+ ASSERT_OK(hclock->NowWithError(&now_after, &error_after));
Timestamp write_timestamp(resp.timestamp());