summaryrefslogtreecommitdiff
path: root/jstests/sharding
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/sharding')
-rw-r--r--jstests/sharding/auth_repl.js4
-rw-r--r--jstests/sharding/auth_slaveok_routing.js4
-rw-r--r--jstests/sharding/covered_shard_key_indexes.js57
-rw-r--r--jstests/sharding/explain1.js42
-rw-r--r--jstests/sharding/large_skip_one_shard.js2
-rw-r--r--jstests/sharding/limit_push.js3
-rwxr-xr-xjstests/sharding/read_pref.js34
-rw-r--r--jstests/sharding/shard2.js14
-rw-r--r--jstests/sharding/shard3.js17
9 files changed, 79 insertions, 98 deletions
diff --git a/jstests/sharding/auth_repl.js b/jstests/sharding/auth_repl.js
index f4deba6f195..568cbc4a5ac 100644
--- a/jstests/sharding/auth_repl.js
+++ b/jstests/sharding/auth_repl.js
@@ -102,9 +102,9 @@ assert.eq(1, testDB.auth('a', 'a'));
// Find out the current cached secondary in the repl connection
conn.setSlaveOk(true);
-var secHost = testColl.find().readPref('secondary').explain().server;
+var serverInfo = testColl.find().readPref('secondary').explain().serverInfo;
var secNodeIdx = -1;
-var secPortStr = secHost.split(':')[1];
+var secPortStr = serverInfo.port.toString();
for (var x = 0; x < nodeCount; x++) {
var nodePortStr = replTest.nodes[x].host.split(':')[1];
diff --git a/jstests/sharding/auth_slaveok_routing.js b/jstests/sharding/auth_slaveok_routing.js
index f89a6da086a..a6552590351 100644
--- a/jstests/sharding/auth_slaveok_routing.js
+++ b/jstests/sharding/auth_slaveok_routing.js
@@ -13,8 +13,8 @@
* @return {boolean} true if query was routed to a secondary node.
*/
function doesRouteToSec( coll, query ) {
- var explain = coll.find( query ).explain();
- var conn = new Mongo( explain.server );
+ var serverInfo = coll.find( query ).explain().serverInfo;
+ var conn = new Mongo( serverInfo.host + ":" + serverInfo.port.toString());
var cmdRes = conn.getDB( 'admin' ).runCommand({ isMaster: 1 });
jsTest.log('isMaster: ' + tojson(cmdRes));
diff --git a/jstests/sharding/covered_shard_key_indexes.js b/jstests/sharding/covered_shard_key_indexes.js
index 989d3a80198..22e3aebd984 100644
--- a/jstests/sharding/covered_shard_key_indexes.js
+++ b/jstests/sharding/covered_shard_key_indexes.js
@@ -3,6 +3,9 @@
// particular queries
//
+// Include helpers for analyzing explain output.
+load("jstests/libs/analyze_plan.js");
+
var options = { separateConfig : true };
var st = new ShardingTest({ shards : 1, other : options });
@@ -28,7 +31,7 @@ assert.writeOK(coll.insert({ _id : true, a : true, b : true }));
var shardExplain = function(mongosExplainDoc) {
var explainDoc = mongosExplainDoc.shards[shards[0].host][0];
printjson(explainDoc);
- return explainDoc;
+ return explainDoc.executionStats;
};
assert.commandWorked(st.shard0.adminCommand({ setParameter: 1,
@@ -37,23 +40,23 @@ assert.commandWorked(st.shard0.adminCommand({ setParameter: 1,
//
// Index without shard key query - not covered
assert.commandWorked(coll.ensureIndex({ a : 1 }));
-assert.eq(1, shardExplain(coll.find({ a : true }).explain()).nscannedObjects);
-assert.eq(1, shardExplain(coll.find({ a : true }, { _id : 1, a : 1 }).explain()).nscannedObjects);
+assert.eq(1, shardExplain(coll.find({ a : true }).explain()).totalDocsExamined);
+assert.eq(1, shardExplain(coll.find({ a : true }, { _id : 1, a : 1 }).explain()).totalDocsExamined);
//
// Index with shard key query - covered when projecting
assert.commandWorked(coll.dropIndexes());
assert.commandWorked(coll.ensureIndex({ a : 1, _id : 1 }));
-assert.eq(1, shardExplain(coll.find({ a : true }).explain()).nscannedObjects);
-assert.eq(0, shardExplain(coll.find({ a : true }, { _id : 1, a : 1 }).explain()).nscannedObjects);
+assert.eq(1, shardExplain(coll.find({ a : true }).explain()).totalDocsExamined);
+assert.eq(0, shardExplain(coll.find({ a : true }, { _id : 1, a : 1 }).explain()).totalDocsExamined);
//
// Compound index with shard key query - covered when projecting
assert.commandWorked(coll.dropIndexes());
assert.commandWorked(coll.ensureIndex({ a : 1, b : 1, _id : 1 }));
-assert.eq(1, shardExplain(coll.find({ a : true, b : true }).explain()).nscannedObjects);
+assert.eq(1, shardExplain(coll.find({ a : true, b : true }).explain()).totalDocsExamined);
assert.eq(0, shardExplain(coll.find({ a : true, b : true }, { _id : 1, a : 1 })
- .explain()).nscannedObjects);
+ .explain()).totalDocsExamined);
//
//
@@ -68,14 +71,14 @@ assert.writeOK(coll.insert({ _id : true, a : true, b : true }));
//
// Index without shard key query - not covered
assert.commandWorked(coll.ensureIndex({ a : 1 }));
-assert.eq(1, shardExplain(coll.find({ a : true }).explain()).nscannedObjects);
-assert.eq(1, shardExplain(coll.find({ a : true }, { _id : 0, a : 1 }).explain()).nscannedObjects);
+assert.eq(1, shardExplain(coll.find({ a : true }).explain()).totalDocsExamined);
+assert.eq(1, shardExplain(coll.find({ a : true }, { _id : 0, a : 1 }).explain()).totalDocsExamined);
//
// Index with shard key query - can't be covered since hashed index
assert.commandWorked(coll.dropIndex({ a : 1 }));
-assert.eq(1, shardExplain(coll.find({ _id : true }).explain()).nscannedObjects);
-assert.eq(1, shardExplain(coll.find({ _id : true }, { _id : 0 }).explain()).nscannedObjects);
+assert.eq(1, shardExplain(coll.find({ _id : true }).explain()).totalDocsExamined);
+assert.eq(1, shardExplain(coll.find({ _id : true }, { _id : 0 }).explain()).totalDocsExamined);
//
//
@@ -90,25 +93,25 @@ assert.writeOK(coll.insert({ _id : true, a : true, b : true, c : true, d : true
//
// Index without shard key query - not covered
assert.commandWorked(coll.ensureIndex({ c : 1 }));
-assert.eq(1, shardExplain(coll.find({ c : true }).explain()).nscannedObjects);
+assert.eq(1, shardExplain(coll.find({ c : true }).explain()).totalDocsExamined);
assert.eq(1, shardExplain(coll.find({ c : true }, { _id : 0, a : 1, b : 1, c : 1 })
- .explain()).nscannedObjects);
+ .explain()).totalDocsExamined);
//
// Index with shard key query - covered when projecting
assert.commandWorked(coll.dropIndex({ c : 1 }));
assert.commandWorked(coll.ensureIndex({ c : 1, b : 1, a : 1 }));
-assert.eq(1, shardExplain(coll.find({ c : true }).explain()).nscannedObjects);
+assert.eq(1, shardExplain(coll.find({ c : true }).explain()).totalDocsExamined);
assert.eq(0, shardExplain(coll.find({ c : true }, { _id : 0, a : 1, b : 1, c : 1 })
- .explain()).nscannedObjects);
+ .explain()).totalDocsExamined);
//
// Compound index with shard key query - covered when projecting
assert.commandWorked(coll.dropIndex({ c : 1, b : 1, a : 1 }));
assert.commandWorked(coll.ensureIndex({ c : 1, d : 1, a : 1, b : 1, _id : 1 }));
-assert.eq(1, shardExplain(coll.find({ c : true, d : true }).explain()).nscannedObjects);
+assert.eq(1, shardExplain(coll.find({ c : true, d : true }).explain()).totalDocsExamined);
assert.eq(0, shardExplain(coll.find({ c : true, d : true }, { a : 1, b : 1, c : 1, d : 1 })
- .explain()).nscannedObjects);
+ .explain()).totalDocsExamined);
//
//
@@ -123,17 +126,17 @@ assert.writeOK(coll.insert({ _id : true, a : { b : true }, c : true }));
//
// Index without shard key query - not covered
assert.commandWorked(coll.ensureIndex({ c : 1 }));
-assert.eq(1, shardExplain(coll.find({ c : true }).explain()).nscannedObjects);
+assert.eq(1, shardExplain(coll.find({ c : true }).explain()).totalDocsExamined);
assert.eq(1, shardExplain(coll.find({ c : true }, { _id : 0, 'a.b' : 1, c : 1 })
- .explain()).nscannedObjects);
+ .explain()).totalDocsExamined);
//
// Index with shard key query - nested query not covered even when projecting
assert.commandWorked(coll.dropIndex({ c : 1 }));
assert.commandWorked(coll.ensureIndex({ c : 1, 'a.b' : 1 }));
-assert.eq(1, shardExplain(coll.find({ c : true }).explain()).nscannedObjects);
+assert.eq(1, shardExplain(coll.find({ c : true }).explain()).totalDocsExamined);
assert.eq(1, shardExplain(coll.find({ c : true }, { _id : 0, 'a.b' : 1, c : 1 })
- .explain()).nscannedObjects);
+ .explain()).totalDocsExamined);
//
//
@@ -149,9 +152,9 @@ assert.writeOK(st.shard0.getCollection(coll.toString()).insert({ _id : "bad data
// Index without shard key query - not covered but succeeds
assert.commandWorked(coll.ensureIndex({ c : 1 }));
var explain = shardExplain(coll.find({ c : true }).explain());
-assert.eq(0, explain.n);
-assert.eq(1, explain.nscannedObjects);
-assert.eq(1, explain.nChunkSkips);
+assert.eq(0, explain.nReturned);
+assert.eq(1, explain.totalDocsExamined);
+assert.eq(1, getChunkSkips(explain.executionStages));
//
// Index with shard key query - covered and succeeds and returns result
@@ -160,9 +163,9 @@ assert.eq(1, explain.nChunkSkips);
assert.commandWorked(coll.ensureIndex({ c : 1, a : 1 }));
jsTest.log(tojson(coll.find({ c : true }, { _id : 0, a : 1, c : 1 }).toArray()));
var explain = shardExplain(coll.find({ c : true }, { _id : 0, a : 1, c : 1 }).explain());
-assert.eq(1, explain.n);
-assert.eq(0, explain.nscannedObjects);
-assert.eq(0, explain.nChunkSkips);
+assert.eq(1, explain.nReturned);
+assert.eq(0, explain.totalDocsExamined);
+assert.eq(0, getChunkSkips(explain.executionStages));
jsTest.log("DONE!");
st.stop();
diff --git a/jstests/sharding/explain1.js b/jstests/sharding/explain1.js
deleted file mode 100644
index 68e523af1aa..00000000000
--- a/jstests/sharding/explain1.js
+++ /dev/null
@@ -1,42 +0,0 @@
-// Check explain() results reported for a sharded cluster, in particular nscannedObjects.
-// SERVER-4161
-
-s = new ShardingTest( "explain1" , 2 , 2 );
-
-// Tests can be invalidated by the balancer.
-s.stopBalancer()
-
-db = s.getDB( "test" );
-
-s.adminCommand( { enablesharding : "test" } );
-s.adminCommand( { shardcollection : "test.foo" , key : { _id : 1 } } );
-
-t = db.foo;
-for( i = 0; i < 10; ++i ) {
- t.save( { a:i } );
-}
-
-// Without an index.
-explain = t.find( { a:{ $gte:5 } } ).explain();
-assert.eq( explain.cursor, 'BasicCursor' );
-assert.eq( explain.n, 5 );
-assert.eq( explain.nscanned, 10 );
-assert.eq( explain.nscannedObjects, 10 );
-
-// With an index.
-t.ensureIndex( { a:1 } );
-explain = t.find( { a:{ $gte:5 } } ).explain();
-assert.eq( explain.cursor, 'BtreeCursor a_1' );
-assert.eq( explain.n, 5 );
-assert.eq( explain.nscanned, 5 );
-assert.eq( explain.nscannedObjects, 5 );
-
-// With a covered index.
-t.ensureIndex( { a:1 } );
-explain = t.find( { a:{ $gte:5 } }, { _id:0, a:1 } ).explain();
-assert.eq( explain.cursor, 'BtreeCursor a_1' );
-assert.eq( explain.n, 5 );
-assert.eq( explain.nscanned, 5 );
-assert.eq( explain.nscannedObjects, 5 ); // Queries against sharded collections are never covered.
-
-s.stop();
diff --git a/jstests/sharding/large_skip_one_shard.js b/jstests/sharding/large_skip_one_shard.js
index 0de8615b75a..ec8f250de03 100644
--- a/jstests/sharding/large_skip_one_shard.js
+++ b/jstests/sharding/large_skip_one_shard.js
@@ -42,7 +42,7 @@ function testSelectWithSkip(coll){
}
// What we're actually testing
- assert.lt(explain.n, 90);
+ assert.lt(explain.executionStats.nReturned, 90);
}
testSelectWithSkip(collSharded);
diff --git a/jstests/sharding/limit_push.js b/jstests/sharding/limit_push.js
index b508e307eb7..91754ee9682 100644
--- a/jstests/sharding/limit_push.js
+++ b/jstests/sharding/limit_push.js
@@ -42,7 +42,8 @@ assert.eq("ParallelSort", exp.clusteredType, "Not a ParallelSort");
var k = 0;
for (var j in exp.shards) {
- assert.eq( 1 , exp.shards[j][0].n, "'n' is not 1 from shard000" + k.toString());
+ assert.eq( 1 , exp.shards[j][0].executionStats.nReturned,
+ "'n' is not 1 from shard000" + k.toString());
k++
}
diff --git a/jstests/sharding/read_pref.js b/jstests/sharding/read_pref.js
index b930678a2b5..431fe0aa6d5 100755
--- a/jstests/sharding/read_pref.js
+++ b/jstests/sharding/read_pref.js
@@ -114,20 +114,23 @@ var doTest = function(useDollarQuerySyntax) {
// Read pref should work without slaveOk
var explain = getExplain("secondary");
- assert.neq( primaryNode.name, explain.server );
+ var explainServer = explain.serverInfo.host + ":" + explain.serverInfo.port.toString();
+ assert.neq( primaryNode.name, explainServer );
conn.setSlaveOk();
// It should also work with slaveOk
explain = getExplain("secondary");
- assert.neq( primaryNode.name, explain.server );
+ explainServer = explain.serverInfo.host + ":" + explain.serverInfo.port.toString();
+ assert.neq( primaryNode.name, explainServer );
// Check that $readPreference does not influence the actual query
- assert.eq( 1, explain.n );
+ assert.eq( 1, explain.executionStats.nReturned );
explain = getExplain("secondaryPreferred", [{ s: "2" }]);
- checkTag( explain.server, { s: "2" });
- assert.eq( 1, explain.n );
+ explainServer = explain.serverInfo.host + ":" + explain.serverInfo.port.toString();
+ checkTag( explainServer, { s: "2" });
+ assert.eq( 1, explain.executionStats.nReturned );
// Cannot use tags with primaryOnly
assert.throws( function() {
@@ -136,21 +139,25 @@ var doTest = function(useDollarQuerySyntax) {
// Ok to use empty tags on primaryOnly
explain = coll.find().readPref("primary", [{}]).explain();
- assert.eq(primaryNode.name, explain.server);
+ explainServer = explain.serverInfo.host + ":" + explain.serverInfo.port.toString();
+ assert.eq(primaryNode.name, explainServer);
explain = coll.find().readPref("primary", []).explain();
- assert.eq(primaryNode.name, explain.server);
+ explainServer = explain.serverInfo.host + ":" + explain.serverInfo.port.toString();
+ assert.eq(primaryNode.name, explainServer);
// Check that mongos will try the next tag if nothing matches the first
explain = getExplain("secondary", [{ z: "3" }, { dc: "jp" }]);
- checkTag( explain.server, { dc: "jp" });
- assert.eq( 1, explain.n );
+ explainServer = explain.serverInfo.host + ":" + explain.serverInfo.port.toString();
+ checkTag( explainServer, { dc: "jp" });
+ assert.eq( 1, explain.executionStats.nReturned );
// Check that mongos will fallback to primary if none of tags given matches
explain = getExplain("secondaryPreferred", [{ z: "3" }, { dc: "ph" }]);
+ explainServer = explain.serverInfo.host + ":" + explain.serverInfo.port.toString();
// Call getPrimary again since the primary could have changed after the restart.
- assert.eq(replTest.getPrimary().name, explain.server);
- assert.eq( 1, explain.n );
+ assert.eq(replTest.getPrimary().name, explainServer);
+ assert.eq( 1, explain.executionStats.nReturned );
// Kill all members except one
var stoppedNodes = [];
@@ -171,8 +178,9 @@ var doTest = function(useDollarQuerySyntax) {
// Test to make sure that connection is ok, in prep for priOnly test
explain = getExplain("nearest");
- assert.eq( explain.server, replTest.nodes[NODES - 1].name );
- assert.eq( 1, explain.n );
+ explainServer = explain.serverInfo.host + ":" + explain.serverInfo.port.toString();
+ assert.eq( explainServer, replTest.nodes[NODES - 1].name );
+ assert.eq( 1, explain.executionStats.nReturned );
// Should assert if request with priOnly but no primary
assert.throws( function(){
diff --git a/jstests/sharding/shard2.js b/jstests/sharding/shard2.js
index 006a9340682..a229c4dc4b1 100644
--- a/jstests/sharding/shard2.js
+++ b/jstests/sharding/shard2.js
@@ -141,12 +141,14 @@ placeCheck( 7 );
db.foo.find().sort( { _id : 1 } ).forEach( function(z){ print( z._id ); } )
zzz = db.foo.find().explain();
-assert.eq( 6 , zzz.nscanned , "EX1a" )
-assert.eq( 6 , zzz.n , "EX1b" )
-
-zzz = db.foo.find().sort( { _id : 1 } ).explain();
-assert.eq( 6 , zzz.nscanned , "EX2a" )
-assert.eq( 6 , zzz.n , "EX2a" )
+assert.eq( 0 , zzz.totalKeysExamined , "EX1a" )
+assert.eq( 6 , zzz.nReturned , "EX1b" )
+assert.eq( 6 , zzz.totalDocsExamined , "EX1c" )
+
+zzz = db.foo.find().hint( { _id : 1 } ).sort( { _id : 1 } ).explain();
+assert.eq( 6 , zzz.totalKeysExamined , "EX2a" )
+assert.eq( 6 , zzz.nReturned , "EX2b" )
+assert.eq( 6 , zzz.totalDocsExamined , "EX2c" )
// getMore
assert.eq( 4 , db.foo.find().limit(-4).toArray().length , "getMore 1" );
diff --git a/jstests/sharding/shard3.js b/jstests/sharding/shard3.js
index 8b36f809686..5ecf1fb8140 100644
--- a/jstests/sharding/shard3.js
+++ b/jstests/sharding/shard3.js
@@ -1,5 +1,8 @@
// shard3.js
+// Include helpers for analyzing explain output.
+load("jstests/libs/analyze_plan.js");
+
s = new ShardingTest( "shard3" , 2 , 1 , 2 , { enableBalancer : 1 } );
s2 = s._mongos[1];
@@ -64,10 +67,16 @@ var total = doCounts( "before wrong save" )
assert.writeOK(secondary.insert( { _id : 111 , num : -3 } ));
doCounts( "after wrong save" , total , true )
e = a.find().explain();
-assert.eq( 3 , e.n , "ex1" )
-assert.eq( 4 , e.nscanned , "ex2" )
-assert.eq( 4 , e.nscannedObjects , "ex3" )
-assert.eq( 1 , e.nChunkSkips , "ex4" )
+assert.eq( 3 , e.nReturned , "ex1" )
+assert.eq( 0 , e.totalKeysExamined , "ex2" )
+assert.eq( 4 , e.totalDocsExamined , "ex3" )
+
+var chunkSkips = 0;
+for (var shard in e.shards) {
+ var theShard = e.shards[shard][0];
+ chunkSkips += getChunkSkips(theShard.executionStats.executionStages);
+}
+assert.eq( 1 , chunkSkips , "ex4" )
// SERVER-4612
// make sure idhack obeys chunks