Repository navigation
[#3743] [Store] Stop HA leader monitor spinning on an empty master view - #65
Merged
Merged
Conversation
… master view Backport the LeaderMonitorThreadMain hunk of upstream kvcache-ai#3743 that was left out when #59 (hy/ha-rpc-staged) backported the rest of that change. When master_view is absent (every master is gone and the 5 s view lease has expired) or holds a warming placeholder (a newly elected leader that has not yet published its RPC endpoint, introduced by #59), ReadCurrentView() returns an empty view. WaitForViewChange() then reports changed=true with no view, and the monitor loop used to `continue` with the stale known_version, so every iteration returned immediately: one thread per client busy-looped, re-armed the etcd watch and re-read master_view each time, and EtcdHelper::Get logged "key not found" at thousands of lines per second. Clear current_master_view_ when the empty observation still refers to the view this iteration started from, so the next wait uses an empty known_version and blocks on the watch until a ready view is published. The function body now matches upstream d1b9c56 and current upstream main. No other part of kvcache-ai#3743 or kvcache-ai#3943 is included. (cherry picked from commit d1b9c56, LeaderMonitorThreadMain hunk only)
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
修复禅道 Bug 2816432 中的 client 空转部分:HA 模式下,master 全部退出后,或新 leader 处于预热窗口期间,client 监视 leader 的线程会无休眠地空转。
现象(
v0.3.13.post1_l4现网包): master 全部退出后,每个 client 进程的LeaderMonitorThreadMain线程:WaitForViewChange,每轮都重新挂一次 etcd watch、读一次master_view;etcd_helper.cpp:75] key=.../master_view, error=key not found in etcd,每个进程约每秒 1,000 多条;mooncake_client,每秒约 3,500 次 etcd 读、3,500 行 ERROR,mooncake_client的 CPU 约 180%。正常切主时也会空转:新 leader 先写“预热中”的占位值,RPC 就绪后才发布地址。这个窗口里
Get能成功,所以不打日志,但空转照样发生。原因:
ReadCurrentView()在 key 不存在或值为预热占位值时,都返回空视图。WaitForViewChange(旧版本)因此返回changed=true, current_view=空。continue,known_version仍是旧版本,下一轮立即再次返回。上游 kvcache-ai#3743(
d1b9c565)在这里加了处理。#59 回移 kvcache-ai#3743 时,带进了预热占位值的逻辑,却漏掉了LeaderMonitorThreadMain中的这一段,所以空转的触发范围从“master 全部退出”扩大到“每次切主或启动的预热窗口”。改动:
LeaderMonitorThreadMain的这一段,共 19 行。current_master_view_。下一轮known_version为空,与空视图一致,于是阻塞在 watch 上,等新的就绪视图出现。如果心跳线程已经并发装上了更新的视图,就不清除。d1b9c565和当前上游 main 逐字一致。cherry picked from记录。与 2816432 中“推理卡住”的关系:
ga510a9):推理卡住。240 s 内只完成 38 个请求,p99 为 65 s,P 健康检查 14/40 次失败。g3cae46,含 [Store] Backport HA RPC recovery fixes #59):推理正常。同期完成 2,208 个请求,p50 为 0.44 s。batch_exists_v2。旧连接策略下,每次调用约 2.3 s 才失败。[Store] Backport HA RPC recovery fixes #59 把 master 连接池改为不重试、1 s 连接超时,之后调用立即失败。Module
mooncake-transfer-engine)mooncake-store)mooncake-reshard)mooncake-ep)mooncake-pg)mooncake-integration)mooncake-p2p-store)mooncake-wheel)mooncake-common)mooncake-rl)Type of Change
How Has This Been Tested?
说明: 测试基于
3cae469b。之后变基到当前v0.3.13.post1_l4(350b6f54),无冲突;client_service.cpp在这两个提交之间没有变化。场景测试(独立
mooncake_client,单节点):mooncake_master --enable_ha+ 1 个mooncake_client(etcd://地址,tcp)。g3cae46;3cae469b编译的基线,打开USE_ETCD、STORE_USE_ETCD;mooncake_master字节相同,只有mooncake_client不同。Test commands:
Test results:
ReadCurrentView。这是原有行为,上游也一样。Clients: 1,client 的 segment 重新挂载成功。未覆盖:
Client类,代码路径相同。LeaderMonitorThreadMain是私有函数,需要真实 etcd;上游 [Store] Avoid blocking HA reattachment on master connection retries kvcache-ai/Mooncake#3743 也没有直接覆盖它的单测。Checklist
./scripts/code_format.sh(没有运行这个脚本;改动的行已用同版本 clang-format 20.1.8 检查,无需调整)AI Assistance Disclosure
使用 Claude Code 协助完成:定位空转原因、对比 #59 与上游 kvcache-ai#3743、回移代码,以及编写和执行上述场景测试。