From a89ac0225f5f4455f0ac2b2b12851d994d7175a3 Mon Sep 17 00:00:00 2001 From: Dennis Zhuang Date: Sat, 18 May 2024 12:05:28 +0800 Subject: [PATCH] feat: adds admin functions and doc to zh folder --- docs/nightly/en/reference/sql/functions.md | 1 - .../user-guide/operations/region-migration.md | 17 ++++++++++++++++ docs/nightly/zh/reference/sql/functions.md | 20 +++++++++++++++++++ .../user-guide/operations/region-migration.md | 16 +++++++++++++++ 4 files changed, 53 insertions(+), 1 deletion(-) diff --git a/docs/nightly/en/reference/sql/functions.md b/docs/nightly/en/reference/sql/functions.md index 3ede67b42..88500ba8f 100644 --- a/docs/nightly/en/reference/sql/functions.md +++ b/docs/nightly/en/reference/sql/functions.md @@ -58,7 +58,6 @@ select compact_table("test"); ``` - ## Time and Date ### `date_trunc` diff --git a/docs/nightly/en/user-guide/operations/region-migration.md b/docs/nightly/en/user-guide/operations/region-migration.md index 1a02d9f25..29a5c260f 100644 --- a/docs/nightly/en/user-guide/operations/region-migration.md +++ b/docs/nightly/en/user-guide/operations/region-migration.md @@ -60,3 +60,20 @@ select migrate_region(region_id, from_peer_id, to_peer_id, replay_timeout); | `from_peer_id` | The peer id of the migration source(Datanode). | **Required** | | | `to_peer_id` | The peer id of the migration destination(Datanode). | **Required** | | | `replay_timeout` | The timeout(secs) of replay data. If the new Region fails to replay the data within the specified timeout, the migration will fail, however the data in the old Region will not be lost. | Optional | | + +## Query the migration state + +The `migrate_region` function returns the procedure id that executes the migration, queries the procedure state by it: + +```sql +select procedure_state('538b7476-9f79-4e50-aa9c-b1de90710839') +``` + +If it's done, outputs the state in JSON: + +```json + {"status":"Done"} +``` + +Of course, you can confirm the region distribution by querying from `region_peers` and `partitions` in `information_schema`. + diff --git a/docs/nightly/zh/reference/sql/functions.md b/docs/nightly/zh/reference/sql/functions.md index 69961071b..f00dc54a4 100644 --- a/docs/nightly/zh/reference/sql/functions.md +++ b/docs/nightly/zh/reference/sql/functions.md @@ -36,6 +36,26 @@ arrow_cast(expression, datatype) 请参考 [API 文档](https://greptimedb.rs/script/python/rspython/builtins/greptime_builtin/index.html#functions) +### 管理函数 + +GreptimeDB 提供了一些管理函数来管理数据库和数据: + +* `flush_table(table_name)` 通过表名将表的内存表刷写到 SST 文件。 +* `flush_region(region_id)` 通过 Region Id 将 Region 的内存表刷写到 SST 文件。可以通过 [REGION_PEERS](./information-schema/region-peers.md) 表查找 Region Id。 +* `compact_table(table_name)` 通过表名为表发起compaction 任务。 +* `compact_region(region_id)` 通过 Region Id 为 Region 发起 compaction 任务。 +* `migrate_region(region_id, from_peer, to_peer, [timeout])` 在 Datanode 之间迁移 Region,请阅读 [ Region迁移](/user-guide/operations/region-migration)。 +* `procedure_state(procedure_id)` 通过 Procedure Id 查询 Procedure 状态。 + +例如: +```sql +-- 刷新表 test -- +select flush_table("test"); + +-- 为表 test 启动一个 compaction 任务 -- +select compact_table("test"); +``` + ## Time and Date ### `date_trunc` diff --git a/docs/nightly/zh/user-guide/operations/region-migration.md b/docs/nightly/zh/user-guide/operations/region-migration.md index 6f41ee8ca..63805df89 100644 --- a/docs/nightly/zh/user-guide/operations/region-migration.md +++ b/docs/nightly/zh/user-guide/operations/region-migration.md @@ -59,3 +59,19 @@ select migrate_region(region_id, from_peer_id, to_peer_id, replay_timeout); | `from_peer_id` | 迁移起始节点(Datanode) 的 peer id。 | **Required** | | | `to_peer_id` | 迁移目标节点(Datanode) 的 peer id。 | **Required** | | | `replay_timeout` | 迁移时回放数据的超时时间(单位:秒)。如果新 Region 未能在指定时间内回放数据,迁移将失败,旧 Region 中的数据不会丢失。 | Optional | | + +## 查询迁移状态 + +`migrate_region` 函数将返回执行迁移的 Procedure Id,可以通过它查询过程状态: + +```sql +select procedure_state('538b7476-9f79-4e50-aa9c-b1de90710839') +``` + +如果顺利完成,将输出 JSON 格式的状态: + +```json + {"status":"Done"} +``` + +当然,最终可以通过从 `information_schema` 中查询 `region_peers` 和 `partitions` 来确认 Region 分布是否符合预期。