summaryrefslogtreecommitdiff
path: root/src/mongo/db/query/query_request.cpp
diff options
context:
space:
mode:
authorMax Hirschhorn <max.hirschhorn@mongodb.com>2019-02-11 15:43:27 -0500
committerMax Hirschhorn <max.hirschhorn@mongodb.com>2019-02-11 15:43:27 -0500
commit9db1a8dffe753808bea0d8c47d9fc959eaea9ea0 (patch)
tree26b5750c5088d745ab1fb93596d010501b0b4cbe /src/mongo/db/query/query_request.cpp
parent691ab6da0c38f52f32c1028a8fa7447997ced255 (diff)
downloadmongo-9db1a8dffe753808bea0d8c47d9fc959eaea9ea0.tar.gz
SERVER-39169 Add $_internalReadAtClusterTime option to find and dbHash.
The new $_internalReadAtClusterTime option replaces all usages of running the dbHash command inside of a multi-statement transaction. It can be used to read from a consistent snapshot in place of specifying an atClusterTime read concern. Unlike multi-statement transactions, the new $_internalReadAtClusterTime option doesn't cause locks to be left on the server after returning a network response. It instead restores the snapshot to read from as part of handling the request.
Diffstat (limited to 'src/mongo/db/query/query_request.cpp')
-rw-r--r--src/mongo/db/query/query_request.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/mongo/db/query/query_request.cpp b/src/mongo/db/query/query_request.cpp
index 7f02487ff7f..42c338bb5ec 100644
--- a/src/mongo/db/query/query_request.cpp
+++ b/src/mongo/db/query/query_request.cpp
@@ -103,6 +103,7 @@ const char kTermField[] = "term";
const char kOptionsField[] = "options";
const char kReadOnceField[] = "readOnce";
const char kAllowSpeculativeMajorityReadField[] = "allowSpeculativeMajorityRead";
+const char kInternalReadAtClusterTimeField[] = "$_internalReadAtClusterTime";
// Field names for sorting options.
const char kNaturalSortField[] = "$natural";
@@ -381,6 +382,12 @@ StatusWith<unique_ptr<QueryRequest>> QueryRequest::parseFromFindCommand(unique_p
return status;
}
qr->_allowSpeculativeMajorityRead = el.boolean();
+ } else if (fieldName == kInternalReadAtClusterTimeField) {
+ Status status = checkFieldType(el, BSONType::bsonTimestamp);
+ if (!status.isOK()) {
+ return status;
+ }
+ qr->_internalReadAtClusterTime = el.timestamp();
} else if (!isGenericArgument(fieldName)) {
return Status(ErrorCodes::FailedToParse,
str::stream() << "Failed to parse: " << cmdObj.toString() << ". "
@@ -549,6 +556,10 @@ void QueryRequest::asFindCommandInternal(BSONObjBuilder* cmdBuilder) const {
if (_allowSpeculativeMajorityRead) {
cmdBuilder->append(kAllowSpeculativeMajorityReadField, true);
}
+
+ if (_internalReadAtClusterTime) {
+ cmdBuilder->append(kInternalReadAtClusterTimeField, *_internalReadAtClusterTime);
+ }
}
void QueryRequest::addReturnKeyMetaProj() {
@@ -1044,6 +1055,12 @@ StatusWith<BSONObj> QueryRequest::asAggregationCommand() const {
<< " not supported in aggregation."};
}
+ if (_internalReadAtClusterTime) {
+ return {ErrorCodes::InvalidPipelineOperator,
+ str::stream() << "Option " << kInternalReadAtClusterTimeField
+ << " not supported in aggregation."};
+ }
+
// Now that we've successfully validated this QR, begin building the aggregation command.
aggregationBuilder.append("aggregate", _nss.coll());