diff options
author | Ian Boros <puppyofkosh@gmail.com> | 2019-05-21 17:53:00 -0400 |
---|---|---|
committer | Ian Boros <puppyofkosh@gmail.com> | 2019-05-28 11:44:42 -0400 |
commit | 3927d0fdcc4b93ea5d7f007eefcb9e505d012cab (patch) | |
tree | 076bae37ba1db4ee623e511f9a09a1814231e53a /src/mongo/db/pipeline | |
parent | 3219b9784947b4f1bb7f07d56a42610e74eba1cd (diff) | |
download | mongo-3927d0fdcc4b93ea5d7f007eefcb9e505d012cab.tar.gz |
SERVER-40015 make $sb work sharded
Diffstat (limited to 'src/mongo/db/pipeline')
8 files changed, 47 insertions, 2 deletions
diff --git a/src/mongo/db/pipeline/mongo_process_interface.h b/src/mongo/db/pipeline/mongo_process_interface.h index e96298a9fe3..1e19144b4f5 100644 --- a/src/mongo/db/pipeline/mongo_process_interface.h +++ b/src/mongo/db/pipeline/mongo_process_interface.h @@ -243,6 +243,23 @@ public: const boost::intrusive_ptr<ExpressionContext>& expCtx, Pipeline* pipeline) = 0; /** + * Accepts a pipeline and returns a new one which will draw input from the underlying + * collection _locally_. Trying to run this method on mongos is a programming error. Running + * this method on a shard server will only return results which match the pipeline on that + * shard. + + * Performs no further optimization of the pipeline. NamespaceNotFound will be + * thrown if ExpressionContext has a UUID and that UUID doesn't exist anymore. That should be + * the only case where NamespaceNotFound is returned. + * + * This function takes ownership of the 'pipeline' argument as if it were a unique_ptr. + * Changing it to a unique_ptr introduces a circular dependency on certain platforms where the + * compiler expects to find an implementation of PipelineDeleter. + */ + virtual std::unique_ptr<Pipeline, PipelineDeleter> attachCursorSourceToPipelineForLocalRead( + const boost::intrusive_ptr<ExpressionContext>& expCtx, Pipeline* pipeline) = 0; + + /** * Returns a vector of owned BSONObjs, each of which contains details of an in-progress * operation or, optionally, an idle connection. If userMode is kIncludeAllUsers, report * operations for all authenticated users; otherwise, report only the current user's operations. diff --git a/src/mongo/db/pipeline/mongos_process_interface.h b/src/mongo/db/pipeline/mongos_process_interface.h index ae78e9e7f89..16780eb1398 100644 --- a/src/mongo/db/pipeline/mongos_process_interface.h +++ b/src/mongo/db/pipeline/mongos_process_interface.h @@ -168,6 +168,12 @@ public: std::unique_ptr<Pipeline, PipelineDeleter> attachCursorSourceToPipeline( const boost::intrusive_ptr<ExpressionContext>& expCtx, Pipeline* pipeline) final; + std::unique_ptr<Pipeline, PipelineDeleter> attachCursorSourceToPipelineForLocalRead( + const boost::intrusive_ptr<ExpressionContext>& expCtx, Pipeline* pipeline) final { + // It is not meaningful to perform a "local read" on mongos. + MONGO_UNREACHABLE; + } + std::string getShardName(OperationContext* opCtx) const final { MONGO_UNREACHABLE; } diff --git a/src/mongo/db/pipeline/process_interface_shardsvr.cpp b/src/mongo/db/pipeline/process_interface_shardsvr.cpp index a66fe05d25b..ea6b39f8472 100644 --- a/src/mongo/db/pipeline/process_interface_shardsvr.cpp +++ b/src/mongo/db/pipeline/process_interface_shardsvr.cpp @@ -197,7 +197,7 @@ unique_ptr<Pipeline, PipelineDeleter> MongoInterfaceShardServer::attachCursorSou // this function, to be sure the collection didn't become sharded between the time we checked // whether it's sharded and the time we took the lock. - return MongoInterfaceStandalone::attachCursorSourceToPipeline(expCtx, pipeline.release()); + return attachCursorSourceToPipelineForLocalRead(expCtx, pipeline.release()); } } // namespace mongo diff --git a/src/mongo/db/pipeline/process_interface_standalone.cpp b/src/mongo/db/pipeline/process_interface_standalone.cpp index e0f26909e61..ca12adc1640 100644 --- a/src/mongo/db/pipeline/process_interface_standalone.cpp +++ b/src/mongo/db/pipeline/process_interface_standalone.cpp @@ -379,6 +379,12 @@ std::unique_ptr<Pipeline, PipelineDeleter> MongoInterfaceStandalone::makePipelin unique_ptr<Pipeline, PipelineDeleter> MongoInterfaceStandalone::attachCursorSourceToPipeline( const boost::intrusive_ptr<ExpressionContext>& expCtx, Pipeline* ownedPipeline) { + return attachCursorSourceToPipelineForLocalRead(expCtx, ownedPipeline); +} + +unique_ptr<Pipeline, PipelineDeleter> +MongoInterfaceStandalone::attachCursorSourceToPipelineForLocalRead( + const boost::intrusive_ptr<ExpressionContext>& expCtx, Pipeline* ownedPipeline) { std::unique_ptr<Pipeline, PipelineDeleter> pipeline(ownedPipeline, PipelineDeleter(expCtx->opCtx)); diff --git a/src/mongo/db/pipeline/process_interface_standalone.h b/src/mongo/db/pipeline/process_interface_standalone.h index 6d09bd2a28c..d6b15346f97 100644 --- a/src/mongo/db/pipeline/process_interface_standalone.h +++ b/src/mongo/db/pipeline/process_interface_standalone.h @@ -101,6 +101,8 @@ public: const MakePipelineOptions opts = MakePipelineOptions{}) final; std::unique_ptr<Pipeline, PipelineDeleter> attachCursorSourceToPipeline( const boost::intrusive_ptr<ExpressionContext>& expCtx, Pipeline* pipeline) override; + std::unique_ptr<Pipeline, PipelineDeleter> attachCursorSourceToPipelineForLocalRead( + const boost::intrusive_ptr<ExpressionContext>& expCtx, Pipeline* pipeline) override; std::string getShardName(OperationContext* opCtx) const final; std::pair<std::vector<FieldPath>, bool> collectDocumentKeyFieldsForHostedCollection( OperationContext* opCtx, const NamespaceString&, UUID) const override; diff --git a/src/mongo/db/pipeline/stub_mongo_process_interface.h b/src/mongo/db/pipeline/stub_mongo_process_interface.h index abbf1555cb0..4647a8e2cb8 100644 --- a/src/mongo/db/pipeline/stub_mongo_process_interface.h +++ b/src/mongo/db/pipeline/stub_mongo_process_interface.h @@ -141,6 +141,11 @@ public: MONGO_UNREACHABLE; } + std::unique_ptr<Pipeline, PipelineDeleter> attachCursorSourceToPipelineForLocalRead( + const boost::intrusive_ptr<ExpressionContext>& expCtx, Pipeline* pipeline) override { + MONGO_UNREACHABLE; + } + std::vector<BSONObj> getCurrentOps(const boost::intrusive_ptr<ExpressionContext>& expCtx, CurrentOpConnectionsMode connMode, CurrentOpSessionsMode sessionMode, diff --git a/src/mongo/db/pipeline/stub_mongo_process_interface_lookup_single_document.cpp b/src/mongo/db/pipeline/stub_mongo_process_interface_lookup_single_document.cpp index cb4abf32cb6..a5b877a9e49 100644 --- a/src/mongo/db/pipeline/stub_mongo_process_interface_lookup_single_document.cpp +++ b/src/mongo/db/pipeline/stub_mongo_process_interface_lookup_single_document.cpp @@ -56,7 +56,7 @@ StubMongoProcessInterfaceLookupSingleDocument::makePipeline( } std::unique_ptr<Pipeline, PipelineDeleter> -StubMongoProcessInterfaceLookupSingleDocument::attachCursorSourceToPipeline( +StubMongoProcessInterfaceLookupSingleDocument::attachCursorSourceToPipelineForLocalRead( const boost::intrusive_ptr<ExpressionContext>& expCtx, Pipeline* ownedPipeline) { std::unique_ptr<Pipeline, PipelineDeleter> pipeline(ownedPipeline, PipelineDeleter(expCtx->opCtx)); @@ -64,6 +64,13 @@ StubMongoProcessInterfaceLookupSingleDocument::attachCursorSourceToPipeline( return pipeline; } +std::unique_ptr<Pipeline, PipelineDeleter> +StubMongoProcessInterfaceLookupSingleDocument::attachCursorSourceToPipeline( + const boost::intrusive_ptr<ExpressionContext>& expCtx, Pipeline* ownedPipeline) { + return attachCursorSourceToPipelineForLocalRead(expCtx, ownedPipeline); +} + + boost::optional<Document> StubMongoProcessInterfaceLookupSingleDocument::lookupSingleDocument( const boost::intrusive_ptr<ExpressionContext>& expCtx, const NamespaceString& nss, diff --git a/src/mongo/db/pipeline/stub_mongo_process_interface_lookup_single_document.h b/src/mongo/db/pipeline/stub_mongo_process_interface_lookup_single_document.h index 089d38b2908..4b3bcbaafdc 100644 --- a/src/mongo/db/pipeline/stub_mongo_process_interface_lookup_single_document.h +++ b/src/mongo/db/pipeline/stub_mongo_process_interface_lookup_single_document.h @@ -56,6 +56,8 @@ public: std::unique_ptr<Pipeline, PipelineDeleter> attachCursorSourceToPipeline( const boost::intrusive_ptr<ExpressionContext>& expCtx, Pipeline* ownedPipeline) final; + std::unique_ptr<Pipeline, PipelineDeleter> attachCursorSourceToPipelineForLocalRead( + const boost::intrusive_ptr<ExpressionContext>& expCtx, Pipeline* ownedPipeline) final; boost::optional<Document> lookupSingleDocument( const boost::intrusive_ptr<ExpressionContext>& expCtx, |