mirror of
https://github.com/MariaDB/server.git
synced 2025-01-22 06:44:16 +01:00
d25fa2c4d9
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.
201 lines
4.7 KiB
Text
201 lines
4.7 KiB
Text
/************************************************************************
|
|
The hash table with external chains
|
|
|
|
(c) 1994-1997 Innobase Oy
|
|
|
|
Created 8/18/1994 Heikki Tuuri
|
|
*************************************************************************/
|
|
|
|
#include "ut0rnd.h"
|
|
#include "mem0mem.h"
|
|
|
|
/***************************************************************
|
|
Deletes a hash node. */
|
|
|
|
void
|
|
ha_delete_hash_node(
|
|
/*================*/
|
|
hash_table_t* table, /* in: hash table */
|
|
buf_block_t* block, /* in: buffer block, or NULL */
|
|
ha_node_t* del_node); /* in: node to be deleted */
|
|
|
|
/**********************************************************************
|
|
Gets a hash node data. */
|
|
UNIV_INLINE
|
|
void*
|
|
ha_node_get_data(
|
|
/*=============*/
|
|
/* out: pointer to the data */
|
|
ha_node_t* node) /* in: hash chain node */
|
|
{
|
|
return(node->data);
|
|
}
|
|
|
|
/**********************************************************************
|
|
Sets hash node data. */
|
|
UNIV_INLINE
|
|
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;
|
|
}
|
|
|
|
/**********************************************************************
|
|
Gets the next node in a hash chain. */
|
|
UNIV_INLINE
|
|
ha_node_t*
|
|
ha_chain_get_next(
|
|
/*==============*/
|
|
/* out: next node, NULL if none */
|
|
ha_node_t* node) /* in: hash chain node */
|
|
{
|
|
return(node->next);
|
|
}
|
|
|
|
/**********************************************************************
|
|
Gets the first node in a hash chain. */
|
|
UNIV_INLINE
|
|
ha_node_t*
|
|
ha_chain_get_first(
|
|
/*===============*/
|
|
/* out: first node, NULL if none */
|
|
hash_table_t* table, /* in: hash table */
|
|
ulint fold) /* in: fold value determining the chain */
|
|
{
|
|
return(hash_get_nth_cell(table, hash_calc_hash(fold, table))->node);
|
|
}
|
|
|
|
/*****************************************************************
|
|
Looks for an element in a hash table. */
|
|
UNIV_INLINE
|
|
ha_node_t*
|
|
ha_search(
|
|
/*======*/
|
|
/* out: pointer to the first hash table node
|
|
in chain having the fold number, NULL if not
|
|
found */
|
|
hash_table_t* table, /* in: hash table */
|
|
ulint fold) /* in: folded value of the searched data */
|
|
{
|
|
ha_node_t* node;
|
|
|
|
#ifdef UNIV_SYNC_DEBUG
|
|
ut_ad(!table->mutexes || mutex_own(hash_get_mutex(table, fold)));
|
|
#endif /* UNIV_SYNC_DEBUG */
|
|
|
|
node = ha_chain_get_first(table, fold);
|
|
|
|
while (node) {
|
|
if (node->fold == fold) {
|
|
|
|
return(node);
|
|
}
|
|
|
|
node = ha_chain_get_next(node);
|
|
}
|
|
|
|
return(NULL);
|
|
}
|
|
|
|
/*****************************************************************
|
|
Looks for an element in a hash table. */
|
|
UNIV_INLINE
|
|
void*
|
|
ha_search_and_get_data(
|
|
/*===================*/
|
|
/* out: pointer to the data of the first hash
|
|
table node in chain having the fold number,
|
|
NULL if not found */
|
|
hash_table_t* table, /* in: hash table */
|
|
ulint fold) /* in: folded value of the searched data */
|
|
{
|
|
ha_node_t* node;
|
|
|
|
#ifdef UNIV_SYNC_DEBUG
|
|
ut_ad(!table->mutexes || mutex_own(hash_get_mutex(table, fold)));
|
|
#endif /* UNIV_SYNC_DEBUG */
|
|
|
|
node = ha_chain_get_first(table, fold);
|
|
|
|
while (node) {
|
|
if (node->fold == fold) {
|
|
|
|
return(node->data);
|
|
}
|
|
|
|
node = ha_chain_get_next(node);
|
|
}
|
|
|
|
return(NULL);
|
|
}
|
|
|
|
/*************************************************************
|
|
Looks for an element when we know the pointer to the data. */
|
|
UNIV_INLINE
|
|
ha_node_t*
|
|
ha_search_with_data(
|
|
/*================*/
|
|
/* out: pointer to the hash table node, NULL
|
|
if not found in the table */
|
|
hash_table_t* table, /* in: hash table */
|
|
ulint fold, /* in: folded value of the searched data */
|
|
void* data) /* in: pointer to the data */
|
|
{
|
|
ha_node_t* node;
|
|
|
|
#ifdef UNIV_SYNC_DEBUG
|
|
ut_ad(!table->mutexes || mutex_own(hash_get_mutex(table, fold)));
|
|
#endif /* UNIV_SYNC_DEBUG */
|
|
|
|
node = ha_chain_get_first(table, fold);
|
|
|
|
while (node) {
|
|
if (node->data == data) {
|
|
|
|
return(node);
|
|
}
|
|
|
|
node = ha_chain_get_next(node);
|
|
}
|
|
|
|
return(NULL);
|
|
}
|
|
|
|
/*************************************************************
|
|
Looks for an element when we know the pointer to the data, and deletes
|
|
it from the hash table, if found. */
|
|
UNIV_INLINE
|
|
ibool
|
|
ha_search_and_delete_if_found(
|
|
/*==========================*/
|
|
/* out: TRUE if found */
|
|
hash_table_t* table, /* in: hash table */
|
|
ulint fold, /* in: folded value of the searched data */
|
|
buf_block_t* block, /* in: buffer block, or NULL */
|
|
void* data) /* in: pointer to the data */
|
|
{
|
|
ha_node_t* node;
|
|
|
|
#ifdef UNIV_SYNC_DEBUG
|
|
ut_ad(!table->mutexes || mutex_own(hash_get_mutex(table, fold)));
|
|
#endif /* UNIV_SYNC_DEBUG */
|
|
|
|
node = ha_search_with_data(table, fold, data);
|
|
|
|
if (node) {
|
|
ha_delete_hash_node(table, block, node);
|
|
|
|
return(TRUE);
|
|
}
|
|
|
|
return(FALSE);
|
|
}
|