Browse Source

MDEV-12266: Remove dict_table_is_discarded()

The predicate dict_table_is_discarded() checks whether
ALTER TABLE…DISCARD TABLESPACE has been executed.

Replace most occurrences of dict_table_is_discarded() with
checks of dict_table_t::space. A few checks for the flag
DICT_TF2_DISCARDED are necessary; write them inline.

Because !is_readable() implies !space, some checks for
dict_table_is_discarded() were redundant.
pull/759/head
Marko Mäkelä 8 years ago
parent
commit
5e84ea9634
  1. 10
      storage/innobase/dict/dict0crea.cc
  2. 2
      storage/innobase/dict/dict0dict.cc
  3. 2
      storage/innobase/dict/dict0stats.cc
  4. 6
      storage/innobase/fil/fil0fil.cc
  5. 2
      storage/innobase/fts/fts0fts.cc
  6. 12
      storage/innobase/handler/ha_innodb.cc
  7. 12
      storage/innobase/handler/handler0alter.cc
  8. 10
      storage/innobase/include/dict0dict.h
  9. 12
      storage/innobase/include/dict0dict.ic
  10. 5
      storage/innobase/include/dict0mem.h
  11. 2
      storage/innobase/row/row0log.cc
  12. 2
      storage/innobase/row/row0merge.cc
  13. 4
      storage/innobase/row/row0mysql.cc
  14. 2
      storage/innobase/row/row0sel.cc
  15. 2
      storage/innobase/row/row0trunc.cc
  16. 35
      storage/innobase/trx/trx0roll.cc

10
storage/innobase/dict/dict0crea.cc

