For High Availability, In Replica set, priority and votes fields are very important and play key role while electing new primary in case of any issue with current primary.
Priority:
Based on value assigned to priority field, it has priority to participate in election and to become as a primary. By default all secondary members are eligible to become as primary though election process.
To modify priorities, you can update array of members in replica set configuration. The array index begins with 0.
General form like, members[n].priority = value.
Ex: members[0].priority = 0.5
members[1].priority = 2.
In the above example, member 1 has high priority to become as primary, member 0 has low priority.
We can give any number between 0 and 1000 as a value to priority field of members. The default value for the priority field is 1.
To block a member from becoming as a primary, change the priority value of that member to 0.
Ex: members[2].priority = 0.
Votes and voting:
A replica set can have up to 50 members, but voting members should be 7 only, remaining nodes we can add as non-voting members. These non-voting members can have data and will allow read connections from client application, but don't participate and vote in elections.
For non-voting members, Priority and votes value should be equal to 0.
Members with priority greater than 0 cannot have 0 votes. But members with votes equal to 1, can have priority as 0, like Arbiter node.
Arbiter node has priority value equal to 0 as it should not become as primary as it doesn't hold any data and it has votes equal to 1 as it should participate in election to elect new primary. If your replica set has even number of nodes, you can add an arbiter node to avoid tie during elections for new primary.
We can check priority and votes with rs.conf() by connecting to database server.
rs0:PRIMARY> rs.conf()
{
"_id" : "rs0",
"version" : 3,
"protocolVersion" : NumberLong(1),
"writeConcernMajorityJournalDefault" : true,
"members" : [
{
"_id" : 0,
"host" : "localhost:27000",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 1,
"host" : "localhost:27001",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 2,
"host" : "localhost:27002",
"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("5d0e133f74cae82235a32ff7")
}
}
Note: Base information from MongoDB docs.
Updating values of priority and votes in replica set configuration, will share in next post .. :)
-- Thiru //
No comments:
Post a Comment