Repository navigation
Description
Is there an existing issue for the same bug?
- I have checked the existing issues.
Searches for "lock table bind changed", ErrLockTableBindChanged, lockservice allocator bind epoch, and stale lock table bind allocator found several historical closed issues, but I did not find an open issue for this specific allocator-epoch stale-bind scenario.
Branch Name
- Affected production image:
registry.jst.com.cn/moi/matrixone:3.0.0-5e4210029-hotfix-20260603 - Affected local branch/repro:
3.0-dev
Commit ID
- Production image commit:
5e4210029 - Local reproduction commit:
1b4aa0a7a458d69c834c1292a9628056eed86cae
Other Environment Information
- Deployment mode: distributed MO with CN and TN/DN pods
- Component:
lockservice,lockTableAllocator, pessimistic transaction commit validation - Observed during a data import workflow. The failing SQL observed in MO logs was
COMMIT, not the preceding DML.
Actual Behavior
A CN can keep local lock table binds created by an older TN/DN lock allocator epoch after the TN/DN allocator pod is rebuilt. If the CN does not restart, and it later accesses another table first, the new allocator registers the same CN service ID again. After that, normal keepalive returns OK=true, but it does not validate the CN's already cached table binds.
As a result, stale table binds can remain on the CN for a long time and are only detected at transaction commit time by allocator.Valid(). The user-visible result is:
Error 20702 (HY000): lock table bind changed
Evidence from one incident:
old allocator start:
2026-06-05 15:13:42 +0800
version=1780643622856501201
old binds assigned:
2026-06-08 14:07:25 +0800
table=272592 / 272593
bind version=1780643622856501202
new allocator start after DN pod rebuild:
2026-06-08 14:11:38 +0800
version=1780899098803397307
commit failure:
2026-06-09 09:39:55 +0800
error=lock table bind changed
allocator current=0-0(0)--0
received old bind=0-272592(272592)-...-1780643622856501202
received old bind=0-272593(272593)-...-1780643622856501202
The important part is that the later keepalive can be healthy (OK=true) even though the CN still has stale per-table binds from the old allocator epoch.
Expected Behavior
After the TN/DN lock allocator restarts and gets a new allocator epoch, CNs that still cache binds from an older allocator epoch should proactively fence and remove those stale local lock tables before a user transaction reaches COMMIT.
allocator.Valid() should remain as the final safety check, but normal operation should not allow an old allocator epoch bind to sit on a live CN until a business transaction commit fails.
Steps to Reproduce
A minimal reproduction can be modeled in pkg/lockservice/service_test.go:
- Start one CN lock service and one lock table allocator.
- Let the CN lock and unlock table A so that it caches table A's local lock table bind.
- Simulate a TN/DN allocator pod rebuild while the CN stays alive:
- clear allocator
services - clear allocator
lockTables - move allocator
versionforward to represent a new allocator epoch
- clear allocator
- Let the same CN access table B. This calls
GetBindand registers the same CN service ID in the new allocator. KeepLockTableBind(serviceID)can now returnOK=true.- The old table A bind still exists in the CN's local
tableGroups. - Call
allocator.Valid(serviceID, txnID, []LockTable{oldTableABind})to simulate commit validation. - The allocator returns table A as invalid, matching the production
ErrLockTableBindChangedpath.
A local UT was added to demonstrate this behavior:
go test ./pkg/lockservice -run TestCommitDetectsStaleLocalBindAfterAllocatorRestart -count=1The test demonstrates the current bug shape: keepalive can be OK after the CN re-registers through another table, while the older table bind is still only detected by allocator.Valid().
Additional information
Likely root cause:
lockTableAllocator.versionis initialized fromtime.Now().UnixNano()when the allocator is constructed.- Normal
ServiceLockEnablekeepalive does not send all localLockTables. KeepLockTableBind(serviceID)only checks whether the service exists and marks it active.- If the service has already been re-registered in the new allocator epoch by another
GetBind, keepalive returns OK and does not remove stale per-table binds.
Suggested fix direction:
- Add an explicit allocator epoch/version field to allocator responses, at least:
GetBindResponse.AllocatorVersionKeepLockTableBindResponse.AllocatorVersion
- CN should observe allocator epoch from those responses through a serialized
observeAllocatorVersion(...)path. - When a newer allocator epoch is observed, CN should purge local lock tables whose bind version belongs to an older allocator epoch.
- Do not infer allocator epoch from an arbitrary
LockTable.Version:createBindLockedsetsb.Version = allocator.version, buttryRebindLockeddoesold.Version++, soLockTable.Versionisallocator_epoch + per-table increment, not a pure allocator epoch. - Keep
allocator.Valid()as the final commit-time safety check.
A design note and task breakdown were prepared locally under docs/lockservice/lock-table-bind-epoch-fencing-fix-design.md.
Activity
Ariznawlll commentedon Jul 13, 2026
已在最新
main完成回归和扩展白盒验证,当前问题无法复现,修复有效。验证环境
main2865ed6cc8a39727b8b274bb52b88fe441d0b30cfix(lockservice): fence stale binds by allocator epoch)原始故障链路回归
执行
TestCommitDetectsStaleLocalBindAfterAllocatorRestart,用例完整模拟了 issue 中的现场路径:272592的 local lock table bind;services和lockTables,推进 allocator epoch,模拟 TN/DN allocator pod 重建,而 CN 不重启;allocator.Valid()会被判为 invalid,证明测试确实构造出了原始故障前提;50011829,触发新 allocator 的GetBind;272592的旧本地 bind;KeepLockTableBind正常;272592时重新获取新 bind,新旧 bind 的 identity 不同,后续 Lock/Unlock 成功。该原始用例连续执行 100 轮,全部通过:
扩展白盒测试矩阵
以下 21 个测试均开启
-race,每个连续执行 10 轮,共 210 次,全部通过且未发现数据竞争:覆盖点和结果如下:
OK=true和OK=false路径都能观察新 allocator;旧 local/remote/proxy bind 被清理,新 epoch 的 proxy bind 被保留。ErrLockTableNotFound,不会永久挂起。全包回归
另外执行了 lockservice 全包测试:
代码结论
当前实现已把 allocator identity/epoch 放入 bind/keepalive 响应,并通过串行化的 allocator state observer 统一处理状态切换。发现新 allocator 时会在 CN 侧主动 purge 旧 local/remote/proxy lock table,同时保留
allocator.Valid()作为最终安全校验;旧 allocator 的延迟响应也无法把 stale bind 重新写回。因此,issue 所描述的“CN keepalive 健康,但旧 epoch bind 一直保留到业务事务 COMMIT 才报
lock table bind changed”路径在最新main已被阻断。本轮未发现新的回归缺陷,可以关闭。