Skip to content

Commit 90635c6

Browse files
author
Jan Lindström
committed
MDEV-7620: Transaction lock wait is missing number of lock
waits and total wait time.
1 parent 8366ce4 commit 90635c6

File tree

4 files changed

+68
-0
lines changed

4 files changed

+68
-0
lines changed

storage/innobase/include/trx0trx.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,19 @@ struct trx_t{
10091009
/*------------------------------*/
10101010
char detailed_error[256]; /*!< detailed error message for last
10111011
error, or empty. */
1012+
/* Lock wait statistics */
1013+
ulint n_rec_lock_waits;
1014+
/*!< Number of record lock waits,
1015+
might not be exactly correct. */
1016+
ulint n_table_lock_waits;
1017+
/*!< Number of table lock waits,
1018+
might not be exactly correct. */
1019+
ulint total_rec_lock_wait_time;
1020+
/*!< Total rec lock wait time up
1021+
to this moment. */
1022+
ulint total_table_lock_wait_time;
1023+
/*!< Total table lock wait time
1024+
up to this moment. */
10121025
};
10131026

10141027
/* Transaction isolation levels (trx->isolation_level) */

storage/innobase/lock/lock0lock.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2034,6 +2034,8 @@ lock_rec_enqueue_waiting(
20342034

20352035
MONITOR_INC(MONITOR_LOCKREC_WAIT);
20362036

2037+
trx->n_rec_lock_waits++;
2038+
20372039
return(DB_LOCK_WAIT);
20382040
}
20392041

@@ -2454,6 +2456,15 @@ lock_grant(
24542456
}
24552457
}
24562458

2459+
/* Cumulate total lock wait time for statistics */
2460+
if (lock_get_type_low(lock) & LOCK_TABLE) {
2461+
lock->trx->total_table_lock_wait_time +=
2462+
(ulint)difftime(ut_time(), lock->trx->lock.wait_started);
2463+
} else {
2464+
lock->trx->total_rec_lock_wait_time +=
2465+
(ulint)difftime(ut_time(), lock->trx->lock.wait_started);
2466+
}
2467+
24572468
trx_mutex_exit(lock->trx);
24582469
}
24592470

@@ -4458,6 +4469,7 @@ lock_table_enqueue_waiting(
44584469

44594470
trx->lock.wait_started = ut_time();
44604471
trx->lock.was_chosen_as_deadlock_victim = FALSE;
4472+
trx->n_table_lock_waits++;
44614473

44624474
ut_a(que_thr_stop(thr));
44634475

@@ -5458,6 +5470,14 @@ lock_print_info_all_transactions(
54585470
trx->read_view->up_limit_id);
54595471
}
54605472

5473+
/* Total trx lock waits and times */
5474+
fprintf(file, "Trx #rec lock waits %lu #table lock waits %lu\n",
5475+
trx->n_rec_lock_waits, trx->n_table_lock_waits);
5476+
fprintf(file, "Trx total rec lock wait time %lu SEC\n",
5477+
trx->total_rec_lock_wait_time);
5478+
fprintf(file, "Trx total table lock wait time %lu SEC\n",
5479+
trx->total_table_lock_wait_time);
5480+
54615481
if (trx->lock.que_state == TRX_QUE_LOCK_WAIT) {
54625482

54635483
fprintf(file,

storage/xtradb/include/trx0trx.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*****************************************************************************
22
33
Copyright (c) 1996, 2013, Oracle and/or its affiliates. All Rights Reserved.
4+
Copyright (c) 2015, MariaDB Corporation
45
56
This program is free software; you can redistribute it and/or modify it under
67
the terms of the GNU General Public License as published by the Free Software
@@ -1058,6 +1059,20 @@ struct trx_t{
10581059
#define DPAH_SIZE 8192
10591060
byte* distinct_page_access_hash;
10601061
ibool take_stats;
1062+
1063+
/* Lock wait statistics */
1064+
ulint n_rec_lock_waits;
1065+
/*!< Number of record lock waits,
1066+
might not be exactly correct. */
1067+
ulint n_table_lock_waits;
1068+
/*!< Number of table lock waits,
1069+
might not be exactly correct. */
1070+
ulint total_rec_lock_wait_time;
1071+
/*!< Total rec lock wait time up
1072+
to this moment. */
1073+
ulint total_table_lock_wait_time;
1074+
/*!< Total table lock wait time
1075+
up to this moment. */
10611076
};
10621077

10631078
/* Transaction isolation levels (trx->isolation_level) */

storage/xtradb/lock/lock0lock.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2055,6 +2055,8 @@ lock_rec_enqueue_waiting(
20552055

20562056
MONITOR_INC(MONITOR_LOCKREC_WAIT);
20572057

2058+
trx->n_rec_lock_waits++;
2059+
20582060
return(DB_LOCK_WAIT);
20592061
}
20602062

@@ -2474,6 +2476,15 @@ lock_grant(
24742476
}
24752477
}
24762478

2479+
/* Cumulate total lock wait time for statistics */
2480+
if (lock_get_type_low(lock) & LOCK_TABLE) {
2481+
lock->trx->total_table_lock_wait_time +=
2482+
(ulint)difftime(ut_time(), lock->trx->lock.wait_started);
2483+
} else {
2484+
lock->trx->total_rec_lock_wait_time +=
2485+
(ulint)difftime(ut_time(), lock->trx->lock.wait_started);
2486+
}
2487+
24772488
trx_mutex_exit(lock->trx);
24782489
}
24792490

@@ -4484,6 +4495,7 @@ lock_table_enqueue_waiting(
44844495

44854496
trx->lock.wait_started = ut_time();
44864497
trx->lock.was_chosen_as_deadlock_victim = FALSE;
4498+
trx->n_table_lock_waits++;
44874499

44884500
if (UNIV_UNLIKELY(trx->take_stats)) {
44894501
ut_usectime(&sec, &ms);
@@ -5495,6 +5507,14 @@ lock_print_info_all_transactions(
54955507
trx->read_view->up_limit_id);
54965508
}
54975509

5510+
/* Total trx lock waits and times */
5511+
fprintf(file, "Trx #rec lock waits %lu #table lock waits %lu\n",
5512+
trx->n_rec_lock_waits, trx->n_table_lock_waits);
5513+
fprintf(file, "Trx total rec lock wait time %lu SEC\n",
5514+
trx->total_rec_lock_wait_time);
5515+
fprintf(file, "Trx total table lock wait time %lu SEC\n",
5516+
trx->total_table_lock_wait_time);
5517+
54985518
if (trx->lock.que_state == TRX_QUE_LOCK_WAIT) {
54995519

55005520
fprintf(file,

0 commit comments

Comments
 (0)