summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Mulrow <jack.mulrow@mongodb.com>2016-12-14 13:18:59 -0500
committerJudah Schvimer <judah@mongodb.com>2016-12-28 15:26:48 -0500
commit56ea371a1ebb6062cfee204e22103242bd7ec8dc (patch)
tree0ea673064e3003a1cbfa044385b1479e5789939d
parent6a1fcbfa9073e18e2e2d59dd79b051436d8d9e97 (diff)
downloadmongo-56ea371a1ebb6062cfee204e22103242bd7ec8dc.tar.gz
SERVER-27118 Default shutdown command's timeoutSecs argument to 10 seconds
(cherry picked from commit 232832a0e79252a29061def2fb89b985f29b78c7)
-rw-r--r--jstests/replsets/shutdown_primary.js62
-rw-r--r--src/mongo/db/dbcommands.cpp2
2 files changed, 63 insertions, 1 deletions
diff --git a/jstests/replsets/shutdown_primary.js b/jstests/replsets/shutdown_primary.js
new file mode 100644
index 00000000000..0192bc41b49
--- /dev/null
+++ b/jstests/replsets/shutdown_primary.js
@@ -0,0 +1,62 @@
+/**
+ * Test that the shutdown command called on a primary node waits for a majority of secondaries to
+ * catch up before taking effect, and will fail otherwise.
+ *
+ * 1. Initiate a 3-node replica set
+ * 2. Block replication to secondaries
+ * 3. Write to primary
+ * 4. Try to shut down primary and expect failure
+ * 5. Try to shut down primary in a parallel shell and expect success
+ * 6. Resume replication on secondaries
+ * 7. Try to create a new connection to the shut down primary and expect an error
+ *
+ */
+(function() {
+ load("jstests/libs/write_concern_util.js"); // for stopReplicationOnSecondaries,
+ // restartReplSetReplication
+
+ "use strict";
+
+ var name = "shutdown_primary";
+
+ var replTest = new ReplSetTest({name: name, nodes: 3});
+ replTest.startSet();
+ replTest.initiate();
+
+ var primary = replTest.getPrimary();
+ var testDB = primary.getDB(name);
+ var timeout = 5 * 60 * 1000;
+ assert.writeOK(testDB.foo.insert({x: 1}, {writeConcern: {w: 3, wtimeout: timeout}}));
+
+ jsTestLog("Blocking replication to secondaries.");
+ stopReplicationOnSecondaries(replTest);
+
+ jsTestLog("Executing write to primary.");
+ assert.writeOK(testDB.foo.insert({x: 2}));
+
+ jsTestLog("Attempting to shut down primary.");
+ assert.commandFailedWithCode(primary.adminCommand({shutdown: 1}),
+ ErrorCodes.ExceededTimeLimit,
+ "shut down did not fail with 'ExceededTimeLimit'");
+
+ jsTestLog("Verifying primary did not shut down.");
+ assert.writeOK(testDB.foo.insert({x: 3}));
+
+ jsTestLog("Shutting down primary in a parallel shell");
+ var awaitShell = startParallelShell(function() {
+ db.adminCommand({shutdown: 1, timeoutSecs: 60});
+ }, primary.port);
+
+ jsTestLog("Resuming replication.");
+ restartReplSetReplication(replTest);
+
+ jsTestLog("Verifying primary shut down and cannot be connected to.");
+ // Successful shutdown throws network error.
+ var exitCode = awaitShell({checkExitSuccess: false});
+ assert.neq(0, exitCode, "expected shutdown to close the shell's connection");
+ assert.throws(function() {
+ new Mongo(primary.host);
+ });
+
+ replTest.stopSet();
+})();
diff --git a/src/mongo/db/dbcommands.cpp b/src/mongo/db/dbcommands.cpp
index e65da17dd07..228c5ea150d 100644
--- a/src/mongo/db/dbcommands.cpp
+++ b/src/mongo/db/dbcommands.cpp
@@ -141,7 +141,7 @@ public:
BSONObjBuilder& result) {
bool force = cmdObj.hasField("force") && cmdObj["force"].trueValue();
- long long timeoutSecs = 0;
+ long long timeoutSecs = 10;
if (cmdObj.hasField("timeoutSecs")) {
timeoutSecs = cmdObj["timeoutSecs"].numberLong();
}