mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +03:00
InnoDB: Truncate SHOW INNODB STATUS output at the start of the list
of active transactions, if necessary and possible. (Bug #5436) innobase/include/lock0lock.h: Split lock_print_info() into lock_print_info_summary() and lock_print_info_all_transactions(). innobase/lock/lock0lock.c: Split lock_print_info() into lock_print_info_summary() and lock_print_info_all_transactions(). innobase/include/srv0srv.h: srv_printf_innodb_monitor(): Add output parameters trx_start and trx_end. innobase/srv/srv0srv.c: srv_printf_innodb_monitor(): Add output parameters trx_start and trx_end. sql/ha_innodb.cc: innodb_show_status(): Truncate oversized output at the beginning of the list of active transactions, if possible.
This commit is contained in:
@ -530,8 +530,15 @@ lock_rec_print(
|
|||||||
Prints info of locks for all transactions. */
|
Prints info of locks for all transactions. */
|
||||||
|
|
||||||
void
|
void
|
||||||
lock_print_info(
|
lock_print_info_summary(
|
||||||
/*============*/
|
/*====================*/
|
||||||
|
FILE* file); /* in: file where to print */
|
||||||
|
/*************************************************************************
|
||||||
|
Prints info of locks for each transaction. */
|
||||||
|
|
||||||
|
void
|
||||||
|
lock_print_info_all_transactions(
|
||||||
|
/*=============================*/
|
||||||
FILE* file); /* in: file where to print */
|
FILE* file); /* in: file where to print */
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
Validates the lock queue on a table. */
|
Validates the lock queue on a table. */
|
||||||
|
@ -398,7 +398,11 @@ Outputs to a file the output of the InnoDB Monitor. */
|
|||||||
void
|
void
|
||||||
srv_printf_innodb_monitor(
|
srv_printf_innodb_monitor(
|
||||||
/*======================*/
|
/*======================*/
|
||||||
FILE* file); /* in: output stream */
|
FILE* file, /* in: output stream */
|
||||||
|
ulint* trx_start, /* out: file position of the start of
|
||||||
|
the list of active transactions */
|
||||||
|
ulint* trx_end); /* out: file position of the end of
|
||||||
|
the list of active transactions */
|
||||||
|
|
||||||
|
|
||||||
/* Types for the threads existing in the system. Threads of types 4 - 9
|
/* Types for the threads existing in the system. Threads of types 4 - 9
|
||||||
|
@ -4126,21 +4126,10 @@ lock_get_n_rec_locks(void)
|
|||||||
Prints info of locks for all transactions. */
|
Prints info of locks for all transactions. */
|
||||||
|
|
||||||
void
|
void
|
||||||
lock_print_info(
|
lock_print_info_summary(
|
||||||
/*============*/
|
/*====================*/
|
||||||
FILE* file) /* in: file where to print */
|
FILE* file) /* in: file where to print */
|
||||||
{
|
{
|
||||||
lock_t* lock;
|
|
||||||
trx_t* trx;
|
|
||||||
ulint space;
|
|
||||||
ulint page_no;
|
|
||||||
page_t* page;
|
|
||||||
ibool load_page_first = TRUE;
|
|
||||||
ulint nth_trx = 0;
|
|
||||||
ulint nth_lock = 0;
|
|
||||||
ulint i;
|
|
||||||
mtr_t mtr;
|
|
||||||
|
|
||||||
/* We must protect the MySQL thd->query field with a MySQL mutex, and
|
/* We must protect the MySQL thd->query field with a MySQL mutex, and
|
||||||
because the MySQL mutex must be reserved before the kernel_mutex of
|
because the MySQL mutex must be reserved before the kernel_mutex of
|
||||||
InnoDB, we call innobase_mysql_prepare_print_arbitrary_thd() here. */
|
InnoDB, we call innobase_mysql_prepare_print_arbitrary_thd() here. */
|
||||||
@ -4179,6 +4168,26 @@ lock_print_info(
|
|||||||
fprintf(file,
|
fprintf(file,
|
||||||
"Total number of lock structs in row lock hash table %lu\n",
|
"Total number of lock structs in row lock hash table %lu\n",
|
||||||
(ulong) lock_get_n_rec_locks());
|
(ulong) lock_get_n_rec_locks());
|
||||||
|
}
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
Prints info of locks for each transaction. */
|
||||||
|
|
||||||
|
void
|
||||||
|
lock_print_info_all_transactions(
|
||||||
|
/*=============================*/
|
||||||
|
FILE* file) /* in: file where to print */
|
||||||
|
{
|
||||||
|
lock_t* lock;
|
||||||
|
ulint space;
|
||||||
|
ulint page_no;
|
||||||
|
page_t* page;
|
||||||
|
ibool load_page_first = TRUE;
|
||||||
|
ulint nth_trx = 0;
|
||||||
|
ulint nth_lock = 0;
|
||||||
|
ulint i;
|
||||||
|
mtr_t mtr;
|
||||||
|
trx_t* trx;
|
||||||
|
|
||||||
fprintf(file, "LIST OF TRANSACTIONS FOR EACH SESSION:\n");
|
fprintf(file, "LIST OF TRANSACTIONS FOR EACH SESSION:\n");
|
||||||
|
|
||||||
|
@ -1470,7 +1470,11 @@ Outputs to a file the output of the InnoDB Monitor. */
|
|||||||
void
|
void
|
||||||
srv_printf_innodb_monitor(
|
srv_printf_innodb_monitor(
|
||||||
/*======================*/
|
/*======================*/
|
||||||
FILE* file) /* in: output stream */
|
FILE* file, /* in: output stream */
|
||||||
|
ulint* trx_start, /* out: file position of the start of
|
||||||
|
the list of active transactions */
|
||||||
|
ulint* trx_end) /* out: file position of the end of
|
||||||
|
the list of active transactions */
|
||||||
{
|
{
|
||||||
double time_elapsed;
|
double time_elapsed;
|
||||||
time_t current_time;
|
time_t current_time;
|
||||||
@ -1519,7 +1523,24 @@ srv_printf_innodb_monitor(
|
|||||||
|
|
||||||
mutex_exit(&dict_foreign_err_mutex);
|
mutex_exit(&dict_foreign_err_mutex);
|
||||||
|
|
||||||
lock_print_info(file);
|
lock_print_info_summary(file);
|
||||||
|
if (trx_start) {
|
||||||
|
long t = ftell(file);
|
||||||
|
if (t < 0) {
|
||||||
|
*trx_start = ULINT_UNDEFINED;
|
||||||
|
} else {
|
||||||
|
*trx_start = (ulint) t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lock_print_info_all_transactions(file);
|
||||||
|
if (trx_end) {
|
||||||
|
long t = ftell(file);
|
||||||
|
if (t < 0) {
|
||||||
|
*trx_end = ULINT_UNDEFINED;
|
||||||
|
} else {
|
||||||
|
*trx_end = (ulint) t;
|
||||||
|
}
|
||||||
|
}
|
||||||
fputs("--------\n"
|
fputs("--------\n"
|
||||||
"FILE I/O\n"
|
"FILE I/O\n"
|
||||||
"--------\n", file);
|
"--------\n", file);
|
||||||
@ -1672,13 +1693,13 @@ loop:
|
|||||||
last_monitor_time = time(NULL);
|
last_monitor_time = time(NULL);
|
||||||
|
|
||||||
if (srv_print_innodb_monitor) {
|
if (srv_print_innodb_monitor) {
|
||||||
srv_printf_innodb_monitor(stderr);
|
srv_printf_innodb_monitor(stderr, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (srv_innodb_status) {
|
if (srv_innodb_status) {
|
||||||
mutex_enter(&srv_monitor_file_mutex);
|
mutex_enter(&srv_monitor_file_mutex);
|
||||||
rewind(srv_monitor_file);
|
rewind(srv_monitor_file);
|
||||||
srv_printf_innodb_monitor(srv_monitor_file);
|
srv_printf_innodb_monitor(srv_monitor_file, NULL, NULL);
|
||||||
os_file_set_eof(srv_monitor_file);
|
os_file_set_eof(srv_monitor_file);
|
||||||
mutex_exit(&srv_monitor_file_mutex);
|
mutex_exit(&srv_monitor_file_mutex);
|
||||||
}
|
}
|
||||||
|
@ -5168,8 +5168,12 @@ innodb_show_status(
|
|||||||
/*===============*/
|
/*===============*/
|
||||||
THD* thd) /* in: the MySQL query thread of the caller */
|
THD* thd) /* in: the MySQL query thread of the caller */
|
||||||
{
|
{
|
||||||
Protocol *protocol= thd->protocol;
|
Protocol* protocol = thd->protocol;
|
||||||
trx_t* trx;
|
trx_t* trx;
|
||||||
|
static const char truncated_msg[] = "... truncated...\n";
|
||||||
|
const long MAX_STATUS_SIZE = 64000;
|
||||||
|
ulint trx_list_start = ULINT_UNDEFINED;
|
||||||
|
ulint trx_list_end = ULINT_UNDEFINED;
|
||||||
|
|
||||||
DBUG_ENTER("innodb_show_status");
|
DBUG_ENTER("innodb_show_status");
|
||||||
|
|
||||||
@ -5184,33 +5188,57 @@ innodb_show_status(
|
|||||||
|
|
||||||
innobase_release_stat_resources(trx);
|
innobase_release_stat_resources(trx);
|
||||||
|
|
||||||
/* We let the InnoDB Monitor to output at most 64000 bytes of text. */
|
/* We let the InnoDB Monitor to output at most MAX_STATUS_SIZE
|
||||||
|
bytes of text. */
|
||||||
|
|
||||||
long flen;
|
long flen, usable_len;
|
||||||
char* str;
|
char* str;
|
||||||
|
|
||||||
mutex_enter_noninline(&srv_monitor_file_mutex);
|
mutex_enter_noninline(&srv_monitor_file_mutex);
|
||||||
rewind(srv_monitor_file);
|
rewind(srv_monitor_file);
|
||||||
srv_printf_innodb_monitor(srv_monitor_file);
|
srv_printf_innodb_monitor(srv_monitor_file,
|
||||||
|
&trx_list_start, &trx_list_end);
|
||||||
flen = ftell(srv_monitor_file);
|
flen = ftell(srv_monitor_file);
|
||||||
os_file_set_eof(srv_monitor_file);
|
os_file_set_eof(srv_monitor_file);
|
||||||
if (flen < 0) {
|
if (flen < 0) {
|
||||||
flen = 0;
|
flen = 0;
|
||||||
} else if (flen > 64000 - 1) {
|
}
|
||||||
flen = 64000 - 1;
|
|
||||||
|
if (flen > MAX_STATUS_SIZE) {
|
||||||
|
usable_len = MAX_STATUS_SIZE;
|
||||||
|
} else {
|
||||||
|
usable_len = flen;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* allocate buffer for the string, and
|
/* allocate buffer for the string, and
|
||||||
read the contents of the temporary file */
|
read the contents of the temporary file */
|
||||||
|
|
||||||
if (!(str = my_malloc(flen + 1, MYF(0))))
|
if (!(str = my_malloc(usable_len + 1, MYF(0))))
|
||||||
{
|
{
|
||||||
mutex_exit_noninline(&srv_monitor_file_mutex);
|
mutex_exit_noninline(&srv_monitor_file_mutex);
|
||||||
DBUG_RETURN(-1);
|
DBUG_RETURN(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
rewind(srv_monitor_file);
|
rewind(srv_monitor_file);
|
||||||
flen = fread(str, 1, flen, srv_monitor_file);
|
if (flen < MAX_STATUS_SIZE) {
|
||||||
|
/* Display the entire output. */
|
||||||
|
flen = fread(str, 1, flen, srv_monitor_file);
|
||||||
|
} else if (trx_list_end < (ulint) flen
|
||||||
|
&& trx_list_start < trx_list_end
|
||||||
|
&& trx_list_start + (flen - trx_list_end)
|
||||||
|
< MAX_STATUS_SIZE - sizeof truncated_msg - 1) {
|
||||||
|
/* Omit the beginning of the list of active transactions. */
|
||||||
|
long len = fread(str, 1, trx_list_start, srv_monitor_file);
|
||||||
|
memcpy(str + len, truncated_msg, sizeof truncated_msg - 1);
|
||||||
|
len += sizeof truncated_msg - 1;
|
||||||
|
usable_len = (MAX_STATUS_SIZE - 1) - len;
|
||||||
|
fseek(srv_monitor_file, flen - usable_len, SEEK_SET);
|
||||||
|
len += fread(str + len, 1, usable_len, srv_monitor_file);
|
||||||
|
flen = len;
|
||||||
|
} else {
|
||||||
|
/* Omit the end of the output. */
|
||||||
|
flen = fread(str, 1, MAX_STATUS_SIZE - 1, srv_monitor_file);
|
||||||
|
}
|
||||||
|
|
||||||
mutex_exit_noninline(&srv_monitor_file_mutex);
|
mutex_exit_noninline(&srv_monitor_file_mutex);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user