Skip to content

[core] Surface JDBC lock acquisition failures - #10272

Open
LuciferYang wants to merge 1 commit into
apache:masterfrom
LuciferYang:m/core-094-jdbc-lock
Open

LuciferYang wants to merge 1 commit into
apache:masterfrom
LuciferYang:m/core-094-jdbc-lock

Conversation

@LuciferYang

Copy link
Copy Markdown
Contributor

Purpose

AbstractDistributedLockDialect.lockAcquire caught every SQLException and returned false, meaning "lock not acquired". Real contention does surface as a primary-key constraint violation on the lock row, so false is correct there, but a non-contention error (a dead pooled connection, a missing distributed_locks table, access denied) was swallowed the same way: JdbcCatalogLock.lock() then busy-spins for the whole lock-acquire timeout re-issuing the same failing INSERT and finally throws a generic Acquire lock failed with time: ... that hides the cause.

This returns false only for a constraint violation (contention) and rethrows any other SQLException, so a non-retryable failure fails fast with its root cause and the operator can tell "someone else holds the lock" apart from "the lock table is gone". Contention is classified by SQLState 23xxx or SQLIntegrityConstraintViolationException, with a message-substring fallback for dialects that report neither (SQLite, where the fallback is load-bearing). The high-value errors this surfaces (connection reset, missing table, column overflow) do not contain the fallback substrings, so they are not reclassified as contention.

This closes #10271.

Tests

  • testBrokenLockInsertSurfacesRootCause pins that a non-contention failure on the lock INSERT propagates instead of being retried for the full timeout.
  • testAcquireLockFail continues to pin that real contention returns false and times out as before.

API and Format

No.

Documentation

No.

lockAcquire converted every SQLException of the lock INSERT into
false, so anything but a held lock — a lock key exceeding the column
size, a missing lock table, a connection failover — silently spun for
the whole acquire timeout and then failed without a cause.

Treat only constraint violations as a held lock and rethrow the rest.

Assisted-by: GLM-5.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JDBC catalog lock swallows non-contention SQL errors as lock contention and busy-spins

1 participant