diff options
author | unknown <marko@hundin.mysql.fi> | 2004-04-06 16:14:43 +0300 |
---|---|---|
committer | unknown <marko@hundin.mysql.fi> | 2004-04-06 16:14:43 +0300 |
commit | 80fe399fee3a7752aecdfc888edfcf56a2be7b0a (patch) | |
tree | f7bc427aa7ce4a54802d6e8931ca1dfe64c7bfa8 /sql/ha_innodb.cc | |
parent | d809c4413e9f991bde407690aafdaaa3eaae9232 (diff) | |
download | mariadb-git-80fe399fee3a7752aecdfc888edfcf56a2be7b0a.tar.gz |
InnoDB: send diagnostic output to stderr or files
instead of stdout or fixed-size memory buffers
innobase/btr/btr0btr.c:
Output to stderr; quote table and index names
innobase/btr/btr0cur.c:
Output to stderr; quote table and index names
innobase/btr/btr0sea.c:
Output to stderr
innobase/buf/buf0buf.c:
Output to stderr; quote table and index names
innobase/buf/buf0flu.c:
Output to stderr
innobase/buf/buf0lru.c:
Output to stderr
innobase/buf/buf0rea.c:
Output to stderr
innobase/data/data0data.c:
Remove dtuple_validate() unless #ifdef UNIV_DEBUG
Remove unnecessary sprintf() calls
Output to stderr
innobase/data/data0type.c:
Output to stderr
innobase/dict/dict0boot.c:
Remove dummy call to printf()
innobase/dict/dict0crea.c:
Output diagnostic information to stream, not to memory
innobase/dict/dict0dict.c:
Output diagnostics to a file, not to a memory buffer
innobase/dict/dict0load.c:
Output to stderr; quote table and index names
innobase/eval/eval0eval.c:
Output to stderr
innobase/fil/fil0fil.c:
Output to stderr
innobase/fsp/fsp0fsp.c:
Output to stderr
Avoid sprintf()
innobase/fut/fut0lst.c:
Output to stderr
innobase/ha/ha0ha.c:
Output to stream, not to memory buffer
innobase/ibuf/ibuf0ibuf.c:
Output to stderr
Avoid sprintf()
innobase/include/buf0buf.h:
Output to stream, not to memory buffer
innobase/include/buf0buf.ic:
Use %p for displaying pointers
innobase/include/data0data.h:
Remove dtuple_sprintf()
innobase/include/dict0dict.h:
Output to stream, not to memory buffer
innobase/include/ha0ha.h:
Output to stream, not to memory buffer
innobase/include/ibuf0ibuf.h:
Output to stream, not to memory buffer
innobase/include/lock0lock.h:
Output to stream, not to memory buffer
innobase/include/log0log.h:
Output to stream, not to memory buffer
innobase/include/mtr0log.ic:
Output to stderr
Display pointers with %p
innobase/include/os0file.h:
Output to stream, not to memory buffer
innobase/include/rem0rec.h:
Remove rec_sprintf()
innobase/include/rem0rec.ic:
Output to stderr
innobase/include/row0sel.ic:
Output to stderr
innobase/include/row0upd.ic:
Quote table and index names
innobase/include/srv0srv.h:
Remove srv_sprintf_innodb_monitor()
innobase/include/sync0arr.h:
Output to stream, not to memory buffer
innobase/include/sync0sync.h:
Output to stream, not to memory buffer
innobase/include/trx0sys.h:
Output to stderr
innobase/include/trx0trx.h:
Output to stream, not to memory buffer
innobase/include/ut0ut.h:
Remove ut_sprintf_buf()
Add ut_print_name(), ut_print_namel() and ut_copy_file()
innobase/lock/lock0lock.c:
Output to stream, not to memory buffer
innobase/log/log0log.c:
Output to stderr
innobase/log/log0recv.c:
Output to stderr
innobase/mem/mem0dbg.c:
Output to stderr
innobase/mtr/mtr0log.c:
Display pointers with %p
innobase/mtr/mtr0mtr.c:
Output to stderr
innobase/os/os0file.c:
Output to stream, not to memory buffer
innobase/os/os0proc.c:
Output to stderr
innobase/os/os0thread.c:
Output to stderr
innobase/page/page0cur.c:
Output to stderr
innobase/page/page0page.c:
Avoid sprintf()
Output to stderr instead of stdout
innobase/pars/pars0opt.c:
Output to stderr instead of stdout
innobase/rem/rem0rec.c:
Remove rec_sprintf()
Output to stderr instead of stdout
innobase/row/row0ins.c:
Output diagnostics to stream instead of memory buffer
innobase/row/row0mysql.c:
Output to stderr instead of stdout
Quote table and index names
innobase/row/row0purge.c:
Output to stderr instead of stdout
innobase/row/row0row.c:
Quote table and index names
innobase/row/row0sel.c:
Output to stderr instead of stdout
Quote table and index names
innobase/row/row0umod.c:
Avoid sprintf()
Quote table and index names
innobase/row/row0undo.c:
Output to stderr instead of stdout
innobase/row/row0upd.c:
Avoid sprintf()
innobase/srv/srv0srv.c:
Output to stderr instead of stdout
innobase/srv/srv0start.c:
Handle srv_monitor_file
Make some global variables static
innobase/sync/sync0arr.c:
Output to stderr instead of stdout
Output to stream instead of memory buffer
innobase/sync/sync0rw.c:
Output to stderr instead of stdout
innobase/sync/sync0sync.c:
Output to stderr instead of stdout
Output to stream instead of memory buffer
innobase/trx/trx0purge.c:
Output to stderr instead of stdout
innobase/trx/trx0rec.c:
Quote index and table names
Avoid sprintf()
innobase/trx/trx0roll.c:
Quote identifier names
Output to stderr instead of stdout
innobase/trx/trx0sys.c:
Output to stderr instead of stdout
innobase/trx/trx0trx.c:
Output to stream instead of memory buffer
innobase/trx/trx0undo.c:
Output to stderr instead of stdout
innobase/ut/ut0ut.c:
Declare mysql_get_identifier_quote_char()
Remove ut_sprintf_buf()
Add ut_print_name() and ut_print_namel()
Add ut_copy_file()
sql/ha_innodb.cc:
innobase_mysql_print_thd(): output to stream, not to memory buffer
Add mysql_get_identifier_quote_char()
Remove unused function innobase_print_error()
Display pointers with %p
Buffer InnoDB output via files, not via statically allocated memory
Diffstat (limited to 'sql/ha_innodb.cc')
-rw-r--r-- | sql/ha_innodb.cc | 292 |
1 files changed, 159 insertions, 133 deletions
diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc index ff249b9d251..759679d5bd6 100644 --- a/sql/ha_innodb.cc +++ b/sql/ha_innodb.cc @@ -309,70 +309,49 @@ convert_error_code_to_mysql( } } -extern "C" { /***************************************************************** Prints info of a THD object (== user session thread) to the standard output. NOTE that /mysql/innobase/trx/trx0trx.c must contain the prototype for this function! */ - +extern "C" void innobase_mysql_print_thd( /*=====================*/ - char* buf, /* in/out: buffer where to print, must be at least - 400 bytes */ + FILE* f, /* in: output stream */ void* input_thd)/* in: pointer to a MySQL THD object */ { THD* thd; - char* old_buf = buf; thd = (THD*) input_thd; - /* We cannot use the return value of normal sprintf() as this is - not portable to some old non-Posix Unixes, e.g., some old SCO - Unixes */ - - buf += my_sprintf(buf, - (buf, "MySQL thread id %lu, query id %lu", - thd->thread_id, thd->query_id)); - if (thd->host) { - *buf = ' '; - buf++; - buf = strnmov(buf, thd->host, 30); - } + fprintf(f, "MySQL thread id %lu, query id %lu", + thd->thread_id, thd->query_id); + if (thd->host) { + putc(' ', f); + fputs(thd->host, f); + } - if (thd->ip) { - *buf = ' '; - buf++; - buf=strnmov(buf, thd->ip, 20); - } + if (thd->ip) { + putc(' ', f); + fputs(thd->ip, f); + } if (thd->user) { - *buf = ' '; - buf++; - buf=strnmov(buf, thd->user, 20); - } - - if (thd->proc_info) { - *buf = ' '; - buf++; - buf=strnmov(buf, thd->proc_info, 50); + putc(' ', f); + fputs(thd->user, f); } - if (thd->query) { - *buf = '\n'; - buf++; - buf=strnmov(buf, thd->query, 150); - } - - buf[0] = '\n'; - buf[1] = '\0'; /* Note that we must put a null character here to end - the printed string */ + if (thd->proc_info) { + putc(' ', f); + fputs(thd->proc_info, f); + } - /* We test the printed length did not overrun the buffer length of - 400 bytes */ + if (thd->query) { + putc(' ', f); + fputs(thd->query, f); + } - ut_a(strlen(old_buf) < 400); -} + putc('\n', f); } /************************************************************************* @@ -605,12 +584,11 @@ innobase_query_caching_of_table_permitted( return((my_bool)FALSE); } -extern "C" { /********************************************************************* Invalidates the MySQL query cache for the table. NOTE that the exact prototype of this function has to be in /innobase/row/row0ins.c! */ - +extern "C" void innobase_invalidate_query_cache( /*============================*/ @@ -630,6 +608,17 @@ innobase_invalidate_query_cache( TRUE); #endif } + +/********************************************************************* +Get the quote character to be used in SQL identifiers. */ +extern "C" +char +mysql_get_identifier_quote_char(void) +/*=================================*/ + /* out: quote character to be + used in SQL identifiers */ +{ + return '`'; } /********************************************************************* @@ -1244,19 +1233,6 @@ innobase_close_connection( return(0); } -/********************************************************************** -Prints an error message. */ -static -void -innobase_print_error( -/*=================*/ - const char* db_errpfx, /* in: error prefix text */ - char* buffer) /* in: error text */ -{ - sql_print_error("%s: %s", db_errpfx, buffer); -} - - /***************************************************************************** ** InnoDB database tables *****************************************************************************/ @@ -2017,24 +1993,20 @@ ha_innobase::write_row( if (prebuilt->trx != (trx_t*) current_thd->transaction.all.innobase_tid) { - char err_buf[2000]; - fprintf(stderr, "InnoDB: Error: the transaction object for the table handle is at\n" -"InnoDB: %lx, but for the current thread it is at %lx\n", - (ulong)prebuilt->trx, - (ulong)current_thd->transaction.all.innobase_tid); - - ut_sprintf_buf(err_buf, ((byte*)prebuilt) - 100, 200); - fprintf(stderr, -"InnoDB: Dump of 200 bytes around prebuilt: %.1000s\n", err_buf); - - ut_sprintf_buf(err_buf, +"InnoDB: %p, but for the current thread it is at %p\n", + prebuilt->trx, + current_thd->transaction.all.innobase_tid); + fputs("InnoDB: Dump of 200 bytes around prebuilt: ", stderr); + ut_print_buf(stderr, ((const byte*)prebuilt) - 100, 200); + fputs("\n" + "InnoDB: Dump of 200 bytes around transaction.all: ", + stderr); + ut_print_buf(stderr, ((byte*)(&(current_thd->transaction.all))) - 100, 200); - fprintf(stderr, -"InnoDB: Dump of 200 bytes around transaction.all: %.1000s\n", err_buf); - - ut_a(0); + putc('\n', stderr); + ut_error; } statistic_increment(ha_write_count, &LOCK_status); @@ -4225,15 +4197,18 @@ ha_innobase::update_table_comment( info on foreign keys */ const char* comment)/* in: table comment defined by user */ { - row_prebuilt_t* prebuilt = (row_prebuilt_t*)innobase_prebuilt; - uint length = strlen(comment); - char* str = my_malloc(length + 16500, MYF(0)); - char* pos; + uint length = strlen(comment); + char* str; + row_prebuilt_t* prebuilt = (row_prebuilt_t*)innobase_prebuilt; /* We do not know if MySQL can call this function before calling external_lock(). To be safe, update the thd of the current table handle. */ + if(length > 64000 - 3) { + return((char*)comment); /* string too long */ + } + update_thd(current_thd); prebuilt->trx->op_info = (char*)"returning table comment"; @@ -4242,36 +4217,45 @@ ha_innobase::update_table_comment( possible adaptive hash latch to avoid deadlocks of threads */ trx_search_latch_release_if_reserved(prebuilt->trx); - - if (!str) { - prebuilt->trx->op_info = (char*)""; + str = NULL; + + if (FILE* file = tmpfile()) { + long flen; + + /* output the data to a temporary file */ + fprintf(file, "InnoDB free: %lu kB", + (ulong) innobase_get_free_space()); + dict_print_info_on_foreign_keys(FALSE, file, prebuilt->table); + flen = ftell(file); + if(length + flen + 3 > 64000) { + flen = 64000 - 3 - length; + } - return((char*)comment); - } + ut_ad(flen > 0); - pos = str; - if (length) { - pos=strmov(str, comment); - *pos++=';'; - *pos++=' '; - } + /* allocate buffer for the full string, and + read the contents of the temporary file */ - pos += my_sprintf(pos, - (pos,"InnoDB free: %lu kB", - (ulong) innobase_get_free_space())); + str = my_malloc(length + flen + 3, MYF(0)); - /* We assume 16000 - length bytes of space to print info; the limit - 16000 bytes is arbitrary, and MySQL could handle at least 64000 - bytes */ - - if (length < 16000) { - dict_print_info_on_foreign_keys(FALSE, pos, 16000 - length, - prebuilt->table); + if (str) { + char* pos = str + length; + if(length) { + memcpy(str, comment, length); + *pos++ = ';'; + *pos++ = ' '; + } + rewind(file); + flen = fread(pos, 1, flen, file); + pos[flen] = 0; + } + + fclose(file); } prebuilt->trx->op_info = (char*)""; - return(str); + return(str ? str : (char*) comment); } /*********************************************************************** @@ -4285,7 +4269,7 @@ ha_innobase::get_foreign_key_create_info(void) MUST be freed with ::free_foreign_key_create_info */ { row_prebuilt_t* prebuilt = (row_prebuilt_t*)innobase_prebuilt; - char* str; + char* str = 0; ut_a(prebuilt != NULL); @@ -4295,20 +4279,45 @@ ha_innobase::get_foreign_key_create_info(void) update_thd(current_thd); - prebuilt->trx->op_info = (char*)"getting info on foreign keys"; + if (FILE* file = tmpfile()) { + long flen; - /* In case MySQL calls this in the middle of a SELECT query, release - possible adaptive hash latch to avoid deadlocks of threads */ + prebuilt->trx->op_info = (char*)"getting info on foreign keys"; - trx_search_latch_release_if_reserved(prebuilt->trx); - - str = (char*)ut_malloc(10000); + /* In case MySQL calls this in the middle of a SELECT query, + release possible adaptive hash latch to avoid + deadlocks of threads */ - str[0] = '\0'; - - dict_print_info_on_foreign_keys(TRUE, str, 9000, prebuilt->table); + trx_search_latch_release_if_reserved(prebuilt->trx); - prebuilt->trx->op_info = (char*)""; + /* output the data to a temporary file */ + dict_print_info_on_foreign_keys(TRUE, file, prebuilt->table); + prebuilt->trx->op_info = (char*)""; + + flen = ftell(file); + if(flen > 64000 - 1) { + flen = 64000 - 1; + } + + ut_ad(flen >= 0); + + /* allocate buffer for the string, and + read the contents of the temporary file */ + + str = my_malloc(flen + 1, MYF(0)); + + if (str) { + rewind(file); + flen = fread(str, 1, flen, file); + str[flen] = 0; + } + + fclose(file); + } else { + /* unable to create temporary file */ + str = my_malloc(1, MYF(0)); + str[0] = 0; + } return(str); } @@ -4344,7 +4353,7 @@ ha_innobase::free_foreign_key_create_info( char* str) /* in, own: create info string to free */ { if (str) { - ut_free(str); + my_free(str, MYF(0)); } } @@ -4615,39 +4624,56 @@ innodb_show_status( innobase_release_stat_resources(trx); - /* We let the InnoDB Monitor to output at most 60 kB of text, add - a safety margin of 100 kB for buffer overruns */ + /* We let the InnoDB Monitor to output at most 64000 bytes of text. */ + + long flen; + char* str; + + mutex_enter(&srv_monitor_file_mutex); + rewind(srv_monitor_file); + srv_printf_innodb_monitor(srv_monitor_file); + flen = ftell(srv_monitor_file); + if(flen > 64000 - 1) { + flen = 64000 - 1; + } + + ut_ad(flen > 0); + + /* allocate buffer for the string, and + read the contents of the temporary file */ + + str = my_malloc(flen + 1, MYF(0)); + + if (str) { + rewind(srv_monitor_file); + flen = fread(str, 1, flen, srv_monitor_file); + str[flen] = 0; + } + + mutex_exit(&srv_monitor_file_mutex); - buf = (char*)ut_malloc(160 * 1024); - - srv_sprintf_innodb_monitor(buf, 60 * 1024); - List<Item> field_list; - field_list.push_back(new Item_empty_string("Status", strlen(buf))); + field_list.push_back(new Item_empty_string("Status", flen)); if (send_fields(thd, field_list, 1)) { - ut_free(buf); + my_free(str, MYF(0)); - DBUG_RETURN(-1); + DBUG_RETURN(-1); } - packet->length(0); - - net_store_data(packet, buf); - - if (my_net_write(&thd->net, (char*)thd->packet.ptr(), - packet->length())) { - ut_free(buf); - - DBUG_RETURN(-1); - } + packet->length(0); + net_store_data(packet, str); + my_free(str, MYF(0)); - ut_free(buf); + if (my_net_write(&thd->net, (char*)thd->packet.ptr(), + packet->length())) { - send_eof(&thd->net); + DBUG_RETURN(-1); + } + send_eof(&thd->net); DBUG_RETURN(0); } |