Change Sharded Cluster to WiredTiger

Note

Starting in version 4.2, MongoDB removes the deprecated MMAPv1storage engine. Before upgrading to MongoDB 4.2 from a MongoDB 4.0deployment that uses MMAPv1, you must first upgrade to WiredTiger.

Use this tutorial to update MongoDB 4.0 sharded clusters to useWiredTiger.

For earlier versions of MongoDB:

Considerations

Downtime

If you change the host or port of any shard, you must updatethe shard configuration as well.

PSA 3-member Architecture

Starting in MongoDB 3.6, "majority" read concern,available for WiredTiger, is enabled by default. However, for MongoDB4.0.3+, if you have a three-member shard replica set with aprimary-secondary-arbiter (PSA) architecture, you can disable"majority" read concern for that shard replica set.Disabling "majority" for a three member PSA architectureavoids possible cache-pressure build up.

The procedure below disables "majority" read concern forMongoDB 4.0.3 PSA architecture by including—enableMajorityReadConcern false. If you are running a MongoDB 4.0.1 or4.0.2 PSA architecture, first upgrade to the latest 4.0 version inorder to disable this read concern.

Note

Disabling "majority" read concern disables supportfor Change Streams for MongoDB 4.0 and earlier. For MongoDB4.2+, disabling read concern "majority" has no effect on changestreams availability.

Disabling "majority" read concern affects support fortransactions on sharded clusters. Specifically:

  • A transaction cannot use read concern "snapshot" ifthe transaction involves a shard that has disabled readconcern “majority”.
  • A transaction that writes to multiple shards errors if any of thetransaction’s read or write operations involves a shard that hasdisabled read concern "majority".

However, it does not affect transactionson replica sets. For transactions on replica sets, you can specifyread concern "majority" (or "snapshot"or "local" ) for multi-document transactions even ifread concern "majority" is disabled.

For more information on PSA architecture and read concern"majority", see Disable Read Concern Majority.

MongoDB 3.0 or Greater

You must be using MongoDB version 3.0 or greater in order to use theWiredTiger storage engine. If using an earlier MongoDB version, youmust upgrade your MongoDB version before proceeding to change yourstorage engine. To upgrade your MongoDB version, refer to theappropriate version of the manual.

Default Bind to Localhost

Starting with MongoDB 3.6, MongoDB binaries, mongod andmongos, bind to localhost by default.From MongoDB versions 2.6 to 3.4, only the binaries from theofficial MongoDB RPM (Red Hat, CentOS, Fedora Linux, and derivatives)and DEB (Debian, Ubuntu, and derivatives) packages would bind tolocalhost by default. To learn more about this change, seeLocalhost Binding Compatibility Changes.

Config Servers

Starting in version 3.4, config servers must be deployed asreplica sets (CSRS). As such, version 3.4+ configservers already use the WiredTiger storage engine.

XFS and WiredTiger

With the WiredTiger storage engine, using XFS for data bearing nodes isrecommended on Linux. For more information, seeKernel and File Systems.

MMAPv1 Only Restrictions

Once upgraded to WiredTiger, your WiredTiger deployment is notsubject to the following MMAPv1-only restrictions:

MMAPv1 RestrictionsShort Description
Number of NamespacesFor MMAPv1, the number of namespaces is limited to the size ofthe namespace file divided by 628.
Size of Namespace FileFor MMAPv1, namespace files can be no larger than 2047 megabytes.
Database SizeThe MMAPv1 storage engine limits each database to no more than16000 data files.
Data SizeFor MMAPv1, a single mongod instance cannotmanage a data set that exceeds maximum virtual memory addressspace provided by the underlying operating system.
Number of Collections in a DatabaseFor the MMAPv1 storage engine, the maximum number of collectionsin a database is a function of the size of the namespace fileand the number of indexes of collections in the database.

Procedure

For each replica set shard, to change the storageengine to WiredTiger:

A. Update the secondary members to WiredTiger.

Update the secondary members one at a time:

Shut down the secondary member.

In the mongo shell, shut down the secondary.

  1. use admin
  2. db.shutdownServer()

