A unit test program revealed a deadlock between sux_lock::u_x_upgrade() and sux_lock::u_lock() operations. The u_x_upgrade() operation is very rarely used, and contention with u_lock() is very rare. It has only been observed when using the non-default setting innodb_adaptive_hash_index=ON.
The futex-based implementation in the 10.6.0 server works correctly. Only the fallback to POSIX mutex and condition variables is affected. The following patch fixes the issue:
diff --git a/storage/innobase/include/rw_lock.h b/storage/innobase/include/rw_lock.h
|
index 94f59f761c0..3f1d76d8d97 100644
|
--- a/storage/innobase/include/rw_lock.h
|
+++ b/storage/innobase/include/rw_lock.h
|
@@ -161,13 +161,14 @@ class rw_lock
|
bool read_unlock()
|
{
|
auto l= lock.fetch_sub(1, std::memory_order_release);
|
+ DBUG_ASSERT(!(l & WRITER)); /* no write lock must have existed */
|
#ifdef SUX_LOCK_GENERIC
|
DBUG_ASSERT(~(WRITER_PENDING | UPDATER) & l); /* at least one read lock */
|
+ return (~(WRITER_PENDING | UPDATER) & l) == 1;
|
#else /* SUX_LOCK_GENERIC */
|
DBUG_ASSERT(~(WRITER_PENDING) & l); /* at least one read lock */
|
-#endif /* SUX_LOCK_GENERIC */
|
- DBUG_ASSERT(!(l & WRITER)); /* no write lock must have existed */
|
return (~WRITER_PENDING & l) == 1;
|
+#endif /* SUX_LOCK_GENERIC */
|
}
|
#ifdef SUX_LOCK_GENERIC
|
/** Release an update lock */
|
diff --git a/storage/innobase/sync/srw_lock.cc b/storage/innobase/sync/srw_lock.cc
|
index 63fc88285cb..b76194c89e3 100644
|
--- a/storage/innobase/sync/srw_lock.cc
|
+++ b/storage/innobase/sync/srw_lock.cc
|
@@ -111,13 +111,13 @@ void ssux_lock_low::update_lock(uint32_t l)
|
{
|
do
|
{
|
- if (l == WRITER_WAITING)
|
+ if ((l | UPDATER) == (UPDATER | WRITER_WAITING))
|
{
|
wake_writer:
|
pthread_mutex_lock(&mutex);
|
for (;;)
|
{
|
- if (l == WRITER_WAITING)
|
+ if ((l | UPDATER) == (UPDATER | WRITER_WAITING))
|
pthread_cond_signal(&cond_exclusive);
|
l= value();
|
if (!(l & WRITER_PENDING))
|
@@ -133,7 +133,7 @@ void ssux_lock_low::update_lock(uint32_t l)
|
ut_delay(srv_spin_wait_delay);
|
if (update_trylock(l))
|
return;
|
- else if (l == WRITER_WAITING)
|
+ else if ((l | UPDATER) == (UPDATER | WRITER_WAITING))
|
goto wake_writer;
|
}
|
|
The cause of the problem is that this implementation cannot remember more than one pending exclusive lock request. If multiple requests have been enqueued, the WRITER_WAITING flag will be cleared when the first waiting writer acquires the exclusive lock. If the other waiting writers are not woken up, the flag would not be set.
The refinement of the futex-based implementation (Linux, OpenBSD, Microsoft Windows) in MDEV-25404 is not affected by this, because we can reliably count up to 2,147,483,648 pending requests.
- is caused by
-
MDEV-24142
rw_lock_t has unnecessarily complex wait logic
-
-
Closed
{"report":{"fcp":1187,"ttfb":244,"pageVisibility":"visible","entityId":99138,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"3c8c07d4-d820-46a8-a8d0-00db46c96746","navigationType":0,"readyForUser":1273.1000003814697,"redirectCount":0,"resourceLoadedEnd":1305.8000001907349,"resourceLoadedStart":249.5,"resourceTiming":[{"duration":327.4000005722046,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bv2/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":249.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":249.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":576.9000005722046,"responseStart":0,"secureConnectionStart":0},{"duration":327.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2bv2/820016/12ta74/2380add21a9a1006587582385952de73/_/download/contextbatch/css/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true","startTime":249.80000019073486,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":249.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":577.3000001907349,"responseStart":0,"secureConnectionStart":0},{"duration":336.29999923706055,"initiatorType":"script","name":"https://jira.mariadb.org/s/e9b27a47da5fb0f74a35acd57e9847fb-CDN/lu2bv2/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":249.9000005722046,"connectEnd":249.9000005722046,"connectStart":249.9000005722046,"domainLookupEnd":249.9000005722046,"domainLookupStart":249.9000005722046,"fetchStart":249.9000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":249.9000005722046,"responseEnd":586.1999998092651,"responseStart":586.1999998092651,"secureConnectionStart":249.9000005722046},{"duration":377.30000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/c32eb0da7ad9831253f8397e6cc26afd-CDN/lu2bv2/820016/12ta74/2380add21a9a1006587582385952de73/_/download/contextbatch/js/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true","startTime":250.10000038146973,"connectEnd":250.10000038146973,"connectStart":250.10000038146973,"domainLookupEnd":250.10000038146973,"domainLookupStart":250.10000038146973,"fetchStart":250.10000038146973,"redirectEnd":0,"redirectStart":0,"requestStart":250.10000038146973,"responseEnd":627.4000005722046,"responseStart":627.4000005722046,"secureConnectionStart":250.10000038146973},{"duration":381.70000076293945,"initiatorType":"script","name":"https://jira.mariadb.org/s/bc0bcb146314416123c992714ee00ff7-CDN/lu2bv2/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":250.19999980926514,"connectEnd":250.19999980926514,"connectStart":250.19999980926514,"domainLookupEnd":250.19999980926514,"domainLookupStart":250.19999980926514,"fetchStart":250.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":250.19999980926514,"responseEnd":631.9000005722046,"responseStart":631.9000005722046,"secureConnectionStart":250.19999980926514},{"duration":382.1000003814697,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":250.5,"connectEnd":250.5,"connectStart":250.5,"domainLookupEnd":250.5,"domainLookupStart":250.5,"fetchStart":250.5,"redirectEnd":0,"redirectStart":0,"requestStart":250.5,"responseEnd":632.6000003814697,"responseStart":632.6000003814697,"secureConnectionStart":250.5},{"duration":382.4000005722046,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":250.69999980926514,"connectEnd":250.69999980926514,"connectStart":250.69999980926514,"domainLookupEnd":250.69999980926514,"domainLookupStart":250.69999980926514,"fetchStart":250.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":250.69999980926514,"responseEnd":633.1000003814697,"responseStart":633.1000003814697,"secureConnectionStart":250.69999980926514},{"duration":488,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2bv2/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":250.9000005722046,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":250.9000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":738.9000005722046,"responseStart":0,"secureConnectionStart":0},{"duration":382.80000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":251,"connectEnd":251,"connectStart":251,"domainLookupEnd":251,"domainLookupStart":251,"fetchStart":251,"redirectEnd":0,"redirectStart":0,"requestStart":251,"responseEnd":633.8000001907349,"responseStart":633.6999998092651,"secureConnectionStart":251},{"duration":487.80000019073486,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2bv2/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/css/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.css?jira.create.linked.issue=true","startTime":251.30000019073486,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":251.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":739.1000003814697,"responseStart":0,"secureConnectionStart":0},{"duration":383.19999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/s/719848dd97ebe0663199f49a3936487a-CDN/lu2bv2/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/js/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.js?jira.create.linked.issue=true&locale=en","startTime":251.4000005722046,"connectEnd":251.4000005722046,"connectStart":251.4000005722046,"domainLookupEnd":251.4000005722046,"domainLookupStart":251.4000005722046,"fetchStart":251.4000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":251.4000005722046,"responseEnd":634.6000003814697,"responseStart":634.6000003814697,"secureConnectionStart":251.4000005722046},{"duration":701.4000005722046,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":259,"connectEnd":259,"connectStart":259,"domainLookupEnd":259,"domainLookupStart":259,"fetchStart":259,"redirectEnd":0,"redirectStart":0,"requestStart":259,"responseEnd":960.4000005722046,"responseStart":960.4000005722046,"secureConnectionStart":259},{"duration":1025.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":259.6000003814697,"connectEnd":259.6000003814697,"connectStart":259.6000003814697,"domainLookupEnd":259.6000003814697,"domainLookupStart":259.6000003814697,"fetchStart":259.6000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":259.6000003814697,"responseEnd":1285.1000003814697,"responseStart":1285.1000003814697,"secureConnectionStart":259.6000003814697},{"duration":209.9000005722046,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":751.1999998092651,"connectEnd":751.1999998092651,"connectStart":751.1999998092651,"domainLookupEnd":751.1999998092651,"domainLookupStart":751.1999998092651,"fetchStart":751.1999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":751.1999998092651,"responseEnd":961.1000003814697,"responseStart":961.1000003814697,"secureConnectionStart":751.1999998092651},{"duration":228.80000019073486,"initiatorType":"link","name":"https://jira.mariadb.org/s/d5715adaadd168a9002b108b2b039b50-CDN/lu2bv2/820016/12ta74/be4b45e9cec53099498fa61c8b7acba4/_/download/contextbatch/css/jira.project.sidebar,-_super,-project.issue.navigator,-jira.general,-jira.browse.project,-jira.view.issue,-jira.global,-atl.general,-com.atlassian.jira.projects.sidebar.init/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true","startTime":1077,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1077,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1305.8000001907349,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":77,"responseStart":244,"responseEnd":259,"domLoading":248,"domInteractive":1342,"domContentLoadedEventStart":1342,"domContentLoadedEventEnd":1386,"domComplete":2384,"loadEventStart":2384,"loadEventEnd":2386,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1320.3000001907349},{"name":"bigPipe.sidebar-id.end","time":1321.1000003814697},{"name":"bigPipe.activity-panel-pipe-id.start","time":1321.4000005722046},{"name":"bigPipe.activity-panel-pipe-id.end","time":1323.9000005722046},{"name":"activityTabFullyLoaded","time":1402.1000003814697}],"measures":[],"correlationId":"b63a935e6afd9b","effectiveType":"4g","downlink":9.7,"rtt":0,"serverDuration":99,"dbReadsTimeInMs":11,"dbConnsTimeInMs":18,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}