diff options
author | Judah Schvimer <judah@mongodb.com> | 2017-02-27 13:14:03 -0500 |
---|---|---|
committer | Judah Schvimer <judah@mongodb.com> | 2017-02-27 13:14:03 -0500 |
commit | a4e1443629b733c7c0fd44dddcd78e884da848bd (patch) | |
tree | 03f5b69a0069ed5ff1847a5e4df61c437603395d /src/mongo/shell | |
parent | 417c0158a6e154f9f6494b8db1b8358c379f7b99 (diff) | |
download | mongo-a4e1443629b733c7c0fd44dddcd78e884da848bd.tar.gz |
SERVER-27839 Allow for step downs during reconfig in ReplSetTest initiate
Diffstat (limited to 'src/mongo/shell')
-rw-r--r-- | src/mongo/shell/db.js | 2 | ||||
-rw-r--r-- | src/mongo/shell/replsettest.js | 19 | ||||
-rw-r--r-- | src/mongo/shell/utils.js | 8 |
3 files changed, 23 insertions, 6 deletions
diff --git a/src/mongo/shell/db.js b/src/mongo/shell/db.js index 7a48128023e..4ad30cd7a33 100644 --- a/src/mongo/shell/db.js +++ b/src/mongo/shell/db.js @@ -331,7 +331,7 @@ var DB; } catch (e) { // we expect the command to not return a response, as the server will shut down // immediately. - if (e.message.indexOf("error doing query: failed") >= 0) { + if (isNetworkError(e)) { print('server should be down...'); return; } diff --git a/src/mongo/shell/replsettest.js b/src/mongo/shell/replsettest.js index 331b8e3c98b..087e55c8bc7 100644 --- a/src/mongo/shell/replsettest.js +++ b/src/mongo/shell/replsettest.js @@ -747,9 +747,20 @@ var ReplSetTest = function(opts) { // if a heartbeat times out during the quorum check. We retry three times to reduce // the chance of failing this way. assert.retry(() => { - const res = master.runCommand(cmd); - if (res.ok === 1) { - return true; + var res; + try { + res = master.runCommand(cmd); + if (res.ok === 1) { + return true; + } + } catch (e) { + // reconfig can lead to a stepdown if the primary looks for a majority before + // a majority of nodes have successfully joined the set. If there is a stepdown + // then the reconfig request will be killed and respond with a network error. + if (isNetworkError(e)) { + return true; + } + throw e; } assert.commandFailedWithCode( @@ -834,7 +845,7 @@ var ReplSetTest = function(opts) { try { assert.commandWorked(this.getPrimary().adminCommand({replSetReconfig: config})); } catch (e) { - if (tojson(e).indexOf("error doing query: failed") < 0) { + if (!isNetworkError(e)) { throw e; } } diff --git a/src/mongo/shell/utils.js b/src/mongo/shell/utils.js index 2b8bfde5bbc..b79e4cf7ba8 100644 --- a/src/mongo/shell/utils.js +++ b/src/mongo/shell/utils.js @@ -37,6 +37,12 @@ function _getErrorWithCode(codeOrObj, message) { return e; } +// Checks if a javascript exception is a network error. +function isNetworkError(error) { + return error.message.indexOf("error doing query") >= 0 || + error.message.indexOf("socket exception") >= 0; +} + // Please consider using bsonWoCompare instead of this as much as possible. friendlyEqual = function(a, b) { if (a == b) @@ -1188,7 +1194,7 @@ rs._runCmd = function(c) { try { res = db.adminCommand(c); } catch (e) { - if (("" + e).indexOf("error doing query") >= 0) { + if (isNetworkError(e)) { // closed connection. reconnect. db.getLastErrorObj(); var o = db.getLastErrorObj(); |