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 the verifier is not in the stream hashing phase, the cutover process might take a long 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.
Wait for all transactions on the source cluster to either commit or abort.
mongosync
enables destination-only write-blocking by default. You can explicitly enable it by startingmongosync
withenableUserWriteBlocking
set to"destinationOnly"
.mongosync
only blocks writes on the destination and unblocks them right beforecanWrite
is set totrue
.If you start
mongosync
withenableUserWriteBlocking
set to"sourceAndDestination"
,mongosync
blocks all write operations on the destination cluster and unblocks them right beforecanWrite
is set totrue
.mongosync
blocks writes on the source after you call/commit
.If you start
mongosync
withenableUserWriteBlocking
set to"none"
, 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.
If your source cluster contains Persistant Query Settings (PQS), you must manually migrate PQS to your destination cluster.
If you previously set enableUserWriteBlocking
to true
, mongosync
blocks writes on the source cluster
once you complete this step.
Verify data transfer.
Verify the successful sync of data from the source to the destination cluster.
For more information, see Verify Data Transfer.
If you manually blocked writes on the destination cluster by using setUserWriteBlockMode
, 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.
If you started mongosync
with write-blocking by using the enableUserWriteBlocking
option on
the /start endpoint, you do not need
to complete this step.
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.