Updated on 2023-11-21 GMT+08:00

Cold and Hot Data Separation

GeminiDB Influx allows you to separate cold and hot data based on the retention policy (RP). You can configure data retention duration and number of backups, and then the system automatically archives hot data that meets the conditions to cold storage.

Background

In big data scenarios, cold data and hot data is distinguished. Historical time-series data is less likely to be queried and analyzed as time goes by. In addition, the historical data will take up space that may increase storage costs. Therefore, it is necessary for enterprises to reduce cold data storage costs. GeminiDB Influx provides cold and hot data separation and uses low-cost media to store cold data. It can help you greatly reduce storage costs in just a few clicks.

Cold and hot data separation is based on the RP. You need to set a time boundary between cold and hot data in the RP, and the system will automatically archives cold data to cold storage. When you query data, the system will automatically retrieve it from hot or cold data storage based on the time range you specify.

Principles

You can configure the retention period of hot data. When data is written, it is stored in the hot storage first. GeminiDB Influx determines whether the data is hot or cold based on the data timestamp. If the data timestamp is within the hot data storage duration, the data is still hot. Otherwise, the hot data will be automatically archived in cold storage.

Figure 1 Diagram

Basic Usage

  1. Set the cold and hot time boundary.

    Specify WARM DURATION in the RP. Data generated before the value of WARM DURATION is cold data.

    To set WARM DURATION, perform the following steps:

    //Create an RP named myrp for database named mydb. The value of WARM DURATION is 6d, indicating that data generated six days ago is cold data.
    create retention policy myrp on mydb duration 30d replication 1 warm duration 6d shard duration 3d
    //Create an RP named myrp for database mydb. If WARM DURATION is not specified, no cold data exists.
    create retention policy myrp on mydb duration 30d replication 1 shard duration 3d
    //Create a database named mydb with an RP named myrp. The value of WARM DURATION is 3d, indicating that data generated three days ago is cold data.
    create database mydb with duration 6d warm duration 3d name myrp
    //Change the value of WARM DURATION to 7d, indicating that data generated seven days ago is cold data.
    alter retention policy myrp on mydb warm duration 7d
  2. Write data to the storage.

    Hot and cold data is written in the same way. Data is first stored in the hot storage when being written. As time goes by, if the timestamp of the data in the hot storage exceeds the value of WARM DURATION, the system automatically archives the data to the cold storage. This process is completely transparent to the user.

  3. Query data.

    The methods for querying hot and cold data are the same. During data query, the system automatically queries hot or cold storage based on the TimeRange condition in the query statement. This process is completely transparent to the user. The response to a cold data query is longer than that to a hot data query.

  4. Check the status of hot and cold data.
    > show shards
    name: _internal
    id database  retention_policy shard_group start_time           end_time             expiry_time          owners tier
    -- --------  ---------------- ----------- ----------           --------             -----------          ------ ----
    1  _internal monitor          1           2021-06-29T00:00:00Z 2021-06-30T00:00:00Z 2021-07-07T00:00:00Z 4      warm
    2  _internal monitor          1           2021-06-29T00:00:00Z 2021-06-30T00:00:00Z 2021-07-07T00:00:00Z 5      warm
    3  _internal monitor          1           2021-06-29T00:00:00Z 2021-06-30T00:00:00Z 2021-07-07T00:00:00Z 7      warm
    4  _internal monitor          1           2021-06-29T00:00:00Z 2021-06-30T00:00:00Z 2021-07-07T00:00:00Z 6      warm
    
    name: hsdb
    id database retention_policy shard_group start_time           end_time             expiry_time          owners tier
    -- -------- ---------------- ----------- ----------           --------             -----------          ------ ----
    5  hsdb     myrp             2           2019-08-12T00:00:00Z 2019-08-19T00:00:00Z 2019-08-19T00:00:00Z 4      cold
    6  hsdb     myrp             2           2019-08-12T00:00:00Z 2019-08-19T00:00:00Z 2019-08-19T00:00:00Z 5      moving
    7  hsdb     myrp             2           2019-08-12T00:00:00Z 2019-08-19T00:00:00Z 2019-08-19T00:00:00Z 6      warm
    8  hsdb     myrp             2           2019-08-12T00:00:00Z 2019-08-19T00:00:00Z 2019-08-19T00:00:00Z 7      cold
    • If the tier value is cold, the current shard stores cold data.
    • If the tier value is warm, the current shard store hot data.
    • If the tier value is moving, the current shard is being changed from hot data to cold data.
    • The process of changing hot data to cold data involves only the transfer of TSM files from hot storage to cold storage. Other files of the shard are still stored in hot storage and do not need to be moved.