summaryrefslogtreecommitdiff
path: root/src/mongo/db/repl/optime.cpp
diff options
context:
space:
mode:
authorEric Milkie <milkie@10gen.com>2013-02-27 07:24:29 -0500
committerEric Milkie <milkie@10gen.com>2013-03-11 11:15:02 -0400
commitcac2effa776649208b8428f6c8c9692d45148fd2 (patch)
tree53851ecfb8378103b5e1dd69c5b316badc15e715 /src/mongo/db/repl/optime.cpp
parentc77acec063b7319a2e2bb4d304cb3d5abb563c29 (diff)
downloadmongo-cac2effa776649208b8428f6c8c9692d45148fd2.tar.gz
SERVER-7772 move optime.h and create new optime.cpp
Diffstat (limited to 'src/mongo/db/repl/optime.cpp')
-rw-r--r--src/mongo/db/repl/optime.cpp78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/mongo/db/repl/optime.cpp b/src/mongo/db/repl/optime.cpp
new file mode 100644
index 00000000000..5f3f4055252
--- /dev/null
+++ b/src/mongo/db/repl/optime.cpp
@@ -0,0 +1,78 @@
+/* Copyright 2009 10gen Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "mongo/db/repl/optime.h"
+
+#include <iostream>
+#include <ctime>
+
+#include "mongo/bson/inline_decls.h"
+#include "mongo/util/debug_util.h"
+#include "mongo/util/log.h"
+
+namespace mongo {
+
+ NOINLINE_DECL OpTime OpTime::skewed() {
+ bool toLog = false;
+ ONCE toLog = true;
+ RARELY toLog = true;
+ last.i++;
+ if ( last.i & 0x80000000 )
+ toLog = true;
+ if ( toLog ) {
+ log() << "clock skew detected prev: " << last.secs << " now: " << (unsigned) time(0) << endl;
+ }
+ if ( last.i & 0x80000000 ) {
+ log() << "error large clock skew detected, shutting down" << endl;
+ throw ClockSkewException();
+ }
+ return last;
+ }
+
+ /*static*/ OpTime OpTime::_now() {
+ OpTime result;
+ unsigned t = (unsigned) time(0);
+ if ( last.secs == t ) {
+ last.i++;
+ result = last;
+ }
+ else if ( t < last.secs ) {
+ result = skewed(); // separate function to keep out of the hot code path
+ }
+ else {
+ last = OpTime(t, 1);
+ result = last;
+ }
+ notifier.notify_all();
+ return last;
+ }
+
+ OpTime OpTime::now(const mongo::mutex::scoped_lock&) {
+ return _now();
+ }
+
+ OpTime OpTime::getLast(const mongo::mutex::scoped_lock&) {
+ return last;
+ }
+
+ void OpTime::waitForDifferent(unsigned millis){
+ mutex::scoped_lock lk(m);
+ while (*this == last) {
+ if (!notifier.timed_wait(lk.boost(), boost::posix_time::milliseconds(millis)))
+ return; // timed out
+ }
+ }
+
+}