Prepare a data directory for the new mongod running with WiredTiger.

Prepare a data directory for the new mongod instance thatwill run with the WiredTiger storage engine. mongod must have readand write permissions for this directory. You can either delete thecontents of the stopped secondary member’s current data directory orcreate a new directory entirely.

mongod with WiredTiger will not start with data files created witha different storage engine.

Update configuration for WiredTiger.

Remove any MMAPv1 Specific Configuration Options from the mongodinstance configuration.

Start mongod with WiredTiger.

Start mongod, specifying wiredTiger as the—storageEngine and the prepared data directory forWiredTiger as the —dbpath.

Specify additional options as appropriate, such as—bind_ip.

Warning

Before binding to a non-localhost (e.g. publicly accessible)IP address, ensure you have secured your cluster from unauthorizedaccess. For a complete list of security recommendations, seeSecurity Checklist. At minimum, considerenabling authentication andhardening network infrastructure.

  • General Use (For Most Architectures)
  • PSA Architecture
  1. mongod --storageEngine wiredTiger --dbpath <newWiredTigerDBPath> --replSet <replSetName> --bind_ip localhost,<hostname(s)|ip address(es)>

Important

If you are running a three-member PSA architecture andMongoDB version 4.0.3+, include—enableMajorityReadConcern false to disable read concern majority. See PSA 3-member Architecture.

  1. mongod --storageEngine wiredTiger --dbpath <newWiredTigerDBPath> --replSet <replSetName> --bind_ip localhost,<hostname(s)|ip address(es)> --enableMajorityReadConcern false

Since no data exists in the —dbpath, the mongod will perform aninitial sync. The length of theinitial sync process depends on the size of the database and networkconnection between members of the replica set.

You can also specify the options in a configuration file. To specify the storage engine, usethe storage.engine setting.

Repeat the steps for the remaining secondary members, updating them oneat a time.

B. Step down the primary.

Once all the secondary members have been upgraded to WiredTiger,connect a mongo shell to the primary and users.stepDown() to step down the primary and force an electionof a new primary.

  1. rs.stepDown()

C. Update the old primary.

When the primary has stepped down and become a secondary, update thesecondary to use WiredTiger as before:

Shut down the secondary member.

In the mongo shell, shut down the secondary.

  1. use admin
  2. db.shutdownServer()

Prepare a data directory for the new mongod running with WiredTiger.

Prepare a data directory for the new mongod instance thatwill run with the WiredTiger storage engine. mongod must have readand write permissions for this directory. You can either delete thecontents of the stopped secondary member’s current data directory orcreate a new directory entirely.

mongod with WiredTiger will not start with data files created witha different storage engine.

Update configuration for WiredTiger.

Remove any MMAPv1 Specific Configuration Options from the mongodinstance configuration.

Start mongod with WiredTiger.

Start mongod, specifying wiredTiger as the—storageEngine and the prepared data directory forWiredTiger as the —dbpath.

Specify additional options as appropriate, such as—bind_ip.

Warning

Before binding to a non-localhost (e.g. publicly accessible)IP address, ensure you have secured your cluster from unauthorizedaccess. For a complete list of security recommendations, seeSecurity Checklist. At minimum, considerenabling authentication andhardening network infrastructure.

  • General Use (For Most Architectures)
  • PSA Architecture
  1. mongod --storageEngine wiredTiger --dbpath <newWiredTigerDBPath> --replSet <replSetName> --bind_ip localhost,<hostname(s)|ip address(es)>

Important

If you are running a three-member PSA architecture andMongoDB version 4.0.3+, include—enableMajorityReadConcern false to disable read concern majority. See PSA 3-member Architecture.

  1. mongod --storageEngine wiredTiger --dbpath <newWiredTigerDBPath> --replSet <replSetName> --bind_ip localhost,<hostname(s)|ip address(es)> --enableMajorityReadConcern false

Since no data exists in the —dbpath, the mongod will perform aninitial sync. The length of theinitial sync process depends on the size of the database and networkconnection between members of the replica set.

You can also specify the options in a configuration file. To specify the storage engine, usethe storage.engine setting.

Repeat the procedure for the other shards.