~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/dict/dict0dict.c

  • Committer: Stewart Smith
  • Author(s): Vasil Dimov
  • Date: 2010-11-17 05:01:55 UTC
  • mto: (2021.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1971.
  • Revision ID: stewart@flamingspork.com-20101117050155-yj8coqr9wa9yvhd8
Merge Revision revid:vasil.dimov@oracle.com-20100622163043-dc0lxy0byg74viet from MySQL InnoDB

Original revid:vasil.dimov@oracle.com-20100622163043-dc0lxy0byg74viet

Original Authors: Vasil Dimov <vasil.dimov@oracle.com>
Original commit 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)

Show diffs side-by-side

added added

removed removed

Lines of Context:
863
863
        /* Add table to LRU list of tables */
864
864
        UT_LIST_ADD_FIRST(table_LRU, dict_sys->table_LRU, table);
865
865
 
866
 
        dict_sys->size += mem_heap_get_size(table->heap);
 
866
        dict_sys->size += mem_heap_get_size(table->heap)
 
867
                + strlen(table->name) + 1;
867
868
}
868
869
 
869
870
/**********************************************************************//**
917
918
        dict_foreign_t* foreign;
918
919
        dict_index_t*   index;
919
920
        ulint           fold;
920
 
        ulint           old_size;
921
 
        const char*     old_name;
 
921
        char            old_name[MAX_TABLE_NAME_LEN + 1];
922
922
 
923
923
        ut_ad(table);
924
924
        ut_ad(mutex_own(&(dict_sys->mutex)));
925
925
 
926
 
        old_size = mem_heap_get_size(table->heap);
927
 
        old_name = table->name;
 
926
        /* store the old/current name to an automatic variable */
 
927
        if (strlen(table->name) + 1 <= sizeof(old_name)) {
 
928
                memcpy(old_name, table->name, strlen(table->name) + 1);
 
929
        } else {
 
930
                ut_print_timestamp(stderr);
 
931
                fprintf(stderr, "InnoDB: too long table name: '%s', "
 
932
                        "max length is %d\n", table->name,
 
933
                        MAX_TABLE_NAME_LEN);
 
934
                ut_error;
 
935
        }
928
936
 
929
937
        fold = ut_fold_string(new_name);
930
938
 
970
978
        /* Remove table from the hash tables of tables */
971
979
        HASH_DELETE(dict_table_t, name_hash, dict_sys->table_hash,
972
980
                    ut_fold_string(old_name), table);
973
 
        table->name = mem_heap_strdup(table->heap, new_name);
 
981
 
 
982
        if (strlen(new_name) > strlen(table->name)) {
 
983
                /* We allocate MAX_TABLE_NAME_LEN+1 bytes here to avoid
 
984
                memory fragmentation, we assume a repeated calls of
 
985
                ut_realloc() with the same size do not cause fragmentation */
 
986
                ut_a(strlen(new_name) <= MAX_TABLE_NAME_LEN);
 
987
                table->name = ut_realloc(table->name, MAX_TABLE_NAME_LEN + 1);
 
988
        }
 
989
        memcpy(table->name, new_name, strlen(new_name) + 1);
974
990
 
975
991
        /* Add table to hash table of tables */
976
992
        HASH_INSERT(dict_table_t, name_hash, dict_sys->table_hash, fold,
977
993
                    table);
978
 
        dict_sys->size += (mem_heap_get_size(table->heap) - old_size);
 
994
 
 
995
        dict_sys->size += strlen(new_name) - strlen(old_name);
 
996
        ut_a(dict_sys->size > 0);
979
997
 
980
998
        /* Update the table_name field in indexes */
981
999
        index = dict_table_get_first_index(table);
1200
1218
        /* Remove table from LRU list of tables */
1201
1219
        UT_LIST_REMOVE(table_LRU, dict_sys->table_LRU, table);
1202
1220
 
1203
 
        size = mem_heap_get_size(table->heap);
 
1221
        size = mem_heap_get_size(table->heap) + strlen(table->name) + 1;
1204
1222
 
1205
1223
        ut_ad(dict_sys->size >= size);
1206
1224