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