]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Clock: add new clock_offset config option, and use it in g_clock.now()
authorGreg Farnum <gregory.farnum@dreamhost.com>
Wed, 11 May 2011 20:27:07 +0000 (13:27 -0700)
committerGreg Farnum <gregory.farnum@dreamhost.com>
Wed, 11 May 2011 20:27:07 +0000 (13:27 -0700)
This way we can test clock drifts without needing to actually
drift the clocks.

Signed-off-by: Greg Farnum <gregory.farnum@dreamhost.com>
src/common/Clock.cc
src/common/Clock.h
src/common/config.cc
src/common/config.h

index 6d5e1255613bfbf671e27957b8b862a4540185c5..2446854b9def64fde7dfc54c30f28ba1934be654 100644 (file)
@@ -24,3 +24,16 @@ Clock::Clock() {
 
 Clock::~Clock() {
 }
+
+utime_t Clock::now() {
+  struct timeval tv;
+  gettimeofday(&tv, NULL);
+  utime_t n(&tv);
+  n += g_conf.clock_offset;
+  if (n < last) {
+    //derr << "WARNING: clock jumped backwards from " << last << " to " << n << dendl;
+    n = last;    // clock jumped backwards!
+  } else
+    last = n;
+  return n;
+}
index 4be950f80de2aba35f0e2d4a61f5ee2642b077f7..a1ca17d40ba33180a7f60d1f41eea1f52710fcbe 100644 (file)
@@ -30,17 +30,7 @@ class Clock {
   Clock();
   ~Clock();
 
-  utime_t now() {
-    struct timeval tv;
-    gettimeofday(&tv, NULL);
-    utime_t n(&tv);
-    if (n < last) {
-      //derr << "WARNING: clock jumped backwards from " << last << " to " << n << dendl;
-      n = last;    // clock jumped backwards!
-    } else
-      last = n;
-    return n;
-  }
+  utime_t now();
 
   utime_t recent_now() {
     return last;
@@ -58,7 +48,6 @@ class Clock {
   time_t gettime() {
     return now().sec();
   }
-
 };
 
 extern Clock g_clock;
index 8b4ce85b512511a2e9a0d7a16cbbb42775459cf5..8027d1a8e722d90a94cbb8414e3eb4a31e5340ce 100644 (file)
@@ -212,6 +212,7 @@ struct config_option config_optionsp[] = {
   OPTION(paxos_propose_interval, OPT_DOUBLE, 1.0),  // gather updates for this long before proposing a map update
   OPTION(paxos_min_wait, OPT_DOUBLE, 0.05),  // min time to gather updates for after period of inactivity
   OPTION(paxos_observer_timeout, OPT_DOUBLE, 5*60), // gather updates for this long before proposing a map update
+  OPTION(clock_offset, OPT_DOUBLE, 0), // how much to offset the system clock by with g_clock
   OPTION(auth_supported, OPT_STR, "none"),
   OPTION(auth_mon_ticket_ttl, OPT_DOUBLE, 60*60*12),
   OPTION(auth_service_ticket_ttl, OPT_DOUBLE, 60*60),
index f5e8e61e85ba30df2c8e8288447a32b91fa6d13d..3ac0928db818624732d18fe0ee93ed36bf6031e9 100644 (file)
@@ -245,6 +245,8 @@ public:
   double paxos_min_wait;
   double paxos_observer_timeout;
 
+  double clock_offset;
+
   // auth
   std::string auth_supported;
   double auth_mon_ticket_ttl;