Skip to content

Commit 8799f87

Browse files
author
Jan Lindström
committed
MDEV-7623: Add lock wait time and hold time to every record/table lock in
InnoDB transaction lock printout.
1 parent 90635c6 commit 8799f87

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

storage/innobase/include/lock0priv.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*****************************************************************************
22
33
Copyright (c) 2007, 2011, 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
@@ -72,6 +73,12 @@ struct lock_t {
7273
hash_node_t hash; /*!< hash chain node for a record
7374
lock */
7475
dict_index_t* index; /*!< index for a record lock */
76+
77+
/* Statistics for how long lock has been held and time
78+
how long this lock had to be waited before it was granted */
79+
time_t requested_time; /*!< Lock request time */
80+
ulint wait_time; /*!< Time waited this lock or 0 */
81+
7582
union {
7683
lock_table_t tab_lock;/*!< table lock */
7784
lock_rec_t rec_lock;/*!< record lock */

storage/innobase/lock/lock0lock.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*****************************************************************************
22
33
Copyright (c) 1996, 2014, Oracle and/or its affiliates. All Rights Reserved.
4+
Copyright (c) 2014, 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
@@ -1886,6 +1887,9 @@ lock_rec_create(
18861887
/* Set the bit corresponding to rec */
18871888
lock_rec_set_nth_bit(lock, heap_no);
18881889

1890+
lock->requested_time = ut_time();
1891+
lock->wait_time = 0;
1892+
18891893
index->table->n_rec_locks++;
18901894

18911895
ut_ad(index->table->n_ref_count > 0 || !index->table->can_be_evicted);
@@ -2465,6 +2469,8 @@ lock_grant(
24652469
(ulint)difftime(ut_time(), lock->trx->lock.wait_started);
24662470
}
24672471

2472+
lock->wait_time = (ulint)difftime(ut_time(), lock->requested_time);
2473+
24682474
trx_mutex_exit(lock->trx);
24692475
}
24702476

@@ -4226,6 +4232,8 @@ lock_table_create(
42264232

42274233
lock->type_mode = type_mode | LOCK_TABLE;
42284234
lock->trx = trx;
4235+
lock->requested_time = ut_time();
4236+
lock->wait_time = 0;
42294237

42304238
lock->un_member.tab_lock.table = table;
42314239

@@ -5145,6 +5153,10 @@ lock_table_print(
51455153
fputs(" waiting", file);
51465154
}
51475155

5156+
fprintf(file, " lock hold time %lu wait time before grant %lu ",
5157+
(ulint)difftime(ut_time(), lock->requested_time),
5158+
lock->wait_time);
5159+
51485160
putc('\n', file);
51495161
}
51505162

@@ -5212,6 +5224,10 @@ lock_rec_print(
52125224

52135225
mtr_start(&mtr);
52145226

5227+
fprintf(file, " lock hold time %lu wait time before grant %lu ",
5228+
(ulint)difftime(ut_time(), lock->requested_time),
5229+
lock->wait_time);
5230+
52155231
putc('\n', file);
52165232

52175233
block = buf_page_try_get(space, page_no, &mtr);

storage/xtradb/include/lock0priv.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*****************************************************************************
22
33
Copyright (c) 2007, 2011, 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
@@ -72,6 +73,12 @@ struct lock_t {
7273
hash_node_t hash; /*!< hash chain node for a record
7374
lock */
7475
dict_index_t* index; /*!< index for a record lock */
76+
77+
/* Statistics for how long lock has been held and time
78+
how long this lock had to be waited before it was granted */
79+
time_t requested_time; /*!< Lock request time */
80+
ulint wait_time; /*!< Time waited this lock or 0 */
81+
7582
union {
7683
lock_table_t tab_lock;/*!< table lock */
7784
lock_rec_t rec_lock;/*!< record lock */

storage/xtradb/lock/lock0lock.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*****************************************************************************
22
33
Copyright (c) 1996, 2014, Oracle and/or its affiliates. All Rights Reserved.
4+
Copyright (c) 2014, 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
@@ -1897,6 +1898,9 @@ lock_rec_create(
18971898
/* Set the bit corresponding to rec */
18981899
lock_rec_set_nth_bit(lock, heap_no);
18991900

1901+
lock->requested_time = ut_time();
1902+
lock->wait_time = 0;
1903+
19001904
index->table->n_rec_locks++;
19011905

19021906
ut_ad(index->table->n_ref_count > 0 || !index->table->can_be_evicted);
@@ -2485,6 +2489,8 @@ lock_grant(
24852489
(ulint)difftime(ut_time(), lock->trx->lock.wait_started);
24862490
}
24872491

2492+
lock->wait_time = (ulint)difftime(ut_time(), lock->requested_time);
2493+
24882494
trx_mutex_exit(lock->trx);
24892495
}
24902496

@@ -4250,6 +4256,8 @@ lock_table_create(
42504256

42514257
lock->type_mode = type_mode | LOCK_TABLE;
42524258
lock->trx = trx;
4259+
lock->requested_time = ut_time();
4260+
lock->wait_time = 0;
42534261

42544262
lock->un_member.tab_lock.table = table;
42554263

@@ -5180,6 +5188,10 @@ lock_table_print(
51805188
fputs(" waiting", file);
51815189
}
51825190

5191+
fprintf(file, " lock hold time %lu wait time before grant %lu ",
5192+
(ulint)difftime(ut_time(), lock->requested_time),
5193+
lock->wait_time);
5194+
51835195
putc('\n', file);
51845196
}
51855197

@@ -5247,6 +5259,10 @@ lock_rec_print(
52475259

52485260
mtr_start(&mtr);
52495261

5262+
fprintf(file, " lock hold time %lu wait time before grant %lu ",
5263+
(ulint)difftime(ut_time(), lock->requested_time),
5264+
lock->wait_time);
5265+
52505266
putc('\n', file);
52515267

52525268
if ( srv_show_verbose_locks ) {

0 commit comments

Comments
 (0)