This topic describes how to configure two-way synchronization between ApsaraDB for Redis Enhanced Edition (Tair) instances by using Data Transmission Service (DTS). The data synchronization feature is applicable to scenarios such as active geo-redundancy and geo-disaster recovery.
Prerequisites
The source and destination instances are ApsaraDB for Redis Enhanced Edition (Tair) instances that run Redis 5.0.
Note
- A storage-optimized instance of ApsaraDB for Redis Enhanced Edition (Tair) cannot be configured as the source instance.
- If a persistent memory-optimized instance of ApsaraDB for Redis Enhanced Edition (Tair) is configured as the source instance, you must set the appendonly parameter to yes.
- ApsaraDB for Redis Enhanced Edition (Tair) supports the cluster, standard, and read/write splitting architectures.
- The timeout period for data replication between the master and replica nodes in the source instance is specified by the repl-timeout parameter. By default, this parameter is set to 60 seconds. We recommend that you run the
config set repl-timeout 600
command to set this parameter to 600 seconds. 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.
Precautions
- During two-way data 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. Warning To ensure data consistency, do not modify or write data to the same key in the source and destination databases when the two-way data synchronization tasks are 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 databases. 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.
Note For more information about data eviction policies, see How does ApsaraDB for Redis evict data by default? - 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. Note The 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 instance, DTS uses the proxy forwarding mode to write data to the destination instance. Note For 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 or destination ApsaraDB for Redis instance is increased or decreased, or if you change the specifications of the source or destination instance, such as scaling up the memory capacity, you must reconfigure the data synchronization task. To ensure data consistency, we recommend that you clear the data that has been synchronized to the source and destination ApsaraDB for Redis instances before you reconfigure the data synchronization task.
- During data synchronization, the endpoint of the source or destination ApsaraDB for Redis instance may be changed. For example, the endpoint of the source or destination 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.
- If the source or destination instance resides in a region outside the Chinese mainland, two-way data synchronization is supported only between instances located within the same region. For example, if the source instance resides in the Japan (Tokyo) region, data can be synchronized only within the Japan (Tokyo) region and cannot be synchronized to the Germany (Frankfurt) region.
- 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:
We recommend that you perform operations on only one key during data synchronization. This prevents the data synchronization task from being interrupted.CROSSSLOT Keys in request don't hash to the same slot
- 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.
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. |
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 ApsaraDB for Redis instance is deployed in the cluster architecture.
Important
- The PUBLISH command 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 instance. This is because the destination instance 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 in the destination instance. As a result, the destination instance may contain duplicate data records.
Permissions required for database accounts
Database | Permissions and authorization method |
---|---|
Source ApsaraDB for Redis instance | The database accounts of the source and destination ApsaraDB for Redis instances must have the read and write permissions. For more information about how to authorize a database account, see Create and manage database accounts. |
Destination ApsaraDB for Redis instance |
Procedure
- Purchase a data synchronization instance. For more information, see Purchase a DTS instance. Important On the buy page, set the Source Instance parameter to Redis, the Destination Instance parameter to Redis, and the Synchronization Topology parameter to Two-way Synchronization.
- Log on to the DTS console. Note If you are redirected to the Data Management (DMS) console, you can click the
icon in the lower-right corner to go to the previous version of the DTS console.
- In the left-side navigation pane, click Data Synchronization.
- In the upper part of the Data Synchronization Tasks page, select the region in which the destination instance resides.
- Configure the data synchronization task in the forward direction.
- Wait until initial forward synchronization is completed and the data synchronization task is in the Synchronizing state. You can view the status of the data synchronization task on the Synchronization Tasks page.
- Configure the data synchronization task in the reverse direction.
Result
After a period of time, both data synchronization tasks are in the Synchronizing state.