Commit 51fbf760 authored by marko's avatar marko

branches/zip: Remove the buf_block_align() calls from ha0ha.c that caused

an assertion failure in debug builds when a context switch occurred in
buf_LRU_search_and_free_block() before the call to
btr_search_drop_page_hash_index() managed to acquire the mutexes again.

ha_node_t: Add the field buf_block_t* block.

ha_search_and_update_if_found(): Rename to ha_search_and_update_if_found_func()
with added buf_block_t* parameter in debug builds.  Define the wrapper macro
ha_search_and_update_if_found() that always takes the buf_block_t* parameter.

ha_insert_for_fold(): Rename to ha_insert_for_fold_func()
with added buf_block_t* parameter in debug builds.  Define the wrapper macro
ha_insert_for_fold() that always takes the buf_block_t* parameter.
parent bfd7087b
......@@ -441,7 +441,8 @@ btr_search_update_hash_ref(
ut_ad(rw_lock_own(&btr_search_latch, RW_LOCK_EX));
#endif /* UNIV_SYNC_DEBUG */
ha_insert_for_fold(btr_search_sys->hash_index, fold, rec);
ha_insert_for_fold(btr_search_sys->hash_index, fold,
block, rec);
}
}
......@@ -1273,7 +1274,7 @@ btr_search_build_page_hash_index(
for (i = 0; i < n_cached; i++) {
ha_insert_for_fold(table, folds[i], recs[i]);
ha_insert_for_fold(table, folds[i], block, recs[i]);
}
exit_func:
......@@ -1442,7 +1443,7 @@ btr_search_update_hash_node_on_insert(
table = btr_search_sys->hash_index;
ha_search_and_update_if_found(table, cursor->fold, rec,
page_rec_get_next(rec));
block, page_rec_get_next(rec));
rw_lock_x_unlock(&btr_search_latch);
} else {
......@@ -1531,7 +1532,7 @@ btr_search_update_hash_on_insert(
locked = TRUE;
ha_insert_for_fold(table, ins_fold, ins_rec);
ha_insert_for_fold(table, ins_fold, block, ins_rec);
}
goto check_next_rec;
......@@ -1547,9 +1548,9 @@ btr_search_update_hash_on_insert(
}
if (!left_side) {
ha_insert_for_fold(table, fold, rec);
ha_insert_for_fold(table, fold, block, rec);
} else {
ha_insert_for_fold(table, ins_fold, ins_rec);
ha_insert_for_fold(table, ins_fold, block, ins_rec);
}
}
......@@ -1564,7 +1565,7 @@ btr_search_update_hash_on_insert(
locked = TRUE;
}
ha_insert_for_fold(table, ins_fold, ins_rec);
ha_insert_for_fold(table, ins_fold, block, ins_rec);
}
goto function_exit;
......@@ -1581,14 +1582,14 @@ btr_search_update_hash_on_insert(
if (!left_side) {
ha_insert_for_fold(table, ins_fold, ins_rec);
ha_insert_for_fold(table, ins_fold, block, ins_rec);
/*
fputs("Hash insert for ", stderr);
dict_index_name_print(stderr, cursor->index);
fprintf(stderr, " fold %lu\n", ins_fold);
*/
} else {
ha_insert_for_fold(table, next_fold, next_rec);
ha_insert_for_fold(table, next_fold, block, next_rec);
}
}
......
......@@ -66,8 +66,8 @@ is found, its node is updated to point to the new data, and no new node
is inserted. */
ibool
ha_insert_for_fold(
/*===============*/
ha_insert_for_fold_func(
/*====================*/
/* out: TRUE if succeed, FALSE if no more
memory could be allocated */
hash_table_t* table, /* in: hash table */
......@@ -75,17 +75,18 @@ ha_insert_for_fold(
the same fold value already exists, it is
updated to point to the same data, and no new
node is created! */
#ifdef UNIV_DEBUG
buf_block_t* block, /* in: buffer block containing the data */
#endif /* UNIV_DEBUG */
void* data) /* in: data, must not be NULL */
{
hash_cell_t* cell;
ha_node_t* node;
ha_node_t* prev_node;
#ifdef UNIV_DEBUG
buf_block_t* prev_block;
#endif /* UNIV_DEBUG */
ulint hash;
ut_ad(table && data);
ut_ad(block->frame == page_align(data));
#ifdef UNIV_SYNC_DEBUG
ut_ad(!table->mutexes || mutex_own(hash_get_mutex(table, fold)));
#endif /* UNIV_SYNC_DEBUG */
......@@ -99,12 +100,10 @@ ha_insert_for_fold(
if (prev_node->fold == fold) {
#ifdef UNIV_DEBUG
if (table->adaptive) {
mutex_enter(&buf_pool->mutex);
prev_block = buf_block_align(prev_node->data);
buf_block_t* prev_block = prev_node->block;
ut_a(prev_block->n_pointers > 0);
prev_block->n_pointers--;
buf_block_align(data)->n_pointers++;
mutex_exit(&buf_pool->mutex);
block->n_pointers++;
}
#endif /* UNIV_DEBUG */
prev_node->data = data;
......@@ -128,13 +127,15 @@ ha_insert_for_fold(
return(FALSE);
}
ha_node_set_data(node, data);
ha_node_set_data(node,
#ifdef UNIV_DEBUG
block,
#endif /* UNIV_DEBUG */
data);
#ifdef UNIV_DEBUG
if (table->adaptive) {
mutex_enter(&buf_pool->mutex);
buf_block_align(data)->n_pointers++;
mutex_exit(&buf_pool->mutex);
block->n_pointers++;
}
#endif /* UNIV_DEBUG */
node->fold = fold;
......@@ -211,11 +212,14 @@ Looks for an element when we know the pointer to the data, and updates
the pointer to data, if found. */
void
ha_search_and_update_if_found(
/*==========================*/
ha_search_and_update_if_found_func(
/*===============================*/
hash_table_t* table, /* in: hash table */
ulint fold, /* in: folded value of the searched data */
void* data, /* in: pointer to the data */
#ifdef UNIV_DEBUG
buf_block_t* new_block,/* in: block containing new_data */
#endif
void* new_data)/* in: new pointer to the data */
{
ha_node_t* node;
......@@ -223,17 +227,16 @@ ha_search_and_update_if_found(
#ifdef UNIV_SYNC_DEBUG
ut_ad(!table->mutexes || mutex_own(hash_get_mutex(table, fold)));
#endif /* UNIV_SYNC_DEBUG */
ut_ad(new_block->frame == page_align(new_data));
node = ha_search_with_data(table, fold, data);
if (node) {
#ifdef UNIV_DEBUG
if (table->adaptive) {
mutex_enter(&buf_pool->mutex);
ut_a(buf_block_align(node->data)->n_pointers > 0);
buf_block_align(node->data)->n_pointers--;
buf_block_align(new_data)->n_pointers++;
mutex_exit(&buf_pool->mutex);
ut_a(node->block->n_pointers > 0);
node->block->n_pointers--;
new_block->n_pointers++;
}
#endif /* UNIV_DEBUG */
node->data = new_data;
......
......@@ -31,12 +31,23 @@ Looks for an element when we know the pointer to the data and updates
the pointer to data if found. */
void
ha_search_and_update_if_found(
/*==========================*/
ha_search_and_update_if_found_func(
/*===============================*/
hash_table_t* table, /* in: hash table */
ulint fold, /* in: folded value of the searched data */
void* data, /* in: pointer to the data */
#ifdef UNIV_DEBUG
buf_block_t* new_block,/* in: block containing new_data */
#endif
void* new_data);/* in: new pointer to the data */
#ifdef UNIV_DEBUG
# define ha_search_and_update_if_found(table,fold,data,new_block,new_data) \
ha_search_and_update_if_found_func(table,fold,data,new_block,new_data)
#else
# define ha_search_and_update_if_found(table,fold,data,new_block,new_data) \
ha_search_and_update_if_found_func(table,fold,data,new_data)
#endif
/*****************************************************************
Creates a hash table with >= n array cells. The actual number of cells is
chosen to be a prime number slightly bigger than n. */
......@@ -56,8 +67,8 @@ is found, its node is updated to point to the new data, and no new node
is inserted. */
ibool
ha_insert_for_fold(
/*===============*/
ha_insert_for_fold_func(
/*====================*/
/* out: TRUE if succeed, FALSE if no more
memory could be allocated */
hash_table_t* table, /* in: hash table */
......@@ -65,7 +76,17 @@ ha_insert_for_fold(
the same fold value already exists, it is
updated to point to the same data, and no new
node is created! */
#ifdef UNIV_DEBUG
buf_block_t* block, /* in: buffer block containing the data */
#endif /* UNIV_DEBUG */
void* data); /* in: data, must not be NULL */
#ifdef UNIV_DEBUG
# define ha_insert_for_fold(t,f,b,d) ha_insert_for_fold_func(t,f,b,d)
#else
# define ha_insert_for_fold(t,f,b,d) ha_insert_for_fold_func(t,f,d)
#endif
/*****************************************************************
Deletes an entry from a hash table. */
......@@ -123,9 +144,10 @@ ha_print_info(
typedef struct ha_node_struct ha_node_t;
struct ha_node_struct {
ha_node_t* next; /* next chain node or NULL if none */
void* data; /* pointer to the data */
ulint fold; /* fold value for the data */
ha_node_t* next; /* next chain node or NULL if none */
buf_block_t* block; /* buffer block containing the data, or NULL */
void* data; /* pointer to the data */
ulint fold; /* fold value for the data */
};
#ifndef UNIV_NONINL
......
......@@ -38,8 +38,14 @@ void
ha_node_set_data(
/*=============*/
ha_node_t* node, /* in: hash chain node */
#ifdef UNIV_DEBUG
buf_block_t* block, /* in: buffer block containing the data */
#endif /* UNIV_DEBUG */
void* data) /* in: pointer to the data */
{
#ifdef UNIV_DEBUG
node->block = block;
#endif /* UNIV_DEBUG */
node->data = data;
}
......
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