MongoDB.live, free & fully virtual. June 9th - 10th. Register Now MongoDB.live, free & fully virtual. June 9th - 10th. Register Now

After restart of primary replica member, it becomes primary again instead of secondary

After restart of primary replica member it becomes again primary ideally it should behave as secondary now. Because new primary were there after the failure. But this doesn’t happen.

Both have same priorties even i.e 1

This is probably your issue. You should have 3 members. Ideally 3 data members but 1 can be an arbiter.

Hi Chris,

Thanks for the answer. But I already have Arbitor also having priorty 0.

Let me re-explain what happend.

Currently:-

"members" : [
		{
			"_id" : 1,
			"name" : "ip-172-19-1-123:27017",
			"health" : 0,
			"state" : 6,
			"stateStr" : "(not reachable/healthy)",
			"uptime" : 0,
			"optime" : {
				"ts" : Timestamp(0, 0),
				"t" : NumberLong(-1)
			},
			"optimeDurable" : {
				"ts" : Timestamp(0, 0),
				"t" : NumberLong(-1)
			},
			"optimeDate" : ISODate("1970-01-01T00:00:00Z"),
			"optimeDurableDate" : ISODate("1970-01-01T00:00:00Z"),
			"lastHeartbeat" : ISODate("2020-03-25T08:42:30.681Z"),
			"lastHeartbeatRecv" : ISODate("2020-03-25T08:42:30.644Z"),
			"pingMs" : NumberLong(0),
			"lastHeartbeatMessage" : "",
			"authenticated" : false,
			"syncingTo" : "",
			"syncSourceHost" : "",
			"syncSourceId" : -1,
			"infoMessage" : "",
			"configVersion" : -1
		},
		{
			"_id" : 2,
			"name" : "ip-172-19-7-214:27017",
			"health" : 1,
			"state" : 1,
			"stateStr" : "PRIMARY",
			"uptime" : 71650,
			"optime" : {
				"ts" : Timestamp(1585125746, 1),
				"t" : NumberLong(25)
			},
			"optimeDate" : ISODate("2020-03-25T08:42:26Z"),
			"syncingTo" : "",
			"syncSourceHost" : "",
			"syncSourceId" : -1,
			"infoMessage" : "",
			"electionTime" : Timestamp(1585054112, 2),
			"electionDate" : ISODate("2020-03-24T12:48:32Z"),
			"configVersion" : 4,
			"self" : true,
			"lastHeartbeatMessage" : ""
		},
		{
			"_id" : 3,
			"name" : "ip-172-19-7-229:27017",
			"health" : 1,
			"state" : 7,
			"stateStr" : "ARBITER",
			"uptime" : 71649,
			"lastHeartbeat" : ISODate("2020-03-25T08:42:30.210Z"),
			"lastHeartbeatRecv" : ISODate("2020-03-25T08:42:30.137Z"),
			"pingMs" : NumberLong(0),
			"lastHeartbeatMessage" : "",
			"syncingTo" : "",
			"syncSourceHost" : "",
			"syncSourceId" : -1,
			"infoMessage" : "",
			"configVersion" : 4
		}

Initially 172-19-1-123 was my “primary” node. I have forcefully closed the box for testing. Then 172-19-7-214 becomes primary as expected.
But after that i have restarted the 172-19-1-123 and it becomes secondary now. That’s also fine.

Again i have killed 172-19-7-214 box which is primary now then 172-19-1-123 becomes primary which is also fine.

Now the issue is when i again restarted 172-19-7-214 it must be secondary but it becomes primary even after restart so why this is happening. The changes during the downtime of 172-19-7-214 is persited in 172-19-1-123. After restart of 172-19-7-214 it must be secondary(Why again it become primary?)

Version , OS ?

You’ll have to look at the logs to see what is going on. Has 123 fully synced the oplog before killing 214?

Can you paste output from rs.conf() & rs.status() ?