Skip to content

Commit 3ec139a

Browse files
author
Jan Lindström
committed
Merge pull request #104 from philip-galera/10.0-galera-mysql-wsrep-gh202
Refs codership/mysql-wsrep#202 Added schema info into wsrep messages
2 parents 4d33f9d + 43b2a45 commit 3ec139a

File tree

8 files changed

+79
-36
lines changed

8 files changed

+79
-36
lines changed

sql/events.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,8 @@ int wsrep_create_event_query(THD *thd, uchar** buf, size_t* buf_len)
11951195

11961196
if (create_query_string(thd, &log_query))
11971197
{
1198-
WSREP_WARN("events create string failed: %s", thd->query());
1198+
WSREP_WARN("events create string failed: schema: %s, query: %s",
1199+
(thd->db ? thd->db : "(null)"), thd->query());
11991200
return 1;
12001201
}
12011202
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)
12221223

12231224
if (wsrep_alter_query_string(thd, &log_query))
12241225
{
1225-
WSREP_WARN("events alter string failed: %s", thd->query());
1226+
WSREP_WARN("events alter string failed: schema: %s, query: %s",
1227+
(thd->db ? thd->db : "(null)"), thd->query());
12261228
return 1;
12271229
}
12281230
return wsrep_to_buf_helper(thd, log_query.ptr(), log_query.length(), buf, buf_len);

sql/mdl.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ void sql_print_information(const char *format, ...)
3333

3434
extern bool
3535
wsrep_grant_mdl_exception(MDL_context *requestor_ctx,
36-
MDL_ticket *ticket);
36+
MDL_ticket *ticket,
37+
const MDL_key *key);
3738
#endif /* WITH_WSREP */
3839
#ifdef HAVE_PSI_INTERFACE
3940
static PSI_mutex_key key_MDL_map_mutex;
@@ -1549,7 +1550,8 @@ void MDL_lock::Ticket_list::add_ticket(MDL_ticket *ticket)
15491550
if (granted->get_ctx() != ticket->get_ctx() &&
15501551
granted->is_incompatible_when_granted(ticket->get_type()))
15511552
{
1552-
if (!wsrep_grant_mdl_exception(ticket->get_ctx(), granted))
1553+
if (!wsrep_grant_mdl_exception(ticket->get_ctx(), granted,
1554+
&ticket->get_lock()->key))
15531555
{
15541556
WSREP_DEBUG("MDL victim killed at add_ticket");
15551557
}
@@ -1941,7 +1943,7 @@ MDL_lock::can_grant_lock(enum_mdl_type type_arg,
19411943
wsrep_thd_query(requestor_ctx->wsrep_get_thd()));
19421944
can_grant = true;
19431945
}
1944-
else if (!wsrep_grant_mdl_exception(requestor_ctx, ticket))
1946+
else if (!wsrep_grant_mdl_exception(requestor_ctx, ticket, &key))
19451947
{
19461948
wsrep_can_grant= FALSE;
19471949
if (wsrep_log_conflicts)

sql/mdl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ class MDL_request
457457
MDL_key key;
458458

459459
public:
460+
460461
static void *operator new(size_t size, MEM_ROOT *mem_root) throw ()
461462
{ return alloc_root(mem_root, size); }
462463
static void operator delete(void *ptr, MEM_ROOT *mem_root) {}

sql/sp.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2302,7 +2302,8 @@ int wsrep_create_sp(THD *thd, uchar** buf, size_t* buf_len)
23022302
&(thd->lex->definer->host),
23032303
saved_mode))
23042304
{
2305-
WSREP_WARN("SP create string failed: %s", thd->query());
2305+
WSREP_WARN("SP create string failed: schema: %s, query: %s",
2306+
(thd->db ? thd->db : "(null)"), thd->query());
23062307
return 1;
23072308
}
23082309
return wsrep_to_buf_helper(thd, log_query.ptr(), log_query.length(), buf, buf_len);

