Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1602051
  • 博文数量: 184
  • 博客积分: 3044
  • 博客等级: 中校
  • 技术积分: 2467
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-25 15:04
文章分类

全部博文(184)

文章存档

2022年(4)

2021年(3)

2020年(1)

2019年(5)

2018年(13)

2017年(6)

2016年(10)

2015年(11)

2014年(11)

2013年(13)

2012年(23)

2011年(25)

2010年(2)

2008年(1)

2007年(5)

2006年(51)

分类: 服务器与存储

2012-04-11 17:52:15

One can easily reconfigure a replica set when some members are down as long as a majority is still up. In that case, simply send the reconfig command to the current primary.

If there is no majority (i.e. a majority of nodes are not up or reachable and will not be anytime soon), you must manually intervene to change the set configuration. Reconfiguring a minority partition can be dangerous, as two sides of a network partition won't both be aware of the reconfiguration. Thus, this should not be done in scripts, but only by an operator after careful consideration.

In v2.0+, the force : true option was added for reconfiguring the set when a majority is down. force is for manually reconfiguring the set when there is a serious problem, such as a disaster recovery failover. Do not use it every time you reconfigure, or put it into a script that automatically runs, or use it when there is still a primary.

If you use force and look at your replica set config, you will notice that your version number has jumped a lot (by tens or hundreds of thousands). This is normal and designed to prevent set version collisions if network partitioning ends.

Suggestions on how to deal with majority outages are outlined below.

v2.0+

In newer versions we are able to recover when a majority of nodes are down or on the wrong side of a network partition. We will connect to a surviving member (any one is fine) and "force" a reconfiguration of the set without the down hosts.

  1. Consider doing a backup on a surviving member, both for safety and to bring up more new set members more easily.
  2. Save the current config somewhere so that you can switch back to the old configuration once the down/unreachable members are healed.
    > config = rs.config() > printjson(config) # store this somewhere
  3. Remove the down members from the config.members array.
    > // remove the unreachable members of the set. this is just an example, look > // at config to determine which members to keep > config.members = [config.members[1], config.members[3], config.members[4]]
  4. Reconfigure the set using the force option on the surviving member.
    > rs.reconfig(config, {force : true})

You should now have a new primary, most likely the node you are connected to.

If the failure or partition was only temporary, when healed the nodes will detect that they have been removed from the set and enter a special state where they are up but refuse to answer requests as they are no longer syncing changes. You can now re-add them to the config object and do a reconfig (without force). Be sure that each host has the same _id it had before. If it does not, it will not become an active member of the set and complain verbosely in the logs until you restart it (at which point it will be fine).

Once you add the removed hosts back into the set, they will will detect that they have been added and synchronize to the current state of the set. Be aware that if the original master was one of the removed nodes, these members may need to [rollback].

阅读(2105) | 评论(0) | 转发(0) |
0

上一篇:shell编程之sed

下一篇:shell参数展开

给主人留下些什么吧!~~