Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[doc] TTL cn #1934

Merged
merged 39 commits into from
Mar 17, 2020
Merged
Changes from 32 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
4ea645e
Fix lambda captured by reference (#1681)
critical27 Jan 20, 2020
32eabfd
Merge branch 'master' of https://github.com/jude-zhu/nebula
jude-zhu Jan 21, 2020
5e802ac
Merge branch 'master' of https://github.com/jude-zhu/nebula
jude-zhu Feb 10, 2020
658a48e
Merge branch 'master' of https://github.com/jude-zhu/nebula
jude-zhu Feb 12, 2020
29bfbb2
Merge branch 'master' of https://github.com/jude-zhu/nebula
jude-zhu Feb 18, 2020
daa23e0
Merge branch 'master' of https://github.com/jude-zhu/nebula
jude-zhu Feb 26, 2020
fa83f27
Fix meta would crash when balance in multiple relica (#1826)
critical27 Feb 26, 2020
0f0b19c
support charset in schema (#1709)
panda-sheep Feb 26, 2020
f6407b2
Lookup benchmark (#1738)
bright-starry-sky Feb 26, 2020
3e6bd57
update readme link (#1815)
amber-moe Feb 26, 2020
453bf8f
update (#1809)
amber-moe Feb 26, 2020
ee97825
[doc] prerequisite added in quick start (#1808)
wilsonyou Feb 26, 2020
bd511e2
fix metrics-exposer comments and comment out (#1797)
amber-moe Feb 26, 2020
f3fa0a0
[doc]configure TTL (#1791)
amber-moe Feb 26, 2020
14f80c0
[doc]add lookup and update toc (#1778)
amber-moe Feb 26, 2020
53f6a32
Added sanitizer option for compile scripts. (#1819)
monadbobo Feb 26, 2020
ace9ab2
[doc] Group By statement updated (#1835)
wilsonyou Feb 27, 2020
ca6a864
Bidirectional traverse. (#1740)
CPWstatic Feb 28, 2020
e41d870
add charset doc (#1750)
amber-moe Feb 28, 2020
7d0568d
[doc]modify block cache (#1829)
amber-moe Feb 28, 2020
30f8a9e
default value supports expression (#1838)
amber-moe Feb 28, 2020
237dfb5
Fixed an error when using update sentence. (#1830)
monadbobo Mar 2, 2020
8a09218
[doc]add bidirect (#1752)
amber-moe Mar 2, 2020
d187735
Support delete vertices (#1317)
Mar 3, 2020
617ec4b
Check if inputs has duplicate column. (#1841)
CPWstatic Mar 3, 2020
2e9599e
support return partial result in get of kv interfaces (#1840)
critical27 Mar 3, 2020
8ecdcb3
Merge branch 'master' of https://github.com/vesoft-inc/nebula
jude-zhu Mar 4, 2020
9bb7a9d
Merge branch 'master' of https://github.com/jude-zhu/nebula
jude-zhu Mar 5, 2020
7c122ef
Merge branch 'master' of https://github.com/jude-zhu/nebula
jude-zhu Mar 17, 2020
2f79987
update ttl cn
jude-zhu Mar 17, 2020
cf91474
udpate
jude-zhu Mar 17, 2020
876b5e1
update
jude-zhu Mar 17, 2020
0dc0172
udpate
jude-zhu Mar 17, 2020
00456c8
update
jude-zhu Mar 17, 2020
1470953
update
jude-zhu Mar 17, 2020
9a809af
udpate
jude-zhu Mar 17, 2020
a413ff3
update
jude-zhu Mar 17, 2020
ae02f82
update
jude-zhu Mar 17, 2020
3fb4af7
Merge branch 'master' into ttl
dangleptr Mar 17, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,79 +1,111 @@
# TTL (time-to-live)

借助 **TTL**,**Nebula Graph** 支持当数据过期后,在查询顶点和边时,会自动过滤掉过期的数据,过期的数据在 compaction 阶段会自动删除,不需要客户显式发出的 delete 操作
Nebula 支持 **TTL** ,在一定时间后或在特定时钟时间自动从数据库中删除点或者边。过期数据会在下次 compaction 时被删除,在下次 compaction 来临前,query 会过滤掉过期的点和边

`ttl_col` 用来指出 TTL 列,`ttl_duration` 用来指出 TTL 的持续时间,某一条数据的 TTL 列值加上 ttl_duration 值小于当前时间,则认为该条数据过期。`ttl_col` 列类型为 integer 或者 timestamp,单位为秒, `ttl_duration` 单位也是秒
ttl 功能需要 `ttl_col` `ttl_duration` 一起使用。自从 `ttl_col` 指定的字段的值起,经过 `ttl_duration` 指定的秒数后,该条数据过期。即,到期阈值是 `ttl_col`指定的 property 的值加上 `ttl_duration` 设置的秒数。其中 `ttl_col` 指定的字段的类型需为 integer 或者 timestamp

## TTL 配置

TTL 值以秒为单位设置的
- `ttl_duration` 单位为秒,当 `ttl_duration` 被设置为 -1 或者 0,则点的此 tag 属性不会过期

- 如果设置 TTL,当某一行的 `ttl_col` 列值加上 `ttl_duration` 值小于当前时间时,则认为该条数据过期
- `ttl_col` 指定的字段的值加上 `ttl_duration` 值小于当前时间时,该条数据过期

- 如果未设置 TTL 或 `ttl_col` 为空,则 TTL 不起作用
- 当该条数据有多个 tag,每个 tag 的 ttl 单独处理

- 如果 TTL 设置为 -1 或者 0,则此字段数据不会过期。

## 设置 TTL

设置 TTL 可用来指定数据的存活时间。

先创建 tag,然后增加 TTL 属性。
* 对已经创建的 tag,设置 TTL。

```ngql
nebula> CREATE TAG t(a int, b int, c string);
nebula> ALTER TAG t ADD ttl_col = "a", ttl_duration = 1000; -- add ttl attribute
nebula> CREATE TAG t(a timestamp, b int, c string);
nebula> ALTER TAG t ttl_col = "a", ttl_duration = 100; -- 创建 ttl
nebula> SHOW CREATE TAG t;
```
点的 TAG t 属性会在 `a` 字段的值,经过 100s 后过期。

* 在创建 tag 时设置 TTL。

```ngql
nebula> CREATE TAG t(a timestamp, b int, c string) ttl_duration= 100, ttl_col = "a";
```

或亦可在创建 tag 时设置 TTL 属性。
```ngql
nebula> CREATE TAG t1(a timestamp) ttl_duration= 5, ttl_col = "a";
nebula> CREATE TAG t2(a timestamp) ttl_duration= 10, ttl_col = "a"
nebula> INSERT VERTEX t1(a),t2(a) values 100:(now(), now()+15)
```
从 now() 起,5s 后,点 100 的 t1 属性值过期,20s 后,t2 属性值过期。

当点有多个 tag 时

```ngql
nebula> CREATE TAG t(a int, b int, c string) ttl_duration= 100, ttl_col = "a";
nebula> CREATE TAG t3(a string)
nebula> INSERT VERTEX t1(a),t3(a) values 200:(now(), "hello")
```

5s 后, 点 Vertex 200 的 t1 属性过期。

```ngql
nebula> fetch prop on t1 200
Execution succeeded (Time spent: 5.945/7.492 ms)


nebula> fetch prop on t3 200
======================
| VertexID | t3.name |
======================
| 200 | hello |
----------------------
```


## 删除 TTL

如果为字段设置了 TTL 值,但又不希望数据自动过期,则可以删除该 TTL 属性,或者让 TTL 属性失效。例如,接着前面的示例
如果想要删除 TTL,可以 设置 `ttl_col` 字段为空,或删除配置的 `ttl_col` 字段,或者设置 `ttl_duration` 为 0 或者 -1

删除 TTL 属性:

```ngql
nebula> ALTER TAG t ttl_col = ""; -- drop ttl attribute
```

删除含有 TTL 属性的列
删除配置的 `ttl_col` 字段

```ngql
nebula> ALTER TAG t DROP a; -- drop field a with the ttl attribute
```

让 TTL 属性失效
设置 ttl_duration 为 0 或者 -1

```ngql
nebula> ALTER TAG t ttl_duration = 0; -- keep the ttl but the data never expires
```

## TTL 使用注意事项

- 如果字段包含 TTL,则不支持对该字段的更改操作
- 不能修改 `ttl_col` 所配置的字段

``` ngql
nebula> ALTER TAG t ADD ttl_col = "b", ttl_duration = 1000;
nebula> ALTER TAG t ttl_col = "b", ttl_duration = 1000;
nebula> ALTER TAG t CHANGE (b string); -- failed
```

- 注意一个 tag 或 edge 不能同时拥有 TTL 和索引,只能二者择其一。
- 注意一个 tag 或 edge 不能同时拥有 TTL 和索引,只能二者择其一,即使 `ttl_col` 配置的字段与要创建索引的字段不同

``` ngql
nebula> CREATE TAG t(a int, b int, c string) ttl_duration = 100, ttl_col = "a";
nebula> CREATE TAG INDEX id1 ON t(a); -- failed
```

``` ngql
nebula> CREATE TAG t(a int, b int, c string) ttl_duration = 100, ttl_col = "a";
nebula> CREATE TAG INDEX id1 ON t(b); -- failed
```

```ngql
nebula> CREATE TAG t1(a int, b int, c string);
nebula> CREATE TAG INDEX id1 ON t1(a);
nebula> ALTER TAG t1 ADD ttl_col = "a", ttl_duration = 100; -- failed
nebula> ALTER TAG t1 ttl_col = "a", ttl_duration = 100; -- failed
```

- edge 添加 TTL 与 tag 类似。
- edge 配置 TTL 与 tag 类似。