Skip to content

Commit 187958a

Browse files
author
Sergey Vojtovich
committed
Backport from 6.0-codebase.
WL#3951 - MyISAM: Additional Error Logs for Data Corruption When table corruption is detected, in addition to current error message provide following information: - list of threads (and queries) accessing a table; - thread_id of a thread that detected corruption; - source file name and line number where this corruption was detected; - optional extra information (string).
1 parent bd64678 commit 187958a

18 files changed

+98
-3
lines changed

mysql-test/r/myisam_crash_before_flush_keys.result

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#
44
# Don't test this under valgrind, memory leaks will occur
55
# Binary must be compiled with debug for crash to occur
6+
call mtr.add_suppression("Got an error from thread_id=.*ha_myisam.cc:");
7+
call mtr.add_suppression("MySQL thread id .*, query id .* localhost.*root Checking table");
68
SET GLOBAL delay_key_write=ALL;
79
CREATE TABLE t1(a INT,
810
b INT,

mysql-test/t/myisam_crash_before_flush_keys.test

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
--echo # Binary must be compiled with debug for crash to occur
99
--source include/have_debug.inc
1010

11+
call mtr.add_suppression("Got an error from thread_id=.*ha_myisam.cc:");
12+
call mtr.add_suppression("MySQL thread id .*, query id .* localhost.*root Checking table");
13+
1114
let $MYSQLD_DATADIR= `select @@datadir`;
1215
SET GLOBAL delay_key_write=ALL;
1316
CREATE TABLE t1(a INT,

storage/myisam/CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ SET(MYISAM_SOURCES ft_boolean_search.c ft_nlq_search.c ft_parser.c ft_static.c
2626
mi_rfirst.c mi_rlast.c mi_rnext.c mi_rnext_same.c mi_rprev.c mi_rrnd.c
2727
mi_rsame.c mi_rsamepos.c mi_scan.c mi_search.c mi_static.c mi_statrec.c
2828
mi_unique.c mi_update.c mi_write.c rt_index.c rt_key.c rt_mbr.c
29-
rt_split.c sort.c sp_key.c ft_eval.h myisamdef.h rt_index.h mi_rkey.c)
29+
rt_split.c sort.c sp_key.c ft_eval.h mi_extrafunc.h myisamdef.h
30+
rt_index.h mi_rkey.c)
3031

3132
MYSQL_STORAGE_ENGINE(MYISAM)
3233

storage/myisam/Makefile.am

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ myisampack_LDADD= @CLIENT_EXTRA_LDFLAGS@ libmyisam.a \
5050
noinst_PROGRAMS = mi_test1 mi_test2 mi_test3 rt_test sp_test #ft_test1 ft_eval
5151
noinst_HEADERS = myisamdef.h rt_index.h rt_key.h rt_mbr.h sp_defs.h \
5252
fulltext.h ftdefs.h ft_test1.h ft_eval.h \
53-
ha_myisam.h
53+
ha_myisam.h mi_extrafunc.h
5454
mi_test1_DEPENDENCIES= $(LIBRARIES)
5555
mi_test1_LDADD= @CLIENT_EXTRA_LDFLAGS@ libmyisam.a \
5656
$(top_builddir)/mysys/libmysys.a \

storage/myisam/ha_myisam.cc

+40
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,45 @@ void mi_check_print_warning(MI_CHECK *param, const char *fmt,...)
539539
va_end(args);
540540
}
541541

542+
543+
/**
544+
Report list of threads (and queries) accessing a table, thread_id of a
545+
thread that detected corruption, ource file name and line number where
546+
this corruption was detected, optional extra information (string).
547+
548+
This function is intended to be used when table corruption is detected.
549+
550+
@param[in] file MI_INFO object.
551+
@param[in] message Optional error message.
552+
@param[in] sfile Name of source file.
553+
@param[in] sline Line number in source file.
554+
555+
@return void
556+
*/
557+
558+
void _mi_report_crashed(MI_INFO *file, const char *message,
559+
const char *sfile, uint sline)
560+
{
561+
THD *cur_thd;
562+
LIST *element;
563+
char buf[1024];
564+
pthread_mutex_lock(&file->s->intern_lock);
565+
if ((cur_thd= (THD*) file->in_use.data))
566+
sql_print_error("Got an error from thread_id=%lu, %s:%d", cur_thd->thread_id,
567+
sfile, sline);
568+
else
569+
sql_print_error("Got an error from unknown thread, %s:%d", sfile, sline);
570+
if (message)
571+
sql_print_error("%s", message);
572+
for (element= file->s->in_use; element; element= list_rest(element))
573+
{
574+
THD *thd= (THD*) element->data;
575+
sql_print_error("%s", thd ? thd_security_context(thd, buf, sizeof(buf), 0)
576+
: "Unknown thread accessing table");
577+
}
578+
pthread_mutex_unlock(&file->s->intern_lock);
579+
}
580+
542581
}
543582

