Use the Tablestore SDK for Java to update the data lifecycle, maximum number of versions, maximum version offset, update permissions, Stream, and reserved throughput settings of a Wide Column model table.
Prerequisites
Install the Tablestore SDK for Java and initialize the client.
Function description
public UpdateTableResponse updateTable(UpdateTableRequest request) throws TableStoreException, ClientException
Call updateTable() to update the table options, Stream settings, or reserved throughput of a table. Each request must specify at least one configuration group. If you update TableOptions, specify at least one table option.
The following sample code updates the data lifecycle, maximum number of versions, maximum version offset, and update permissions of the example_table table.
UpdateTableRequest request = new UpdateTableRequest("example_table");
TableOptions tableOptions = new TableOptions();
tableOptions.setTimeToLive(86400);
tableOptions.setMaxVersions(3);
tableOptions.setMaxTimeDeviation(86400L);
tableOptions.setAllowUpdate(false);
request.setTableOptionsForUpdate(tableOptions);
client.updateTable(request);
Parameters
UpdateTableRequest contains the following parameters.
-
tableName (required)
String: The name of the table. -
tableOptionsForUpdate (optional)
TableOptions: The table options to update, which contain the following parameters. Set at least one of the parameters.Name
Type
Description
timeToLive (optional)
OptionalValue<Integer>
The time to live (TTL) of data. Unit: seconds.
-
Set this parameter to -1 to retain data indefinitely. For other values, the minimum is 86400 (one day). Data that exceeds its TTL is automatically deleted.
-
To use a search index or secondary index, set the TTL to -1 or set the
allowUpdateparameter tofalse.
maxVersions (optional)
OptionalValue<Integer>
The maximum number of data versions to retain.
To use a search index or secondary index, set this parameter to 1.
maxTimeDeviation (optional)
OptionalValue<Long>
The max version offset. Unit: seconds.
-
The difference between the timestamp of the written data and the current system time must be within the max version offset. Otherwise, the write operation fails.
-
The valid version range for attribute column data is
[max(Data write time - Max version offset, Data write time - Time to live), Data write time + Max version offset).
allowUpdate (optional)
OptionalValue<Boolean>
Specifies whether data can be updated by using the
updateRowmethod.If this parameter is set to
false, data cannot be updated.ImportantYou can set
updateFullRowonly when you create a table. You cannot modify it by calling theupdateTablemethod. -
-
streamSpecification (optional)
StreamSpecification: The Stream configuration, which contains the following parameters.Name
Type
Description
enableStream (required)
boolean
Specifies whether to enable Stream.
expirationTime (optional)
OptionalValue<Integer>
The retention period of incremental logs. Unit: hours. Maximum value: 168 (7 days).
The
expirationTimeparameter is required ifenableStreamis set totrue. -
reservedThroughputForUpdate (optional)
ReservedThroughput: The reserved read/write throughput to update. Unit: CU. Default value: 0. This setting is supported only for compute-optimized instances in CU mode.
Scenario examples
Update Stream settings
The following sample code enables Stream for the example_table table and sets the retention period of incremental logs to 168 hours.
UpdateTableRequest request = new UpdateTableRequest("example_table");
request.setStreamSpecification(new StreamSpecification(true, 168));
client.updateTable(request);
Update reserved throughput
Reserved throughput is supported only for compute-optimized instances in CU mode. The following sample code sets both the reserved read throughput and reserved write throughput of the example_table table to 0 CUs.
UpdateTableRequest request = new UpdateTableRequest("example_table");
ReservedThroughput reservedThroughput = new ReservedThroughput(0, 0);
request.setReservedThroughputForUpdate(reservedThroughput);
client.updateTable(request);