Skip to content

Commit 36a9694

Browse files
author
Jan Lindström
committed
MDEV-18562 [ERROR] InnoDB: WSREP: referenced FK check fail: Lock wait index
Lock wait can happen on secondary index when doing FK checks for wsrep. We should just return error to upper layer and applier will retry operation when needed.
1 parent 44b0c86 commit 36a9694

File tree

4 files changed

+40
-30
lines changed

4 files changed

+40
-30
lines changed

include/mysql/service_wsrep.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ extern struct wsrep_service_st {
9999
enum wsrep_conflict_state (*wsrep_thd_get_conflict_state_func)(MYSQL_THD);
100100
my_bool (*wsrep_thd_is_BF_func)(MYSQL_THD , my_bool);
101101
my_bool (*wsrep_thd_is_wsrep_func)(MYSQL_THD thd);
102-
char * (*wsrep_thd_query_func)(THD *thd);
102+
const char * (*wsrep_thd_query_func)(THD *thd);
103103
enum wsrep_query_state (*wsrep_thd_query_state_func)(THD *thd);
104104
const char * (*wsrep_thd_query_state_str_func)(THD *thd);
105105
int (*wsrep_thd_retry_counter_func)(THD *thd);
@@ -182,7 +182,7 @@ extern long wsrep_protocol_version;
182182

183183
bool wsrep_consistency_check(THD *thd);
184184
bool wsrep_prepare_key(const unsigned char* cache_key, size_t cache_key_len, const unsigned char* row_id, size_t row_id_len, struct wsrep_buf* key, size_t* key_len);
185-
char *wsrep_thd_query(THD *thd);
185+
const char *wsrep_thd_query(THD *thd);
186186
const char *wsrep_thd_conflict_state_str(THD *thd);
187187
const char *wsrep_thd_exec_mode_str(THD *thd);
188188
const char *wsrep_thd_query_state_str(THD *thd);

sql/wsrep_dummy.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ enum wsrep_conflict_state wsrep_thd_get_conflict_state(THD *)
101101
my_bool wsrep_thd_is_wsrep(THD *)
102102
{ return 0; }
103103

104-
char *wsrep_thd_query(THD *)
105-
{ return 0; }
104+
const char *wsrep_thd_query(THD *)
105+
{ return "NULL"; }
106106

107107
enum wsrep_query_state wsrep_thd_query_state(THD *)
108108
{ return QUERY_IDLE; }

sql/wsrep_mysqld.cc

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,25 +1594,6 @@ static bool wsrep_can_run_in_toi(THD *thd, const char *db, const char *table,
15941594
}
15951595
}
15961596

1597-
static const char* wsrep_get_query_or_msg(const THD* thd)
1598-
{
1599-
switch(thd->lex->sql_command)
1600-
{
1601-
case SQLCOM_CREATE_USER:
1602-
return "CREATE USER";
1603-
case SQLCOM_GRANT:
1604-
return "GRANT";
1605-
case SQLCOM_REVOKE:
1606-
return "REVOKE";
1607-
case SQLCOM_SET_OPTION:
1608-
if (thd->lex->definer)
1609-
return "SET PASSWORD";
1610-
/* fallthrough */
1611-
default:
1612-
return thd->query();
1613-
}
1614-
}
1615-
16161597
/*
16171598
returns:
16181599
0: statement was replicated as TOI
@@ -1636,7 +1617,7 @@ static int wsrep_TOI_begin(THD *thd, char *db_, char *table_,
16361617
}
16371618

16381619
WSREP_DEBUG("TO BEGIN: %lld, %d : %s", (long long)wsrep_thd_trx_seqno(thd),
1639-
thd->wsrep_exec_mode, wsrep_get_query_or_msg(thd));
1620+
thd->wsrep_exec_mode, wsrep_thd_query(thd));
16401621

16411622
switch (thd->lex->sql_command)
16421623
{
@@ -1716,13 +1697,13 @@ static void wsrep_TOI_end(THD *thd) {
17161697
wsrep_to_isolation--;
17171698

17181699
WSREP_DEBUG("TO END: %lld, %d: %s", (long long)wsrep_thd_trx_seqno(thd),
1719-
thd->wsrep_exec_mode, wsrep_get_query_or_msg(thd));
1700+
thd->wsrep_exec_mode, wsrep_thd_query(thd));
17201701

17211702
wsrep_set_SE_checkpoint(thd->wsrep_trx_meta.gtid.uuid,
17221703
thd->wsrep_trx_meta.gtid.seqno);
17231704
WSREP_DEBUG("TO END: %lld, update seqno",
17241705
(long long)wsrep_thd_trx_seqno(thd));
1725-
1706+
17261707
if (WSREP_OK == (ret = wsrep->to_execute_end(wsrep, thd->thread_id))) {
17271708
WSREP_DEBUG("TO END: %lld", (long long)wsrep_thd_trx_seqno(thd));
17281709
}
@@ -2674,9 +2655,28 @@ extern "C" query_id_t wsrep_thd_query_id(THD *thd)
26742655
}
26752656

26762657

2677-
char *wsrep_thd_query(THD *thd)
2658+
const char *wsrep_thd_query(THD *thd)
26782659
{
2679-
return (thd) ? thd->query() : NULL;
2660+
if (thd)
2661+
{
2662+
switch(thd->lex->sql_command)
2663+
{
2664+
case SQLCOM_CREATE_USER:
2665+
return "CREATE USER";
2666+
case SQLCOM_GRANT:
2667+
return "GRANT";
2668+
case SQLCOM_REVOKE:
2669+
return "REVOKE";
2670+
case SQLCOM_SET_OPTION:
2671+
if (thd->lex->definer)
2672+
return "SET PASSWORD";
2673+
/* fallthrough */
2674+
default:
2675+
if (thd->query())
2676+
return thd->query();
2677+
}
2678+
}
2679+
return "NULL";
26802680
}
26812681

26822682

storage/innobase/row/row0upd.cc

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2472,17 +2472,27 @@ row_upd_sec_index_entry(
24722472
case DB_NO_REFERENCED_ROW:
24732473
err = DB_SUCCESS;
24742474
break;
2475+
case DB_LOCK_WAIT:
2476+
if (wsrep_debug) {
2477+
ib::warn() << "WSREP: sec index FK lock wait"
2478+
<< " index " << index->name
2479+
<< " table " << index->table->name
2480+
<< " query " << wsrep_thd_query(trx->mysql_thd);
2481+
}
2482+
break;
24752483
case DB_DEADLOCK:
24762484
if (wsrep_debug) {
24772485
ib::warn() << "WSREP: sec index FK check fail for deadlock"
24782486
<< " index " << index->name
2479-
<< " table " << index->table->name;
2487+
<< " table " << index->table->name
2488+
<< " query " << wsrep_thd_query(trx->mysql_thd);
24802489
}
24812490
break;
24822491
default:
24832492
ib::error() << "WSREP: referenced FK check fail: " << ut_strerr(err)
24842493
<< " index " << index->name
2485-
<< " table " << index->table->name;
2494+
<< " table " << index->table->name
2495+
<< " query " << wsrep_thd_query(trx->mysql_thd);
24862496

24872497
break;
24882498
}

0 commit comments

Comments
 (0)