How to upgrade MongoDB without downtime · mongo config servers and mongos processes. In order to...

34
How to upgrade MongoDB without downtime

Transcript of How to upgrade MongoDB without downtime · mongo config servers and mongos processes. In order to...

Page 1: How to upgrade MongoDB without downtime · mongo config servers and mongos processes. In order to upgrade the shards, we can follow exactly the same steps as we've used in the replicasets.

How to upgrade MongoDB without downtime

Page 2: How to upgrade MongoDB without downtime · mongo config servers and mongos processes. In order to upgrade the shards, we can follow exactly the same steps as we've used in the replicasets.

me - @adamotonete

Adamo Tonete, Senior Technical EngineerBrazil

Page 3: How to upgrade MongoDB without downtime · mongo config servers and mongos processes. In order to upgrade the shards, we can follow exactly the same steps as we've used in the replicasets.

3

Agenda

● Versioning● Upgrades● Operations that always require downtime● Upgrading a replica-set● Upgrading a sharded cluster● Live demo - changing versions● Review● Q&A

Page 4: How to upgrade MongoDB without downtime · mongo config servers and mongos processes. In order to upgrade the shards, we can follow exactly the same steps as we've used in the replicasets.

Versioning

Page 5: How to upgrade MongoDB without downtime · mongo config servers and mongos processes. In order to upgrade the shards, we can follow exactly the same steps as we've used in the replicasets.

5

Versioning

Production-ready releases are even numbers:

2.2, 3.0, 3.2

Never EVER use an odd version in production.

2.3, 3.3 are testing versions.

Page 6: How to upgrade MongoDB without downtime · mongo config servers and mongos processes. In order to upgrade the shards, we can follow exactly the same steps as we've used in the replicasets.

6

Versioning

How to read version numbers:

3.2.15

3.2 = release series

15 = revision

Page 7: How to upgrade MongoDB without downtime · mongo config servers and mongos processes. In order to upgrade the shards, we can follow exactly the same steps as we've used in the replicasets.

Upgrading

Page 8: How to upgrade MongoDB without downtime · mongo config servers and mongos processes. In order to upgrade the shards, we can follow exactly the same steps as we've used in the replicasets.

8

Major and Minor upgrades

Minor upgrades are very straight forward, just drop in replacement.

What is a minor upgrade?

Replacing 3.2.14 with 3.2.15 is a revision upgrade.

Database still in the same versions, some fixes were added and might some new features without breaking backwards compatibility.

Page 9: How to upgrade MongoDB without downtime · mongo config servers and mongos processes. In order to upgrade the shards, we can follow exactly the same steps as we've used in the replicasets.

9

Major and Minor upgrades

Minor upgrades may add features from new versions.

MongoDB 3.2.10 has some features and enhancements that were introduced in 3.4...

Such as config servers as replica-set and improvements on wiredTiger.

Page 10: How to upgrade MongoDB without downtime · mongo config servers and mongos processes. In order to upgrade the shards, we can follow exactly the same steps as we've used in the replicasets.

10

Major and Minor upgrades

Major upgrades

Moving from 2.6.x to 3.0.x is considered a major upgrade.

It usually requires driver updates and some testing.

Sometimes there are differences in the database architecture.

If a rollback is necessary, it is way more complicated than updating.

Page 11: How to upgrade MongoDB without downtime · mongo config servers and mongos processes. In order to upgrade the shards, we can follow exactly the same steps as we've used in the replicasets.

11

Major and Minor upgrades

A few examples:

● 2.4 to 2.6 new authentication algorithm.● 3.0 to 3.2 pluggable storage engine. WiredTiger.● 3.2 to 3.4 config servers are now replicasets, data new types, huge

changes in WiredTiger, improvements on initial sync.● 3.4 to 3.6 pre transactions, sessions.● 3.6 to 4.0 transactions.

Page 12: How to upgrade MongoDB without downtime · mongo config servers and mongos processes. In order to upgrade the shards, we can follow exactly the same steps as we've used in the replicasets.

12

Major and Minor upgrades - Rollbacks

Sometimes upgrades don't work as we expect, and a version rollback is necessary.

It is usually possible to rollback, but please check the documented steps before upgrading.

Page 13: How to upgrade MongoDB without downtime · mongo config servers and mongos processes. In order to upgrade the shards, we can follow exactly the same steps as we've used in the replicasets.

13

Feature Compatibility Version

Since version 3.4 it has been possible to turn off new version features to keep compatibility with previous versions.

With that option, it is possible to make 3.4 behave like 3.2, and the same is true for 3.6

Page 14: How to upgrade MongoDB without downtime · mongo config servers and mongos processes. In order to upgrade the shards, we can follow exactly the same steps as we've used in the replicasets.

Operations that require downtime

Page 15: How to upgrade MongoDB without downtime · mongo config servers and mongos processes. In order to upgrade the shards, we can follow exactly the same steps as we've used in the replicasets.

