本文介绍如何通过 Java SDK 更新全局表中物理表的配置信息,例如是否可写等。
注意事项
如果修改后主备模式下多个副本均可写,则会出现数据冲突。通常不建议修改,只需在主备切换时修改。
更新场景
主备模式:主备切换时,更新副本地域为可写,或设置为具备主资质。
多活模式:更新副本地域为可读或可写。
前提条件
方法说明
public UpdateGlobalTableResponse updateGlobalTable(UpdateGlobalTableRequest request) throws TableStoreException, ClientException示例
private static void updateGlobalTableExample(SyncClient client) {
// 构造待更新的物理表配置
GlobalTableTypes.UpdatePhyTable phyTable = new GlobalTableTypes.UpdatePhyTable(
// 副本所在地域 ID
"cn-shanghai",
// 副本所属实例名称
"instance-replica-sh",
// 副本表名称
"i-dest-test"
);
// 在主备模式下进行主备切换时,可按需修改 writable和 primaryEligible
// 在多活模式下进行副本可读性修改时,只需修改 writable
phyTable.setWritable(true); // 将该副本设为可写
phyTable.setPrimaryEligible(true); // 允许该副本具备成为主表的资质(用于主备切换)
// 构造请求
UpdateGlobalTableRequest request = new UpdateGlobalTableRequest(
// 全局表 ID
"gt-ee1b54db-f5d9-43f3-ad36-ec44********",
// 全局表名称
"t-gt-test-1",
phyTable
);
// 发起请求
UpdateGlobalTableResponse response = client.updateGlobalTable(request);
System.out.println("Update succeeded. Request ID: " + response.getRequestId());
}