544583

@@ -1894,6 +1933,7 @@ int ha_myisam::delete_table(const char *name)
18941933

18951934
int ha_myisam::external_lock(THD *thd, int lock_type)
18961935
{
1936+
file->in_use.data= thd;
18971937
return mi_lock_database(file, !table->s->tmp_table ?
18981938
lock_type : ((lock_type == F_UNLCK) ?
18991939
F_UNLCK : F_EXTRA_LCK));

storage/myisam/mi_extrafunc.h

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* Copyright (C) 2000-2006 MySQL AB
2+
3+
This program is free software; you can redistribute it and/or modify
4+
it under the terms of the GNU General Public License as published by
5+
the Free Software Foundation; version 2 of the License.
6+
7+
This program is distributed in the hope that it will be useful,
8+
but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
GNU General Public License for more details.
11+
12+
You should have received a copy of the GNU General Public License
13+
along with this program; if not, write to the Free Software
14+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
15+
16+
void _mi_report_crashed(MI_INFO *file __attribute__((unused)),
17+
const char *message __attribute__((unused)),
18+
const char *sfile __attribute__((unused)),
19+
uint sline __attribute__((unused)))
20+
{
21+
}

storage/myisam/mi_locking.c

+4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ int mi_lock_database(MI_INFO *info, int lock_type)
4545
++share->w_locks;
4646
++share->tot_locks;
4747
info->lock_type= lock_type;
48+
info->s->in_use= list_add(info->s->in_use, &info->in_use);
4849
DBUG_RETURN(0);
4950
}
5051

@@ -136,6 +137,7 @@ int mi_lock_database(MI_INFO *info, int lock_type)
136137
}
137138
info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED);
138139
info->lock_type= F_UNLCK;
140+
info->s->in_use= list_delete(info->s->in_use, &info->in_use);
139141
break;
140142
case F_RDLCK:
141143
if (info->lock_type == F_WRLCK)
@@ -182,6 +184,7 @@ int mi_lock_database(MI_INFO *info, int lock_type)
182184
share->r_locks++;
183185
share->tot_locks++;
184186
info->lock_type=lock_type;
187+
info->s->in_use= list_add(info->s->in_use, &info->in_use);
185188
break;
186189
case F_WRLCK:
187190
if (info->lock_type == F_RDLCK)
@@ -231,6 +234,7 @@ int mi_lock_database(MI_INFO *info, int lock_type)
231234
info->invalidator=info->s->invalidator;
232235
share->w_locks++;
233236
share->tot_locks++;
237+
info->s->in_use= list_add(info->s->in_use, &info->in_use);
234238
break;
235239
default:
236240
break; /* Impossible */

storage/myisam/mi_test1.c

+2
Original file line numberDiff line numberDiff line change
@@ -679,3 +679,5 @@ static void usage()
679679
my_print_help(my_long_options);
680680
my_print_variables(my_long_options);
681681
}
682+
683+
#include "mi_extrafunc.h"

storage/myisam/mi_test2.c

+2
Original file line numberDiff line numberDiff line change
@@ -1055,3 +1055,5 @@ static void copy_key(MI_INFO *info,uint inx,uchar *rec,uchar *key_buff)
10551055
}
10561056
return;
10571057
}
1058+
1059+
#include "mi_extrafunc.h"

storage/myisam/mi_test3.c

+2
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,8 @@ int test_update(MI_INFO *file,int id,int lock_type)
488488
return 0;
489489
}
490490

491+
#include "mi_extrafunc.h"
492+
491493
#else /* __NETWARE__ */
492494

493495
#include <stdio.h>

storage/myisam/myisam_ftdump.c

+2
Original file line numberDiff line numberDiff line change
@@ -274,3 +274,5 @@ static void complain(int val) /* Kinda assert :-) */
274274
exit(1);
275275
}
276276
}
277+
278+
#include "mi_extrafunc.h"

storage/myisam/myisamchk.c

+2
Original file line numberDiff line numberDiff line change
@@ -1815,3 +1815,5 @@ void mi_check_print_error(MI_CHECK *param, const char *fmt,...)
18151815
va_end(args);
18161816
DBUG_VOID_RETURN;
18171817
}
1818+
1819+
#include "mi_extrafunc.h"

