Commit 3ec139a4 authored by Jan Lindström's avatar Jan Lindström

Merge pull request #104 from philip-galera/10.0-galera-mysql-wsrep-gh202

Refs codership/mysql-wsrep#202 Added schema info into wsrep messages
parents 4d33f9dc 43b2a451
...@@ -1195,7 +1195,8 @@ int wsrep_create_event_query(THD *thd, uchar** buf, size_t* buf_len) ...@@ -1195,7 +1195,8 @@ int wsrep_create_event_query(THD *thd, uchar** buf, size_t* buf_len)
if (create_query_string(thd, &log_query)) if (create_query_string(thd, &log_query))
{ {
WSREP_WARN("events create string failed: %s", thd->query()); WSREP_WARN("events create string failed: schema: %s, query: %s",
(thd->db ? thd->db : "(null)"), thd->query());
return 1; return 1;
} }
return wsrep_to_buf_helper(thd, log_query.ptr(), log_query.length(), buf, buf_len); return wsrep_to_buf_helper(thd, log_query.ptr(), log_query.length(), buf, buf_len);
...@@ -1222,7 +1223,8 @@ int wsrep_alter_event_query(THD *thd, uchar** buf, size_t* buf_len) ...@@ -1222,7 +1223,8 @@ int wsrep_alter_event_query(THD *thd, uchar** buf, size_t* buf_len)
if (wsrep_alter_query_string(thd, &log_query)) if (wsrep_alter_query_string(thd, &log_query))
{ {
WSREP_WARN("events alter string failed: %s", thd->query()); WSREP_WARN("events alter string failed: schema: %s, query: %s",
(thd->db ? thd->db : "(null)"), thd->query());
return 1; return 1;
} }
return wsrep_to_buf_helper(thd, log_query.ptr(), log_query.length(), buf, buf_len); return wsrep_to_buf_helper(thd, log_query.ptr(), log_query.length(), buf, buf_len);
......
...@@ -33,7 +33,8 @@ void sql_print_information(const char *format, ...) ...@@ -33,7 +33,8 @@ void sql_print_information(const char *format, ...)
extern bool extern bool
wsrep_grant_mdl_exception(MDL_context *requestor_ctx, wsrep_grant_mdl_exception(MDL_context *requestor_ctx,
MDL_ticket *ticket); MDL_ticket *ticket,
const MDL_key *key);
#endif /* WITH_WSREP */ #endif /* WITH_WSREP */
#ifdef HAVE_PSI_INTERFACE #ifdef HAVE_PSI_INTERFACE
static PSI_mutex_key key_MDL_map_mutex; static PSI_mutex_key key_MDL_map_mutex;
...@@ -1549,7 +1550,8 @@ void MDL_lock::Ticket_list::add_ticket(MDL_ticket *ticket) ...@@ -1549,7 +1550,8 @@ void MDL_lock::Ticket_list::add_ticket(MDL_ticket *ticket)
if (granted->get_ctx() != ticket->get_ctx() && if (granted->get_ctx() != ticket->get_ctx() &&
granted->is_incompatible_when_granted(ticket->get_type())) granted->is_incompatible_when_granted(ticket->get_type()))
{ {
if (!wsrep_grant_mdl_exception(ticket->get_ctx(), granted)) if (!wsrep_grant_mdl_exception(ticket->get_ctx(), granted,
&ticket->get_lock()->key))
{ {
WSREP_DEBUG("MDL victim killed at add_ticket"); WSREP_DEBUG("MDL victim killed at add_ticket");
} }
...@@ -1941,7 +1943,7 @@ MDL_lock::can_grant_lock(enum_mdl_type type_arg, ...@@ -1941,7 +1943,7 @@ MDL_lock::can_grant_lock(enum_mdl_type type_arg,
wsrep_thd_query(requestor_ctx->wsrep_get_thd())); wsrep_thd_query(requestor_ctx->wsrep_get_thd()));
can_grant = true; can_grant = true;
} }
else if (!wsrep_grant_mdl_exception(requestor_ctx, ticket)) else if (!wsrep_grant_mdl_exception(requestor_ctx, ticket, &key))
{ {
wsrep_can_grant= FALSE; wsrep_can_grant= FALSE;
if (wsrep_log_conflicts) if (wsrep_log_conflicts)
......
...@@ -457,6 +457,7 @@ class MDL_request ...@@ -457,6 +457,7 @@ class MDL_request
MDL_key key; MDL_key key;
public: public:
static void *operator new(size_t size, MEM_ROOT *mem_root) throw () static void *operator new(size_t size, MEM_ROOT *mem_root) throw ()
{ return alloc_root(mem_root, size); } { return alloc_root(mem_root, size); }
static void operator delete(void *ptr, MEM_ROOT *mem_root) {} static void operator delete(void *ptr, MEM_ROOT *mem_root) {}
......
...@@ -2302,7 +2302,8 @@ int wsrep_create_sp(THD *thd, uchar** buf, size_t* buf_len) ...@@ -2302,7 +2302,8 @@ int wsrep_create_sp(THD *thd, uchar** buf, size_t* buf_len)
&(thd->lex->definer->host), &(thd->lex->definer->host),
saved_mode)) saved_mode))
{ {
WSREP_WARN("SP create string failed: %s", thd->query()); WSREP_WARN("SP create string failed: schema: %s, query: %s",
(thd->db ? thd->db : "(null)"), thd->query());
return 1; return 1;
} }
return wsrep_to_buf_helper(thd, log_query.ptr(), log_query.length(), buf, buf_len); return wsrep_to_buf_helper(thd, log_query.ptr(), log_query.length(), buf, buf_len);
......
...@@ -239,8 +239,9 @@ static int wsrep_rollback(handlerton *hton, THD *thd, bool all) ...@@ -239,8 +239,9 @@ static int wsrep_rollback(handlerton *hton, THD *thd, bool all)
if (WSREP(thd) && wsrep->post_rollback(wsrep, &thd->wsrep_ws_handle)) if (WSREP(thd) && wsrep->post_rollback(wsrep, &thd->wsrep_ws_handle))
{ {
DBUG_PRINT("wsrep", ("setting rollback fail")); DBUG_PRINT("wsrep", ("setting rollback fail"));
WSREP_ERROR("settting rollback fail: thd: %llu SQL: %s", WSREP_ERROR("settting rollback fail: thd: %llu, schema: %s, SQL: %s",
(long long)thd->real_id, thd->query()); (long long)thd->real_id, (thd->db ? thd->db : "(null)"),
thd->query());
} }
wsrep_cleanup_transaction(thd); wsrep_cleanup_transaction(thd);
} }
...@@ -279,8 +280,9 @@ int wsrep_commit(handlerton *hton, THD *thd, bool all) ...@@ -279,8 +280,9 @@ int wsrep_commit(handlerton *hton, THD *thd, bool all)
if (WSREP(thd) && wsrep->post_rollback(wsrep, &thd->wsrep_ws_handle)) if (WSREP(thd) && wsrep->post_rollback(wsrep, &thd->wsrep_ws_handle))
{ {
DBUG_PRINT("wsrep", ("setting rollback fail")); DBUG_PRINT("wsrep", ("setting rollback fail"));
WSREP_ERROR("settting rollback fail: thd: %llu SQL: %s", WSREP_ERROR("settting rollback fail: thd: %llu, schema: %s, SQL: %s",
(long long)thd->real_id, thd->query()); (long long)thd->real_id, (thd->db ? thd->db : "(null)"),
thd->query());
} }
wsrep_cleanup_transaction(thd); wsrep_cleanup_transaction(thd);
} }
...@@ -441,9 +443,11 @@ wsrep_run_wsrep_commit(THD *thd, handlerton *hton, bool all) ...@@ -441,9 +443,11 @@ wsrep_run_wsrep_commit(THD *thd, handlerton *hton, bool all)
if (WSREP_UNDEFINED_TRX_ID == thd->wsrep_ws_handle.trx_id) if (WSREP_UNDEFINED_TRX_ID == thd->wsrep_ws_handle.trx_id)
{ {
WSREP_WARN("SQL statement was ineffective, THD: %lu, buf: %zu\n" WSREP_WARN("SQL statement was ineffective, THD: %lu, buf: %zu\n"
"schema: %s \n"
"QUERY: %s\n" "QUERY: %s\n"
" => Skipping replication", " => Skipping replication",
thd->thread_id, data_len, thd->query()); thd->thread_id, data_len,
(thd->db ? thd->db : "(null)"), thd->query());
rcode = WSREP_TRX_FAIL; rcode = WSREP_TRX_FAIL;
} }
else if (!rcode) else if (!rcode)
...@@ -458,8 +462,8 @@ wsrep_run_wsrep_commit(THD *thd, handlerton *hton, bool all) ...@@ -458,8 +462,8 @@ wsrep_run_wsrep_commit(THD *thd, handlerton *hton, bool all)
&thd->wsrep_trx_meta); &thd->wsrep_trx_meta);
if (rcode == WSREP_TRX_MISSING) { if (rcode == WSREP_TRX_MISSING) {
WSREP_WARN("Transaction missing in provider, thd: %ld, SQL: %s", WSREP_WARN("Transaction missing in provider, thd: %ld, schema: %s, SQL: %s",
thd->thread_id, thd->query()); thd->thread_id, (thd->db ? thd->db : "(null)"), thd->query());
rcode = WSREP_TRX_FAIL; rcode = WSREP_TRX_FAIL;
} else if (rcode == WSREP_BF_ABORT) { } else if (rcode == WSREP_BF_ABORT) {
WSREP_DEBUG("thd %lu seqno %lld BF aborted by provider, will replay", WSREP_DEBUG("thd %lu seqno %lld BF aborted by provider, will replay",
......
...@@ -1253,9 +1253,11 @@ static int wsrep_TOI_begin(THD *thd, char *db_, char *table_, ...@@ -1253,9 +1253,11 @@ static int wsrep_TOI_begin(THD *thd, char *db_, char *table_,
} }
else if (key_arr.keys_len > 0) { else if (key_arr.keys_len > 0) {
/* jump to error handler in mysql_execute_command() */ /* jump to error handler in mysql_execute_command() */
WSREP_WARN("TO isolation failed for: %d, sql: %s. Check wsrep " WSREP_WARN("TO isolation failed for: %d, schema: %s, sql: %s. Check wsrep "
"connection state and retry the query.", "connection state and retry the query.",
ret, (thd->query()) ? thd->query() : "void"); ret,
(thd->db ? thd->db : "(null)"),
(thd->query()) ? thd->query() : "void");
my_error(ER_LOCK_DEADLOCK, MYF(0), "WSREP replication failed. Check " my_error(ER_LOCK_DEADLOCK, MYF(0), "WSREP replication failed. Check "
"your wsrep connection state and retry the query."); "your wsrep connection state and retry the query.");
wsrep_keys_free(&key_arr); wsrep_keys_free(&key_arr);
...@@ -1288,8 +1290,10 @@ static void wsrep_TOI_end(THD *thd) { ...@@ -1288,8 +1290,10 @@ static void wsrep_TOI_end(THD *thd) {
WSREP_DEBUG("TO END: %lld", (long long)wsrep_thd_trx_seqno(thd)); WSREP_DEBUG("TO END: %lld", (long long)wsrep_thd_trx_seqno(thd));
} }
else { else {
WSREP_WARN("TO isolation end failed for: %d, sql: %s", WSREP_WARN("TO isolation end failed for: %d, schema: %s, sql: %s",
ret, (thd->query()) ? thd->query() : "void"); ret,
(thd->db ? thd->db : "(null)"),
(thd->query()) ? thd->query() : "void");
} }
} }
...@@ -1302,7 +1306,10 @@ static int wsrep_RSU_begin(THD *thd, char *db_, char *table_) ...@@ -1302,7 +1306,10 @@ static int wsrep_RSU_begin(THD *thd, char *db_, char *table_)
ret = wsrep->desync(wsrep); ret = wsrep->desync(wsrep);
if (ret != WSREP_OK) if (ret != WSREP_OK)
{ {
WSREP_WARN("RSU desync failed %d for %s", ret, thd->query()); WSREP_WARN("RSU desync failed %d for schema: %s, query: %s",
ret,
(thd->db ? thd->db : "(null)"),
thd->query());
my_error(ER_LOCK_DEADLOCK, MYF(0)); my_error(ER_LOCK_DEADLOCK, MYF(0));
return(ret); return(ret);
} }
...@@ -1313,7 +1320,9 @@ static int wsrep_RSU_begin(THD *thd, char *db_, char *table_) ...@@ -1313,7 +1320,9 @@ static int wsrep_RSU_begin(THD *thd, char *db_, char *table_)
if (wsrep_wait_committing_connections_close(5000)) if (wsrep_wait_committing_connections_close(5000))
{ {
/* no can do, bail out from DDL */ /* no can do, bail out from DDL */
WSREP_WARN("RSU failed due to pending transactions, %s", thd->query()); WSREP_WARN("RSU failed due to pending transactions, schema: %s, query %s",
(thd->db ? thd->db : "(null)"),
thd->query());
mysql_mutex_lock(&LOCK_wsrep_replaying); mysql_mutex_lock(&LOCK_wsrep_replaying);
wsrep_replaying--; wsrep_replaying--;
mysql_mutex_unlock(&LOCK_wsrep_replaying); mysql_mutex_unlock(&LOCK_wsrep_replaying);
...@@ -1321,7 +1330,10 @@ static int wsrep_RSU_begin(THD *thd, char *db_, char *table_) ...@@ -1321,7 +1330,10 @@ static int wsrep_RSU_begin(THD *thd, char *db_, char *table_)
ret = wsrep->resync(wsrep); ret = wsrep->resync(wsrep);
if (ret != WSREP_OK) if (ret != WSREP_OK)
{ {
WSREP_WARN("resync failed %d for %s", ret, thd->query()); WSREP_WARN("resync failed %d for schema: %s, query: %s",
ret,
(thd->db ? thd->db : "(null)"),
thd->query());
} }
my_error(ER_LOCK_DEADLOCK, MYF(0)); my_error(ER_LOCK_DEADLOCK, MYF(0));
return(1); return(1);
...@@ -1330,7 +1342,9 @@ static int wsrep_RSU_begin(THD *thd, char *db_, char *table_) ...@@ -1330,7 +1342,9 @@ static int wsrep_RSU_begin(THD *thd, char *db_, char *table_)
wsrep_seqno_t seqno = wsrep->pause(wsrep); wsrep_seqno_t seqno = wsrep->pause(wsrep);
if (seqno == WSREP_SEQNO_UNDEFINED) if (seqno == WSREP_SEQNO_UNDEFINED)
{ {
WSREP_WARN("pause failed %lld for %s", (long long)seqno, thd->query()); WSREP_WARN("pause failed %lld for schema: %s, query: %s", (long long)seqno,
(thd->db ? thd->db : "(null)"),
thd->query());
return(1); return(1);
} }
WSREP_DEBUG("paused at %lld", (long long)seqno); WSREP_DEBUG("paused at %lld", (long long)seqno);
...@@ -1352,12 +1366,16 @@ static void wsrep_RSU_end(THD *thd) ...@@ -1352,12 +1366,16 @@ static void wsrep_RSU_end(THD *thd)
ret = wsrep->resume(wsrep); ret = wsrep->resume(wsrep);
if (ret != WSREP_OK) if (ret != WSREP_OK)
{ {
WSREP_WARN("resume failed %d for %s", ret, thd->query()); WSREP_WARN("resume failed %d for schema: %s, query: %s", ret,
(thd->db ? thd->db : "(null)"),
thd->query());
} }
ret = wsrep->resync(wsrep); ret = wsrep->resync(wsrep);
if (ret != WSREP_OK) if (ret != WSREP_OK)
{ {
WSREP_WARN("resync failed %d for %s", ret, thd->query()); WSREP_WARN("resync failed %d for schema: %s, query: %s", ret,
(thd->db ? thd->db : "(null)"),
thd->query());
return; return;
} }
thd->variables.wsrep_on = 1; thd->variables.wsrep_on = 1;
...@@ -1377,8 +1395,10 @@ int wsrep_to_isolation_begin(THD *thd, char *db_, char *table_, ...@@ -1377,8 +1395,10 @@ int wsrep_to_isolation_begin(THD *thd, char *db_, char *table_,
if (thd->wsrep_conflict_state == MUST_ABORT) if (thd->wsrep_conflict_state == MUST_ABORT)
{ {
WSREP_INFO("thread: %lu, %s has been aborted due to multi-master conflict", WSREP_INFO("thread: %lu, schema: %s, query: %s has been aborted due to multi-master conflict",
thd->thread_id, thd->query()); thd->thread_id,
(thd->db ? thd->db : "(null)"),
thd->query());
mysql_mutex_unlock(&thd->LOCK_wsrep_thd); mysql_mutex_unlock(&thd->LOCK_wsrep_thd);
return WSREP_TRX_FAIL; return WSREP_TRX_FAIL;
} }
...@@ -1456,12 +1476,12 @@ void wsrep_to_isolation_end(THD *thd) ...@@ -1456,12 +1476,12 @@ void wsrep_to_isolation_end(THD *thd)
} }
} }
#define WSREP_MDL_LOG(severity, msg, req, gra) \ #define WSREP_MDL_LOG(severity, msg, schema, schema_len, req, gra) \
WSREP_##severity( \ WSREP_##severity( \
"%s\n" \ "schema: %.*s\n" \
"request: (%lu \tseqno %lld \twsrep (%d, %d, %d) cmd %d %d \t%s)\n" \ "request: (%lu \tseqno %lld \twsrep (%d, %d, %d) cmd %d %d \t%s)\n" \
"granted: (%lu \tseqno %lld \twsrep (%d, %d, %d) cmd %d %d \t%s)", \ "granted: (%lu \tseqno %lld \twsrep (%d, %d, %d) cmd %d %d \t%s)", \
msg, \ msg, schema_len, schema, \
req->thread_id, (long long)wsrep_thd_trx_seqno(req), \ req->thread_id, (long long)wsrep_thd_trx_seqno(req), \
req->wsrep_exec_mode, req->wsrep_query_state, req->wsrep_conflict_state, \ req->wsrep_exec_mode, req->wsrep_query_state, req->wsrep_conflict_state, \
req->get_command(), req->lex->sql_command, req->query(), \ req->get_command(), req->lex->sql_command, req->query(), \
...@@ -1481,7 +1501,8 @@ void wsrep_to_isolation_end(THD *thd) ...@@ -1481,7 +1501,8 @@ void wsrep_to_isolation_end(THD *thd)
bool bool
wsrep_grant_mdl_exception(MDL_context *requestor_ctx, wsrep_grant_mdl_exception(MDL_context *requestor_ctx,
MDL_ticket *ticket MDL_ticket *ticket,
const MDL_key *key
) { ) {
/* Fallback to the non-wsrep behaviour */ /* Fallback to the non-wsrep behaviour */
if (!WSREP_ON) return FALSE; if (!WSREP_ON) return FALSE;
...@@ -1490,19 +1511,24 @@ wsrep_grant_mdl_exception(MDL_context *requestor_ctx, ...@@ -1490,19 +1511,24 @@ wsrep_grant_mdl_exception(MDL_context *requestor_ctx,
THD *granted_thd = ticket->get_ctx()->wsrep_get_thd(); THD *granted_thd = ticket->get_ctx()->wsrep_get_thd();
bool ret = FALSE; bool ret = FALSE;
const char* schema= key->db_name();
int schema_len= key->db_name_length();
mysql_mutex_lock(&request_thd->LOCK_wsrep_thd); mysql_mutex_lock(&request_thd->LOCK_wsrep_thd);
if (request_thd->wsrep_exec_mode == TOTAL_ORDER || if (request_thd->wsrep_exec_mode == TOTAL_ORDER ||
request_thd->wsrep_exec_mode == REPL_RECV) request_thd->wsrep_exec_mode == REPL_RECV)
{ {
mysql_mutex_unlock(&request_thd->LOCK_wsrep_thd); mysql_mutex_unlock(&request_thd->LOCK_wsrep_thd);
WSREP_MDL_LOG(DEBUG, "MDL conflict ", request_thd, granted_thd); WSREP_MDL_LOG(DEBUG, "MDL conflict ", schema, schema_len,
request_thd, granted_thd);
ticket->wsrep_report(wsrep_debug); ticket->wsrep_report(wsrep_debug);
mysql_mutex_lock(&granted_thd->LOCK_wsrep_thd); mysql_mutex_lock(&granted_thd->LOCK_wsrep_thd);
if (granted_thd->wsrep_exec_mode == TOTAL_ORDER || if (granted_thd->wsrep_exec_mode == TOTAL_ORDER ||
granted_thd->wsrep_exec_mode == REPL_RECV) granted_thd->wsrep_exec_mode == REPL_RECV)
{ {
WSREP_MDL_LOG(INFO, "MDL BF-BF conflict", request_thd, granted_thd); WSREP_MDL_LOG(INFO, "MDL BF-BF conflict", schema, schema_len,
request_thd, granted_thd);
ticket->wsrep_report(true); ticket->wsrep_report(true);
mysql_mutex_unlock(&granted_thd->LOCK_wsrep_thd); mysql_mutex_unlock(&granted_thd->LOCK_wsrep_thd);
ret = TRUE; ret = TRUE;
...@@ -1533,7 +1559,8 @@ wsrep_grant_mdl_exception(MDL_context *requestor_ctx, ...@@ -1533,7 +1559,8 @@ wsrep_grant_mdl_exception(MDL_context *requestor_ctx,
} }
else else
{ {
WSREP_MDL_LOG(DEBUG, "MDL conflict-> BF abort", request_thd, granted_thd); WSREP_MDL_LOG(DEBUG, "MDL conflict-> BF abort", schema, schema_len,
request_thd, granted_thd);
ticket->wsrep_report(wsrep_debug); ticket->wsrep_report(wsrep_debug);
mysql_mutex_unlock(&granted_thd->LOCK_wsrep_thd); mysql_mutex_unlock(&granted_thd->LOCK_wsrep_thd);
wsrep_abort_thd((void*)request_thd, (void*)granted_thd, 1); wsrep_abort_thd((void*)request_thd, (void*)granted_thd, 1);
......
...@@ -274,8 +274,10 @@ void wsrep_replay_transaction(THD *thd) ...@@ -274,8 +274,10 @@ void wsrep_replay_transaction(THD *thd)
wsrep->post_rollback(wsrep, &thd->wsrep_ws_handle); wsrep->post_rollback(wsrep, &thd->wsrep_ws_handle);
break; break;
default: default:
WSREP_ERROR("trx_replay failed for: %d, query: %s", WSREP_ERROR("trx_replay failed for: %d, schema: %s, query: %s",
rcode, thd->query() ? thd->query() : "void"); rcode,
(thd->db ? thd->db : "(null)"),
thd->query() ? thd->query() : "void");
/* we're now in inconsistent state, must abort */ /* we're now in inconsistent state, must abort */
/* http://bazaar.launchpad.net/~codership/codership-mysql/5.6/revision/3962#sql/wsrep_thd.cc */ /* http://bazaar.launchpad.net/~codership/codership-mysql/5.6/revision/3962#sql/wsrep_thd.cc */
......
...@@ -512,14 +512,18 @@ bool wsrep_desync_update (sys_var *self, THD* thd, enum_var_type type) ...@@ -512,14 +512,18 @@ bool wsrep_desync_update (sys_var *self, THD* thd, enum_var_type type)
if (wsrep_desync) { if (wsrep_desync) {
ret = wsrep->desync (wsrep); ret = wsrep->desync (wsrep);
if (ret != WSREP_OK) { if (ret != WSREP_OK) {
WSREP_WARN ("SET desync failed %d for %s", ret, thd->query()); WSREP_WARN ("SET desync failed %d for schema: %s, query: %s", ret,
(thd->db ? thd->db : "(null)"),
thd->query());
my_error (ER_CANNOT_USER, MYF(0), "'desync'", thd->query()); my_error (ER_CANNOT_USER, MYF(0), "'desync'", thd->query());
return true; return true;
} }
} else { } else {
ret = wsrep->resync (wsrep); ret = wsrep->resync (wsrep);
if (ret != WSREP_OK) { if (ret != WSREP_OK) {
WSREP_WARN ("SET resync failed %d for %s", ret, thd->query()); WSREP_WARN ("SET resync failed %d for schema: %s, query: %s", ret,
(thd->db ? thd->db : "(null)"),
thd->query());
my_error (ER_CANNOT_USER, MYF(0), "'resync'", thd->query()); my_error (ER_CANNOT_USER, MYF(0), "'resync'", thd->query());
return true; return true;
} }
......
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