@@ -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
843852return true ;
@@ -2043,6 +2052,14 @@ lock_rec_has_to_wait_in_queue(
20432052if (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
20462063return (lock);
20472064}
20482065}
0 commit comments