Skip to content

fix(events): edge bus Subscribe 拆锁——磁盘回放移出 b.mu 临界区 - #2165

Merged
DeliciousBuding merged 1 commit into
masterfrom
chore/cleanup-round-22
Aug 31, 2026
Merged

fix(events): edge bus Subscribe 拆锁——磁盘回放移出 b.mu 临界区#2165
DeliciousBuding merged 1 commit into
masterfrom
chore/cleanup-round-22

Conversation

@DeliciousBuding

Copy link
Copy Markdown
Collaborator

范围(#2154 性能 lane F15,P1)

Bus.Subscribe 原先在 b.mu 内调用 EventLog.ReadFrom(文件 IO + 逐行 unmarshal,日志最大 ~50MiB):一个带旧 cursor 的重连客户端可把整个 edge 事件的 Publish fanout 停住整个回放时长。

  • ReadFrom 移到取锁之前执行(eventLog 指针在构造期固定,竞态安全)
  • b.mu 内只保留 subscriber 注册 + 内存 history 回放 + 合并(纯内存)
  • 合并逻辑抽成纯函数 mergeReplayWithLog(gap 注入 / seenSeqs 去重 history 优先 / seq 排序),新增 3 个契约测试
  • 回放语义不变:并发发布由 history 去重覆盖;gap/排序与旧实现一致

验证

  • go test ./edge-server/... -short -count=1 全绿
  • go vet ./internal/events/ 绿;新增 3 测试绿
  • git diff --check 干净

#2154 perf-lane F15(P1):Subscribe 在 b.mu 内调 EventLog.ReadFrom(文件 IO + 逐行 unmarshal),带旧 cursor 的重连客户端可把整个 Publish fanout 停住整个回放时长(日志最大 ~50MiB)。

- ReadFrom 移到取锁之前(eventLog 指针构造期固定,竞态安全);b.mu 内只做 subscriber 注册 + 内存 history 回放 + 合并
- 合并逻辑抽成纯函数 mergeReplayWithLog(gap 注入 / seenSeqs 去重 history 优先 / seq 排序),新增 3 个契约测试
- 语义不变:并发发布仍由 history 去重覆盖,gap 语义与排序与旧实现一致

验证:edge-server 全量 go test -short 绿;events 包 go vet 绿;新增 3 测试绿;git diff --check 干净

Co-authored-by: Cursor <cursor@vectorcontrol.tech>
@coderabbitai

coderabbitai Bot commented Aug 31, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Team

Run ID: dfcd13d6-b7ad-41f2-ad25-8a576508eeac

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@DeliciousBuding
DeliciousBuding merged commit 668ea5b into master Aug 31, 2026
39 checks passed
@DeliciousBuding
DeliciousBuding deleted the chore/cleanup-round-22 branch August 31, 2026 23:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant