示例#1
0
/*******************************************************************//**
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(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);
}
示例#2
0
/*******************************************************************//**
Copies data into the storage and returns a pointer to the copy. If the
same data chunk is already present, then pointer to it is returned.
Data chunks are considered to be equal if len1 == len2 and
memcmp(data1, data2, len1) == 0. If "data" is not present (and thus
data_len bytes need to be allocated) and the size of storage is going to
become more than "memlim" then "data" is not added and NULL is returned.
To disable this behavior "memlim" can be set to 0, which stands for
"no limit". */
UNIV_INTERN
const void*
ha_storage_put_memlim(
    /*==================*/
    ha_storage_t*	storage,	/*!< in/out: hash storage */
    const void*	data,		/*!< in: data to store */
    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(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);
}
示例#3
0
ulint
buf_calc_page_old_checksum(
/*=======================*/
               /* out: checksum */
    uchar*    page) /* in: buffer page */
{
    ulint checksum;

    checksum= ut_fold_binary(page, FIL_PAGE_FILE_FLUSH_LSN);

    checksum= checksum & 0xFFFFFFFF;

    return(checksum);
}
示例#4
0
ulint
buf_calc_page_new_checksum(
/*=======================*/
               /* out: checksum */
    uchar*    page) /* in: buffer page */
{
    ulint checksum;

    /* Since the fields FIL_PAGE_FILE_FLUSH_LSN and ..._ARCH_LOG_NO
    are written outside the buffer pool to the first pages of data
    files, we have to skip them in the page checksum calculation.
    We must also skip the field FIL_PAGE_SPACE_OR_CHKSUM where the
    checksum is stored, and also the last 8 bytes of page because
    there we store the old formula checksum. */

    checksum= ut_fold_binary(page + FIL_PAGE_OFFSET,
                             FIL_PAGE_FILE_FLUSH_LSN - FIL_PAGE_OFFSET)
            + ut_fold_binary(page + FIL_PAGE_DATA,
                             UNIV_PAGE_SIZE - FIL_PAGE_DATA
                             - FIL_PAGE_END_LSN_OLD_CHKSUM);
    checksum= checksum & 0xFFFFFFFF;

    return(checksum);
}