sql/wsrep_hton.cc

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,9 @@ static int wsrep_rollback(handlerton *hton, THD *thd, bool all)
239239
if (WSREP(thd) && wsrep->post_rollback(wsrep, &thd->wsrep_ws_handle))
240240
{
241241
DBUG_PRINT("wsrep", ("setting rollback fail"));
242-
WSREP_ERROR("settting rollback fail: thd: %llu SQL: %s",
243-
(long long)thd->real_id, thd->query());
242+
WSREP_ERROR("settting rollback fail: thd: %llu, schema: %s, SQL: %s",
243+
(long long)thd->real_id, (thd->db ? thd->db : "(null)"),
244+
thd->query());
244245
}
245246
wsrep_cleanup_transaction(thd);
246247
}
@@ -279,8 +280,9 @@ int wsrep_commit(handlerton *hton, THD *thd, bool all)
279280
if (WSREP(thd) && wsrep->post_rollback(wsrep, &thd->wsrep_ws_handle))
280281
{
281282
DBUG_PRINT("wsrep", ("setting rollback fail"));
282-
WSREP_ERROR("settting rollback fail: thd: %llu SQL: %s",
283-
(long long)thd->real_id, thd->query());
283+
WSREP_ERROR("settting rollback fail: thd: %llu, schema: %s, SQL: %s",
284+
(long long)thd->real_id, (thd->db ? thd->db : "(null)"),
285+
thd->query());
284286
}
285287
wsrep_cleanup_transaction(thd);
286288
}
@@ -441,9 +443,11 @@ wsrep_run_wsrep_commit(THD *thd, handlerton *hton, bool all)
441443
if (WSREP_UNDEFINED_TRX_ID == thd->wsrep_ws_handle.trx_id)
442444
{
443445
WSREP_WARN("SQL statement was ineffective, THD: %lu, buf: %zu\n"
446+
"schema: %s \n"
444447
"QUERY: %s\n"
445448
" => Skipping replication",
446-
thd->thread_id, data_len, thd->query());
449+
thd->thread_id, data_len,
450+
(thd->db ? thd->db : "(null)"), thd->query());
447451
rcode = WSREP_TRX_FAIL;
448452
}
449453
else if (!rcode)
@@ -458,8 +462,8 @@ wsrep_run_wsrep_commit(THD *thd, handlerton *hton, bool all)
458462
&thd->wsrep_trx_meta);
459463

