Repository: kudu
Updated Branches:
  refs/heads/master ddaa766e2 -> a09c89abc


hybrid_clock: restore SleepFor in WaitUntilAfterLocally

This seems to have gone missing from commit f2d96437c. The end result is a
busy loop, which was probably unintentional. I also removed the loop, which
seemed unnecessary with the SleepFor.

To test, I wrote a small program that scanned a table at Now() + 10s, after
setting --scanner_max_wait_ms to 10000 (default is 1000). Although the wall
clock time was the same, the cycle count was far higher per perf stat.

Change-Id: Iecbb077b1f88293dcb0ab53e40ff3862f772694e
Reviewed-on: http://gerrit.cloudera.org:8080/11495
Tested-by: Kudu Jenkins
Reviewed-by: Andrew Wong <aw...@cloudera.com>


Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/24b38f73
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/24b38f73
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/24b38f73

Branch: refs/heads/master
Commit: 24b38f73739ef76f69fbe950ff103dc6c1b3e6a8
Parents: ddaa766
Author: Adar Dembo <a...@cloudera.com>
Authored: Fri Sep 21 12:27:41 2018 -0700
Committer: David Ribeiro Alves <davidral...@gmail.com>
Committed: Mon Sep 24 15:03:30 2018 +0000

----------------------------------------------------------------------
 src/kudu/clock/hybrid_clock.cc | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/24b38f73/src/kudu/clock/hybrid_clock.cc
----------------------------------------------------------------------
diff --git a/src/kudu/clock/hybrid_clock.cc b/src/kudu/clock/hybrid_clock.cc
index b97fd2d..7e87d4d 100644
--- a/src/kudu/clock/hybrid_clock.cc
+++ b/src/kudu/clock/hybrid_clock.cc
@@ -291,31 +291,31 @@ Status HybridClock::WaitUntilAfter(const Timestamp& then,
 
   SleepFor(MonoDelta::FromMicroseconds(wait_for_usec));
 
-
   VLOG(1) << "WaitUntilAfter(): Incoming time(latest): " << then_latest_usec
           << " Now(earliest): " << now_earliest_usec << " error: " << error
           << " Waiting for: " << wait_for_usec;
-
   return Status::OK();
 }
 
 Status HybridClock::WaitUntilAfterLocally(const Timestamp& then,
                                           const MonoTime& deadline) {
-  while (true) {
-    Timestamp now;
-    uint64_t error;
-    {
-      std::lock_guard<simple_spinlock> lock(lock_);
-      NowWithError(&now, &error);
-    }
-    if (now > then) {
-      return Status::OK();
-    }
-    uint64_t wait_for_usec = GetPhysicalValueMicros(then) - 
GetPhysicalValueMicros(now);
-
-    // Check that sleeping wouldn't sleep longer than our deadline.
-    RETURN_NOT_OK(CheckDeadlineNotWithinMicros(deadline, wait_for_usec));
+  Timestamp now;
+  uint64_t error;
+  {
+    std::lock_guard<simple_spinlock> lock(lock_);
+    NowWithError(&now, &error);
   }
+  if (now > then) {
+    return Status::OK();
+  }
+  uint64_t wait_for_usec = GetPhysicalValueMicros(then) - 
GetPhysicalValueMicros(now);
+
+  // Check that sleeping wouldn't sleep longer than our deadline.
+  RETURN_NOT_OK(CheckDeadlineNotWithinMicros(deadline, wait_for_usec));
+
+  SleepFor(MonoDelta::FromMicroseconds(wait_for_usec));
+
+  return Status::OK();
 }
 
 bool HybridClock::IsAfter(Timestamp t) {

Reply via email to