Skip to content

Commit

Permalink
Follow-up fix to MDEV-13201 Assertion srv_undo_sources || ... faile…
Browse files Browse the repository at this point in the history
…d on shutdown during DDL operation

Introduce the debug flag trx_t::persistent_stats to suppress the
assertion for the updates of persistent statistics during fast
shutdown.

dict_stats_exec_sql(): Do execute the statement even though shutdown
has been initiated.
  • Loading branch information
dr-m committed Dec 6, 2017
1 parent 7dc6066 commit 77fb7cc
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 14 deletions.
3 changes: 1 addition & 2 deletions mysql-test/suite/innodb/r/truncate_restart.result
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
call mtr.add_suppression("InnoDB: Cannot save table statistics for table `test`\\.`t1`: Persistent statistics do not exist");
SET GLOBAL innodb_stats_persistent= ON;
CREATE TABLE t1 (t TEXT) ENGINE=InnoDB;
CREATE TABLE t1 (t TEXT) ENGINE=InnoDB STATS_PERSISTENT=1;
connect con1,localhost,root,,test;
SET DEBUG_SYNC='ib_trunc_table_trunc_completing SIGNAL committed WAIT_FOR ever';
TRUNCATE TABLE t1;
Expand Down
4 changes: 1 addition & 3 deletions mysql-test/suite/innodb/t/truncate_restart.test
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
--source include/have_debug.inc
--source include/have_debug_sync.inc

call mtr.add_suppression("InnoDB: Cannot save table statistics for table `test`\\.`t1`: Persistent statistics do not exist");

SET GLOBAL innodb_stats_persistent= ON;
CREATE TABLE t1 (t TEXT) ENGINE=InnoDB;
CREATE TABLE t1 (t TEXT) ENGINE=InnoDB STATS_PERSISTENT=1;
--connect (con1,localhost,root,,test)
SET DEBUG_SYNC='ib_trunc_table_trunc_completing SIGNAL committed WAIT_FOR ever';
--send
Expand Down
2 changes: 2 additions & 0 deletions storage/innobase/btr/btr0defragment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,7 @@ DECLARE_THREAD(btr_defragment_thread)(void*)
mtr_commit(&mtr);
/* Reaching the end of the index. */
dict_stats_empty_defrag_stats(index);
ut_d(trx->persistent_stats = true);
++trx->will_lock;
dberr_t err = dict_stats_save_defrag_stats(index, trx);
if (err == DB_SUCCESS) {
Expand All @@ -849,6 +850,7 @@ DECLARE_THREAD(btr_defragment_thread)(void*)
trx_commit_for_mysql(trx);
}

ut_d(trx->persistent_stats = false);
btr_defragment_remove_item(item);
}
}
Expand Down
12 changes: 4 additions & 8 deletions storage/innobase/dict/dict0stats.cc
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,6 @@ dict_stats_exec_sql(
{
dberr_t err;

extern bool dict_stats_start_shutdown;

if (dict_stats_start_shutdown
|| !dict_stats_persistent_storage_check(true)) {
pars_info_free(pinfo);
return(DB_STATS_DO_NOT_EXIST);
}

err = que_eval_sql(pinfo, sql, FALSE, trx); /* pinfo is freed here */

DBUG_EXECUTE_IF("stats_index_error",
Expand Down Expand Up @@ -2276,6 +2268,8 @@ dict_stats_save_index_stat(
char db_utf8[MAX_DB_UTF8_LEN];
char table_utf8[MAX_TABLE_UTF8_LEN];

ut_ad(trx->persistent_stats || trx->in_mysql_trx_list);

dict_fs2utf8(index->table->name.m_name, db_utf8, sizeof(db_utf8),
table_utf8, sizeof(table_utf8));

Expand Down Expand Up @@ -2401,6 +2395,8 @@ dict_stats_save(
char db_utf8[MAX_DB_UTF8_LEN];
char table_utf8[MAX_TABLE_UTF8_LEN];

ut_ad(trx->persistent_stats || trx->in_mysql_trx_list);

if (table_orig->is_readable()) {
} else {
return (dict_stats_report_error(table_orig));
Expand Down
2 changes: 2 additions & 0 deletions storage/innobase/dict/dict0stats_bg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ DECLARE_THREAD(dict_stats_thread)(void*)
#endif /* UNIV_PFS_THREAD */

trx_t* trx = trx_allocate_for_background();
ut_d(trx->persistent_stats = true);

while (!dict_stats_start_shutdown) {

Expand Down Expand Up @@ -476,6 +477,7 @@ DECLARE_THREAD(dict_stats_thread)(void*)
os_event_reset(dict_stats_event);
}

ut_d(trx->persistent_stats = false);
trx_free_for_background(trx);
srv_dict_stats_thread_active = false;

Expand Down
5 changes: 5 additions & 0 deletions storage/innobase/handler/ha_innodb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6468,9 +6468,12 @@ ha_innobase::open(const char* name, int, uint)
if (alloc) {
trx = trx_allocate_for_background();
}
ut_ad(!trx->persistent_stats);
ut_d(trx->persistent_stats = true);
++trx->will_lock;
dict_stats_init(ib_table, trx);
innobase_commit_low(trx);
ut_d(trx->persistent_stats = false);
if (alloc) {
trx_free_for_background(trx);
}
Expand Down Expand Up @@ -14592,6 +14595,7 @@ ha_innobase::info_low(
on the mysql.innodb_table_stats,
mysql.innodb_index_stats tables. */
trx_t* trx = trx_allocate_for_background();
ut_d(trx->persistent_stats = true);
++trx->will_lock;
ret = dict_stats_update(ib_table, opt, trx);

Expand All @@ -14604,6 +14608,7 @@ ha_innobase::info_low(
trx_commit_for_mysql(trx);
}

ut_d(trx->persistent_stats = false);
trx_free_for_background(trx);

if (ret != DB_SUCCESS) {
Expand Down
3 changes: 3 additions & 0 deletions storage/innobase/include/trx0trx.h
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,9 @@ struct trx_t {
mysql_trx_list; /*!< list of transactions created for
MySQL; protected by trx_sys->mutex */
#ifdef UNIV_DEBUG
/** whether this transaction is updating persistent statistics
(used for silencing a debug assertion at shutdown) */
bool persistent_stats;
bool in_mysql_trx_list;
/*!< true if in
trx_sys->mysql_trx_list */
Expand Down
3 changes: 2 additions & 1 deletion storage/innobase/trx/trx0purge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,8 @@ trx_purge_add_update_undo_to_history(
&& purge_sys->state == PURGE_STATE_INIT)
|| (srv_force_recovery >= SRV_FORCE_NO_BACKGROUND
&& purge_sys->state == PURGE_STATE_DISABLED)
|| ((trx->undo_no == 0 || trx->in_mysql_trx_list)
|| ((trx->undo_no == 0 || trx->in_mysql_trx_list
|| trx->persistent_stats)
&& srv_fast_shutdown));

/* Add the log as the first in the history list */
Expand Down
1 change: 1 addition & 0 deletions storage/innobase/trx/trx0trx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ trx_validate_state_before_free(trx_t* trx)
ut_ad(!trx->declared_to_be_inside_innodb);
ut_ad(!trx->n_mysql_tables_in_use);
ut_ad(!trx->mysql_n_tables_locked);
ut_ad(!trx->persistent_stats);

if (trx->declared_to_be_inside_innodb) {

Expand Down

0 comments on commit 77fb7cc

Please sign in to comment.