Skip to content

Commit

Permalink
MDEV-25594: Improve debug checks
Browse files Browse the repository at this point in the history
trx_t::will_lock: Changed the type to bool.

trx_t::is_autocommit_non_locking(): Replaces
trx_is_autocommit_non_locking().

trx_is_ac_nl_ro(): Remove (replaced with equivalent assertion expressions).

assert_trx_nonlocking_or_in_list(): Remove.
Replaced with at least as strict checks in each place.

check_trx_state(): Moved to a static function; partially replaced with
individual debug assertions implementing equivalent or stricter checks.

This is a backport of commit 7b51d11
from 10.5.
  • Loading branch information
dr-m committed Jul 27, 2021
1 parent 0bd9f75 commit cf1fc59
Show file tree
Hide file tree
Showing 12 changed files with 185 additions and 238 deletions.
72 changes: 24 additions & 48 deletions storage/innobase/handler/ha_innodb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4503,7 +4503,7 @@ innobase_commit_low(
if (trx_is_started(trx)) {
trx_commit_for_mysql(trx);
} else {
trx->will_lock = 0;
trx->will_lock = false;
#ifdef WITH_WSREP
trx->wsrep = false;
#endif /* WITH_WSREP */
Expand Down Expand Up @@ -4860,7 +4860,7 @@ innobase_rollback_trx(
lock_unlock_table_autoinc(trx);

if (!trx->has_logged()) {
trx->will_lock = 0;
trx->will_lock = false;
#ifdef WITH_WSREP
trx->wsrep = false;
#endif
Expand Down Expand Up @@ -8176,20 +8176,12 @@ ha_innobase::write_row(
if (high_level_read_only) {
ib_senderrf(ha_thd(), IB_LOG_LEVEL_WARN, ER_READ_ONLY_MODE);
DBUG_RETURN(HA_ERR_TABLE_READONLY);
} else if (UNIV_UNLIKELY(m_prebuilt->trx != trx)) {
ib::error() << "The transaction object for the table handle is"
" at " << static_cast<const void*>(m_prebuilt->trx)
<< ", but for the current thread it is at "
<< static_cast<const void*>(trx);

fputs("InnoDB: Dump of 200 bytes around m_prebuilt: ", stderr);
ut_print_buf(stderr, ((const byte*) m_prebuilt) - 100, 200);
fputs("\nInnoDB: Dump of 200 bytes around ha_data: ", stderr);
ut_print_buf(stderr, ((const byte*) trx) - 100, 200);
putc('\n', stderr);
ut_error;
} else if (!trx_is_started(trx)) {
++trx->will_lock;
}

ut_a(m_prebuilt->trx == trx);

if (!trx_is_started(trx)) {
trx->will_lock = true;
}

#ifdef WITH_WSREP
Expand Down Expand Up @@ -8964,7 +8956,7 @@ ha_innobase::update_row(
ib_senderrf(ha_thd(), IB_LOG_LEVEL_WARN, ER_READ_ONLY_MODE);
DBUG_RETURN(HA_ERR_TABLE_READONLY);
} else if (!trx_is_started(trx)) {
++trx->will_lock;
trx->will_lock = true;
}

if (m_upd_buf == NULL) {
Expand Down Expand Up @@ -9110,7 +9102,7 @@ ha_innobase::delete_row(
ib_senderrf(ha_thd(), IB_LOG_LEVEL_WARN, ER_READ_ONLY_MODE);
DBUG_RETURN(HA_ERR_TABLE_READONLY);
} else if (!trx_is_started(trx)) {
++trx->will_lock;
trx->will_lock = true;
}

if (!m_prebuilt->upd_node) {
Expand Down Expand Up @@ -9990,7 +9982,7 @@ ha_innobase::ft_init()
them as regular read only transactions for now. */

if (!trx_is_started(trx)) {
++trx->will_lock;
trx->will_lock = true;
}

DBUG_RETURN(rnd_init(false));
Expand Down Expand Up @@ -10056,7 +10048,7 @@ ha_innobase::ft_init_ext(
them as regular read only transactions for now. */

if (!trx_is_started(trx)) {
++trx->will_lock;
trx->will_lock = true;
}

dict_table_t* ft_table = m_prebuilt->table;
Expand Down Expand Up @@ -13081,7 +13073,7 @@ create_table_info_t::allocate_trx()
{
m_trx = innobase_trx_allocate(m_thd);

m_trx->will_lock++;
m_trx->will_lock = true;
m_trx->ddl = true;
}

Expand Down Expand Up @@ -13372,13 +13364,7 @@ inline int ha_innobase::delete_table(const char* name, enum_sql_command sqlcom)

ut_a(name_len < 1000);

/* Either the transaction is already flagged as a locking transaction
or it hasn't been started yet. */

ut_a(!trx_is_started(trx) || trx->will_lock > 0);

/* We are doing a DDL operation. */
++trx->will_lock;
trx->will_lock = true;

/* Drop the table in InnoDB */

Expand Down Expand Up @@ -13555,14 +13541,7 @@ innobase_drop_database(
#endif /* _WIN32 */

trx_t* trx = innobase_trx_allocate(thd);

/* Either the transaction is already flagged as a locking transaction
or it hasn't been started yet. */

ut_a(!trx_is_started(trx) || trx->will_lock > 0);

/* We are doing a DDL operation. */
++trx->will_lock;
trx->will_lock = true;

ulint dummy;

Expand Down Expand Up @@ -13606,7 +13585,7 @@ inline dberr_t innobase_rename_table(trx_t *trx, const char *from,
DEBUG_SYNC_C("innodb_rename_table_ready");

trx_start_if_not_started(trx, true);
ut_ad(trx->will_lock > 0);
ut_ad(trx->will_lock);

if (commit) {
/* Serialize data dictionary operations with dictionary mutex:
Expand Down Expand Up @@ -13651,7 +13630,7 @@ inline dberr_t innobase_rename_table(trx_t *trx, const char *from,
/* Transaction must be flagged as a locking transaction or it hasn't
been started yet. */

ut_a(trx->will_lock > 0);
ut_a(trx->will_lock);

error = row_rename_table_for_mysql(norm_from, norm_to, trx, commit,
commit);
Expand Down Expand Up @@ -13737,7 +13716,7 @@ int ha_innobase::truncate()

if (!srv_safe_truncate) {
if (!trx_is_started(m_prebuilt->trx)) {
++m_prebuilt->trx->will_lock;
m_prebuilt->trx->will_lock = true;
}

dberr_t err = row_truncate_table_for_mysql(
Expand Down Expand Up @@ -13791,8 +13770,7 @@ int ha_innobase::truncate()
heap, ib_table->name.m_name, ib_table->id);
const char* name = mem_heap_strdup(heap, ib_table->name.m_name);
trx_t* trx = innobase_trx_allocate(m_user_thd);

++trx->will_lock;
trx->will_lock = true;
trx_set_dict_operation(trx, TRX_DICT_OP_TABLE);
row_mysql_lock_data_dictionary(trx);
dict_stats_wait_bg_to_stop_using_table(ib_table, trx);
Expand Down Expand Up @@ -13877,9 +13855,7 @@ ha_innobase::rename_table(
}

trx_t* trx = innobase_trx_allocate(thd);

/* We are doing a DDL operation. */
++trx->will_lock;
trx->will_lock = true;
trx_set_dict_operation(trx, TRX_DICT_OP_INDEX);

dberr_t error = innobase_rename_table(trx, from, to, true);
Expand Down Expand Up @@ -15880,7 +15856,7 @@ ha_innobase::start_stmt(
innobase_register_trx(ht, thd, trx);

if (!trx_is_started(trx)) {
++trx->will_lock;
trx->will_lock = true;
}

DBUG_RETURN(0);
Expand Down Expand Up @@ -16103,7 +16079,7 @@ ha_innobase::external_lock(
&& (m_prebuilt->select_lock_type != LOCK_NONE
|| m_prebuilt->stored_select_lock_type != LOCK_NONE)) {

++trx->will_lock;
trx->will_lock = true;
}

DBUG_RETURN(0);
Expand Down Expand Up @@ -16150,7 +16126,7 @@ ha_innobase::external_lock(
&& (m_prebuilt->select_lock_type != LOCK_NONE
|| m_prebuilt->stored_select_lock_type != LOCK_NONE)) {

++trx->will_lock;
trx->will_lock = true;
}

DBUG_RETURN(0);
Expand Down Expand Up @@ -16829,7 +16805,7 @@ ha_innobase::store_lock(
&& (m_prebuilt->select_lock_type != LOCK_NONE
|| m_prebuilt->stored_select_lock_type != LOCK_NONE)) {

++trx->will_lock;
trx->will_lock = true;
}

return(to);
Expand Down
3 changes: 1 addition & 2 deletions storage/innobase/handler/handler0alter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ ha_innobase::check_if_supported_inplace_alter(
}
}

m_prebuilt->trx->will_lock++;
m_prebuilt->trx->will_lock = true;

if (!online) {
/* We already determined that only a non-locking
Expand Down Expand Up @@ -8954,7 +8954,6 @@ ha_innobase::commit_inplace_alter_table(
m_prebuilt = ctx->prebuilt;
}
trx_start_if_not_started(user_trx, true);
user_trx->will_lock++;
m_prebuilt->trx = user_trx;
}
DBUG_INJECT_CRASH("ib_commit_inplace_crash",
Expand Down
6 changes: 3 additions & 3 deletions storage/innobase/include/trx0i_s.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*****************************************************************************
Copyright (c) 2007, 2015, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2017, 2019, MariaDB Corporation.
Copyright (c) 2017, 2021, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Expand Down Expand Up @@ -164,8 +164,8 @@ struct i_s_trx_row_t {
/*!< detailed_error in trx_t */
ulint trx_is_read_only;
/*!< trx_t::read_only */
ulint trx_is_autocommit_non_locking;
/*!< trx_is_autocommit_non_locking(trx)
bool trx_is_autocommit_non_locking;
/*!< trx:t::is_autocommit_non_locking()
*/
};

Expand Down
6 changes: 4 additions & 2 deletions storage/innobase/include/trx0sys.ic
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*****************************************************************************

Copyright (c) 1996, 2015, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2018, 2019, MariaDB Corporation.
Copyright (c) 2018, 2021, MariaDB Corporation.

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Expand Down Expand Up @@ -251,7 +251,9 @@ trx_rw_min_trx_id_low(void)
if (trx == NULL) {
id = trx_sys->max_trx_id;
} else {
assert_trx_in_rw_list(trx);
ut_ad(!trx->read_only);
ut_ad(trx->in_rw_trx_list);
ut_ad(!trx->is_autocommit_non_locking());
id = trx->id;
}

Expand Down
Loading

0 comments on commit cf1fc59

Please sign in to comment.