Skip to content

[BugFix] Locker: rollback partial intensive-lock acquisition#72423

Merged
alvin-phoenix-ai merged 1 commit into
StarRocks:mainfrom
kevincai:bugfix/fix-locker-rollback-symmetric
May 2, 2026
Merged

[BugFix] Locker: rollback partial intensive-lock acquisition#72423
alvin-phoenix-ai merged 1 commit into
StarRocks:mainfrom
kevincai:bugfix/fix-locker-rollback-symmetric

Conversation

@kevincai

@kevincai kevincai commented May 1, 2026

Copy link
Copy Markdown
Contributor

lockTableWithIntensiveDbLock and lockTablesWithIntensiveDbLock acquire a DB intention lock first and then one or more table locks. If any of the table-lock acquisitions threw (deadlock victim selection, interrupt, timeout, etc.), the helpers caught LockException and rethrew it as ErrorReportException without releasing the DB intention lock that was already held -- and, in the multi-table variant, without releasing any table locks acquired earlier in the loop. The result was a stranded IS / IX lock on the database that blocked subsequent DB-WRITE operations (DROP DATABASE / DROP TABLE / quota change / rename) indefinitely until the FE process restarted.

Callers could not work around this from the call site:

  • Lock-acquisition outside try/finally: catch is never reached, the finally never runs, so the partial DB lock leaks.
  • Lock-acquisition inside try/finally: the finally calls the matching unLock... helper, which first releases the DB intention lock (good) and then iterates the table-id list calling release on each -- but table locks past the failure point were never acquired, so their release throws and masks the original LockException with a less informative "lock not held" error. The DB lock is released in this case, but the diagnostics are wrong.

Fix the helpers themselves. On any LockException during acquisition, call a new private rollbackPartialIntensiveLock that releases each table lock that did get acquired (in acquisition order, like the existing tryLockTablesWithIntensiveDbLock pattern at lines 338-348), then releases the DB intention lock if it was acquired. Each release is wrapped in a defensive try/catch that logs and swallows any secondary error, so the original LockException surfaces to the caller instead of being masked by a release-side failure.

After this change, the lock-acquisition-outside-try/finally idiom at the call sites is correct: a partial-acquire failure leaves no held locks behind, so there is nothing for a finally block to release.

Why I'm doing:

What I'm doing:

Fixes #issue

What type of PR is this:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

Does this PR entail a change in behavior?

  • Yes, this PR will result in a change in behavior.
  • No, this PR will not result in a change in behavior.

If yes, please specify the type of change:

  • Interface/UI changes: syntax, type conversion, expression evaluation, display information
  • Parameter changes: default values, similar parameters but with different default values
  • Policy changes: use new policy to replace old one, functionality automatically enabled
  • Feature removed
  • Miscellaneous: upgrade & downgrade compatibility, etc.

Checklist:

  • I have added test cases for my bug fix or my new feature
  • This pr needs user documentation (for new or modified features or behaviors)
    • I have added documentation for my new feature or new function
    • This pr needs auto generate documentation
  • This is a backport pr

Bugfix cherry-pick branch check:

  • I have checked the version labels which the pr will be auto-backported to the target branch
    • 4.1
    • 4.0
    • 3.5
    • 3.4

lockTableWithIntensiveDbLock and lockTablesWithIntensiveDbLock acquire
a DB intention lock first and then one or more table locks. If any of
the table-lock acquisitions threw (deadlock victim selection, interrupt,
timeout, etc.), the helpers caught LockException and rethrew it as
ErrorReportException without releasing the DB intention lock that was
already held -- and, in the multi-table variant, without releasing any
table locks acquired earlier in the loop. The result was a stranded
IS / IX lock on the database that blocked subsequent DB-WRITE
operations (DROP DATABASE / DROP TABLE / quota change / rename)
indefinitely until the FE process restarted.

Callers could not work around this from the call site:
  - Lock-acquisition outside try/finally: catch is never reached, the
    finally never runs, so the partial DB lock leaks.
  - Lock-acquisition inside try/finally: the finally calls the matching
    unLock... helper, which first releases the DB intention lock (good)
    and then iterates the table-id list calling release on each -- but
    table locks past the failure point were never acquired, so their
    release throws and masks the original LockException with a less
    informative "lock not held" error. The DB lock is released in this
    case, but the diagnostics are wrong.

Fix the helpers themselves. On any LockException during acquisition,
call a new private rollbackPartialIntensiveLock that releases each
table lock that did get acquired (in acquisition order, like the
existing tryLockTablesWithIntensiveDbLock pattern at lines 338-348),
then releases the DB intention lock if it was acquired. Each release
is wrapped in a defensive try/catch that logs and swallows any
secondary error, so the original LockException surfaces to the caller
instead of being masked by a release-side failure.

After this change, the lock-acquisition-outside-try/finally idiom at
the call sites is correct: a partial-acquire failure leaves no held
locks behind, so there is nothing for a finally block to release.

