使用 Python SDK 更新数据表的数据生命周期、版本、更新方式和预留读写吞吐量。
前提条件
安装Tablestore Python SDK并初始化客户端。
功能说明
调用 update_table 方法更新表配置。table_options 和 reserved_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(必选) |
|
数据表名称。 |
|
table_options(可选) |
|
待更新的表配置。与 |
|
reserved_throughput(可选) |
|
待更新的预留读写吞吐量。与 |
表配置
table_options 的类型为 TableOptions,包含以下参数。
|
名称 |
类型 |
说明 |
|
time_to_live(可选) |
|
数据生命周期,单位为秒。设置为 |
|
max_version(可选) |
|
每个属性列最多保留的版本数。使用多元索引或二级索引时,必须设置为 |
|
max_time_deviation(可选) |
|
有效版本偏差,单位为秒。写入数据的时间戳与系统当前时间的差值必须在有效版本偏差范围内。属性列数据的有效版本范围为 |
|
allow_update(可选) |
|
是否允许通过 |
预留读写吞吐量
reserved_throughput 的类型为 ReservedThroughput,包含以下参数。
|
名称 |
类型 |
说明 |
|
capacity_unit(必选) |
|
预留读写吞吐量,单位为 CU。仅 CU 模式的高性能型实例支持设置非零值。 |
返回值
UpdateTableResponse 包含以下业务信息。
|
字段 |
类型 |
说明 |
|
table_options |
|
更新后的表配置。 |
|
reserved_throughput_details |
|
当前预留读写吞吐量,以及最近一次上调和下调的时间。 |
场景示例
更新预留读写吞吐量
以下示例将 example_table 的预留读写吞吐量设置为 0 CU。
reserved_throughput = ReservedThroughput(
CapacityUnit(read=0, write=0)
)
client.update_table(
"example_table",
reserved_throughput=reserved_throughput,
)