更新表配置

更新时间:
复制 MD 格式

使用 Python SDK 更新数据表的数据生命周期、版本、更新方式和预留读写吞吐量。

前提条件

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

功能说明

调用 update_table 方法更新表配置。table_optionsreserved_throughput 至少设置一项。

def update_table(
    self,
    table_name,
    table_options=None,
    reserved_throughput=None,
)

以下示例将 example_table 的数据生命周期更新为 7 天,并禁止通过 update_row 方法更新数据。

table_options = TableOptions(
    time_to_live=604800,
    max_version=1,
    max_time_deviation=86400,
    allow_update=False,
)

client.update_table(
    "example_table",
    table_options=table_options,
)

参数说明

update_table 方法包含以下参数。

名称

类型

说明

table_name(必选)

str

数据表名称。

table_options(可选)

TableOptions

待更新的表配置。与 reserved_throughput 至少设置一项。

reserved_throughput(可选)

ReservedThroughput

待更新的预留读写吞吐量。与 table_options 至少设置一项。

表配置

table_options 的类型为 TableOptions,包含以下参数。

名称

类型

说明

time_to_live(可选)

int

数据生命周期,单位为秒。设置为 -1 表示数据永不过期;设置为其他值时,最小值为 86400(1 天),超出生命周期的数据将被自动清除。使用多元索引或二级索引时,必须设置为 -1,或将 allow_update 设置为 False

max_version(可选)

int

每个属性列最多保留的版本数。使用多元索引或二级索引时,必须设置为 1

max_time_deviation(可选)

int

有效版本偏差,单位为秒。写入数据的时间戳与系统当前时间的差值必须在有效版本偏差范围内。属性列数据的有效版本范围为 [max(数据写入时间-有效版本偏差, 数据写入时间-数据生命周期), 数据写入时间+有效版本偏差)

allow_update(可选)

bool

是否允许通过 update_row 方法更新数据。设置为 False 时,无法通过 update_row 方法更新数据。

预留读写吞吐量

reserved_throughput 的类型为 ReservedThroughput,包含以下参数。

名称

类型

说明

capacity_unit(必选)

CapacityUnit

预留读写吞吐量,单位为 CU。仅 CU 模式的高性能型实例支持设置非零值。

返回值

UpdateTableResponse 包含以下业务信息。

字段

类型

说明

table_options

TableOptions

更新后的表配置。

reserved_throughput_details

ReservedThroughputDetails

当前预留读写吞吐量,以及最近一次上调和下调的时间。

场景示例

更新预留读写吞吐量

以下示例将 example_table 的预留读写吞吐量设置为 0 CU。

reserved_throughput = ReservedThroughput(
    CapacityUnit(read=0, write=0)
)

client.update_table(
    "example_table",
    reserved_throughput=reserved_throughput,
)