15

Operations that require downtime

● Enable security● Change cluster shared key● Change listen ip

Page 16: How to upgrade MongoDB without downtime · mongo config servers and mongos processes. In order to upgrade the shards, we can follow exactly the same steps as we've used in the replicasets.

Upgrading a replica-set

Page 17: How to upgrade MongoDB without downtime · mongo config servers and mongos processes. In order to upgrade the shards, we can follow exactly the same steps as we've used in the replicasets.

17

Upgrading a replica-set

In order to upgrade a replica-set, we will take advantage of high availability.

Page 18: How to upgrade MongoDB without downtime · mongo config servers and mongos processes. In order to upgrade the shards, we can follow exactly the same steps as we've used in the replicasets.

18

Upgrading a replica-set

Removing a secondary or setting the instance as hidden:

Page 19: How to upgrade MongoDB without downtime · mongo config servers and mongos processes. In order to upgrade the shards, we can follow exactly the same steps as we've used in the replicasets.

19

Upgrading a replica-set

Then drivers will see this configuration:

Page 20: How to upgrade MongoDB without downtime · mongo config servers and mongos processes. In order to upgrade the shards, we can follow exactly the same steps as we've used in the replicasets.

20

Upgrading a replica-set

Repeat the process in the remaining secondaries:

Page 21: How to upgrade MongoDB without downtime · mongo config servers and mongos processes. In order to upgrade the shards, we can follow exactly the same steps as we've used in the replicasets.

21

Upgrading a replica-set

Step the primary down and replace the remaining old instance.

Page 22: How to upgrade MongoDB without downtime · mongo config servers and mongos processes. In order to upgrade the shards, we can follow exactly the same steps as we've used in the replicasets.

22

Upgrading a replica-set

It is not necessary to remove the old versions while updating. We can set the instance as hidden : true in the rs.config() before removing them.

The application driver must be aware of the replica-set configuration, otherwise the application may face downtime.

It is preferable to trigger an election (to step down the primary) as the last operation in the upgrade.

Page 23: How to upgrade MongoDB without downtime · mongo config servers and mongos processes. In order to upgrade the shards, we can follow exactly the same steps as we've used in the replicasets.

Upgrading a sharded environment

Page 24: How to upgrade MongoDB without downtime · mongo config servers and mongos processes. In order to upgrade the shards, we can follow exactly the same steps as we've used in the replicasets.

24

Upgrading a sharded environment

A sharded cluster is one or more shards (replica-sets) managed by the mongo config servers and mongos processes.

In order to upgrade the shards, we can follow exactly the same steps as we've used in the replicasets. However, there is a sequence to be respected when upgrading a sharded cluster.

Page 25: How to upgrade MongoDB without downtime · mongo config servers and mongos processes. In order to upgrade the shards, we can follow exactly the same steps as we've used in the replicasets.

25

Upgrading a sharded cluster

1. Stop the balancer2. Upgrade the config servers3. Upgrade the shards4. Upgrade the mongos5. Re-enable the balancer

Page 26: How to upgrade MongoDB without downtime · mongo config servers and mongos processes. In order to upgrade the shards, we can follow exactly the same steps as we've used in the replicasets.

Live Demo

Page 27: How to upgrade MongoDB without downtime · mongo config servers and mongos processes. In order to upgrade the shards, we can follow exactly the same steps as we've used in the replicasets.

27

This can be a bit boring...

Page 28: How to upgrade MongoDB without downtime · mongo config servers and mongos processes. In order to upgrade the shards, we can follow exactly the same steps as we've used in the replicasets.

Upgrading Replica-set

Page 29: How to upgrade MongoDB without downtime · mongo config servers and mongos processes. In order to upgrade the shards, we can follow exactly the same steps as we've used in the replicasets.

Changing the storage engine on the fly

Page 30: How to upgrade MongoDB without downtime · mongo config servers and mongos processes. In order to upgrade the shards, we can follow exactly the same steps as we've used in the replicasets.

Review

Page 31: How to upgrade MongoDB without downtime · mongo config servers and mongos processes. In order to upgrade the shards, we can follow exactly the same steps as we've used in the replicasets.

31

Review

● The driver plays a very important part in keeping the application online.● Do not move from an ancient version to a new one.● Test the new version before applying it in production.● Create backups before upgrading.

Page 32: How to upgrade MongoDB without downtime · mongo config servers and mongos processes. In order to upgrade the shards, we can follow exactly the same steps as we've used in the replicasets.

Q&A

Page 33: How to upgrade MongoDB without downtime · mongo config servers and mongos processes. In order to upgrade the shards, we can follow exactly the same steps as we've used in the replicasets.

33

Rate Our Session

Page 34: How to upgrade MongoDB without downtime · mongo config servers and mongos processes. In order to upgrade the shards, we can follow exactly the same steps as we've used in the replicasets.

Thank you!