全部產品
Search
文件中心

Tablestore:更新表配置

更新時間:Aug 05, 2026

使用 Java SDK 更新寬表模型資料表的資料生命週期、最大版本數、有效版本偏差、更新許可權、Stream 和預留讀寫輸送量配置。

前提條件

安裝Tablestore Java SDK並初始化用戶端。

功能說明

調用 updateTable 方法更新指定資料表的表屬性、Stream 或預留讀寫輸送量。每次請求必須至少設定一類配置。更新 TableOptions 時,必須至少設定一項表屬性。

public UpdateTableResponse updateTable(UpdateTableRequest request) throws TableStoreException, ClientException

以下樣本更新 example_table 資料表的資料生命週期、最大版本數、有效版本偏差和更新許可權。

UpdateTableRequest request = new UpdateTableRequest("example_table");

TableOptions tableOptions = new TableOptions();
tableOptions.setTimeToLive(86400);
tableOptions.setMaxVersions(3);
tableOptions.setMaxTimeDeviation(86400L);
tableOptions.setAllowUpdate(false);
request.setTableOptionsForUpdate(tableOptions);

client.updateTable(request);

參數說明

UpdateTableRequest包含以下參數。

名稱

類型

說明

tableName(必選)

String

資料表名稱。

tableOptionsForUpdate(可選)

TableOptions

要更新的表屬性。至少設定一項表屬性。

streamSpecification(可選)

StreamSpecification

Stream 配置。

reservedThroughputForUpdate(可選)

ReservedThroughput

預留讀寫輸送量配置。僅 CU 模式的高效能型執行個體支援設定非零值。

tableOptionsForUpdate、streamSpecification 和 reservedThroughputForUpdate 必須至少設定一個。

表配置

tableOptionsForUpdate 的類型為 TableOptions,包含以下參數。

名稱

類型

說明

timeToLive(可選)

Integer

資料生命週期,單位為秒。設定為 -1 時資料永不到期;設定為其他值時,最小值為 86400(1 天),超出生命週期的資料將被自動清除。使用多元索引或二級索引時,需設定為 -1,或將 allowUpdate 設定為 false。

maxVersions(可選)

Integer

每個屬性列最多保留的版本數。使用多元索引或二級索引時必須設定為 1。

maxTimeDeviation(可選)

Long

有效版本偏差,單位為秒。寫入資料的時間戳記與系統目前時間的差值必須在有效版本偏差範圍內。屬性列資料的有效版本範圍為 [max(資料寫入時間-有效版本偏差, 資料寫入時間-資料生命週期), 資料寫入時間+有效版本偏差)。

allowUpdate(可選)

Boolean

是否允許通過 updateRow 方法更新資料。設定為 false 時不允許更新資料。

重要

updateFullRow只能在建立資料表時設定,不能通過updateTable方法修改。

Stream 配置

streamSpecification 的類型為 StreamSpecification,包含以下參數。

名稱

類型

說明

enableStream(必選)

Boolean

是否開啟 Stream。

expirationTime(可選)

Integer

增量日誌的保留時間長度,單位為小時,最大值為 168(7 天)。enableStream 設定為 true 時必須設定。

預留讀寫輸送量

reservedThroughputForUpdate 的類型為 ReservedThroughput,包含以下參數。

名稱

類型

說明

capacityUnit(必選)

CapacityUnit

預留讀寫輸送量配置。

容量單元

reservedThroughputForUpdate.capacityUnit 的類型為 CapacityUnit,包含以下參數。

名稱

類型

說明

readCapacityUnit(必選)

Integer

預留讀輸送量,單位為 CU。

writeCapacityUnit(必選)

Integer

預留寫輸送量,單位為 CU。

情境樣本

更新 Stream 配置

以下樣本為 example_table 資料表開啟 Stream,並將增量日誌的到期時間設定為 168 小時。

UpdateTableRequest request = new UpdateTableRequest("example_table");
request.setStreamSpecification(new StreamSpecification(true, 168));

client.updateTable(request);

更新預留讀寫輸送量

僅 CU 模式的高效能型執行個體支援預留讀寫輸送量。以下樣本將 example_table 資料表的預留讀輸送量和預留寫輸送量都設定為 0 CU。

UpdateTableRequest request = new UpdateTableRequest("example_table");
ReservedThroughput reservedThroughput = new ReservedThroughput(0, 0);
request.setReservedThroughputForUpdate(reservedThroughput);

client.updateTable(request);