Uploaded image for project: 'Percona Server for MySQL'
  1. Percona Server for MySQL
  2. PS-8073

Replication crash when updating a table with a stored generated field in the primary key

Details

    • Bug
    • Status: Done
    • Medium
    • Resolution: Fixed
    • 8.0.25-15 (Q2 2021), 8.0.26-16 (Q3 2021), 8.0.26-17 (Q3 2021 feature release)
    • 8.0.32-24 (Q1 2023)
    • None

    Description

      When updating versions 8.0.23-14 and 8.0.22-13 to any of the versions 8.0.25-15/8.0.26-16/8.0.26-17, replication began to fall.
      Last_SQL_Error: Could not execute Update_rows event on table testReplication.table_1; Can't find record in 'table_1', Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND; the event's master log mysql-bin.000003, end_log_pos 2171
      Enabling and disabling GTID mode, using single-threaded or multi-threaded replication did not change the results.
      Tested on:

      • master 8.0.23-14 or 8.0.22-13, slave 8.0.25-15 or 8.0.26-16 or 8.0.26-17
      • master 8.0.26-17, slave 8.0.26-17

      Reproduse instructions

      1)Preparing the structure and insert data on master

      drop database if exists testReplication;
      create database testReplication CHARACTER SET utf8mb4;use testReplication;
      
      CREATE TABLE `table_1` (
        `ownerId` binary(16) NOT NULL DEFAULT '\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0',
        `pageId` tinyint unsigned NOT NULL DEFAULT '1',
        `param1` int unsigned DEFAULT NULL,
        `param2` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
        `needToRemove` tinyint unsigned GENERATED ALWAYS AS ((`param1` is null) and (`param2` is null)) STORED NOT NULL,
        PRIMARY KEY (`ownerId`,`pageId`,`needToRemove`)
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='test table'
      /*!50100 PARTITION BY LIST (`needToRemove`)
      (PARTITION forRemove VALUES IN (1) ENGINE = InnoDB,
       PARTITION main VALUES IN (0) ENGINE = InnoDB) */;
      
      INSERT INTO `table_1` (`ownerId`, `pageId`, `param1`, `param2`) VALUES (0x93f213c750078811a5be227e832b715c, '1', 1, NULL), (0xfe218d10b6a0f75ad272ec6f76ef1e07, '1', 1, NULL) ON DUPLICATE KEY UPDATE `ownerId` = VALUES(`ownerId`), `pageId` = VALUES(`pageId`), `param1` = VALUES(`param1`), `param2` = VALUES(`param2`);

      2)Check replication on slave, output will be as usual, replication worked fine.

      show slave status \G
      

      3)Modify a single record using the INSERT ON DUPLICATE KEY UPDATE construct on master.

      INSERT INTO `table_1` (`ownerId`, `pageId`, `param1`, `param2`) VALUES (0xfe218d10b6a0f75ad272ec6f76ef1e07, '1', 1, 'test update') ON DUPLICATE KEY UPDATE `ownerId` = VALUES(`ownerId`), `pageId` = VALUES(`pageId`), `param1` = VALUES(`param1`), `param2` = VALUES(`param2`);
      
      

      4)Check replication on slave. Replication failed with an error.
      Last_SQL_Error: Could not execute Update_rows event on table testReplication.table_1; Can't find record in 'table_1', Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND; the event's master log mysql-bin.000003, end_log_pos 2171

      show slave status \G
      

      5)Docker reproduse instructions

      1) Download and unzip archive
      unzip dockerTest.zip ;cd dockerTest
      
      2) Build and start the docker image
      docker-compose up --build -d
      
      3) Preparing the structure and insert data
      docker exec -it mysql_master bash -l -c "mysql -u root -proot < /backup/initData.sql"
      
      4) Check replication
      docker exec -it mysql_slave mysql -u root -proot -e "show slave status \G"
      
      5) Update one row
      docker exec -it mysql_master bash -l -c "mysql -u root -proot < /backup/updateData.sql"
      
      6) Check replication
      docker exec -it mysql_slave mysql -u root -proot -e "show slave status \G"
      

      Attachments

        Issue Links

          Activity

            People

              amonar Anton Matvienko
              Mastervi Sergey
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Smart Checklist