-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tidb: add document for external timestamp read
Signed-off-by: YangKeao <yangkeao@chunibyo.icu>
- Loading branch information
Showing
4 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
--- | ||
title: 通过系统变量 `tidb_external_ts` 读取历史数据 | ||
summary: 了解如何通过系统变量 `tidb_external_ts` 读取历史数据。 | ||
--- | ||
|
||
# 通过系统变量 `tidb_external_ts` 读取历史数据 | ||
|
||
为了支持出读取历史版本数据,TiDB 从 6.4 版本起引入了一个新的系统变量 `tidb_external_ts`。本文档介绍如何通过该系统变量读取历史数据,其中包括具体的操作流程。 | ||
|
||
|
||
## 场景介绍 | ||
|
||
通过配置让 TiDB 能够读取某一固定时间点的历史数据对于 TiCDC 等数据同步工具非常有用。在数据同步工具完成了某一时间点前的数据同步之后,可以通过设置下游 TiDB 的 `tidb_external_ts` 系统变量,使得下游 TiDB 的请求能够读取到该时间点前的数据。这将避免在同步过程中,下游 TiDB 读取到尚未完全同步而不一致的数据。 | ||
|
||
## 示例 | ||
|
||
系统变量 `tidb_external_ts` 用于指定该功能启用时,读取历史数据使用的时间戳。 | ||
|
||
系统变量 `tidb_enable_external_ts_read` 控制着是否在当前会话或全局启用该功能。默认值为 `OFF`,这意味着该功能关闭,并且 `tidb_external_ts` 没有作用。当该变量被全局地设置为 `ON`,所有的请求都将读取到 `tidb_external_ts` 指定时间之前的历史数据。如果 `tidb_enable_external_ts_read` 仅在某一会话被设置为 `ON`,则只有该会话中的请求会读取到历史数据。 | ||
|
||
以下是一个使用该功能的示例: | ||
|
||
```sql | ||
create table t (c int); | ||
``` | ||
|
||
``` | ||
Query OK, 0 rows affected (0.01 sec) | ||
``` | ||
|
||
```sql | ||
insert into t values (1), (2), (3); | ||
``` | ||
|
||
``` | ||
Query OK, 3 rows affected (0.00 sec) | ||
``` | ||
|
||
查看表中的数据: | ||
|
||
```sql | ||
select * from t; | ||
``` | ||
|
||
``` | ||
+------+ | ||
| c | | ||
+------+ | ||
| 1 | | ||
| 2 | | ||
| 3 | | ||
+------+ | ||
3 rows in set (0.00 sec) | ||
``` | ||
|
||
将 `tidb_external_ts` 设置为 `@@tidb_current_ts`: | ||
|
||
```sql | ||
start transaction;set global tidb_external_ts=@@tidb_current_ts;commit; | ||
``` | ||
|
||
插入新的一行: | ||
|
||
```sql | ||
insert into t values (4); | ||
``` | ||
|
||
``` | ||
Query OK, 1 row affected (0.001 sec) | ||
``` | ||
|
||
确认新的一行已经被插入: | ||
|
||
```sql | ||
select * from t; | ||
``` | ||
|
||
``` | ||
+------+ | ||
| id | | ||
+------+ | ||
| 1 | | ||
| 2 | | ||
| 3 | | ||
| 4 | | ||
+------+ | ||
4 rows in set (0.00 sec) | ||
``` | ||
|
||
然而,因为 `tidb_external_ts` 被设置为插入这一行之前的时间,在将 `tidb_enable_external_ts_read` 启动后,将读取不到新插入的行: | ||
|
||
```sql | ||
set tidb_enable_external_ts_read=ON; | ||
select * from t; | ||
``` | ||
|
||
``` | ||
+------+ | ||
| c | | ||
+------+ | ||
| 1 | | ||
| 2 | | ||
| 3 | | ||
+------+ | ||
3 rows in set (0.00 sec) | ||
``` |