All Products
Search
Document Center

ApsaraDB for OceanBase:Configure a two-way synchronization task

Last Updated:Dec 12, 2024

This topic describes two-way synchronization between a MySQL database and a MySQL tenant of OceanBase Database.

Important

A data migration task remaining in an inactive state for a long time may fail to be resumed depending on the retention period of incremental logs. Inactive states are Failed, Stopped, and Completed. The data transmission service releases data migration tasks remaining in an inactive state for more than 3 days to reclaim related resources. We recommend that you configure alerting for data migration tasks and handle task exceptions in a timely manner.

Background

What is two-way synchronization?

During incremental data synchronization, you can configure both forward and reverse migration tasks for the same data source to synchronize data between the source and target. A cyclical replication prevention mechanism is used to prevent data that has been synchronized in one direction from being repeatedly synchronized by a task in the reverse direction.

Note

Two-way synchronization does not support simultaneous writes to the source and target. If an application simultaneously writes the same data identified by the same primary or unique key to the source and target, you must define a conflict resolution strategy (overwrite or ignore) for the two-way synchronization task. We recommend that you prohibit an application from simultaneously writing the same data to the source and target.

Migration types that support two-way synchronization

The data transmission service supports two-way data synchronization between a MySQL database and a MySQL tenant of OceanBase Database, between an Oracle database and an Oracle tenant of OceanBase Database, and between OceanBase databases. For more information about the limitations and considerations, see the topics about the corresponding types of data migration.

Statements for creating a schema and granting privileges for an Oracle data source

Before you perform two-way synchronization between an Oracle database and OceanBase Database, create a schema named OMS in the Oracle data source of the current task, and grant the CREATE TABLE privilege to the database account in the data source. Otherwise, data inconsistency may occur in two-way synchronization.

  • Create an OMS user

    CREATE USER OMS IDENTIFIED BY <YOUR_PASSWORD>; // Replace YOUR_PASSWORD with the user password.
    ALTER USER OMS QUOTA unlimited ON <USERS>; // Replace USERS with the user tablespace.
    ALTER USER OMS QUOTA unlimited ON <YOUR_USERNAME> // Replace YOUR_USERNAME with the username for logging in to the data source.
  • Grant privileges

    GRANT CREATE ANY TABLE TO <YOUR_USERNAME>; 
    GRANT INSERT ANY TABLE TO <YOUR_USERNAME>;
    GRANT UPDATE ANY TABLE TO <YOUR_USERNAME>;
    GRANT DELETE ANY TABLE TO <YOUR_USERNAME>;
    GRANT SELECT ANY TABLE TO <YOUR_USERNAME>;

Considerations

A two-way synchronization task consists of a forward task and a reverse task.

Type

Description

Forward task

  • The forward task supports schema migration, full migration, incremental synchronization of DML operations, incremental synchronization of DDL operations, and full verification.

  • The forward task is not supported in database or table aggregation scenarios. For example, it is not supported for table aggregation from sources a and b to target c.

  • Do not perform DDL operations that modify database or table schemas during schema migration or full migration. Otherwise, the task may fail.

  • Do not specify a transaction table for Object Exclusion Rule when you select migration objects by using the Match Rules option.

Reverse task

  • You can configure a reverse task only when the forward task is in the incremental synchronization phase and in the Running state.

  • The reverse task supports only incremental synchronization of DML operations.

  • You cannot modify the synchronization objects when you configure a reverse task. By default, the synchronization objects specified in the forward task are used.

Other considerations

  • If the two-way synchronization task involves a table without a primary key or non-null unique key, duplicate data may appear in the corresponding database or table at the target during synchronization.

  • The two-way synchronization task creates a database or schema named OMS in the MySQL or Oracle database and creates a transaction table in the OMS database or schema to avoid cyclical data synchronization. Do not perform DML or DDL operations on the transaction table during running of the task.

Data conflict scenarios

To ensure data consistency in two-way synchronization, make sure that data operations on the same primary key or non-null unique key are performed only at the source or target. If data is simultaneously updated at the source and target, data conflicts may occur, including the following scenarios.

  • Unique key conflict in INSERT operations

    If an application executes INSERT operations on the same unique key at the source and target approximately at the same time, the INSERT operation at the target fails due to the UNIQUE constraint during synchronization to the target. You can configure the task to ignore conflicting data or overwrite data at the target.

  • Unique key conflict in UPDATE operations

    • If the data to be updated by an UPDATE operation already exists at the target, the data at the target is overwritten by the data from the source.

    • If the data to be updated by an UPDATE operation does not exist at the target, the UPDATE operation fails.

    • If an UPDATE operation results in a primary key or unique key conflict at the target, the UPDATE operation fails.

  • Unique key conflict in DELETE operations

    • If the data to be deleted by a DELETE operation does not exist, the DELETE operation fails.

