Skip to content

Commit 034382c

Browse files
authored
Merge d8320af into 8999d1e
2 parents 8999d1e + d8320af commit 034382c

File tree

4 files changed

+116
-10
lines changed

4 files changed

+116
-10
lines changed

ydb/docs/en/core/concepts/_includes/ttl.md

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,21 @@ This section describes how the TTL mechanism works and what its limits are. It a
44

55
## How it works {#how-it-works}
66

7-
{{ ydb-short-name }} allows you to specify a TTL column in both [row-oriented](../datamodel/table.md#row-oriented-tables) and [column-oriented](../datamodel/table.md#column-oriented-tables) tables. Values in TTL columns determine the table rows lifetime.
7+
The table's TTL is a sequence of storage tiers. Each tier contains an expression (TTL expression) and an action. When the expression triggers, that tier is assigned to the row. When a tier is assigned to a row, the specified action is automatically performed: moving the row to an external storage or deleting it. External storage is represented by the [external data source](https://ydb.tech/docs/en/concepts/datamodel/external_data_source) object. Deleting action can only be specified for the last tier.
8+
9+
{% note info %}
10+
11+
Currently, only an Object Storage is available as external storage.
12+
13+
{% endnote %}
14+
15+
{{ ydb-short-name }} allows you to specify a column (TTL column) whose values are used in TTL expressions. The expression triggers when the specified number of seconds have passed since the time recorded in the TTL column.
16+
17+
{% note info %}
18+
19+
Automatic data eviction to external storage is available only for column-oriented tables. For row-oriented tables, this functionality is under development.
20+
21+
{% endnote %}
822

923
{% note warning %}
1024

@@ -15,12 +29,12 @@ An item with the `NULL` value in the TTL column is never deleted.
1529
The timestamp for deleting a table item is determined by the formula:
1630

1731
```text
18-
expiration_time = valueof(ttl_column) + expire_after_seconds
32+
eviction_time = valueof(ttl_column) + evict_after_seconds
1933
```
2034

2135
{% note info %}
2236

23-
TTL doesn't guarantee that the item will be deleted exactly at `expiration_time`, it might happen later. If it's important to exclude logically obsolete but not yet physically deleted items from the selection, use query-level filtering.
37+
TTL doesn't guarantee that the item will be deleted exactly at `eviction_time`, it might happen later. If it's important to exclude logically obsolete but not yet physically deleted items from the selection, use query-level filtering.
2438

2539
{% endnote %}
2640

@@ -176,6 +190,45 @@ The example below shows how to use the `modified_at` column with a numeric type
176190

177191
{% endlist %}
178192

193+
### Enabling eviction to Object Storage for an existing table {#enable-tiering-on-existing-tables}
194+
195+
{% note info %}
196+
197+
This functionality is only available for column-oriented tables. For row-oriented tables, this functionality is under development.
198+
199+
{% endnote %}
200+
201+
In the following example, rows of the table `mytable` will be moved to the bucket described in the external data source `/Root/s3_cold_data` one hour after the time recorded in the column `created_at`, and will be deleted after 24 hours:
202+
203+
{% list tabs group=tool %}
204+
205+
- YQL
206+
207+
```yql
208+
ALTER TABLE `mytable` SET (TTL = Interval("PT1H") TO EXTERNAL DATA SOURCE `/Root/s3_cold_data`, Interval(PT24H) DELETE ON modified_at AS SECONDS);
209+
```
210+
211+
{% if oss == true %}
212+
213+
- C++
214+
215+
```c++
216+
session.AlterTable(
217+
"mytable",
218+
TAlterTableSettings()
219+
.BeginAlterTtlSettings()
220+
.Set("created_at", {
221+
TTtlTierSettings(TDuration::Hours(1), TTtlEvictToExternalStorageAction("/Root/s3_cold_data")),
222+
TTtlTierSettings(TDuration::Hours(24), TTtlDeleteAction("/Root/s3_cold_data"))
223+
})
224+
.EndAlterTtlSettings()
225+
);
226+
```
227+
228+
{% endif %}
229+
230+
{% endlist %}
231+
179232
### Enabling TTL for a newly created table {#enable-for-new-table}
180233
181234
For a newly created table, you can pass TTL settings along with the table description:

ydb/docs/en/core/concepts/datamodel/_includes/table.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ If there are multiple followers, their delay from the leader may vary: although
134134

135135
| Parameter name | Type | Acceptable values | Update capability | Reset capability |
136136
| ------------- | --- | ------------------- | --------------------- | ------------------ |
137-
| `TTL` | Expression | `Interval("<literal>") ON <column> [AS <unit>]` | Yes | Yes |
137+
| `TTL` | Expression | `<tier>, ..., <tier> ON <column> [AS <unit>]`, где `<tier>``Inteval("<literal>") TO EXTERNAL DATA SOURCE <path_to_source>` или `Inteval("<literal>") TO DELETE`. Краткая форма: `Interval("<literal>") ON <column> [AS <unit>]` — задаёт удаление данных | Да | Да |
138138

139139
Where `<unit>` is a unit of measurement, specified only for column with a [numeric type](../../../concepts/ttl.md#restrictions):
140140

ydb/docs/ru/core/concepts/_includes/ttl.md

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,37 @@
44

55
## Принцип работы {#how-it-works}
66

7-
{{ ydb-short-name }} позволяет указать для строковых и колоночных таблиц колонку (TTL-колонка), значения которой будут использоваться для определения времени жизни строк. TTL автоматически удаляет из таблицы строки, когда проходит указанное количество секунд от времени, записанного в TTL-колонку.
7+
TTL таблицы задаётся последовательностью тиров хранения. Для каждого тира задаётся выражение, при срабатывании которого строке присваивается данный тир. Когда строке будет присвоен тир, TTL автоматически выполнит заданное действие: перенесёт строку во внешнее хранилище или удалит её. Внешние хранилища представляются объектом [external data source](https://ydb.tech/docs/ru/concepts/datamodel/external_data_source). Удаление может быть задано только для последнего тира.
8+
9+
{% note info %}
10+
11+
На данный момент, в качестве внешнего хранилища доступен только Object Storage.
12+
13+
{% endnote %}
14+
15+
{{ ydb-short-name }} позволяет указать для строковых и колоночных таблиц колонку (TTL-колонка), значения которой будут использоваться в TTL-выражениях. Выражение срабатывает, когда проходит указанное количество секунд от времени, записанного в TTL-колонку.
16+
17+
{% note info %}
18+
19+
Автоматическое перемещение данных во внешние хранилища доступно только для колоночных таблиц. Для строчных таблиц функциональность находится в разработке.
20+
21+
{% endnote %}
822

923
{% note warning %}
1024

11-
Строка с `NULL` в TTL-колонке никогда не будет удалена.
25+
Строка с `NULL` в TTL-колонке никогда не сменит тир хранения.
1226

1327
{% endnote %}
1428

15-
Момент времени, когда строка таблицы может быть удалена, определяется по следующей формуле:
29+
Момент времени, когда срабатывает TTL-выражение, определяется по следующей формуле:
1630

1731
```text
18-
expiration_time = valueof(ttl_column) + expire_after_seconds
32+
eviction_time = valueof(ttl_column) + evict_after_seconds
1933
```
2034

2135
{% note info %}
2236

23-
Не гарантируется, что удаление произойдет именно в `expiration_time` — оно может случиться позже. Если важно исключить из выборки логически устаревшие, но пока еще физически не удаленные строки, нужно использовать фильтрацию уровня запроса.
37+
Не гарантируется, что удаление произойдет именно в `eviction_time` — оно может случиться позже. Если важно исключить из выборки логически устаревшие, но пока еще физически не удаленные строки, нужно использовать фильтрацию уровня запроса.
2438

2539
{% endnote %}
2640

@@ -176,6 +190,45 @@ expiration_time = valueof(ttl_column) + expire_after_seconds
176190

177191
{% endlist %}
178192

193+
### Включение вытеснения в Object Storage для существующих таблиц {#enable-tiering-on-existing-tables}
194+
195+
{% note info %}
196+
197+
Данная функциональность доступна только для колоночных таблиц. Для строчных таблиц функциональность находится в разработке.
198+
199+
{% endnote %}
200+
201+
В следующем примере строки таблицы `mytable` будут переноситься в бакет, описанный во внешнем источнике данных `/Root/s3_cold_data`, спустя час после наступления времени, записанного в колонке `created_at`, а спустя 24 часа будут удаляться:
202+
203+
{% list tabs group=tool %}
204+
205+
- YQL
206+
207+
```yql
208+
ALTER TABLE `mytable` SET (TTL = Interval("PT1H") TO EXTERNAL DATA SOURCE `/Root/s3_cold_data`, Interval(PT24H) DELETE ON modified_at AS SECONDS);
209+
```
210+
211+
{% if oss == true %}
212+
213+
- C++
214+
215+
```c++
216+
session.AlterTable(
217+
"mytable",
218+
TAlterTableSettings()
219+
.BeginAlterTtlSettings()
220+
.Set("created_at", {
221+
TTtlTierSettings(TDuration::Hours(1), TTtlEvictToExternalStorageAction("/Root/s3_cold_data")),
222+
TTtlTierSettings(TDuration::Hours(24), TTtlDeleteAction("/Root/s3_cold_data"))
223+
})
224+
.EndAlterTtlSettings()
225+
);
226+
```
227+
228+
{% endif %}
229+
230+
{% endlist %}
231+
179232
### Включение TTL для вновь создаваемой таблицы {#enable-for-new-table}
180233
181234
Для вновь создаваемой таблицы можно передать настройки TTL вместе с ее описанием:

ydb/docs/ru/core/concepts/datamodel/_includes/table.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ CREATE TABLE article (
135135

136136
| Имя параметра | Тип | Допустимые значения | Возможность<br/>изменения | Возможность<br/>сброса |
137137
| ------------- | --- | ------------------- | --------------------- | ------------------ |
138-
| `TTL` | Expression | `Interval("<literal>") ON <column> [AS <unit>]` | Да | Да |
138+
| `TTL` | Expression | `<tier>, ..., <tier> ON <column> [AS <unit>]`, где `<tier>``Inteval("<literal>") TO EXTERNAL DATA SOURCE <path_to_source>` или `Inteval("<literal>") TO DELETE`. Краткая форма: `Interval("<literal>") ON <column> [AS <unit>]` — задаёт удаление данных | Да | Да |
139139

140140
Где `<unit>` — единица измерения, указывается только для колонок с [числовым типом](../../../concepts/ttl.md#restrictions):
141141

0 commit comments

Comments
 (0)