You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: Repeated snapshot initialization duplicates entries and fills the export quota #25889
snapshotManager.Init appends every on-disk exported snapshot to the existing in-memory record each time it is called. It does not clear the previous view or deduplicate an equal snapshot index.
As a result, retrying replica initialization makes one physical snapshot appear many times in memory. After 20 retries, one snapshot is counted as 20 snapshots, which reaches the default MaxExportedSnapshot quota.
Affected version
Latest main tested at 862d9d30c2cd7a55995fd0bae0951af0809f5752.
Production path
Both store.startReplica and store.startNonVotingReplica call snapshotMgr.Init(shardID, replicaID) before NodeHost.StartReplica.
A repeated/retried bootstrap command therefore appends the same snapshots before Dragonboat can return ErrShardAlreadyExist. The inflated count is then used by shouldDoExport:
This can prematurely stop snapshot export and delay the export/import path used for log truncation and WAL compaction.
Root cause
snapshotManager.Init sorts the directory indexes and calls addLocked for each one, but it never replaces the existing in-memory record. snapshotRecord.add also permits an index equal to the current last index.
Expected behavior
Initialization should be idempotent for a (shardID, replicaID): the in-memory view should reflect the unique on-disk snapshot directories, regardless of how many times initialization is retried.
No matching open issue was found with searches for snapshot initialization idempotency, duplicate snapshot counts, bootstrap retry, and MaxExportedSnapshot quota exhaustion.
go test ./pkg/logservice \
-run '^TestAuditSnapshotManagerInitIsIdempotent$' \
-count=100
go test -race ./pkg/logservice \
-run '^TestAuditSnapshotManagerInitIsIdempotent$' \
-count=50
Head: gouhongshen:agent/issue-25889 at 4c08d6076bfb5c311a83ac726251b36acec593a0; base: matrixorigin/matrixone:main. The PR is open and marked Draft, and its description links this issue with Fixes #25889.
go test ./pkg/logservice -run '^(TestSnapshotItemValid|TestSnapshotItemInValid|TestInitSnapshotMgr|TestInitSnapshotMgrReplacesInMemoryView|TestAddSnapshot|TestRemoveSnapshot|TestEvalImportSnapshot)$' -count=3 -v
对同一集合执行 go test -race ... -count=3
回归测试
该问题属于 logservice 的磁盘目录与内存索引同步,不具备稳定 SQL 黑盒入口;回归保留在 pkg/logservice Go UT,不加入 motr。
Activity
Ariznawlll commentedon Jul 20, 2026
最新 main 白盒验证
main@862d9d30c2cd7a55995fd0bae0951af0809f5752pkg/logservice/snapshot_init_audit_test.go(shardID, replicaID)重复初始化时,内存快照视图是否与磁盘唯一目录保持一致。测试用例
TestAuditSnapshotManagerInitIsIdempotent执行以下步骤:100;目录内包含snapshot.metadata和对应的.gbsnap文件。snapshotManager.Init20 次;20 是当前默认MaxExportedSnapshot。Count必须始终为1,不能因重试达到导出配额。原始代码测试命令与结果
普通模式稳定性测试:
结果:
FAIL 3/3。每轮均得到:Race 模式:
结果:
FAIL 1/1,同样为expected 1, actual 20;没有检测到 data race,说明这是确定性的状态重复问题,不是测试竞争导致。临时修复对照
临时修改
snapshotManager.Init:在重新扫描磁盘目录后,先释放并移除该 shard/replica 的旧内存记录,再从磁盘重建唯一视图。结果:普通模式
PASS 100/100,race 模式PASS 50/50。结论与清理
Init追加旧内存状态而非重建/去重。gouhongshen commentedon Jul 31, 2026
Draft PR opened: #26502
Head:
gouhongshen:agent/issue-25889at4c08d6076bfb5c311a83ac726251b36acec593a0; base:matrixorigin/matrixone:main. The PR is open and marked Draft, and its description links this issue withFixes #25889.fix(logservice): make snapshot initialization idempotent (#26502)
gouhongshen commentedon Aug 2, 2026
fxied
Ariznawlll commentedon Aug 3, 2026
测试版本
mainb18cdee19bad80a51ea54789a727aa1753fd0b08原问题验证
执行 snapshot manager 的初始化、目录扫描及导入/删除回归。普通模式连续执行 3 轮、
-race连续执行 3 轮,均 exit 0。Happy Path 覆盖
Unhappy Path 覆盖
-race未报告数据竞争。白盒验证
snapshot_test.gogo test ./pkg/logservice -run '^(TestSnapshotItemValid|TestSnapshotItemInValid|TestInitSnapshotMgr|TestInitSnapshotMgrReplacesInMemoryView|TestAddSnapshot|TestRemoveSnapshot|TestEvalImportSnapshot)$' -count=3 -vgo test -race ... -count=3回归测试
该问题属于 logservice 的磁盘目录与内存索引同步,不具备稳定 SQL 黑盒入口;回归保留在
pkg/logserviceGo UT,不加入 motr。测试证据
上述命令于 2026-08-03 在 commit
b18cdee19bad80a51ea54789a727aa1753fd0b08执行,普通模式和 race 模式均为 exit 0。测试结论
测试通过。
fix(logservice): make snapshot initialization idempotent (matrixorigi…
fix(logservice): make snapshot initialization idempotent (matrixorigi…
fix(logservice): make snapshot initialization idempotent (matrixorigi…