Skip to content

fix(lockservice): check bind before lock success - #24395

Merged
mergify[bot] merged 1 commit into
matrixorigin:mainfrom
LeftHandCold:fix-lock-bind-success-check-main
May 14, 2026
Merged

fix(lockservice): check bind before lock success#24395
mergify[bot] merged 1 commit into
matrixorigin:mainfrom
LeftHandCold:fix-lock-bind-success-check-main

Conversation

@LeftHandCold

Copy link
Copy Markdown
Contributor

What type of PR is this?

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

Which issue(s) this PR fixes:

Refs #24346

What this PR does / why we need it:

This is a focused follow-up for the bind-change fencing fix. It closes the stale-success race where a bind change has already started and is waiting behind the active txn lock while an in-flight lock operation is about to return success.

The change adds a final success-path check before returning local lock success or writing remote/forward lock success responses. The check releases the txn lock, waits behind any pending bind-change fence using the existing bindChangeMu ordering, reacquires the txn lock, and only then allows success if the txn and bind are still current.

This keeps the fix narrow: no retry policy, allocator behavior, commit validation, or logging behavior is changed.

Validation

  • go test ./pkg/lockservice -run 'Test(BindChangedBeforeLockSuccessReturnsBindChanged|BindChangedFencesActiveTxnHoldingOldBind|BindChangedFencesActiveTxnAfterOldTableRemoved|Issue3538)$' -count=1 -timeout=3m\n- go test ./pkg/lockservice -count=1 -timeout=5m

Wait for any pending bind-change fence before reporting lock success locally or writing remote lock success responses. This closes the stale-success race where a bind change is waiting on the txn lock while an in-flight lock returns success.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 14, 2026 08:28
@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 →

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Closes a stale-success race in lockservice where a lock op could return success after a bind change had begun fencing. After a successful lock acquisition, the code now re-checks under bindChangeMu (with the same lock ordering as the entry path) that the txn id, txn.bindChanged flag, and the lock table's bind are still current; otherwise it returns ErrTxnNotFound or ErrLockTableBindChanged.

Changes:

  • Add checkBindChangedBeforeLockSuccess helper that briefly unlocks the txn, takes bindChangeMu (RLock), reacquires the txn lock, and validates txn id / bindChanged / table bind.
  • Invoke the helper on the success path of service.Lock, handleRemoteLock, and handleForwardLock, mapping any failure to a clean pb.Result{} plus error.
  • Add TestBindChangedBeforeLockSuccessReturnsBindChanged covering the race using beforeLockAdded + concurrent handleBindChanged.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
pkg/lockservice/service.go Adds the post-lock bind/txn revalidation helper and uses it in the local Lock success path.
pkg/lockservice/service_remote.go Applies the same revalidation in the remote and forward lock async callbacks (with a defensive txnID copy).
pkg/lockservice/service_test.go New test that fences a lock between waiter add and success return to assert ErrLockTableBindChanged is returned.

@mergify mergify Bot added the queued label May 14, 2026
@mergify

mergify Bot commented May 14, 2026

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • Entered queue2026-05-14 10:03 UTC · Rule: main
  • Checks skipped · PR is already up-to-date
  • Merged2026-05-14 10:04 UTC · at 68d96ed58ca567199854c0e1cd84a5ce8de8a6d2 · squash

This pull request spent 21 seconds in the queue, including 4 seconds running CI.

Required conditions to merge
  • #approved-reviews-by >= 1 [🛡 GitHub branch protection]
  • #changes-requested-reviews-by = 0 [🛡 GitHub branch protection]
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-decision = APPROVED [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-neutral = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-skipped = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Ubuntu/x86
    • check-neutral = Matrixone CI / SCA Test on Ubuntu/x86
    • check-skipped = Matrixone CI / SCA Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-neutral = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-skipped = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage

@mergify
mergify Bot merged commit 731530a into matrixorigin:main May 14, 2026
27 of 28 checks passed
@mergify mergify Bot removed the queued label May 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/S Denotes a PR that changes [10,99] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants