Skip to content

Commit

Permalink
Fixed test failure on galere_wsrep_log_conflicts on XtraDB.
Browse files Browse the repository at this point in the history
Problem was that trx_sys->mutex was acquired to print trx info
even when we already hold trx_sys->mutex. Fixed similarly as
in InnoDB, i.e. with wsrep_trx_print_locking() function that
does not acquire trx_sys->mutex.
  • Loading branch information
Jan Lindström committed Mar 20, 2017
1 parent f66395f commit 53c6195
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 11 deletions.
1 change: 1 addition & 0 deletions storage/innobase/include/trx0trx.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*****************************************************************************
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2015, 2017, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Expand Down
10 changes: 6 additions & 4 deletions storage/innobase/lock/lock0lock.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*****************************************************************************
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2014, 2016, MariaDB Corporation
Copyright (c) 2014, 2017, MariaDB Corporation
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Expand Down Expand Up @@ -1704,13 +1704,14 @@ wsrep_kill_victim(
is in the queue*/
} else if (lock->trx != trx) {
if (wsrep_log_conflicts) {
if (bf_this)
fputs("\n*** Priority TRANSACTION:\n",
if (bf_this) {
fputs("\n*** Priority TRANSACTION:\n",
stderr);
else {
} else {
fputs("\n*** Victim TRANSACTION:\n",
stderr);
}

wsrep_trx_print_locking(stderr, trx, 3000);

if (bf_other) {
Expand All @@ -1720,6 +1721,7 @@ wsrep_kill_victim(
fputs("\n*** Victim TRANSACTION:\n",
stderr);
}

wsrep_trx_print_locking(stderr, lock->trx, 3000);

fputs("*** WAITING FOR THIS LOCK TO BE GRANTED:\n",
Expand Down
1 change: 1 addition & 0 deletions storage/innobase/trx/trx0trx.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*****************************************************************************
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2015, 2017, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Expand Down
20 changes: 19 additions & 1 deletion storage/xtradb/include/trx0trx.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*****************************************************************************
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2015, MariaDB Corporation
Copyright (c) 2015, 2017, MariaDB Corporation
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Expand Down Expand Up @@ -333,6 +333,24 @@ trx_print_low(
/*!< in: mem_heap_get_size(trx->lock.lock_heap) */
MY_ATTRIBUTE((nonnull));

#ifdef WITH_WSREP
/**********************************************************************//**
Prints info about a transaction.
Transaction information may be retrieved without having trx_sys->mutex acquired
so it may not be completely accurate. The caller must own lock_sys->mutex
and the trx must have some locks to make sure that it does not escape
without locking lock_sys->mutex. */
UNIV_INTERN
void
wsrep_trx_print_locking(
/*==============*/
FILE* f, /*!< in: output stream */
const trx_t* trx, /*!< in: transaction */
ulint max_query_len) /*!< in: max query length to print,
or 0 to use the default max length */
MY_ATTRIBUTE((nonnull));
#endif /* WITH_WSREP */

/**********************************************************************//**
Prints info about a transaction.
The caller must hold lock_sys->mutex and trx_sys->mutex.
Expand Down
9 changes: 3 additions & 6 deletions storage/xtradb/lock/lock0lock.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*****************************************************************************
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2014, 2015, MariaDB Corporation
Copyright (c) 2014, 2017, MariaDB Corporation
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Expand Down Expand Up @@ -1714,7 +1714,6 @@ wsrep_kill_victim(
is in the queue*/
} else if (lock->trx != trx) {
if (wsrep_log_conflicts) {
mutex_enter(&trx_sys->mutex);
if (bf_this) {
fputs("\n*** Priority TRANSACTION:\n",
stderr);
Expand All @@ -1723,7 +1722,7 @@ wsrep_kill_victim(
stderr);
}

trx_print_latched(stderr, trx, 3000);
wsrep_trx_print_locking(stderr, trx, 3000);

if (bf_other) {
fputs("\n*** Priority TRANSACTION:\n",
Expand All @@ -1733,9 +1732,7 @@ wsrep_kill_victim(
stderr);
}

trx_print_latched(stderr, lock->trx, 3000);

mutex_exit(&trx_sys->mutex);
wsrep_trx_print_locking(stderr, lock->trx, 3000);

fputs("*** WAITING FOR THIS LOCK TO BE GRANTED:\n",
stderr);
Expand Down
114 changes: 114 additions & 0 deletions storage/xtradb/trx/trx0trx.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*****************************************************************************
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2015, 2017, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Expand Down Expand Up @@ -2156,6 +2157,119 @@ trx_print_latched(
mem_heap_get_size(trx->lock.lock_heap));
}

#ifdef WITH_WSREP
/**********************************************************************//**
Prints info about a transaction.
Transaction information may be retrieved without having trx_sys->mutex acquired
so it may not be completely accurate. The caller must own lock_sys->mutex
and the trx must have some locks to make sure that it does not escape
without locking lock_sys->mutex. */
UNIV_INTERN
void
wsrep_trx_print_locking(
/*==========*/
FILE* f,
/*!< in: output stream */
const trx_t* trx,
/*!< in: transaction */
ulint max_query_len)
/*!< in: max query length to print,
or 0 to use the default max length */
{
ibool newline;
const char* op_info;

ut_ad(lock_mutex_own());
ut_ad(trx->lock.trx_locks.count > 0);

fprintf(f, "TRANSACTION " TRX_ID_FMT, trx->id);

/* trx->state may change since trx_sys->mutex is not required */
switch (trx->state) {
case TRX_STATE_NOT_STARTED:
fputs(", not started", f);
goto state_ok;
case TRX_STATE_ACTIVE:
fprintf(f, ", ACTIVE %lu sec",
(ulong) difftime(time(NULL), trx->start_time));
goto state_ok;
case TRX_STATE_PREPARED:
fprintf(f, ", ACTIVE (PREPARED) %lu sec",
(ulong) difftime(time(NULL), trx->start_time));
goto state_ok;
case TRX_STATE_COMMITTED_IN_MEMORY:
fputs(", COMMITTED IN MEMORY", f);
goto state_ok;
}
fprintf(f, ", state %lu", (ulong) trx->state);
ut_ad(0);
state_ok:

/* prevent a race condition */
op_info = trx->op_info;

if (*op_info) {
putc(' ', f);
fputs(op_info, f);
}

if (trx->is_recovered) {
fputs(" recovered trx", f);
}

if (trx->declared_to_be_inside_innodb) {
fprintf(f, ", thread declared inside InnoDB %lu",
(ulong) trx->n_tickets_to_enter_innodb);
}

putc('\n', f);

if (trx->n_mysql_tables_in_use > 0 || trx->mysql_n_tables_locked > 0) {
fprintf(f, "mysql tables in use %lu, locked %lu\n",
(ulong) trx->n_mysql_tables_in_use,
(ulong) trx->mysql_n_tables_locked);
}

newline = TRUE;

/* trx->lock.que_state of an ACTIVE transaction may change
while we are not holding trx->mutex. We perform a dirty read
for performance reasons. */

switch (trx->lock.que_state) {
case TRX_QUE_RUNNING:
newline = FALSE; break;
case TRX_QUE_LOCK_WAIT:
fputs("LOCK WAIT ", f); break;
case TRX_QUE_ROLLING_BACK:
fputs("ROLLING BACK ", f); break;
case TRX_QUE_COMMITTING:
fputs("COMMITTING ", f); break;
default:
fprintf(f, "que state %lu ", (ulong) trx->lock.que_state);
}

if (trx->has_search_latch) {
newline = TRUE;
fputs(", holds adaptive hash latch", f);
}

if (trx->undo_no != 0) {
newline = TRUE;
fprintf(f, ", undo log entries " TRX_ID_FMT, trx->undo_no);
}

if (newline) {
putc('\n', f);
}

if (trx->mysql_thd != NULL) {
innobase_mysql_print_thd(
f, trx->mysql_thd, static_cast<uint>(max_query_len));
}
}
#endif /* WITH_WSREP */

/**********************************************************************//**
Prints info about a transaction.
Acquires and releases lock_sys->mutex and trx_sys->mutex. */
Expand Down

0 comments on commit 53c6195

Please sign in to comment.