Commit 36a96943 authored by Jan Lindström's avatar Jan Lindström

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.
parent 44b0c869
......@@ -99,7 +99,7 @@ extern struct wsrep_service_st {
enum wsrep_conflict_state (*wsrep_thd_get_conflict_state_func)(MYSQL_THD);
my_bool (*wsrep_thd_is_BF_func)(MYSQL_THD , my_bool);
my_bool (*wsrep_thd_is_wsrep_func)(MYSQL_THD thd);
char * (*wsrep_thd_query_func)(THD *thd);
const char * (*wsrep_thd_query_func)(THD *thd);
enum wsrep_query_state (*wsrep_thd_query_state_func)(THD *thd);
const char * (*wsrep_thd_query_state_str_func)(THD *thd);
int (*wsrep_thd_retry_counter_func)(THD *thd);
......@@ -182,7 +182,7 @@ extern long wsrep_protocol_version;
bool wsrep_consistency_check(THD *thd);
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);
char *wsrep_thd_query(THD *thd);
const char *wsrep_thd_query(THD *thd);
const char *wsrep_thd_conflict_state_str(THD *thd);
const char *wsrep_thd_exec_mode_str(THD *thd);
const char *wsrep_thd_query_state_str(THD *thd);
......
......@@ -101,8 +101,8 @@ enum wsrep_conflict_state wsrep_thd_get_conflict_state(THD *)
my_bool wsrep_thd_is_wsrep(THD *)
{ return 0; }
char *wsrep_thd_query(THD *)
{ return 0; }
const char *wsrep_thd_query(THD *)
{ return "NULL"; }
enum wsrep_query_state wsrep_thd_query_state(THD *)
{ return QUERY_IDLE; }
......
......@@ -1594,25 +1594,6 @@ static bool wsrep_can_run_in_toi(THD *thd, const char *db, const char *table,
}
}
static const char* wsrep_get_query_or_msg(const THD* thd)
{
switch(thd->lex->sql_command)
{
case SQLCOM_CREATE_USER:
return "CREATE USER";
case SQLCOM_GRANT:
return "GRANT";
case SQLCOM_REVOKE:
return "REVOKE";
case SQLCOM_SET_OPTION:
if (thd->lex->definer)
return "SET PASSWORD";
/* fallthrough */
default:
return thd->query();
}
}
/*
returns:
0: statement was replicated as TOI
......@@ -1636,7 +1617,7 @@ static int wsrep_TOI_begin(THD *thd, char *db_, char *table_,
}
WSREP_DEBUG("TO BEGIN: %lld, %d : %s", (long long)wsrep_thd_trx_seqno(thd),
thd->wsrep_exec_mode, wsrep_get_query_or_msg(thd));
thd->wsrep_exec_mode, wsrep_thd_query(thd));
switch (thd->lex->sql_command)
{
......@@ -1716,13 +1697,13 @@ static void wsrep_TOI_end(THD *thd) {
wsrep_to_isolation--;
WSREP_DEBUG("TO END: %lld, %d: %s", (long long)wsrep_thd_trx_seqno(thd),
thd->wsrep_exec_mode, wsrep_get_query_or_msg(thd));
thd->wsrep_exec_mode, wsrep_thd_query(thd));
wsrep_set_SE_checkpoint(thd->wsrep_trx_meta.gtid.uuid,
thd->wsrep_trx_meta.gtid.seqno);
WSREP_DEBUG("TO END: %lld, update seqno",
(long long)wsrep_thd_trx_seqno(thd));
if (WSREP_OK == (ret = wsrep->to_execute_end(wsrep, thd->thread_id))) {
WSREP_DEBUG("TO END: %lld", (long long)wsrep_thd_trx_seqno(thd));
}
......@@ -2674,9 +2655,28 @@ extern "C" query_id_t wsrep_thd_query_id(THD *thd)
}
char *wsrep_thd_query(THD *thd)
const char *wsrep_thd_query(THD *thd)
{
return (thd) ? thd->query() : NULL;
if (thd)
{
switch(thd->lex->sql_command)
{
case SQLCOM_CREATE_USER:
return "CREATE USER";
case SQLCOM_GRANT:
return "GRANT";
case SQLCOM_REVOKE:
return "REVOKE";
case SQLCOM_SET_OPTION:
if (thd->lex->definer)
return "SET PASSWORD";
/* fallthrough */
default:
if (thd->query())
return thd->query();
}
}
return "NULL";
}
......
......@@ -2472,17 +2472,27 @@ row_upd_sec_index_entry(
case DB_NO_REFERENCED_ROW:
err = DB_SUCCESS;
break;
case DB_LOCK_WAIT:
if (wsrep_debug) {
ib::warn() << "WSREP: sec index FK lock wait"
<< " index " << index->name
<< " table " << index->table->name
<< " query " << wsrep_thd_query(trx->mysql_thd);
}
break;
case DB_DEADLOCK:
if (wsrep_debug) {
ib::warn() << "WSREP: sec index FK check fail for deadlock"
<< " index " << index->name
<< " table " << index->table->name;
<< " table " << index->table->name
<< " query " << wsrep_thd_query(trx->mysql_thd);
}
break;
default:
ib::error() << "WSREP: referenced FK check fail: " << ut_strerr(err)
<< " index " << index->name
<< " table " << index->table->name;
<< " table " << index->table->name
<< " query " << wsrep_thd_query(trx->mysql_thd);
break;
}
......
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