Skip to content

Commit bd52f1a

Browse files
committed
Cleanup: Remove lock_number_of_rows_locked()
Let us access trx->lock.n_rec_locks directly.
1 parent 3dabe63 commit bd52f1a

File tree

9 files changed

+24
-45
lines changed

9 files changed

+24
-45
lines changed

storage/innobase/include/lock0lock.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*****************************************************************************
22
33
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
4-
Copyright (c) 2017, 2020, MariaDB Corporation.
4+
Copyright (c) 2017, 2021, MariaDB Corporation.
55
66
This program is free software; you can redistribute it and/or modify it under
77
the terms of the GNU General Public License as published by the Free Software
@@ -534,16 +534,6 @@ void
534534
lock_print_info_all_transactions(
535535
/*=============================*/
536536
FILE* file); /*!< in: file where to print */
537-
/*********************************************************************//**
538-
Return approximate number or record locks (bits set in the bitmap) for
539-
this transaction. Since delete-marked records may be removed, the
540-
record count will not be precise.
541-
The caller must be holding lock_sys.mutex. */
542-
ulint
543-
lock_number_of_rows_locked(
544-
/*=======================*/
545-
const trx_lock_t* trx_lock) /*!< in: transaction locks */
546-
MY_ATTRIBUTE((warn_unused_result));
547537

