Skip to content

Commit

Permalink
SERVER-47773 Error consistently when tailable cursors and $near are u…
Browse files Browse the repository at this point in the history
…sed together

(cherry picked from commit c8ced6d)
(cherry picked from commit e9c31e7)
  • Loading branch information
paroski authored and Evergreen Agent committed May 27, 2020
1 parent 42f5522 commit 444dab3
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
6 changes: 6 additions & 0 deletions etc/backports_required_for_multiversion_tests.yml
Expand Up @@ -31,6 +31,8 @@ replica_sets_jscore_multiversion_passthrough:
test_file: jstests/core/txns/new_transaction_waits_for_previous_txn_table_updates.js
- ticket: SERVER-40805
test_file: jstests/core/profile_find.js
- ticket: SERVER-47773
test_file: jstests/core/geo_near_tailable.js

replica_sets_multiversion:
- ticket: SERVER-42825
Expand Down Expand Up @@ -65,5 +67,9 @@ sharding_multiversion:
test_file: jstests/sharding/retryable_writes.js

sharding_jscore_multiversion_passthrough:
- ticket: SERVER-47773
test_file: jstests/core/geo_near_tailable.js

sharded_collections_jscore_multiversion_passthrough:
- ticket: SERVER-47773
test_file: jstests/core/geo_near_tailable.js
25 changes: 25 additions & 0 deletions 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);
})();
6 changes: 6 additions & 0 deletions src/mongo/db/query/canonical_query.cpp
Expand Up @@ -409,6 +409,12 @@ Status CanonicalQuery::isValid(MatchExpression* root, const QueryRequest& parsed
return Status(ErrorCodes::BadValue, "text and tailable cursor not allowed in same query");
}

// NEAR and tailable are incompatible.
if (numGeoNear > 0 && parsed.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) {
Expand Down
2 changes: 1 addition & 1 deletion src/mongo/db/query/query_planner.cpp
Expand Up @@ -550,7 +550,7 @@ StatusWith<std::vector<std::unique_ptr<QuerySolution>>> QueryPlanner::plan(
// If the query requests a tailable cursor, the only solution is a collscan + filter with
// tailable set on the collscan.
if (isTailable) {
if (!QueryPlannerCommon::hasNode(query.root(), MatchExpression::GEO_NEAR) && canTableScan) {
if (canTableScan) {
auto soln = buildCollscanSoln(query, isTailable, params);
if (soln) {
out.push_back(std::move(soln));
Expand Down

0 comments on commit 444dab3

Please sign in to comment.