This topic describes how to use the Java software development kit (SDK) to update the configurations of a physical table in a global table, such as whether the table is writable.
Precautions
Data conflicts occur if multiple replicas are writable in active-passive mode. Change this configuration only when you perform an active-passive switchover.
Prerequisites
Method description
public UpdateGlobalTableResponse updateGlobalTable(UpdateGlobalTableRequest request) throws TableStoreException, ClientExceptionExample
private static void updateGlobalTableExample(SyncClient client) {
// Construct the configuration of the physical table to update.
GlobalTableTypes.UpdatePhyTable phyTable = new GlobalTableTypes.UpdatePhyTable(
// 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",
// The name of the replica table.
"i-dest-test"
);
// To perform an active-passive switchover in active-passive mode, modify both writable and primaryEligible.
phyTable.setWritable(true); // Set this replica to be writable.
phyTable.setPrimaryEligible(true); // Allow this replica to be eligible to become the primary table (for active-passive switchover).
// Construct the request.
UpdateGlobalTableRequest request = new UpdateGlobalTableRequest(
// The ID of the global table.
"gt-ee1b54db-f5d9-43f3-ad36-ec44********",
// The name of the global table.
"t-gt-test-1",
phyTable
);
// Send the request.
UpdateGlobalTableResponse response = client.updateGlobalTable(request);
System.out.println("Update succeeded. Request ID: " + response.getRequestId());
}