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).
Marko Mäkelä
made changes -
2017-11-07 13:28
Field
Original Value
New Value
Summary
ALTER TABLE…ADD INDEX may corrupt the InnoDB system tablespace
Possible corruption by table-rebuilding or index-creating ALTER TABLE…ALGORITHM=INPLACE
Marko Mäkelä
made changes -
2017-11-07 13:28
Affects Version/s
10.3.0
[ 22127
]
Marko Mäkelä
made changes -
2017-11-07 13:33
Status
Open
[ 1
]
Confirmed
[ 10101
]
Marko Mäkelä
made changes -
2017-11-07 21:04
Fix Version/s
10.2.11
[ 22634
]
Fix Version/s
10.3.3
[ 22644
]
Fix Version/s
10.2
[ 14601
]
Resolution
Fixed
[ 1
]
Status
Confirmed
[ 10101
]
Closed
[ 6
]
Marko Mäkelä
made changes -
2017-11-20 08:23
Resolution
Fixed
[ 1
]
Status
Closed
[ 6
]
Stalled
[ 10000
]
Marko Mäkelä
made changes -
2017-11-20 08:23
Labels
corruption ddl performance upstream
corruption ddl performance
Marko Mäkelä
made changes -
2017-11-20 08:23
Affects Version/s
10.2.11
[ 22634
]
Affects Version/s
10.3.3
[ 22644
]
Affects Version/s
10.2.2
[ 22013
]
Affects Version/s
10.3.0
[ 22127
]
Marko Mäkelä
made changes -
2017-11-20 08:23
Priority
Critical
[ 2
]
Blocker
[ 1
]
Marko Mäkelä
made changes -
2017-11-20 15:36
issue.field.resolutiondate
2017-11-20 15:36:25.0
2017-11-20 15:36:25.321
Marko Mäkelä
made changes -
2017-11-20 15:36
Resolution
Fixed
[ 1
]
Status
Stalled
[ 10000
]
Closed
[ 6
]
Sergei Golubchik
made changes -
2021-12-06 21:45
Workflow
MariaDB v3
[ 83663
]
MariaDB v4
[ 153132
]
{"report":{"fcp":1598.1000000238419,"ttfb":565.1000000238419,"pageVisibility":"visible","entityId":64162,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"ccc4adae-7c92-4d28-a17d-13bf609608f6","navigationType":0,"readyForUser":1700.8000000715256,"redirectCount":0,"resourceLoadedEnd":1756.3999999761581,"resourceLoadedStart":570.7000000476837,"resourceTiming":[{"duration":129.10000002384186,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":570.7000000476837,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":570.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":699.8000000715256,"responseStart":0,"secureConnectionStart":0},{"duration":129.5,"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":571,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":571,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":700.5,"responseStart":0,"secureConnectionStart":0},{"duration":499.59999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/fbf975c0cce4b1abf04784eeae9ba1f4-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":571.3000000715256,"connectEnd":571.3000000715256,"connectStart":571.3000000715256,"domainLookupEnd":571.3000000715256,"domainLookupStart":571.3000000715256,"fetchStart":571.3000000715256,"redirectEnd":0,"redirectStart":0,"requestStart":571.3000000715256,"responseEnd":1070.8999999761581,"responseStart":1070.8999999761581,"secureConnectionStart":571.3000000715256},{"duration":602.1000000238419,"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":571.6000000238419,"connectEnd":571.6000000238419,"connectStart":571.6000000238419,"domainLookupEnd":571.6000000238419,"domainLookupStart":571.6000000238419,"fetchStart":571.6000000238419,"redirectEnd":0,"redirectStart":0,"requestStart":571.6000000238419,"responseEnd":1173.7000000476837,"responseStart":1173.7000000476837,"secureConnectionStart":571.6000000238419},{"duration":605.6999999284744,"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":571.7000000476837,"connectEnd":571.7000000476837,"connectStart":571.7000000476837,"domainLookupEnd":571.7000000476837,"domainLookupStart":571.7000000476837,"fetchStart":571.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":571.7000000476837,"responseEnd":1177.3999999761581,"responseStart":1177.3999999761581,"secureConnectionStart":571.7000000476837},{"duration":605.7000000476837,"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":572,"connectEnd":572,"connectStart":572,"domainLookupEnd":572,"domainLookupStart":572,"fetchStart":572,"redirectEnd":0,"redirectStart":0,"requestStart":572,"responseEnd":1177.7000000476837,"responseStart":1177.7000000476837,"secureConnectionStart":572},{"duration":606.1000000238419,"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":572.1000000238419,"connectEnd":572.1000000238419,"connectStart":572.1000000238419,"domainLookupEnd":572.1000000238419,"domainLookupStart":572.1000000238419,"fetchStart":572.1000000238419,"redirectEnd":0,"redirectStart":0,"requestStart":572.1000000238419,"responseEnd":1178.2000000476837,"responseStart":1178.2000000476837,"secureConnectionStart":572.1000000238419},{"duration":641.0999999046326,"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":572.3000000715256,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":572.3000000715256,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1213.3999999761581,"responseStart":0,"secureConnectionStart":0},{"duration":606.3000000715256,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":572.3999999761581,"connectEnd":572.3999999761581,"connectStart":572.3999999761581,"domainLookupEnd":572.3999999761581,"domainLookupStart":572.3999999761581,"fetchStart":572.3999999761581,"redirectEnd":0,"redirectStart":0,"requestStart":572.3999999761581,"responseEnd":1178.7000000476837,"responseStart":1178.7000000476837,"secureConnectionStart":572.3999999761581},{"duration":641,"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":572.6000000238419,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":572.6000000238419,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1213.6000000238419,"responseStart":0,"secureConnectionStart":0},{"duration":606.5,"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":572.8000000715256,"connectEnd":572.8000000715256,"connectStart":572.8000000715256,"domainLookupEnd":572.8000000715256,"domainLookupStart":572.8000000715256,"fetchStart":572.8000000715256,"redirectEnd":0,"redirectStart":0,"requestStart":572.8000000715256,"responseEnd":1179.3000000715256,"responseStart":1179.3000000715256,"secureConnectionStart":572.8000000715256},{"duration":847.5,"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":579.2000000476837,"connectEnd":579.2000000476837,"connectStart":579.2000000476837,"domainLookupEnd":579.2000000476837,"domainLookupStart":579.2000000476837,"fetchStart":579.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":579.2000000476837,"responseEnd":1426.7000000476837,"responseStart":1426.7000000476837,"secureConnectionStart":579.2000000476837},{"duration":961.5,"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":579.2000000476837,"connectEnd":579.2000000476837,"connectStart":579.2000000476837,"domainLookupEnd":579.2000000476837,"domainLookupStart":579.2000000476837,"fetchStart":579.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":579.2000000476837,"responseEnd":1540.7000000476837,"responseStart":1540.7000000476837,"secureConnectionStart":579.2000000476837},{"duration":202.10000002384186,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1225,"connectEnd":1225,"connectStart":1225,"domainLookupEnd":1225,"domainLookupStart":1225,"fetchStart":1225,"redirectEnd":0,"redirectStart":0,"requestStart":1225,"responseEnd":1427.1000000238419,"responseStart":1427.1000000238419,"secureConnectionStart":1225},{"duration":93.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/d5715adaadd168a9002b108b2b039b50-CDN/lu2bu7/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":1497.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1497.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1591,"responseStart":0,"secureConnectionStart":0},{"duration":253.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/e65b778d185daf5aee24936755b43da6/_/download/contextbatch/js/browser-metrics-plugin.contrib,-_super,-project.issue.navigator,-jira.view.issue,-atl.general/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true","startTime":1498.3999999761581,"connectEnd":1498.3999999761581,"connectStart":1498.3999999761581,"domainLookupEnd":1498.3999999761581,"domainLookupStart":1498.3999999761581,"fetchStart":1498.3999999761581,"redirectEnd":0,"redirectStart":0,"requestStart":1498.3999999761581,"responseEnd":1751.8999999761581,"responseStart":1751.8999999761581,"secureConnectionStart":1498.3999999761581},{"duration":202.30000007152557,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":1590.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1590.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1792.8000000715256,"responseStart":0,"secureConnectionStart":0},{"duration":257.59999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/f51ef5507eea4c158f257c66c93b2a3f-CDN/lu2bu7/820016/12ta74/be4b45e9cec53099498fa61c8b7acba4/_/download/contextbatch/js/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.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true","startTime":1498.8000000715256,"connectEnd":1498.8000000715256,"connectStart":1498.8000000715256,"domainLookupEnd":1498.8000000715256,"domainLookupStart":1498.8000000715256,"fetchStart":1498.8000000715256,"redirectEnd":0,"redirectStart":0,"requestStart":1498.8000000715256,"responseEnd":1756.3999999761581,"responseStart":1756.3999999761581,"secureConnectionStart":1498.8000000715256}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":324,"responseStart":565,"responseEnd":577,"domLoading":568,"domInteractive":1796,"domContentLoadedEventStart":1796,"domContentLoadedEventEnd":1859,"domComplete":2169,"loadEventStart":2169,"loadEventEnd":2170,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1758.2000000476837},{"name":"bigPipe.sidebar-id.end","time":1758.8999999761581},{"name":"bigPipe.activity-panel-pipe-id.start","time":1759.1000000238419},{"name":"bigPipe.activity-panel-pipe-id.end","time":1764.2000000476837},{"name":"activityTabFullyLoaded","time":1882.8999999761581}],"measures":[],"correlationId":"ec9c114208970b","effectiveType":"4g","downlink":9.1,"rtt":0,"serverDuration":169,"dbReadsTimeInMs":34,"dbConnsTimeInMs":44,"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.