diff options
author | Misha Tyulenev <misha@mongodb.com> | 2017-02-14 17:39:46 -0500 |
---|---|---|
committer | Misha Tyulenev <misha@mongodb.com> | 2017-02-15 14:47:55 -0500 |
commit | 7d36244539cff23adb813f9cc006b1e9fe4305e0 (patch) | |
tree | fe139db2fd9807151435c296dc77697a69523fab /src/mongo/db/logical_clock.cpp | |
parent | 7284884f3d8f3cf1d1489579180c2637efcc42b2 (diff) | |
download | mongo-7d36244539cff23adb813f9cc006b1e9fe4305e0.tar.gz |
SERVER-27746: Integrate LogicalClock with oplog
Diffstat (limited to 'src/mongo/db/logical_clock.cpp')
-rw-r--r-- | src/mongo/db/logical_clock.cpp | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/mongo/db/logical_clock.cpp b/src/mongo/db/logical_clock.cpp index ad61792045b..6aeef259528 100644 --- a/src/mongo/db/logical_clock.cpp +++ b/src/mongo/db/logical_clock.cpp @@ -26,13 +26,17 @@ * it in the license file. */ +#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault + +#include "mongo/platform/basic.h" + #include "mongo/db/logical_clock.h" #include "mongo/base/status.h" #include "mongo/db/operation_context.h" #include "mongo/db/service_context.h" #include "mongo/db/time_proof_service.h" -#include "mongo/platform/basic.h" +#include "mongo/util/log.h" namespace mongo { @@ -85,6 +89,16 @@ Status LogicalClock::advanceClusterTime(const SignedLogicalTime& newTime) { return Status::OK(); } +Status LogicalClock::advanceClusterTimeFromTrustedSource(LogicalTime newTime) { + stdx::lock_guard<stdx::mutex> lock(_mutex); + // TODO: rate check per SERVER-27721 + if (newTime > _clusterTime.getTime()) { + _clusterTime = _makeSignedLogicalTime(newTime); + } + + return Status::OK(); +} + LogicalTime LogicalClock::reserveTicks(uint64_t ticks) { invariant(ticks > 0); @@ -104,6 +118,14 @@ LogicalTime LogicalClock::reserveTicks(uint64_t ticks) { auto currentTime = clusterTimestamp; clusterTimestamp.addTicks(ticks - 1); + // Fail if time is not moving forward for 2**31 ticks + if (MONGO_unlikely(clusterTimestamp.asTimestamp().getSecs() > wallClockSecs) && + clusterTimestamp.asTimestamp().getInc() >= 1U << 31) { + mongo::severe() << "clock skew detected, prev: " << wallClockSecs + << " now: " << clusterTimestamp.asTimestamp().getSecs(); + fassertFailed(17449); + } + _clusterTime = _makeSignedLogicalTime(clusterTimestamp); return currentTime; } |