From 5af7f696d5fbb99f63df60e9c62b5dec8ec2fcf9 Mon Sep 17 00:00:00 2001 From: Todd Christensen Date: Thu, 8 Feb 2018 16:01:33 -0800 Subject: [PATCH] Never delete all changelog rows. Otherwise, indexes get confused on MySQL restart. The changelog can start over at 1, and mview_state will be ahead. This causes incremental indexing to simply not execute. To prevent this, we always keep the highest version id row, which makes MySQL handle auto_increment as expected, even after a restart. --- .../Magento/Framework/Mview/View/Changelog.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/Mview/View/Changelog.php b/lib/internal/Magento/Framework/Mview/View/Changelog.php index 91caf66228360..e64ec6c3ab882 100644 --- a/lib/internal/Magento/Framework/Mview/View/Changelog.php +++ b/lib/internal/Magento/Framework/Mview/View/Changelog.php @@ -121,7 +121,15 @@ public function clear($versionId) throw new ChangelogTableNotExistsException(new Phrase("Table %1 does not exist", [$changelogTableName])); } - $this->connection->delete($changelogTableName, ['version_id <= ?' => (int)$versionId]); + // It's important we don't clear the latest value in the table. + // On restart, common versions of MySQL will reset the increment_id. + // This can be removed once the minimum requirements are raised to: + // * MySQL/Percona 8.0 + // * MariaDB 10.2.3 + $latestVersionId = $this->getVersion(); + $deleteVersionId = $versionId >= $latestVersionId ? $latestVersionId - 1 : $versionId; + + $this->connection->delete($changelogTableName, ['version_id <= ?' => (int)$deleteVersionId]); return true; }