summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Storch <david.storch@10gen.com>2015-10-15 15:20:37 -0400
committerDavid Storch <david.storch@10gen.com>2015-10-22 13:40:06 -0400
commit737bb20fcb9176eb5f664bd874cdaece779d4012 (patch)
tree5cb4e17313f1d01f13fa86f9887628246a5c49eb
parent1ede17a6b615eaf742ce97fc92c31680601d71c5 (diff)
downloadmongo-737bb20fcb9176eb5f664bd874cdaece779d4012.tar.gz
SERVER-20935 do not attempt to attach shard version to OpCtx inside direct client
-rw-r--r--jstests/aggregation/bugs/server7781.js15
-rw-r--r--src/mongo/db/dbcommands.cpp4
2 files changed, 18 insertions, 1 deletions
diff --git a/jstests/aggregation/bugs/server7781.js b/jstests/aggregation/bugs/server7781.js
index 9a3520bab22..c369ddccbe0 100644
--- a/jstests/aggregation/bugs/server7781.js
+++ b/jstests/aggregation/bugs/server7781.js
@@ -116,6 +116,21 @@ function test(db, sharded, indexType) {
aggCmd.$geoNear.near = queryPoint;
aggArr = [aggCmd, {$limit: 50}, {$limit:60}, {$limit:40}];
checkOutput(db.runCommand(geoCmd), db[coll].aggregate(aggArr), 40);
+
+ // Test $geoNear with an initial batchSize of 0. Regression test for SERVER-20935.
+ queryPoint = pointMaker.mkPt(0.25);
+ geoCmd.spherical = true;
+ geoCmd.near = queryPoint;
+ geoCmd.limit = 70;
+ delete geoCmd.num;
+ aggCmd.$geoNear.spherical = true;
+ aggCmd.$geoNear.near = queryPoint;
+ aggCmd.$geoNear.limit = 70;
+ delete aggCmd.$geoNear.num;
+ var cmdRes = db[coll].runCommand("aggregate", {pipeline: [aggCmd], cursor: {batchSize: 0}});
+ assert.commandWorked(cmdRes);
+ var cmdCursor = new DBCommandCursor(db[coll].getMongo(), cmdRes, 0);
+ checkOutput(db.runCommand(geoCmd), cmdCursor, 70);
}
test(db, false, '2d');
diff --git a/src/mongo/db/dbcommands.cpp b/src/mongo/db/dbcommands.cpp
index 78e13ad8a27..9d18c8269e8 100644
--- a/src/mongo/db/dbcommands.cpp
+++ b/src/mongo/db/dbcommands.cpp
@@ -1250,7 +1250,9 @@ void Command::execCommand(OperationContext* txn,
CurOp::get(txn)->setMaxTimeMicros(static_cast<unsigned long long>(maxTimeMS) * 1000);
- if (iAmPrimary) {
+ // Operations are only versioned against the primary. We also make sure not to redo shard
+ // version handling if this command was issued via the direct client.
+ if (iAmPrimary && !txn->getClient()->isInDirectClient()) {
// Handle shard version and config optime information that may have been sent along with
// the command.
auto& operationShardVersion = OperationShardVersion::get(txn);