You can call the API operations of Data Transmission Service (DTS) in OpenAPI Explorer to configure one-way or two-way synchronization between ApsaraDB for Redis Enhanced Edition (Tair) instances. This topic describes the usage notes and provides sample code.
Prerequisites
The source and destination instances are ApsaraDB for Redis Enhanced Edition (Tair) instances that run Redis 5.0.
For one-way synchronization, the source instance cannot be a storage-optimized instance. For two-way synchronization, the source and destination instances cannot be storage-optimized instances.
The appendonly parameter is set to yes if the source instance is a persistent memory-optimized instance of ApsaraDB for Redis Enhanced Edition (Tair).
The architecture of the instances is not limited. The architecture can be cluster, standard, or read/write splitting.
Usage notes
During two-way synchronization, the data synchronization task in the forward direction performs initial full data synchronization and incremental data synchronization. The data synchronization task in the reverse direction performs only incremental data synchronization.
WarningTo ensure data consistency, do not modify or write data to the same key in the source and destination databases when the two-way synchronization task is running.
DTS uses the resources of the source and destination databases during initial full data synchronization. This may increase the loads on the database servers. If you synchronize a large amount of data or if the server specifications do not meet your requirements, database services may become unavailable. Before you synchronize data, evaluate the impact of data synchronization on the performance of the source and destination instances. We recommend that you synchronize data during off-peak hours.
We recommend that you do not run the
FLUSHDB
orFLUSHALL
command in the source instance during data synchronization. If you run one of the commands, data inconsistency may occur between the source and destination instances.By default, the maxmemory-policy parameter that specifies how data is evicted is set to volatile-lru for ApsaraDB for Redis instances. If the destination instance has insufficient memory, data inconsistency may occur between the source and destination instances due to data eviction. In this case, the data synchronization task does not stop running.
To prevent data inconsistency, we recommend that you set maxmemory-policy to noeviction for the destination instance. This way, the data synchronization task fails if the destination instance has insufficient memory, but data loss can be prevented for the destination instance.
NoteFor more information about data eviction policies, see What is the default eviction policy of ApsaraDB for Redis?
If an expiration policy is enabled for specific keys in the source database, these keys may not be deleted at the earliest opportunity after they expire. Therefore, the number of keys in the destination database may be less than that in the source database. You can run the INFO command to view the number of keys in the destination database.
NoteThe number of keys that do not have the expiration policy enabled or have not expired is the same between the source and destination databases.
If direct connection is disabled for the destination ApsaraDB for Redis Enhanced Edition (Tair) instance, DTS uses the proxy forwarding mode to write data to the destination instance.
NoteFor more information about how to enable direct connection, see Enable the direct connection mode.
During data synchronization, if the number of shards in the source instance increases or decreases or if the instance specifications are changed (for example, the memory capacity is scaled up), you must reconfigure the data synchronization task. To ensure data consistency, we recommend that you clear the data that has been synchronized to the destination instance before you reconfigure the data synchronization task.
During data synchronization, the endpoint of the source instance may be changed. For example, the endpoint of the source instance is changed if the zone of the instance is changed or the network type is changed from classic network to Virtual Private Cloud (VPC). In this case, you must reconfigure the data synchronization task.
Limits on synchronizing data from a standalone Redis instance to a Redis cluster: Each command can be run only on a single slot in a Redis cluster. If you perform operations on multiple keys in the source database and the keys belong to different slots, the following error occurs:
CROSSSLOT Keys in request don't hash to the same slot
We recommend that you perform operations on only one key during data synchronization. This prevents the data synchronization task from being interrupted.
If the destination instance is deployed in a cluster architecture and the amount of memory used by a shard in the destination instance reaches the upper limit, or if the available storage space of the destination instance is insufficient, the data synchronization task fails due to out of memory (OOM).
If the transparent data encryption (TDE) feature is enabled for the source or destination instance, you cannot use DTS to synchronize data from the source database to the destination database.
The timeout period for data replication between the master and replica nodes in a Redis database is specified by the repl-timeout parameter. We recommend that you run the
config set repl-timeout 600
command to set the timeout period to 600 seconds for the source instance. If the source instance stores a large amount of data, you can increase the value of the repl-timeout parameter based on your business requirements.
Billing
Synchronization type | Task configuration fee |
Schema synchronization and full data synchronization | Free of charge. |
Incremental data synchronization | Charged. For more information, see Billing overview. |
Limits
One-way cascade synchronization is not supported. For more information, see Synchronization topologies.
Commands that can be synchronized
APPEND
BITOP, BLPOP, BRPOP, and BRPOPLPUSH
DECR, DECRBY, and DEL
EVAL, EVALSHA, EXEC, EXPIRE, and EXPIREAT
GEOADD and GETSET
HDEL, HINCRBY, HINCRBYFLOAT, HMSET, HSET, and HSETNX
INCR, INCRBY, and INCRBYFLOAT
LINSERT, LPOP, LPUSH, LPUSHX, LREM, LSET, and LTRIM
MOVE, MSET, MSETNX, and MULTI
PERSIST, PEXPIRE, PEXPIREAT, PFADD, PFMERGE, and PSETEX
RENAME, RENAMENX, RPOP, RPOPLPUSH, RPUSH, and RPUSHX
SADD, SDIFFSTORE, SELECT, SET, SETBIT, SETEX, SETNX, SETRANGE, SINTERSTORE, SMOVE, SPOP, SREM, and SUNIONSTORE
UNLINK, ZADD, ZINCRBY, ZINTERSTORE, ZREM, ZREMRANGEBYLEX, ZUNIONSTORE, ZREMRANGEBYRANK, and ZREMRANGEBYSCORE
SWAPDB (This command cannot be synchronized if the source or destination instance is deployed in the cluster architecture.)
PUBLISH commands cannot be synchronized.
If you run the EVAL or EVALSHA command to call Lua scripts, DTS cannot identify whether these Lua scripts are executed on the destination database. This is because the destination database does not explicitly return the execution results of Lua scripts during incremental data synchronization.
When DTS runs the SYNC or PSYNC command to transfer data of the LIST type, DTS does not clear the existing data. As a result, the destination instance may contain duplicate data records.
Before you begin
To protect the AccessKey pair of your Alibaba Cloud account, we recommend that you create a Resource Access Management (RAM) user, grant the RAM user the permissions to access DTS, and then use the AccessKey pair of the RAM user to call DTS SDK for Java. For more information, see Control access to resources by using RAM users.
Create a data synchronization instance
Log on to OpenAPI Explorer.
Configure the request parameters based on your business requirements. The following table describes the parameters.
Parameter
Description
Value
SourceRegion
The ID of the region in which the source instance resides.
Specify a value for these parameters based on your business requirements.
DestRegion
The ID of the region in which the destination instance resides.
Topology
The synchronization topology. Valid values:
oneway (default): one-way synchronization.
bidirectional: two-way synchronization.
SynchronizationJobClass
The instance class of the data synchronization instance. Valid values: micro, small, medium, and large.
PayType
The billing method of the data synchronization instance. Valid values:
PrePaid: subscription.
PostPaid (default): pay-as-you-go.
SourceEndpoint.InstanceType
The type of the source instance.
Set the value to Redis.
DestinationEndpoint.InstanceType
The type of the destination instance.
Set the value to Redis.
NoteFor more information, see CreateSynchronizationJob.
In the lower part of the page, click Initiate Call.
On the Response tab, view the status of the request and the response.
ImportantIf the request fails, you need to modify the request parameters based on the message returned in the response and send the request again until the request is successful.
Optional. Obtain the sample code of the SDK.
Click the SDK Sample Code tab.
Specify the SDK version and programming language.
Click the icon in the upper-right corner of the code section.
Configure a one-way synchronization task
In this example, the database account of the source instance has the read permissions on the source database. The database account of the destination instance has the read and write permissions on the destination database.
When you configure a one-way synchronization task, you can also use a self-managed Redis database or an ApsaraDB for Redis Community Edition instance as the source or destination database. The configuration method is similar to that described in this topic. However, you must specify the request parameters such as MigrationReserved
based on your actual scenario.
Log on to OpenAPI Explorer.
Configure the request parameters based on your business requirements.
NoteYou must set the SynchronizationDirection parameter to Forward. For more information, see ConfigureSynchronizationJob.
In the lower part of the page, click Initiate Call.
On the Response tab, view the status of the request and the response.
ImportantIf the request fails, you need to modify the request parameters based on the message returned in the response and send the request again until the request is successful.
Optional. Obtain the sample code of the SDK.
Click the SDK Sample Code tab.
Specify the SDK version and programming language.
Click the icon in the upper-right corner of the code section.
Configure two-way synchronization tasks
In this example, the database accounts used for data synchronization have the read and write permissions.
Configure a data synchronization task in the forward direction. For more information, see the Configure a one-way synchronization task section of this topic.
Wait until the state of the data synchronization task in the forward direction changes to Synchronizing.
NoteYou can view the status of a data synchronization task in the DTS console or by calling the DescribeSynchronizationJobStatus operation.
Configure the data synchronization task in the reverse direction.
Optional. Log on to OpenAPI Explorer.
Configure the request parameters based on your business requirements.
NoteYou must set the SynchronizationDirection parameter to Reverse. For more information, see ConfigureSynchronizationJob.
In the lower part of the page, click Initiate Call.
On the Response tab, view the status of the request and the response.
ImportantIf the request fails, you need to modify the request parameters based on the message returned in the response and send the request again until the request is successful.
Optional. Obtain the sample code of the SDK.
Click the SDK Sample Code tab.
Specify the SDK version and programming language.
Click the icon in the upper-right corner of the code section.
References
View the connection status and performance of data synchronization
You can view the performance of data synchronization by using the performance metrics. DTS provides the connection and performance metrics to help you manage data synchronization tasks.
Add an object to a data synchronization task or Remove an object from a data synchronization task
During a data synchronization task, you can add objects to or remove objects from the task.