Problem:
Twice or thrice a day our node-js process memory goes high and restarted or errored. ( normally it's fine with read & write operation ). I'm getting the following errors when this happened.
[MongoError: no primary found in replicaset] www-1 name: 'MongoError', www-1 message: 'no primary found in replicaset' }
pm2 request timeout about 10 sec > I think it's related with electionTimeout ( https://docs.mongodb.com/manual/reference/replica-configuration/#rsconf.settings.electionTimeoutMillis )
Configuration:
MongoDB 3.2.4 replica set with 3 server (m4.xlarge)
Nodejs using pm2 4 cluseter x 4server (m4.xlarge)
rs.conf setting:
"members" : [
{
"_id" : NumberInt(0),
"host" : "host1:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : NumberInt(1),
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : NumberInt(1)
},
{
"_id" : NumberInt(1),
"host" : "host2:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : NumberInt(1),
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : NumberInt(1)
},
{
"_id" : NumberInt(2),
"host" : "host3:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : NumberInt(1),
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : NumberInt(1)
}]
"settings" : {
"chainingAllowed" : true,
"heartbeatIntervalMillis" : NumberInt(2000),
"heartbeatTimeoutSecs" : NumberInt(10),
"electionTimeoutMillis" : NumberInt(10000),
"getLastErrorModes" : {
},
"getLastErrorDefaults" : {
"w" : NumberInt(1),
"wtimeout" : NumberInt(0)
},
"replicaSetId" : ObjectId("577de60fc5cb2c022f96841f")}
Question:
1.Why am I getting this error?
2.Does MongoDB replica set election occur even if each server has a good health?
I'm not sure if I understand this document correctly. https://docs.mongodb.com/manual/replication/#asynchronous-replication
3.What if I set MongoDB electionTimeoutMillis lower than 10sec. Does this help?