Database Administrators Asked by Sweeti Bharti on November 25, 2021
We are trying to implement DR setup for our mongodb replica set and currently three nodes in DR are configured to run as hidden nodes. We are trying to test failover to DR which will require promoting hidden node to primary and secondary respectively. What is the best way to achieve this?
I was able to achieve it via using below code snippet:
import pymongo
client = pymongo.MongoClient()
cfgDict = client.local.system.replset.find_one()
for mem in cfgDict['members']:
if(mem.get('host') == "hidden-node-1:27017"):
mem['hidden'] = False
mem['priority'] = 20 #assign highest priority
elif(mem.get('host') == "hidden-node-2:27017"):
mem['hidden'] = False
mem['priority'] = 5
else:
print("NO MATCH FOUND... NOTHING TO RECONFIGURE!")
try:
client.admin.command({'replSetReconfig': cfgDict}, force=True)
except pymongo.errors.ConnectionFailure:
pass
Answered by Sweeti Bharti on November 25, 2021
We are trying to implement DR setup for our mongodb replica set and currently three nodes in DR are configured to run as hidden nodes.
As per MongoDB documentation Configure a Hidden Replica Set Member Hidden members are part of a replica set but cannot become primary and are invisible to client applications. Hidden members may vote in elections.
The most common use of hidden nodes is to support delayed members. If you only need to prevent a member from becoming primary, configure a priority 0 member.
Member Configuration Document
To configure a secondary member as hidden, set its members[n].priority value to 0 and set its members[n].hidden value to true in its member configuration:
{
"_id" : <num>
"host" : <hostname:port>,
"priority" : 0,
"hidden" : true
}
Configuration Procedure
The following example hides the secondary member currently at the index 0 in the members array. To configure a hidden member, use the following sequence of operations in a mongo shell connected to the primary, specifying the member to configure by its array index in the members array:
cfg = rs.conf()
cfg.members[0].priority = 0
cfg.members[0].hidden = true
rs.reconfig(cfg)
After re-configuring the set, this secondary member has a priority of 0 so that it cannot become primary and is hidden. The other members in the set will not advertise the hidden member in the isMaster or db.isMaster() output.
We are trying to test failover to DR which will require promoting hidden node to primary and secondary respectively. What is the best way to achieve this?
Note with WARNING:
primary to step down
, which causes
an election.
When the primary steps down, the mongod
closes all client connections. While this typically takes 10-20
seconds, try to make these changes during scheduled maintenance
periods.Answered by Md Haidar Ali Khan on November 25, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP