Commit bda8a2a6 authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-24671 fixup: Merge lock_sys_t::wait_pending into wait_count

The maximum number of concurrently waiting transactions is one less
than the maximum number of concurrent transactions.

A 45-bit cumulative counter of lock waits will support more than
one million lock waits per second for a year.
parent 78284a4c
......@@ -670,10 +670,11 @@ class lock_sys_t
/** mutex covering lock waits; @see trx_lock_t::wait_lock */
MY_ALIGNED(CPU_LEVEL1_DCACHE_LINESIZE) mysql_mutex_t wait_mutex;
private:
/** Cumulative number of lock waits; protected by wait_mutex */
ulint wait_count;
/** Pending number of lock waits; protected by wait_mutex */
uint32_t wait_pending;
/** The increment of wait_count for a wait. Anything smaller is a
pending wait count. */
static constexpr uint64_t WAIT_COUNT_STEP= 1U << 19;
/** waits and total number of lock waits; protected by wait_mutex */
uint64_t wait_count;
/** Cumulative wait time; protected by wait_mutex */
uint32_t wait_time;
/** Longest wait time; protected by wait_mutex */
......@@ -818,9 +819,13 @@ class lock_sys_t
inline void wait_resume(THD *thd, my_hrtime_t start, my_hrtime_t now);
/** @return pending number of lock waits */
ulint get_wait_pending() const { return wait_pending; }
ulint get_wait_pending() const
{
return static_cast<ulint>(wait_count & (WAIT_COUNT_STEP - 1));
}
/** @return cumulative number of lock waits */
ulint get_wait_cumulative() const { return wait_count; }
ulint get_wait_cumulative() const
{ return static_cast<ulint>(wait_count / WAIT_COUNT_STEP); }
/** Cumulative wait time; protected by wait_mutex */
ulint get_wait_time_cumulative() const { return wait_time; }
/** Longest wait time; protected by wait_mutex */
......
......@@ -1587,8 +1587,11 @@ lock_rec_has_to_wait_in_queue(const hash_cell_t &cell, const lock_t *wait_lock)
inline void lock_sys_t::wait_start()
{
mysql_mutex_assert_owner(&wait_mutex);
wait_pending++;
wait_count++;
wait_count+= WAIT_COUNT_STEP + 1;
/* The maximum number of concurrently waiting transactions is one less
than the maximum number of concurrent transactions. */
static_assert(WAIT_COUNT_STEP == UNIV_PAGE_SIZE_MAX / 16 * TRX_SYS_N_RSEGS,
"compatibility");
}
/** Note that a record lock wait resumed */
......@@ -1596,7 +1599,9 @@ inline
void lock_sys_t::wait_resume(THD *thd, my_hrtime_t start, my_hrtime_t now)
{
mysql_mutex_assert_owner(&wait_mutex);
wait_pending--;
ut_ad(get_wait_pending());
ut_ad(get_wait_cumulative());
wait_count--;
if (now.val >= start.val)
{
const uint32_t diff_time=
......
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