diff options
author | Matthew Russotto <matthew.russotto@10gen.com> | 2017-11-10 21:14:01 -0500 |
---|---|---|
committer | Matthew Russotto <matthew.russotto@10gen.com> | 2017-11-14 17:27:43 -0500 |
commit | 685001a0e63b7966f34b6513c886b156aee0258b (patch) | |
tree | 224c0bcecbba7ab5a0043f69b248dda88bddb956 /src | |
parent | 6e618dac9c850f0bbcc9ef471243ac8a8abfd2e2 (diff) | |
download | mongo-685001a0e63b7966f34b6513c886b156aee0258b.tar.gz |
SERVER-30834 Look up collation for unsharded collection when running aggregate on mongos.
(cherry picked from commit b4f6f2c967afc21d03bfca68f09d148d50e59134)
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/s/commands/cluster_aggregate.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/mongo/s/commands/cluster_aggregate.cpp b/src/mongo/s/commands/cluster_aggregate.cpp index da76c01db97..b49625a7255 100644 --- a/src/mongo/s/commands/cluster_aggregate.cpp +++ b/src/mongo/s/commands/cluster_aggregate.cpp @@ -34,6 +34,7 @@ #include <boost/intrusive_ptr.hpp> +#include "mongo/bson/util/bson_extract.h" #include "mongo/db/auth/authorization_session.h" #include "mongo/db/client.h" #include "mongo/db/commands.h" @@ -605,6 +606,33 @@ BSONObj establishMergingMongosCursor( return cursorResponse.obj(); } +BSONObj getDefaultCollationForUnshardedCollection(const Shard* primaryShard, + const NamespaceString& nss) { + ScopedDbConnection conn(primaryShard->getConnString()); + BSONObj defaultCollation; + std::list<BSONObj> all = + conn->getCollectionInfos(nss.db().toString(), BSON("name" << nss.coll())); + if (all.empty()) { + return defaultCollation; + } + BSONObj collectionInfo = all.front(); + if (collectionInfo["options"].type() == BSONType::Object) { + BSONObj collectionOptions = collectionInfo["options"].Obj(); + BSONElement collationElement; + auto status = bsonExtractTypedField( + collectionOptions, "collation", BSONType::Object, &collationElement); + if (status.isOK()) { + defaultCollation = collationElement.Obj().getOwned(); + uassert(ErrorCodes::BadValue, + "Default collation in collection metadata cannot be empty.", + !defaultCollation.isEmpty()); + } else if (status != ErrorCodes::NoSuchKey) { + uassertStatusOK(status); + } + } + return defaultCollation; +} + } // namespace Status ClusterAggregate::runAggregate(OperationContext* opCtx, @@ -669,6 +697,14 @@ Status ClusterAggregate::runAggregate(OperationContext* opCtx, if (chunkMgr->getDefaultCollator()) { collation = chunkMgr->getDefaultCollator()->clone(); } + } else { + // Unsharded collection. Get collection metadata from primary chunk. + auto collationObj = getDefaultCollationForUnshardedCollection( + executionNsRoutingInfo.primary().get(), namespaces.executionNss); + if (!collationObj.isEmpty()) { + collation = uassertStatusOK(CollatorFactoryInterface::get(opCtx->getServiceContext()) + ->makeFromBSON(collationObj)); + } } boost::intrusive_ptr<ExpressionContext> mergeCtx = |