diff options
author | Spencer T Brody <spencer@mongodb.com> | 2018-03-09 19:25:12 -0500 |
---|---|---|
committer | Spencer T Brody <spencer@mongodb.com> | 2018-03-15 19:31:57 -0400 |
commit | 0abcf8f3cf547327c4dab4aea1ff22e1d75a8db8 (patch) | |
tree | 1974c43d6ee2abf8f62ac782ba3054db362b2051 /src/mongo/db/read_concern.cpp | |
parent | 352cf826069d74ceb6c8a4b4ae2198098c05ba2a (diff) | |
download | mongo-0abcf8f3cf547327c4dab4aea1ff22e1d75a8db8.tar.gz |
SERVER-33798 Fail atClusterTime reads at times newer than the current cluster time
Diffstat (limited to 'src/mongo/db/read_concern.cpp')
-rw-r--r-- | src/mongo/db/read_concern.cpp | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/src/mongo/db/read_concern.cpp b/src/mongo/db/read_concern.cpp index b5af878c5b8..95350667659 100644 --- a/src/mongo/db/read_concern.cpp +++ b/src/mongo/db/read_concern.cpp @@ -255,18 +255,32 @@ Status waitForReadConcern(OperationContext* opCtx, if (!allowAfterClusterTime) { return {ErrorCodes::InvalidOptions, "afterClusterTime is not allowed for this command"}; } - - auto currentTime = LogicalClock::get(opCtx)->getClusterTime(); - if (currentTime < *afterClusterTime) { - return {ErrorCodes::InvalidOptions, - "readConcern afterClusterTime must not be greater than clusterTime value"}; - } } if (!readConcernArgs.isEmpty()) { invariant(!afterClusterTime || !atClusterTime); auto targetClusterTime = afterClusterTime ? afterClusterTime : atClusterTime; - if (replCoord->isReplEnabled() && targetClusterTime) { + + if (targetClusterTime) { + std::string readConcernName = afterClusterTime ? "afterClusterTime" : "atClusterTime"; + + if (!replCoord->isReplEnabled()) { + return {ErrorCodes::IllegalOperation, + str::stream() << "Cannot specify " << readConcernName + << " readConcern without replication enabled"}; + } + + auto currentTime = LogicalClock::get(opCtx)->getClusterTime(); + if (currentTime < *targetClusterTime) { + return {ErrorCodes::InvalidOptions, + str::stream() << "readConcern " << readConcernName + << " value must not be greater than the current clusterTime. " + "Requested clusterTime: " + << targetClusterTime->toString() + << "; current clusterTime: " + << currentTime.toString()}; + } + auto status = makeNoopWriteIfNeeded(opCtx, *targetClusterTime); if (!status.isOK()) { LOG(0) << "Failed noop write at clusterTime: " << targetClusterTime->toString() |