Skip to content

Commit a44d896

Browse files
sjaakolajanlindstrom
authored andcommitted
10.4-MDEV-29684 Fixes for cluster wide write conflict resolving
If two high priority threads have lock conflict, we look at the order of these transactions and honor the earlier transaction. for_locking parameter in lock_rec_has_to_wait() has become obsolete and it is now removed from the code . Reviewed-by: Jan Lindström <jan.lindstrom@mariadb.com>
1 parent 0ff7f33 commit a44d896

File tree

3 files changed

+39
-22
lines changed

3 files changed

+39
-22
lines changed

sql/service_wsrep.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2018-2021 Codership Oy <info@codership.com>
1+
/* Copyright 2018-2023 Codership Oy <info@codership.com>
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -274,7 +274,9 @@ extern "C" my_bool wsrep_thd_skip_locking(const THD *thd)
274274

275275
extern "C" my_bool wsrep_thd_order_before(const THD *left, const THD *right)
276276
{
277-
if (wsrep_thd_trx_seqno(left) < wsrep_thd_trx_seqno(right)) {
277+
if (wsrep_thd_is_BF(left, false) &&
278+
wsrep_thd_is_BF(right, false) &&
279+
wsrep_thd_trx_seqno(left) < wsrep_thd_trx_seqno(right)) {
278280
WSREP_DEBUG("BF conflict, order: %lld %lld\n",
279281
(long long)wsrep_thd_trx_seqno(left),
280282
(long long)wsrep_thd_trx_seqno(right));

sql/sql_class.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5230,8 +5230,6 @@ thd_need_ordering_with(const MYSQL_THD thd, const MYSQL_THD other_thd)
52305230
(e.g. InnoDB does it by keeping lock_sys.mutex locked)
52315231
*/
52325232
if (WSREP_ON &&
5233-
wsrep_thd_is_BF(thd, false) &&
5234-
wsrep_thd_is_BF(other_thd, false) &&
52355233
wsrep_thd_order_before(thd, other_thd))
52365234
return 0;
52375235
#endif /* WITH_WSREP */

storage/innobase/lock/lock0lock.cc

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -819,25 +819,34 @@ lock_rec_has_to_wait(
819819
}
820820

821821
#ifdef WITH_WSREP
822-
/* New lock request from a transaction is using unique key
823-
scan and this transaction is a wsrep high priority transaction
824-
(brute force). If conflicting transaction is also wsrep high
825-
priority transaction we should avoid lock conflict because
826-
ordering of these transactions is already decided and
827-
conflicting transaction will be later replayed. Note
828-
that thread holding conflicting lock can't be
829-
committed or rolled back while we hold
830-
lock_sys->mutex. */
831-
if (trx->is_wsrep_UK_scan()
832-
&& wsrep_thd_is_BF(lock2->trx->mysql_thd, false)) {
833-
return false;
834-
}
822+
/* New lock request from a transaction is using unique key
823+
scan and this transaction is a wsrep high priority transaction
824+
(brute force). If conflicting transaction is also wsrep high
825+
priority transaction we should avoid lock conflict because
826+
ordering of these transactions is already decided and
827+
conflicting transaction will be later replayed. Note
828+
that thread holding conflicting lock can't be
829+
committed or rolled back while we hold
830+
lock_sys->mutex. */
831+
if (trx->is_wsrep_UK_scan()
832+
&& wsrep_thd_is_BF(lock2->trx->mysql_thd, false)) {
833+
return false;
834+
}
835835

836-
/* We very well can let bf to wait normally as other
837-
BF will be replayed in case of conflict. For debug
838-
builds we will do additional sanity checks to catch
839-
unsupported bf wait if any. */
840-
ut_d(wsrep_assert_no_bf_bf_wait(lock2, trx));
836+
/* If BF-BF conflict, we have to look at write set order */
837+
if (trx->is_wsrep()
838+
&& (type_mode & LOCK_MODE_MASK) == LOCK_X
839+
&& (lock2->type_mode & LOCK_MODE_MASK) == LOCK_X
840+
&& wsrep_thd_order_before(trx->mysql_thd,
841+
lock2->trx->mysql_thd)) {
842+
return false;
843+
}
844+
845+
/* We very well can let bf to wait normally as other
846+
BF will be replayed in case of conflict. For debug
847+
builds we will do additional sanity checks to catch
848+
unsupported bf wait if any. */
849+
ut_d(wsrep_assert_no_bf_bf_wait(lock2, trx));
841850
#endif /* WITH_WSREP */
842851

843852
return true;
@@ -2043,6 +2052,14 @@ lock_rec_has_to_wait_in_queue(
20432052
if (heap_no < lock_rec_get_n_bits(lock)
20442053
&& (p[bit_offset] & bit_mask)
20452054
&& lock_has_to_wait(wait_lock, lock)) {
2055+
#ifdef WITH_WSREP
2056+
if (lock->trx->is_wsrep()
2057+
&& wsrep_thd_order_before(wait_lock->trx->mysql_thd,
2058+
lock->trx->mysql_thd)) {
2059+
/* don't wait for another BF lock */
2060+
continue;
2061+
}
2062+
#endif
20462063
return(lock);
20472064
}
20482065
}

0 commit comments

Comments
 (0)