548538
/*********************************************************************//**
549539
Return the number of table locks for a transaction.

storage/innobase/include/lock0priv.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*****************************************************************************
22
33
Copyright (c) 2007, 2016, Oracle and/or its affiliates. All Rights Reserved.
4-
Copyright (c) 2015, 2018, MariaDB Corporation.
4+
Copyright (c) 2015, 2021, MariaDB Corporation.
55
66
This program is free software; you can redistribute it and/or modify it under
77
the terms of the GNU General Public License as published by the Free Software
@@ -515,6 +515,7 @@ lock_rec_set_nth_bit(
515515
@return previous value of the bit */
516516
inline byte lock_rec_reset_nth_bit(lock_t* lock, ulint i)
517517
{
518+
lock_sys.mutex_assert_locked();
518519
ut_ad(lock_get_type_low(lock) == LOCK_REC);
519520
ut_ad(i < lock->un_member.rec_lock.n_bits);
520521

@@ -524,8 +525,9 @@ inline byte lock_rec_reset_nth_bit(lock_t* lock, ulint i)
524525
*b &= byte(~mask);
525526

526527
if (bit != 0) {
527-
ut_ad(lock->trx->lock.n_rec_locks > 0);
528-
--lock->trx->lock.n_rec_locks;
528+
ut_d(auto n=)
529+
lock->trx->lock.n_rec_locks--;
530+
ut_ad(n);
529531
}
530532

531533
return(bit);

storage/innobase/include/lock0priv.ic

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*****************************************************************************
22
33
Copyright (c) 2007, 2014, Oracle and/or its affiliates. All Rights Reserved.
4-
Copyright (c) 2018, 2020, MariaDB Corporation.
4+
Copyright (c) 2018, 2021, MariaDB Corporation.
55
66
This program is free software; you can redistribute it and/or modify it under
77
the terms of the GNU General Public License as published by the Free Software
@@ -91,6 +91,7 @@ lock_rec_set_nth_bit(
9191
ulint byte_index;
9292
ulint bit_index;
9393

94+
lock_sys.mutex_assert_locked();
9495
ut_ad(lock);
9596
ut_ad(lock_get_type_low(lock) == LOCK_REC);
9697
ut_ad(i < lock->un_member.rec_lock.n_bits);
@@ -106,7 +107,7 @@ lock_rec_set_nth_bit(
106107
#if defined __GNUC__ && !defined __clang__ && __GNUC__ < 6
107108
# pragma GCC diagnostic pop
108109
#endif
109-
++lock->trx->lock.n_rec_locks;
110+
lock->trx->lock.n_rec_locks++;
110111
}
111112

112113
/*********************************************************************//**

storage/innobase/include/trx0i_s.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*****************************************************************************
22
33
Copyright (c) 2007, 2015, Oracle and/or its affiliates. All Rights Reserved.
4-
Copyright (c) 2017, 2020, MariaDB Corporation.
4+
Copyright (c) 2017, 2021, MariaDB Corporation.
55
66
This program is free software; you can redistribute it and/or modify it under
77
the terms of the GNU General Public License as published by the Free Software
@@ -138,7 +138,7 @@ struct i_s_trx_row_t {
138138
ulint trx_lock_memory_bytes;
139139
/*!< mem_heap_get_size(
140140
trx->lock_heap) */
141-
ulint trx_rows_locked;/*!< lock_number_of_rows_locked() */
141+
ulint trx_rows_locked;/*!< trx_lock_t::n_rec_locks */
142142
uintmax_t trx_rows_modified;/*!< trx_t::undo_no */
143143
uint trx_isolation_level;
144144
/*!< trx_t::isolation_level */

storage/innobase/include/trx0trx.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*****************************************************************************
22
33
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
4-
Copyright (c) 2015, 2020, MariaDB Corporation.
4+
Copyright (c) 2015, 2021, MariaDB Corporation.
55
66
This program is free software; you can redistribute it and/or modify it under
77
the terms of the GNU General Public License as published by the Free Software
@@ -245,7 +245,7 @@ trx_print_low(
245245
/*!< in: max query length to print,
246246
or 0 to use the default max length */
247247
ulint n_rec_locks,
248-
/*!< in: lock_number_of_rows_locked(&trx->lock) */
248+
/*!< in: trx->lock.n_rec_locks */
249249
ulint n_trx_locks,
250250
/*!< in: length of trx->lock.trx_locks */
251251
ulint heap_size);
@@ -560,7 +560,8 @@ struct trx_lock_t {
560560
mutex to prevent recursive deadlocks.
561561
Protected by both the lock sys mutex
562562
and the trx_t::mutex. */
563-
ulint n_rec_locks; /*!< number of rec locks in this trx */
563+
/** number of record locks; writes are protected by lock_sys.mutex */
564+
ulint n_rec_locks;
564565
};
565566

566567
/** Logical first modification time of a table in a transaction */

storage/innobase/lock/lock0lock.cc

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*****************************************************************************
22
33
Copyright (c) 1996, 2017, Oracle and/or its affiliates. All Rights Reserved.
4-
Copyright (c) 2014, 2020, MariaDB Corporation.
4+
Copyright (c) 2014, 2021, MariaDB Corporation.
55
66
This program is free software; you can redistribute it and/or modify it under
77
the terms of the GNU General Public License as published by the Free Software
@@ -1157,21 +1157,6 @@ lock_sec_rec_some_has_impl(
11571157
return(trx);
11581158
}
11591159

1160-
/*********************************************************************//**
1161-
Return approximate number or record locks (bits set in the bitmap) for
1162-
this transaction. Since delete-marked records may be removed, the
1163-
record count will not be precise.
1164-
The caller must be holding lock_sys.mutex. */
1165-
ulint
1166-
lock_number_of_rows_locked(
1167-
/*=======================*/
1168-
const trx_lock_t* trx_lock) /*!< in: transaction locks */
1169-
{
1170-
lock_sys.mutex_assert_locked();
1171-
1172-
return(trx_lock->n_rec_locks);
1173-
}
1174-
11751160
/*********************************************************************//**
11761161
Return the number of table locks for a transaction.
11771162
The caller must be holding lock_sys.mutex. */
@@ -5940,7 +5925,7 @@ DeadlockChecker::print(const trx_t* trx, ulint max_query_len)
59405925
{
59415926
lock_sys.mutex_assert_locked();
59425927

5943-
ulint n_rec_locks = lock_number_of_rows_locked(&trx->lock);
5928+
ulint n_rec_locks = trx->lock.n_rec_locks;
59445929
ulint n_trx_locks = UT_LIST_GET_LEN(trx->lock.trx_locks);
59455930
ulint heap_size = mem_heap_get_size(trx->lock.lock_heap);
59465931

storage/innobase/row/row0ins.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*****************************************************************************
22
33
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
4-
Copyright (c) 2016, 2020, MariaDB Corporation.
4+
Copyright (c) 2016, 2021, MariaDB Corporation.
55
66
This program is free software; you can redistribute it and/or modify it under
77
the terms of the GNU General Public License as published by the Free Software
@@ -705,7 +705,7 @@ row_ins_foreign_trx_print(
705705
ut_ad(!srv_read_only_mode);
706706

707707
lock_sys.mutex_lock();
708-
n_rec_locks = lock_number_of_rows_locked(&trx->lock);
708+
n_rec_locks = trx->lock.n_rec_locks;
709709
n_trx_locks = UT_LIST_GET_LEN(trx->lock.trx_locks);
710710
heap_size = mem_heap_get_size(trx->lock.lock_heap);
711711
lock_sys.mutex_unlock();

storage/innobase/trx/trx0i_s.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*****************************************************************************
22
33
Copyright (c) 2007, 2015, Oracle and/or its affiliates. All Rights Reserved.
4-
Copyright (c) 2017, 2020, MariaDB Corporation.
4+
Copyright (c) 2017, 2021, MariaDB Corporation.
55
66
This program is free software; you can redistribute it and/or modify it under
77
the terms of the GNU General Public License as published by the Free Software
@@ -487,7 +487,7 @@ fill_trx_row(
487487

488488
row->trx_lock_memory_bytes = mem_heap_get_size(trx->lock.lock_heap);
489489

490-
row->trx_rows_locked = lock_number_of_rows_locked(&trx->lock);
490+
row->trx_rows_locked = trx->lock.n_rec_locks;
491491

492492
row->trx_rows_modified = trx->undo_no;
493493

storage/innobase/trx/trx0trx.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,7 +1761,7 @@ trx_print_low(
17611761
/*!< in: max query length to print,
17621762
or 0 to use the default max length */
17631763
ulint n_rec_locks,
1764-
/*!< in: lock_number_of_rows_locked(&trx->lock) */
1764+
/*!< in: trx->lock.n_rec_locks */
17651765
ulint n_trx_locks,
17661766
/*!< in: length of trx->lock.trx_locks */
17671767
ulint heap_size)
@@ -1872,7 +1872,7 @@ trx_print_latched(
18721872
lock_sys.mutex_assert_locked();
18731873

18741874
trx_print_low(f, trx, max_query_len,
1875-
lock_number_of_rows_locked(&trx->lock),
1875+
trx->lock.n_rec_locks,
18761876
UT_LIST_GET_LEN(trx->lock.trx_locks),
18771877
mem_heap_get_size(trx->lock.lock_heap));
18781878
}
@@ -1893,7 +1893,7 @@ trx_print(
18931893
ulint heap_size;
18941894

18951895
lock_sys.mutex_lock();
1896-
n_rec_locks = lock_number_of_rows_locked(&trx->lock);
1896+
n_rec_locks = trx->lock.n_rec_locks;
18971897
n_trx_locks = UT_LIST_GET_LEN(trx->lock.trx_locks);
18981898
heap_size = mem_heap_get_size(trx->lock.lock_heap);
18991899
lock_sys.mutex_unlock();

0 commit comments

Comments
 (0)