In the general case, the upgrade from MongoDB 2.2 to 2.4 is a
binary-compatible “drop-in” upgrade: shut down the mongod
instances and replace them with mongod instances running
2.4. However, before you attempt any upgrade please familiarize
yourself with the content of this document, particularly the procedure
for upgrading sharded clusters and the
considerations for reverting to 2.2 after running 2.4.
Upgrade a Sharded Cluster from MongoDB 2.2 to MongoDB 2.4
Important
Only upgrade sharded clusters to 2.4 if all members
of the cluster are currently running instances of 2.2. The only
supported upgrade path for sharded clusters running 2.0 is via 2.2.
Upgrading a sharded cluster from MongoDB version 2.2 to 2.4
(or 2.3) requires that you run a 2.4 mongos
with the --upgrade option, described in
this procedure. The upgrade process does not require downtime.
The upgrade to MongoDB 2.4 adds epochs to the meta-data for all
collections and chunks in the existing cluster. MongoDB 2.2 processes
are capable of handling epochs, even though 2.2 did not require them.
This procedure applies only to upgrades from version 2.2. Earlier
versions of MongoDB do not correctly handle epochs.
Warning
- Before you start the upgrade, ensure that the amount of free space on
the filesystem for the config database is 4 to 5 times the amount of space
currently used by the config database data files.
- While the upgrade is in progress, you cannot make changes to the
collection meta-data. For example, during the upgrade, do not
perform:
- Once you upgrade to 2.4 and complete the upgrade procedure do
not use 2.0 mongod and mongos processes in
your cluster. 2.0 process may re-introduce old meta-data formats
into cluster meta-data.
Resync after an Interruption of the Critical Section
During the short critical section of the upgrade that applies changes
to the meta-data, it is unlikely but possible that a network
interruption can prevent all three config servers from verifying or
modifying data. If this occurs, the config servers must be re-synced, and there may be problems
starting new mongos processes. The sharded cluster
will remain accessible, but avoid all cluster meta-data changes until
you resync the config servers. Operations that change meta-data include:
adding shards, dropping databases, and dropping collections.
Note
Only perform the following procedure if something (e.g. network,
power, etc.) interrupts the upgrade process during the short
critical section of the upgrade. Remember, you may always safely
attempt the meta data upgrade procedure.
To resync the config servers:
Turn off the balancer in the
sharded cluster and stop all meta-data operations. If you are in the
middle of an upgrade process (Upgrade a Sharded Cluster from MongoDB 2.2 to MongoDB 2.4), you
have already disabled the balancer.
Shut down two of the three config servers, preferably the last two listed
in the configdb string. For example, if your configdb
string is configA:27019,configB:27019,configC:27019, shut down
configB and configC. Shutting down the last two config servers
ensures that most mongos instances will have
uninterrupted access to cluster meta-data.
mongodump the data files of the active config server
(configA).
Move the data files of the deactivated config servers (configB
and configC) to a backup location.
Create new, empty data directories.
Restart the disabled config servers with --dbpath
pointing to the now-empty data directory and --port
pointing to an alternate port (e.g. 27020).
Use mongorestore to repopulate the data files on the
disabled documents from the active
config server (configA) to the restarted config servers on the new
port (configB:27020,configC:27020). These config servers are now
re-synced.
Restart the restored config servers on the old port, resetting the
port back to the old settings (configB:27019 and configC:27019).
In some cases connection pooling may cause spurious failures, as
the mongos disables old connections only after attempted
use. 2.4 fixes this problem, but to avoid this issue in version
2.2, you can restart all mongos instances (one-by-one,
to avoid downtime) and use the rs.stepDown() method
before restarting each of the shard replica set
primaries.
The sharded cluster is now fully resynced; however before you
attempt the upgrade process again, you must manually reset the
upgrade state using a version 2.2 mongos. Begin by
connecting to the 2.2 mongos with the mongo
shell:
mongo <mongos.example.net>
Then, use the following operation to reset the upgrade process:
db.getMongo().getCollection("config.version").update({ _id : 1 }, { $unset : { upgradeState : 1 } })
Finally retry the upgrade process, as in
Upgrade a Sharded Cluster from MongoDB 2.2 to MongoDB 2.4.
Complete Sharded Cluster Upgrade
After you have successfully completed the meta-data upgrade process
described in Meta-Data Upgrade Procedure, and the 2.4
mongos instance starts, you can upgrade the other processes
in your MongoDB deployment.
While the balancer is still disabled, upgrade the components of your
sharded cluster in the following order:
- Upgrade all mongos instances in the cluster, in any
order.
- Upgrade all 3 mongod config server instances, upgrading
the first system in the mongos --configdb argument
last.
- Upgrade each shard, one at a time, upgrading the mongod
secondaries before running replSetStepDown and
upgrading the primary of each shard.
When this process is complete, you can now re-enable the
balancer.
Rolling Upgrade Limitation for 2.2.0 Deployments Running with auth Enabled
MongoDB cannot support deployments that mix 2.2.0 and 2.4.0, or
greater, components. MongoDB version 2.2.1 and later processes can
exist in mixed deployments with 2.4-series processes. Therefore you
cannot perform a rolling upgrade from MongoDB 2.2.0 to MongoDB
2.4.0. To upgrade a cluster with 2.2.0 components, use one of the
following procedures.
- Perform a rolling upgrade of all 2.2.0 processes to the latest
2.2-series release (e.g. 2.2.3) so that there are no processes in
the deployment that predate 2.2.1. When there are no 2.2.0
processes in the deployment, perform a rolling upgrade to 2.4.0.
- Stop all processes in the cluster. Upgrade all processes to a
2.4-series release of MongoDB, and start all processes at the same
time.
Upgrade from 2.3 to 2.4
If you used a mongod from the 2.3 or 2.4-rc (release
candidate) series, you can safely transition these databases to 2.4.0
or later; however, if you created 2dsphere or text indexes
using a mongod before v2.4-rc2, you will need to rebuild
these indexes. For example:
db.records.dropIndex( { loc: "2dsphere" } )
db.records.dropIndex( "records_text" )
db.records.ensureIndex( { loc: "2dsphere" } )
db.records.ensureIndex( { records: "text" } )
Downgrade MongoDB from 2.4 to Previous Versions
For some cases the on-disk format of data files used by 2.4 and 2.2
mongod is compatible, and you can upgrade and downgrade if
needed. However, several new features in 2.4 are incompatible with
previous versions:
- 2dsphere indexes are incompatible with 2.2 and earlier
mongod instances.
- text indexes are incompatible with 2.2 and earlier
mongod instances.
- using a hashed index as a shard key are incompatible with 2.2 and
earlier mongos instances
- hashed indexes are incompatible with 2.0 and earlier
mongod instances.
Note
In sharded clusters, once you have completed the meta-data upgrade
procedure, you cannot use 2.0
mongod or mongos instances in the same
cluster.
If you complete the meta-data upgrade, you can have a mixed cluster
that has both 2.2 and 2.4 mongod and mongos
instances, if needed. However, do not create 2dsphere or
text indexes in a cluster that has 2.2 components.
Considerations and Compatibility
If you upgrade to MongoDB 2.4, and then need to run MongoDB 2.2 with
the same data files, consider the following limitations.
- If you use a hashed index as the shard key index, which is only
possible under 2.4 you will not be able to query data in this
sharded collection. Furthermore, a 2.2 mongos cannot
properly route an insert operation for a collections sharded using a
hashed index for the shard key index: any data that you insert
using a 2.2 mongos, will not arrive on the correct shard
and will not be reachable by future queries.
- If you never create an 2dsphere or text index, you can
move between a 2.4 and 2.2 mongod for a given data set;
however, after you create the first 2dsphere or text index
with a 2.4 mongod you will need to run a 2.2
mongod with the --upgrade
option and drop any 2dsphere or text index.
Upgrade and Downgrade Procedures
Basic Downgrade and Upgrade
Except as described below, moving between 2.2 and 2.4 is a drop-in
replacement:
stop the existing mongod, using the --shutdown option as follows:
mongod --dbpath /var/mongod/data --shutdown
Replace /var/mongod/data with your MongoDB dbpath.
start the new mongod processes with the same
dbpath setting, for example:
mongod --dbpath /var/mongod/data
Replace /var/mongod/data with your MongoDB dbpath.
Downgrade to 2.2 After Creating a 2dsphere or text Index
If you have created 2dsphere or text indexes while running a
2.4 mongod instance, you can downgrade at any time, by
starting the 2.2 mongod with the --upgrade option as follows:
mongod --dbpath /var/mongod/data/ --upgrade
Then, you will need to drop any existing 2dsphere or text
indexes using db.collection.dropIndex(), for example:
db.records.dropIndex( { loc: "2dsphere" } )
db.records.dropIndex( "records_text" )
Warning
--upgrade will run
repairDatabase on any database where you have created
a 2dsphere or text index, which will rebuild all
indexes.
Troubleshooting Upgrade/Downgrade Operations
If you do not use --upgrade, when you
attempt to start a 2.2 mongod and you have created a
2dsphere or text index, mongod will return the
following message:
'need to upgrade database index_plugin_upgrade with pdfile version 4.6, new version: 4.5 Not upgrading, exiting'
While running 2.4, to check the data file version of a MongoDB
database, use the following operation in the shell:
db.getSiblingDB('<databasename>').stats().dataFileVersion
The major data file version for both 2.2 and 2.4 is 4, the minor
data file version for 2.2 is 5 and the minor data file version for
2.4 is 6 if you have created a 2dsphere or text.