All Products
Search
Document Center

:Redirect read requests to data images while data is being updated

Last Updated:Jun 17, 2024

ApsaraDB for MongoDB allows you to create read-only data images in a replica set instance or a sharded cluster instance. A data image in a replica set instance can store up to 3 TB of data and that in a sharded cluster instance can store up to 96 TB of data.

Note

You can create data images only in a replica set or sharded cluster instance that runs MongoDB 3.4.

Scenarios

After you create data images for an instance in which a large amount of data is being updated, all read requests from applications are redirected to read data from the data images. The applications do not read data from the instance until data is completely updated in the instance. The applications read data from the data images as if they read data from the instance, without any compromise to the read performance.

Note

After data is updated in the instance, you can synchronize the updated data to the data images so that the applications can read the latest data from the data images later. You can use the commands provided by Alibaba Cloud to enable automatic data synchronization within seconds. Data synchronization does not affect normal read operations.

Create data images in a replica set instance

  1. Connect to the primary or secondary node in which you want to create a data image by using the mongo shell. For more information, see Connect to an ApsaraDB for MongoDB replica set instance by using the mongo shell.

  2. Run the following command to create a data image:

    db.runCommand({checkpoint:"create"})
  3. Run the following command to delete the data image when you no longer need it:

    db.runCommand({checkpoint:"drop"})

Create data images in a sharded cluster instance

  1. Connect to a mongos node in a sharded cluster instance by using the mongo shell. For more information, see Connect to an ApsaraDB for MongoDB sharded cluster instance by using the mongo shell.

  2. Run the following command to create a data image:

    • Run the following command to create a data image on the primary node of each shard:

      db.runCommand({runCommandOnShard: "all", "command": {checkpoint:"create"}})
    • Run the following command to create a data image on a secondary node of each shard:

      db.runCommand({runCommandOnShard: "all", "command": {checkpoint:"create"}, $queryOptions: {$readPreference: {mode: 'secondary'}}})
  3. Run the following command to delete the data image when you no longer need it:

    • Run the following command to delete the data image on the primary node of each shard:

      db.runCommand({runCommandOnShard: "all", "command": {checkpoint:"drop"}})
    • Run the following command to delete the data image on a secondary node of each shard:

      db.runCommand({runCommandOnShard: "all", "command": {checkpoint:"drop"}, $queryOptions: {$readPreference: {mode: 'secondary'}}})