summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline
diff options
context:
space:
mode:
authorCharlie Swanson <charlie.swanson@mongodb.com>2017-11-07 16:58:37 +0000
committerCharlie Swanson <charlie.swanson@mongodb.com>2017-11-17 17:20:45 -0500
commitf7122973bd8001bb8dd393b7ad7851493b8b7743 (patch)
tree13614d9c57256c1b374e45d5a2a676ac518813a5 /src/mongo/db/pipeline
parenta40d277a1c7a735e4d7ed5cf394e23181f8620fb (diff)
downloadmongo-f7122973bd8001bb8dd393b7ad7851493b8b7743.tar.gz
SERVER-31665 Use correct read concern/preference during update lookup
Diffstat (limited to 'src/mongo/db/pipeline')
-rw-r--r--src/mongo/db/pipeline/aggregation_request.h2
-rw-r--r--src/mongo/db/pipeline/document_source.h8
-rw-r--r--src/mongo/db/pipeline/document_source_lookup_change_post_image.cpp10
-rw-r--r--src/mongo/db/pipeline/document_source_lookup_change_post_image_test.cpp3
-rw-r--r--src/mongo/db/pipeline/expression_context.cpp2
-rw-r--r--src/mongo/db/pipeline/expression_context.h3
-rw-r--r--src/mongo/db/pipeline/pipeline_d.cpp7
-rw-r--r--src/mongo/db/pipeline/stub_mongo_process_interface.h3
8 files changed, 28 insertions, 10 deletions
diff --git a/src/mongo/db/pipeline/aggregation_request.h b/src/mongo/db/pipeline/aggregation_request.h
index b34fc383d20..d6b87a5f183 100644
--- a/src/mongo/db/pipeline/aggregation_request.h
+++ b/src/mongo/db/pipeline/aggregation_request.h
@@ -274,7 +274,7 @@ private:
// {$hint: <String>}, where <String> is the index name hinted.
BSONObj _hint;
- // The comment parameter attached to this aggregation.
+ // The comment parameter attached to this aggregation, empty if not set.
std::string _comment;
BSONObj _readConcern;
diff --git a/src/mongo/db/pipeline/document_source.h b/src/mongo/db/pipeline/document_source.h
index 0ecd0fcf92a..4585c68637c 100644
--- a/src/mongo/db/pipeline/document_source.h
+++ b/src/mongo/db/pipeline/document_source.h
@@ -847,9 +847,11 @@ public:
* no matching documents were found, including cases where the given namespace does not
* exist.
*/
- virtual boost::optional<Document> lookupSingleDocument(const NamespaceString& nss,
- UUID collectionUUID,
- const Document& documentKey) = 0;
+ virtual boost::optional<Document> lookupSingleDocument(
+ const NamespaceString& nss,
+ UUID collectionUUID,
+ const Document& documentKey,
+ boost::optional<BSONObj> readConcern) = 0;
/**
* Returns a vector of all local cursors.
diff --git a/src/mongo/db/pipeline/document_source_lookup_change_post_image.cpp b/src/mongo/db/pipeline/document_source_lookup_change_post_image.cpp
index 7752fbfd751..b616b5ec659 100644
--- a/src/mongo/db/pipeline/document_source_lookup_change_post_image.cpp
+++ b/src/mongo/db/pipeline/document_source_lookup_change_post_image.cpp
@@ -105,9 +105,15 @@ Value DocumentSourceLookupChangePostImage::lookupPostImage(const Document& updat
auto resumeToken =
ResumeToken::parse(updateOp[DocumentSourceChangeStream::kIdField].getDocument());
+ const auto readConcern = pExpCtx->inMongos
+ ? boost::optional<BSONObj>(BSON("level"
+ << "majority"
+ << "afterClusterTime"
+ << resumeToken.getData().clusterTime))
+ : boost::none;
invariant(resumeToken.getData().uuid);
- auto lookedUpDoc =
- _mongoProcessInterface->lookupSingleDocument(nss, *resumeToken.getData().uuid, documentKey);
+ auto lookedUpDoc = _mongoProcessInterface->lookupSingleDocument(
+ nss, *resumeToken.getData().uuid, documentKey, readConcern);
// Check whether the lookup returned any documents. Even if the lookup itself succeeded, it may
// not have returned any results if the document was deleted in the time since the update op.
diff --git a/src/mongo/db/pipeline/document_source_lookup_change_post_image_test.cpp b/src/mongo/db/pipeline/document_source_lookup_change_post_image_test.cpp
index 3d35f875619..1d003c9c09e 100644
--- a/src/mongo/db/pipeline/document_source_lookup_change_post_image_test.cpp
+++ b/src/mongo/db/pipeline/document_source_lookup_change_post_image_test.cpp
@@ -115,7 +115,8 @@ public:
boost::optional<Document> lookupSingleDocument(const NamespaceString& nss,
UUID collectionUUID,
- const Document& documentKey) {
+ const Document& documentKey,
+ boost::optional<BSONObj> readConcern) {
boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest(nss));
auto swPipeline = makePipeline({BSON("$match" << documentKey)}, expCtx);
if (swPipeline == ErrorCodes::NamespaceNotFound) {
diff --git a/src/mongo/db/pipeline/expression_context.cpp b/src/mongo/db/pipeline/expression_context.cpp
index e2b2e1e758d..471a66626e1 100644
--- a/src/mongo/db/pipeline/expression_context.cpp
+++ b/src/mongo/db/pipeline/expression_context.cpp
@@ -46,6 +46,7 @@ ExpressionContext::ExpressionContext(OperationContext* opCtx,
StringMap<ResolvedNamespace> resolvedNamespaces)
: ExpressionContext(opCtx, collator.get()) {
explain = request.getExplain();
+ comment = request.getComment();
fromMongos = request.isFromMongos();
needsMerge = request.needsMerge();
allowDiskUse = request.shouldAllowDiskUse();
@@ -131,6 +132,7 @@ intrusive_ptr<ExpressionContext> ExpressionContext::copyWith(
expCtx->uuid = std::move(uuid);
expCtx->explain = explain;
+ expCtx->comment = comment;
expCtx->needsMerge = needsMerge;
expCtx->fromMongos = fromMongos;
expCtx->from34Mongos = from34Mongos;
diff --git a/src/mongo/db/pipeline/expression_context.h b/src/mongo/db/pipeline/expression_context.h
index a2e16163a73..e949e068f2b 100644
--- a/src/mongo/db/pipeline/expression_context.h
+++ b/src/mongo/db/pipeline/expression_context.h
@@ -165,6 +165,9 @@ public:
// The explain verbosity requested by the user, or boost::none if no explain was requested.
boost::optional<ExplainOptions::Verbosity> explain;
+ // The comment provided by the user, or the empty string if no comment was provided.
+ std::string comment;
+
bool fromMongos = false;
bool needsMerge = false;
bool inMongos = false;
diff --git a/src/mongo/db/pipeline/pipeline_d.cpp b/src/mongo/db/pipeline/pipeline_d.cpp
index b32f18828d0..f19c9aa3abf 100644
--- a/src/mongo/db/pipeline/pipeline_d.cpp
+++ b/src/mongo/db/pipeline/pipeline_d.cpp
@@ -386,12 +386,15 @@ public:
boost::optional<Document> lookupSingleDocument(const NamespaceString& nss,
UUID collectionUUID,
- const Document& documentKey) final {
+ const Document& documentKey,
+ boost::optional<BSONObj> readConcern) final {
+ invariant(!readConcern); // We don't currently support a read concern on mongod - it's only
+ // expected to be necessary on mongos.
+ //
// Be sure to do the lookup using the collection default collation.
auto foreignExpCtx =
_ctx->copyWith(nss, collectionUUID, _getCollectionDefaultCollator(nss, collectionUUID));
auto swPipeline = makePipeline({BSON("$match" << documentKey)}, foreignExpCtx);
-
if (swPipeline == ErrorCodes::NamespaceNotFound) {
return boost::none;
}
diff --git a/src/mongo/db/pipeline/stub_mongo_process_interface.h b/src/mongo/db/pipeline/stub_mongo_process_interface.h
index c0beb0504ba..6b0032b1fd3 100644
--- a/src/mongo/db/pipeline/stub_mongo_process_interface.h
+++ b/src/mongo/db/pipeline/stub_mongo_process_interface.h
@@ -120,7 +120,8 @@ public:
boost::optional<Document> lookupSingleDocument(const NamespaceString& nss,
UUID collectionUUID,
- const Document& documentKey) {
+ const Document& documentKey,
+ boost::optional<BSONObj> readConcern) {
MONGO_UNREACHABLE;
}