Use the Tablestore SDK for Go to update the TTL, maximum number of versions, maximum version offset, update permissions, Stream settings, and reserved throughput of a table.
Prerequisites
Install the Tablestore SDK for Go and initialize the client.
Description
Call UpdateTable to update the table properties, Stream settings, or reserved throughput of a table. Each request must specify at least one type of configuration.
func (tableStoreClient *TableStoreClient) UpdateTable(request *UpdateTableRequest) (*UpdateTableResponse, error)
The following sample updates the TTL, maximum number of versions, maximum version offset, and update permissions of the example_table table.
request := &tablestore.UpdateTableRequest{
TableName: "example_table",
TableOption: &tablestore.TableOption{
TimeToAlive: 86400,
MaxVersion: 3,
DeviationCellVersionInSec: 86400,
AllowUpdate: proto.Bool(false),
},
}
_, err := client.UpdateTable(request)
if err != nil {
log.Fatal(err)
}
Parameters
UpdateTableRequest contains the following parameters.
|
Name |
Type |
Description |
|
TableName (required) |
|
The table name. |
|
TableOption (optional) |
|
The table properties to update. |
|
StreamSpec (optional) |
|
The Stream settings. |
|
ReservedThroughput (optional) |
|
The reserved read/write throughput. Non-zero values apply only to high-performance instances in CU mode. |
At least one of TableOption, StreamSpec, and ReservedThroughput is required.
Table options
TableOption contains the following parameters.
|
Name |
Type |
Description |
|
TimeToAlive (optional) |
|
The time to live (TTL), in seconds. A value of |
|
MaxVersion (optional) |
|
The maximum number of versions retained for each attribute column. To use a search index or secondary index, set this parameter to |
|
DeviationCellVersionInSec (optional) |
|
The maximum version offset, in seconds. The difference between the timestamp of written data and the current system time must be within this range. Valid versions fall within |
|
AllowUpdate (optional) |
|
Specifies whether data can be updated by calling |
UpdateFullRow can be configured only when a table is created. It cannot be modified by calling UpdateTable.
Stream settings
StreamSpec is of the StreamSpecification type and contains the following parameters.
|
Name |
Type |
Description |
|
EnableStream (required) |
|
Specifies whether to enable Stream. |
|
ExpirationTime (optional) |
|
The retention period of incremental logs, in hours. Maximum value: Important
When you modify the |
Reserved throughput
ReservedThroughput contains the following parameters.
|
Name |
Type |
Description |
|
Readcap (optional) |
|
The reserved read throughput, in CUs. Default value: |
|
Writecap (optional) |
|
The reserved write throughput, in CUs. Default value: |
Examples
Update Stream settings
The following sample enables Stream for the example_table table and sets the incremental log retention period to 168 hours.
request := &tablestore.UpdateTableRequest{
TableName: "example_table",
StreamSpec: &tablestore.StreamSpecification{
EnableStream: true,
ExpirationTime: 168,
},
}
_, err := client.UpdateTable(request)
if err != nil {
log.Fatal(err)
}