This topic describes how to use the Java software development kit (SDK) to add one or more replicas to a global table.
Notes
After the bind operation is successful, the system asynchronously binds the new replica and synchronizes data. Call the DescribeGlobalTable operation to view the current status of the global table. If the returned status is Active, the new replica is successfully bound.
Prerequisites
Method description
public BindGlobalTableResponse bindGlobalTable(BindGlobalTableRequest request) throws TableStoreException, ClientExceptionExample
private static void bindGlobalTableExample(SyncClient client) {
// Create a request.
BindGlobalTableRequest request = new BindGlobalTableRequest(
// The global table ID.
"gt-ee1b54db-f5d9-43f3-ad36-ec44********",
// The name of the global table.
"my-global-table"
);
// Create a list of placements. The list must contain at least one replica configuration.
List<GlobalTableTypes.Placement> placements = new ArrayList<>();
// Example: Add a replica in the China (Hangzhou) region.
GlobalTableTypes.Placement hangzhouReplica = new GlobalTableTypes.Placement(
// The ID of the region where the replica is located.
"cn-hangzhou",
// The name of the instance to which the replica belongs.
"instance-replica-hz",
// In active-passive mode, the replica table is not writable. The default value is false.
false
);
// Example: Add a replica in the China (Shanghai) region.
GlobalTableTypes.Placement shanghaiReplica = new GlobalTableTypes.Placement(
// The ID of the region where the replica is located.
"cn-shanghai",
// The name of the instance to which the replica belongs.
"instance-replica-sh",
// In active-passive mode, the replica table is not writable. The default value is false.
false
);
placements.add(hangzhouReplica);
placements.add(shanghaiReplica);
request.setPlacements(placements);
// Send the request.
BindGlobalTableResponse response = client.bindGlobalTable(request);
System.out.println("Bind succeeded. Request ID: " + response.getRequestId());
}