Skip to content

Commit

Permalink
MDEV-12266: Remove dict_table_is_discarded()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dr-m committed May 12, 2018
1 parent c57e983 commit 5e84ea9
Show file tree
Hide file tree
Showing 16 changed files with 38 additions and 82 deletions.
10 changes: 3 additions & 7 deletions storage/innobase/dict/dict0crea.cc
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ dict_create_index_tree_step(

dberr_t err = DB_SUCCESS;

if (!index->is_readable() || dict_table_is_discarded(index->table)) {
if (!index->is_readable()) {
node->page_no = FIL_NULL;
} else {
index->set_modified(mtr);
Expand Down Expand Up @@ -873,19 +873,15 @@ dict_create_index_tree_in_mem(
mtr_t mtr;

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_set_log_mode(&mtr, MTR_LOG_NO_REDO);

/* Currently this function is being used by temp-tables only.
Import/Discard of temp-table is blocked and so this assert. */
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->id, index, NULL, &mtr);
Expand Down
2 changes: 1 addition & 1 deletion storage/innobase/dict/dict0dict.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1591,7 +1591,7 @@ dict_table_rename_in_cache(
/* If the table is stored in a single-table tablespace, rename the
.ibd file and rebuild the .isl file if needed. */

if (dict_table_is_discarded(table)) {
if (!table->space) {
bool exists;
char* filepath;

Expand Down
2 changes: 1 addition & 1 deletion storage/innobase/dict/dict0stats.cc
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ dict_stats_update_transient(

index = dict_table_get_first_index(table);

if (dict_table_is_discarded(table)) {
if (!table->space) {
/* Nothing to do. */
dict_stats_empty_table(table, true);
return;
Expand Down
6 changes: 2 additions & 4 deletions storage/innobase/fil/fil0fil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5049,8 +5049,7 @@ fil_mtr_rename_log(
const char* old_path = old_table->space->chain.start->name;
/* Temp filepath must not exist. */
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) {
ut_free(tmp_path);
return(err);
Expand All @@ -5072,8 +5071,7 @@ fil_mtr_rename_log(
TABLE starts and ends with a file_per-table tablespace. */
if (!old_table->space_id) {
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) {
ut_free(old_path);
return(err);
Expand Down
2 changes: 1 addition & 1 deletion storage/innobase/fts/fts0fts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4486,7 +4486,7 @@ fts_sync_table(

ut_ad(table->fts);

if (!dict_table_is_discarded(table) && table->fts->cache
if (table->space && table->fts->cache
&& !dict_table_is_corrupted(table)) {
err = fts_sync(table->fts->cache->sync,
unlock_cache, wait, has_dict);
Expand Down
12 changes: 6 additions & 6 deletions storage/innobase/handler/ha_innodb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6184,7 +6184,7 @@ ha_innobase::open(const char* name, int, uint)

MONITOR_INC(MONITOR_TABLE_OPEN);

if (dict_table_is_discarded(ib_table)) {
if ((ib_table->flags2 & DICT_TF2_DISCARDED)) {

ib_senderrf(thd,
IB_LOG_LEVEL_WARN, ER_TABLESPACE_DISCARDED,
Expand Down Expand Up @@ -9976,7 +9976,7 @@ ha_innobase::ft_init_ext(
}

/* 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,
table->s->table_name.str);
return(NULL);
Expand Down Expand Up @@ -13369,7 +13369,7 @@ ha_innobase::records_in_range(
/* There exists possibility of not being able to find requested
index due to inconsistency between MySQL and InoDB dictionary info.
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;
goto func_exit;
}
Expand Down Expand Up @@ -14343,7 +14343,7 @@ ha_innobase::optimize(

if (innodb_optimize_fulltext_only) {
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_optimize_table(m_prebuilt->table);
}
Expand Down Expand Up @@ -14385,7 +14385,7 @@ ha_innobase::check(
build_template(true);
}

if (dict_table_is_discarded(m_prebuilt->table)) {
if (!m_prebuilt->table->space) {

ib_senderrf(
thd,
Expand Down Expand Up @@ -15500,7 +15500,7 @@ ha_innobase::external_lock(
&& thd_sql_command(thd) == SQLCOM_FLUSH
&& 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,
ER_TABLESPACE_DISCARDED,
table->s->table_name.str);
Expand Down
12 changes: 5 additions & 7 deletions storage/innobase/handler/handler0alter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5641,7 +5641,7 @@ prepare_inplace_alter_table_dict(
by a modification log. */
} else if (!ctx->online
|| !user_table->is_readable()
|| dict_table_is_discarded(user_table)) {
|| !user_table->space) {
/* No need to allocate a modification log. */
DBUG_ASSERT(!index->online_log);
} else {
Expand Down Expand Up @@ -7118,8 +7118,7 @@ ha_innobase::inplace_alter_table(

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;
}

Expand Down Expand Up @@ -8544,7 +8543,7 @@ commit_try_rebuild(

/* The new table must inherit the flag from the
"parent" table. */
if (dict_table_is_discarded(user_table)) {
if (!user_table->space) {
rebuilt_table->file_unreadable = true;
rebuilt_table->flags2 |= DICT_TF2_DISCARDED;
}
Expand Down Expand Up @@ -8596,8 +8595,7 @@ commit_cache_rebuild(
DBUG_ENTER("commit_cache_rebuild");
DEBUG_SYNC_C("commit_cache_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(
ctx->heap, ctx->old_table->name.m_name);
Expand Down Expand Up @@ -9048,7 +9046,7 @@ alter_stats_rebuild(
{
DBUG_ENTER("alter_stats_rebuild");

if (dict_table_is_discarded(table)
if (!table->space
|| !dict_stats_is_persistent_enabled(table)) {
DBUG_VOID_RETURN;
}
Expand Down
10 changes: 0 additions & 10 deletions storage/innobase/include/dict0dict.h
Original file line number Diff line number Diff line change
Expand Up @@ -1832,16 +1832,6 @@ dict_tf2_is_valid(
ulint flags,
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
compressed. Updates the compression padding information. */
Expand Down
12 changes: 0 additions & 12 deletions storage/innobase/include/dict0dict.ic
Original file line number Diff line number Diff line change
Expand Up @@ -1390,18 +1390,6 @@ dict_table_is_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.
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
Expand Down
5 changes: 1 addition & 4 deletions storage/innobase/include/dict0mem.h
Original file line number Diff line number Diff line change
Expand Up @@ -1921,10 +1921,7 @@ inline void dict_index_t::set_modified(mtr_t& mtr) const
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
{
Expand Down
2 changes: 1 addition & 1 deletion storage/innobase/row/row0log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3938,7 +3938,7 @@ row_log_apply(
}

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
dict_set_corrupted_index_cache_only(index) here,
because the index is not "public" yet. */
Expand Down
2 changes: 1 addition & 1 deletion storage/innobase/row/row0merge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4412,7 +4412,7 @@ row_merge_rename_tables_dict(
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(
trx, new_table->id, true);
}
Expand Down
4 changes: 2 additions & 2 deletions storage/innobase/row/row0mysql.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1369,7 +1369,7 @@ row_insert_for_mysql(
ut_a(prebuilt->magic_n == 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
<< " doesn't have a corresponding tablespace, it was"
Expand Down Expand Up @@ -4343,7 +4343,7 @@ row_rename_table_for_mysql(
goto funct_exit;

} else if (!table->is_readable() && !table->space
&& !dict_table_is_discarded(table)) {
&& !(table->flags2 & DICT_TF2_DISCARDED)) {

err = DB_TABLE_NOT_FOUND;

Expand Down
2 changes: 1 addition & 1 deletion storage/innobase/row/row0sel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4218,7 +4218,7 @@ row_search_mvcc(

ut_ad(!sync_check_iterate(sync_check()));

if (dict_table_is_discarded(prebuilt->table)) {
if (!prebuilt->table->space) {
DBUG_RETURN(DB_TABLESPACE_DELETED);
} else if (!prebuilt->table->is_readable()) {
DBUG_RETURN(prebuilt->table->space
Expand Down
2 changes: 1 addition & 1 deletion storage/innobase/row/row0trunc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1580,7 +1580,7 @@ dberr_t
row_truncate_sanity_checks(
const dict_table_t* table)
{
if (dict_table_is_discarded(table)) {
if (!table->space) {

return(DB_TABLESPACE_DELETED);

Expand Down
35 changes: 12 additions & 23 deletions storage/innobase/trx/trx0roll.cc
Original file line number Diff line number Diff line change
Expand Up @@ -635,8 +635,6 @@ trx_rollback_active(
que_fork_t* fork;
que_thr_t* thr;
roll_node_t* roll_node;
dict_table_t* table;
ibool dictionary_locked = FALSE;
const trx_id_t trx_id = trx->id;

ut_ad(trx_id);
Expand All @@ -659,9 +657,11 @@ trx_rollback_active(

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);
dictionary_locked = TRUE;
}

que_run_threads(thr);
Expand All @@ -679,27 +679,16 @@ trx_rollback_active(

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;
Expand Down

0 comments on commit 5e84ea9

Please sign in to comment.