@@ -4,7 +4,7 @@ Copyright (c) 2000, 2018, Oracle and/or its affiliates. All Rights Reserved.
44Copyright (c) 2008, 2009 Google Inc.
55Copyright (c) 2009, Percona Inc.
66Copyright (c) 2012, Facebook Inc.
7- Copyright (c) 2013, 2018 , MariaDB Corporation.
7+ Copyright (c) 2013, 2019 , MariaDB Corporation.
88
99Portions of this file contain modifications contributed and copyrighted by
1010Google, Inc. Those modifications are gratefully acknowledged and are described
@@ -12700,22 +12700,19 @@ ha_innobase::discard_or_import_tablespace(
1270012700DBUG_RETURN(HA_ERR_TABLE_READONLY);
1270112701}
1270212702
12703- dict_table_t* dict_table = m_prebuilt->table;
12704-
12705- if (dict_table->is_temporary()) {
12706-
12703+ if (m_prebuilt->table->is_temporary()) {
1270712704ib_senderrf(
1270812705m_prebuilt->trx->mysql_thd, IB_LOG_LEVEL_ERROR,
1270912706ER_CANNOT_DISCARD_TEMPORARY_TABLE);
1271012707
1271112708DBUG_RETURN(HA_ERR_TABLE_NEEDS_UPGRADE);
1271212709}
1271312710
12714- if (dict_table ->space == fil_system.sys_space) {
12711+ if (m_prebuilt->table ->space == fil_system.sys_space) {
1271512712ib_senderrf(
1271612713m_prebuilt->trx->mysql_thd, IB_LOG_LEVEL_ERROR,
1271712714ER_TABLE_IN_SYSTEM_TABLESPACE,
12718- dict_table ->name.m_name);
12715+ m_prebuilt->table ->name.m_name);
1271912716
1272012717DBUG_RETURN(HA_ERR_TABLE_NEEDS_UPGRADE);
1272112718}
@@ -12724,7 +12721,7 @@ ha_innobase::discard_or_import_tablespace(
1272412721
1272512722/* Obtain an exclusive lock on the table. */
1272612723dberr_t err = row_mysql_lock_table(
12727- m_prebuilt->trx, dict_table , LOCK_X,
12724+ m_prebuilt->trx, m_prebuilt->table , LOCK_X,
1272812725discard ? "setting table lock for DISCARD TABLESPACE"
1272912726: "setting table lock for IMPORT TABLESPACE");
1273012727
@@ -12737,32 +12734,32 @@ ha_innobase::discard_or_import_tablespace(
1273712734user may want to set the DISCARD flag in order to IMPORT
1273812735a new tablespace. */
1273912736
12740- if (!dict_table ->is_readable()) {
12737+ if (!m_prebuilt->table ->is_readable()) {
1274112738ib_senderrf(
1274212739m_prebuilt->trx->mysql_thd,
1274312740IB_LOG_LEVEL_WARN, ER_TABLESPACE_MISSING,
12744- dict_table ->name.m_name);
12741+ m_prebuilt->table ->name.m_name);
1274512742}
1274612743
1274712744err = row_discard_tablespace_for_mysql(
12748- dict_table ->name.m_name, m_prebuilt->trx);
12745+ m_prebuilt->table ->name.m_name, m_prebuilt->trx);
1274912746
12750- } else if (dict_table ->is_readable()) {
12747+ } else if (m_prebuilt->table ->is_readable()) {
1275112748/* Commit the transaction in order to
1275212749release the table lock. */
1275312750trx_commit_for_mysql(m_prebuilt->trx);
1275412751
1275512752ib::error() << "Unable to import tablespace "
12756- << dict_table ->name << " because it already"
12753+ << m_prebuilt->table ->name << " because it already"
1275712754" exists. Please DISCARD the tablespace"
1275812755" before IMPORT.";
1275912756ib_senderrf(
1276012757m_prebuilt->trx->mysql_thd, IB_LOG_LEVEL_ERROR,
12761- ER_TABLESPACE_EXISTS, dict_table ->name.m_name);
12758+ ER_TABLESPACE_EXISTS, m_prebuilt->table ->name.m_name);
1276212759
1276312760DBUG_RETURN(HA_ERR_TABLE_EXIST);
1276412761} else {
12765- err = row_import_for_mysql(dict_table , m_prebuilt);
12762+ err = row_import_for_mysql(m_prebuilt->table , m_prebuilt);
1276612763
1276712764if (err == DB_SUCCESS) {
1276812765
@@ -12778,12 +12775,35 @@ ha_innobase::discard_or_import_tablespace(
1277812775/* Commit the transaction in order to release the table lock. */
1277912776trx_commit_for_mysql(m_prebuilt->trx);
1278012777
12781- if (err == DB_SUCCESS && !discard
12782- && dict_stats_is_persistent_enabled(dict_table)) {
12778+ if (discard || err != DB_SUCCESS) {
12779+ DBUG_RETURN(convert_error_code_to_mysql(
12780+ err, m_prebuilt->table->flags, NULL));
12781+ }
12782+
12783+ /* Evict and reload the table definition in order to invoke
12784+ btr_cur_instant_init(). */
12785+ table_id_t id = m_prebuilt->table->id;
12786+ ut_ad(id);
12787+ mutex_enter(&dict_sys->mutex);
12788+ dict_table_close(m_prebuilt->table, TRUE, FALSE);
12789+ dict_table_remove_from_cache(m_prebuilt->table);
12790+ m_prebuilt->table = dict_table_open_on_id(id, TRUE,
12791+ DICT_TABLE_OP_NORMAL);
12792+ mutex_exit(&dict_sys->mutex);
12793+ if (!m_prebuilt->table) {
12794+ err = DB_TABLE_NOT_FOUND;
12795+ } else {
12796+ if (const Field* ai = table->found_next_number_field) {
12797+ initialize_auto_increment(m_prebuilt->table, ai);
12798+ }
12799+ dict_stats_init(m_prebuilt->table);
12800+ }
12801+
12802+ if (dict_stats_is_persistent_enabled(m_prebuilt->table)) {
1278312803dberr_t ret;
1278412804
1278512805/* Adjust the persistent statistics. */
12786- ret = dict_stats_update(dict_table ,
12806+ ret = dict_stats_update(m_prebuilt->table ,
1278712807DICT_STATS_RECALC_PERSISTENT);
1278812808
1278912809if (ret != DB_SUCCESS) {
@@ -12793,11 +12813,12 @@ ha_innobase::discard_or_import_tablespace(
1279312813ER_ALTER_INFO,
1279412814"Error updating stats for table '%s'"
1279512815" after table rebuild: %s",
12796- dict_table->name.m_name, ut_strerr(ret));
12816+ m_prebuilt->table->name.m_name,
12817+ ut_strerr(ret));
1279712818}
1279812819}
1279912820
12800- DBUG_RETURN(convert_error_code_to_mysql(err, dict_table->flags, NULL) );
12821+ DBUG_RETURN(0 );
1280112822}
1280212823
1280312824/**
0 commit comments