Skip to content

使用 Pebble 替换 oplog 本地落盘队列#987

Open
SisyphusSQ wants to merge 4 commits into
alibaba:developfrom
SisyphusSQ:develop
Open

使用 Pebble 替换 oplog 本地落盘队列#987
SisyphusSQ wants to merge 4 commits into
alibaba:developfrom
SisyphusSQ:develop

Conversation

@SisyphusSQ

Copy link
Copy Markdown
Contributor

背景

关联 issue:#982

当前 full_sync.reader.oplog_store_disk=true 路径依赖 go-diskqueue 作为本地 oplog 临时队列。本 PR 将该路径替换为 Pebble-backed spool,保持原有用户配置不变,并补齐 checkpoint、重启恢复、指标和测试覆盖。

主要变更

  • 新增 collector/spool 内部接口和 Pebble 实现,支持 FIFO 写入、批量读取、推进、深度统计、关闭重开、删除和旧格式 fail fast。
  • 改造 Persister 的磁盘落盘/回放状态机:全量期间写入 Pebble spool,全量完成后按顺序回放到 pending queue,回放完成后删除 spool 并切回内存 apply。
  • 保持 checkpoint 语义:OplogDiskQueue / OplogDiskQueueFinishTs 只在 spool 回放完成且 worker checkpoint 追上后才标记完成;重启时可重新打开未完成 spool。
  • 新增 raw BSON timestamp helper,并在 oplog reader 发送 raw bytes 前 clone 数据,避免 cursor buffer 复用影响 spool timestamp 解析。
  • /persist 增加 spool_depthspool_read_seqspool_write_seq;Prometheus 增加 spool_depthspool_write_seqspool_read_seqspool_write_totalspool_read_totalspool_errors_total
  • 限制 full_sync.reader.oplog_store_disk 仅用于 oplog fetch method,避免 change stream 路径被误用。

不包含

  • 不支持 change stream spool。
  • 不迁移旧 go-diskqueue 本地文件;检测到旧格式时明确失败。
  • 目标端写入一致性不在本次验证范围内。

验证

本地目标测试和构建已通过:

go test ./oplog -run TestExtractRawTimestamp -count=1
go test ./collector -run 'TestPersister(GetQueryTsFromDiskQueueReadsRawOplogTimestamp|Retrieve)|TestCheckpoint' -count=1
go test ./collector/spool -count=1
go test ./collector/reader -run TestCloneOplogRawDetachesCursorBuffer -count=1
go test ./cmd/collector -run TestCheckDefaultValue -count=1
go test ./common -run 'Test.*Prom' -count=1
go build -o /tmp/mongoshake-collector ./cmd/collector
git diff --check

除本地测试和构建外,还做了两类运行验证:

  1. 单任务链路验证
  • 使用真实源端数据流启动 collector
  • 开启 full_sync.reader.oplog_store_disk=true
  • collector 正常进入 full sync 与 incr sync 协调流程。
  • persister 能创建 Pebble spool,并在 full sync 期间持续写入捕获到的 oplog。
  • full sync 完成后,persister 能从 Pebble spool 顺序回放数据。
  • 回放完成后,spool_depth 降为 0,spool_errors 保持 0。
  • 日志确认 spool 删除成功,实例 spool 目录已清理。
  • collector 随后进入增量阶段,checkpoint 持续推进。
  1. 分片集群链路验证
  • 使用真实分片源端数据流启动 collector
  • 6 个 shard / replica 维度均观察到 Pebble spool 打开。
  • 6 个维度均进入 spool 回放阶段。
  • 6 个维度均完成 spool 删除。
  • 6 个维度均进入增量阶段,并观察到增量 write_success > 0
  • full sync 进度完成,full_sync_collections_progress_ratio = 1
  • full sync 完成集合数为 228。
  • 所有 shard 的 spool_depth 汇总为 0。
  • watcher 已调整为聚合 rotated logs,避免只读取当前日志文件导致成功证据丢失。

上述验证覆盖 Pebble spool 的打开、写入、回放、清空、删除、checkpoint 推进和增量续跑。目标端写入一致性不在本次验证范围内。

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