MongoDB failover reasons

failovermongodb

I have a replica set on MongoDB with 3 members – primary, secondary and arbiter. One day I came and saw that primary and secondary have switched. I'd like to find a reason for the failover that caused the elections. Please advise me how and where I can find what caused it. I looked in the logs and I found only this:

2015-03-03T12:18:41.540-0500 [rsHealthPoll] replset info
my_server:27017 thinks that we are down 2015-03-03T12:18:41.540-0500
[rsHealthPoll] replSet member my_another_server:27017 is now in state
PRIMARY 2015-03-03T12:18:41.540-0500 [rsMgr] stepping down; another
primary was elected more recently

Thanks

Best Answer

Here is what you can do to start

Run the following on the old PRIMARY

var dt = new Date(db.serverStatus().localTime - db.serverStatus().uptime*1000).toString() ; dt

This will print the exact time mongod was started.

PRIMARY failover was triggered 2015-03-03T12:18:41.540-0500.

  • If dt is close to 2015-03-03T12:18:41.540-0500
    • mongod crashed or was restarted
    • Check the mongod Log File on the old PRIMARY for that same timeframe
  • If dt is not close to 2015-03-03T12:18:41.540-0500
    • mongod is still running fine
    • The old PRIMARY simply became unreachable
    • Check network logs along port 27017