Skip to content

fix(lockservice): fence stale binds by allocator epoch (#24906) - #25819

Closed
iamlinjunhong wants to merge 4 commits into
matrixorigin:4.1-devfrom
iamlinjunhong:d4-24896
Closed

iamlinjunhong wants to merge 4 commits into
matrixorigin:4.1-devfrom
iamlinjunhong:d4-24896

Conversation

@iamlinjunhong

Copy link
Copy Markdown
Contributor

fix(lockservice): fence stale binds by allocator epoch

Approved by: @aptend, @XuPeng-SH, @aunjgr

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #24896

What this PR does / why we need it:

fix(lockservice): fence stale binds by allocator epoch (#24906)

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request changes: late NewBind responses can republish a bind from a superseded allocator after the new allocator has already purged it.

Reproduced locally with this ordering: cache remote bind from A0 → observe A1 (version may regress) and purge the table → deliver an in-flight NewBind from A0 whose allocator ID matches the request bind. The table is recreated with AllocatorID=A0, violating the core fence invariant and allowing new transactions to use a bind the current TN allocator no longer recognizes. The same bypass exists in the keeper response path.

Please route these asynchronous NewBind publications through allocator-state validation (or refresh from the current allocator), and add race regressions for both paths.

Comment thread pkg/lockservice/lock_table_remote.go Resolved
Comment thread pkg/lockservice/lock_table_keeper.go Resolved
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

1 similar comment
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@gouhongshen gouhongshen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex automated review

No blocking correctness, concurrency, compatibility, or resource-handling regressions found. Verified the allocator-epoch fencing paths and ran go test ./pkg/lockservice -count=1.

@iamlinjunhong
iamlinjunhong requested review from XuPeng-SH and aunjgr and removed request for a user, LeftHandCold, dengn, jiangxinmeng1, ouyuanning and volgariver6 July 20, 2026 07:05

@aunjgr aunjgr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed head efa6161. This is a clean 4.1-dev backport of the already-merged allocator-epoch fencing and late-bind rejection fixes. The ownership, cancellation, refresh-failure, and exact-bind invalidation paths retain the upstream behavior. No remaining blockers found.

@gouhongshen gouhongshen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex automated review

The allocator fencing works for fully upgraded peers, and both the full lockservice suite and focused race tests pass. However, the original stale-bind-until-COMMIT failure remains reachable during a mixed-version rolling upgrade.

P1 - Fence legacy binds when allocator identity first appears (pkg/lockservice/service.go:795)

A new CN can cache binds from an old TN whose responses contain no allocator metadata, leaving lastAllocatorID/Version and each bind's AllocatorID empty. If that TN is then upgraded/restarted with a regressed or equal epoch, this condition sets allocatorChanged=false because no previous allocator state was recorded. The purge consequently falls back to bind.Version < observed.version, retains the legacy binds, and then records the new allocator ID; subsequent keepalives hit the same-allocator fast path and never reconsider them. If another table re-registers the CN first, keepalive is OK=true, reproducing the original behavior where the stale bind survives until commit validation fails. Treat the first non-empty allocator ID as an identity boundary for already-cached empty-ID binds, and cover old-TN → new-TN transition with a regressed epoch.

@iamlinjunhong

Copy link
Copy Markdown
Contributor Author

Codex automated review

The allocator fencing works for fully upgraded peers, and both the full lockservice suite and focused race tests pass. However, the original stale-bind-until-COMMIT failure remains reachable during a mixed-version rolling upgrade.

P1 - Fence legacy binds when allocator identity first appears (pkg/lockservice/service.go:795)

A new CN can cache binds from an old TN whose responses contain no allocator metadata, leaving lastAllocatorID/Version and each bind's AllocatorID empty. If that TN is then upgraded/restarted with a regressed or equal epoch, this condition sets allocatorChanged=false because no previous allocator state was recorded. The purge consequently falls back to bind.Version < observed.version, retains the legacy binds, and then records the new allocator ID; subsequent keepalives hit the same-allocator fast path and never reconsider them. If another table re-registers the CN first, keepalive is OK=true, reproducing the original behavior where the stale bind survives until commit validation fails. Treat the first non-empty allocator ID as an identity boundary for already-cached empty-ID binds, and cover old-TN → new-TN transition with a regressed epoch.

fixed

@gouhongshen gouhongshen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex automated review

One P1 mixed-version fencing gap remains.

P1 - Observe allocator identity before filtering an otherwise equal legacy bind (pkg/lockservice/lock_table_keeper.go:236)

A successful GetBind response is passed to allocator fencing only when newBind.Changed(bind). Changed intentionally treats an empty AllocatorID as compatible with a non-empty one, so an old-TN bind and an upgraded allocator's equal-version, same-owner bind compare unchanged. The new allocator identity is then discarded: legacy tables are not purged and active transactions are not fenced. Because allocator validation uses the same compatibility comparison, such a transaction can also pass commit validation before the next keepalive. The identical gate exists in remoteLockTable refresh paths. Validate allocator state on every successful GetBind before using structural equality to decide publication, and test equal-epoch old-TN→new-TN refreshes with an active transaction.

@gouhongshen gouhongshen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex automated review

No actionable regressions found at verified HEAD 15bf309. Prior review blockers are resolved: stale responses are fenced before publication, and first allocator identity observation purges legacy empty-ID binds. Protocol changes are additive and rolling compatibility is handled explicitly. Concurrency, cleanup, unhappy paths, and focused coverage are coherent. go test ./pkg/lockservice -count=1 passed in 584.972s; current CI checks are green and git diff --check is clean.

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants