summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrew Paroski <drew.paroski@mongodb.com>2020-04-28 18:36:49 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-05-19 13:59:42 +0000
commite9c31e791b2e056c016c048d7e21c59e0e2452ea (patch)
tree0c35e40ed4f5d21d06c9765518ec80cbba507093
parent0873f81d970825745da7ac8421744380ad2b92ad (diff)
downloadmongo-e9c31e791b2e056c016c048d7e21c59e0e2452ea.tar.gz
SERVER-47773 Error consistently when tailable cursors and $near are used together
(cherry picked from commit c8ced6df8f620daaa2e539f192f2eef356c63e9c)
-rw-r--r--etc/backports_required_for_multiversion_tests.yml6
-rw-r--r--jstests/core/geo_near_tailable.js25
-rw-r--r--src/mongo/db/query/canonical_query.cpp6
-rw-r--r--src/mongo/db/query/query_planner.cpp4
4 files changed, 37 insertions, 4 deletions
diff --git a/etc/backports_required_for_multiversion_tests.yml b/etc/backports_required_for_multiversion_tests.yml
index 5fad77960bc..7163117d38c 100644
--- a/etc/backports_required_for_multiversion_tests.yml
+++ b/etc/backports_required_for_multiversion_tests.yml
@@ -33,6 +33,8 @@ replica_sets_jscore_multiversion_passthrough:
test_file: jstests/core/txns/new_transaction_waits_for_previous_txn_table_updates.js
- ticket: SERVER-46196
test_file: jstests/core/create_collection_fail_cleanup.js
+- ticket: SERVER-47773
+ test_file: jstests/core/geo_near_tailable.js
replica_sets_multiversion:
- ticket: SERVER-42825
@@ -77,7 +79,11 @@ sharding_multiversion:
sharding_jscore_multiversion_passthrough:
- ticket: SERVER-46196
test_file: jstests/core/create_collection_fail_cleanup.js
+- ticket: SERVER-47773
+ test_file: jstests/core/geo_near_tailable.js
sharded_collections_jscore_multiversion_passthrough:
- ticket: SERVER-46196
test_file: jstests/core/create_collection_fail_cleanup.js
+- ticket: SERVER-47773
+ test_file: jstests/core/geo_near_tailable.js
diff --git a/jstests/core/geo_near_tailable.js b/jstests/core/geo_near_tailable.js
new file mode 100644
index 00000000000..405e236707c
--- /dev/null
+++ b/jstests/core/geo_near_tailable.js
@@ -0,0 +1,25 @@
+// @tags: [requires_capped]
+//
+// Tests that combine $geoNear and tailable cursors.
+//
+(function() {
+"use strict";
+
+let cmdRes;
+const collName = 'geo_near_tailable';
+const cappedCollName = 'geo_near_tailable_capped';
+
+// Avoid using the drop() shell helper here in order to avoid "implicit collection recreation"
+// which can happen when this test runs in certain passthroughs. For details, see
+// "jstests/libs/override_methods/implicitly_shard_accessed_collections.js".
+db.runCommand({drop: collName});
+db.runCommand({drop: cappedCollName});
+assert.commandWorked(db.createCollection(collName));
+assert.commandWorked(db.createCollection(cappedCollName, {capped: true, size: 10000}));
+
+// Error when tailable option is used with NEAR.
+cmdRes = db.runCommand({find: collName, filter: {a: {$geoNear: [1, 2]}}, tailable: true});
+assert.commandFailedWithCode(cmdRes, ErrorCodes.BadValue);
+cmdRes = db.runCommand({find: cappedCollName, filter: {a: {$geoNear: [1, 2]}}, tailable: true});
+assert.commandFailedWithCode(cmdRes, ErrorCodes.BadValue);
+})();
diff --git a/src/mongo/db/query/canonical_query.cpp b/src/mongo/db/query/canonical_query.cpp
index 31b4ea1e575..3ddf8b17a36 100644
--- a/src/mongo/db/query/canonical_query.cpp
+++ b/src/mongo/db/query/canonical_query.cpp
@@ -467,6 +467,12 @@ StatusWith<QueryMetadataBitSet> CanonicalQuery::isValid(MatchExpression* root,
return Status(ErrorCodes::BadValue, "text and tailable cursor not allowed in same query");
}
+ // NEAR and tailable are incompatible.
+ if (numGeoNear > 0 && request.isTailable()) {
+ return Status(ErrorCodes::BadValue,
+ "Tailable cursors and geo $near cannot be used together");
+ }
+
// $natural sort order must agree with hint.
if (sortNaturalElt) {
if (!hintObj.isEmpty() && !hintNaturalElt) {
diff --git a/src/mongo/db/query/query_planner.cpp b/src/mongo/db/query/query_planner.cpp
index 5c8337ee25b..29413613cc6 100644
--- a/src/mongo/db/query/query_planner.cpp
+++ b/src/mongo/db/query/query_planner.cpp
@@ -569,10 +569,6 @@ StatusWith<std::vector<std::unique_ptr<QuerySolution>>> QueryPlanner::plan(
"Running with 'notablescan', so tailable cursors (which always do a table "
"scan) are not allowed");
}
- if (QueryPlannerCommon::hasNode(query.root(), MatchExpression::GEO_NEAR)) {
- return Status(ErrorCodes::NoQueryExecutionPlans,
- "Tailable cursors and geo $near cannot be used together");
- }
auto soln = buildCollscanSoln(query, isTailable, params);
if (!soln) {
return Status(ErrorCodes::NoQueryExecutionPlans,