Commit 90635c6f authored by Jan Lindström's avatar Jan Lindström

MDEV-7620: Transaction lock wait is missing number of lock

waits and total wait time.
parent 8366ce47
...@@ -1009,6 +1009,19 @@ struct trx_t{ ...@@ -1009,6 +1009,19 @@ struct trx_t{
/*------------------------------*/ /*------------------------------*/
char detailed_error[256]; /*!< detailed error message for last char detailed_error[256]; /*!< detailed error message for last
error, or empty. */ error, or empty. */
/* Lock wait statistics */
ulint n_rec_lock_waits;
/*!< Number of record lock waits,
might not be exactly correct. */
ulint n_table_lock_waits;
/*!< Number of table lock waits,
might not be exactly correct. */
ulint total_rec_lock_wait_time;
/*!< Total rec lock wait time up
to this moment. */
ulint total_table_lock_wait_time;
/*!< Total table lock wait time
up to this moment. */
}; };
/* Transaction isolation levels (trx->isolation_level) */ /* Transaction isolation levels (trx->isolation_level) */
......
...@@ -2034,6 +2034,8 @@ lock_rec_enqueue_waiting( ...@@ -2034,6 +2034,8 @@ lock_rec_enqueue_waiting(
MONITOR_INC(MONITOR_LOCKREC_WAIT); MONITOR_INC(MONITOR_LOCKREC_WAIT);
trx->n_rec_lock_waits++;
return(DB_LOCK_WAIT); return(DB_LOCK_WAIT);
} }
...@@ -2454,6 +2456,15 @@ lock_grant( ...@@ -2454,6 +2456,15 @@ lock_grant(
} }
} }
/* Cumulate total lock wait time for statistics */
if (lock_get_type_low(lock) & LOCK_TABLE) {
lock->trx->total_table_lock_wait_time +=
(ulint)difftime(ut_time(), lock->trx->lock.wait_started);
} else {
lock->trx->total_rec_lock_wait_time +=
(ulint)difftime(ut_time(), lock->trx->lock.wait_started);
}
trx_mutex_exit(lock->trx); trx_mutex_exit(lock->trx);
} }
...@@ -4458,6 +4469,7 @@ lock_table_enqueue_waiting( ...@@ -4458,6 +4469,7 @@ lock_table_enqueue_waiting(
trx->lock.wait_started = ut_time(); trx->lock.wait_started = ut_time();
trx->lock.was_chosen_as_deadlock_victim = FALSE; trx->lock.was_chosen_as_deadlock_victim = FALSE;
trx->n_table_lock_waits++;
ut_a(que_thr_stop(thr)); ut_a(que_thr_stop(thr));
...@@ -5458,6 +5470,14 @@ lock_print_info_all_transactions( ...@@ -5458,6 +5470,14 @@ lock_print_info_all_transactions(
trx->read_view->up_limit_id); trx->read_view->up_limit_id);
} }
/* Total trx lock waits and times */
fprintf(file, "Trx #rec lock waits %lu #table lock waits %lu\n",
trx->n_rec_lock_waits, trx->n_table_lock_waits);
fprintf(file, "Trx total rec lock wait time %lu SEC\n",
trx->total_rec_lock_wait_time);
fprintf(file, "Trx total table lock wait time %lu SEC\n",
trx->total_table_lock_wait_time);
if (trx->lock.que_state == TRX_QUE_LOCK_WAIT) { if (trx->lock.que_state == TRX_QUE_LOCK_WAIT) {
fprintf(file, fprintf(file,
......
/***************************************************************************** /*****************************************************************************
Copyright (c) 1996, 2013, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 1996, 2013, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2015, MariaDB Corporation
This program is free software; you can redistribute it and/or modify it under 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 the terms of the GNU General Public License as published by the Free Software
...@@ -1058,6 +1059,20 @@ struct trx_t{ ...@@ -1058,6 +1059,20 @@ struct trx_t{
#define DPAH_SIZE 8192 #define DPAH_SIZE 8192
byte* distinct_page_access_hash; byte* distinct_page_access_hash;
ibool take_stats; ibool take_stats;
/* Lock wait statistics */
ulint n_rec_lock_waits;
/*!< Number of record lock waits,
might not be exactly correct. */
ulint n_table_lock_waits;
/*!< Number of table lock waits,
might not be exactly correct. */
ulint total_rec_lock_wait_time;
/*!< Total rec lock wait time up
to this moment. */
ulint total_table_lock_wait_time;
/*!< Total table lock wait time
up to this moment. */
}; };
/* Transaction isolation levels (trx->isolation_level) */ /* Transaction isolation levels (trx->isolation_level) */
......
...@@ -2055,6 +2055,8 @@ lock_rec_enqueue_waiting( ...@@ -2055,6 +2055,8 @@ lock_rec_enqueue_waiting(
MONITOR_INC(MONITOR_LOCKREC_WAIT); MONITOR_INC(MONITOR_LOCKREC_WAIT);
trx->n_rec_lock_waits++;
return(DB_LOCK_WAIT); return(DB_LOCK_WAIT);
} }
...@@ -2474,6 +2476,15 @@ lock_grant( ...@@ -2474,6 +2476,15 @@ lock_grant(
} }
} }
/* Cumulate total lock wait time for statistics */
if (lock_get_type_low(lock) & LOCK_TABLE) {
lock->trx->total_table_lock_wait_time +=
(ulint)difftime(ut_time(), lock->trx->lock.wait_started);
} else {
lock->trx->total_rec_lock_wait_time +=
(ulint)difftime(ut_time(), lock->trx->lock.wait_started);
}
trx_mutex_exit(lock->trx); trx_mutex_exit(lock->trx);
} }
...@@ -4484,6 +4495,7 @@ lock_table_enqueue_waiting( ...@@ -4484,6 +4495,7 @@ lock_table_enqueue_waiting(
trx->lock.wait_started = ut_time(); trx->lock.wait_started = ut_time();
trx->lock.was_chosen_as_deadlock_victim = FALSE; trx->lock.was_chosen_as_deadlock_victim = FALSE;
trx->n_table_lock_waits++;
if (UNIV_UNLIKELY(trx->take_stats)) { if (UNIV_UNLIKELY(trx->take_stats)) {
ut_usectime(&sec, &ms); ut_usectime(&sec, &ms);
...@@ -5495,6 +5507,14 @@ lock_print_info_all_transactions( ...@@ -5495,6 +5507,14 @@ lock_print_info_all_transactions(
trx->read_view->up_limit_id); trx->read_view->up_limit_id);
} }
/* Total trx lock waits and times */
fprintf(file, "Trx #rec lock waits %lu #table lock waits %lu\n",
trx->n_rec_lock_waits, trx->n_table_lock_waits);
fprintf(file, "Trx total rec lock wait time %lu SEC\n",
trx->total_rec_lock_wait_time);
fprintf(file, "Trx total table lock wait time %lu SEC\n",
trx->total_table_lock_wait_time);
if (trx->lock.que_state == TRX_QUE_LOCK_WAIT) { if (trx->lock.que_state == TRX_QUE_LOCK_WAIT) {
fprintf(file, fprintf(file,
......
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