Add replicas to a global table
The Tablestore SDK for Java can add one or more replicas to an existing global table and configure whether each replica accepts writes in active-passive or multi-active mode.
Prerequisites
Before you begin, make sure that you have:
Version 5.17.7 or later of the Tablestore SDK for Java, with a client initialized
Tablestore instances in the destination regions to host the replicas
Feature description
Call bindGlobalTable to add one or more same-named replica tables in specified instances for an existing global table. The request does not change the global table's service mode. New replicas are read-only in active-passive mode. In multi-active mode, each replica can be configured to accept writes as needed.
public BindGlobalTableResponse bindGlobalTable(BindGlobalTableRequest request) throws TableStoreException, ClientException
bindGlobalTable is asynchronous. A successful response indicates only that the task has started, and the returned status is RE_CONF. Call describeGlobalTable and wait until status becomes ACTIVE before you use the new replica.
The following example adds a read-only replica to an active-passive global table. Tablestore automatically creates a same-named replica table in the destination instance.
String globalTableId = "gt-01234567-89ab-cdef-0123-456789abcdef";
String globalTableName = "example_table";
BindGlobalTableRequest request = new BindGlobalTableRequest(
globalTableId, globalTableName);
request.addPlacement(new GlobalTableTypes.Placement(
"cn-beijing", "example-replica-instance", false));
BindGlobalTableResponse response = client.bindGlobalTable(request);
System.out.println("GlobalTableId: " + response.getGlobalTableId());
System.out.println("Status: " + response.getStatus());
Parameters
BindGlobalTableRequest contains the following parameters.
|
Name |
Type |
Description |
|
globalTableId (required) |
String |
The global table ID. If you did not record the ID, locate the global table by a physical table. For more information, see Query global table information. |
|
globalTableName (required) |
String |
The global table name, which must match the base table name. |
|
placements (required) |
|
The replica placement list. Add at least one element. Each element configures one replica. |
Replica placement
Each element in placements[] is a Placement object that contains the following parameters.
|
Name |
Type |
Description |
|
regionId (required) |
String |
The ID of the region that contains the replica. Example: |
|
instanceName (required) |
String |
The name of the instance that contains the replica. |
|
writable (required) |
boolean |
Specifies whether the replica accepts writes. Set this parameter to |
Response
BindGlobalTableResponse contains the following fields that are specific to the add operation.
|
Field |
Type |
Description |
|
globalTableId |
String |
Obtain the global table ID by calling |
|
status |
GlobalTableStatus |
Obtain the current status by calling |