This topic uses parameters and sample code to describe how to use Tablestore SDK for Java 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.
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.
private static void updateTable(SyncClient client) {
// Specify the TTL of data in the data table. A value of -1 specifies that data in the data table never expires.
int timeToLive = -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.
int maxVersions = 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).
long maxTimeDeviation = 86400L;
TableOptions tableOptions = new TableOptions(timeToLive, maxVersions, maxTimeDeviation);
// Specify that the UpdateRow operation on the data table is allowed.
tableOptions.setAllowUpdate(true);
// Enable the Stream feature and set the validity period of streams to 24 hours.
//StreamSpecification streamSpecification = new StreamSpecification(true, 24);
// Specify the name of the data table.
UpdateTableRequest request = new UpdateTableRequest("<TABLE_NAME>");
request.setTableOptionsForUpdate(tableOptions);
client.updateTable(request);
}
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.
private static void updateTable(SyncClient client) {
// 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.
ReservedThroughput reservedThroughput = new ReservedThroughput(new CapacityUnit(1, 1));
// Specify the name of the data table.
UpdateTableRequest request = new UpdateTableRequest("<TABLE_NAME>");
request.setReservedThroughputForUpdate(reservedThroughput);
client.updateTable(request);
}
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 Operations on tables.
Operations on data. For more information, see Basic operations on data.