Update table configurations
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
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.
public UpdateTableResponse updateTable(UpdateTableRequest request) throws TableStoreException, ClientException
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.
|
Name |
Type |
Description |
|
tableName (required) |
|
The name of the table. |
|
tableOptionsForUpdate (optional) |
|
The table configurations to update. Specify at least one table configuration. |
|
streamSpecification (optional) |
|
The Stream configuration. |
|
reservedThroughputForUpdate (optional) |
|
The reserved read/write throughput configuration. You can specify non-zero values only for compute-optimized instances in CU mode. |
You must specify at least one of tableOptionsForUpdate, streamSpecification, and reservedThroughputForUpdate.
Table configurations
tableOptionsForUpdate is of the TableOptions type and contains the following parameters.
|
Name |
Type |
Description |
|
timeToLive (optional) |
|
The time to live (TTL) of data. Unit: seconds. A value of |
|
maxVersions (optional) |
|
The maximum number of versions to retain for each attribute column. To use a search index or secondary index, set this parameter to |
|
maxTimeDeviation (optional) |
|
The maximum version offset. Unit: seconds. The difference between the timestamp of the data and the current system time must be within the maximum version offset. The valid version range for attribute column data is |
|
allowUpdate (optional) |
|
Specifies whether data can be updated by calling |
You can set updateFullRow only when you create a table. You cannot modify it by calling updateTable.
Stream configuration
streamSpecification 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. Unit: hours. Maximum value: |
Reserved read/write throughput
reservedThroughputForUpdate is of the ReservedThroughput type and contains the following parameter.
|
Name |
Type |
Description |
|
capacityUnit (required) |
|
The reserved read/write throughput configuration. |
Capacity units
reservedThroughputForUpdate.capacityUnit is of the CapacityUnit type and contains the following parameters.
|
Name |
Type |
Description |
|
readCapacityUnit (required) |
|
The reserved read throughput. Unit: CUs. |
|
writeCapacityUnit (required) |
|
The reserved write throughput. Unit: CUs. |
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);