When I merged MDEV-13328 from 10.1 to 10.2, the innodb.innodb test suddenly started to fail.
The culprit seemed to be a correct-looking conflict resolution in FlushObserver::flush(). As part of the test, innodb.innodb is executing the following:
let $default=`select @@storage_engine`;
|
set storage_engine=INNODB;
|
source include/varchar.inc;
|
This includes the following:
--error ER_DUP_ENTRY
|
alter table t1 add unique(v);
|
The duplicate key error triggers the following code at the end of row_merge_build_indexes():
if (error != DB_SUCCESS) {
|
flush_observer->interrupted();
|
}
|
|
flush_observer->flush();
|
This in turn causes a choice of a dangerous parameter:
/** Flush dirty pages and wait. */
|
void
|
FlushObserver::flush()
|
{
|
/** Flush dirty pages and wait. */
|
void
|
FlushObserver::flush()
|
{
|
buf_remove_t buf_remove;
|
|
if (m_interrupted) {
|
buf_remove = BUF_REMOVE_FLUSH_NO_WRITE;
|
} else {
|
buf_remove = BUF_REMOVE_FLUSH_WRITE;
|
…
|
}
|
|
/* Flush or remove dirty pages. */
|
buf_LRU_flush_or_remove_pages(m_space_id, buf_remove, m_trx);
|
The danger here is that m_space_id=0, the system tablespace. This is potentially discarding other writes to the InnoDB system tablespace, potentially corrupting the whole instance.
We must use the equivalent of BUF_REMOVE_FLUSH_WRITE for the system tablespace (and in MySQL 5.7, for any table that resides in a persistent shared tablespace). Failure to do so caused all sorts of trouble when running innodb.innodb after the merge, especially when using --innodb-buffer-pool-size=5m (the minimum).
Apparently the corruption was caused by the following sequence of events:
- Some pages in the system tablespace are modified.
- The ADD UNIQUE INDEX operation runs and fails, and finally removes system tablespace pages from the buf_pool->flush_list without writing to the file (see above).
- Some affected not-written-back pages are evicted from the buffer pool.
- A page is eventually needed and read back to the buffer pool, with too old contents, or with all-zero contents.
Various assertions failed due to a supposedly-initialized page being all-zero.
Note: For a failed ALTER TABLE in a tablename.ibd file, it is perfectly OK to discard the entries from the flush_list, and to subsequently mark the pages as freed, or to delete the file (if it was a table-rebuilding ALTER).
{"report":{"fcp":1358.0999999046326,"ttfb":557.0999999046326,"pageVisibility":"visible","entityId":64162,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"69048c90-d87a-45ff-8e6a-a3b396d3af82","navigationType":0,"readyForUser":1450,"redirectCount":0,"resourceLoadedEnd":1086,"resourceLoadedStart":562.1999998092651,"resourceTiming":[{"duration":207.40000009536743,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":562.1999998092651,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":562.1999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":769.5999999046326,"responseStart":0,"secureConnectionStart":0},{"duration":207.7999997138977,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2bu7/820016/12ta74/8679b4946efa1a0bb029a3a22206fb5d/_/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":562.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":562.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":770.2999997138977,"responseStart":0,"secureConnectionStart":0},{"duration":391.69999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/s/fbf975c0cce4b1abf04784eeae9ba1f4-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":562.5999999046326,"connectEnd":562.5999999046326,"connectStart":562.5999999046326,"domainLookupEnd":562.5999999046326,"domainLookupStart":562.5999999046326,"fetchStart":562.5999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":780,"responseEnd":954.2999997138977,"responseStart":793.2999997138977,"secureConnectionStart":562.5999999046326},{"duration":236.69999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/s/94c15bff32baef80f4096a08aceae8bc-CDN/lu2bu7/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":562.6999998092651,"connectEnd":562.6999998092651,"connectStart":562.6999998092651,"domainLookupEnd":562.6999998092651,"domainLookupStart":562.6999998092651,"fetchStart":562.6999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":781,"responseEnd":799.3999996185303,"responseStart":798.3999996185303,"secureConnectionStart":562.6999998092651},{"duration":508.90000009536743,"initiatorType":"script","name":"https://jira.mariadb.org/s/099b33461394b8015fc36c0a4b96e19f-CDN/lu2bu7/820016/12ta74/8679b4946efa1a0bb029a3a22206fb5d/_/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":562.6999998092651,"connectEnd":562.6999998092651,"connectStart":562.6999998092651,"domainLookupEnd":562.6999998092651,"domainLookupStart":562.6999998092651,"fetchStart":562.6999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":780.1999998092651,"responseEnd":1071.5999999046326,"responseStart":794.5999999046326,"secureConnectionStart":562.6999998092651},{"duration":237.59999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":562.7999997138977,"connectEnd":562.7999997138977,"connectStart":562.7999997138977,"domainLookupEnd":562.7999997138977,"domainLookupStart":562.7999997138977,"fetchStart":562.7999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":781.2999997138977,"responseEnd":800.3999996185303,"responseStart":799.5999999046326,"secureConnectionStart":562.7999997138977},{"duration":243,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":562.8999996185303,"connectEnd":562.8999996185303,"connectStart":562.8999996185303,"domainLookupEnd":562.8999996185303,"domainLookupStart":562.8999996185303,"fetchStart":562.8999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":788.0999999046326,"responseEnd":805.8999996185303,"responseStart":805.0999999046326,"secureConnectionStart":562.8999996185303},{"duration":224.2999997138977,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2bu7/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":563,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":563,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":787.2999997138977,"responseStart":0,"secureConnectionStart":0},{"duration":245.59999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":563.0999999046326,"connectEnd":563.0999999046326,"connectStart":563.0999999046326,"domainLookupEnd":563.0999999046326,"domainLookupStart":563.0999999046326,"fetchStart":563.0999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":792.2999997138977,"responseEnd":808.6999998092651,"responseStart":807.7999997138977,"secureConnectionStart":563.0999999046326},{"duration":227.59999990463257,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2bu7/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":563.2999997138977,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":563.2999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":790.8999996185303,"responseStart":0,"secureConnectionStart":0},{"duration":254,"initiatorType":"script","name":"https://jira.mariadb.org/s/3339d87fa2538a859872f2df449bf8d0-CDN/lu2bu7/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":563.3999996185303,"connectEnd":563.3999996185303,"connectStart":563.3999996185303,"domainLookupEnd":563.3999996185303,"domainLookupStart":563.3999996185303,"fetchStart":563.3999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":795.5,"responseEnd":817.3999996185303,"responseStart":815.5,"secureConnectionStart":563.3999996185303},{"duration":515.6999998092651,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":569.1999998092651,"connectEnd":569.1999998092651,"connectStart":569.1999998092651,"domainLookupEnd":569.1999998092651,"domainLookupStart":569.1999998092651,"fetchStart":569.1999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":941.5,"responseEnd":1084.8999996185303,"responseStart":1081.0999999046326,"secureConnectionStart":569.1999998092651},{"duration":516.7000002861023,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":569.2999997138977,"connectEnd":569.2999997138977,"connectStart":569.2999997138977,"domainLookupEnd":569.2999997138977,"domainLookupStart":569.2999997138977,"fetchStart":569.2999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":1052.5999999046326,"responseEnd":1086,"responseStart":1082.7999997138977,"secureConnectionStart":569.2999997138977},{"duration":190.19999980926514,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1091.5999999046326,"connectEnd":1091.5999999046326,"connectStart":1091.5999999046326,"domainLookupEnd":1091.5999999046326,"domainLookupStart":1091.5999999046326,"fetchStart":1091.5999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":1241.8999996185303,"responseEnd":1281.7999997138977,"responseStart":1281,"secureConnectionStart":1091.5999999046326},{"duration":215.30000019073486,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1311.8999996185303,"connectEnd":1311.8999996185303,"connectStart":1311.8999996185303,"domainLookupEnd":1311.8999996185303,"domainLookupStart":1311.8999996185303,"fetchStart":1311.8999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":1490.0999999046326,"responseEnd":1527.1999998092651,"responseStart":1526.2999997138977,"secureConnectionStart":1311.8999996185303},{"duration":182.40000009536743,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":1351.3999996185303,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1351.3999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1533.7999997138977,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":325,"domainLookupEnd":337,"connectStart":337,"connectEnd":356,"secureConnectionStart":345,"requestStart":356,"responseStart":557,"responseEnd":564,"domLoading":560,"domInteractive":1555,"domContentLoadedEventStart":1555,"domContentLoadedEventEnd":1605,"domComplete":2057,"loadEventStart":2057,"loadEventEnd":2058,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1529.2999997138977},{"name":"bigPipe.sidebar-id.end","time":1530.0999999046326},{"name":"bigPipe.activity-panel-pipe-id.start","time":1530.2999997138977},{"name":"bigPipe.activity-panel-pipe-id.end","time":1531.5999999046326},{"name":"activityTabFullyLoaded","time":1625.2999997138977}],"measures":[],"correlationId":"df42e64843f0cc","effectiveType":"4g","downlink":9.8,"rtt":0,"serverDuration":111,"dbReadsTimeInMs":15,"dbConnsTimeInMs":23,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
Actually, the impact of this bug is more widespread than I initially thought.
During online table-rebuilding ALTER (say, DROP COLUMN, or ADD COLUMN before the instant variant
MDEV-11369in MariaDB 10.3.2), the code could discard changes from INSERT, UPDATE and other statements that were run concurrently with the failed or killed ALTER TABLE statement.Also locking ALGORITHM=INPLACE operations with innodb_file_per_table=1 may be affected, because LOCK=SHARED or LOCK=EXCLUSIVE does not prevent purge or change buffer merge from running.
Any ALGORITHM=INPLACE operation that involves ADD UNIQUE INDEX or ADD INDEX or rebuilding the table is potentially affected.