Commit 9e5df967 authored by Marko Mäkelä's avatar Marko Mäkelä

Reduce the amount of time(NULL) calls for lock processing

lock_t::requested_time: Document what the field is used for.

lock_t::wait_time: Document that the field is only used for
diagnostics and may be garbage if the system time is being adjusted.

srv_slot_t::suspend_time: Document that this is duplicating
trx_lock_t::wait_started.

lock_table_print(), lock_rec_print(): Declare in static scope.
Add a parameter for the current time.

lock_deadlock_check_and_resolve(), lock_deadlock_lock_print(),
lock_deadlock_joining_trx_print():
Add a parameter for the current time.
parent 2b5bc761
......@@ -615,22 +615,6 @@ lock_report_trx_id_insanity(
trx_id_t max_trx_id) /*!< in: trx_sys_get_max_trx_id() */
MY_ATTRIBUTE((nonnull));
/*********************************************************************//**
Prints info of a table lock. */
UNIV_INTERN
void
lock_table_print(
/*=============*/
FILE* file, /*!< in: file where to print */
const lock_t* lock); /*!< in: table type lock */
/*********************************************************************//**
Prints info of a record lock. */
UNIV_INTERN
void
lock_rec_print(
/*===========*/
FILE* file, /*!< in: file where to print */
const lock_t* lock); /*!< in: record type lock */
/*********************************************************************//**
Prints info of locks for all transactions.
@return FALSE if not able to obtain lock mutex and exits without
printing info */
......
......@@ -74,10 +74,14 @@ struct lock_t {
lock */
dict_index_t* index; /*!< index for a record lock */
/* Statistics for how long lock has been held and time
how long this lock had to be waited before it was granted */
time_t requested_time; /*!< Lock request time */
ulint wait_time; /*!< Time waited this lock or 0 */
/** time(NULL) of the lock request creation.
Used for computing wait_time and diagnostics only.
Note: bogus durations may be reported
when the system time is adjusted! */
time_t requested_time;
/** Cumulated wait time in seconds.
Note: may be bogus when the system time is adjusted! */
ulint wait_time;
union {
lock_table_t tab_lock;/*!< table lock */
......
......@@ -1078,10 +1078,14 @@ struct srv_slot_t{
ibool suspended; /*!< TRUE if the thread is
waiting for the event of this
slot */
ib_time_t suspend_time; /*!< time when the thread was
suspended. Initialized by
lock_wait_table_reserve_slot()
for lock wait */
/** time(NULL) when the thread was suspended.
FIXME: Use my_interval_timer() or similar, to avoid bogus
timeouts in lock_wait_check_and_cancel() or lock_wait_suspend_thread()
when the system time is adjusted to the past!
FIXME: This is duplicating trx_lock_t::wait_started,
which is being used for diagnostic purposes only. */
time_t suspend_time;
ulong wait_timeout; /*!< wait time that if exceeded
the thread will be timed out.
Initialized by
......
/*****************************************************************************
Copyright (c) 2007, 2011, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2019, MariaDB Corporation.
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
......@@ -133,7 +134,7 @@ struct i_s_trx_row_t {
/*!< pointer to a row
in innodb_locks if trx
is waiting, or NULL */
ib_time_t trx_wait_started; /*!< trx_t::wait_started */
time_t trx_wait_started; /*!< trx->lock.wait_started */
ullint trx_weight; /*!< TRX_WEIGHT() */
ulint trx_mysql_thread_id; /*!< thd_get_thread_id() */
const char* trx_query; /*!< MySQL statement being
......
This diff is collapsed.
......@@ -226,7 +226,6 @@ lock_wait_suspend_thread(
user OS thread */
{
srv_slot_t* slot;
double wait_time;
trx_t* trx;
ulint had_dict_lock;
ibool was_declared_inside_innodb;
......@@ -360,7 +359,7 @@ lock_wait_suspend_thread(
row_mysql_freeze_data_dictionary(trx);
}
wait_time = ut_difftime(ut_time(), slot->suspend_time);
double wait_time = difftime(time(NULL), slot->suspend_time);
/* Release the slot for others to use */
......@@ -451,19 +450,12 @@ lock_wait_check_and_cancel(
const srv_slot_t* slot) /*!< in: slot reserved by a user
thread when the wait started */
{
trx_t* trx;
double wait_time;
ib_time_t suspend_time = slot->suspend_time;
ut_ad(lock_wait_mutex_own());
ut_ad(slot->in_use);
ut_ad(slot->suspended);
wait_time = ut_difftime(ut_time(), suspend_time);
trx = thr_get_trx(slot->thr);
double wait_time = difftime(time(NULL), slot->suspend_time);
trx_t* trx = thr_get_trx(slot->thr);
if (trx_is_interrupted(trx)
|| (slot->wait_timeout < 100000000
......@@ -497,7 +489,6 @@ lock_wait_check_and_cancel(
trx_mutex_exit(trx);
}
}
/*********************************************************************//**
......
......@@ -629,22 +629,6 @@ lock_report_trx_id_insanity(
trx_id_t max_trx_id) /*!< in: trx_sys_get_max_trx_id() */
MY_ATTRIBUTE((nonnull));
/*********************************************************************//**
Prints info of a table lock. */
UNIV_INTERN
void
lock_table_print(
/*=============*/
FILE* file, /*!< in: file where to print */
const lock_t* lock); /*!< in: table type lock */
/*********************************************************************//**
Prints info of a record lock. */
UNIV_INTERN
void
lock_rec_print(
/*===========*/
FILE* file, /*!< in: file where to print */
const lock_t* lock); /*!< in: record type lock */
/*********************************************************************//**
Prints info of locks for all transactions.
@return FALSE if not able to obtain lock mutex and exits without
printing info */
......
......@@ -74,10 +74,14 @@ struct lock_t {
lock */
dict_index_t* index; /*!< index for a record lock */
/* Statistics for how long lock has been held and time
how long this lock had to be waited before it was granted */
time_t requested_time; /*!< Lock request time */
ulint wait_time; /*!< Time waited this lock or 0 */
/** time(NULL) of the lock request creation.
Used for computing wait_time and diagnostics only.
Note: bogus durations may be reported
when the system time is adjusted! */
time_t requested_time;
/** Cumulated wait time in seconds.
Note: may be bogus when the system time is adjusted! */
ulint wait_time;
union {
lock_table_t tab_lock;/*!< table lock */
......
......@@ -1332,7 +1332,10 @@ struct srv_slot_t{
/** time(NULL) when the thread was suspended.
FIXME: Use my_interval_timer() or similar, to avoid bogus
timeouts in lock_wait_check_and_cancel() or lock_wait_suspend_thread()
when the system time is adjusted to the past! */
when the system time is adjusted to the past!
FIXME: This is duplicating trx_lock_t::wait_started,
which is being used for diagnostic purposes only. */
time_t suspend_time;
ulong wait_timeout; /*!< wait time that if exceeded
the thread will be timed out.
......
/*****************************************************************************
Copyright (c) 2007, 2011, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2019, MariaDB Corporation.
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
......@@ -133,7 +134,7 @@ struct i_s_trx_row_t {
/*!< pointer to a row
in innodb_locks if trx
is waiting, or NULL */
ib_time_t trx_wait_started; /*!< trx_t::wait_started */
time_t trx_wait_started; /*!< trx->lock.wait_started */
ullint trx_weight; /*!< TRX_WEIGHT() */
ulint trx_mysql_thread_id; /*!< thd_get_thread_id() */
const char* trx_query; /*!< MySQL statement being
......
This diff is collapsed.
......@@ -280,7 +280,6 @@ lock_wait_suspend_thread(
user OS thread */
{
srv_slot_t* slot;
double wait_time;
trx_t* trx;
ulint had_dict_lock;
ibool was_declared_inside_innodb;
......@@ -416,7 +415,7 @@ lock_wait_suspend_thread(
row_mysql_freeze_data_dictionary(trx);
}
wait_time = ut_difftime(ut_time(), slot->suspend_time);
double wait_time = difftime(time(NULL), slot->suspend_time);
/* Release the slot for others to use */
......@@ -509,19 +508,12 @@ lock_wait_check_and_cancel(
const srv_slot_t* slot) /*!< in: slot reserved by a user
thread when the wait started */
{
trx_t* trx;
double wait_time;
ib_time_t suspend_time = slot->suspend_time;
ut_ad(lock_wait_mutex_own());
ut_ad(slot->in_use);
ut_ad(slot->suspended);
wait_time = ut_difftime(ut_time(), suspend_time);
trx = thr_get_trx(slot->thr);
double wait_time = difftime(time(NULL), slot->suspend_time);
trx_t* trx = thr_get_trx(slot->thr);
if (trx_is_interrupted(trx)
|| (slot->wait_timeout < 100000000
......@@ -555,7 +547,6 @@ lock_wait_check_and_cancel(
trx_mutex_exit(trx);
}
}
/*********************************************************************//**
......
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