diff options
Diffstat (limited to 'jstests/replsets/explain_slaveok.js')
-rw-r--r-- | jstests/replsets/explain_slaveok.js | 107 |
1 files changed, 54 insertions, 53 deletions
diff --git a/jstests/replsets/explain_slaveok.js b/jstests/replsets/explain_slaveok.js index 68eda89bce7..f3215af9ab6 100644 --- a/jstests/replsets/explain_slaveok.js +++ b/jstests/replsets/explain_slaveok.js @@ -1,12 +1,12 @@ // Test the explain command on the primary and on secondaries: // -// 1) Explain of read operations should work on the secondaries iff slaveOk is set. +// 1) Explain of read operations should work on the secondaries iff secondaryOk is set. // // 2) Explain of write operations should -// --fail on secondaries, even if slaveOk is set, +// --fail on secondaries, even if secondaryOk is set, // --succeed on primary without applying any writes. -var name = "explain_slaveok"; +var name = "explain_secondaryok"; print("Start replica set with two nodes"); var replTest = new ReplSetTest({name: name, nodes: 2}); @@ -16,22 +16,22 @@ var primary = replTest.getPrimary(); // Insert a document and let it sync to the secondary. print("Initial sync"); -primary.getDB("test").explain_slaveok.insert({a: 1}); +primary.getDB("test").explain_secondaryok.insert({a: 1}); replTest.awaitReplication(); // Check that the document is present on the primary. -assert.eq(1, primary.getDB("test").explain_slaveok.findOne({a: 1})["a"]); +assert.eq(1, primary.getDB("test").explain_secondaryok.findOne({a: 1})["a"]); -// We shouldn't be able to read from the secondary with slaveOk off. +// We shouldn't be able to read from the secondary with secondaryOk off. var secondary = replTest.getSecondary(); -secondary.getDB("test").getMongo().setSlaveOk(false); +secondary.getDB("test").getMongo().setSecondaryOk(false); assert.throws(function() { - secondary.getDB("test").explain_slaveok.findOne({a: 1}); + secondary.getDB("test").explain_secondaryok.findOne({a: 1}); }); -// With slaveOk on, we should be able to read from the secondary. -secondary.getDB("test").getMongo().setSlaveOk(true); -assert.eq(1, secondary.getDB("test").explain_slaveok.findOne({a: 1})["a"]); +// With secondaryOk on, we should be able to read from the secondary. +secondary.getDB("test").getMongo().setSecondaryOk(); +assert.eq(1, secondary.getDB("test").explain_secondaryok.findOne({a: 1})["a"]); // // Test explains on primary. @@ -39,12 +39,12 @@ assert.eq(1, secondary.getDB("test").explain_slaveok.findOne({a: 1})["a"]); // Explain a count on the primary. var explainOut = primary.getDB("test").runCommand( - {explain: {count: "explain_slaveok", query: {a: 1}}, verbosity: "executionStats"}); + {explain: {count: "explain_secondaryok", query: {a: 1}}, verbosity: "executionStats"}); assert.commandWorked(explainOut, "explain read op on primary"); // Explain an update on the primary. explainOut = primary.getDB("test").runCommand({ - explain: {update: "explain_slaveok", updates: [{q: {a: 1}, u: {$set: {a: 5}}}]}, + explain: {update: "explain_secondaryok", updates: [{q: {a: 1}, u: {$set: {a: 5}}}]}, verbosity: "executionStats" }); assert.commandWorked(explainOut, "explain write op on primary"); @@ -57,52 +57,52 @@ assert.eq(1, stages.nWouldModify); // Confirm that the document did not actually get modified on the primary // or on the secondary. -assert.eq(1, primary.getDB("test").explain_slaveok.findOne({a: 1})["a"]); -secondary.getDB("test").getMongo().setSlaveOk(true); -assert.eq(1, secondary.getDB("test").explain_slaveok.findOne({a: 1})["a"]); +assert.eq(1, primary.getDB("test").explain_secondaryok.findOne({a: 1})["a"]); +secondary.getDB("test").getMongo().setSecondaryOk(); +assert.eq(1, secondary.getDB("test").explain_secondaryok.findOne({a: 1})["a"]); // // Test explains on secondary. // -// Explain a count on the secondary with slaveOk off. Should fail because -// slaveOk is required for explains on a secondary. -secondary.getDB("test").getMongo().setSlaveOk(false); +// Explain a count on the secondary with secondaryOk off. Should fail because +// secondaryOk is required for explains on a secondary. +secondary.getDB("test").getMongo().setSecondaryOk(false); explainOut = secondary.getDB("test").runCommand( - {explain: {count: "explain_slaveok", query: {a: 1}}, verbosity: "executionStats"}); -assert.commandFailed(explainOut, "explain read op on secondary, slaveOk false"); + {explain: {count: "explain_secondaryok", query: {a: 1}}, verbosity: "executionStats"}); +assert.commandFailed(explainOut, "explain read op on secondary, secondaryOk false"); -// Explain of count should succeed once slaveOk is true. -secondary.getDB("test").getMongo().setSlaveOk(true); +// Explain of count should succeed once secondaryOk is true. +secondary.getDB("test").getMongo().setSecondaryOk(); explainOut = secondary.getDB("test").runCommand( - {explain: {count: "explain_slaveok", query: {a: 1}}, verbosity: "executionStats"}); -assert.commandWorked(explainOut, "explain read op on secondary, slaveOk true"); + {explain: {count: "explain_secondaryok", query: {a: 1}}, verbosity: "executionStats"}); +assert.commandWorked(explainOut, "explain read op on secondary, secondaryOk true"); -// Explain .find() on a secondary, setting slaveOk directly on the query. -secondary.getDB("test").getMongo().setSlaveOk(false); +// Explain .find() on a secondary, setting secondaryOk directly on the query. +secondary.getDB("test").getMongo().setSecondaryOk(false); assert.throws(function() { - secondary.getDB("test").explain_slaveok.explain("executionStats").find({a: 1}).finish(); + secondary.getDB("test").explain_secondaryok.explain("executionStats").find({a: 1}).finish(); }); -secondary.getDB("test").getMongo().setSlaveOk(false); +secondary.getDB("test").getMongo().setSecondaryOk(false); explainOut = secondary.getDB("test") - .explain_slaveok.explain("executionStats") + .explain_secondaryok.explain("executionStats") .find({a: 1}) .addOption(DBQuery.Option.slaveOk) .finish(); -assert.commandWorked(explainOut, "explain read op on secondary, slaveOk set to true on query"); +assert.commandWorked(explainOut, "explain read op on secondary, slaveOk bit set to true on query"); -secondary.getDB("test").getMongo().setSlaveOk(true); +secondary.getDB("test").getMongo().setSecondaryOk(); explainOut = - secondary.getDB("test").explain_slaveok.explain("executionStats").find({a: 1}).finish(); -assert.commandWorked(explainOut, "explain .find() on secondary, slaveOk set to true"); + secondary.getDB("test").explain_secondaryok.explain("executionStats").find({a: 1}).finish(); +assert.commandWorked(explainOut, "explain .find() on secondary, secondaryOk set to true"); -// Explain .find() on a secondary, setting slaveOk to false with various read preferences. +// Explain .find() on a secondary, setting secondaryOk to false with various read preferences. var readPrefModes = ["secondary", "secondaryPreferred", "primaryPreferred", "nearest"]; readPrefModes.forEach(function(prefString) { - secondary.getDB("test").getMongo().setSlaveOk(false); + secondary.getDB("test").getMongo().setSecondaryOk(false); explainOut = secondary.getDB("test") - .explain_slaveok.explain("executionStats") + .explain_secondaryok.explain("executionStats") .find({a: 1}) .readPref(prefString) .finish(); @@ -112,7 +112,7 @@ readPrefModes.forEach(function(prefString) { // Similarly should succeed if a read preference is set on the connection. secondary.setReadPref(prefString); explainOut = - secondary.getDB("test").explain_slaveok.explain("executionStats").find({a: 1}).finish(); + secondary.getDB("test").explain_secondaryok.explain("executionStats").find({a: 1}).finish(); assert.commandWorked( explainOut, "explain .find() on secondary, '" + prefString + "' read preference on connection"); @@ -120,35 +120,36 @@ readPrefModes.forEach(function(prefString) { secondary.setReadPref(); }); -// Fail explain find() on a secondary, setting slaveOk to false with read preference set to primary. +// Fail explain find() on a secondary, setting secondaryOk to false with read preference set to +// primary. var prefStringPrimary = "primary"; -secondary.getDB("test").getMongo().setSlaveOk(false); +secondary.getDB("test").getMongo().setSecondaryOk(false); explainOut = secondary.getDB("test").runCommand( - {explain: {find: "explain_slaveok", query: {a: 1}}, verbosity: "executionStats"}); -assert.commandFailed(explainOut, "not master and slaveOk=false"); + {explain: {find: "explain_secondaryok", query: {a: 1}}, verbosity: "executionStats"}); +assert.commandFailed(explainOut, "not primary and secondaryOk=false"); // Similarly should fail if a read preference is set on the connection. secondary.setReadPref(prefStringPrimary); explainOut = secondary.getDB("test").runCommand( - {explain: {find: "explain_slaveok", query: {a: 1}}, verbosity: "executionStats"}); -assert.commandFailed(explainOut, "not master and slaveOk=false"); + {explain: {find: "explain_secondaryok", query: {a: 1}}, verbosity: "executionStats"}); +assert.commandFailed(explainOut, "not primary and secondaryOk=false"); // Unset read pref on the connection. secondary.setReadPref(); -// Explain an update on the secondary with slaveOk off. Should fail because -// slaveOk is required for explains on a secondary. -secondary.getDB("test").getMongo().setSlaveOk(false); +// Explain an update on the secondary with secondaryOk off. Should fail because +// secondaryOk is required for explains on a secondary. +secondary.getDB("test").getMongo().setSecondaryOk(false); explainOut = secondary.getDB("test").runCommand({ - explain: {update: "explain_slaveok", updates: [{q: {a: 1}, u: {$set: {a: 5}}}]}, + explain: {update: "explain_secondaryok", updates: [{q: {a: 1}, u: {$set: {a: 5}}}]}, verbosity: "executionStats" }); -assert.commandFailed(explainOut, "explain write op on secondary, slaveOk false"); +assert.commandFailed(explainOut, "explain write op on secondary, secondaryOk false"); -// Explain of the update should also fail with slaveOk on. -secondary.getDB("test").getMongo().setSlaveOk(true); +// Explain of the update should also fail with secondaryOk on. +secondary.getDB("test").getMongo().setSecondaryOk(); explainOut = secondary.getDB("test").runCommand({ - explain: {update: "explain_slaveok", updates: [{q: {a: 1}, u: {$set: {a: 5}}}]}, + explain: {update: "explain_secondaryok", updates: [{q: {a: 1}, u: {$set: {a: 5}}}]}, verbosity: "executionStats" }); -assert.commandFailed(explainOut, "explain write op on secondary, slaveOk true"); +assert.commandFailed(explainOut, "explain write op on secondary, secondaryOk true"); replTest.stopSet(); |