Docs Menu

Docs HomeMongoDB Cluster-to-Cluster Sync

commit

On this page

  • Description
  • Requirements
  • Request
  • Request Body Parameters
  • Response
  • Example
  • Confirm that the Synchronization is Ready
  • Send the Commit Request
  • Behavior

Finalizes the sync between the source cluster and the destination cluster and stops continuous sync between clusters. commit also restores collection characteristics that mongosync temporarily alters during synchronization.

The following table illustrates the impact of commit on collection characteristics that mongosync alters during the synchronization process.

Collection Characteristic
Impact of commit
Unique Indexes
commit resets unique indexes that mongosync replicated as non-unique on the destination cluster.
commit resets expireAfterSeconds which mongosync set to the value of MAX_INT on the destination cluster.
commit resets hidden indexes that mongosync replicated as non-hidden on the destination cluster.
If mongosync disabled writes on the destination cluster, commit disables the Write Block Mode.

Before using the commit endpoint:

  • Stop your application. This ensures that no additional writes occur on the source cluster.

  • Use the progress endpoint to confirm the following values:

    • state: "RUNNING"

    • canCommit: true

    • lagTimeSeconds is near 0 (Recommended, but not required)

      Note

      lagTimeSeconds

      lagTimeSeconds indicates the time between the last applied event and time of the current latest event. When you send a commit request, mongosync enters the COMMITTING state for the amount of seconds reported by lagTimeSeconds, and then transitions to the COMMITTED state.

      When lagTimeSeconds is 0, the source and destination clusters are in a consistent state.

POST /api/v1/commit

This endpoint does not use HTTP request body parameters. However, you must specify the --data option with an empty object { }.

Field
Type
Description
success
boolean
When the request is successful, this value is true.
error
string
If an error occurred, indicates the name of the error. This field is omitted from the response when success is true.
errorDescription
string
Detailed description of the error that occurred. This field is omitted from the response when success is true.

The following example commits the synchronization operation to the destination cluster.

Before sending a request to the commit endpoint, use the progress endpoint to confirm that the synchronization is ready to be committed.

curl localhost:27182/api/v1/progress -XGET
{
"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"
}
}
}

The progress endpoint returned "canCommit":true, which means that the commit request can run successfully.

The following command sends a request to the commit endpoint:

curl localhost:27182/api/v1/commit -XPOST --data '{ }'
{"success":true}

If the commit request is successful, mongosync enters the COMMITTING state, then automatically transitions to the COMMITTED state. Once mongosync enters the COMMITTED state, continuous sync between the clusters stops.

←  resumereverse →