summaryrefslogtreecommitdiff
path: root/src/mongo/db/logical_clock.cpp
diff options
context:
space:
mode:
authorJack Mulrow <jack.mulrow@mongodb.com>2017-06-08 19:06:02 -0400
committerJack Mulrow <jack.mulrow@mongodb.com>2017-06-16 14:11:33 -0400
commit1dfd505d9fd3547a963fe748c34690c0d5c9add4 (patch)
tree9e700fcf85f1a4b52ca92d963acc5b416adc542f /src/mongo/db/logical_clock.cpp
parent73390210633a157f87221d561ce6cad1497225f9 (diff)
downloadmongo-1dfd505d9fd3547a963fe748c34690c0d5c9add4.tar.gz
SERVER-28459 Prevent the max value from being reached in the logical clock
Diffstat (limited to 'src/mongo/db/logical_clock.cpp')
-rw-r--r--src/mongo/db/logical_clock.cpp21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/mongo/db/logical_clock.cpp b/src/mongo/db/logical_clock.cpp
index 35861cf9ea2..d8e4d097ef4 100644
--- a/src/mongo/db/logical_clock.cpp
+++ b/src/mongo/db/logical_clock.cpp
@@ -69,6 +69,11 @@ public:
namespace {
const auto getLogicalClock = ServiceContext::declareDecoration<std::unique_ptr<LogicalClock>>();
+
+bool lessThanOrEqualToMaxPossibleTime(LogicalTime time, uint64_t nTicks) {
+ return time.asTimestamp().getSecs() <= LogicalClock::kMaxSignedInt &&
+ time.asTimestamp().getInc() <= (LogicalClock::kMaxSignedInt - nTicks);
+}
}
LogicalClock* LogicalClock::get(ServiceContext* service) {
@@ -108,7 +113,7 @@ Status LogicalClock::advanceClusterTime(const LogicalTime newTime) {
LogicalTime LogicalClock::reserveTicks(uint64_t nTicks) {
- invariant(nTicks > 0 && nTicks < (1U << 31));
+ invariant(nTicks > 0 && nTicks <= kMaxSignedInt);
stdx::lock_guard<stdx::mutex> lock(_mutex);
@@ -127,7 +132,7 @@ LogicalTime LogicalClock::reserveTicks(uint64_t nTicks) {
// in order to preserve compatibility with potentially signed or unsigned integral Timestamp
// increment types. It is also unlikely to apply more than 2^31 oplog entries in the span of one
// second.
- else if (clusterTime.asTimestamp().getInc() >= ((1U << 31) - nTicks)) {
+ else if (clusterTime.asTimestamp().getInc() > (kMaxSignedInt - nTicks)) {
log() << "Exceeded maximum allowable increment value within one second. Moving clusterTime "
"forward to the next second.";
@@ -136,6 +141,10 @@ LogicalTime LogicalClock::reserveTicks(uint64_t nTicks) {
clusterTime = LogicalTime(Timestamp(clusterTime.asTimestamp().getSecs() + 1, 0));
}
+ uassert(40482,
+ "cluster time cannot be advanced beyond its maximum value",
+ lessThanOrEqualToMaxPossibleTime(clusterTime, nTicks));
+
// Save the next cluster time.
clusterTime.addTicks(1);
_clusterTime = clusterTime;
@@ -154,6 +163,10 @@ void LogicalClock::setClusterTimeFromTrustedSource(LogicalTime newTime) {
// Rate limit checks are skipped here so a server with no activity for longer than
// maxAcceptableLogicalClockDriftSecs seconds can still have its cluster time initialized.
+ uassert(40483,
+ "cluster time cannot be advanced beyond its maximum value",
+ lessThanOrEqualToMaxPossibleTime(newTime, 0));
+
if (newTime > _clusterTime) {
_clusterTime = newTime;
}
@@ -174,6 +187,10 @@ Status LogicalClock::_passesRateLimiter_inlock(LogicalTime newTime) {
<< ".");
}
+ uassert(40484,
+ "cluster time cannot be advanced beyond its maximum value",
+ lessThanOrEqualToMaxPossibleTime(newTime, 0));
+
return Status::OK();
}