You can call the UpdateTable operation to update the configurations and Stream settings of a data table and 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 data tables.
Operation
/**
* Update the configurations, Stream settings, and reserved read and write throughput of a table.
* You can call this operation to increase or decrease the reserved read and write throughput of a data table.
* @api
* @param [] $request The request parameters.
* @return [] The response.
* @throws OTSClientException The exception that is thrown when a parameter error occurs or the Tablestore server returns a verification error.
* @throws OTSServerException The exception that is thrown if the Tablestore server returns an error.
*/
public function updateTable(array $request);
Parameters
Request Information
Request parameters
Parameter | Description |
table_name | The name of the data table. |
table_options | The configuration information about the data table. For more information, see Data versions and TTL. The configuration information includes the following parameters:
|
reserved_throughput | The reserved read or write throughput of the data table. Note The minimum interval between two consecutive attempts to modify the reserved throughput is 1 minute. You can set the reserved read or write throughput only to 0 for data tables in capacity instances. Reserved throughput does not apply to these instances. The default value 0 specifies that you are charged for all throughput on a pay-as-you-go basis. Unit: capacity unit (CU).
|
stream_spec | (Optional) The Stream configurations.
|
Sample request
$result = $client->updateTable([
'table_name' => '<string>', // Specify the name of the data table. This parameter is required.
'reserved_throughput' => [
'capacity_unit' => [
'read' => <integer>,
'write' => <integer>
]
],
'table_options' => [
'time_to_live' => <integer>,
'max_versions' => <integer>,
'deviation_cell_version_in_sec' => <integer>
],
'stream_spec' => [
'enable_stream' => true || false,
'expiration_time' => <integer>
]
]);
Response
Response parameters
Parameter | Description |
capacity_unit_details | The reserved read or write throughput of the data table. The following parameters are included:
|
table_options | The configuration information about the data table. The following parameters are included: time_to_live, max_versions, and deviation_cell_version_in_sec, which are consistent with the configuration in the request. |
stream_details | The Stream information about the data table. The following parameters are included:
|
Sample response
[
'capacity_unit_details' => [
'capacity_unit' => [
'read' => <integer>,
'write' => <integer>
],
'last_increase_time' => <integer>,
'last_decrease_time' => <integer>
],
'table_options' => [
'time_to_live' => <integer>,
'max_versions' => <integer>,
'deviation_cell_version_in_sec' => <integer>
],
'stream_details' => [
'enable_stream' => true || false,
'stream_id' => '<string>',
'expiration_time' => <integer>,
'last_enable_time' => <integer>
]
]
Examples
Update the reserved throughput of a data table
The following sample code provides an example on how to update the reserved read throughput to 1 and the reserved write throughput to 2 for a data table:
$result = $client->updateTable([
'table_name' => 'SampleTable',
'reserved_throughput' => [
'capacity_unit' => [
'read' => 1, // You can separately update the reserved read and write throughput.
'write' => 2
]
]
]);
Update the lifecycle of a data table
The following sample code provides an example on how to update the lifecycle of a data table to one day (86400 seconds), the maximum data version to 2, and the maximum version offset to 10 seconds:
$result = $client->updateTable([
'table_name' => 'SampleTable',
'table_options' => [
'time_to_live' => 86400,
'max_versions' => 2,
'deviation_cell_version_in_sec' => 10
]
]);
Update the Stream data of a data table
The following sample code provides an example on how to enable Stream for a data table and set the expiration time to 24 hours:
$result = $client->updateTable([
'table_name' => 'SampleTable',
'stream_spec' => [
'enable_stream' => true,
'expiration_time' => 24
]
]);
References
For information about the API operation that you can call to update a table, see UpdateTable.
You can query the description of a table to view the updated configuration information about the table. For more information, see Query the description of a table.
You can call API operations to read and write data in a table. For more information, see Basic operations on data.