Quick Start for Global Tables
Global Table automatically synchronizes data across multiple regions to provide cross-region disaster recovery. Use Global Table when your cross-region business requires low-latency access, high availability, reads and writes from the nearest replica, and disaster recovery switchover.
Prerequisites
Instances are created in both the primary region and each target replica region. For instructions, see Create an instance.
Supported regions — Global Table is available in the China (Hangzhou), China (Shanghai), China (Qingdao), China (Beijing), China (Zhangjiakou), China (Hohhot), China (Ulanqab), China (Shenzhen), China (Guangzhou), and China (Chengdu) regions. Due to data compliance and other reasons, you cannot create a Global Table across regions in different countries. For the regions that Global Table supports, see Supported regions.
Procedure
Step 1: Prepare the base table
In the primary region, create a data table to serve as the base for the Global Table.
Go to the Instance Management page.
Log on to the Tablestore console.
In the top navigation bar, select a resource group and a region.
On the Overview page, click an instance alias, or click Manage Instance in the Actions column of the instance.
On the Instance Details tab, click Create Table.
In the Create Table dialog box, set Data Table Name and Primary Key.
Turn on the Advanced Settings switch, and then turn on the Quick Set Global Table Dependency switch. The system automatically configures the required dependencies for the Global Table, as described in Prerequisites.
For Data Table Name, enter
exampletable. In the Primary Key section, add two primary keys: set the name of the first primary key touser_id, set the type to String, and set it as the partition key; set the name of the second primary key toregion_idand the type to String.Click Create.
Step 2: Create the Global Table
Convert the base table into a Global Table and add replica regions. After the Global Table is created, the system automatically creates the corresponding data tables in the selected replica regions and establishes data synchronization channels.
In the primary region, on the Tables tab, click Create Global Table in the Actions column of the base table. Alternatively, click the data table name, go to the Global Table tab, and then click Create Sync Relationship to continue.
In the Create Global Table dialog box, set the parameters based on the synchronization mode you choose.
If a data table with the same name as the Global Table already exists in the destination instance, the Global Table creation fails.
Configure active-passive mode
In the Current Resource area, set Global Sync Mode to Primary/Standby Mode (Cross-Region Replication).
In the Target Table area, select the region and instance name of the destination instance. You can add multiple destination instances at once. After you create the Global Table, the system automatically creates the target tables in the instances of the selected regions, with the same names as the current base table.
The read/write permission of the destination instance is Read-only.
Configure active-active mode
In the Current Resource area, set Global Sync Mode to Multi-Read Multi-Write (Cross-Region Replication).
In the Target Table area, select the region, instance name, and read/write mode of the destination instance. You can add multiple destination instances at once. After you create the Global Table, the system automatically creates the target tables in the instances of the selected regions, with the same names as the current base table.
Click OK.
To confirm success, in the Create Global Table dialog box, click View List. The new Global Table then appears on the Global Table tab.
Step 3: Verify and use the Global Table
After the Global Table is created, verify data synchronization by performing basic read and write tests.
Write test data — Write test data to the data table in the primary region.
In the primary region, on the Tables tab, click Query in the Actions column of the base table.
On the Query Data tab, click Insert.
In the Insert dialog box, set the primary keys, click Add Column to add an attribute, and then click OK.
Verify data synchronization — Wait 1 to 3 seconds, and then query the data in a replica region.
In the primary region, on the Tables tab, click Query in the Actions column of the base table.
On the Global Table tab of the base table, click the name of a replica table in a replica region.
On the Query Data tab of the replica table, view the data synchronized from the base table. The replica table contains the same data that you wrote in the primary region, which confirms that synchronization succeeded.