Skip to content

[4.2] fix(lockservice): exclude uncertain locks from deadlock graph - #27129

Merged
XuPeng-SH merged 2 commits into
matrixorigin:4.2-devfrom
LeftHandCold:backport/4.2-lockservice-uncertain-deadlock
Aug 13, 2026
Merged

XuPeng-SH merged 2 commits into
matrixorigin:4.2-devfrom
LeftHandCold:backport/4.2-lockservice-uncertain-deadlock

Conversation

@LeftHandCold

Copy link
Copy Markdown
Collaborator

What type of PR is this?

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

Which issue(s) this PR fixes:

Related to #27124.

Backport of #26925, which fixes #26922.

What this PR does / why we need it:

Root cause

When a remote Lock response is lost, canceled, or times out, the source CN must retain the requested rows so transaction close can conservatively send Unlock. In 4.2-dev those cleanup records are stored in activeTxn.tableKeys, and distributed deadlock detection also treats every entry in that collection as proof that the transaction holds the row.

If the request is still waiting on the owner, the owner returns that same transaction as a waiter and the polluted wait-for graph produces a false T <= T self-cycle. This exact sequence is present in #27124: a failed remote lock with context canceled is followed by a self-cycle and user-visible 20701.

Fix

  • Keep uncertain rows in tableKeys so conservative remote cleanup remains unchanged.
  • Track cleanup-only rows in a sparse per-table set and exclude them from fetchWhoWaitingMe.
  • Promote an uncertain row after a successful Lock result.
  • Never downgrade an already confirmed row after a later uncertain retry.
  • Remove sparse state on lock removal, table cleanup, transaction close, and object reuse.

This does not suppress genuine multi-transaction deadlocks. It removes only deadlock edges that are not backed by a confirmed lock. Normal successful Lock calls do not allocate the sparse state.

Validation

  • TestRemoteWaitingListRequiresConfirmedHolder: passed; race -count=100 passed.
  • TestCleanupOnlyLockStateTransitions: passed; race -count=100 passed.
  • TestLockRemoteWithContextTimeoutTracksLockForUnlock: passed; race -count=100 passed.
  • go build ./pkg/lockservice: passed.
  • go vet ./pkg/lockservice: passed.
  • go test ./pkg/lockservice: passed.
  • go test -race ./pkg/lockservice: passed.

Cherry-picked from e88f5e4a706f28590f6dd69076cd38981eceaaa9.

@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 →

@LeftHandCold LeftHandCold left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Reviewed exact head a4f693ccfbbba3f218579eb150fee32f7429fa47. No blocking findings. The cleanup-only/confirmed state transitions are closed: failed remote responses remain conservatively unlockable but are excluded from wait-for edges; successful retries promote those rows; later failures do not downgrade confirmed holders; individual lock removal, table cleanup, and transaction reuse remove the auxiliary state. The deadlock scan snapshots both lock rows and uncertainty under the transaction read lock, and the newer 4.2-dev base changes do not overlap lockservice. This patch also matches the already approved and merged upstream fix in #26925. LGTM.

@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.

Approved exact head a4f693c. This backport has the same stable patch-id as the previously reviewed and merged upstream fix e88f5e4. The 4.2 branch differences around the affected state machine do not alter the cleanup-only/confirmed lock invariants: uncertain rows remain unlockable but are excluded from wait-for edges, successful retries promote them, later failures do not downgrade confirmed holders, and lock/table/transaction cleanup removes the auxiliary state.

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

kind/bug Something isn't working size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants