Upgrade a Sharded Cluster to 3.4

Note

  • Starting in version 3.4.21, MongoDB 3.4-series removes support forUbuntu 16.04 POWER/PPC64LE.

  • For earlier MongoDB Enterprise versions that support Ubuntu 16.04POWER/PPC64LE:

Due to a lock elision bug present in older versionsof the glibc package on Ubuntu 16.04 for POWER, you mustupgrade the glibc package to at least glibc 2.23-0ubuntu5before running MongoDB. Systems with older versions of theglibc package will experience database server crashes andmisbehavior due to random memory corruption, and are unsuitablefor production deployments of MongoDB

Important

Before you attempt any upgrade, please familiarize yourself with thecontent of this document.

If you need guidance on upgrading to 3.4, MongoDB offers major versionupgrade services to help ensurea smooth transition without interruption to your MongoDB application.

Upgrade Recommendations and Checklists

When upgrading, consider the following:

Upgrade Version Path

To upgrade an existing MongoDB deployment to 3.4, you must berunning a 3.2-series release.

To upgrade from a version earlier than the 3.2-series, you mustsuccessively upgrade major releases until you have upgraded to3.2-series. For example, if you are running a 3.0-series, you must3.2before you can upgrade to 3.4.

Preparedness

Before beginning your upgrade, see the Compatibility Changes in MongoDB 3.4 document toensure that your applications and deployments are compatible withMongoDB 3.4. Resolve the incompatibilities in your deployment beforestarting the upgrade.

Before upgrading MongoDB, always test your application in a stagingenvironment before deploying the upgrade to your productionenvironment.

Downgrade Consideration

Once upgraded to 3.4, you cannot downgrade to a 3.2.7 or earlierversion. You can only downgrade to a 3.2.8 or later version.

Avoid reconfiguring replica sets that contain members of differentMongoDB versions as validation rules may differ across MongoDB versions.

mongos and Earlier Versions of mongod Instances

Version 3.4 mongos instances cannot connect toearlier versions of mongod instances.

The 3.2 and earlier mongo shell is not compatible with 3.4clusters.

Prerequisites

    • Version 3.2 or Greater
    • To upgrade a sharded cluster to 3.4, all members of thecluster must be at least version 3.2. The upgrade process checksall components of the cluster and will produce warnings if anycomponent is running version earlier than 3.2.
    • Config Server as Replica Set (CSRS)
    • Starting in 3.4, the use of the deprecated mirroredmongod instances as config servers (SCCC) is no longersupported.

Before you can upgrade your sharded clusters to 3.4, you mustconvert your config servers from SCCC to a replica set (CSRS). Toconvert your config servers from SCCC to CSRS, see UpgradeConfig Servers to Replica Set.

  • Disable the balancer

    • Back up the config Database
    • Optional but Recommended. As a precaution, take a backup of theconfig database before upgrading the sharded cluster.

Download 3.4 Binaries

Use Package Manager

If you installed MongoDB from the MongoDB apt, yum, dnf, orzypper repositories, you should upgrade to 3.4 using your packagemanager.

Follow the appropriate 3.4 installation instructions for your Linux system. Thiswill involve adding a repository for the new release, then performingthe actual upgrade process.

Download 3.4 Binaries Manually

If you have not installed MongoDB using a package manager, you canmanually download the MongoDB binaries from the MongoDB DownloadCenter.

See 3.4 installation instructions for more information.

Upgrade Process

Disable the Balancer.

Disable the balancer as described inDisable the Balancer.

Upgrade the config servers.

If the config servers are replica sets:

  • Upgrade the secondarymembers of the replica set one at a time:

    • Shut down the secondary mongod instance and replacethe 3.2 binary with the 3.4 binary.

    • Start the 3.4 binary with both the —configsvr and—port options:

  1. mongod --configsvr --port <port> --dbpath <path>

If using a configuration file, update the file tospecify sharding.clusterRole: configsvr and net.port and start the3.4 binary:

  1. sharding:
  2. clusterRole: configsvr
  3. net:
  4. port: <port>
  5. storage:
  6. dbpath: <path>

Include any other configuration as appropriate for your deployment.

  • Wait for the member to recover to SECONDARY state beforeupgrading the next secondary member. To check the member’s state,issue rs.status() in the mongo shell.

Repeat for each secondary member.

  • Step down the replica set primary.

    • Connect a mongo shell to the primary and users.stepDown() to step down the primary and force anelection of a new primary:
  1. rs.stepDown()
  • When rs.status() shows that the primary has steppeddown and another member has assumed PRIMARY state, shut downthe stepped-down primary and replace the mongod binarywith the 3.4 binary.

  • Start the 3.4 binary with both the —configsvr and—port options:

  1. mongod --configsvr --port <port> --dbpath <path>

If using a configuration file, update the file tospecify sharding.clusterRole: configsvr and net.port and start the3.4 binary:

  1. sharding:
  2. clusterRole: configsvr
  3. net:
  4. port: <port>
  5. storage:
  6. dbpath: <path>

Include any other configuration as appropriate for your deployment.

Upgrade the shards.

Upgrade the shards one at a time. If the shards are replica sets, for each shard:

  • Upgrade the secondarymembers of the replica set one at a time:

    • Shut down the mongod instance and replace the 3.2binary with the 3.4 binary.

    • Start the 3.4 binary with the —shardsvr and—port command line options.

  1. mongod --shardsvr --port <port> --dbpath <path>

Of if using a configuration file, update the file toinclude sharding.clusterRole: shardsvr and net.port and start:

  1. sharding:
  2. clusterRole: shardsvr
  3. net:
  4. port: <port>
  5. storage:
  6. dbpath: <path>

Include any other configuration as appropriate for your deployment.

  • Wait for the member to recover to SECONDARY state beforeupgrading the next secondary member. To check the member’sstate, you can issue rs.status() in themongo shell.

Repeat for each secondary member.

  • Step down the replica set primary.

Connect a mongo shell to the primary and users.stepDown() to step down the primary and force anelection of a new primary:

  1. rs.stepDown()
  • When rs.status()shows that the primary has stepped down and another memberhas assumed PRIMARY state, upgrade the stepped-down primary:

    • Shut down the stepped-down primary and replace themongod binary with the 3.4 binary.

    • Start the 3.4 binary with the —shardsvr and—port command line options.

  1. mongod --shardsvr --port <port> --dbpath <path>

Of if using a configuration file, update the file tospecify sharding.clusterRole: shardsvr and net.port and start the3.4 binary:

  1. sharding:
  2. clusterRole: shardsvr
  3. net:
  4. port: <port>
  5. storage:
  6. dbpath: <path>

Include any other configuration as appropriate for your deployment.

Upgrade the mongos instances.

Replace each mongos instance with the 3.4 binary andrestart. Include any other configuration as appropriate for your deployment.

Note

In 3.4, mongos no longer supports —chunkSize and—noAutoSplit runtime options (or the corresponding sharding.chunkSizeand sharding.autoSplit settings). If your 3.2 mongosconfiguration includes these settings, remove the settings when running the 3.4mongos.

  1. mongos --configdb csReplSet/<rsconfigsver1:port1>,<rsconfigsver2:port2>,<rsconfigsver3:port3>

Re-enable the balancer.

Using a 3.4 mongo shell, re-enable the balancer asdescribed in Enable the Balancer.

The 3.2 and earlier mongo shell is not compatible with 3.4clusters.

Enable backwards-incompatible 3.4 features.

At this point, you can run the 3.4 binaries without the3.4 features that are incompatible with 3.2.

To enable these 3.4 features, set the feature compatibilityversion to 3.4.

Warning

Enabling these backwards-incompatible features can complicatethe downgrade process. For details,see Remove 3.4 Incompatible Features.

It is recommended that after upgrading, you allow your deployment torun without enabling these features for a burn-in period to ensurethe likelihood of downgrade is minimal. When you are confident thatthe likelihood of downgrade is minimal, enable these features.

On a mongos instance, run thesetFeatureCompatibilityVersion command in the admindatabase:

  1. db.adminCommand( { setFeatureCompatibilityVersion: "3.4" } )

This command must perform writes to an internal systemcollection. If for any reason the command does not completesuccessfully, you can safely retry the command on themongos as the operation is idempotent.

Additional Upgrade Procedures