summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorDavid Storch <david.storch@10gen.com>2014-09-25 12:35:38 -0400
committerDavid Storch <david.storch@10gen.com>2014-11-18 18:07:05 -0500
commitf420349563f0a4aff5f0ec1fcb6854e5e20f0a0a (patch)
treea13bfe841aa0169d55bd4b803e2f8967ce6c8ecf /jstests
parent19bcb1fadddfc72b21329809c9964ac279c5e194 (diff)
downloadmongo-f420349563f0a4aff5f0ec1fcb6854e5e20f0a0a.tar.gz
SERVER-15233 allow plan cache commands to run on secondaries is slaveOk explicitly set to true
(cherry picked from commit 77b00970997d13d0758c745e5a94fc79982d4401) Conflicts: src/mongo/s/commands/cluster_plan_cache_cmd.cpp
Diffstat (limited to 'jstests')
-rw-r--r--jstests/replsets/plan_cache_slaveok.js68
1 files changed, 68 insertions, 0 deletions
diff --git a/jstests/replsets/plan_cache_slaveok.js b/jstests/replsets/plan_cache_slaveok.js
new file mode 100644
index 00000000000..65d2d36cd18
--- /dev/null
+++ b/jstests/replsets/plan_cache_slaveok.js
@@ -0,0 +1,68 @@
+// Verify that the plan cache commands can be run on secondaries, but only
+// if slave ok is explicitly set.
+
+var name = "plan_cache_slaveok";
+
+function assertPlanCacheCommandsSucceed(db) {
+ // .listQueryShapes()
+ assert.commandWorked(db.runCommand({
+ planCacheListQueryShapes: name
+ }));
+
+ // .getPlansByQuery()
+ assert.commandWorked(db.runCommand({
+ planCacheListPlans: name,
+ query: {a: 1}
+ }));
+
+ // .clear()
+ assert.commandWorked(db.runCommand({
+ planCacheClear: name,
+ query: {a: 1}
+ }));
+}
+
+function assertPlanCacheCommandsFail(db) {
+ // .listQueryShapes()
+ assert.commandFailed(db.runCommand({
+ planCacheListQueryShapes: name
+ }));
+
+ // .getPlansByQuery()
+ assert.commandFailed(db.runCommand({
+ planCacheListPlans: name,
+ query: {a: 1}
+ }));
+
+ // .clear()
+ assert.commandFailed(db.runCommand({
+ planCacheClear: name,
+ query: {a: 1}
+ }));
+}
+
+print("Start replica set with two nodes");
+var replTest = new ReplSetTest({name: name, nodes: 2});
+var nodes = replTest.startSet();
+replTest.initiate();
+var primary = replTest.getMaster();
+
+// Insert a document and let it sync to the secondary.
+print("Initial sync");
+primary.getDB("test")[name].insert({a: 1});
+replTest.awaitReplication();
+
+// Check that the document is present on the primary.
+assert.eq(1, primary.getDB("test")[name].findOne({a: 1})["a"]);
+
+// Make sure the plan cache commands succeed on the primary.
+assertPlanCacheCommandsSucceed(primary.getDB("test"));
+
+// With slave ok false, the commands should fail on the secondary.
+var secondary = replTest.getSecondary();
+secondary.getDB("test").getMongo().setSlaveOk(false);
+assertPlanCacheCommandsFail(secondary.getDB("test"));
+
+// With slave ok true, the commands should succeed on the secondary.
+secondary.getDB("test").getMongo().setSlaveOk(true);
+assertPlanCacheCommandsSucceed(secondary.getDB("test"));