460464
if (rcode == WSREP_TRX_MISSING) {
461-
WSREP_WARN("Transaction missing in provider, thd: %ld, SQL: %s",
462-
thd->thread_id, thd->query());
465+
WSREP_WARN("Transaction missing in provider, thd: %ld, schema: %s, SQL: %s",
466+
thd->thread_id, (thd->db ? thd->db : "(null)"), thd->query());
463467
rcode = WSREP_TRX_FAIL;
464468
} else if (rcode == WSREP_BF_ABORT) {
465469
WSREP_DEBUG("thd %lu seqno %lld BF aborted by provider, will replay",

sql/wsrep_mysqld.cc

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,9 +1253,11 @@ static int wsrep_TOI_begin(THD *thd, char *db_, char *table_,
12531253
}
12541254
else if (key_arr.keys_len > 0) {
12551255
/* jump to error handler in mysql_execute_command() */
1256-
WSREP_WARN("TO isolation failed for: %d, sql: %s. Check wsrep "
1256+
WSREP_WARN("TO isolation failed for: %d, schema: %s, sql: %s. Check wsrep "
12571257
"connection state and retry the query.",
1258-
ret, (thd->query()) ? thd->query() : "void");
1258+
ret,
1259+
(thd->db ? thd->db : "(null)"),
1260+
(thd->query()) ? thd->query() : "void");
12591261
my_error(ER_LOCK_DEADLOCK, MYF(0), "WSREP replication failed. Check "
12601262
"your wsrep connection state and retry the query.");
12611263
wsrep_keys_free(&key_arr);
@@ -1288,8 +1290,10 @@ static void wsrep_TOI_end(THD *thd) {
12881290
WSREP_DEBUG("TO END: %lld", (long long)wsrep_thd_trx_seqno(thd));
12891291
}
12901292
else {
1291-
WSREP_WARN("TO isolation end failed for: %d, sql: %s",
1292-
ret, (thd->query()) ? thd->query() : "void");
1293+
WSREP_WARN("TO isolation end failed for: %d, schema: %s, sql: %s",
1294+
ret,
1295+
(thd->db ? thd->db : "(null)"),
1296+
(thd->query()) ? thd->query() : "void");
12931297
}
12941298
}
12951299

@@ -1302,7 +1306,10 @@ static int wsrep_RSU_begin(THD *thd, char *db_, char *table_)
13021306
ret = wsrep->desync(wsrep);
13031307
if (ret != WSREP_OK)
13041308
{
1305-
WSREP_WARN("RSU desync failed %d for %s", ret, thd->query());
1309+
WSREP_WARN("RSU desync failed %d for schema: %s, query: %s",
1310+
ret,
1311+
(thd->db ? thd->db : "(null)"),
1312+
thd->query());
13061313
my_error(ER_LOCK_DEADLOCK, MYF(0));
13071314
return(ret);
13081315
}
@@ -1313,15 +1320,20 @@ static int wsrep_RSU_begin(THD *thd, char *db_, char *table_)
13131320
if (wsrep_wait_committing_connections_close(5000))
13141321
{
13151322
/* no can do, bail out from DDL */
1316-
WSREP_WARN("RSU failed due to pending transactions, %s", thd->query());
1323+
WSREP_WARN("RSU failed due to pending transactions, schema: %s, query %s",
1324+
(thd->db ? thd->db : "(null)"),
1325+
thd->query());
13171326
mysql_mutex_lock(&LOCK_wsrep_replaying);
13181327
wsrep_replaying--;
13191328
mysql_mutex_unlock(&LOCK_wsrep_replaying);
13201329

13211330
ret = wsrep->resync(wsrep);
13221331
if (ret != WSREP_OK)
13231332
{
1324-
WSREP_WARN("resync failed %d for %s", ret, thd->query());
1333+
WSREP_WARN("resync failed %d for schema: %s, query: %s",
1334+
ret,
1335+
(thd->db ? thd->db : "(null)"),
1336+
thd->query());
13251337
}
13261338
my_error(ER_LOCK_DEADLOCK, MYF(0));
13271339
return(1);
@@ -1330,7 +1342,9 @@ static int wsrep_RSU_begin(THD *thd, char *db_, char *table_)
13301342
wsrep_seqno_t seqno = wsrep->pause(wsrep);
13311343
if (seqno == WSREP_SEQNO_UNDEFINED)
13321344
{
1333-
WSREP_WARN("pause failed %lld for %s", (long long)seqno, thd->query());
1345+
WSREP_WARN("pause failed %lld for schema: %s, query: %s", (long long)seqno,
1346+
(thd->db ? thd->db : "(null)"),
1347+
thd->query());
13341348
return(1);
13351349
}
13361350
WSREP_DEBUG("paused at %lld", (long long)seqno);
@@ -1352,12 +1366,16 @@ static void wsrep_RSU_end(THD *thd)
13521366
ret = wsrep->resume(wsrep);
13531367
if (ret != WSREP_OK)
13541368
{
1355-
WSREP_WARN("resume failed %d for %s", ret, thd->query());
1369+
WSREP_WARN("resume failed %d for schema: %s, query: %s", ret,
1370+
(thd->db ? thd->db : "(null)"),
1371+
thd->query());
13561372
}
13571373
ret = wsrep->resync(wsrep);
13581374
if (ret != WSREP_OK)
13591375
{
1360-
WSREP_WARN("resync failed %d for %s", ret, thd->query());
1376+
WSREP_WARN("resync failed %d for schema: %s, query: %s", ret,
1377+
(thd->db ? thd->db : "(null)"),
1378+
thd->query());
13611379
return;
13621380
}
13631381
thd->variables.wsrep_on = 1;
@@ -1377,8 +1395,10 @@ int wsrep_to_isolation_begin(THD *thd, char *db_, char *table_,
13771395

13781396
if (thd->wsrep_conflict_state == MUST_ABORT)
13791397
{
1380-
WSREP_INFO("thread: %lu, %s has been aborted due to multi-master conflict",
1381-
thd->thread_id, thd->query());
1398+
WSREP_INFO("thread: %lu, schema: %s, query: %s has been aborted due to multi-master conflict",
1399+
thd->thread_id,
1400+
(thd->db ? thd->db : "(null)"),
1401+
thd->query());
13821402
mysql_mutex_unlock(&thd->LOCK_wsrep_thd);
13831403
return WSREP_TRX_FAIL;
13841404
}
@@ -1456,12 +1476,12 @@ void wsrep_to_isolation_end(THD *thd)
14561476
}
14571477
}
14581478

1459-
#define WSREP_MDL_LOG(severity, msg, req, gra) \
1479+
#define WSREP_MDL_LOG(severity, msg, schema, schema_len, req, gra) \
14601480
WSREP_##severity( \
1461-
"%s\n" \
1481+
"schema: %.*s\n" \
14621482
"request: (%lu \tseqno %lld \twsrep (%d, %d, %d) cmd %d %d \t%s)\n" \
14631483
"granted: (%lu \tseqno %lld \twsrep (%d, %d, %d) cmd %d %d \t%s)", \
1464-
msg, \
1484+
msg, schema_len, schema, \
14651485
req->thread_id, (long long)wsrep_thd_trx_seqno(req), \
14661486
req->wsrep_exec_mode, req->wsrep_query_state, req->wsrep_conflict_state, \
14671487
req->get_command(), req->lex->sql_command, req->query(), \
@@ -1481,7 +1501,8 @@ void wsrep_to_isolation_end(THD *thd)
14811501

14821502
bool
14831503
wsrep_grant_mdl_exception(MDL_context *requestor_ctx,
1484-
MDL_ticket *ticket
1504+
MDL_ticket *ticket,
1505+
const MDL_key *key
14851506
) {
14861507
/* Fallback to the non-wsrep behaviour */
14871508
if (!WSREP_ON) return FALSE;
@@ -1490,19 +1511,24 @@ wsrep_grant_mdl_exception(MDL_context *requestor_ctx,
14901511
THD *granted_thd = ticket->get_ctx()->wsrep_get_thd();
14911512
bool ret = FALSE;
14921513

1514+
const char* schema= key->db_name();
1515+
int schema_len= key->db_name_length();
1516+
14931517
mysql_mutex_lock(&request_thd->LOCK_wsrep_thd);
14941518
if (request_thd->wsrep_exec_mode == TOTAL_ORDER ||
14951519
request_thd->wsrep_exec_mode == REPL_RECV)
14961520
{
14971521
mysql_mutex_unlock(&request_thd->LOCK_wsrep_thd);
1498-
WSREP_MDL_LOG(DEBUG, "MDL conflict ", request_thd, granted_thd);
1522+
WSREP_MDL_LOG(DEBUG, "MDL conflict ", schema, schema_len,
1523+
request_thd, granted_thd);
14991524
ticket->wsrep_report(wsrep_debug);
15001525

15011526
mysql_mutex_lock(&granted_thd->LOCK_wsrep_thd);
15021527
if (granted_thd->wsrep_exec_mode == TOTAL_ORDER ||
15031528
granted_thd->wsrep_exec_mode == REPL_RECV)
15041529
{
1505-
WSREP_MDL_LOG(INFO, "MDL BF-BF conflict", request_thd, granted_thd);
1530+
WSREP_MDL_LOG(INFO, "MDL BF-BF conflict", schema, schema_len,
1531+
request_thd, granted_thd);
15061532
ticket->wsrep_report(true);
15071533
mysql_mutex_unlock(&granted_thd->LOCK_wsrep_thd);
15081534
ret = TRUE;
@@ -1533,7 +1559,8 @@ wsrep_grant_mdl_exception(MDL_context *requestor_ctx,
15331559
}
15341560
else
15351561
{
1536-
WSREP_MDL_LOG(DEBUG, "MDL conflict-> BF abort", request_thd, granted_thd);
1562+
WSREP_MDL_LOG(DEBUG, "MDL conflict-> BF abort", schema, schema_len,
1563+
request_thd, granted_thd);
15371564
ticket->wsrep_report(wsrep_debug);
15381565
mysql_mutex_unlock(&granted_thd->LOCK_wsrep_thd);
15391566
wsrep_abort_thd((void*)request_thd, (void*)granted_thd, 1);

sql/wsrep_thd.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,10 @@ void wsrep_replay_transaction(THD *thd)
274274
wsrep->post_rollback(wsrep, &thd->wsrep_ws_handle);
275275
break;
276276
default:
277-
WSREP_ERROR("trx_replay failed for: %d, query: %s",
278-
rcode, thd->query() ? thd->query() : "void");
277+
WSREP_ERROR("trx_replay failed for: %d, schema: %s, query: %s",
278+
rcode,
279+
(thd->db ? thd->db : "(null)"),
280+
thd->query() ? thd->query() : "void");
279281
/* we're now in inconsistent state, must abort */
280282

281283
/* http://bazaar.launchpad.net/~codership/codership-mysql/5.6/revision/3962#sql/wsrep_thd.cc */

sql/wsrep_var.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,14 +512,18 @@ bool wsrep_desync_update (sys_var *self, THD* thd, enum_var_type type)
512512
if (wsrep_desync) {
513513
ret = wsrep->desync (wsrep);
514514
if (ret != WSREP_OK) {
515-
WSREP_WARN ("SET desync failed %d for %s", ret, thd->query());
515+
WSREP_WARN ("SET desync failed %d for schema: %s, query: %s", ret,
516+
(thd->db ? thd->db : "(null)"),
517+
thd->query());
516518
my_error (ER_CANNOT_USER, MYF(0), "'desync'", thd->query());
517519
return true;
518520
}
519521
} else {
520522
ret = wsrep->resync (wsrep);
521523
if (ret != WSREP_OK) {
522-
WSREP_WARN ("SET resync failed %d for %s", ret, thd->query());
524+
WSREP_WARN ("SET resync failed %d for schema: %s, query: %s", ret,
525+
(thd->db ? thd->db : "(null)"),
526+
thd->query());
523527
my_error (ER_CANNOT_USER, MYF(0), "'resync'", thd->query());
524528
return true;
525529
}

0 commit comments

Comments
 (0)