@@ -925,15 +925,21 @@ lock_reset_lock_and_trx_wait(
925925
926926ib_logf (IB_LOG_LEVEL_INFO,
927927" Trx id " TRX_ID_FMT
928- " is waiting a lock in statement %s "
928+ " is waiting a lock "
929929" for this trx id " TRX_ID_FMT
930- " and statement %s wait_lock %p" ,
930+ " wait_lock %p" ,
931931lock->trx ->id ,
932- stmt ? stmt : " NULL" ,
933932trx_id,
934- stmt2 ? stmt2 : " NULL" ,
935933lock->trx ->lock .wait_lock );
936934
935+ if (stmt) {
936+ ib_logf (IB_LOG_LEVEL_INFO, " SQL1: %s\n " , stmt);
937+ }
938+
939+ if (stmt2) {
940+ ib_logf (IB_LOG_LEVEL_INFO, " SQL2: %s\n " , stmt2);
941+ }
942+
937943ut_ad (lock->trx ->lock .wait_lock == lock);
938944}
939945
@@ -1151,7 +1157,7 @@ lock_rec_has_to_wait(
11511157type_mode, lock_is_on_supremum);
11521158fprintf (stderr,
11531159" conflicts states: my %d locked %d\n " ,
1154- wsrep_thd_conflict_state (trx->mysql_thd , FALSE ),
1160+ wsrep_thd_conflict_state (trx->mysql_thd , FALSE ),
11551161wsrep_thd_conflict_state (lock2->trx ->mysql_thd , FALSE ) );
11561162lock_rec_print (stderr, lock2);
11571163if (for_locking) return FALSE ;
@@ -1687,7 +1693,7 @@ lock_rec_discard(lock_t* in_lock);
16871693Checks if some other transaction has a lock request in the queue.
16881694@return lock or NULL */
16891695static
1690- const lock_t *
1696+ lock_t *
16911697lock_rec_other_has_expl_req (
16921698/* ========================*/
16931699enum lock_mode mode,/* !< in: LOCK_S or LOCK_X */
@@ -1704,7 +1710,7 @@ lock_rec_other_has_expl_req(
17041710requests by all transactions
17051711are taken into account */
17061712{
1707- const lock_t * lock;
1713+ lock_t * lock;
17081714
17091715ut_ad (lock_mutex_own ());
17101716ut_ad (mode == LOCK_X || mode == LOCK_S);
@@ -1713,7 +1719,7 @@ lock_rec_other_has_expl_req(
17131719
17141720for (lock = lock_rec_get_first (block, heap_no);
17151721 lock != NULL ;
1716- lock = lock_rec_get_next_const (heap_no, lock)) {
1722+ lock = lock_rec_get_next (heap_no, lock)) {
17171723
17181724if (lock->trx != trx
17191725 && (gap
@@ -1800,7 +1806,7 @@ Checks if some other transaction has a conflicting explicit lock request
18001806in the queue, so that we have to wait.
18011807@return lock or NULL */
18021808static
1803- const lock_t *
1809+ lock_t *
18041810lock_rec_other_has_conflicting (
18051811/* ===========================*/
18061812enum lock_mode mode,/* !< in: LOCK_S or LOCK_X,
@@ -1812,7 +1818,7 @@ lock_rec_other_has_conflicting(
18121818ulint heap_no,/* !< in: heap number of the record */
18131819const trx_t * trx)/* !< in: our transaction */
18141820{
1815- const lock_t * lock;
1821+ lock_t * lock;
18161822ibool is_supremum;
18171823
18181824ut_ad (lock_mutex_own ());
@@ -1821,13 +1827,16 @@ lock_rec_other_has_conflicting(
18211827
18221828for (lock = lock_rec_get_first (block, heap_no);
18231829 lock != NULL ;
1824- lock = lock_rec_get_next_const (heap_no, lock)) {
1830+ lock = lock_rec_get_next (heap_no, lock)) {
18251831
18261832#ifdef WITH_WSREP
18271833if (lock_rec_has_to_wait (TRUE , trx, mode, lock, is_supremum)) {
18281834if (wsrep_on_trx (trx)) {
18291835trx_mutex_enter (lock->trx );
1830- wsrep_kill_victim (trx, lock);
1836+ /* Below function will roll back either trx
1837+ or lock->trx depending on priority of the
1838+ transaction. */
1839+ wsrep_kill_victim (const_cast <trx_t *>(trx), lock);
18311840trx_mutex_exit (lock->trx );
18321841}
18331842#else
@@ -2023,15 +2032,17 @@ wsrep_print_wait_locks(
20232032{
20242033if (wsrep_debug && c_lock->trx ->lock .wait_lock != c_lock) {
20252034fprintf (stderr, " WSREP: c_lock != wait lock\n " );
2026- if (lock_get_type_low (c_lock) & LOCK_TABLE)
2035+ if (lock_get_type_low (c_lock) & LOCK_TABLE) {
20272036lock_table_print (stderr, c_lock);
2028- else
2037+ } else {
20292038lock_rec_print (stderr, c_lock);
2039+ }
20302040
2031- if (lock_get_type_low (c_lock->trx ->lock .wait_lock ) & LOCK_TABLE)
2041+ if (lock_get_type_low (c_lock->trx ->lock .wait_lock ) & LOCK_TABLE) {
20322042lock_table_print (stderr, c_lock->trx ->lock .wait_lock );
2033- else
2043+ } else {
20342044lock_rec_print (stderr, c_lock->trx ->lock .wait_lock );
2045+ }
20352046}
20362047}
20372048#endif /* WITH_WSREP */
@@ -2217,8 +2228,8 @@ lock_rec_create(
22172228if (wsrep_debug) {
22182229fprintf (
22192230stderr,
2220- " WSREP: c_lock canceled %llu \n " ,
2221- (ulonglong) c_lock->trx ->id );
2231+ " WSREP: c_lock canceled " TRX_ID_FMT " \n " ,
2232+ c_lock->trx ->id );
22222233}
22232234
22242235/* have to bail out here to avoid lock_set_lock... */
@@ -2519,6 +2530,16 @@ lock_rec_enqueue_waiting(
25192530err = DB_LOCK_WAIT;
25202531}
25212532
2533+ #ifdef WITH_WSREP
2534+ if (!lock_get_wait (lock) && wsrep_thd_is_BF (trx->mysql_thd , FALSE )) {
2535+ if (wsrep_debug) {
2536+ fprintf (stderr, " WSREP: BF thread got lock granted early, ID " TRX_ID_FMT
2537+ " \n " ,
2538+ lock->trx ->id );
2539+ }
2540+ return (DB_SUCCESS);
2541+ }
2542+ #endif /* WITH_WSREP */
25222543// Move it only when it does not cause a deadlock.
25232544if (err != DB_DEADLOCK
25242545&& innodb_lock_schedule_algorithm
@@ -2814,7 +2835,7 @@ lock_rec_lock_slow(
28142835/* The trx already has a strong enough lock on rec: do
28152836nothing */
28162837#ifdef WITH_WSREP
2817- } else if ((c_lock = ( ib_lock_t *) lock_rec_other_has_conflicting (
2838+ } else if ((c_lock = lock_rec_other_has_conflicting (
28182839 static_cast <enum lock_mode>(mode),
28192840 block, heap_no, trx))) {
28202841#else
@@ -2946,6 +2967,15 @@ lock_rec_has_to_wait_in_queue(
29462967#ifdef WITH_WSREP
29472968if (wsrep_thd_is_BF (wait_lock->trx ->mysql_thd , FALSE ) &&
29482969 wsrep_thd_is_BF (lock->trx ->mysql_thd , TRUE )) {
2970+ if (wsrep_debug) {
2971+ fprintf (stderr,
2972+ " BF-BF lock conflict " TRX_ID_FMT
2973+ " : " TRX_ID_FMT " \n " ,
2974+ wait_lock->trx ->id ,
2975+ lock->trx ->id );
2976+ lock_rec_print (stderr, wait_lock);
2977+ lock_rec_print (stderr, lock);
2978+ }
29492979/* don't wait for another BF lock */
29502980continue ;
29512981}
@@ -3104,7 +3134,7 @@ lock_grant_and_move_on_page(
31043134&& !lock_rec_has_to_wait_in_queue (lock)) {
31053135
31063136lock_grant (lock, false );
3107-
3137+
31083138if (previous != NULL ) {
31093139/* Move the lock to the head of the list. */
31103140HASH_GET_NEXT (hash, previous) = HASH_GET_NEXT (hash, lock);
@@ -4978,8 +5008,8 @@ lock_table_create(
49785008}
49795009
49805010if (wsrep_debug) {
4981- fprintf (stderr, " WSREP: c_lock canceled %llu \n " ,
4982- (ulonglong) c_lock->trx ->id );
5011+ fprintf (stderr, " WSREP: c_lock canceled " TRX_ID_FMT " \n " ,
5012+ c_lock->trx ->id );
49835013}
49845014}
49855015if (c_lock) {
@@ -5251,7 +5281,7 @@ Checks if other transactions have an incompatible mode lock request in
52515281the lock queue.
52525282@return lock or NULL */
52535283UNIV_INLINE
5254- const lock_t *
5284+ lock_t *
52555285lock_table_other_has_incompatible (
52565286/* ==============================*/
52575287const trx_t * trx,/* !< in: transaction, or NULL if all
@@ -5262,7 +5292,7 @@ lock_table_other_has_incompatible(
52625292const dict_table_t * table,/* !< in: table */
52635293enum lock_mode mode)/* !< in: lock mode */
52645294{
5265- const lock_t * lock;
5295+ lock_t * lock;
52665296
52675297ut_ad (lock_mutex_own ());
52685298
@@ -5315,7 +5345,7 @@ lock_table(
53155345#endif
53165346trx_t * trx;
53175347dberr_t err;
5318- const lock_t * wait_for;
5348+ lock_t * wait_for;
53195349
53205350ut_ad (table != NULL );
53215351ut_ad (thr != NULL );
@@ -5362,13 +5392,13 @@ lock_table(
53625392
53635393if (wait_for != NULL ) {
53645394#ifdef WITH_WSREP
5365- err = lock_table_enqueue_waiting (( ib_lock_t *) wait_for, mode | flags, table, thr);
5395+ err = lock_table_enqueue_waiting (wait_for, mode | flags, table, thr);
53665396#else
53675397err = lock_table_enqueue_waiting (mode | flags, table, thr);
53685398#endif
53695399} else {
53705400#ifdef WITH_WSREP
5371- lock_table_create (c_lock, table, mode | flags, trx);
5401+ lock_table_create (c_lock, table, mode | flags, trx);
53725402#else
53735403lock_table_create (table, mode | flags, trx);
53745404#endif
@@ -7036,10 +7066,10 @@ lock_rec_insert_check_and_lock(
70367066on the successor, which produced an unnecessary deadlock. */
70377067
70387068#ifdef WITH_WSREP
7039- if ((c_lock = ( ib_lock_t *) lock_rec_other_has_conflicting (
7040- static_cast <enum lock_mode>(
7041- LOCK_X | LOCK_GAP | LOCK_INSERT_INTENTION),
7042- block, next_rec_heap_no, trx))) {
7069+ if ((c_lock = lock_rec_other_has_conflicting (
7070+ static_cast <enum lock_mode>(
7071+ LOCK_X | LOCK_GAP | LOCK_INSERT_INTENTION),
7072+ block, next_rec_heap_no, trx))) {
70437073#else
70447074if (lock_rec_other_has_conflicting (
70457075 static_cast <enum lock_mode>(
@@ -7052,7 +7082,7 @@ lock_rec_insert_check_and_lock(
70527082
70537083#ifdef WITH_WSREP
70547084err = lock_rec_enqueue_waiting (c_lock,
7055- LOCK_X | LOCK_GAP | LOCK_INSERT_INTENTION,
7085+ LOCK_X | LOCK_GAP | LOCK_INSERT_INTENTION,
70567086block, next_rec_heap_no, index, thr);
70577087#else
70587088err = lock_rec_enqueue_waiting (
0 commit comments