summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorJames Wahlin <james@mongodb.com>2021-02-10 15:06:55 -0500
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-03-05 22:01:44 +0000
commita407cf2e8e25aad8762bb379854e10acf17793bd (patch)
tree75c2174a4b9ee4ea157ae2a03837e0dcce84c6ae /src/mongo
parenta6b5cdc3fa1722ea241a3d1ff9575a82e4a46081 (diff)
downloadmongo-a407cf2e8e25aad8762bb379854e10acf17793bd.tar.gz
SERVER-49228 Remove kickback to mongos requirement for cluster view read when view is backed by unsharded collection
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/commands/run_aggregate.cpp31
1 files changed, 28 insertions, 3 deletions
diff --git a/src/mongo/db/commands/run_aggregate.cpp b/src/mongo/db/commands/run_aggregate.cpp
index fe536e06399..c2ceddd2a18 100644
--- a/src/mongo/db/commands/run_aggregate.cpp
+++ b/src/mongo/db/commands/run_aggregate.cpp
@@ -70,6 +70,7 @@
#include "mongo/db/repl/oplog.h"
#include "mongo/db/repl/read_concern_args.h"
#include "mongo/db/repl/speculative_majority_read_info.h"
+#include "mongo/db/s/collection_sharding_state.h"
#include "mongo/db/s/operation_sharding_state.h"
#include "mongo/db/s/sharding_state.h"
#include "mongo/db/service_context.h"
@@ -661,6 +662,10 @@ Status runAggregate(OperationContext* opCtx,
<< " is not supported against a view",
!request.getCollectionUUID());
+ uassert(ErrorCodes::CommandNotSupportedOnView,
+ "mapReduce on a view is not supported",
+ !request.getIsMapReduceCommand());
+
// Check that the default collation of 'view' is compatible with the operation's
// collation. The check is skipped if the request did not specify a collation.
if (!request.getCollation().get_value_or(BSONObj()).isEmpty()) {
@@ -676,13 +681,33 @@ Status runAggregate(OperationContext* opCtx,
auto resolvedView = uassertStatusOK(DatabaseHolder::get(opCtx)
->getViewCatalog(opCtx, nss.db())
->resolveView(opCtx, nss));
- uassert(std::move(resolvedView),
- "On sharded systems, resolved views must be executed by mongos",
- !ShardingState::get(opCtx)->enabled());
// With the view & collation resolved, we can relinquish locks.
ctx.reset();
+ // Set this operation's shard version for the underlying collection to unsharded.
+ // This is prerequisite for future shard versioning checks.
+ OperationShardingState::get(opCtx).initializeClientRoutingVersions(
+ resolvedView.getNamespace(), ChunkVersion::UNSHARDED(), boost::none);
+
+ bool collectionIsSharded = [opCtx, &resolvedView]() {
+ AutoGetCollection autoColl(opCtx,
+ resolvedView.getNamespace(),
+ MODE_IS,
+ AutoGetCollectionViewMode::kViewsPermitted);
+ return CollectionShardingState::get(opCtx, resolvedView.getNamespace())
+ ->getCollectionDescription(opCtx)
+ .isSharded();
+ }();
+
+ uassert(std::move(resolvedView),
+ "Resolved views on sharded collections must be executed by mongos",
+ !collectionIsSharded);
+
+ uassert(std::move(resolvedView),
+ "Explain of a resolved view must be executed by mongos",
+ !ShardingState::get(opCtx)->enabled() || !request.getExplain());
+
// Parse the resolved view into a new aggregation request.
auto newRequest = resolvedView.asExpandedViewAggregation(request);
auto newCmd = aggregation_request_helper::serializeToCommandObj(newRequest);