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

IMPORT TABLESPACE fails to adjust all tablespace ID in root pages




      I happened to get this crash today once on a 10.5-based branch.


      CURRENT_TEST: innodb.innodb-wl5522-debug
      mysqltest: At line 1138: query 'ALTER TABLE test_wl5522.t1 IMPORT TABLESPACE' failed: 2013: Lost connection to MySQL server during query
      2020-01-21 15:20:37 3 [Note] InnoDB: Phase IV - Flush complete
      2020-01-21 15:20:37 3 [Note] InnoDB: `test_wl5522`.`t1` autoinc value set to 248
      2020-01-21 15:20:37 0x7f10499c9700  InnoDB: Assertion failure in file /mariadb/10.5-MDEV-12353/storage/innobase/btr/btr0btr.cc line 204
      InnoDB: Failing assertion: mach_read_from_4(seg_header + FSEG_HDR_SPACE) == space
      #6  0x00005599e08d7f49 in btr_root_block_get (index=0x7f101c0e9c88, mode=<optimized out>, mtr=<optimized out>) at /mariadb/10.5-MDEV-12353/storage/innobase/btr/btr0btr.cc:243
      #7  0x00005599e08d7f8e in btr_root_get (index=0x2, mtr=0x0) at /mariadb/10.5-MDEV-12353/storage/innobase/btr/btr0btr.cc:271
      #8  0x00005599e0903b90 in btr_cur_instant_init_low (index=<optimized out>, mtr=0x7f10499c5f90) at /mariadb/10.5-MDEV-12353/storage/innobase/btr/btr0cur.cc:409
      #9  btr_cur_instant_init (table=<optimized out>) at /mariadb/10.5-MDEV-12353/storage/innobase/btr/btr0cur.cc:662
      #10 0x00005599e09bfaea in dict_load_table_one (name=..., ignore_err=<optimized out>, fk_tables=...) at /mariadb/10.5-MDEV-12353/storage/innobase/dict/dict0load.cc:3011
      #11 0x00005599e09bd4ae in dict_load_table (name=0x7f101c071518 "test_wl5522/t1", ignore_err=DICT_ERR_IGNORE_FK_NOKEY) at /mariadb/10.5-MDEV-12353/storage/innobase/dict/dict0load.cc:2742
      #12 0x00005599e09c0e0f in dict_load_table_on_id (table_id=<optimized out>, ignore_err=<optimized out>) at /mariadb/10.5-MDEV-12353/storage/innobase/dict/dict0load.cc:3179
      #13 0x00005599e09a439f in dict_table_open_on_id_low (table_id=86, ignore_err=1234983936, cached_only=<optimized out>) at /mariadb/10.5-MDEV-12353/storage/innobase/dict/dict0dict.cc:225
      #14 dict_table_open_on_id (table_id=86, dict_locked=true, table_op=DICT_TABLE_OP_NORMAL, thd=0x0, mdl=0x0) at /mariadb/10.5-MDEV-12353/storage/innobase/dict/dict0dict.cc:933
      #15 0x00005599e06999dc in ha_innobase::discard_or_import_tablespace (this=0x7f101c11a520, discard=<optimized out>) at /mariadb/10.5-MDEV-12353/storage/innobase/handler/ha_innodb.cc:13396
      #16 0x00005599e01c1d1e in mysql_discard_or_import_tablespace (thd=0x7f101c000cf8, table_list=0x7f101c014c98, discard=false) at /mariadb/10.5-MDEV-12353/sql/sql_table.cc:5972
      #17 0x00005599e023f2ab in Sql_cmd_discard_import_tablespace::execute (this=0x7f101c015358, thd=0x7f101c000cf8) at /mariadb/10.5-MDEV-12353/sql/sql_alter.cc:559
      #18 0x00005599e010a8ac in mysql_execute_command (thd=0x7f101c000cf8) at /mariadb/10.5-MDEV-12353/sql/sql_parse.cc:5959
      #19 0x00005599e0105818 in mysql_parse (thd=0x7f101c000cf8, rawbuf=0x7f101c014b80 "ALTER TABLE test_wl5522.t1 IMPORT TABLESPACE", length=<optimized out>, parser_state=<optimized out>, is_com_multi=<optimized out>, is_next_command=<optimized out>) at /mariadb/10.5-MDEV-12353/sql/sql_parse.cc:7988

      The following code was added to ha_innobase::discard_or_import_tablespace() in MDEV-18295:

             /* Evict and reload the table definition in order to invoke
             btr_cur_instant_init(). */
             table_id_t id = m_prebuilt->table->id;
             dict_table_close(m_prebuilt->table, TRUE, FALSE);
             m_prebuilt->table = dict_table_open_on_id(id, TRUE,

      I believe that the check called by btr_cur_instant_init_low() must be relaxed. It is a hard assertion, affecting non-debug builds as well, because UNIV_BTR_DEBUG is always enabled. That is why I am setting this to Critical.

      We should not crash, but return a failure to the caller of btr_cur_instant_init_low(). This may require specializing the btr_root_get() call.

      Furthermore, when opening the table during IMPORT TABLESPACE, we must either suppress the tablespace ID validation, or we should temporarily set table->space_id to the ID that is present in the tablespace file.

      Last but not least, during IMPORT TABLESPACE, the call to btr_cur_instant_init_low() must not fetch an older page from the buffer pool (it might be there after DISCARD TABLESPACE), but actually read the page from the file. See also the related 10.4+ bug MDEV-18543.


        Issue Links



              marko Marko Mäkelä
              marko Marko Mäkelä
              2 Vote for this issue
              8 Start watching this issue



                Git Integration

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