Skip to content

fix(lockservice): recover from stale empty locks - #27296

Merged
mergify[bot] merged 8 commits into
matrixorigin:mainfrom
daviszhen:fix/epinions-lock-panic
Aug 19, 2026
Merged

mergify[bot] merged 8 commits into
matrixorigin:mainfrom
daviszhen:fix/epinions-lock-panic

Conversation

@daviszhen

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:

issue #27291

#27293

What this PR does / why we need it:

  • tryHold 遇到空锁返回错误,不再触发 panic。
  • 清理并重试残留的空 row/range lock。
  • range endpoint 失配时,优先使用有效配对端恢复锁状态。
  • 增加空 row、空 range 和 tryHold 回归测试。

当前主干已包含 nil-pointer 问题的 LockOp 修复(9661f93b0、f3039c909),本分支补齐了后续 try hold on empty lock 问题。

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

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

[P1] Do not attach an orphan endpoint to an adjacent live range

In deleteEmptyLockLocked, findPairedRangeLock only finds the nearest endpoint of the opposite kind; it does not prove that endpoint belonged to the stale lock. With an orphan empty range-start at key 1 and an otherwise valid live range [3,5], this branch treats key 5 as the pair, copies its holders/waiters into key 1, and leaves both starts (1 and 3) pointing at the same end. When the live owner later unlocks [3,5], that shared state is returned to the pools while key 1 still references it, so a subsequent allocation can mutate a lock that remains in this table. I reproduced the bad three-entry state directly at this head. Only rebuild an endpoint when its counterpart can be identified unambiguously; otherwise remove the orphan without splicing it into a neighboring range. Please add a regression with an orphan endpoint adjacent to a complete live range.

[P2] Restart the merge transaction before retrying an empty conflict

The errEmptyLock branch at lock_table_local.go:989-998 continues the outer range scan without rolling back/reinitializing mc. Any locks owned by the requester that were visited before the stale entry have already had their waiters copied into mc.to; the retry visits them again and copies the same waiter a second time. A concrete reproduction is: txn 1 owns [1,2], txn 2 is waiting on it, insert an empty row entry at key 5, then let txn 1 extend its range to [1,10]. The call succeeds, but the final range queue contains txn 2 twice. Discard/reinitialize the in-progress merge state before rescanning (including mergedWaiters/mergedLocks, not only the queue change marker), and cover this retry-after-partial-merge case.

@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 current head 06fca7d. The structural pair identity checks, merge-context restart, orphan cleanup, and half-live endpoint repair close the prior stale-range invariants. The lockservice regressions cover adjacent live ranges, retry-after-partial-merge, and both half-live endpoint directions. No additional blocking findings.

@daviszhen
daviszhen requested a review from aptend August 19, 2026 10:25

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

Deep re-review of exact head 06fca7d. I read the complete review/thread history, checked the b5ddcfd increment against the prior reviewed head and re-audited the full diff. The half-live endpoint repair now preserves the structural pair without attaching an orphan to an adjacent complete range; abandoned pooled state is only released after store-reference checks; and merge restart rolls back speculative waiter refs and bookkeeping before rescanning. I also reviewed row/range acquisition, waiter detach/notification, merge commit/rollback, unlock bookkeeping, and the LockOp shared-target path. Both affected packages pass under the repository CGO environment. No blocking findings remain.

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

Deep review of exact head 06fca7dfdc26782c26d738c3eeb8d541145a3e4d: no blocking findings.

I re-audited the complete stale-lock recovery, not only the latest patch. Structural endpoint pairing now stops before an adjacent complete range; a unique half-live counterpart is repaired without changing its holder/waiter generation; abandoned pooled states are released only after checking remaining store references; and a retry after a partially accumulated range merge rolls back both waiter-queue changes and merged-key bookkeeping before rescanning. Row/range waiter detach, unlock notification, endpoint removal, and the LockOp shared-target/default-checker paths preserve ownership and wait-for invariants.

Verification on this exact worktree:

  • git diff --check passed.
  • Seven stale endpoint/partial-merge/empty-lock regressions passed with -race -count=20.
  • Both LockOp regressions passed with -race -count=20.
  • Full ./pkg/lockservice passed with -race -count=1 (99.176s).

@mergify

mergify Bot commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Queued — the merge queue status continues in this comment ↓.

@mergify mergify Bot added the queued label Aug 19, 2026
@mergify

mergify Bot commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-19 11:41 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-08-19 13:12 UTC · at ebfbffbdc59f5432587f2393fdc322833ebdec38 · squash

This pull request spent 1 hour 31 minutes 12 seconds in the queue, including 50 minutes 14 seconds running CI.

Required conditions to merge
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]
  • 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 CI / SCA Test on Linux/arm64
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)

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/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants