我在ec2上有一个死节点。如何使用pymongo从rep set中删除死的二级?
{u'date': datetime.datetime(2012, 11, 16, 11, 53, 53),
u'members': [{u'_id': 0,
u'health': 1.0,
u'name': u'xxxxxxxxx:27017',
u'optime': Timestamp(1352810702, 1),
u'optimeDate': datetime.datetime(2012, 11, 13, 12, 45, 2),
u'self': True,
u'state': 1,
u'stateStr': u'PRIMARY',
u'uptime': 507560},
{u'_id': 1,
u'health': 1.0,
u'lastHeartbeat': datetime.datetime(2012, 11, 16, 11, 53, 51),
u'name': u'ffffffffff:27017',
u'optime': Timestamp(1352810702, 1),
u'optimeDate': datetime.datetime(2012, 11, 13, 12, 45, 2),
u'pingMs': 1,
u'state': 2,
u'stateStr': u'SECONDARY',
u'uptime': 163187},
{u'_id': 2,
u'errmsg': u'socket exception [CONNECT_ERROR] for jjjjjjjj:27017',
u'health': 0.0,
u'lastHeartbeat': datetime.datetime(2012, 11, 16, 11, 53, 14),
u'name': u'jjjjjjjjjj:27017',
u'optime': Timestamp(1352810702, 1),
u'optimeDate': datetime.datetime(2012, 11, 13, 12, 45, 2),
u'pingMs': 0,
u'state': 8,
u'stateStr': u'(not reachable/healthy)',
u'uptime': 0}],
u'myState': 1,
u'ok': 1.0,
u'set': u'heythat'}
答案 0 :(得分:0)
您可以从local.system.replset
集合中获取副本集配置:
>>> from pymongo import Connection
>>> c = Connection()
>>> conf = c['local']['system.replset'].find_one()
如果你在mongo shell中签入了rs.reconfig包装器的功能,你会发现它还会增加版本,然后运行一个特殊的replSetReconfig
命令。
default:PRIMARY> rs.reconfig
function (cfg, options) {
cfg.version = rs.conf().version + 1;
cmd = {replSetReconfig:cfg};
for (var i in options) {
cmd[i] = options[i];
}
return this._runCmd(cmd);
}
从Python做同样的事情。修改conf['members']
文档(例如删除死节点)并更新版本(添加1)。然后使用更新的replSetReconfig
字典作为参数对管理数据库运行conf
命令。
>>> # change conf['members'] accordingly
>>> conf['version'] += 1
>>> c['admin'].command({'replSetReconfig':conf})