Time series data lifecycle

更新时间:
复制 MD 格式

To automatically clean up historical data in a time series table, you can use the data lifecycle (TTL) feature. This helps you efficiently manage your time series data, reduce storage usage, and lower storage costs. After you configure a TTL, you can modify its value if you want to extend the data retention period.

Precautions

  • Deleted data cannot be recovered. Proceed with caution.

    Before you configure a TTL to clean up historical data, back up the data if needed. You can use the Data Integration service in DataWorks to export time series data to OSS. For more information, see Synchronize data to OSS.

  • Before you modify the TTL, you can call the DescribeTimeseriesTable operation to view the current data lifecycle setting.

Data lifecycle

In the time series model, data includes time series metadata and time series data, which are stored in a time series metadata table and a time series data table, respectively. Tablestore provides separate data lifecycles for time series metadata and time series data.

Time series table data lifecycle

The data lifecycle for a time series table is an attribute of the time series data table. It specifies the data retention period in seconds. When the age of the time series data exceeds the configured TTL, the system automatically and asynchronously deletes the expired data.

For example, if a table's TTL is set to 86400 (one day), then at 2016-07-21 00:00:00 UTC+8, all time series data from before 2016-07-20 00:00:00 UTC+8 expires. The system then automatically and asynchronously deletes the expired data.

When you create a time series table, if you do not set a TTL, the system uses the default value of -1, which means the data never expires. You can also define a custom TTL. After you create the table, you can call the UpdateTimeseriesTable operation to modify the TTL.

Expired data is considered invalid and cannot be queried, even if the system has not yet physically deleted it.

  • If you decrease the TTL, some data in the time series table may immediately expire. The system asynchronously deletes this expired data.

  • If you increase the TTL, data that had expired under the old TTL but is still within the new TTL's retention period may become queryable again, provided the system has not yet deleted it.

Time series metadata lifecycle

The data lifecycle for time series metadata is an attribute of the time series metadata table. It specifies the retention period for the metadata in seconds. When the age of the time series metadata exceeds the configured TTL, the system automatically and asynchronously deletes the expired metadata. This process does not delete the corresponding time series data.

Important

If time series metadata expires but the corresponding time series data has not, you can still query the time series data by specifying its time series identifier in a GetTimeseriesData API call.

When you create a time series table, if you do not set a TTL for its metadata, the system uses the default value of -1, which means the metadata never expires. You can also define a custom TTL. After you create the table, you can call the UpdateTimeseriesTable operation to modify the TTL.

Important

The time series metadata includes an updatable attribute column named _attributes. However, you can update this attribute only when the data lifecycle for the time series metadata is set to -1, which means the metadata never expires.

If you change the data lifecycle for time series metadata from -1 to a value of 7 days or more, ensure your business logic does not require updating time series metadata attributes. You must also set Whether to Update Attributes of Time Series Metadata to No.

To set Whether to Update Attributes of Time Series Metadata to Yes, you must set the TTL of Time Series Metadata to -1.

Expired metadata is considered invalid and cannot be searched, even if the system has not yet physically deleted it.

  • If you decrease the TTL, some metadata in the time series metadata table may immediately expire. The system asynchronously deletes this expired metadata.

  • If you increase the TTL, metadata that had expired under the old TTL but is still within the new TTL's retention period may become searchable again, provided the system has not yet deleted it.

Methods

You can configure the data lifecycle when you create a time series table or modify it after the table is created. This section shows how to modify the data lifecycle for an existing table by using the console, CLI, or an SDK.

Note
  • For information about how to configure the data lifecycle when you create a table, see Manage time series tables.

  • The supported features may vary based on the method that you use.

Console

You can use the console to modify the data lifecycle for time series data or time series metadata.

Data lifecycle

  1. Go to the Instance Management page.

    1. Log on to the Tablestore console.

    2. In the top navigation bar, select a resource group and a region.

    3. On the Overview page, click an instance name or click Manage Instance in the Actions column for that instance.

  2. On the Instance Details tab, click the Time Series Tables tab.

  3. On the Time Series Tables tab, click the name of the time series table.

  4. On the Basic Information tab, in the Description section, click the image.png icon next to Data Lifecycle.

  5. In the dialog box that appears, modify the data lifecycle value.

    The TTL is the data retention period in seconds. Set an integer value of 86400 (one day) or more, or -1. A value of -1 means the data never expires.

  6. Click Yes.

Metadata lifecycle

  1. Go to the Instance Management page.

    1. Log on to the Tablestore console.

    2. In the top navigation bar, select a resource group and a region.

    3. On the Overview page, click an instance name or click Manage Instance in the Actions column for that instance.

  2. On the Instance Details tab, click the Time Series Tables tab.

  3. On the Time Series Tables tab, click the name of the time series table.

  4. On the Basic Information tab, in the Description section, click the image.png icon next to TTL of Time Series Metadata.

  5. In the dialog box that appears, modify the data lifecycle value.

    The TTL is the metadata retention period in seconds. Set an integer value of 604800 (7 days) or more, or -1. A value of -1 means the metadata never expires.

  6. Click Yes.

CLI

You can use the CLI to modify the data lifecycle for a time series table.

Run the alter command to update the table information. For more information, see Update a table.

The following example shows how to change the data lifecycle of the current table to 86,400 seconds (1 day).

alter --ttl 86400 --ts

SDK

You can use an SDK to modify the data lifecycle for time series data or time series metadata.

Data lifecycle

The following sample code provides an example on how to change the TTL of the data in a time series table to three years.

private static void updateTimeseriesTable(TimeseriesClient client) {
    // Specify the name of the time series table. 
    String tableName = "<TIMESERIES_TABLE>";
    UpdateTimeseriesTableRequest updateTimeseriesTableRequest = new UpdateTimeseriesTableRequest(tableName);
    // Change the TTL to three years. 
    updateTimeseriesTableRequest.setTimeseriesTableOptions(new TimeseriesTableOptions(86400 * 365 * 3)); 
    client.updateTimeseriesTable(updateTimeseriesTableRequest);

    DescribeTimeseriesTableResponse describeTimeseriesTableResponse = client.describeTimeseriesTable(new DescribeTimeseriesTableRequest(tableName));
    TimeseriesTableMeta tableMeta = describeTimeseriesTableResponse.getTimeseriesTableMeta();
    // View the modified TTL. 
    System.out.println(tableMeta.getTimeseriesTableOptions().getTimeToLive()); 
}

Metadata lifecycle

The following example shows how to update the TTL for the time series metadata in a specified table to 3 years.

private static void updateTimeseriesMetaTableTTL(TimeseriesClient client) {
    // Specify the name of the time series table.
    String tableName = "<TIMESERIES_TABLE>";
    UpdateTimeseriesTableRequest updateTimeseriesTableRequest = new UpdateTimeseriesTableRequest(tableName);
    // Update the TTL to 3 years.
    TimeseriesMetaOptions options = new TimeseriesMetaOptions();
    options.setMetaTimeToLive(86400 * 365 * 3);
    updateTimeseriesTableRequest.setTimeseriesMetaOptions(options);
    client.updateTimeseriesTable(updateTimeseriesTableRequest);
}

FAQ

How do I delete time series data?

Related documents

The analytical store is a low-cost storage engine optimized for time series scenarios. You can use the analytical store to store time series data cost-effectively and perform fast queries and analysis.