storage/myisam/myisamdef.h

+6
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ typedef struct st_mi_isam_share { /* Shared between opens */
165165
MI_COLUMNDEF *rec; /* Pointer to field information */
166166
MI_PACK pack; /* Data about packed records */
167167
MI_BLOB *blobs; /* Pointer to blobs */
168+
LIST *in_use; /* List of threads using this table */
168169
char *unique_file_name; /* realpath() of index file */
169170
char *data_file_name, /* Resolved path names from symlinks */
170171
*index_file_name;
@@ -242,6 +243,7 @@ struct st_myisam_info {
242243
DYNAMIC_ARRAY *ft1_to_ft2; /* used only in ft1->ft2 conversion */
243244
MEM_ROOT ft_memroot; /* used by the parser */
244245
MYSQL_FTPARSER_PARAM *ftparser_param; /* share info between init/deinit */
246+
LIST in_use; /* Thread using this table */
245247
char *filename; /* parameter to open filename */
246248
uchar *buff, /* Temp area for key */
247249
*lastkey,*lastkey2; /* Last used search key */
@@ -385,8 +387,10 @@ typedef struct st_mi_sort_param
385387
#define mi_putint(x,y,nod) { uint16 boh=(nod ? (uint16) 32768 : 0) + (uint16) (y);\
386388
mi_int2store(x,boh); }
387389
#define mi_test_if_nod(x) (x[0] & 128 ? info->s->base.key_reflength : 0)
390+
#define mi_report_crashed(A, B) _mi_report_crashed((A), (B), __FILE__, __LINE__)
388391
#define mi_mark_crashed(x) do{(x)->s->state.changed|= STATE_CRASHED; \
389392
DBUG_PRINT("error", ("Marked table crashed")); \
393+
mi_report_crashed((x), 0); \
390394
}while(0)
391395
#define mi_mark_crashed_on_repair(x) do{(x)->s->state.changed|= \
392396
STATE_CRASHED|STATE_CRASHED_ON_REPAIR; \
@@ -764,6 +768,8 @@ int mi_open_keyfile(MYISAM_SHARE *share);
764768
void mi_setup_functions(register MYISAM_SHARE *share);
765769
my_bool mi_dynmap_file(MI_INFO *info, my_off_t size);
766770
void mi_remap_file(MI_INFO *info, my_off_t size);
771+
void _mi_report_crashed(MI_INFO *file, const char *message,
772+
const char *sfile, uint sline);
767773

768774
/* Functions needed by mi_check */
769775
volatile int *killed_ptr(MI_CHECK *param);

storage/myisam/myisamlog.c

+2
Original file line numberDiff line numberDiff line change
@@ -845,3 +845,5 @@ static my_bool cmp_filename(struct file_info *file_info, char * name)
845845
return 1;
846846
return strcmp(file_info->name,name) ? 1 : 0;
847847
}
848+
849+
#include "mi_extrafunc.h"

storage/myisam/myisampack.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -3201,4 +3201,4 @@ static int fakecmp(my_off_t **count1, my_off_t **count2)
32013201
}
32023202
#endif
32033203

3204-
3204+
#include "mi_extrafunc.h"

storage/myisam/rt_test.c

+2
Original file line numberDiff line numberDiff line change
@@ -468,3 +468,5 @@ int main(int argc __attribute__((unused)),char *argv[] __attribute__((unused)))
468468
exit(0);
469469
}
470470
#endif /*HAVE_RTREE_KEYS*/
471+
472+
#include "mi_extrafunc.h"

storage/myisam/sp_test.c

+1
Original file line numberDiff line numberDiff line change
@@ -562,3 +562,4 @@ int main(int argc __attribute__((unused)),char *argv[] __attribute__((unused)))
562562
}
563563
#endif /*HAVE_SPATIAL*/
564564

565+
#include "mi_extrafunc.h"

storage/myisammrg/ha_myisammrg.cc

+3
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,10 @@ int ha_myisammrg::extra_opt(enum ha_extra_function operation, ulong cache_size)
10091009

10101010
int ha_myisammrg::external_lock(THD *thd, int lock_type)
10111011
{
1012+
MYRG_TABLE *tmp;
10121013
DBUG_ASSERT(this->file->children_attached);
1014+
for (tmp= file->open_tables; tmp != file->end_table; tmp++)
1015+
tmp->table->in_use.data= thd;
10131016
return myrg_lock_database(file,lock_type);
10141017
}
10151018

0 commit comments

Comments
 (0)