1.

What is Covered Query and what is the usage of this?

Answer»

When the primary of a replica set is not available secondary becomes primary, this is done via elections where the most appropriate member of the replica set is promoted to primary. Apart from unavailability, there are few situations when elections are triggered such as:

  • When we initiate any replica set
  • Adding new members to the replica set
  • Changing the CONFIGURATION of the replica set using rs.reconfig() command.
  • Performing maintenance on a replica set by stepping down the member using rs.stepDown().
  • Loss of connectivity between primary and secondary members for more than configured time.
    Until the elections are completed and a new primary is elected, the replica set cannot accept write operations and can only work in read-only mode, if configured for reading from secondary. Below Factors affect the election of new primary: 
    • MongoDB has introduced new Replication protocolVersion: 1 to reduces replica set failover time. In the earlier protocolVersion time taken for election of the new primary was high.
    • All members in replica set send ping requests as heartbeats to every other member every two seconds. If it does not receive the reply of ping requests in 10 seconds, it assumes member is down and MARKS it inaccessible.
    • While initiating the mongod for replica sets members are assigned priority which helps in the decision for the election of the primary. Members with high priority are given more preference to become primary than members with low priority. Zero priority members can NEVER become primary. We can USE this configuration to control which member can become primary. For example, if we want a member from a particular data centre to never become primary we can assign it to zero priority. Arbiters always have zero priority.
    • There might be situations when complete datacenter is down. In such cases, the ability of a replica set to elect primary from other data centre may be affected.
    • In case of a network partition, we may have primary in the partition with a minority member of nodes. In such cases, primary steps down to secondary as it can see only minority nodes. In case we have a partition with majority members a primary WOULD be elected out of them.
    • Of all replica set members, 7 can be voting members. These members participate in the election for the election of the primary. We can control it by selecting appropriate members to be voting members and assigning them votes. For example, we can assign a member more votes to influence the decision of primary election.


Discussion

No Comment Found