summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
authorMilitsa Sotirova <militsa.sotirova@mongodb.com>2021-06-21 18:00:06 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-07-01 13:45:52 +0000
commit3f0bedf42873fdf53a0ee3c38d98847d8359c602 (patch)
tree2cdcdd2e1727221f050cea375bf37d2cc7585f3f /src/mongo/db
parenta969d643218bd3df38ff57709949350fceab44d2 (diff)
downloadmongo-3f0bedf42873fdf53a0ee3c38d98847d8359c602.tar.gz
SERVER-52021: Create feature flag for support lookup and graphLookup into a sharded collection
Diffstat (limited to 'src/mongo/db')
-rw-r--r--src/mongo/db/pipeline/document_source_graph_lookup.cpp13
-rw-r--r--src/mongo/db/pipeline/document_source_lookup.cpp22
-rw-r--r--src/mongo/db/pipeline/document_source_lookup.h4
-rw-r--r--src/mongo/db/query/query_feature_flags.idl5
-rw-r--r--src/mongo/db/query/query_knobs.idl7
5 files changed, 27 insertions, 24 deletions
diff --git a/src/mongo/db/pipeline/document_source_graph_lookup.cpp b/src/mongo/db/pipeline/document_source_graph_lookup.cpp
index c6550aef5f6..f550c2c68a2 100644
--- a/src/mongo/db/pipeline/document_source_graph_lookup.cpp
+++ b/src/mongo/db/pipeline/document_source_graph_lookup.cpp
@@ -49,9 +49,6 @@
namespace mongo {
namespace {
-bool foreignShardedLookupAllowed() {
- return getTestCommandsEnabled() && internalQueryAllowShardedLookup.load();
-}
// Parses $graphLookup 'from' field. The 'from' field must be a string with the exception of
// 'local.system.tenantMigration.oplogView'.
@@ -210,7 +207,8 @@ void DocumentSourceGraphLookUp::doBreadthFirstSearch() {
long long depth = 0;
bool shouldPerformAnotherQuery;
do {
- if (!foreignShardedLookupAllowed()) {
+ if (!feature_flags::gFeatureFlagShardedLookup.isEnabled(
+ serverGlobalParams.featureCompatibility)) {
// Enforce that the foreign collection must be unsharded for $graphLookup.
_fromExpCtx->mongoProcessInterface->setExpectedShardVersion(
_fromExpCtx->opCtx, _fromExpCtx->ns, ChunkVersion::UNSHARDED());
@@ -244,7 +242,8 @@ void DocumentSourceGraphLookUp::doBreadthFirstSearch() {
pipelineOpts.optimize = true;
pipelineOpts.attachCursorSource = true;
// By default, $graphLookup doesn't support a sharded 'from' collection.
- pipelineOpts.allowTargetingShards = internalQueryAllowShardedLookup.load();
+ pipelineOpts.allowTargetingShards = feature_flags::gFeatureFlagShardedLookup.isEnabled(
+ serverGlobalParams.featureCompatibility);
_variables.copyToExpCtx(_variablesParseState, _fromExpCtx.get());
auto pipeline = Pipeline::makePipeline(_fromPipeline, _fromExpCtx, pipelineOpts);
while (auto next = pipeline->getNext()) {
@@ -393,7 +392,9 @@ void DocumentSourceGraphLookUp::performSearch() {
if (auto staleInfo = ex.extraInfo<StaleConfigInfo>()) {
uassert(31428,
"Cannot run $graphLookup with sharded foreign collection",
- foreignShardedLookupAllowed() || !staleInfo->getVersionWanted() ||
+ feature_flags::gFeatureFlagShardedLookup.isEnabled(
+ serverGlobalParams.featureCompatibility) ||
+ !staleInfo->getVersionWanted() ||
staleInfo->getVersionWanted() == ChunkVersion::UNSHARDED());
}
throw;
diff --git a/src/mongo/db/pipeline/document_source_lookup.cpp b/src/mongo/db/pipeline/document_source_lookup.cpp
index d34df7f095a..87b7992aff5 100644
--- a/src/mongo/db/pipeline/document_source_lookup.cpp
+++ b/src/mongo/db/pipeline/document_source_lookup.cpp
@@ -87,10 +87,6 @@ void lookupPipeValidator(const Pipeline& pipeline) {
});
}
-bool foreignShardedLookupAllowed() {
- return getTestCommandsEnabled() && internalQueryAllowShardedLookup.load();
-}
-
// Parses $lookup 'from' field. The 'from' field must be a string or one of the following
// exceptions:
// {from: {db: "config", coll: "cache.chunks.*"}, ...} or
@@ -310,7 +306,9 @@ StageConstraints DocumentSourceLookUp::constraints(Pipeline::SplitState) const {
} else {
// When $lookup on sharded foreign collections is allowed, the foreign collection is
// sharded, and the stage is executing on mongos, the stage can run on mongos or any shard.
- hostRequirement = (foreignShardedLookupAllowed() && pExpCtx->inMongos &&
+ hostRequirement = (feature_flags::gFeatureFlagShardedLookup.isEnabled(
+ serverGlobalParams.featureCompatibility) &&
+ pExpCtx->inMongos &&
pExpCtx->mongoProcessInterface->isSharded(pExpCtx->opCtx, _fromNs))
? HostTypeRequirement::kNone
: HostTypeRequirement::kPrimaryShard;
@@ -371,7 +369,9 @@ DocumentSource::GetNextResult DocumentSourceLookUp::doGetNext() {
if (auto staleInfo = ex.extraInfo<StaleConfigInfo>()) {
uassert(51069,
"Cannot run $lookup with sharded foreign collection",
- foreignShardedLookupAllowed() || !staleInfo->getVersionWanted() ||
+ feature_flags::gFeatureFlagShardedLookup.isEnabled(
+ serverGlobalParams.featureCompatibility) ||
+ !staleInfo->getVersionWanted() ||
staleInfo->getVersionWanted() == ChunkVersion::UNSHARDED());
}
throw;
@@ -408,7 +408,8 @@ std::unique_ptr<Pipeline, PipelineDeleter> DocumentSourceLookUp::buildPipeline(
// Resolve the 'let' variables to values per the given input document.
resolveLetVariables(inputDoc, &_fromExpCtx->variables);
- if (!foreignShardedLookupAllowed()) {
+ if (!feature_flags::gFeatureFlagShardedLookup.isEnabled(
+ serverGlobalParams.featureCompatibility)) {
// Enforce that the foreign collection must be unsharded for lookup.
_fromExpCtx->mongoProcessInterface->setExpectedShardVersion(
_fromExpCtx->opCtx, _fromExpCtx->ns, ChunkVersion::UNSHARDED());
@@ -421,7 +422,8 @@ std::unique_ptr<Pipeline, PipelineDeleter> DocumentSourceLookUp::buildPipeline(
pipelineOpts.attachCursorSource = true;
pipelineOpts.validator = lookupPipeValidator;
// By default, $lookup doesnt support sharded 'from' collections.
- pipelineOpts.allowTargetingShards = internalQueryAllowShardedLookup.load();
+ pipelineOpts.allowTargetingShards = feature_flags::gFeatureFlagShardedLookup.isEnabled(
+ serverGlobalParams.featureCompatibility);
return Pipeline::makePipeline(_resolvedPipeline, _fromExpCtx, pipelineOpts);
}
@@ -451,7 +453,9 @@ std::unique_ptr<Pipeline, PipelineDeleter> DocumentSourceLookUp::buildPipeline(
if (!_cache->isServing()) {
// The cache has either been abandoned or has not yet been built. Attach a cursor.
pipeline = pExpCtx->mongoProcessInterface->attachCursorSourceToPipeline(
- pipeline.release(), internalQueryAllowShardedLookup.load() /* allowTargetingShards*/);
+ pipeline.release(),
+ feature_flags::gFeatureFlagShardedLookup
+ .isEnabledAndIgnoreFCV() /* allowTargetingShards*/);
}
// If the cache has been abandoned, release it.
diff --git a/src/mongo/db/pipeline/document_source_lookup.h b/src/mongo/db/pipeline/document_source_lookup.h
index 75a2fc42a4e..29df6539f17 100644
--- a/src/mongo/db/pipeline/document_source_lookup.h
+++ b/src/mongo/db/pipeline/document_source_lookup.h
@@ -76,8 +76,8 @@ public:
* Lookup from a sharded collection may not be allowed.
*/
bool allowShardedForeignCollection(NamespaceString nss) const override final {
- const bool foreignShardedAllowed =
- getTestCommandsEnabled() && internalQueryAllowShardedLookup.load();
+ const bool foreignShardedAllowed = feature_flags::gFeatureFlagShardedLookup.isEnabled(
+ serverGlobalParams.featureCompatibility);
if (foreignShardedAllowed) {
return true;
}
diff --git a/src/mongo/db/query/query_feature_flags.idl b/src/mongo/db/query/query_feature_flags.idl
index 4c7cd6a1b46..1ce15a6fb19 100644
--- a/src/mongo/db/query/query_feature_flags.idl
+++ b/src/mongo/db/query/query_feature_flags.idl
@@ -60,3 +60,8 @@ feature_flags:
description: "Feature flag for allowing use of topN family of accumulators"
cpp_varname: gFeatureFlagExactTopNAccumulator
default: false
+
+ featureFlagShardedLookup:
+ description: "Feature flag for allowing $lookup/$graphLookup into a sharded collection"
+ cpp_varname: gFeatureFlagShardedLookup
+ default: false
diff --git a/src/mongo/db/query/query_knobs.idl b/src/mongo/db/query/query_knobs.idl
index fb43fd9c4c2..24e265a7877 100644
--- a/src/mongo/db/query/query_knobs.idl
+++ b/src/mongo/db/query/query_knobs.idl
@@ -350,13 +350,6 @@ server_parameters:
cpp_vartype: AtomicWord<bool>
default: false
- internalQueryAllowShardedLookup:
- description: "If true, activates the incomplete sharded $lookup feature."
- set_at: [ startup, runtime ]
- cpp_varname: "internalQueryAllowShardedLookup"
- cpp_vartype: AtomicWord<bool>
- default: false
-
internalQueryMaxJsEmitBytes:
description: "Limits the vector of values emitted from a single document's call to JsEmit to the
given size in bytes."