Commit 8cf6771b authored by mmakela's avatar mmakela

branches/innodb+: Add debug assertions to track down Bug #52360.

hash_table_t::magic_n: Add HASH_TABLE_MAGIC_N checks, which were fully absent.
ut_hash_ulint(): Assert table_size > 0 before division.
parent d08cd430
...@@ -101,6 +101,8 @@ ha_clear( ...@@ -101,6 +101,8 @@ ha_clear(
ulint i; ulint i;
ulint n; ulint n;
ut_ad(table);
ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
#ifdef UNIV_SYNC_DEBUG #ifdef UNIV_SYNC_DEBUG
ut_ad(rw_lock_own(&btr_search_latch, RW_LOCK_EXCLUSIVE)); ut_ad(rw_lock_own(&btr_search_latch, RW_LOCK_EXCLUSIVE));
#endif /* UNIV_SYNC_DEBUG */ #endif /* UNIV_SYNC_DEBUG */
...@@ -146,7 +148,9 @@ ha_insert_for_fold_func( ...@@ -146,7 +148,9 @@ ha_insert_for_fold_func(
ha_node_t* prev_node; ha_node_t* prev_node;
ulint hash; ulint hash;
ut_ad(table && data); ut_ad(data);
ut_ad(table);
ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG #if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
ut_a(block->frame == page_align(data)); ut_a(block->frame == page_align(data));
#endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */ #endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
...@@ -237,6 +241,8 @@ ha_delete_hash_node( ...@@ -237,6 +241,8 @@ ha_delete_hash_node(
hash_table_t* table, /*!< in: hash table */ hash_table_t* table, /*!< in: hash table */
ha_node_t* del_node) /*!< in: node to be deleted */ ha_node_t* del_node) /*!< in: node to be deleted */
{ {
ut_ad(table);
ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG #if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
# ifndef UNIV_HOTBACKUP # ifndef UNIV_HOTBACKUP
if (table->adaptive) { if (table->adaptive) {
...@@ -267,6 +273,8 @@ ha_search_and_update_if_found_func( ...@@ -267,6 +273,8 @@ ha_search_and_update_if_found_func(
{ {
ha_node_t* node; ha_node_t* node;
ut_ad(table);
ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
ASSERT_HASH_MUTEX_OWN(table, fold); ASSERT_HASH_MUTEX_OWN(table, fold);
#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG #if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
ut_a(new_block->frame == page_align(new_data)); ut_a(new_block->frame == page_align(new_data));
...@@ -304,6 +312,8 @@ ha_remove_all_nodes_to_page( ...@@ -304,6 +312,8 @@ ha_remove_all_nodes_to_page(
{ {
ha_node_t* node; ha_node_t* node;
ut_ad(table);
ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
ASSERT_HASH_MUTEX_OWN(table, fold); ASSERT_HASH_MUTEX_OWN(table, fold);
node = ha_chain_get_first(table, fold); node = ha_chain_get_first(table, fold);
...@@ -353,6 +363,8 @@ ha_validate( ...@@ -353,6 +363,8 @@ ha_validate(
ibool ok = TRUE; ibool ok = TRUE;
ulint i; ulint i;
ut_ad(table);
ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
ut_a(start_index <= end_index); ut_a(start_index <= end_index);
ut_a(start_index < hash_get_n_cells(table)); ut_a(start_index < hash_get_n_cells(table));
ut_a(end_index < hash_get_n_cells(table)); ut_a(end_index < hash_get_n_cells(table));
...@@ -391,6 +403,8 @@ ha_print_info( ...@@ -391,6 +403,8 @@ ha_print_info(
FILE* file, /*!< in: file where to print */ FILE* file, /*!< in: file where to print */
hash_table_t* table) /*!< in: hash table */ hash_table_t* table) /*!< in: hash table */
{ {
ut_ad(table);
ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
#ifdef UNIV_DEBUG #ifdef UNIV_DEBUG
/* Some of the code here is disabled for performance reasons in production /* Some of the code here is disabled for performance reasons in production
builds, see http://bugs.mysql.com/36941 */ builds, see http://bugs.mysql.com/36941 */
......
...@@ -124,7 +124,7 @@ hash_create( ...@@ -124,7 +124,7 @@ hash_create(
table->heaps = NULL; table->heaps = NULL;
#endif /* !UNIV_HOTBACKUP */ #endif /* !UNIV_HOTBACKUP */
table->heap = NULL; table->heap = NULL;
table->magic_n = HASH_TABLE_MAGIC_N; ut_d(table->magic_n = HASH_TABLE_MAGIC_N);
/* Initialize the cell array */ /* Initialize the cell array */
hash_table_clear(table); hash_table_clear(table);
...@@ -140,6 +140,8 @@ hash_table_free( ...@@ -140,6 +140,8 @@ hash_table_free(
/*============*/ /*============*/
hash_table_t* table) /*!< in, own: hash table */ hash_table_t* table) /*!< in, own: hash table */
{ {
ut_ad(table);
ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
#ifndef UNIV_HOTBACKUP #ifndef UNIV_HOTBACKUP
ut_a(table->mutexes == NULL); ut_a(table->mutexes == NULL);
#endif /* !UNIV_HOTBACKUP */ #endif /* !UNIV_HOTBACKUP */
...@@ -165,6 +167,8 @@ hash_create_mutexes_func( ...@@ -165,6 +167,8 @@ hash_create_mutexes_func(
{ {
ulint i; ulint i;
ut_ad(table);
ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
ut_a(n_mutexes > 0); ut_a(n_mutexes > 0);
ut_a(ut_is_2pow(n_mutexes)); ut_a(ut_is_2pow(n_mutexes));
......
...@@ -434,11 +434,12 @@ struct hash_table_struct { ...@@ -434,11 +434,12 @@ struct hash_table_struct {
these heaps */ these heaps */
#endif /* !UNIV_HOTBACKUP */ #endif /* !UNIV_HOTBACKUP */
mem_heap_t* heap; mem_heap_t* heap;
#ifdef UNIV_DEBUG
ulint magic_n; ulint magic_n;
# define HASH_TABLE_MAGIC_N 76561114
#endif /* UNIV_DEBUG */
}; };
#define HASH_TABLE_MAGIC_N 76561114
#ifndef UNIV_NONINL #ifndef UNIV_NONINL
#include "hash0hash.ic" #include "hash0hash.ic"
#endif #endif
......
...@@ -35,6 +35,8 @@ hash_get_nth_cell( ...@@ -35,6 +35,8 @@ hash_get_nth_cell(
hash_table_t* table, /*!< in: hash table */ hash_table_t* table, /*!< in: hash table */
ulint n) /*!< in: cell index */ ulint n) /*!< in: cell index */
{ {
ut_ad(table);
ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
ut_ad(n < table->n_cells); ut_ad(n < table->n_cells);
return(table->array + n); return(table->array + n);
...@@ -48,6 +50,8 @@ hash_table_clear( ...@@ -48,6 +50,8 @@ hash_table_clear(
/*=============*/ /*=============*/
hash_table_t* table) /*!< in/out: hash table */ hash_table_t* table) /*!< in/out: hash table */
{ {
ut_ad(table);
ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
memset(table->array, 0x0, memset(table->array, 0x0,
table->n_cells * sizeof(*table->array)); table->n_cells * sizeof(*table->array));
} }
...@@ -61,6 +65,8 @@ hash_get_n_cells( ...@@ -61,6 +65,8 @@ hash_get_n_cells(
/*=============*/ /*=============*/
hash_table_t* table) /*!< in: table */ hash_table_t* table) /*!< in: table */
{ {
ut_ad(table);
ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
return(table->n_cells); return(table->n_cells);
} }
...@@ -74,6 +80,8 @@ hash_calc_hash( ...@@ -74,6 +80,8 @@ hash_calc_hash(
ulint fold, /*!< in: folded value */ ulint fold, /*!< in: folded value */
hash_table_t* table) /*!< in: hash table */ hash_table_t* table) /*!< in: hash table */
{ {
ut_ad(table);
ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
return(ut_hash_ulint(fold, table->n_cells)); return(ut_hash_ulint(fold, table->n_cells));
} }
...@@ -88,6 +96,8 @@ hash_get_mutex_no( ...@@ -88,6 +96,8 @@ hash_get_mutex_no(
hash_table_t* table, /*!< in: hash table */ hash_table_t* table, /*!< in: hash table */
ulint fold) /*!< in: fold */ ulint fold) /*!< in: fold */
{ {
ut_ad(table);
ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
ut_ad(ut_is_2pow(table->n_mutexes)); ut_ad(ut_is_2pow(table->n_mutexes));
return(ut_2pow_remainder(hash_calc_hash(fold, table), return(ut_2pow_remainder(hash_calc_hash(fold, table),
table->n_mutexes)); table->n_mutexes));
...@@ -103,6 +113,8 @@ hash_get_nth_heap( ...@@ -103,6 +113,8 @@ hash_get_nth_heap(
hash_table_t* table, /*!< in: hash table */ hash_table_t* table, /*!< in: hash table */
ulint i) /*!< in: index of the heap */ ulint i) /*!< in: index of the heap */
{ {
ut_ad(table);
ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
ut_ad(i < table->n_mutexes); ut_ad(i < table->n_mutexes);
return(table->heaps[i]); return(table->heaps[i]);
...@@ -120,6 +132,9 @@ hash_get_heap( ...@@ -120,6 +132,9 @@ hash_get_heap(
{ {
ulint i; ulint i;
ut_ad(table);
ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
if (table->heap) { if (table->heap) {
return(table->heap); return(table->heap);
} }
...@@ -139,6 +154,8 @@ hash_get_nth_mutex( ...@@ -139,6 +154,8 @@ hash_get_nth_mutex(
hash_table_t* table, /*!< in: hash table */ hash_table_t* table, /*!< in: hash table */
ulint i) /*!< in: index of the mutex */ ulint i) /*!< in: index of the mutex */
{ {
ut_ad(table);
ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
ut_ad(i < table->n_mutexes); ut_ad(i < table->n_mutexes);
return(table->mutexes + i); return(table->mutexes + i);
...@@ -156,6 +173,9 @@ hash_get_mutex( ...@@ -156,6 +173,9 @@ hash_get_mutex(
{ {
ulint i; ulint i;
ut_ad(table);
ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
i = hash_get_mutex_no(table, fold); i = hash_get_mutex_no(table, fold);
return(hash_get_nth_mutex(table, i)); return(hash_get_nth_mutex(table, i));
......
...@@ -152,6 +152,7 @@ ut_hash_ulint( ...@@ -152,6 +152,7 @@ ut_hash_ulint(
ulint key, /*!< in: value to be hashed */ ulint key, /*!< in: value to be hashed */
ulint table_size) /*!< in: hash table size */ ulint table_size) /*!< in: hash table size */
{ {
ut_ad(table_size);
key = key ^ UT_HASH_RANDOM_MASK2; key = key ^ UT_HASH_RANDOM_MASK2;
return(key % table_size); return(key % table_size);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment