This topic uses parameters and sample code to describe how to use Tablestore SDK for Go to update the configurations of a table. You can update the time to live (TTL), max versions, max version offset, and Stream configuration of a data table. You can also update the reserved read and write throughput of a data table in a high-performance instance.
Prerequisites
An OTSClient instance is initialized. For more information, see Initialize an OTSClient instance.
A data table is created. For more information, see Create a data table.
API operation
// Update the configurations of a data table by using TableOption, ReservedThroughput, or StreamSpec.
UpdateTable(request *UpdateTableRequest) (*UpdateTableResponse, error)
Parameters
For more information, see Parameters.
Sample code
Update the configurations of a data table
The following sample code provides an example on how to update the configurations of a data table.
func UpdateTable(client *tablestore.TableStoreClient, tableName string) {
updateTableReq := new(tablestore.UpdateTableRequest)
// Specify the name of the data table.
updateTableReq.TableName = tableName
updateTableReq.TableOption = new(tablestore.TableOption)
// Specify the TTL of data in the data table. A value of -1 specifies that data in the data table never expires.
updateTableReq.TableOption.TimeToAlive = -1
// Specify the maximum number of versions that can be retained for data in each attribute column of the data table. In this example, up to five versions of data can be retained for each attribute column.
updateTableReq.TableOption.MaxVersion = 5
// Specify the maximum difference between the current system time and the timestamp of the written data. In this example, the maximum difference is set to 86,400 seconds (one day).
updateTableReq.TableOption.DeviationCellVersionInSec = 86400
// Specify that the UpdateRow operation on the data table is allowed.
updateTableReq.TableOption.AllowUpdate = proto.Bool(true)
// Enable the Stream feature and set the validity period of streams to 24 hours.
//updateTableReq.StreamSpec = new(tablestore.StreamSpecification)
//updateTableReq.StreamSpec.EnableStream = true
//updateTableReq.StreamSpec.ExpirationTime = 24
_, err := client.UpdateTable(updateTableReq)
if (err != nil) {
fmt.Println("failed to update table with error:", err)
} else {
fmt.Println("update finished")
}
}
Update the reserved throughput of a data table in a high-performance instance
The following sample code provides an example on how to update the reserved throughput of a data table in a high-performance instance.
func UpdateTable(client *tablestore.TableStoreClient, tableName string) {
updateTableReq := new(tablestore.UpdateTableRequest)
// Specify the name of the data table.
updateTableReq.TableName = tableName
updateTableReq.ReservedThroughput = new(tablestore.ReservedThroughput)
// Set the new reserved read throughput to 1 and the new reserved write throughput to 1. You can set the reserved read and write throughput only to 0 for a data table in a capacity instance.
updateTableReq.ReservedThroughput.Readcap = 1
updateTableReq.ReservedThroughput.Writecap = 1
_, err := client.UpdateTable(updateTableReq)
if (err != nil) {
fmt.Println("failed to update table with error:", err)
} else {
fmt.Println("update finished")
}
}
References
For more information about the API operation, see UpdateTable.
After you update the configurations of a table, you can perform the following operations:
Operations on the table. For more information, see Table.
Operations on data. For more information, see Basic operations on data.