Finalize Cutover Process
On this page
You can finalize a migration and transfer your application workload from the source to the destination cluster using the mongosync cutover process.
mongosync
should remain active until it reaches the
COMMITTED state. This allows mongosync
to sync
any additional writes that occur during the migration.
Note
Before you switch your application workload to the destination cluster, you should always verify a successful sync. For more information, see Verify Data Transfer.
Steps
Verify the status of mongosync.
Call the progress endpoint to determine
the status of mongosync
before starting the cutover process.
Ensure that the mongosync
process status indicates the
following values:
canCommit
istrue
.lagTimeSeconds
is small (near0
).If
lagTimeSeconds
isn't close to0
when the cutover starts, cutover might take a long time.When using the Embedded Verifier check both the
verification.source
and theverification.destination
return documents. ThelagTimeSeconds
fields in both documents should be near0
and thephase
fields should show"stream hashing"
.If
/commit
is called and the values are not near0
or if the verifier is not in the stream hashing phase, the cutover process might take a long a time.
The following example returns the status of the synchronization process.
Request
curl localhost:27182/api/v1/progress -XGET
Response
{ "progress": { "state":"RUNNING", "canCommit":true, "canWrite":false, "info":"change event application", "lagTimeSeconds":0, "collectionCopy": { "estimatedTotalBytes":694, "estimatedCopiedBytes":694 }, "directionMapping": { "Source":"cluster0: localhost:27017", "Destination":"cluster1: localhost:27018" }, "verification": { "source": { "estimatedDocumentCount": 42, "hashedDocumentCount": 42, "lagTimeSeconds": 2, "totalCollectionCount": 42, "scannedCollectionCount": 10, "phase": "stream hashing" }, "destination": { "estimatedDocumentCount": 42, "hashedDocumentCount": 42, "lagTimeSeconds": 2, "totalCollectionCount": 42, "scannedCollectionCount": 10, "phase": "stream hashing" } } }, "success": true }
Stop any write operations to the synced collections on the source.
If you start
mongosync
withenableUserWriteBlocking
set totrue
,mongosync
blocks all write operations on the entire source cluster during the commit (step 4) for you.If you didn't start
mongosync
withenableUserWriteBlocking
, ensure that you disable writes. For example, run thesetUserWriteBlockMode
command on the source cluster:db.adminCommand( { setUserWriteBlockMode: 1, global: true } ) If
mongosync
uses filtered sync, it's not necessary to disable writes to the entire source cluster. However, you must ensure that you stop write operations for the collections that the filter includes.
Send a commit request to mongosync
.
If you start multiple mongosync
instances for your
migration, you must issue a commit request for each mongosync
instance.
Request
curl localhost:27182/api/v1/commit -XPOST --data '{ }'
Response
{"success":true}
Note
After you submit a commit
request, call the progress
endpoint
to ensure that the mongosync
state is COMMITTING
or
COMMITTED
.
Once you complete this step, mongosync
blocks writes on the source cluster.
Verify data transfer.
Verify the successful sync of data from the source to the destination cluster.
For more information, see Verify Data Transfer.
Enable application writes on the destination cluster.
To enable writes, update setUserWriteBlockMode
:
db.adminCommand( { setUserWriteBlockMode: 1, global: false } )
Then, transfer your application workload to the destination cluster.
Behavior
canWrite and COMMITTED
mongosync
permits writes on the destination cluster at an
earlier stage than the COMMITTED
state.
In the initial sync, mongosync
replicates unique indexes on
the source cluster as non-unique indexes on the destination
cluster. During commit, the relevant non-unique indexes on the
destination cluster are set to prepareUnique
. When this is
done, the /progress
endpoint begins to return canWrite:
true
. Collections with prepareUnique
indexes reject
new documents that violate the unique index constraint.
mongosync
then converts the prepareUnique
indexes into unique indexes. When this is done, mongosync
changes its state to COMMITTED
.
Note
The conversion of prepareUnique
indexes to unique
indexes can be resource intensive when syncing large
collections. This can result in a long time between the
/progress
endpoint returning canWrite: true
and
mongosync
reaching the COMMITTED
state.