Skip to content

[0.49-topru] topru manager keyspace cluster#82

Open
zeminzhou wants to merge 17 commits into0.49from
codex/topru-manager-keyspace-cluster
Open

[0.49-topru] topru manager keyspace cluster#82
zeminzhou wants to merge 17 commits into0.49from
codex/topru-manager-keyspace-cluster

Conversation

@zeminzhou
Copy link
Collaborator

No description provided.

@pingcap-cla-assistant
Copy link

pingcap-cla-assistant bot commented Mar 22, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ zhoucai-pingcap
❌ zeminzhou
You have signed the CLA already but the status is still pending? Let us recheck it.

@ti-chi-bot ti-chi-bot bot added the size/XXL label Mar 22, 2026
@zeminzhou
Copy link
Collaborator Author

跟一下这轮 review comments,刚刚已经在 167a2de 里处理并 push 到这个 PR:

  1. keyspace_cluster 的 cache 无上限问题
    已改成有上限的 LRU cache,默认容量 10000,避免 serverless 活跃 cluster 持续变化时无限增长占内存。

  2. manager 选出来的 active TiDB 为空时没有日志
    已补日志。现在在 manager 返回结果经过筛选后为空时,会输出一条带 manager_server_address / tidb_namespace / shard_config 的信息,方便排查。

  3. resolve_keyspace 失败/未命中时没有写缓存,是否会第一次失败第二次成功
    这里保持“不缓存失败/未命中”是有意为之。这样 PD 元数据延迟出现、临时网络抖动、或者第一次查不到第二次查到时,后续轮询还能恢复;如果把失败结果也缓存住,反而会放大瞬时异常。我在代码里补了注释说明这一点。

  4. manager response body 可能过大,担心内存打爆
    已加 body 大小限制,当前限制为 8 MiB。超过上限会直接报错,不再无限制读完整个 body。

  5. 只配置 manager_server_address,没配置 tidb_namespace 时是什么行为
    我把这块改成 fail-fast 了:现在如果配了 manager_server_addresstidb_namespace 为空/全空白,会直接返回 ConfigurationError,避免之前静默拿不到 TiDB 拓扑的行为。

本地已跑过定向测试:

  • cargo test keyspace_cluster --lib
  • cargo test tidb_manager --lib
  • cargo test normalize_tidb_namespace --lib

如果你更倾向于第 5 点走“fallback 回 etcd”而不是 fail-fast,我也可以再改。

Base automatically changed from 0.49-topru to 0.49 March 24, 2026 02:45
Copy link
Collaborator Author

@zeminzhou zeminzhou left a comment

Choose a reason for hiding this comment

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

claude:整体代码质量不错,测试覆盖充分,review comment 的处理也很到位(LRU cache、body 限制、fail-fast 配置校验等)。

另外有一个关于 TopSQLDeltaLakeSink::newunsafe 块的建议:通过 raw pointer 从 Arc 中取出内部值比较脆弱,如果以后有人改了代码多加了一个 clone 就可能导致 UB。建议重构为:先创建 channel 和 shared state(Arc<Mutex<HashMap<...>>>),spawn task 时直接传这些 Arc,然后正常构造 Self 返回,完全不需要 unsafe。

@zeminzhou
Copy link
Collaborator Author

跟进 review 3997482947,这轮 comment 我确认都需要通过代码修复处理,没有仅靠文字回复即可关闭的项;相关修改已在 54c1fda 中 push 到当前 PR 分支。

处理内容:

  • read_manager_shard_config_from_env 不再在每次 get_up_tidbs 时读取,改为在 LegacyTopologyFetcher 初始化时读取一次并缓存。
  • hash_keyspace_name 补了注释,说明为什么选 FNV-1a,以及它作为跨服务 keyspace sharding 隐式契约的要求。
  • topsql_v2manager_server_address / tidb_namespacePLACEHOLDER doc comment 已补成实际说明。
  • TopSQLDeltaLakeSink::new 里的 unsafe 已移除:现在先正常构造 sink,再 clone 一份给后台 task,不再通过 raw pointer 从 Arc 里取内部值。

本地定向验证:

  • cargo test -q --package vector-extensions --lib manager_shard_config -- --nocapture
  • cargo test -q --package vector-extensions --lib test_send_when_batch_size_reached -- --nocapture
  • cargo test -q --package vector-extensions --lib normalize_tidb_namespace -- --nocapture
  • cargo test -q --package vector-extensions --lib hash_keyspace_name_is_stable -- --nocapture

@zeminzhou
Copy link
Collaborator Author

zeminzhou commented Mar 24, 2026

codex: 关于 review body 里提到的 TopSQLDeltaLakeSink::newunsafe 建议,这部分已经在 54c1fda 里改掉了:现在先正常构造 Self,再 clone 一份给后台 task 使用,不再通过 raw pointer 从 Arc 里取内部值,因此后续即使有人再改初始化路径也不会踩到 UB 风险。

Copy link
Collaborator Author

@zeminzhou zeminzhou left a comment

Choose a reason for hiding this comment

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

claude:LGTM 🎉

上一轮的 review comments 都已修复:

  1. process_events_loop 加了 max retry (5次) + exponential backoff (5s→60s cap) + 超限丢弃日志
  2. unsafe 块移除,改用 #[derive(Clone)] + sink.clone()(data 和 meta processor 都改了)
  3. is_not_found_body 收紧为 "keyspace not found",支持纯文本和 JSON 格式,加了测试
  4. normalize_namespaces 抽成公共函数 normalize_namespace_list
  5. ✅ shard config 初始化时读一次环境变量,缓存到 struct
  6. ✅ doc comment PLACEHOLDER 已补上
  7. ✅ FNV-1a hash 加了注释说明选择原因和跨服务契约

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.

2 participants