Commit 487fbc2e authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-21452 fixup: Introduce trx_t::mutex_is_owner()

When we replaced trx_t::mutex with srw_mutex
in commit 38fd7b7d
we lost the SAFE_MUTEX instrumentation.
Let us introduce a replacement and restore the assertions.
parent 455514c8
......@@ -4478,10 +4478,10 @@ static void innobase_kill_query(handlerton*, THD *thd, enum thd_kill_levels)
mysql_mutex_lock(&lock_sys.wait_mutex);
if (lock_t *lock= trx->lock.wait_lock)
{
trx->mutex.wr_lock();
trx->mutex_lock();
trx->error_state= DB_INTERRUPTED;
lock_cancel_waiting_and_release(lock);
trx->mutex.wr_unlock();
trx->mutex_unlock();
}
lock_sys.mutex_unlock();
mysql_mutex_unlock(&lock_sys.wait_mutex);
......@@ -18007,6 +18007,7 @@ int wsrep_innobase_kill_one_trx(THD *bf_thd, trx_t *victim_trx, bool signal)
ut_ad(bf_thd);
ut_ad(victim_trx);
lock_sys.mutex_assert_locked();
ut_ad(victim_trx->mutex_is_owner());
DBUG_ENTER("wsrep_innobase_kill_one_trx");
......@@ -18110,11 +18111,11 @@ wsrep_abort_transaction(
if (victim_trx) {
lock_sys.mutex_lock();
victim_trx->mutex.wr_lock();
victim_trx->mutex_lock();
int rcode= wsrep_innobase_kill_one_trx(bf_thd,
victim_trx, signal);
lock_sys.mutex_unlock();
victim_trx->mutex.wr_unlock();
victim_trx->mutex_unlock();
DBUG_RETURN(rcode);
} else {
wsrep_thd_bf_abort(bf_thd, victim_thd, signal);
......
......@@ -517,12 +517,12 @@ class rw_trx_hash_t
ut_ad(!trx->read_only || !trx->rsegs.m_redo.rseg);
ut_ad(!trx_is_autocommit_non_locking(trx));
/* trx->state can be anything except TRX_STATE_NOT_STARTED */
ut_d(trx->mutex.wr_lock());
ut_d(trx->mutex_lock());
ut_ad(trx_state_eq(trx, TRX_STATE_ACTIVE) ||
trx_state_eq(trx, TRX_STATE_COMMITTED_IN_MEMORY) ||
trx_state_eq(trx, TRX_STATE_PREPARED_RECOVERED) ||
trx_state_eq(trx, TRX_STATE_PREPARED));
ut_d(trx->mutex.wr_unlock());
ut_d(trx->mutex_unlock());
}
......
......@@ -667,9 +667,41 @@ struct trx_t : ilist_node<> {
trx_sys_t::deregister_rw(), release_locks(). */
trx_id_t id;
private:
/** mutex protecting state and some of lock
(some are protected by lock_sys.mutex) */
srw_mutex mutex;
#ifdef UNIV_DEBUG
/** The owner of mutex (0 if none); protected by mutex */
std::atomic<os_thread_id_t> mutex_owner{0};
#endif /* UNIV_DEBUG */
public:
void mutex_init() { mutex.init(); }
void mutex_destroy() { mutex.destroy(); }
/** Acquire the mutex */
void mutex_lock()
{
ut_ad(!mutex_is_owner());
mutex.wr_lock();
ut_ad(!mutex_owner.exchange(os_thread_get_curr_id(),
std::memory_order_relaxed));
}
/** Release the mutex */
void mutex_unlock()
{
ut_ad(mutex_owner.exchange(0, std::memory_order_relaxed)
== os_thread_get_curr_id());
mutex.wr_unlock();
}
#ifdef UNIV_DEBUG
/** @return whether the current thread holds the mutex */
bool mutex_is_owner() const
{
return mutex_owner.load(std::memory_order_relaxed) ==
os_thread_get_curr_id();
}
#endif /* UNIV_DEBUG */
/** State of the trx from the point of view of concurrency control
and the valid state transitions.
......@@ -1027,6 +1059,7 @@ struct trx_t : ilist_node<> {
{
ut_ad(state == TRX_STATE_NOT_STARTED);
ut_ad(!id);
ut_ad(!mutex_is_owner());
ut_ad(!has_logged());
ut_ad(!is_referenced());
ut_ad(!is_wsrep());
......
......@@ -864,17 +864,12 @@ lock_rec_other_has_expl_req(
#endif /* UNIV_DEBUG */
#ifdef WITH_WSREP
static
void
wsrep_kill_victim(
/*==============*/
const trx_t * const trx,
const lock_t *lock)
ATTRIBUTE_COLD
static void wsrep_kill_victim(const trx_t *trx, const lock_t *lock)
{
lock_sys.mutex_assert_locked();
/* quit for native mysql */
if (!trx->is_wsrep()) return;
ut_ad(lock->trx->mutex_is_owner());
ut_ad(trx->is_wsrep());
if (!wsrep_thd_is_BF(trx->mysql_thd, FALSE)) {
return;
......@@ -958,12 +953,12 @@ lock_rec_other_has_conflicting(
#ifdef WITH_WSREP
if (trx->is_wsrep()) {
trx_t* lock_trx = lock->trx;
lock_trx->mutex.wr_lock();
lock_trx->mutex_lock();
/* Below function will roll back either trx
or lock->trx depending on priority of the
transaction. */
wsrep_kill_victim(const_cast<trx_t*>(trx), lock);
lock_trx->mutex.wr_unlock();
wsrep_kill_victim(trx, lock);
lock_trx->mutex_unlock();
}
#endif /* WITH_WSREP */
return(lock);
......@@ -1104,6 +1099,7 @@ static void lock_set_lock_and_trx_wait(lock_t *lock, trx_t *trx)
ut_ad(!trx->lock.wait_lock || trx->lock.wait_lock != lock);
ut_ad(!trx->lock.wait_lock || (*trx->lock.wait_lock).trx == trx);
lock_sys.mutex_assert_locked();
ut_ad(trx->mutex_is_owner());
trx->lock.wait_lock= lock;
lock->type_mode|= LOCK_WAIT;
......@@ -1138,6 +1134,7 @@ lock_rec_create_low(
ulint n_bytes;
lock_sys.mutex_assert_locked();
ut_ad(holds_trx_mutex == trx->mutex_is_owner());
ut_ad(dict_index_is_clust(index) || !dict_index_is_online_ddl(index));
ut_ad(!(type_mode & LOCK_TABLE));
......@@ -1229,14 +1226,14 @@ lock_rec_create_low(
* if victim was waiting for some other lock
*/
if (holds_trx_mutex) {
trx->mutex.wr_unlock();
trx->mutex_unlock();
}
mysql_mutex_lock(&lock_sys.wait_mutex);
if (holds_trx_mutex) {
trx->mutex.wr_lock();
trx->mutex_lock();
}
trx_t *ctrx = c_lock->trx;
ctrx->mutex.wr_lock();
ctrx->mutex_lock();
if (ctrx->lock.wait_thr) {
ctrx->lock.was_chosen_as_deadlock_victim = 3;
......@@ -1254,31 +1251,32 @@ lock_rec_create_low(
lock_grant, which wants to grant trx mutex again
*/
if (holds_trx_mutex) {
trx->mutex.wr_unlock();
trx->mutex_unlock();
}
lock_cancel_waiting_and_release(
ctrx->lock.wait_lock);
if (holds_trx_mutex) {
trx->mutex.wr_lock();
trx->mutex_lock();
}
ctrx->mutex.wr_unlock();
ctrx->mutex_unlock();
/* have to bail out here to avoid lock_set_lock... */
mysql_mutex_unlock(&lock_sys.wait_mutex);
return(lock);
}
mysql_mutex_unlock(&lock_sys.wait_mutex);
ctrx->mutex.wr_unlock();
ctrx->mutex_unlock();
} else
#endif /* WITH_WSREP */
HASH_INSERT(lock_t, hash, lock_hash_get(type_mode),
page_id.fold(), lock);
if (!holds_trx_mutex) {
trx->mutex.wr_lock();
trx->mutex_lock();
}
ut_ad(trx->mutex_is_owner());
if (type_mode & LOCK_WAIT) {
ut_ad(!trx->lock.wait_lock
|| (*trx->lock.wait_lock).trx == trx);
......@@ -1286,7 +1284,7 @@ lock_rec_create_low(
}
UT_LIST_ADD_LAST(trx->lock.trx_locks, lock);
if (!holds_trx_mutex) {
trx->mutex.wr_unlock();
trx->mutex_unlock();
}
MONITOR_INC(MONITOR_RECLOCK_CREATED);
MONITOR_INC(MONITOR_NUM_RECLOCK);
......@@ -1327,6 +1325,7 @@ lock_rec_enqueue_waiting(
ut_ad(dict_index_is_clust(index) || !dict_index_is_online_ddl(index));
trx_t* trx = thr_get_trx(thr);
ut_ad(trx->mutex_is_owner());
switch (trx_get_dict_operation(trx)) {
case TRX_DICT_OP_NONE:
......@@ -1426,6 +1425,7 @@ lock_rec_add_to_queue(
transaction mutex */
{
lock_sys.mutex_assert_locked();
ut_ad(caller_owns_trx_mutex == trx->mutex_is_owner());
ut_ad(index->is_primary()
|| dict_index_get_online_status(index) != ONLINE_INDEX_CREATION);
ut_ad(!(type_mode & LOCK_TABLE));
......@@ -1567,7 +1567,7 @@ lock_rec_lock(
if (lock_t *lock= lock_sys.get_first(id))
{
dberr_t err= DB_SUCCESS;
trx->mutex.wr_lock();
trx->mutex_lock();
if (lock_rec_get_next_on_page(lock) ||
lock->trx != trx ||
lock->type_mode != mode ||
......@@ -1613,7 +1613,7 @@ lock_rec_lock(
err= DB_SUCCESS_LOCKED_REC;
}
}
trx->mutex.wr_unlock();
trx->mutex_unlock();
return err;
}
else
......@@ -1721,7 +1721,7 @@ dberr_t lock_wait(que_thr_t *thr)
bool had_dict_lock= trx->dict_operation_lock_mode != 0;
mysql_mutex_lock(&lock_sys.wait_mutex);
trx->mutex.wr_lock();
trx->mutex_lock();
trx->error_state= DB_SUCCESS;
if (!trx->lock.wait_lock)
......@@ -1737,12 +1737,12 @@ dberr_t lock_wait(que_thr_t *thr)
}
mysql_mutex_unlock(&lock_sys.wait_mutex);
trx->mutex.wr_unlock();
trx->mutex_unlock();
return trx->error_state;
}
trx->lock.suspend_time= suspend_time;
trx->mutex.wr_unlock();
trx->mutex_unlock();
if (row_lock_wait)
lock_sys.wait_start();
......@@ -1834,9 +1834,9 @@ dberr_t lock_wait(que_thr_t *thr)
mysql_mutex_lock(&lock_sys.wait_mutex);
if (lock_t *lock= trx->lock.wait_lock)
{
trx->mutex.wr_lock();
trx->mutex_lock();
lock_cancel_waiting_and_release(lock);
trx->mutex.wr_unlock();
trx->mutex_unlock();
}
}
mysql_mutex_unlock(&lock_sys.wait_mutex);
......@@ -1849,6 +1849,7 @@ dberr_t lock_wait(que_thr_t *thr)
static void lock_wait_end(trx_t *trx)
{
mysql_mutex_assert_owner(&lock_sys.wait_mutex);
ut_ad(trx->mutex_is_owner());
ut_ad(trx->state == TRX_STATE_ACTIVE);
ut_ad(trx->lock.wait_thr);
......@@ -1868,7 +1869,7 @@ static void lock_grant(lock_t *lock)
mysql_mutex_assert_owner(&lock_sys.wait_mutex);
lock_reset_lock_and_trx_wait(lock);
trx_t *trx= lock->trx;
trx->mutex.wr_lock();
trx->mutex_lock();
if (lock->mode() == LOCK_AUTO_INC)
{
dict_table_t *table= lock->un_member.tab_lock.table;
......@@ -1885,7 +1886,7 @@ static void lock_grant(lock_t *lock)
if (trx->lock.wait_thr)
lock_wait_end(trx);
trx->mutex.wr_unlock();
trx->mutex_unlock();
}
/*************************************************************//**
......@@ -1911,10 +1912,10 @@ lock_rec_cancel(
/* The following releases the trx from lock wait */
trx_t *trx = lock->trx;
trx->mutex.wr_lock();
trx->mutex_lock();
lock_wait_end(trx);
mysql_mutex_unlock(&lock_sys.wait_mutex);
trx->mutex.wr_unlock();
trx->mutex_unlock();
}
/** Remove a record lock request, waiting or granted, from the queue and
......@@ -3156,6 +3157,7 @@ lock_table_create(
ut_ad(table && trx);
lock_sys.mutex_assert_locked();
ut_ad(trx->mutex_is_owner());
check_trx_state(trx);
......@@ -3210,9 +3212,9 @@ lock_table_create(
ut_list_append(table->locks, lock, TableLockGetNode());
}
trx->mutex.wr_unlock();
trx->mutex_unlock();
mysql_mutex_lock(&lock_sys.wait_mutex);
c_lock->trx->mutex.wr_lock();
c_lock->trx->mutex_lock();
if (c_lock->trx->lock.wait_thr) {
c_lock->trx->lock.was_chosen_as_deadlock_victim = TRUE;
......@@ -3230,8 +3232,8 @@ lock_table_create(
}
mysql_mutex_unlock(&lock_sys.wait_mutex);
c_lock->trx->mutex.wr_unlock();
trx->mutex.wr_lock();
c_lock->trx->mutex_unlock();
trx->mutex_lock();
} else
#endif /* WITH_WSREP */
ut_list_append(table->locks, lock, TableLockGetNode());
......@@ -3402,12 +3404,11 @@ lock_table_enqueue_waiting(
#endif
)
{
trx_t* trx;
lock_sys.mutex_assert_locked();
ut_ad(!srv_read_only_mode);
trx = thr_get_trx(thr);
trx_t* trx = thr_get_trx(thr);
ut_ad(trx->mutex_is_owner());
switch (trx_get_dict_operation(trx)) {
case TRX_DICT_OP_NONE:
......@@ -3470,21 +3471,23 @@ lock_table_other_has_incompatible(
lock;
lock = UT_LIST_GET_PREV(un_member.tab_lock.locks, lock)) {
if (lock->trx != trx
trx_t* lock_trx = lock->trx;
if (lock_trx != trx
&& !lock_mode_compatible(lock->mode(), mode)
&& (wait || !lock->is_waiting())) {
#ifdef WITH_WSREP
if (lock->trx->is_wsrep()) {
if (trx->is_wsrep() && lock_trx->is_wsrep()) {
if (UNIV_UNLIKELY(wsrep_debug)) {
ib::info() << "WSREP: table lock abort for table:"
<< table->name;
ib::info() << " SQL: "
<< wsrep_thd_query(lock->trx->mysql_thd);
}
lock->trx->mutex.wr_lock();
wsrep_kill_victim((trx_t *)trx, (lock_t *)lock);
lock->trx->mutex.wr_unlock();
lock_trx->mutex_lock();
wsrep_kill_victim(trx, lock);
lock_trx->mutex_unlock();
}
#endif /* WITH_WSREP */
......@@ -3548,7 +3551,7 @@ lock_table(
wait_for = lock_table_other_has_incompatible(
trx, LOCK_WAIT, table, mode);
trx->mutex.wr_lock();
trx->mutex_lock();
if (wait_for) {
err = lock_table_enqueue_waiting(mode, table, thr
......@@ -3562,7 +3565,7 @@ lock_table(
lock_sys.mutex_unlock();
trx->mutex.wr_unlock();
trx->mutex_unlock();
return(err);
}
......@@ -3583,10 +3586,10 @@ void lock_table_resurrect(dict_table_t *table, trx_t *trx, lock_mode mode)
LockMutexGuard g;
ut_ad(!lock_table_other_has_incompatible(trx, LOCK_WAIT, table, mode));
trx->mutex.wr_lock();
trx->mutex_lock();
lock_table_create(table, mode, trx);
}
trx->mutex.wr_unlock();
trx->mutex_unlock();
}
/*********************************************************************//**
......@@ -3885,6 +3888,7 @@ void lock_release(trx_t* trx)
ulint count = 0;
trx_id_t max_trx_id = trx_sys.get_max_trx_id();
ut_ad(!trx->mutex_is_owner());
LockMutexGuard g;
for (lock_t* lock = UT_LIST_GET_LAST(trx->lock.trx_locks);
......@@ -3938,8 +3942,9 @@ lock_trx_table_locks_remove(
/* It is safe to read this because we are holding the lock mutex */
const bool have_mutex = trx->lock.cancel;
if (!have_mutex) {
trx->mutex.wr_lock();
trx->mutex_lock();
}
ut_ad(trx->mutex_is_owner());
for (lock_list::iterator it = trx->lock.table_locks.begin(),
end = trx->lock.table_locks.end(); it != end; ++it) {
......@@ -3953,7 +3958,7 @@ lock_trx_table_locks_remove(
*it = NULL;
if (!have_mutex) {
trx->mutex.wr_unlock();
trx->mutex_unlock();
}
return;
......@@ -4309,6 +4314,8 @@ lock_trx_table_locks_find(
{
bool found = false;
ut_ad(trx->mutex_is_owner());
for (lock_list::const_iterator it = trx->lock.table_locks.begin(),
end = trx->lock.table_locks.end(); it != end; ++it) {
......@@ -4353,7 +4360,7 @@ lock_table_queue_validate(
/* lock->trx->state cannot change from or to NOT_STARTED
while we are holding the lock_sys.mutex. It may change
from ACTIVE or PREPARED to PREPARED or COMMITTED. */
lock->trx->mutex.wr_lock();
lock->trx->mutex_lock();
check_trx_state(lock->trx);
if (lock->trx->state == TRX_STATE_COMMITTED_IN_MEMORY) {
......@@ -4366,7 +4373,7 @@ lock_table_queue_validate(
}
ut_a(lock_trx_table_locks_find(lock->trx, lock));
lock->trx->mutex.wr_unlock();
lock->trx->mutex_unlock();
}
return(TRUE);
......@@ -4416,13 +4423,13 @@ lock_rec_queue_validate(
ut_ad(!index || lock->index == index);
lock->trx->mutex.wr_lock();
lock->trx->mutex_lock();
ut_ad(!trx_is_ac_nl_ro(lock->trx));
ut_ad(trx_state_eq(lock->trx,
TRX_STATE_COMMITTED_IN_MEMORY)
|| !lock->is_waiting()
|| lock_rec_has_to_wait_in_queue(lock));
lock->trx->mutex.wr_unlock();
lock->trx->mutex_unlock();
}
func_exit:
......@@ -4446,7 +4453,7 @@ lock_rec_queue_validate(
/* impl_trx could have been committed before we
acquire its mutex, but not thereafter. */
impl_trx->mutex.wr_lock();
impl_trx->mutex_lock();
ut_ad(impl_trx->state != TRX_STATE_NOT_STARTED);
if (impl_trx->state == TRX_STATE_COMMITTED_IN_MEMORY) {
} else if (const lock_t* other_lock
......@@ -4497,7 +4504,7 @@ lock_rec_queue_validate(
}
}
impl_trx->mutex.wr_unlock();
impl_trx->mutex_unlock();
}
for (lock = lock_rec_get_first(&lock_sys.rec_hash, block, heap_no);
......@@ -4850,7 +4857,7 @@ lock_rec_insert_check_and_lock(
lock_t* c_lock =
#endif /* WITH_WSREP */
lock_rec_other_has_conflicting(type_mode, block, heap_no, trx)) {
trx->mutex.wr_lock();
trx->mutex_lock();
err = lock_rec_enqueue_waiting(
#ifdef WITH_WSREP
......@@ -4858,7 +4865,7 @@ lock_rec_insert_check_and_lock(
#endif /* WITH_WSREP */
type_mode, block, heap_no, index, thr, NULL);
trx->mutex.wr_unlock();
trx->mutex_unlock();
} else {
err = DB_SUCCESS;
}
......@@ -4925,7 +4932,7 @@ lock_rec_convert_impl_to_expl_for_trx(
DEBUG_SYNC_C("before_lock_rec_convert_impl_to_expl_for_trx");
lock_sys.mutex_lock();
trx->mutex.wr_lock();
trx->mutex_lock();
ut_ad(!trx_state_eq(trx, TRX_STATE_NOT_STARTED));
if (!trx_state_eq(trx, TRX_STATE_COMMITTED_IN_MEMORY)
......@@ -4936,7 +4943,7 @@ lock_rec_convert_impl_to_expl_for_trx(
}
lock_sys.mutex_unlock();
trx->mutex.wr_unlock();
trx->mutex_unlock();
trx->release_reference();
DEBUG_SYNC_C("after_lock_rec_convert_impl_to_expl_for_trx");
......@@ -4959,7 +4966,7 @@ static my_bool lock_rec_other_trx_holds_expl_callback(
mysql_mutex_lock(&element->mutex);
if (element->trx)
{
element->trx->mutex.wr_lock();
element->trx->mutex_lock();
ut_ad(element->trx->state != TRX_STATE_NOT_STARTED);
lock_t *expl_lock= element->trx->state == TRX_STATE_COMMITTED_IN_MEMORY
? NULL : lock_rec_has_expl(LOCK_S | LOCK_REC_NOT_GAP, arg->block,
......@@ -4969,7 +4976,7 @@ static my_bool lock_rec_other_trx_holds_expl_callback(
lock.
*/
ut_ad(!expl_lock || expl_lock->trx == arg->impl_trx);
element->trx->mutex.wr_unlock();
element->trx->mutex_unlock();
}
mysql_mutex_unlock(&element->mutex);
return 0;
......@@ -5520,6 +5527,7 @@ void lock_cancel_waiting_and_release(lock_t *lock)
mysql_mutex_assert_owner(&lock_sys.wait_mutex);
trx_t *trx= lock->trx;
ut_ad(trx->state == TRX_STATE_ACTIVE);
ut_ad(trx->mutex_is_owner());
trx->lock.cancel= true;
......@@ -5552,6 +5560,7 @@ lock_unlock_table_autoinc(
trx_t* trx) /*!< in/out: transaction */
{
lock_sys.mutex_assert_unlocked();
ut_ad(!trx->mutex_is_owner());
ut_ad(!trx->lock.wait_lock);
/* This can be invoked on NOT_STARTED, ACTIVE, PREPARED,
......@@ -5574,6 +5583,7 @@ static inline dberr_t lock_trx_handle_wait_low(trx_t* trx)
{
lock_sys.mutex_assert_locked();
mysql_mutex_assert_owner(&lock_sys.wait_mutex);
ut_ad(trx->mutex_is_owner());
if (trx->lock.was_chosen_as_deadlock_victim)
return DB_DEADLOCK;
......@@ -5603,11 +5613,11 @@ lock_trx_handle_wait(
{
LockMutexGuard g;
mysql_mutex_lock(&lock_sys.wait_mutex);
trx->mutex.wr_lock();
trx->mutex_lock();
err= lock_trx_handle_wait_low(trx);
}
mysql_mutex_unlock(&lock_sys.wait_mutex);
trx->mutex.wr_unlock();
trx->mutex_unlock();
return err;
}
......@@ -5645,7 +5655,7 @@ static my_bool lock_table_locks_lookup(rw_trx_hash_element_t *element,
mysql_mutex_lock(&element->mutex);
if (element->trx)
{
element->trx->mutex.wr_lock();
element->trx->mutex_lock();
check_trx_state(element->trx);
if (element->trx->state != TRX_STATE_COMMITTED_IN_MEMORY)
{
......@@ -5664,7 +5674,7 @@ static my_bool lock_table_locks_lookup(rw_trx_hash_element_t *element,
ut_ad(lock->un_member.tab_lock.table != table);
}
}
element->trx->mutex.wr_unlock();
element->trx->mutex_unlock();
}
mysql_mutex_unlock(&element->mutex);
return 0;
......@@ -6055,9 +6065,7 @@ have been granted its lock by the deadlock checks.
inline trx_t* DeadlockChecker::search()
{
lock_sys.mutex_assert_locked();
ut_ad(m_start != NULL);
ut_ad(m_wait_lock != NULL);
ut_ad(!m_start->mutex_is_owner());
check_trx_state(m_wait_lock->trx);
ut_ad(m_mark_start <= s_lock_mark_counter);
......@@ -6200,6 +6208,7 @@ We will attempt to resolve all deadlocks.
@return whether the transaction was chosen as victim */
inline bool DeadlockChecker::check_and_resolve(trx_t *trx)
{
ut_ad(!trx->mutex_is_owner());
ut_ad(trx->state == TRX_STATE_ACTIVE);
ut_ad(!srv_read_only_mode);
......@@ -6247,13 +6256,13 @@ inline bool DeadlockChecker::check_and_resolve(trx_t *trx)
else
{
mysql_mutex_lock(&lock_sys.wait_mutex);
victim_trx->mutex.wr_lock();
victim_trx->mutex_lock();
const auto state= victim_trx->state;
if (state != TRX_STATE_ACTIVE)
{
ut_ad(state == TRX_STATE_COMMITTED_IN_MEMORY);
mysql_mutex_unlock(&lock_sys.wait_mutex);
victim_trx->mutex.wr_unlock();
victim_trx->mutex_unlock();
return false;
}
print("*** WE ROLL BACK TRANSACTION (1)\n");
......@@ -6261,7 +6270,7 @@ inline bool DeadlockChecker::check_and_resolve(trx_t *trx)
IF_WSREP(.fetch_or(1),= true);
lock_cancel_waiting_and_release(victim_trx->lock.wait_lock);
mysql_mutex_unlock(&lock_sys.wait_mutex);
victim_trx->mutex.wr_unlock();
victim_trx->mutex_unlock();
}
lock_sys.deadlocks++;
break;
......
......@@ -436,6 +436,7 @@ lock_prdt_add_to_queue(
{
const page_id_t id{block->page.id()};
lock_sys.mutex_assert_locked();
ut_ad(caller_owns_trx_mutex == trx->mutex_is_owner());
ut_ad(index->is_spatial());
ut_ad(!dict_index_is_online_ddl(index));
ut_ad(type_mode & (LOCK_PREDICATE | LOCK_PRDT_PAGE));
......@@ -555,7 +556,7 @@ lock_prdt_insert_check_and_lock(
lock_init_prdt_from_mbr(prdt, mbr, 0, trx->lock.lock_heap);
/* Note that we may get DB_SUCCESS also here! */
trx->mutex.wr_lock();
trx->mutex_lock();
err = lock_rec_enqueue_waiting(
#ifdef WITH_WSREP
......@@ -564,7 +565,7 @@ lock_prdt_insert_check_and_lock(
LOCK_X | LOCK_PREDICATE | LOCK_INSERT_INTENTION,
block, PRDT_HEAPNO, index, thr, prdt);
trx->mutex.wr_unlock();
trx->mutex_unlock();
} else {
err = DB_SUCCESS;
}
......@@ -789,7 +790,7 @@ lock_prdt_lock(
|| ((type_mode & LOCK_PREDICATE)
&& (!lock_prdt_consistent(
lock_get_prdt_from_lock(lock), prdt, 0)))) {
trx->mutex.wr_lock();
trx->mutex_lock();
lock = lock_prdt_has_lock(
mode, type_mode, block, prdt, trx);
......@@ -821,7 +822,7 @@ lock_prdt_lock(
}
}
trx->mutex.wr_unlock();
trx->mutex_unlock();
} else {
if (!lock_rec_get_nth_bit(lock, PRDT_HEAPNO)) {
lock_rec_set_nth_bit(lock, PRDT_HEAPNO);
......
......@@ -177,7 +177,7 @@ que_fork_scheduler_round_robin(
que_fork_t* fork, /*!< in: a query fork */
que_thr_t* thr) /*!< in: current pos */
{
fork->trx->mutex.wr_lock();
fork->trx->mutex_lock();
/* If no current, start first available. */
if (thr == NULL) {
......@@ -195,7 +195,7 @@ que_fork_scheduler_round_robin(
que_thr_init_command(thr);
}
fork->trx->mutex.wr_unlock();
fork->trx->mutex_unlock();
return(thr);
}
......@@ -466,14 +466,14 @@ que_thr_node_step(
}
trx_t *trx= thr->graph->trx;
trx->mutex.wr_lock();
trx->mutex_lock();
if (!trx->lock.wait_thr && thr->graph->state == QUE_FORK_ACTIVE) {
thr->state = QUE_THR_COMPLETED;
thr = NULL;
}
trx->mutex.wr_unlock();
trx->mutex_unlock();
return(thr);
}
......@@ -688,18 +688,14 @@ que_run_threads_low(
/*================*/
que_thr_t* thr) /*!< in: query thread */
{
trx_t* trx;
que_thr_t* next_thr;
ut_ad(thr->state == QUE_THR_RUNNING);
ut_a(thr_get_trx(thr)->error_state == DB_SUCCESS);
/* cumul_resource counts how much resources the OS thread (NOT the
query thread) has spent in this function */
trx = thr_get_trx(thr);
do {
for (trx_t* trx = thr_get_trx(thr);;) {
ut_ad(!trx->mutex_is_owner());
ut_a(trx->error_state == DB_SUCCESS);
/* Check that there is enough space in the log to accommodate
possible log entries by this query step; if the operation can
touch more than about 4 pages, checks must be made also within
......@@ -710,17 +706,14 @@ que_run_threads_low(
/* Perform the actual query step: note that the query thread
may change if, e.g., a subprocedure call is made */
/*-------------------------*/
next_thr = que_thr_step(thr);
/*-------------------------*/
if (next_thr) {
ut_a(trx->error_state == DB_SUCCESS);
ut_a(next_thr == thr);
que_thr_t* next_thr = que_thr_step(thr);
ut_ad(trx == thr_get_trx(thr));
if (!next_thr) {
return;
}
ut_ad(trx == thr_get_trx(thr));
} while (next_thr != NULL);
ut_a(next_thr == thr);
}
}
/**********************************************************************//**
......
......@@ -193,10 +193,10 @@ row_vers_impl_x_locked_low(
heap, &prev_version, NULL,
dict_index_has_virtual(index) ? &vrow : NULL, 0);
ut_d(trx->mutex.wr_lock());
ut_d(trx->mutex_lock());
const bool committed = trx_state_eq(
trx, TRX_STATE_COMMITTED_IN_MEMORY);
ut_d(trx->mutex.wr_unlock());
ut_d(trx->mutex_unlock());
/* The oldest visible clustered index version must not be
delete-marked, because we never start a transaction by
......
......@@ -155,6 +155,7 @@ inline void trx_t::rollback_low(trx_savept_t *savept)
@return error code or DB_SUCCESS */
dberr_t trx_t::rollback(trx_savept_t *savept)
{
ut_ad(!mutex_is_owner());
if (state == TRX_STATE_NOT_STARTED)
{
error_state= DB_SUCCESS;
......@@ -724,10 +725,10 @@ static my_bool trx_rollback_recovered_callback(rw_trx_hash_element_t *element,
mysql_mutex_lock(&element->mutex);
if (trx_t *trx= element->trx)
{
trx->mutex.wr_lock();
trx->mutex_lock();
if (trx_state_eq(trx, TRX_STATE_ACTIVE) && trx->is_recovered)
trx_list->push_back(trx);
trx->mutex.wr_unlock();
trx->mutex_unlock();
}
mysql_mutex_unlock(&element->mutex);
return 0;
......@@ -769,10 +770,10 @@ void trx_rollback_recovered(bool all)
trx_list.pop_back();
ut_ad(trx);
ut_d(trx->mutex.wr_lock());
ut_d(trx->mutex_lock());
ut_ad(trx->is_recovered);
ut_ad(trx_state_eq(trx, TRX_STATE_ACTIVE));
ut_d(trx->mutex.wr_unlock());
ut_d(trx->mutex_unlock());
if (srv_shutdown_state != SRV_SHUTDOWN_NONE && !srv_undo_sources &&
srv_fast_shutdown)
......@@ -866,6 +867,7 @@ trx_roll_graph_build(
que_fork_t* fork;
que_thr_t* thr;
ut_ad(trx->mutex_is_owner());
heap = mem_heap_create(512);
fork = que_fork_create(heap);
fork->trx = trx;
......@@ -892,6 +894,7 @@ trx_rollback_start(
{
/* Initialize the rollback field in the transaction */
ut_ad(trx->mutex_is_owner());
ut_ad(!trx->roll_limit);
ut_ad(!trx->in_rollback);
......@@ -960,13 +963,13 @@ trx_rollback_step(
roll_limit = node->savept ? node->savept->least_undo_no : 0;
trx->mutex.wr_lock();
trx->mutex_lock();
trx_commit_or_rollback_prepare(trx);
node->undo_thr = trx_rollback_start(trx, roll_limit);
trx->mutex.wr_unlock();
trx->mutex_unlock();
} else {
ut_ad(node->state == ROLL_NODE_WAIT);
......
......@@ -195,7 +195,7 @@ struct TrxFactory {
trx->trx_savepoints,
&trx_named_savept_t::trx_savepoints);
trx->mutex.init();
trx->mutex_init();
}
/** Release resources held by the transaction object.
......@@ -234,7 +234,7 @@ struct TrxFactory {
UT_DELETE(trx->xid);
ut_free(trx->detailed_error);
trx->mutex.destroy();
trx->mutex_destroy();
trx->mod_tables.~trx_mod_tables_t();
......@@ -1946,9 +1946,9 @@ trx_prepare(
DBUG_EXECUTE_IF("ib_trx_crash_during_xa_prepare_step", DBUG_SUICIDE(););
ut_a(trx->state == TRX_STATE_ACTIVE);
trx->mutex.wr_lock();
trx->mutex_lock();
trx->state = TRX_STATE_PREPARED;
trx->mutex.wr_unlock();
trx->mutex_unlock();
if (lsn) {
/* Depending on the my.cnf options, we may now write the log
......@@ -2090,7 +2090,7 @@ static my_bool trx_get_trx_by_xid_callback(rw_trx_hash_element_t *element,
mysql_mutex_lock(&element->mutex);
if (trx_t *trx= element->trx)
{
trx->mutex.wr_lock();
trx->mutex_lock();
if (trx->is_recovered &&
(trx_state_eq(trx, TRX_STATE_PREPARED) ||
trx_state_eq(trx, TRX_STATE_PREPARED_RECOVERED)) &&
......@@ -2107,7 +2107,7 @@ static my_bool trx_get_trx_by_xid_callback(rw_trx_hash_element_t *element,
arg->trx= trx;
found= 1;
}
trx->mutex.wr_unlock();
trx->mutex_unlock();
}
mysql_mutex_unlock(&element->mutex);
return found;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment