Skip to content

Instantly share code, notes, and snippets.

@sarjarapu
Created June 15, 2018 06:10
Show Gist options
  • Save sarjarapu/9f8b9f25a79c2d1b298dec1cbd7f422a to your computer and use it in GitHub Desktop.
Save sarjarapu/9f8b9f25a79c2d1b298dec1cbd7f422a to your computer and use it in GitHub Desktop.
A JavaScript code to set the electionTimeoutMillis to 2 seconds and stepDown the primary
// # rs0:PRIMARY>
rs.isMaster().me
// mon01:27000
var conf = rs.conf()
conf.settings.electionTimeoutMillis=2000
rs.reconfig(conf)
/*
{
"ok": 1,
"operationTime": Timestamp(1529025863, 1),
"$clusterTime": {
"clusterTime": Timestamp(1529025863, 1),
"signature": {
"hash": BinData(0, "AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId": NumberLong(0)
}
}
}
*/
rs.stepDown()
/*
2018-06-15T03:52:42.042+0000 E QUERY [thread1] Error: error doing query: failed: network error while attempting to run command 'replSetStepDown' on host '127.0.0.1:27000' :
DB.prototype.runCommand@src/mongo/shell/db.js:168:1
DB.prototype.adminCommand@src/mongo/shell/db.js:186:16
rs.stepDown@src/mongo/shell/utils.js:1341:12
@(shell):1:1
2018-06-15T03:52:42.043+0000 I NETWORK [thread1] trying reconnect to 127.0.0.1:27000 (127.0.0.1) failed
2018-06-15T03:52:42.043+0000 I NETWORK [thread1] reconnect 127.0.0.1:27000 (127.0.0.1) ok
*/
// rs0:SECONDARY>
rs.isMaster().primary
// mon02:27000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment