Skip to content

feat(tmq): optimize the logic of changing tablelist for stb sub#35133

Merged
guanshengliang merged 10 commits into3.0from
feat/6935517365
Apr 17, 2026
Merged

feat(tmq): optimize the logic of changing tablelist for stb sub#35133
guanshengliang merged 10 commits into3.0from
feat/6935517365

Conversation

@wangmm0220
Copy link
Copy Markdown
Contributor

@wangmm0220 wangmm0220 commented Apr 14, 2026

Description

Issue(s)

Checklist

Please check the items in the checklist if applicable.

  • Is the user manual updated?
  • Are the test cases passed and automated?
  • Is there no significant decrease in test coverage?

- Refactor tq module: merge tqRead.c/tqSink.c into tqScan.c and new tqInterface.c
- Rename Tmq functions to QuerySub/StbSub naming convention
- Add dynamic table list change support for super table subscription
- Handle table-not-exist scenarios gracefully in meta queries
- Remove deprecated TDMT_VND_TMQ_SEEK message and pFilterOutTbUid mechanism
- Add metaGetTbnameByIdIfTableNotExist and getIdInner for fallback lookups
feat(tmq): update table list wher alter tag & split big files in tmq
- Fix double mutex unlock in tmqMgmtClose (C1)
- Fix use-after-free in tqProcessAlterTbMsg log after destroyAlterTbReq (C2)
- Fix null pointer check: TQ_NULL_GO_TO_END(pBuf) -> TQ_NULL_GO_TO_END(*pBuf) (C3)
- Add buffer overflow checks in WAL body rewriting (H2)
- Eliminate duplicate tqGetUidSuid calls in tqAlterMultiTag using SAlterTagUidCache (M2)
- Improve naming: getSchemaInner -> getSchemaWithVer, metaGetSuidByUid -> metaGetSuidByUidIfTableNotExist
- Add missing newline at end of tqInterface.c
Copilot AI review requested due to automatic review settings April 14, 2026 06:37
@wangmm0220 wangmm0220 requested review from a team, dapan1121 and guanshengliang as code owners April 14, 2026 06:37
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors and optimizes TMQ “query subscription” table-list update/tag-filtering logic (notably for STB subscriptions), including version-aware tag retrieval, plus related test/CI adjustments.

Changes:

  • Refactor executor/vnode/tq APIs from TMQ-scanner naming to “QuerySub” and add version plumbing for tag-based filtering.
  • Add schema/type-mod persistence support via schema_ext.db and make tag-fetch APIs version-aware.
  • Enable/extend TMQ taosx/alter-tag/update-tablelist test coverage and wire tqInterface.c into vnode build.

Reviewed changes

Copilot reviewed 51 out of 52 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
utils/test/c/tmq_ts7402.c Updates expected TMQ meta JSON for TS-7402 test.
test/ci/cases.task Enables test_tmq_taosx.py in CI task list.
test/cases/17-DataSubscription/02-Consume/test_tmq_update_tablelist.py Adjusts tablelist-update subscription test flow and cleanup behavior.
test/cases/17-DataSubscription/02-Consume/test_tmq_taosx.py Expands taosx TMQ validation (stb/db sub) and checks command execution results.
test/cases/17-DataSubscription/02-Consume/test_tmq_bugs.py Adds debugflag setup for TS-7402 bug reproduction.
test/cases/17-DataSubscription/02-Consume/test_tmq_batch_alter_tag.py Updates expected meta JSON for batch alter-tag case; modifies verification.
source/libs/executor/src/executor.c Renames/update QuerySub tablelist APIs; threads version into tag filtering.
source/libs/executor/src/executil.c + inc/executil.h Adds version to doFilterByTagCond; switches to version-aware tag fetch API.
include/libs/executor/storageapi.h + vnodeApi.c Renames meta API hook to getTableTagsByUidVersion.
source/dnode/vnode/src/meta/* + inc/meta.h + inc/vnodeInt.h Adds schema_ext.db, exposes schemasHasTypeMod, makes schema/tag retrieval version/ignore-exist aware.
source/dnode/vnode/src/tq/* + inc/tq.h Refactors tq interfaces (moves logic into tqInterface.c, removes seek path, renames handle encode/decode/destroy).
source/client/src/* + source/client/inc/clientTmq.h Splits TMQ client code into dedicated commit/conf/offset modules.
source/dnode/vnode/CMakeLists.txt Removes tqSink/tqRead sources and adds tqInterface.c.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/cases/17-DataSubscription/02-Consume/test_tmq_bugs.py
Comment thread source/dnode/vnode/src/vnd/vnodeSvr.c
Comment thread utils/test/c/tmq_ts7402.c
@JinqingKuang
Copy link
Copy Markdown
Contributor

代码审查报告

本 PR 涉及 52 个文件、约 20k 行变更,为大型变更集,覆盖率可能下降,结论不确定性相对较高。建议后续拆分为更小的 PR 以获得更高质量的审查。

变更概述

本 PR 围绕 TMQ STB(超级表)订阅的表列表管理进行重构与优化:

  1. 引入 version 感知的 tag 检索(getTableTagsByUidVersion),支持已删除表的历史 tag 查询
  2. tq.c 中消息处理逻辑(poll、subscribe、delete)迁移到新的 tqInterface.c
  3. 新增 tqScan.c 中针对 STB 订阅的表列表实时管理逻辑(tqAddTableListForStbSubtqFilterForStbSub
  4. clientTmq.c 拆分为 clientTmqCommit.cclientTmqConf.cclientTmqOffset.c
  5. 移除 SMqSeekReq/tqProcessSeekReq
  6. WITH_DATA 重命名为 ONLY_DATA,统一 STB 和 DB 订阅的 WAL 扫描循环

发现的问题

🔴 [高危] getUidVersion 在版本不匹配时提前返回错误数据

新代码在游标定位到 (uid, futureVersion)(即目标表在请求版本之后存在修改记录)时,满足 tmp->uid == uid 即直接返回该未来版本号,导致 metaGetTableEntryByVersion 获取到快照时间之后的 tag 值。对于正在处理 WAL 版本 V 的 STB 订阅消费者,若表在 V 之后有过 tag 修改,将错误地返回修改后的 tag 而非修改前的 tag,造成订阅过滤结果出错。

位置source/dnode/vnode/src/meta/metaQuery.cgetUidVersion 函数,if (tmp->uid == uid)

修复方向:在提前返回前校验版本范围:

if (tmp->uid == uid && tmp->version <= *version) {
    *version = tmp->version;
    goto END;
}

🟡 [中危] metaGetTableTagsByUidsVersion 遇错 break 但函数返回 0,部分结果静默丢失

旧版 metaGetTableTagsByUids 对单个表 tag 查询失败仅记录日志并继续;新版改为 break 中断循环,但函数末尾仍 return 0(成功)。批次内靠后的表的 pTagVal 保持 NULL,tag 过滤器收到不完整数据,可能导致错误的表被纳入或排除订阅集。

位置source/dnode/vnode/src/meta/metaQuery.cmetaGetTableTagsByUidsVersion 函数中的 break 语句

修复方向:改为 continue(与旧代码保持一致的容错语义),或将错误码向上传播。


🟡 [中危] metaGetSuidByUidIfTableNotExist O(n) 全表扫描性能问题

函数从 pTbDb 第一条记录开始线性扫描以查找目标 uid(同一问题同样存在于 metaGetTbnameByIdIfTableNotExist)。pTbDb 是以 (uid, version) 为复合键的有序 B 树,在表数量庞大的生产环境中此函数将成为严重瓶颈。

位置source/dnode/vnode/src/meta/metaQuery.cmetaGetSuidByUidIfTableNotExisttdbTbcMoveToFirst 调用处

修复方向:使用有序索引的直接定位:

// 替换 tdbTbcMoveToFirst,直接定位到目标 uid 的起始位置
code = tdbTbcMoveTo(pCur, &(STbDbKey){.uid = uid, .version = 0}, sizeof(STbDbKey), &c);

时间复杂度从 O(n) 降为 O(log n)。


🟡 [中危] DB 订阅的 filter-out 机制被静默移除,行为存在回归风险

tqTaosxScanLog 中原有 TOPIC_SUB_TYPE__DB 分支使用 tqNextDataBlockFilterOut 跳过 pExec->execDb.pFilterOutTbUid 中的表;新代码以统一的 while (pReader->nextBlk < blockSz) 循环替代,tqFilterForStbSub 对 DB 订阅直接返回 false(不跳过)。DB 订阅将接收到此前被 filter-out 的表的数据。若该过滤机制是业务必需(如 taosx 场景),这是一个回归。

位置source/dnode/vnode/src/tq/tqScan.ctqTaosxScanLog 函数,TOPIC_SUB_TYPE__DB 分支被删除处

建议:若有意移除,请在 PR 描述中明确说明,并更新相关测试覆盖此场景。


🔵 [低危] TDMT_VND_TMQ_SEEK handler 已删除但消息类型保留,缺少兼容性说明

vnodeSvr.c 删除了 case TDMT_VND_TMQ_SEEK 处理,tmsgdef.h 仅加注释 "// no longer used",但消息类型枚举值保留。存量旧版客户端发送 SEEK 请求时落入 default: vError 分支,无法得到明确的错误反馈。

修复方向:保留 case TDMT_VND_TMQ_SEEK: 并返回 TSDB_CODE_NOT_SUPPORTED,或在 changelog 中明确标注此为不兼容变更。

Comment thread source/dnode/vnode/src/meta/metaQuery.c
Comment thread source/dnode/vnode/src/meta/metaQuery.c
Comment thread source/dnode/vnode/src/meta/metaQuery.c
Copilot AI review requested due to automatic review settings April 15, 2026 10:09
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 51 out of 52 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread utils/test/c/tmq_ts7402.c
Copilot AI review requested due to automatic review settings April 16, 2026 11:13
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 50 out of 51 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@guanshengliang guanshengliang merged commit 7f43bb3 into 3.0 Apr 17, 2026
13 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants