Repository navigation
Conversation
…sages
The two RWLockImpl::getLock() fast-path assertions ("RWLock is already locked
in exclusive mode" and "Cannot acquire exclusive lock while RWLock is already
locked") are thrown when the requesting query_id is already an owner. Their
messages carried no context about who holds the lock, which makes the rare
CREATE OR REPLACE re-entrant deadlock (surfaced under stress) hard to diagnose:
there is no local reproducer and the only artifact is the exception text.
Add the requesting query_id, the requesting thread id, the number of locks the
requesting query_id already holds, and the full set of owner query_ids to both
messages. The requesting thread id can be correlated with the per-thread stack
dump BaseDaemon prints in the same fatal log to identify the holding thread,
and an owner count > 1 shows the query_id is held by multiple (sibling) threads.
Behavior-neutral: it only enriches two already-existing error strings. The owner
list is formatted by a small helper; the throw sites call it while
internal_state_mtx is already held, and the public getOwnerQueryIdsDescription()
keeps its short critical section (copy under the lock, then format). No new
bookkeeping on the lock hot path.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-author-slot-1:20260719-050200 |
Internal second-model review — adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 1 full pass + 1 delta recheck; behavior-neutral diagnostic change).
Severity: ❌ blocker / Session id: cron:clickhouse-author-slot-1:20260719-050200 |
|
cc @evillique @tavplubix — could you review this? It's a behavior-neutral diagnostic change: the two |
|
Workflow [PR], commit [763c487] Summary: ❌
AI ReviewSummaryThis PR makes the two Final Verdict✅ No blocking or major issues found in the current diff. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 17/23 (73.91%) · Uncovered code |
CI finish ledger — d2ccbafThis PR's diff is a behavior-neutral diagnostic change (RWLock re-entrancy assertion messages). Neither failure below is PR-caused; each has an owner.
Session id: cron:our-pr-ci-monitor:20260719-133000 |
|
Fixing PR for the stress-restart |
|
Fixing PR for LazyMaterializingTransform STID 4770-4443 created: #111003 |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 18/23 (78.26%) · Uncovered code |
CI finish ledger — 65cb446Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20260729-043000 |
|
Fixing PR for the |
| throw Exception(ErrorCodes::LOGICAL_ERROR, | ||
| "RWLockImpl::getLock(): RWLock is already locked in exclusive mode " | ||
| "(requested by query_id '{}' from thread {}; this query_id already holds {} lock(s); current owners: {})", | ||
| query_id, getThreadId(), owner_query_it->second, formatOwnerQueryIds(owner_queries)); |
There was a problem hiding this comment.
optional: drop the requester thread id — it duplicates the log-prefix thread_id and the exception's own captured backtrace, and the holder TID (the one you'd actually pivot from into a thread dump) isn't tracked anyway.
same for the message at line 168. query_id (the lock key) + owner set + hold count are the parts that are genuinely new, so those are worth keeping.
There was a problem hiding this comment.
Done, and verified rather than taken on faith: OwnPatternFormatter::formatExtended writes [ thread_id ] {query_id} from ExtendedLogMessage (src/Loggers/OwnPatternFormatter.cpp:33-50, ExtendedLogMessage.cpp:36), so the requester TID was redundant. Dropped from both messages, and the now-unused base/getThreadId.h include with it.
Your point about the lock key holds up in the code too, so query_id stays: callers pass getInitialQueryId() on some paths (InterpreterSelectQuery.cpp:645, InterpreterInsertQuery.cpp:1042), getCurrentQueryId() on others (InterpreterDeleteQuery, InterpreterDropQuery), and RWLockImpl::NO_QUERY from background threads (MergeTreeCleanupThread.cpp:41).
One thing your comment made me look at: locks taken with NO_QUERY never enter owner_queries (guarded at RWLock.cpp:245 and :305), so "current owners" promised a completeness the map does not have. Reworded to "current owner query_ids", matching IStorage::tryLockTimed.
Rendered messages now:
RWLock is already locked in exclusive mode (requested for query_id 'q_probe',
which already holds 1 lock(s); current owner query_ids: q_probe)
Cannot acquire exclusive lock while RWLock is already locked (requested for
query_id 'q_probe2', which already holds 2 read lock(s); current owner
query_ids: q_other, q_probe2 (2))
All 8 Common.RWLock* unit tests pass.
|
the description leads with adding |
Per review on ClickHouse#110971: the requester thread id duplicates the log-line prefix (OwnPatternFormatter writes `[ thread_id ] {query_id}` from ExtendedLogMessage) and the exception's own backtrace, and the holder TID is not tracked, so it is not the field you would pivot from into a thread dump. The in-message query_id is kept: it is the lock key passed to RWLockImpl::getLock(), which is getInitialQueryId() on some paths, getCurrentQueryId() on others and NO_QUERY in background threads, so it can differ from the ambient prefix query_id. The requester's hold count and the owner query_id set are also kept - they are the information not available anywhere else. The now-unused base/getThreadId.h include is removed.
Locks taken with NO_QUERY never enter owner_queries (RWLock.cpp:245 and :305 both guard on query_id != NO_QUERY), so the printed map is the set of named owners, not the complete holder set. "current owner query_ids" matches the wording already used by IStorage::tryLockTimed and does not promise completeness.
|
Reframed the title and description around the owner New title: "Report the owner query_ids and hold count in RWLock re-entrancy errors". The thread id is dropped from both messages per your inline comment (763c487), and "current owners" became "current owner query_ids" since |
CI finish ledger - 763c487Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
CI state on this head: 176 check-runs, 151 success / 24 skipped / 1 failure, 0 queued or Not caused by this PR: the diff is |
a521cf1
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
When an
RWLockImpl::getLock()re-entrancy assertion fires (RWLock is already locked in exclusive mode/Cannot acquire exclusive lock while RWLock is already locked), the error message now names the otherquery_ids currently owning the lock and how many locks the requestingquery_idalready holds, to make such lock-ordering errors diagnosable.Description
Related: #110893
The two fast-path re-entrancy assertions in
RWLockImpl::getLock()fire when the requestingquery_idis already present inowner_queries, but their messages named nothing at all - so the only artifact of a rare lock-ordering error was the bare sentence. That is the case for theCREATE OR REPLACE MATERIALIZED VIEW ... POPULATEre-entrant deadlock seen under stress, which has no local reproducer.Both messages now report:
query_ids, with a count next to anyquery_idheld by more than one thread - i.e. who else is holding the lock, which is not recoverable from anything else in the log;query_idalready holds - an owner count above one shows the re-entrancy is across sibling threads of the same query rather than a single nested acquisition;query_iditself. This is the lock key passed togetLock(), not the ambientquery_id: callers passgetInitialQueryId()on some paths (InterpreterSelectQuery,InterpreterInsertQuery),getCurrentQueryId()on others, andRWLockImpl::NO_QUERYfrom background threads, so it is not redundant with the log-line prefix.The requester thread id is deliberately not printed:
OwnPatternFormatteralready prefixes every line with[ thread_id ], and the holder TID - the one worth pivoting from into a thread dump - is not tracked. Locks taken withNO_QUERYnever enterowner_queries, hence the wording "owner query_ids" rather than "owners".Behaviour-neutral: two error strings, plus
getOwnerQueryIdsDescription()refactored to share the newformatOwnerQueryIds()helper. No new bookkeeping on the lock hot path; the publicgetOwnerQueryIds()API is unchanged. All 8Common.RWLock*unit tests pass.Version info
26.8.1.1672(included in26.8and later)