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

ticdc: add event filter example (#16856) #17742

Merged
Merged
Changes from all commits
Commits
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
33 changes: 30 additions & 3 deletions ticdc/ticdc-ddl.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ rules = ['test.t*']
| `RENAME TABLE test.t1 TO test.t2` | 同步 | test.t1 符合 filter 规则 |
| `RENAME TABLE test.t1 TO ignore.t1` | 同步 | test.t1 符合 filter 规则 |
| `RENAME TABLE ignore.t1 TO ignore.t2` | 忽略 | ignore.t1 不符合 filter 规则 |
| `RENAME TABLE test.n1 TO test.t1` | 报错,并停止同步。 | test.n1 不符合 filter 规则,但是 test.t1 符合 filter 规则,这是非法操作。请参考错误提示信息进行处理 |
| `RENAME TABLE test.n1 TO test.t1` | 报错,并停止同步。 | 旧表名 test.n1 不符合 filter 规则,但是新表名 test.t1 符合 filter 规则,这是非法操作。请参考错误提示信息进行处理 |
| `RENAME TABLE ignore.t1 TO test.t1` | 报错,并停止同步。 | 理由同上 |

#### 一条 DDL 语句内 rename 多个表

如果一条 DDL 语句重命名多个表,则只有当旧的表库名和新的库名都符合过滤规则时,TiCDC 才会同步该 DDL 语句。此外,TiCDC 不支持同步对表名进行交换的 rename table DDL。下面使用具体示例进行说明。
如果一条 DDL 语句重命名多个表,则只有当**旧的表库名**和**新的库名**都符合过滤规则时,TiCDC 才会同步该 DDL 语句。此外,TiCDC 不支持同步对表名进行交换的 rename table DDL。下面使用具体示例进行说明。

假设你的 changefeed 的配置文件如下:

Expand Down Expand Up @@ -125,4 +125,31 @@ CREATE TABLE "t1" ("a" int PRIMARY KEY);

因为在 TiDB 的默认 SQL 模式下,双引号会被视为字符串而不是标志符,这将会导致 TiCDC 无法正确解析该 DDL 语句。

因此,在创建同步任务的时候,建议在配置文件中指定使用上游 TiDB 集群设置的 SQL 模式。
因此,在创建同步任务的时候,建议在配置文件中指定使用上游 TiDB 集群设置的 SQL 模式。

### 使用 Event Filter 过滤 DDL 事件的注意事项

如果被过滤的 DDL 语句涉及表的创建或删除,TiCDC 只会过滤掉这些 DDL 语句,而不影响 DML 的同步行为。下面使用具体示例进行说明。

假设你的 changefeed 的配置文件如下:

```toml
[filter]
rules = ['test.t*']

matcher = ["test.t1"] # 该过滤规则只应用于 test 库中的 t1 表
ignore-event = ["create table", "drop table", "truncate table"]
```

| DDL | DDL 行为 | DML 行为 | 原因 |
| --- | --- | --- | --- |
| `CREATE TABLE test.t1 (id INT, name VARCHAR(50));` | 忽略 | 同步 | `test.t1` 符合 Event Filter 过滤规则,`CREATE TABLE` 事件被忽略,但不影响 DML 事件的同步 |
| `CREATE TABLE test.t2 (id INT, name VARCHAR(50));` | 同步 | 同步 | `test.t2` 不符合 Event Filter 过滤规则 |
| `CREATE TABLE test.ignore (id INT, name VARCHAR(50));` | 忽略 | 忽略 | `test.ignore` 符合 Table Filter 过滤规则,因此 DDL 和 DML 事件均被忽略 |
| `DROP TABLE test.t1;` | 忽略 | - | `test.t1` 符合 Event Filter,`DROP TABLE` 事件被忽略。该表已被删除,TiCDC 不再同步 t1 的 DML 事件 |
| `TRUNCATE TABLE test.t1;` | 忽略 | 同步 | `test.t1` 符合 Event Filter,`TRUNCATE TABLE` 事件被忽略,但不影响 DML 事件的同步 |

> **注意:**
>
> - 当同步数据到数据库时,应谨慎使用 Event Filter 过滤 DDL 事件,同步过程中需确保上下游的库表结构始终一致。否则,TiCDC 可能会报错或产生未定义的同步行为。
> - 在 v6.5.8、v7.1.4、v7.5.1 之前的版本中,使用 Event Filter 过滤涉及创建或删除表的 DDL 事件,会影响 DML 的同步,不推荐使用该功能。
Loading