From e9c31e791b2e056c016c048d7e21c59e0e2452ea Mon Sep 17 00:00:00 2001 From: Drew Paroski Date: Tue, 28 Apr 2020 18:36:49 -0400 Subject: SERVER-47773 Error consistently when tailable cursors and $near are used together (cherry picked from commit c8ced6df8f620daaa2e539f192f2eef356c63e9c) --- etc/backports_required_for_multiversion_tests.yml | 6 ++++++ jstests/core/geo_near_tailable.js | 25 +++++++++++++++++++++++ src/mongo/db/query/canonical_query.cpp | 6 ++++++ src/mongo/db/query/query_planner.cpp | 4 ---- 4 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 jstests/core/geo_near_tailable.js 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 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>> 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, -- cgit v1.2.1