summaryrefslogtreecommitdiff
path: root/jstests/sharding/explain_read_pref.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/sharding/explain_read_pref.js')
-rw-r--r--jstests/sharding/explain_read_pref.js79
1 files changed, 39 insertions, 40 deletions
diff --git a/jstests/sharding/explain_read_pref.js b/jstests/sharding/explain_read_pref.js
index eab0a190ad4..cdf1d1e74a4 100644
--- a/jstests/sharding/explain_read_pref.js
+++ b/jstests/sharding/explain_read_pref.js
@@ -12,18 +12,16 @@ var assertCorrectTargeting = function(explain, isMongos, secExpected) {
var serverInfo;
if (isMongos) {
serverInfo = explain.queryPlanner.winningPlan.shards[0].serverInfo;
- }
- else {
+ } else {
serverInfo = explain.serverInfo;
}
var explainDestConn = new Mongo(serverInfo.host + ':' + serverInfo.port);
- var isMaster = explainDestConn.getDB('admin').runCommand({ isMaster: 1 });
+ var isMaster = explainDestConn.getDB('admin').runCommand({isMaster: 1});
if (secExpected) {
assert(isMaster.secondary);
- }
- else {
+ } else {
assert(isMaster.ismaster);
}
};
@@ -34,34 +32,34 @@ var testAllModes = function(conn, isMongos) {
// { tag: 'two' } so we can test the interaction of modes and tags. Test
// a bunch of combinations.
[
- // mode, tagSets, expectedHost
- ['primary', undefined, false],
- ['primary', [{}], false],
+ // mode, tagSets, expectedHost
+ ['primary', undefined, false],
+ ['primary', [{}], false],
- ['primaryPreferred', undefined, false],
- ['primaryPreferred', [{tag: 'one'}], false],
- // Correctly uses primary and ignores the tag
- ['primaryPreferred', [{tag: 'two'}], false],
+ ['primaryPreferred', undefined, false],
+ ['primaryPreferred', [{tag: 'one'}], false],
+ // Correctly uses primary and ignores the tag
+ ['primaryPreferred', [{tag: 'two'}], false],
- ['secondary', undefined, true],
- ['secondary', [{tag: 'two'}], true],
- ['secondary', [{tag: 'doesntexist'}, {}], true],
- ['secondary', [{tag: 'doesntexist'}, {tag:'two'}], true],
+ ['secondary', undefined, true],
+ ['secondary', [{tag: 'two'}], true],
+ ['secondary', [{tag: 'doesntexist'}, {}], true],
+ ['secondary', [{tag: 'doesntexist'}, {tag: 'two'}], true],
- ['secondaryPreferred', undefined, true],
- ['secondaryPreferred', [{tag: 'one'}], false],
- ['secondaryPreferred', [{tag: 'two'}], true],
+ ['secondaryPreferred', undefined, true],
+ ['secondaryPreferred', [{tag: 'one'}], false],
+ ['secondaryPreferred', [{tag: 'two'}], true],
- // We don't have a way to alter ping times so we can't predict where an
- // untagged 'nearest' command should go, hence only test with tags.
- ['nearest', [{tag: 'one'}], false],
- ['nearest', [{tag: 'two'}], true]
+ // We don't have a way to alter ping times so we can't predict where an
+ // untagged 'nearest' command should go, hence only test with tags.
+ ['nearest', [{tag: 'one'}], false],
+ ['nearest', [{tag: 'two'}], true]
].forEach(function(args) {
var mode = args[0], tagSets = args[1], secExpected = args[2];
var testDB = conn.getDB('TestDB');
- conn.setSlaveOk(false); // purely rely on readPref
+ conn.setSlaveOk(false); // purely rely on readPref
jsTest.log('Testing mode: ' + mode + ', tag sets: ' + tojson(tagSets));
// .explain().find()
@@ -85,11 +83,8 @@ var testAllModes = function(conn, isMongos) {
assertCorrectTargeting(explain, isMongos, secExpected);
// .explain().group()
- explain = testDB.user.explain().group({
- key: {_id: 1},
- reduce: function(curr, result) {},
- initial: {}
- });
+ explain = testDB.user.explain().group(
+ {key: {_id: 1}, reduce: function(curr, result) {}, initial: {}});
assertCorrectTargeting(explain, isMongos, secExpected);
} finally {
// Restore old read pref.
@@ -98,7 +93,7 @@ var testAllModes = function(conn, isMongos) {
});
};
-var st = new ShardingTest({ shards: { rs0: { nodes: 2 }}});
+var st = new ShardingTest({shards: {rs0: {nodes: 2}}});
st.stopBalancer();
ReplSetTest.awaitRSClientHosts(st.s, st.rs0.nodes);
@@ -106,8 +101,14 @@ ReplSetTest.awaitRSClientHosts(st.s, st.rs0.nodes);
// Tag primary with { dc: 'ny', tag: 'one' }, secondary with { dc: 'ny', tag: 'two' }
var primary = st.rs0.getPrimary();
var secondary = st.rs0.getSecondary();
-var PRIMARY_TAG = { dc: 'ny', tag: 'one' };
-var SECONDARY_TAG = { dc: 'ny', tag: 'two' };
+var PRIMARY_TAG = {
+ dc: 'ny',
+ tag: 'one'
+};
+var SECONDARY_TAG = {
+ dc: 'ny',
+ tag: 'two'
+};
var rsConfig = primary.getDB("local").system.replset.findOne();
jsTest.log('got rsconf ' + tojson(rsConfig));
@@ -124,9 +125,8 @@ rsConfig.version++;
jsTest.log('new rsconf ' + tojson(rsConfig));
try {
- primary.adminCommand({ replSetReconfig: rsConfig });
-}
-catch(e) {
+ primary.adminCommand({replSetReconfig: rsConfig});
+} catch (e) {
jsTest.log('replSetReconfig error: ' + e);
}
@@ -135,10 +135,9 @@ st.rs0.awaitSecondaryNodes();
// Force mongos to reconnect after our reconfig and also create the test database
assert.soon(function() {
try {
- st.s.getDB('TestDB').runCommand({ create: 'TestColl' });
+ st.s.getDB('TestDB').runCommand({create: 'TestColl'});
return true;
- }
- catch (x) {
+ } catch (x) {
// Intentionally caused an error that forces mongos's monitor to refresh.
jsTest.log('Caught exception while doing dummy command: ' + tojson(x));
return false;
@@ -154,8 +153,8 @@ jsTest.log('got rsconf ' + tojson(rsConfig));
var replConn = new Mongo(st.rs0.getURL());
// Make sure replica set connection is ready
-_awaitRSHostViaRSMonitor(primary.name, { ok: true, tags: PRIMARY_TAG }, st.rs0.name);
-_awaitRSHostViaRSMonitor(secondary.name, { ok: true, tags: SECONDARY_TAG }, st.rs0.name);
+_awaitRSHostViaRSMonitor(primary.name, {ok: true, tags: PRIMARY_TAG}, st.rs0.name);
+_awaitRSHostViaRSMonitor(secondary.name, {ok: true, tags: SECONDARY_TAG}, st.rs0.name);
testAllModes(replConn, false);