Reputation: 401
I am trying to create replica set on Amazon Ec2 instances.I have one primary and one secondary node.If I kill the port of primary node within 10 to 12 my secondary node should become primary node but not happening.After 10 minutes also it is in secondary state only.If I start mongodb on primary server it is starting as secondary and immediately secondary becomes primary. When I checking in config settings
"electionTimeoutMillis" : 10000
rs.config() : When primary is up
rs0:SECONDARY> rs.config();
{
"_id" : "rs0",
"version" : 2,
"protocolVersion" : NumberLong(1),
"writeConcernMajorityJournalDefault" : true,
"members" : [
{
"_id" : 0,
"host" : "xx.xxx.xx.xx:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 1,
"host" : "xx.xxx.xxx.xx:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
}
],
"settings" : {
"chainingAllowed" : true,
"heartbeatIntervalMillis" : 2000,
"heartbeatTimeoutSecs" : 10,
"electionTimeoutMillis" : 10000,
"catchUpTimeoutMillis" : -1,
"catchUpTakeoverDelayMillis" : 30000,
"getLastErrorModes" : {
},
"getLastErrorDefaults" : {
"w" : 1,
"wtimeout" : 0
},
"replicaSetId" : ObjectId("5e26f399cf82d4f8bf826660")
}
}
Upvotes: 2
Views: 4649
Reputation: 14287
In a two member replica-set if any node (primary or secondary) goes down the remaining node can be secondary only. If the primary goes down the secondary cannot become primary. If the secondary node goes down, the primary will step down as primary and becomes secondary.
When there is only one node in the replica-set there cannot be any data replication (replica-sets are about data replication, right?).
Once the second node is back up again, an election takes place and one of the nodes becomes a primary. Once there is a primary, writes can happen and data replication will start.
Upvotes: 4
Reputation: 186
Looking at your configuration it seems like you are using even nodes which causes a problem in the election of the primary node.
This blog might help you.
For more info refer Replication in MongoDB
Upvotes: 0