3114 Vasil Dimov 2010-06-23
Merge Bug#47991 fix from mysql-5.1-innodb
------------------------------------------------------------
revno: 3517
revision-id: vasil.dimov@stripped043-dc0lxy0byg74viet
parent: marko.makela@oracle.com-20100621095148-8g73k8k68dpj080u
committer: Vasil Dimov <vasil.dimov@stripped>
branch nick: mysql-5.1-innodb
timestamp: Tue 2010-06-22 19:30:43 +0300
message:
Fix Bug#47991 InnoDB Dictionary Cache memory usage increases indefinitely
when renaming tables
Allocate the table name using ut_malloc() instead of table->heap because
the latter cannot be freed.
Adjust dict_sys->size calculations all over the code.
Change dict_table_t::name from const char* to char* because we need to
ut_malloc()/ut_free() it.
Reviewed by: Inaam, Marko, Heikki (rb://384)
Approved by: Heikki (rb://384)
------------------------------------------------------------
modified:
storage/innobase/dict/dict0dict.c
storage/innobase/dict/dict0mem.c
storage/innobase/include/dict0mem.h
storage/innobase/include/univ.i
storage/innobase/page/page0zip.c
storage/innobase/row/row0merge.c
3113 Marko Mäkelä 2010-06-22
Merge Bug#54686 fix from mysql-5.1-innodb:
------------------------------------------------------------
revno: 3517
revision-id: marko.makela@stripped375
parent: marko.makela@stripped8g73k8k68dpj080u
committer: Marko Mäkelä <marko.makela@stripped>
branch nick: 5.1-innodb
timestamp: Tue 2010-06-22 14:52:15 +0300
message:
Bug#54686 "field->col->mtype == type" assertion error at row/row0sel.c
ha_innobase::index_read(), ha_innobase::records_in_range(): Check that
the index is useable before invoking row_sel_convert_mysql_key_to_innobase().
This fix is based on a suggestion by Yasufumi Kinoshita.
modified:
storage/innobase/handler/ha_innodb.cc
=== modified file 'storage/innobase/dict/dict0dict.c'
--- a/storage/innobase/dict/dict0dict.c revid:marko.makela@stripped7l4uo5kw0fu6e
+++ b/storage/innobase/dict/dict0dict.c revid:vasil.dimov@stripped
@@ -864,7 +864,8 @@ dict_table_add_to_cache(
/* Add table to LRU list of tables */
UT_LIST_ADD_FIRST(table_LRU, dict_sys->table_LRU, table);
- dict_sys->size += mem_heap_get_size(table->heap);
+ dict_sys->size += mem_heap_get_size(table->heap)
+ + strlen(table->name) + 1;
}
/**********************************************************************//**
@@ -918,14 +919,21 @@ dict_table_rename_in_cache(
dict_foreign_t* foreign;
dict_index_t* index;
ulint fold;
- ulint old_size;
- const char* old_name;
+ char old_name[MAX_TABLE_NAME_LEN + 1];
ut_ad(table);
ut_ad(mutex_own(&(dict_sys->mutex)));
- old_size = mem_heap_get_size(table->heap);
- old_name = table->name;
+ /* store the old/current name to an automatic variable */
+ if (strlen(table->name) + 1 <= sizeof(old_name)) {
+ memcpy(old_name, table->name, strlen(table->name) + 1);
+ } else {
+ ut_print_timestamp(stderr);
+ fprintf(stderr, "InnoDB: too long table name: '%s', "
+ "max length is %d\n", table->name,
+ MAX_TABLE_NAME_LEN);
+ ut_error;
+ }
fold = ut_fold_string(new_name);
@@ -971,12 +979,22 @@ dict_table_rename_in_cache(
/* Remove table from the hash tables of tables */
HASH_DELETE(dict_table_t, name_hash, dict_sys->table_hash,
ut_fold_string(old_name), table);
- table->name = mem_heap_strdup(table->heap, new_name);
+
+ if (strlen(new_name) > strlen(table->name)) {
+ /* We allocate MAX_TABLE_NAME_LEN+1 bytes here to avoid
+ memory fragmentation, we assume a repeated calls of
+ ut_realloc() with the same size do not cause fragmentation */
+ ut_a(strlen(new_name) <= MAX_TABLE_NAME_LEN);
+ table->name = ut_realloc(table->name, MAX_TABLE_NAME_LEN + 1);
+ }
+ memcpy(table->name, new_name, strlen(new_name) + 1);
/* Add table to hash table of tables */
HASH_INSERT(dict_table_t, name_hash, dict_sys->table_hash, fold,
table);
- dict_sys->size += (mem_heap_get_size(table->heap) - old_size);
+
+ dict_sys->size += strlen(new_name) - strlen(old_name);
+ ut_a(dict_sys->size > 0);
/* Update the table_name field in indexes */
index = dict_table_get_first_index(table);
@@ -1201,7 +1219,7 @@ dict_table_remove_from_cache(
/* Remove table from LRU list of tables */
UT_LIST_REMOVE(table_LRU, dict_sys->table_LRU, table);
- size = mem_heap_get_size(table->heap);
+ size = mem_heap_get_size(table->heap) + strlen(table->name) + 1;
ut_ad(dict_sys->size >= size);
=== modified file 'storage/innobase/dict/dict0mem.c'
--- a/storage/innobase/dict/dict0mem.c revid:marko.makela@strippeduo5kw0fu6e
+++ b/storage/innobase/dict/dict0mem.c revid:vasil.dimov@stripped
@@ -73,7 +73,8 @@ dict_mem_table_create(
table->heap = heap;
table->flags = (unsigned int) flags;
- table->name = mem_heap_strdup(heap, name);
+ table->name = ut_malloc(strlen(name) + 1);
+ memcpy(table->name, name, strlen(name) + 1);
table->space = (unsigned int) space;
table->n_cols = (unsigned int) (n_cols + DATA_N_SYS_COLS);
@@ -112,6 +113,7 @@ dict_mem_table_free(
#ifndef UNIV_HOTBACKUP
mutex_free(&(table->autoinc_mutex));
#endif /* UNIV_HOTBACKUP */
+ ut_free(table->name);
mem_heap_free(table->heap);
}
=== modified file 'storage/innobase/include/dict0mem.h'
--- a/storage/innobase/include/dict0mem.h revid:marko.makela@stripped5kw0fu6e
+++ b/storage/innobase/include/dict0mem.h revid:vasil.dimov@stripped
@@ -416,7 +416,7 @@ initialized to 0, NULL or FALSE in dict_
struct dict_table_struct{
dulint id; /*!< id of the table */
mem_heap_t* heap; /*!< memory heap */
- const char* name; /*!< table name */
+ char* name; /*!< table name */
const char* dir_path_of_temp_table;/*!< NULL or the directory path
where a TEMPORARY table that was explicitly
created by a user should be placed if
=== modified file 'storage/innobase/include/univ.i'
--- a/storage/innobase/include/univ.i revid:marko.makela@oracle.com-20100622120533-yki7l4uo5kw0fu6e
+++ b/storage/innobase/include/univ.i revid:vasil.dimov@stripped71721-l8mend26quaybmwb
@@ -310,6 +310,12 @@ management to ensure correct alignment f
/* Maximum number of parallel threads in a parallelized operation */
#define UNIV_MAX_PARALLELISM 32
+/* The maximum length of a table name. This is the MySQL limit and is
+defined in mysql_com.h like NAME_CHAR_LEN*SYSTEM_CHARSET_MBMAXLEN, the
+number does not include a terminating '\0'. InnoDB probably can handle
+longer names internally */
+#define MAX_TABLE_NAME_LEN 192
+
/*
UNIVERSAL TYPE DEFINITIONS
==========================
=== modified file 'storage/innobase/page/page0zip.c'
--- a/storage/innobase/page/page0zip.c revid:marko.makela@strippedu6e
+++ b/storage/innobase/page/page0zip.c revid:vasil.dimov@stripped
@@ -1464,6 +1464,7 @@ page_zip_fields_free(
dict_table_t* table = index->table;
mem_heap_free(index->heap);
mutex_free(&(table->autoinc_mutex));
+ ut_free(table->name);
mem_heap_free(table->heap);
}
}
=== modified file 'storage/innobase/row/row0merge.c'
--- a/storage/innobase/row/row0merge.c revid:marko.makela@stripped33-yki7l4uo5kw0fu6e
+++ b/storage/innobase/row/row0merge.c revid:vasil.dimov@strippedybmwb
@@ -2357,7 +2357,7 @@ row_merge_rename_tables(
{
ulint err = DB_ERROR;
pars_info_t* info;
- const char* old_name= old_table->name;
+ char old_name[MAX_TABLE_NAME_LEN + 1];
ut_ad(trx->mysql_thread_id == os_thread_get_curr_id());
ut_ad(old_table != new_table);
@@ -2365,6 +2365,17 @@ row_merge_rename_tables(
ut_a(trx->dict_operation_lock_mode == RW_X_LATCH);
+ /* store the old/current name to an automatic variable */
+ if (strlen(old_table->name) + 1 <= sizeof(old_name)) {
+ memcpy(old_name, old_table->name, strlen(old_table->name) + 1);
+ } else {
+ ut_print_timestamp(stderr);
+ fprintf(stderr, "InnoDB: too long table name: '%s', "
+ "max length is %d\n", old_table->name,
+ MAX_TABLE_NAME_LEN);
+ ut_error;
+ }
+
trx->op_info = "renaming tables";
/* We use the private SQL parser of Innobase to generate the query
Attachment: [text/bzr-bundle] bzr/vasil.dimov@oracle.com-20100623071721-l8mend26quaybmwb.bundle
| Thread |
|---|
| • bzr push into mysql-trunk-innodb branch (vasil.dimov:3113 to 3114) Bug#47991 | vasil.dimov | 23 Jun |