更新表配置

更新时间:
复制 MD 格式

使用 Java SDK 更新宽表模型数据表的数据生命周期、最大版本数、有效版本偏差、更新权限、Stream 和预留读写吞吐量配置。

前提条件

安装Tablestore Java SDK并初始化客户端。

功能说明

public UpdateTableResponse updateTable(UpdateTableRequest request) throws TableStoreException, ClientException

调用 updateTable() 更新指定数据表的表属性、Stream 或预留读写吞吐量。每次请求必须至少设置一类配置。更新 TableOptions 时,必须至少设置一项表属性。

以下示例更新 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:要更新的表属性,包含以下参数。必须至少设置其中一项。

    名称

    类型

    说明

    timeToLive(可选)

    OptionalValue<Integer>

    数据生命周期,单位为秒。

    • 设置为 -1 时,数据永不过期。设置为其他值时,最小值为 86400(1 天),超过生命周期的数据将被自动清除。

    • 使用多元索引或二级索引时,需将数据生命周期设置为 -1,或将allowUpdate设置为false

    maxVersions(可选)

    OptionalValue<Integer>

    最大版本数。

    使用多元索引或二级索引时,必须将最大版本数设置为 1。

    maxTimeDeviation(可选)

    OptionalValue<Long>

    有效版本偏差,单位为秒。

    • 写入数据的时间戳与系统当前时间的差值必须在有效版本偏差范围内,否则写入操作失败。

    • 属性列数据的有效版本范围为[max(数据写入时间-有效版本偏差, 数据写入时间-数据生命周期), 数据写入时间+有效版本偏差)

    allowUpdate(可选)

    OptionalValue<Boolean>

    是否允许通过updateRow方法更新数据。

    设置为false时,不允许更新数据。

    重要

    updateFullRow只能在创建数据表时设置,不能通过updateTable方法修改。

  • streamSpecification(可选)StreamSpecification:Stream 配置,包含以下参数。

    名称

    类型

    说明

    enableStream(必选)

    boolean

    是否开启 Stream。

    expirationTime(可选)

    OptionalValue<Integer>

    增量日志的保留时长。单位为小时,最大值为 168(7 天)。

    expirationTimeenableStream设置为true时必选。

  • reservedThroughputForUpdate(可选)ReservedThroughput预留读写吞吐量,单位为 CU,默认值为 0。仅 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);