@ -831,7 +831,7 @@ dict_create_index_tree_step(
dberr_t err = DB_SUCCESS; dberr_t err = DB_SUCCESS;
if (!index->is_readable() || dict_table_is_discarded(index->table)) {
if (!index->is_readable()) {
node->page_no = FIL_NULL; node->page_no = FIL_NULL;
} else { } else {
index->set_modified(mtr); index->set_modified(mtr);
@ -873,11 +873,7 @@ dict_create_index_tree_in_mem(
mtr_t mtr; mtr_t mtr;
ut_ad(mutex_own(&dict_sys->mutex)); ut_ad(mutex_own(&dict_sys->mutex));
if (index->type == DICT_FTS) {
/* FTS index does not need an index tree */
return(DB_SUCCESS);
}
ut_ad(!(index->type & DICT_FTS));
mtr_start(&mtr); mtr_start(&mtr);
mtr_set_log_mode(&mtr, MTR_LOG_NO_REDO); mtr_set_log_mode(&mtr, MTR_LOG_NO_REDO);
@ -885,7 +881,7 @@ dict_create_index_tree_in_mem(
/* Currently this function is being used by temp-tables only. /* Currently this function is being used by temp-tables only.
Import/Discard of temp-table is blocked and so this assert. */ Import/Discard of temp-table is blocked and so this assert. */
ut_ad(index->is_readable()); ut_ad(index->is_readable());
ut_ad(!dict_table_is_discarded(index->table));
ut_ad(!(index->table->flags2 & DICT_TF2_DISCARDED));
index->page = btr_create(index->type, index->table->space, index->page = btr_create(index->type, index->table->space,
index->id, index, NULL, &mtr); index->id, index, NULL, &mtr);

2
storage/innobase/dict/dict0dict.cc

@ -1591,7 +1591,7 @@ dict_table_rename_in_cache(
/* If the table is stored in a single-table tablespace, rename the /* If the table is stored in a single-table tablespace, rename the
.ibd file and rebuild the .isl file if needed. */ .ibd file and rebuild the .isl file if needed. */
if (dict_table_is_discarded(table)) {
if (!table->space) {
bool exists; bool exists;
char* filepath; char* filepath;

2
storage/innobase/dict/dict0stats.cc

@ -918,7 +918,7 @@ dict_stats_update_transient(
index = dict_table_get_first_index(table); index = dict_table_get_first_index(table);
if (dict_table_is_discarded(table)) {
if (!table->space) {
/* Nothing to do. */ /* Nothing to do. */
dict_stats_empty_table(table, true); dict_stats_empty_table(table, true);
return; return;

6
storage/innobase/fil/fil0fil.cc

@ -5049,8 +5049,7 @@ fil_mtr_rename_log(
const char* old_path = old_table->space->chain.start->name; const char* old_path = old_table->space->chain.start->name;
/* Temp filepath must not exist. */ /* Temp filepath must not exist. */
dberr_t err = fil_rename_tablespace_check( dberr_t err = fil_rename_tablespace_check(
old_path, tmp_path,
dict_table_is_discarded(old_table));
old_path, tmp_path, !old_table->space);
if (err != DB_SUCCESS) { if (err != DB_SUCCESS) {
ut_free(tmp_path); ut_free(tmp_path);
return(err); return(err);
@ -5072,8 +5071,7 @@ fil_mtr_rename_log(
TABLE starts and ends with a file_per-table tablespace. */ TABLE starts and ends with a file_per-table tablespace. */
if (!old_table->space_id) { if (!old_table->space_id) {
dberr_t err = fil_rename_tablespace_check( dberr_t err = fil_rename_tablespace_check(
new_path, old_path,
dict_table_is_discarded(new_table));
new_path, old_path, !new_table->space);
if (err != DB_SUCCESS) { if (err != DB_SUCCESS) {
ut_free(old_path); ut_free(old_path);
return(err); return(err);

2
storage/innobase/fts/fts0fts.cc

@ -4486,7 +4486,7 @@ fts_sync_table(
ut_ad(table->fts); ut_ad(table->fts);
if (!dict_table_is_discarded(table) && table->fts->cache
if (table->space && table->fts->cache
&& !dict_table_is_corrupted(table)) { && !dict_table_is_corrupted(table)) {
err = fts_sync(table->fts->cache->sync, err = fts_sync(table->fts->cache->sync,
unlock_cache, wait, has_dict); unlock_cache, wait, has_dict);

12
storage/innobase/handler/ha_innodb.cc

@ -6184,7 +6184,7 @@ no_such_table:
MONITOR_INC(MONITOR_TABLE_OPEN); MONITOR_INC(MONITOR_TABLE_OPEN);
if (dict_table_is_discarded(ib_table)) {
if ((ib_table->flags2 & DICT_TF2_DISCARDED)) {
ib_senderrf(thd, ib_senderrf(thd,
IB_LOG_LEVEL_WARN, ER_TABLESPACE_DISCARDED, IB_LOG_LEVEL_WARN, ER_TABLESPACE_DISCARDED,
@ -9976,7 +9976,7 @@ ha_innobase::ft_init_ext(
} }
/* If tablespace is discarded, we should return here */ /* If tablespace is discarded, we should return here */
if (dict_table_is_discarded(ft_table)) {
if (!ft_table->space) {
my_error(ER_NO_SUCH_TABLE, MYF(0), table->s->db.str, my_error(ER_NO_SUCH_TABLE, MYF(0), table->s->db.str,
table->s->table_name.str); table->s->table_name.str);
return(NULL); return(NULL);
@ -13369,7 +13369,7 @@ ha_innobase::records_in_range(
/* There exists possibility of not being able to find requested /* There exists possibility of not being able to find requested
index due to inconsistency between MySQL and InoDB dictionary info. index due to inconsistency between MySQL and InoDB dictionary info.
Necessary message should have been printed in innobase_get_index() */ Necessary message should have been printed in innobase_get_index() */
if (dict_table_is_discarded(m_prebuilt->table)) {
if (!m_prebuilt->table->space) {
n_rows = HA_POS_ERROR; n_rows = HA_POS_ERROR;
goto func_exit; goto func_exit;
} }
@ -14343,7 +14343,7 @@ ha_innobase::optimize(
if (innodb_optimize_fulltext_only) { if (innodb_optimize_fulltext_only) {
if (m_prebuilt->table->fts && m_prebuilt->table->fts->cache if (m_prebuilt->table->fts && m_prebuilt->table->fts->cache
&& !dict_table_is_discarded(m_prebuilt->table)) {
&& m_prebuilt->table->space) {
fts_sync_table(m_prebuilt->table, false, true, false); fts_sync_table(m_prebuilt->table, false, true, false);
fts_optimize_table(m_prebuilt->table); fts_optimize_table(m_prebuilt->table);
} }
@ -14385,7 +14385,7 @@ ha_innobase::check(
build_template(true); build_template(true);
} }
if (dict_table_is_discarded(m_prebuilt->table)) {
if (!m_prebuilt->table->space) {
ib_senderrf( ib_senderrf(
thd, thd,
@ -15500,7 +15500,7 @@ ha_innobase::external_lock(
&& thd_sql_command(thd) == SQLCOM_FLUSH && thd_sql_command(thd) == SQLCOM_FLUSH
&& lock_type == F_RDLCK) { && lock_type == F_RDLCK) {
if (dict_table_is_discarded(m_prebuilt->table)) {
if (!m_prebuilt->table->space) {
ib_senderrf(trx->mysql_thd, IB_LOG_LEVEL_ERROR, ib_senderrf(trx->mysql_thd, IB_LOG_LEVEL_ERROR,
ER_TABLESPACE_DISCARDED, ER_TABLESPACE_DISCARDED,
table->s->table_name.str); table->s->table_name.str);

12
storage/innobase/handler/handler0alter.cc

@ -5641,7 +5641,7 @@ error_handling_drop_uncached:
by a modification log. */ by a modification log. */
} else if (!ctx->online } else if (!ctx->online
|| !user_table->is_readable() || !user_table->is_readable()
|| dict_table_is_discarded(user_table)) {
|| !user_table->space) {
/* No need to allocate a modification log. */ /* No need to allocate a modification log. */
DBUG_ASSERT(!index->online_log); DBUG_ASSERT(!index->online_log);
} else { } else {
@ -7118,8 +7118,7 @@ ok_exit:
ctx->m_stage = UT_NEW_NOKEY(ut_stage_alter_t(pk)); ctx->m_stage = UT_NEW_NOKEY(ut_stage_alter_t(pk));
if (!m_prebuilt->table->is_readable()
|| dict_table_is_discarded(m_prebuilt->table)) {
if (!m_prebuilt->table->is_readable()) {
goto all_done; goto all_done;
} }
@ -8544,7 +8543,7 @@ commit_try_rebuild(
/* The new table must inherit the flag from the /* The new table must inherit the flag from the
"parent" table. */ "parent" table. */
if (dict_table_is_discarded(user_table)) {
if (!user_table->space) {
rebuilt_table->file_unreadable = true; rebuilt_table->file_unreadable = true;
rebuilt_table->flags2 |= DICT_TF2_DISCARDED; rebuilt_table->flags2 |= DICT_TF2_DISCARDED;
} }
@ -8596,8 +8595,7 @@ commit_cache_rebuild(
DBUG_ENTER("commit_cache_rebuild"); DBUG_ENTER("commit_cache_rebuild");
DEBUG_SYNC_C("commit_cache_rebuild"); DEBUG_SYNC_C("commit_cache_rebuild");
DBUG_ASSERT(ctx->need_rebuild()); DBUG_ASSERT(ctx->need_rebuild());
DBUG_ASSERT(dict_table_is_discarded(ctx->old_table)
== dict_table_is_discarded(ctx->new_table));
DBUG_ASSERT(!ctx->old_table->space == !ctx->new_table->space);
const char* old_name = mem_heap_strdup( const char* old_name = mem_heap_strdup(
ctx->heap, ctx->old_table->name.m_name); ctx->heap, ctx->old_table->name.m_name);
@ -9048,7 +9046,7 @@ alter_stats_rebuild(
{ {
DBUG_ENTER("alter_stats_rebuild"); DBUG_ENTER("alter_stats_rebuild");
if (dict_table_is_discarded(table)
if (!table->space
|| !dict_stats_is_persistent_enabled(table)) { || !dict_stats_is_persistent_enabled(table)) {
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }

10
storage/innobase/include/dict0dict.h

@ -1832,16 +1832,6 @@ dict_tf2_is_valid(
ulint flags, ulint flags,
ulint flags2); ulint flags2);
/********************************************************************//**
Check if the tablespace for the table has been discarded.
@return true if the tablespace has been discarded. */
UNIV_INLINE
bool
dict_table_is_discarded(
/*====================*/
const dict_table_t* table) /*!< in: table to check */
MY_ATTRIBUTE((warn_unused_result));
/*********************************************************************//** /*********************************************************************//**
This function should be called whenever a page is successfully This function should be called whenever a page is successfully
compressed. Updates the compression padding information. */ compressed. Updates the compression padding information. */

12
storage/innobase/include/dict0dict.ic

@ -1390,18 +1390,6 @@ dict_table_is_corrupted(
return(table->corrupted); return(table->corrupted);
} }
/********************************************************************//**
Check if the tablespace for the table has been discarded.
@return true if the tablespace has been discarded. */
UNIV_INLINE
bool
dict_table_is_discarded(
/*====================*/
const dict_table_t* table) /*!< in: table to check */
{
return(DICT_TF2_FLAG_IS_SET(table, DICT_TF2_DISCARDED));
}
/** Check if the table is found is a file_per_table tablespace. /** Check if the table is found is a file_per_table tablespace.
This test does not use table flags2 since some REDUNDANT tables in the This test does not use table flags2 since some REDUNDANT tables in the
system tablespace may have garbage in the MIX_LEN field where flags2 is system tablespace may have garbage in the MIX_LEN field where flags2 is

5
storage/innobase/include/dict0mem.h

@ -1921,10 +1921,7 @@ inline void dict_index_t::set_modified(mtr_t& mtr) const
mtr.set_named_space(table->space); mtr.set_named_space(table->space);
} }
inline bool dict_index_t::is_readable() const
{
return(UNIV_LIKELY(!table->file_unreadable));
}
inline bool dict_index_t::is_readable() const { return table->is_readable(); }
inline bool dict_index_t::is_instant() const inline bool dict_index_t::is_instant() const
{ {

2
storage/innobase/row/row0log.cc

@ -3938,7 +3938,7 @@ row_log_apply(
} }
if (error != DB_SUCCESS) { if (error != DB_SUCCESS) {
ut_a(!dict_table_is_discarded(index->table));
ut_ad(index->table->space);
/* We set the flag directly instead of invoking /* We set the flag directly instead of invoking
dict_set_corrupted_index_cache_only(index) here, dict_set_corrupted_index_cache_only(index) here,
because the index is not "public" yet. */ because the index is not "public" yet. */

2
storage/innobase/row/row0merge.cc

@ -4412,7 +4412,7 @@ row_merge_rename_tables_dict(
ut_free(old_path); ut_free(old_path);
} }
if (err == DB_SUCCESS && dict_table_is_discarded(new_table)) {
if (err == DB_SUCCESS && (new_table->flags2 & DICT_TF2_DISCARDED)) {
err = row_import_update_discarded_flag( err = row_import_update_discarded_flag(
trx, new_table->id, true); trx, new_table->id, true);
} }

4
storage/innobase/row/row0mysql.cc

@ -1369,7 +1369,7 @@ row_insert_for_mysql(
ut_a(prebuilt->magic_n == ROW_PREBUILT_ALLOCATED); ut_a(prebuilt->magic_n == ROW_PREBUILT_ALLOCATED);
ut_a(prebuilt->magic_n2 == ROW_PREBUILT_ALLOCATED); ut_a(prebuilt->magic_n2 == ROW_PREBUILT_ALLOCATED);
if (dict_table_is_discarded(prebuilt->table)) {
if (!prebuilt->table->space) {
ib::error() << "The table " << prebuilt->table->name ib::error() << "The table " << prebuilt->table->name
<< " doesn't have a corresponding tablespace, it was" << " doesn't have a corresponding tablespace, it was"
@ -4343,7 +4343,7 @@ row_rename_table_for_mysql(
goto funct_exit; goto funct_exit;
} else if (!table->is_readable() && !table->space } else if (!table->is_readable() && !table->space
&& !dict_table_is_discarded(table)) {
&& !(table->flags2 & DICT_TF2_DISCARDED)) {
err = DB_TABLE_NOT_FOUND; err = DB_TABLE_NOT_FOUND;

2
storage/innobase/row/row0sel.cc

@ -4218,7 +4218,7 @@ row_search_mvcc(
ut_ad(!sync_check_iterate(sync_check())); ut_ad(!sync_check_iterate(sync_check()));
if (dict_table_is_discarded(prebuilt->table)) {
if (!prebuilt->table->space) {
DBUG_RETURN(DB_TABLESPACE_DELETED); DBUG_RETURN(DB_TABLESPACE_DELETED);
} else if (!prebuilt->table->is_readable()) { } else if (!prebuilt->table->is_readable()) {
DBUG_RETURN(prebuilt->table->space DBUG_RETURN(prebuilt->table->space

2
storage/innobase/row/row0trunc.cc

@ -1580,7 +1580,7 @@ dberr_t
row_truncate_sanity_checks( row_truncate_sanity_checks(
const dict_table_t* table) const dict_table_t* table)
{ {
if (dict_table_is_discarded(table)) {
if (!table->space) {
return(DB_TABLESPACE_DELETED); return(DB_TABLESPACE_DELETED);

35
storage/innobase/trx/trx0roll.cc

@ -635,8 +635,6 @@ trx_rollback_active(
que_fork_t* fork; que_fork_t* fork;
que_thr_t* thr; que_thr_t* thr;
roll_node_t* roll_node; roll_node_t* roll_node;
dict_table_t* table;
ibool dictionary_locked = FALSE;
const trx_id_t trx_id = trx->id; const trx_id_t trx_id = trx->id;
ut_ad(trx_id); ut_ad(trx_id);
@ -659,9 +657,11 @@ trx_rollback_active(
trx_roll_crash_recv_trx = trx; trx_roll_crash_recv_trx = trx;
if (trx_get_dict_operation(trx) != TRX_DICT_OP_NONE) {
const bool dictionary_locked = trx_get_dict_operation(trx)
!= TRX_DICT_OP_NONE;
if (dictionary_locked) {
row_mysql_lock_data_dictionary(trx); row_mysql_lock_data_dictionary(trx);
dictionary_locked = TRUE;
} }
que_run_threads(thr); que_run_threads(thr);
@ -679,27 +679,16 @@ trx_rollback_active(
ut_a(trx->lock.que_state == TRX_QUE_RUNNING); ut_a(trx->lock.que_state == TRX_QUE_RUNNING);
if (trx_get_dict_operation(trx) != TRX_DICT_OP_NONE
&& trx->table_id != 0) {
ut_ad(dictionary_locked);
/* If the transaction was for a dictionary operation,
we drop the relevant table only if it is not flagged
as DISCARDED. If it still exists. */
if (!dictionary_locked || !trx->table_id) {
} else if (dict_table_t* table = dict_table_open_on_id(
trx->table_id, TRUE, DICT_TABLE_OP_NORMAL)) {
ib::info() << "Dropping table " << table->name
<< ", with id " << trx->table_id
<< " in recovery";
table = dict_table_open_on_id(
trx->table_id, TRUE, DICT_TABLE_OP_NORMAL);
dict_table_close_and_drop(trx, table);
if (table && !dict_table_is_discarded(table)) {
ib::warn() << "Dropping table '" << table->name
<< "', with id " << trx->table_id
<< " in recovery";
dict_table_close_and_drop(trx, table);
trx_commit_for_mysql(trx);
}
trx_commit_for_mysql(trx);
} }
ib::info() << "Rolled back recovered transaction " << trx_id; ib::info() << "Rolled back recovered transaction " << trx_id;

Loading…
Cancel
Save