Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 23 additions & 88 deletions storage/innobase/ha/ha0storage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,46 +29,6 @@ Created September 22, 2007 Vasil Dimov
#include "ha0storage.h"
#include "hash0hash.h"
#include "mem0mem.h"
#include "ut0rnd.h"

/*******************************************************************//**
Retrieves a data from a storage. If it is present, a pointer to the
stored copy of data is returned, otherwise NULL is returned. */
static
const void*
ha_storage_get(
/*===========*/
ha_storage_t* storage, /*!< in: hash storage */
const void* data, /*!< in: data to check for */
ulint data_len) /*!< in: data length */
{
ha_storage_node_t* node;
ulint fold;

/* avoid repetitive calls to ut_fold_binary() in the HASH_SEARCH
macro */
fold = ut_fold_binary(static_cast<const byte*>(data), data_len);

#define IS_FOUND \
node->data_len == data_len && memcmp(node->data, data, data_len) == 0

HASH_SEARCH(
next, /* node->"next" */
&storage->hash, /* the hash table */
fold, /* key */
ha_storage_node_t*, /* type of node->next */
node, /* auxiliary variable */
, /* assertion */
IS_FOUND); /* search criteria */

if (node == NULL) {

return(NULL);
}
/* else */

return(node->data);
}

/*******************************************************************//**
Copies data into the storage and returns a pointer to the copy. If the
Expand All @@ -87,54 +47,29 @@ ha_storage_put_memlim(
ulint data_len, /*!< in: data length */
ulint memlim) /*!< in: memory limit to obey */
{
void* raw;
ha_storage_node_t* node;
const void* data_copy;
ulint fold;

/* check if data chunk is already present */
data_copy = ha_storage_get(storage, data, data_len);
if (data_copy != NULL) {

return(data_copy);
}

/* not present */

/* check if we are allowed to allocate data_len bytes */
if (memlim > 0
&& ha_storage_get_size(storage) + data_len > memlim) {

return(NULL);
}

/* we put the auxiliary node struct and the data itself in one
continuous block */
raw = mem_heap_alloc(storage->heap,
sizeof(ha_storage_node_t) + data_len);

node = (ha_storage_node_t*) raw;
data_copy = (byte*) raw + sizeof(*node);

memcpy((byte*) raw + sizeof(*node), data, data_len);

node->data_len = data_len;
node->data = data_copy;

/* avoid repetitive calls to ut_fold_binary() in the HASH_INSERT
macro */
fold = ut_fold_binary(static_cast<const byte*>(data), data_len);

HASH_INSERT(
ha_storage_node_t, /* type used in the hash chain */
next, /* node->"next" */
&storage->hash, /* the hash table */
fold, /* key */
node); /* add this data to the hash */

/* the output should not be changed because it will spoil the
hash table */
return(data_copy);
const uint32_t fold= my_crc32c(0, data, data_len);
ha_storage_node_t** after = reinterpret_cast<ha_storage_node_t**>
(&storage->hash.cell_get(fold)->node);
for (; *after; after= &(*after)->next)
if ((*after)->data_len == data_len &&
!memcmp((*after)->data, data, data_len))
return (*after)->data;

/* not present */

/* check if we are allowed to allocate data_len bytes */
if (memlim > 0 && ha_storage_get_size(storage) + data_len > memlim)
return nullptr;

/* we put the auxiliary node struct and the data itself in one
continuous block */
ha_storage_node_t *node= static_cast<ha_storage_node_t*>
(mem_heap_alloc(storage->heap, sizeof *node + data_len));
node->data_len= data_len;
node->data= &node[1];
memcpy(const_cast<void*>(node->data), data, data_len);
*after= node;
return node->data;
}

#ifdef UNIV_COMPILE_TEST_FUNCS
Expand Down
14 changes: 9 additions & 5 deletions storage/innobase/include/hash0hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct hash_cell_t
@param insert the being-inserted element
@param next the next-element pointer in T */
template<typename T>
void append(T &insert, T *T::*next)
void append(T &insert, T *T::*next) noexcept
{
void **after;
for (after= &node; *after;
Expand Down Expand Up @@ -174,17 +174,21 @@ struct hash_table_t

/** Create the hash table.
@param n the lower bound of n_cells */
void create(ulint n)
void create(ulint n) noexcept
{
n_cells= ut_find_prime(n);
array= static_cast<hash_cell_t*>(ut_zalloc_nokey(n_cells * sizeof *array));
}

/** Clear the hash table. */
void clear() { memset(array, 0, n_cells * sizeof *array); }
void clear() noexcept { memset(array, 0, n_cells * sizeof *array); }

/** Free the hash table. */
void free() { ut_free(array); array= nullptr; }
void free() noexcept { ut_free(array); array= nullptr; }

ulint calc_hash(ulint fold) const { return ut_hash_ulint(fold, n_cells); }
ulint calc_hash(ulint fold) const noexcept
{ return ut_hash_ulint(fold, n_cells); }

hash_cell_t *cell_get(ulint fold) const noexcept
{ return &array[calc_hash(fold)]; }
};
16 changes: 1 addition & 15 deletions storage/innobase/include/trx0i_s.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,6 @@ do { \
} \
} while (0)

/** A row of INFORMATION_SCHEMA.innodb_locks */
struct i_s_locks_row_t;

/** Objects of trx_i_s_cache_t::locks_hash */
struct i_s_hash_chain_t;

/** Objects of this type are added to the hash table
trx_i_s_cache_t::locks_hash */
struct i_s_hash_chain_t {
i_s_locks_row_t* value; /*!< row of
INFORMATION_SCHEMA.innodb_locks*/
i_s_hash_chain_t* next; /*!< next item in the hash chain */
};

/** This structure represents INFORMATION_SCHEMA.innodb_locks row */
struct i_s_locks_row_t {
trx_id_t lock_trx_id; /*!< transaction identifier */
Expand All @@ -106,7 +92,7 @@ struct i_s_locks_row_t {
table_id_t lock_table_id;
/*!< table identifier from
lock_get_table_id */
i_s_hash_chain_t hash_chain; /*!< hash table chain node for
i_s_locks_row_t *next; /*!< hash table chain node for
trx_i_s_cache_t::locks_hash */
/* @} */
};
Expand Down
Loading