Procedure

Configure a forward task

  1. Configure a data migration task as prompted to proceed to the Select Migration Type step, and set Synchronous Topology to Bidirectional Synchronization.

    For more information, see the topics about the corresponding types of data migration.

    image

  2. On the Select Migration Type page, specify migration types for the data migration task.

    Two-way synchronization supports the following migration types: Schema Migration, Full Data Migration, Incremental synchronization, and Full Verification.

    image

    Migration type

    Description

    Schema migration

    After a schema migration task is started, the data transmission service migrates the definitions of database objects, such as tables, indexes, constraints, comments, and views, from the source database to the target database and automatically filters out temporary tables.

    Full migration

    After a full migration task is started, the data transmission service migrates existing data from tables in the source database to corresponding tables in the target database.

    Incremental synchronization

    After an incremental synchronization task is started, the data transmission service synchronizes changed data (data that is added, modified, or removed) from the source database to corresponding tables in the target database.

    Options for Incremental synchronization are DML synchronization and DDL synchronization. You can select operations as needed. For more information, see Configure DDL/DML synchronization.

    Note
    • In two-way synchronization, the DML synchronization option must be selected.

    • In two-way synchronization, DDL synchronization is supported only for the forward task.

    Full verification

    After the full migration and incremental synchronization tasks are completed, the data transmission service automatically initiates a full verification task to verify the tables in the source and target databases.

  3. Click Next. On the Select Migration Objects page, specify migration objects for the data migration task.

    You can select Specify Objects or Match Rules to specify the migration objects. This topic describes how to select migration objects by using the Specify Objects option. For more information about how to configure matching rules, see Configure matching rules.

    Important
    • The names of tables to be migrated, as well as the names of columns in the tables, must not contain Chinese characters.

    • If a database or table name contains double dollar signs ($$), you cannot create the migration task.

    • If you have selected DDL synchronization on the Select Migration Type page, we recommend that you select migration objects by using the Match Rules option. This way, all new objects that meet the migration rules will be synchronized. If you select migration objects by using the Specify Objects option, new or renamed objects will not be synchronized.

    image.png

    1. In the Select Migration Objects section, select Specify Objects.

    2. In the Source Object(s) list of the Specify Migration Scope section, select the objects to migrate. You can select tables and views of one or more databases.

    3. Click > to add them to the Target Object(s) list.

    The data transmission service allows you to import objects from text files, rename target objects, set row filters, view column information, and remove a single migration object or all migration objects.

    Note

    When you select Match Rules to specify migration objects, object renaming is implemented based on the syntax of the specified matching rules. In the operation area, you can only set filtering conditions. For more information, see Configure matching rules.

    Operation

    Step

    Import objects

    1. In the list on the right, click Import Objects in the upper-right corner.

    2. In the dialog box that appears, click OK.

      Important

      This operation will overwrite previous selections. Proceed with caution.

    3. In the Import Objects dialog box, import the objects to be migrated.

      You can import CSV files to rename databases or tables and set row filtering conditions. For more information, see Download and import the settings of migration objects.

    4. Click Validate.

      After you import the migration objects, check their validity. Column field mapping is not supported at present.

    5. After the validation succeeds, click OK.

    Rename objects

    The data transmission service allows you to rename migration objects. For more information, see Rename a database table.

    Configure settings

    The data transmission service allows you to filter rows by using WHERE conditions. For more information, see Use SQL conditions to filter data.

    You can also view column information of the migration objects in the View Columns section.

    Remove one or all objects

    The data transmission service allows you to remove a single object or all migration objects that are added to the right-side list during data mapping.

    • Remove a single migration object

      In the list on the right, move the pointer over the object that you want to remove, and click Remove to remove the migration object.

    • Remove all migration objects

      In the list on the right, click Remove All in the upper-right corner. In the dialog box that appears, click OK to remove all migration objects.

  4. Click Next. On the Migration Options page, configure the parameters.

    • Full migration

      The following table describes the parameters for full migration, which are displayed only if you have selected Bidirectional Synchronization and Full Data Migration on the Select Migration Type page.

      image

      Parameter

      Description

      Read Concurrency Configuration

      The concurrency for reading data from the source during full migration. The maximum value is 512. A high read concurrency may incur excessive stress on the source, affecting the business.

      Write Concurrency Configuration

      The concurrency for writing data to the target during full migration. The maximum value is 512. A high write concurrency may incur excessive stress on the target, affecting the business.

      Full Data Migration Rate Limit

      You can choose whether to limit the full migration rate as needed. If you choose to limit the full migration rate, you must specify the records per second (RPS) and bytes per second (BPS). The RPS specifies the maximum number of data rows migrated to the target per second during full migration, and the BPS specifies the maximum amount of data in bytes migrated to the target per second during full migration.

      Note

      The RPS and BPS values specified here are only for throttling. The actual full migration performance is subject to factors such as the settings of the source and target and the instance specifications.

      Processing Strategy When Destination Table Has Records

      Valid values are Ignore and Stop Migration.

      • If you select Ignore, when the data to be inserted conflicts with existing data of a target table, the data transmission service logs the conflicting data while retaining the existing data.

        Important

        If you select Ignore, data is pulled in IN mode during full verification. In this case, verification is inapplicable if the target contains data that does not exist in the source, and the verification performance is downgraded.

      • If you select Stop Migration and a target table contains records, an error prompting migration unsupported is reported during full migration. In this case, you must process the data in the target table before continuing with the migration.

        Important

        If you click Resume in the dialog box prompting the error, the data transmission service ignores this error and continues to migrate data. Proceed with caution.

      Whether to Allow Post-indexing

      Specifies whether to create indexes after the full data migration is completed. Post-indexing can shorten the time required for full data migration. For more information about the considerations on post-indexing, see the description below.

      Important
      • This parameter is displayed only if both Schema Migration and Full Data Migration are selected on the Select Migration Type page.

      • Only non-unique key indexes can be created after the migration is completed.

      • If the target OceanBase database returns the following error during index creation, the data transmission service ignores the error and determines that the index is successfully created, without creating it again.

        • Error message in a MySQL tenant of OceanBase Database: Duplicate key name.

        • Error message in an Oracle tenant of OceanBase Database: name is already used by an existing object.

      If you select Allow, set the following parameters:

      • Single index DDL concurrency configuration: the maximum number of concurrent DDL operations allowed for a single index. A larger value indicates higher resource consumption and faster data migration.

      • Maximum concurrent index DDL quantity configuration: the maximum number of post-indexing DDL operations that the system can call at a time.

      If post-indexing is allowed, we recommend that you use a CLI client to modify the following parameters for business tenants based on the hardware conditions of OceanBase Database and your current business traffic:

      // Specify the limit on the file memory buffer size.
      alter system set _temporary_file_io_area_size = '10' tenant = 'xxx'; 
      // Disable throttling in OceanBase Database V4.x.
      alter system set sys_bkgd_net_percentage = 100;  
    • Incremental synchronization

      The following table describes the parameters for incremental synchronization, which are displayed only if you have selected Bidirectional Synchronization and Incremental synchronization on the Select Migration Type page.

      image

      Parameter

      Description

      Write Concurrency Configuration

      The concurrency for writing data to the target during incremental synchronization. The maximum value is 512. A high write concurrency may incur excessive stress on the target, affecting the business.

      Incremental Synchronization Rate Limit

      You can choose whether to limit the incremental synchronization rate as needed. If you choose to limit the incremental synchronization rate, you must specify the RPS and BPS. The RPS specifies the maximum number of data rows synchronized to the target per second during incremental synchronization, and the BPS specifies the maximum amount of data in bytes synchronized to the target per second during incremental synchronization.

      Note

      The RPS and BPS values specified here are only for throttling. The actual incremental synchronization performance is subject to factors such as the settings of the source and target and the instance specifications.

      Data Conflict Handling Strategy

      Valid values are Ignore errors and keep the original data on the target and Ignore conflicts, use source data to overwrite target data. For more information, see the "Data conflict scenarios" section of this topic.

  5. Click Precheck to start a precheck on the data migration task.

    During the precheck, the data transmission service checks the read and write privileges of the database users and the network connections of the databases. A data migration task can be started only after it passes all check items. If an error is returned during the precheck, you can perform the following operations:

    • Identify and troubleshoot the problem and then perform the precheck again.

    • Click Skip in the Actions column of the failed precheck item. In the dialog box that prompts the consequences of the operation, click OK.

  6. After the precheck succeeds, click Start Task to start the forward task.

Configure a reverse task

  1. Go to the Migration Tasks page. Wait until the forward task is in the incremental synchronization phase and in the Running state. Then, click Configuration for the reverse task.|

    image

  2. In the Configure Reverse Tasks dialog box, configure the parameters.

    image

    Parameter

    Description

    Task Instance

    Select an available task instance from the drop-down list to configure the reverse task. If no task instance is available, purchase one. For more information, see Purchase a data migration project.

    Write Concurrency Configuration

    The concurrency for writing data to the target during full migration. The maximum value is 512. A high write concurrency may incur excessive stress on the target, affecting the business.

    Incremental Synchronization Rate Limit

    You can choose whether to limit the incremental synchronization rate as needed.

    Data Conflict Handling Strategy

    Valid values are Ignore errors and keep the original data on the target and Ignore conflicts, use source data to overwrite target data.

  3. Click Precheck. The system prechecks the reverse task.

  4. After the precheck succeeds, click Start Task to start the reverse task.