|
21 | 21 |
|
22 | 22 | # TTL |
23 | 23 |
|
24 | | -IoTDB supports storage-level TTL settings, which means it is able to delete old data automatically and periodically. The benefit of using TTL is that hopefully you can control the total disk space usage and prevent the machine from running out of disks. Moreover, the query performance may downgrade as the total number of files goes up and the memory usage also increase as there are more files. Timely removing such files helps to keep at a high query performance level and reduce memory usage. |
| 24 | +IoTDB supports device-level TTL settings, which means it is able to delete old data automatically and periodically. The benefit of using TTL is that hopefully you can control the total disk space usage and prevent the machine from running out of disks. Moreover, the query performance may downgrade as the total number of files goes up and the memory usage also increases as there are more files. Timely removing such files helps to keep at a high query performance level and reduce memory usage. |
25 | 25 |
|
26 | 26 | The default unit of TTL is milliseconds. If the time precision in the configuration file changes to another, the TTL is still set to milliseconds. |
27 | 27 |
|
28 | | -## Set TTL |
29 | | - |
30 | | -The SQL Statement for setting TTL is as follow: |
31 | | - |
32 | | -``` |
33 | | -IoTDB> set ttl to root.ln 3600000 |
34 | | -``` |
35 | | - |
36 | | -This example means that for data in `root.ln`, only 3600000 ms, that is, the latest 1 hour will remain, the older one is removed or made invisible. |
| 28 | +When setting TTL, the system will look for all devices included in the set path and set TTL for these devices. The system will delete expired data at the device granularity. |
| 29 | +After the device data expires, it will not be queryable. The data in the disk file cannot be guaranteed to be deleted immediately, but it can be guaranteed to be deleted eventually. |
| 30 | +However, due to operational costs, the expired data will not be physically deleted right after expiring. The physical deletion is delayed until compaction. |
| 31 | +Therefore, before the data is physically deleted, if the TTL is reduced or lifted, it may cause data that was previously invisible due to TTL to reappear. |
| 32 | +The system can only set up to 1000 TTL rules, and when this limit is reached, some TTL rules need to be deleted before new rules can be set. |
37 | 33 |
|
| 34 | +## TTL Path Rule |
| 35 | +The path can only be prefix paths (i.e., the path cannot contain \* , except \*\* in the last level). |
| 36 | +This path will match devices and also allows users to specify paths without asterisks as specific databases or devices. |
| 37 | +When the path does not contain asterisks, the system will check if it matches a database; if it matches a database, both the path and path.\*\* will be set at the same time. Note: Device TTL settings do not verify the existence of metadata, i.e., it is allowed to set TTL for a non-existent device. |
38 | 38 | ``` |
39 | | -IoTDB> set ttl to root.sgcc.** 3600000 |
| 39 | +qualified paths: |
| 40 | +root.** |
| 41 | +root.db.** |
| 42 | +root.db.group1.** |
| 43 | +root.db |
| 44 | +root.db.group1.d1 |
| 45 | +
|
| 46 | +unqualified paths: |
| 47 | +root.*.db |
| 48 | +root.**.db.* |
| 49 | +root.db.* |
40 | 50 | ``` |
41 | | -It supports setting TTL for databases in a path. This example represents setting TTL for all databases in the `root.sgcc` path. |
| 51 | +## TTL Applicable Rules |
| 52 | +When a device is subject to multiple TTL rules, the more precise and longer rules are prioritized. For example, for the device "root.bj.hd.dist001.turbine001", the rule "root.bj.hd.dist001.turbine001" takes precedence over "root.bj.hd.dist001.\*\*", and the rule "root.bj.hd.dist001.\*\*" takes precedence over "root.bj.hd.**". |
| 53 | +## Set TTL |
| 54 | +The set ttl operation can be understood as setting a TTL rule, for example, setting ttl to root.sg.group1.** is equivalent to mounting ttl for all devices that can match this path pattern. |
| 55 | +The unset ttl operation indicates unmounting TTL for the corresponding path pattern; if there is no corresponding TTL, nothing will be done. |
| 56 | +If you want to set TTL to be infinitely large, you can use the INF keyword. |
| 57 | +The SQL Statement for setting TTL is as follow: |
42 | 58 | ``` |
43 | | -IoTDB> set ttl to root.** 3600000 |
| 59 | +set ttl to pathPattern 360000; |
44 | 60 | ``` |
45 | | -This example represents setting TTL for all databases. |
46 | | - |
| 61 | +Set the Time to Live (TTL) to a pathPattern of 360,000 milliseconds; the pathPattern should not contain a wildcard (\*) in the middle and must end with a double asterisk (\*\*). The pathPattern is used to match corresponding devices. |
| 62 | +To maintain compatibility with older SQL syntax, if the user-provided pathPattern matches a database (db), the path pattern is automatically expanded to include all sub-paths denoted by path.\*\*. |
| 63 | +For instance, writing "set ttl to root.sg 360000" will automatically be transformed into "set ttl to root.sg.\*\* 360000", which sets the TTL for all devices under root.sg. However, if the specified pathPattern does not match a database, the aforementioned logic will not apply. For example, writing "set ttl to root.sg.group 360000" will not be expanded to "root.sg.group.\*\*" since root.sg.group does not match a database. |
| 64 | +It is also permissible to specify a particular device without a wildcard (*). |
47 | 65 | ## Unset TTL |
48 | 66 |
|
49 | 67 | To unset TTL, we can use follwing SQL statement: |
@@ -87,4 +105,15 @@ IoTDB> show all ttl |
87 | 105 | |root.sgcc| null| |
88 | 106 | | root.DB|3600000| |
89 | 107 | +----------+-------+ |
90 | | -``` |
| 108 | +``` |
| 109 | +Display devices' ttl |
| 110 | +``` |
| 111 | +IoTDB> show devices |
| 112 | ++---------------+---------+---------+ |
| 113 | +| Device|IsAligned| TTL| |
| 114 | ++---------------+---------+---------+ |
| 115 | +|root.sg.device1| false| 36000000| |
| 116 | +|root.sg.device2| true| INF| |
| 117 | ++---------------+---------+---------+ |
| 118 | +``` |
| 119 | +All devices will definitely have a TTL, meaning it cannot be null. INF represents infinity. |
0 commit comments