Signed-off-by: Kevin Cai <kevin.cai@celerdata.com>
@kevincai kevincai requested a review from a team as a code owner May 1, 2026 08:36
@CelerData-Reviewer

Copy link
Copy Markdown

@codex review

@github-actions github-actions Bot requested a review from gengjun-git May 1, 2026 08:37
@github-actions

github-actions Bot commented May 1, 2026

Copy link
Copy Markdown
Contributor

[Java-Extensions Incremental Coverage Report]

pass : 0 / 0 (0%)

@github-actions

github-actions Bot commented May 1, 2026

Copy link
Copy Markdown
Contributor

[FE Incremental Coverage Report]

pass : 24 / 28 (85.71%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 com/starrocks/common/util/concurrent/lock/Locker.java 24 28 85.71% [330, 331, 337, 338]

@github-actions

github-actions Bot commented May 1, 2026

Copy link
Copy Markdown
Contributor

[BE Incremental Coverage Report]

pass : 0 / 0 (0%)

@alvin-phoenix-ai

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@alvin-phoenix-ai alvin-phoenix-ai merged commit f32f70b into StarRocks:main May 2, 2026
79 of 80 checks passed
@github-actions

github-actions Bot commented May 2, 2026

Copy link
Copy Markdown
Contributor

@Mergifyio backport branch-3.4

@github-actions

github-actions Bot commented May 2, 2026

Copy link
Copy Markdown
Contributor

@Mergifyio backport branch-4.0

@github-actions

github-actions Bot commented May 2, 2026

Copy link
Copy Markdown
Contributor

@Mergifyio backport branch-3.5

@github-actions

github-actions Bot commented May 2, 2026

Copy link
Copy Markdown
Contributor

@Mergifyio backport branch-4.1

@mergify

mergify Bot commented May 2, 2026

Copy link
Copy Markdown
Contributor

backport branch-3.4

✅ Backports have been created

Details

Cherry-pick of f32f70b has failed:

On branch mergify/bp/branch-3.4/pr-72423
Your branch is up to date with 'origin/branch-3.4'.

You are currently cherry-picking commit f32f70b5ca.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   fe/fe-core/src/test/java/com/starrocks/common/lock/TestLockInterface.java

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   fe/fe-core/src/main/java/com/starrocks/common/util/concurrent/lock/Locker.java

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

@mergify

mergify Bot commented May 2, 2026

Copy link
Copy Markdown
Contributor

backport branch-4.0

✅ Backports have been created

Details

@mergify

mergify Bot commented May 2, 2026

Copy link
Copy Markdown
Contributor

backport branch-3.5

✅ Backports have been created

Details

@mergify

mergify Bot commented May 2, 2026

Copy link
Copy Markdown
Contributor

backport branch-4.1

✅ Backports have been created

Details

wanpengfei-git pushed a commit that referenced this pull request May 2, 2026
…#72423) (#72480)

Signed-off-by: Kevin Cai <kevin.cai@celerdata.com>
Co-authored-by: Kevin Cai <kevin.cai@celerdata.com>
wanpengfei-git pushed a commit that referenced this pull request May 2, 2026
…#72423) (#72478)

Signed-off-by: Kevin Cai <kevin.cai@celerdata.com>
Co-authored-by: Kevin Cai <kevin.cai@celerdata.com>
wanpengfei-git pushed a commit that referenced this pull request May 2, 2026
…#72423) (#72479)

Signed-off-by: Kevin Cai <kevin.cai@celerdata.com>
Co-authored-by: Kevin Cai <kevin.cai@celerdata.com>
@kevincai

kevincai commented May 5, 2026

Copy link
Copy Markdown
Contributor Author

give up backport to branch-3.4

@kevincai kevincai deleted the bugfix/fix-locker-rollback-symmetric branch May 5, 2026 03:10
robd003 pushed a commit to robd003/starrocks that referenced this pull request May 6, 2026
wanpengfei-git pushed a commit that referenced this pull request May 6, 2026
…#72423) (backport #72479) (#72863)

Signed-off-by: Kevin Cai <kevin.cai@celerdata.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Kevin Cai <kevin.cai@celerdata.com>
xiangguangyxg pushed a commit to xiangguangyxg/starrocks that referenced this pull request May 7, 2026
…ks#72423)

Signed-off-by: Kevin Cai <kevin.cai@celerdata.com>
Signed-off-by: xiangguangyxg <xiangguangyxg@gmail.com>
meegoo pushed a commit to meegoo/starrocks that referenced this pull request May 29, 2026
…POST-1561)

Companion to the Locker-level rollback that already landed upstream
(StarRocks#72423, StarRocks#72789). Those PRs ensure that
`Locker.lock(Table|Tables)WithIntensiveDbLock` releases anything it partially
acquired before re-throwing. This commit closes the remaining symptom at the
PlannerMetaLocker layer.

Pre-fix behavior (the SmartNews 4.0.9 incident):

  caller: try { plannerMetaLocker.lock(); ... } finally { unlock(); }

  1. lock() iterates (db, tables) entries calling inner
     Locker.lockTablesWithIntensiveDbLock on each.
  2. The inner call throws on some entry (e.g. ERR_NO_FILES_FOUND in the
     FILES() planning path forcing the planner to bail, or a real
     LockException). Inner Locker rolls itself back — good.
  3. PlannerMetaLocker.lock() does NOT roll back any earlier (db, tables)
     entries that already succeeded; it just lets the exception propagate.
  4. The caller's finally calls unlock(), which blindly iterates the full
     `tables` map and releases entries that were never acquired.
  5. LockManager.release sees a Locker with no matching LockHolder and
     throws IllegalMonitorStateException: "Attempt to unlock lock, not
     locked by current locker" — surfaced to the client as ERROR 5600,
     masquerading as the original ERR_NO_FILES_FOUND.

Fix:

* `PlannerMetaLocker` now records `heldEntries` on successful lock()/tryLock().
  unlock() only releases entries in `heldEntries`, and is a no-op when null.
* lock() wraps its multi-db loop in try/catch: on failure it releases the
  earlier (db, tables) entries it had successfully acquired (in reverse
  order, best-effort with logging), clears `heldEntries`, and re-throws.
  Inner-layer rollback (already in upstream Locker) handles the failing
  entry itself; this outer rollback only addresses entries that fully
  succeeded before the failing one.
* AutoCloseable.close() → unlock() is now safe to call when lock() was
  never invoked or threw.

Tests:

* `PlannerMetaLockerRollbackTest` (new): unlock-without-lock,
  close-without-lock, normal lock/unlock round-trip, single-db rollback
  (inner fails), multi-db rollback (first db succeeds, second throws —
  asserts the first db's release happened).
* `LockerIntensiveLockRollbackTest` (new): regression test pinning the
  contract that the Locker-layer fix from StarRocks#72423/StarRocks#72789 provides — six
  cases (mid-loop failure, first-rid failure, db-intent failure,
  single-table variant, WRITE mode, success path), each verified by
  trying to acquire an exclusive WRITE on the rid afterward from a fresh
  Locker (any leaked IS/READ would time out the attempt).

Related: POST-1561.
meegoo pushed a commit to meegoo/starrocks that referenced this pull request Jun 1, 2026
…POST-1561)

Companion to the Locker-level rollback that already landed upstream
(StarRocks#72423, StarRocks#72789). Those PRs ensure that
`Locker.lock(Table|Tables)WithIntensiveDbLock` releases anything it partially
acquired before re-throwing. This commit closes the remaining symptom at the
PlannerMetaLocker layer.

Pre-fix behavior (the SmartNews 4.0.9 incident):

  caller: try { plannerMetaLocker.lock(); ... } finally { unlock(); }

  1. lock() iterates (db, tables) entries calling inner
     Locker.lockTablesWithIntensiveDbLock on each.
  2. The inner call throws on some entry (e.g. ERR_NO_FILES_FOUND in the
     FILES() planning path forcing the planner to bail, or a real
     LockException). Inner Locker rolls itself back — good.
  3. PlannerMetaLocker.lock() does NOT roll back any earlier (db, tables)
     entries that already succeeded; it just lets the exception propagate.
  4. The caller's finally calls unlock(), which blindly iterates the full
     `tables` map and releases entries that were never acquired.
  5. LockManager.release sees a Locker with no matching LockHolder and
     throws IllegalMonitorStateException: "Attempt to unlock lock, not
     locked by current locker" — surfaced to the client as ERROR 5600,
     masquerading as the original ERR_NO_FILES_FOUND.

Fix:

* `PlannerMetaLocker` now records `heldEntries` on successful lock()/tryLock().
  unlock() only releases entries in `heldEntries`, and is a no-op when null.
* lock() wraps its multi-db loop in try/catch: on failure it releases the
  earlier (db, tables) entries it had successfully acquired (in reverse
  order, best-effort with logging), clears `heldEntries`, and re-throws.
  Inner-layer rollback (already in upstream Locker) handles the failing
  entry itself; this outer rollback only addresses entries that fully
  succeeded before the failing one.
* AutoCloseable.close() → unlock() is now safe to call when lock() was
  never invoked or threw.

Tests:

* `PlannerMetaLockerRollbackTest` (new): unlock-without-lock,
  close-without-lock, normal lock/unlock round-trip, single-db rollback
  (inner fails), multi-db rollback (first db succeeds, second throws —
  asserts the first db's release happened).
* `LockerIntensiveLockRollbackTest` (new): regression test pinning the
  contract that the Locker-layer fix from StarRocks#72423/StarRocks#72789 provides — six
  cases (mid-loop failure, first-rid failure, db-intent failure,
  single-table variant, WRITE mode, success path), each verified by
  trying to acquire an exclusive WRITE on the rid afterward from a fresh
  Locker (any leaked IS/READ would time out the attempt).

Related: POST-1561.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants