Thanks Jiri Slaby for the great bug report. The issue is easily reproducible from the supplied test case.
What happens here is that a normal deadlock is detected while allocating the next auto-increment value (--innodb-autoinc-lock-mode=1, the default). This takes a table lock on table `struct`, which in this case triggers a deadlock with another parallel transaction. The code is in ha_innobase::get_auto_increment():
void
ha_innobase::get_auto_increment(
...
error = innobase_get_autoinc(&autoinc);
if (error != DB_SUCCESS) {
*first_value = (~(ulonglong) 0);
/* This is an error case. We do the error handling by calling
the error code conversion function. Specifically, we need to
call thd_mark_transaction_to_rollback() to inform sql that we
have rolled back innodb transaction after a deadlock error. We
ignore the returned mysql error code here. */
std::ignore = convert_error_code_to_mysql(
error, m_prebuilt->table->flags, m_user_thd);
return;
}
As we see, the DB_DEADLOCK error is not propagated back to handler::update_auto_increment():
DBUG_RETURN(HA_ERR_AUTOINC_READ_FAILED); // Mark failure
So here the deadlock error turns into a HA_ERR_AUTOINC_READ_FAILED handler error, which later gets converted to the ER_AUTOINC_READ_FAILED.
In other words, the problem here is that the wrong error code is returned to the client for a normal deadlock error.
A work-around is to set --innodb-autoinc-lock-mode=2, then the auto-increment allocation no longer triggers a deadlock error.
Kristian Nielsen
added a comment - Thanks Jiri Slaby for the great bug report. The issue is easily reproducible from the supplied test case.
What happens here is that a normal deadlock is detected while allocating the next auto-increment value (--innodb-autoinc-lock-mode=1, the default). This takes a table lock on table `struct`, which in this case triggers a deadlock with another parallel transaction. The code is in ha_innobase::get_auto_increment():
void
ha_innobase::get_auto_increment(
...
error = innobase_get_autoinc(&autoinc);
if (error != DB_SUCCESS) {
*first_value = (~(ulonglong) 0);
/* This is an error case. We do the error handling by calling
the error code conversion function. Specifically, we need to
call thd_mark_transaction_to_rollback() to inform sql that we
have rolled back innodb transaction after a deadlock error. We
ignore the returned mysql error code here. */
std::ignore = convert_error_code_to_mysql(
error, m_prebuilt->table->flags, m_user_thd);
return;
}
As we see, the DB_DEADLOCK error is not propagated back to handler::update_auto_increment():
get_auto_increment(variables->auto_increment_offset,
variables->auto_increment_increment,
nb_desired_values, &nr,
&nb_reserved_values);
if (nr == ULONGLONG_MAX)
DBUG_RETURN(HA_ERR_AUTOINC_READ_FAILED); // Mark failure
So here the deadlock error turns into a HA_ERR_AUTOINC_READ_FAILED handler error, which later gets converted to the ER_AUTOINC_READ_FAILED.
In other words, the problem here is that the wrong error code is returned to the client for a normal deadlock error.
A work-around is to set --innodb-autoinc-lock-mode=2, then the auto-increment allocation no longer triggers a deadlock error.
The python script inserts into `source` (10 rows) and `struct` (500 rows) in parallel processes (nr=count of cpus). And the insertion to `struct` sometimes fails with the above error. This is a deduced (reduced) testcase, the same happens with the C binding.
Also if I retry – i.e. add ER.AUTOINC_READ_FAILED along with ER.LOCK_DEADLOCK. The second attempt usually succeeds. But I assume AUTOINC_READ_FAILED should not be raised in the first place.
Jiri Slaby
added a comment - - edited The python script inserts into `source` (10 rows) and `struct` (500 rows) in parallel processes (nr=count of cpus). And the insertion to `struct` sometimes fails with the above error. This is a deduced (reduced) testcase, the same happens with the C binding.
Also if I retry – i.e. add ER.AUTOINC_READ_FAILED along with ER.LOCK_DEADLOCK. The second attempt usually succeeds. But I assume AUTOINC_READ_FAILED should not be raised in the first place.
People
Oleksandr Byelkin
Jiri Slaby
Votes:
0Vote for this issue
Watchers:
4Start watching this issue
Dates
Created:
Updated:
Git Integration
Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.
{"report":{"fcp":1659.0999999046326,"ttfb":312.3999996185303,"pageVisibility":"visible","entityId":132993,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"0a3e4b6c-feaa-45f6-b16c-84cc7988ed82","navigationType":0,"readyForUser":1768.0999999046326,"redirectCount":0,"resourceLoadedEnd":2353.0999999046326,"resourceLoadedStart":320.8999996185303,"resourceTiming":[{"duration":760.4000000953674,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":320.8999996185303,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":320.8999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1081.2999997138977,"responseStart":0,"secureConnectionStart":0},{"duration":760.4000000953674,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/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&whisper-enabled=true","startTime":321.19999980926514,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":321.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1081.5999999046326,"responseStart":0,"secureConnectionStart":0},{"duration":758.9000000953674,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":321.3999996185303,"connectEnd":321.3999996185303,"connectStart":321.3999996185303,"domainLookupEnd":321.3999996185303,"domainLookupStart":321.3999996185303,"fetchStart":321.3999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":321.3999996185303,"responseEnd":1080.2999997138977,"responseStart":1080.2999997138977,"secureConnectionStart":321.3999996185303},{"duration":808,"initiatorType":"script","name":"https://jira.mariadb.org/s/2d8175ec2fa4c816e8023260bd8c1786-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/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&whisper-enabled=true","startTime":321.59999990463257,"connectEnd":321.59999990463257,"connectStart":321.59999990463257,"domainLookupEnd":321.59999990463257,"domainLookupStart":321.59999990463257,"fetchStart":321.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":321.59999990463257,"responseEnd":1129.5999999046326,"responseStart":1129.5999999046326,"secureConnectionStart":321.59999990463257},{"duration":815.7000002861023,"initiatorType":"script","name":"https://jira.mariadb.org/s/a9324d6758d385eb45c462685ad88f1d-CDN/lu2cib/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":321.7999997138977,"connectEnd":321.7999997138977,"connectStart":321.7999997138977,"domainLookupEnd":321.7999997138977,"domainLookupStart":321.7999997138977,"fetchStart":321.7999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":321.7999997138977,"responseEnd":1137.5,"responseStart":1137.5,"secureConnectionStart":321.7999997138977},{"duration":816.7999997138977,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":322.09999990463257,"connectEnd":322.09999990463257,"connectStart":322.09999990463257,"domainLookupEnd":322.09999990463257,"domainLookupStart":322.09999990463257,"fetchStart":322.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":322.09999990463257,"responseEnd":1138.8999996185303,"responseStart":1138.8999996185303,"secureConnectionStart":322.09999990463257},{"duration":817.0999999046326,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":322.2999997138977,"connectEnd":322.2999997138977,"connectStart":322.2999997138977,"domainLookupEnd":322.2999997138977,"domainLookupStart":322.2999997138977,"fetchStart":322.2999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":322.2999997138977,"responseEnd":1139.3999996185303,"responseStart":1139.3999996185303,"secureConnectionStart":322.2999997138977},{"duration":929.7999997138977,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2cib/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":322.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":322.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1252.2999997138977,"responseStart":0,"secureConnectionStart":0},{"duration":817.4000000953674,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":322.59999990463257,"connectEnd":322.59999990463257,"connectStart":322.59999990463257,"domainLookupEnd":322.59999990463257,"domainLookupStart":322.59999990463257,"fetchStart":322.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":322.59999990463257,"responseEnd":1140,"responseStart":1140,"secureConnectionStart":322.59999990463257},{"duration":929.8000001907349,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2cib/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":322.69999980926514,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":322.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1252.5,"responseStart":0,"secureConnectionStart":0},{"duration":819.3999996185303,"initiatorType":"script","name":"https://jira.mariadb.org/s/5d5e8fe91fbc506585e83ea3b62ccc4b-CDN/lu2cib/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":323,"connectEnd":323,"connectStart":323,"domainLookupEnd":323,"domainLookupStart":323,"fetchStart":323,"redirectEnd":0,"redirectStart":0,"requestStart":323,"responseEnd":1142.3999996185303,"responseStart":1142.3999996185303,"secureConnectionStart":323},{"duration":1719.6999998092651,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":341.69999980926514,"connectEnd":341.69999980926514,"connectStart":341.69999980926514,"domainLookupEnd":341.69999980926514,"domainLookupStart":341.69999980926514,"fetchStart":341.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":341.69999980926514,"responseEnd":2061.3999996185303,"responseStart":2061.3999996185303,"secureConnectionStart":341.69999980926514},{"duration":2011.3000001907349,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":341.7999997138977,"connectEnd":341.7999997138977,"connectStart":341.7999997138977,"domainLookupEnd":341.7999997138977,"domainLookupStart":341.7999997138977,"fetchStart":341.7999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":341.7999997138977,"responseEnd":2353.0999999046326,"responseStart":2353.0999999046326,"secureConnectionStart":341.7999997138977},{"duration":795.0999999046326,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1277.5999999046326,"connectEnd":1277.5999999046326,"connectStart":1277.5999999046326,"domainLookupEnd":1277.5999999046326,"domainLookupStart":1277.5999999046326,"fetchStart":1277.5999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":1277.5999999046326,"responseEnd":2072.699999809265,"responseStart":2072.699999809265,"secureConnectionStart":1277.5999999046326},{"duration":702.7999997138977,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":1651.5999999046326,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1651.5999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":2354.3999996185303,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":141,"responseStart":313,"responseEnd":337,"domLoading":320,"domInteractive":2393,"domContentLoadedEventStart":2393,"domContentLoadedEventEnd":2454,"domComplete":3304,"loadEventStart":3304,"loadEventEnd":3304,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":2355.2999997138977},{"name":"bigPipe.sidebar-id.end","time":2356.0999999046326},{"name":"bigPipe.activity-panel-pipe-id.start","time":2356.2999997138977},{"name":"bigPipe.activity-panel-pipe-id.end","time":2363},{"name":"activityTabFullyLoaded","time":2469.8999996185303}],"measures":[],"correlationId":"53562038ce8613","effectiveType":"4g","downlink":9.1,"rtt":0,"serverDuration":95,"dbReadsTimeInMs":12,"dbConnsTimeInMs":20,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
Thanks Jiri Slaby for the great bug report. The issue is easily reproducible from the supplied test case.
What happens here is that a normal deadlock is detected while allocating the next auto-increment value (--innodb-autoinc-lock-mode=1, the default). This takes a table lock on table `struct`, which in this case triggers a deadlock with another parallel transaction. The code is in ha_innobase::get_auto_increment():
void
ha_innobase::get_auto_increment(
...
error = innobase_get_autoinc(&autoinc);
if (error != DB_SUCCESS) {
*first_value = (~(ulonglong) 0);
/* This is an error case. We do the error handling by calling
the error code conversion function. Specifically, we need to
call thd_mark_transaction_to_rollback() to inform sql that we
have rolled back innodb transaction after a deadlock error. We
ignore the returned mysql error code here. */
std::ignore = convert_error_code_to_mysql(
error, m_prebuilt->table->flags, m_user_thd);
return;
}
As we see, the DB_DEADLOCK error is not propagated back to handler::update_auto_increment():
get_auto_increment(variables->auto_increment_offset,
variables->auto_increment_increment,
nb_desired_values, &nr,
&nb_reserved_values);
if (nr == ULONGLONG_MAX)
DBUG_RETURN(HA_ERR_AUTOINC_READ_FAILED); // Mark failure
So here the deadlock error turns into a HA_ERR_AUTOINC_READ_FAILED handler error, which later gets converted to the ER_AUTOINC_READ_FAILED.
In other words, the problem here is that the wrong error code is returned to the client for a normal deadlock error.
A work-around is to set --innodb-autoinc-lock-mode=2, then the auto-increment allocation no longer triggers a deadlock error.