Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-26954

Failed ALTER causes table corruption after recovery - Tablespace not found

Details

    Description

      --source include/have_innodb.inc
       
      CREATE TABLE t (pk INT PRIMARY KEY) ENGINE=InnoDB;
      --error ER_ERROR_ON_RENAME
      ALTER TABLE t ADD FOREIGN KEY (pk) REFERENCES t (pk);
       
      CHECK TABLE t;
       
      --let $shutdown_timeout= 0
      --source include/restart_mysqld.inc
       
      CHECK TABLE t;
       
      # Cleanup
      DROP TABLE t;
      

      10.6 fdc4c3a2

      ALTER TABLE t ADD FOREIGN KEY (pk) REFERENCES t (pk);
      ERROR HY000: Error on rename of './test/#sql-alter-25dc40-4' to './test/t' (errno: 150 "Foreign key constraint is incorrectly formed")
      CHECK TABLE t;
      Table	Op	Msg_type	Msg_text
      test.t	check	status	OK
      # restart
      CHECK TABLE t;
      Table	Op	Msg_type	Msg_text
      test.t	check	Error	Unknown storage engine 'InnoDB'
      test.t	check	error	Corrupt
      DROP TABLE t;
      bug.recovery2 'innodb'                   [ fail ]  Found warnings/errors in server log file!
              Test ended at 2021-11-02 01:18:32
      line
      2021-11-02  1:18:32 4 [ERROR] InnoDB: In ALTER TABLE `test`.`t` has or is referenced in foreign key constraints which are not compatible with the new table definition.
      2021-11-02  1:18:32 0 [ERROR] InnoDB: Tablespace 5 was not found at ./test/t.ibd.
      2021-11-02  1:18:32 0 [ERROR] InnoDB: Set innodb_force_recovery=1 to ignore this and to permanently lose all changes to the tablespace.
      2021-11-02  1:18:32 0 [ERROR] InnoDB: Plugin initialization aborted at srv0start.cc[1447] with error Tablespace not found
      2021-11-02  1:18:32 0 [ERROR] Plugin 'InnoDB' init function returned error.
      2021-11-02  1:18:32 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
      ^ Found warnings in /mnt-hd8t/bld/10.6-debug-nightly/mysql-test/var/log/mysqld.1.err
      

      So, after the failed ALTER the table still appears to be all right, but further crash recovery complains about a missing tablespace.

      Reproducible on 10.6 (including 10.6.4), 10.7. Not reproducible on 10.5.
      Reproducible every time for me, but since it's crash recovery imitated via MTR, it can well be non-deterministic.

      Attachments

        Issue Links

          Activity

            UndoLog recovery test ends with a slightly different representation of the same problem.
            The difference in the test flow is that after the induced "crash", the server is started with innodb_force_recovery=3, and then restarted normally.
            In MTR terms, it is this (mind the "sleep", the test is for reproducing purposes only):

            --source include/have_innodb.inc
             
            CREATE TABLE t (pk INT PRIMARY KEY) ENGINE=InnoDB;
            --error ER_ERROR_ON_RENAME
            ALTER TABLE t ADD FOREIGN KEY (pk) REFERENCES t (pk);
             
            CHECK TABLE t;
             
            --let $shutdown_timeout= 0
            --let $restart_parameters= --innodb-force-recovery=3
            --source include/restart_mysqld.inc
             
            --sleep 5
             
            --let $shutdown_timeout= 30
            --let $restart_parameters= --innodb-force-recovery=0
            --source include/restart_mysqld.inc
             
             
            CHECK TABLE t;
             
            # Cleanup
            DROP TABLE t;
            

            So, the restart with force-recovery complains

            bb-10.6-release 109fc67d4d

            2021-11-06 14:43:09 0 [Note] InnoDB: Starting crash recovery from checkpoint LSN=43379,43379
            2021-11-06 14:43:09 0 [Note] InnoDB: At LSN: 45922: unable to open file ./test/#sql-alter-136fdf-4.ibd for tablespace 6
            2021-11-06 14:43:09 0 [Note] InnoDB: At LSN: 47831: unable to open file ./test/#sql-backup-136fdf-4.ibd for tablespace 5
            2021-11-06 14:43:09 0 [Note] InnoDB: At LSN: 51738: unable to open file ./test/#sql-backup-136fdf-4.ibd for tablespace 5
            2021-11-06 14:43:09 0 [Warning] InnoDB: Tablespace 5 was not found at ./test/t.ibd, and innodb_force_recovery was set. All redo log for this tablespace will be ignored!
            

            and then the following normal restart says

            2021-11-06 14:43:15 3 [ERROR] InnoDB: Expected tablespace id 5 but found 0 in the file ./test/t.ibd
            2021-11-06 14:43:15 3 [ERROR] InnoDB: Table `test`.`t` is corrupted. Please drop the table and recreate.
            

            elenst Elena Stepanova added a comment - UndoLog recovery test ends with a slightly different representation of the same problem. The difference in the test flow is that after the induced "crash", the server is started with innodb_force_recovery=3 , and then restarted normally. In MTR terms, it is this (mind the "sleep", the test is for reproducing purposes only): --source include/have_innodb.inc CREATE TABLE t (pk INT PRIMARY KEY ) ENGINE=InnoDB; --error ER_ERROR_ON_RENAME ALTER TABLE t ADD FOREIGN KEY (pk) REFERENCES t (pk); CHECK TABLE t; --let $shutdown_timeout= 0 --let $restart_parameters= --innodb-force-recovery=3 --source include/restart_mysqld.inc   --sleep 5   --let $shutdown_timeout= 30 --let $restart_parameters= --innodb-force-recovery=0 --source include/restart_mysqld.inc   CHECK TABLE t; # Cleanup DROP TABLE t; So, the restart with force-recovery complains bb-10.6-release 109fc67d4d 2021-11-06 14:43:09 0 [Note] InnoDB: Starting crash recovery from checkpoint LSN=43379,43379 2021-11-06 14:43:09 0 [Note] InnoDB: At LSN: 45922: unable to open file ./test/#sql-alter-136fdf-4.ibd for tablespace 6 2021-11-06 14:43:09 0 [Note] InnoDB: At LSN: 47831: unable to open file ./test/#sql-backup-136fdf-4.ibd for tablespace 5 2021-11-06 14:43:09 0 [Note] InnoDB: At LSN: 51738: unable to open file ./test/#sql-backup-136fdf-4.ibd for tablespace 5 2021-11-06 14:43:09 0 [Warning] InnoDB: Tablespace 5 was not found at ./test/t.ibd, and innodb_force_recovery was set. All redo log for this tablespace will be ignored! and then the following normal restart says 2021-11-06 14:43:15 3 [ERROR] InnoDB: Expected tablespace id 5 but found 0 in the file ./test/t.ibd 2021-11-06 14:43:15 3 [ERROR] InnoDB: Table `test`.`t` is corrupted. Please drop the table and recreate.

            People

              thiru Thirunarayanan Balathandayuthapani
              elenst Elena Stepanova
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.