In this post, we’ll examine a couple of ways for upgrading MongoDB replica set.
With the release of MongoDB 3.2, comes a rash of new features and improvements. One of these enhancements is improved replica sets. From MongoDB: “A replica set in MongoDB is a group of mongod processes that maintain the same data set. Replica sets provide redundancy and high availability, and are the basis for all production deployments.”
Config servers are replica sets!
This is HUGE. It signals a significant advancement in backups, metadata stability and overall maturity. It is a very long-awaited feature that shows MongoDB is maturing. It means:
How do we activate all these new awesome features? Let’s do it!
This is by far the easiest upgrade bit but DON’T do it until you know your stable on 3.2. Log into each primary and run:
|
1 |
>cfg = rs.conf();<br> {<br> "_id" : "r1",<br> "version" : 2,<br> "members" : [<br> {<br> "_id" : 0,<br> "host" : "localhost:17001"<br> },<br> {<br> "_id" : 1,<br> "host" : "localhost:17002"<br> },<br> {<br> "_id" : 2,<br> "host" : "localhost:17003",<br> }<br> ]<br>}<br>>cfg.protocolVersion=1;<br>>rs.reconfig(cfg);<br>{<br> "ok" : 1,<br> "$gleStats" : {<br> "lastOpTime" : Timestamp(1464947003, 1),<br> "electionId" : ObjectId("7fffffff0000000000000018")<br> }<br>} |
Or:
|
1 |
>db.getSiblingDB('config').shards.forEach(function(shard){<br> x = new Mongo(shard.host); /* Assumes no auth needed */<br> conf =x.getDB("local").system.replset.findOne()<br> conf.protcolVersion=1;conf.version++;<br> x.getDB('admin').runCommand({ replSetReconfig: conf });<br>}); |
Does what it says: kills every process and launches them on 3.2 binaries with no other changes.
Simply runs the quick rs.reconfig() on each primary, adds the new settings to enable to new replication features.
This is not included as part of a normal upgrade so only do this AFTER you’re stable and don’t do it before upgrading the protocolVersion we just talked about. (I mean it! Disregard this advice and your life will seriously not be awesome!)
The easy way, with a small maintenance window, which lets you just restore a good backup and have a nice and simple rollback plan:
Oh look there is a quick script we have made for you:
Resources
RELATED POSTS