fix: Fix Codis lossless master switch offset alignment - #3268
Open
Mixficsol wants to merge 5 commits into
Open
Conversation
added 3 commits
July 1, 2026 16:53
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
added 2 commits
July 7, 2026 10:21
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.
解决了什么问题
高写入 QPS 下主动切主会失败并丢数据。根因是「切主前确认从库追平」的判断口径错误:代码拿新主自己写 binlog 的 producer 位点去比老主的 producer 位点,而两者是各自独立的坐标系(各自按
binlog-file-size分文件、各自 rollover),newFileNum > oldFileNum就误判「已追上」。从库文件号大往往只是binlog-file-size调小造成的假象,结果没真追平就切主——老主 pause 期间的尾部写入丢失,老主还被迫全量重做。怎么解决的
把「确认从库追平」的信号从「比两节点各自的 producer 位点」改成「老主停写后,看老主视角下该从库的 lag 收敛到阈值内」,这才是同一坐标系下可信的追平信号。
1.
sentinel.go— 修正 lag 解析parseSlaveLag:正确解析 pika 的lag=(db0:N)格式,多 db 取最大值(任一 db 没追平就算没追平),兼容裸整数,full syncing/not syncing等非数字状态返回哨兵值(永不判为追平)。InfoSlave.UnmarshalJSON原用strconv.Atoi("(db0:0)")恒失败,导致 Lag 字段一直为 0;改用parseSlaveLag。2.
topom_group.go— 重写追平判断binlogCaughtUp(比较两节点各自独立的 producer 位点,丢数据根源)。getSlaveLagFromMaster:读老主info replication,按地址定位新主,返回老主视角下该从库的 lag;新主不在老主 slave 列表时判为「未追平」,绝不当作 lag 0。waitCatchUpBeforePromote:老主pause-write停写 → 轮询老主视角下新主的 lag →lag <= threshold才算追平 → 超时按默认策略 abort 并恢复老主写入。3.
client_test.go— 补充单测TestParseSlaveLag、TestMasterInfoReplicationLag,原 master 用例补 Lag 断言。