2007-12-16 14:26:22 +01:00
|
|
|
/* TODO: copyright & Co */
|
|
|
|
|
|
|
|
#include "maria_def.h"
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@brief calculate crc of the page avoiding special values
|
|
|
|
|
|
|
|
@param start The value to start CRC (we use page number here)
|
|
|
|
@param data data pointer
|
|
|
|
@param length length of the data
|
|
|
|
|
|
|
|
@return crc of the page without special values
|
|
|
|
*/
|
|
|
|
|
|
|
|
static uint32 maria_page_crc(ulong start, uchar *data, uint length)
|
|
|
|
{
|
|
|
|
uint32 crc= crc32(start, data, length);
|
|
|
|
|
|
|
|
/* we need this assert to get following comparison working */
|
|
|
|
compile_time_assert(MARIA_NO_CRC_BITMAP_PAGE ==
|
|
|
|
MARIA_NO_CRC_NORMAL_PAGE - 1 &&
|
|
|
|
MARIA_NO_CRC_NORMAL_PAGE == 0xffffffff);
|
|
|
|
if (crc >= MARIA_NO_CRC_BITMAP_PAGE)
|
|
|
|
crc= MARIA_NO_CRC_BITMAP_PAGE - 1;
|
|
|
|
|
|
|
|
return(crc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@brief Maria pages read callback (checks the page CRC)
|
|
|
|
|
|
|
|
@param page The page data to check
|
|
|
|
@param page_no The page number (<offset>/<page length>)
|
|
|
|
@param data_ptr pointer to MARIA_SHARE
|
|
|
|
@param no_crc_val Value which means CRC absence
|
|
|
|
(MARIA_NO_CRC_NORMAL_PAGE or MARIA_NO_CRC_BITMAP_PAGE)
|
|
|
|
@param data_length length of data to calculate CRC
|
|
|
|
|
|
|
|
@retval 0 OK
|
|
|
|
@retval 1 Error
|
|
|
|
*/
|
|
|
|
|
2007-12-18 02:21:32 +01:00
|
|
|
static my_bool maria_page_crc_check(uchar *page,
|
|
|
|
pgcache_page_no_t page_no,
|
|
|
|
MARIA_SHARE *share,
|
|
|
|
uint32 no_crc_val,
|
|
|
|
int data_length)
|
2007-12-16 14:26:22 +01:00
|
|
|
{
|
|
|
|
uint32 crc= uint4korr(page + share->block_size - CRC_SIZE), new_crc;
|
|
|
|
my_bool res;
|
|
|
|
DBUG_ENTER("maria_page_crc_check");
|
|
|
|
|
|
|
|
DBUG_ASSERT((uint)data_length <= share->block_size - CRC_SIZE);
|
|
|
|
|
|
|
|
/* we need this assert to get following comparison working */
|
|
|
|
compile_time_assert(MARIA_NO_CRC_BITMAP_PAGE ==
|
|
|
|
MARIA_NO_CRC_NORMAL_PAGE - 1 &&
|
|
|
|
MARIA_NO_CRC_NORMAL_PAGE == 0xffffffff);
|
|
|
|
/*
|
|
|
|
If crc is no_crc_val then
|
|
|
|
the page has no crc, so there is nothing to check.
|
|
|
|
*/
|
|
|
|
if (crc >= MARIA_NO_CRC_BITMAP_PAGE)
|
|
|
|
{
|
2007-12-18 02:21:32 +01:00
|
|
|
DBUG_PRINT("info", ("No crc: %lu crc: %lu page: %lu ",
|
2007-12-16 14:26:22 +01:00
|
|
|
(ulong) no_crc_val, (ulong) crc, (ulong) page_no));
|
|
|
|
if (crc != no_crc_val)
|
2007-12-18 02:21:32 +01:00
|
|
|
{
|
|
|
|
my_errno= HA_ERR_WRONG_CRC;
|
|
|
|
DBUG_PRINT("error", ("Wrong no CRC value"));
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
DBUG_RETURN(0);
|
2007-12-16 14:26:22 +01:00
|
|
|
}
|
|
|
|
new_crc= maria_page_crc(page_no, page, data_length);
|
|
|
|
DBUG_ASSERT(new_crc != no_crc_val);
|
|
|
|
res= test(new_crc != crc);
|
|
|
|
if (res)
|
|
|
|
{
|
2007-12-18 02:21:32 +01:00
|
|
|
DBUG_PRINT("error", ("Page: %lu crc: %lu calculated crc: %lu",
|
|
|
|
(ulong) page_no, (ulong) crc, (ulong) new_crc));
|
|
|
|
my_errno= HA_ERR_WRONG_CRC;
|
2007-12-16 14:26:22 +01:00
|
|
|
}
|
|
|
|
DBUG_RETURN(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@brief Maria pages write callback (sets the page CRC for data and index
|
|
|
|
files)
|
|
|
|
|
|
|
|
@param page The page data to set
|
|
|
|
@param page_no The page number (<offset>/<page length>)
|
|
|
|
@param data_ptr Write callback data pointer (pointer to MARIA_SHARE)
|
|
|
|
|
|
|
|
@retval 0 OK
|
|
|
|
*/
|
|
|
|
|
|
|
|
my_bool maria_page_crc_set_normal(uchar *page,
|
|
|
|
pgcache_page_no_t page_no,
|
2007-12-18 02:21:32 +01:00
|
|
|
uchar *data_ptr)
|
2007-12-16 14:26:22 +01:00
|
|
|
{
|
|
|
|
MARIA_SHARE *share= (MARIA_SHARE *)data_ptr;
|
|
|
|
int data_length= share->block_size - CRC_SIZE;
|
|
|
|
uint32 crc= maria_page_crc(page_no, page, data_length);
|
|
|
|
DBUG_ENTER("maria_page_crc_set");
|
2007-12-18 02:21:32 +01:00
|
|
|
DBUG_PRINT("info", ("Page %lu crc: %lu", (ulong) page_no, (ulong)crc));
|
2007-12-16 14:26:22 +01:00
|
|
|
|
|
|
|
/* crc is on the stack so it is aligned, pagecache buffer is aligned, too */
|
|
|
|
int4store_aligned(page + data_length, crc);
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@brief Maria pages write callback (sets the page CRC for keys)
|
|
|
|
|
|
|
|
@param page The page data to set
|
|
|
|
@param page_no The page number (<offset>/<page length>)
|
|
|
|
@param data_ptr Write callback data pointer (pointer to MARIA_SHARE)
|
|
|
|
|
|
|
|
@retval 0 OK
|
|
|
|
*/
|
|
|
|
|
|
|
|
my_bool maria_page_crc_set_index(uchar *page,
|
|
|
|
pgcache_page_no_t page_no,
|
2007-12-18 02:21:32 +01:00
|
|
|
uchar *data_ptr)
|
2007-12-16 14:26:22 +01:00
|
|
|
{
|
|
|
|
MARIA_SHARE *share= (MARIA_SHARE *)data_ptr;
|
|
|
|
int data_length= _ma_get_page_used(share, page);
|
|
|
|
uint32 crc= maria_page_crc(page_no, page, data_length);
|
|
|
|
DBUG_ENTER("maria_page_crc_set");
|
|
|
|
|
2007-12-18 02:21:32 +01:00
|
|
|
DBUG_PRINT("info", ("Page %lu crc: %lu",
|
|
|
|
(ulong) page_no, (ulong) crc));
|
2007-12-16 14:26:22 +01:00
|
|
|
DBUG_ASSERT((uint)data_length <= share->block_size - CRC_SIZE);
|
|
|
|
/* crc is on the stack so it is aligned, pagecache buffer is aligned, too */
|
|
|
|
int4store_aligned(page + share->block_size - CRC_SIZE, crc);
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* interface functions */
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@brief Maria pages read callback (checks the page CRC) for index/data pages
|
|
|
|
|
|
|
|
@param page The page data to check
|
|
|
|
@param page_no The page number (<offset>/<page length>)
|
|
|
|
@param data_ptr Read callback data pointer (pointer to MARIA_SHARE)
|
|
|
|
|
|
|
|
@retval 0 OK
|
|
|
|
@retval 1 Error
|
|
|
|
*/
|
|
|
|
|
|
|
|
my_bool maria_page_crc_check_data(uchar *page,
|
|
|
|
pgcache_page_no_t page_no,
|
2007-12-18 02:21:32 +01:00
|
|
|
uchar *data_ptr)
|
2007-12-16 14:26:22 +01:00
|
|
|
{
|
|
|
|
MARIA_SHARE *share= (MARIA_SHARE *)data_ptr;
|
|
|
|
return (maria_page_crc_check(page, page_no, share,
|
|
|
|
MARIA_NO_CRC_NORMAL_PAGE,
|
|
|
|
share->block_size - CRC_SIZE));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@brief Maria pages read callback (checks the page CRC) for bitmap pages
|
|
|
|
|
|
|
|
@param page The page data to check
|
|
|
|
@param page_no The page number (<offset>/<page length>)
|
|
|
|
@param data_ptr Read callback data pointer (pointer to MARIA_SHARE)
|
|
|
|
|
|
|
|
@retval 0 OK
|
|
|
|
@retval 1 Error
|
|
|
|
*/
|
|
|
|
|
|
|
|
my_bool maria_page_crc_check_bitmap(uchar *page,
|
|
|
|
pgcache_page_no_t page_no,
|
2007-12-18 02:21:32 +01:00
|
|
|
uchar *data_ptr)
|
2007-12-16 14:26:22 +01:00
|
|
|
{
|
|
|
|
MARIA_SHARE *share= (MARIA_SHARE *)data_ptr;
|
|
|
|
return (maria_page_crc_check(page, page_no, share,
|
|
|
|
MARIA_NO_CRC_BITMAP_PAGE,
|
|
|
|
share->block_size - CRC_SIZE));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@brief Maria pages read callback (checks the page CRC) for index pages
|
|
|
|
|
|
|
|
@param page The page data to check
|
|
|
|
@param page_no The page number (<offset>/<page length>)
|
|
|
|
@param data_ptr Read callback data pointer (pointer to MARIA_SHARE)
|
|
|
|
|
|
|
|
@retval 0 OK
|
|
|
|
@retval 1 Error
|
|
|
|
*/
|
|
|
|
|
|
|
|
my_bool maria_page_crc_check_index(uchar *page,
|
|
|
|
pgcache_page_no_t page_no,
|
2007-12-18 02:21:32 +01:00
|
|
|
uchar *data_ptr)
|
2007-12-16 14:26:22 +01:00
|
|
|
{
|
|
|
|
MARIA_SHARE *share= (MARIA_SHARE *)data_ptr;
|
2007-12-18 02:21:32 +01:00
|
|
|
uint length= _ma_get_page_used(share, page);
|
|
|
|
if (length > share->block_size - CRC_SIZE)
|
|
|
|
{
|
|
|
|
DBUG_PRINT("error", ("Wrong page length: %u", length));
|
|
|
|
return (my_errno= HA_ERR_WRONG_CRC);
|
|
|
|
}
|
|
|
|
return maria_page_crc_check(page, page_no, share,
|
2007-12-16 14:26:22 +01:00
|
|
|
MARIA_NO_CRC_NORMAL_PAGE,
|
2007-12-18 02:21:32 +01:00
|
|
|
length);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@brief Maria pages dumme read callback for temporary tables
|
|
|
|
|
|
|
|
@retval 0 OK
|
|
|
|
@retval 1 Error
|
|
|
|
*/
|
|
|
|
|
|
|
|
my_bool maria_page_crc_check_none(uchar *page __attribute__((unused)),
|
|
|
|
pgcache_page_no_t page_no
|
|
|
|
__attribute__((unused)),
|
|
|
|
uchar *data_ptr __attribute__((unused)))
|
|
|
|
{
|
|
|
|
return 0;
|
2007-12-16 14:26:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@brief Maria pages write callback (sets the page filler for index/data)
|
|
|
|
|
|
|
|
@param page The page data to set
|
|
|
|
@param page_no The page number (<offset>/<page length>)
|
|
|
|
@param data_ptr Write callback data pointer (pointer to MARIA_SHARE)
|
|
|
|
|
|
|
|
@retval 0 OK
|
|
|
|
*/
|
|
|
|
|
|
|
|
my_bool maria_page_filler_set_normal(uchar *page,
|
2007-12-18 02:21:32 +01:00
|
|
|
pgcache_page_no_t page_no
|
|
|
|
__attribute__((unused)),
|
|
|
|
uchar *data_ptr)
|
2007-12-16 14:26:22 +01:00
|
|
|
{
|
|
|
|
DBUG_ENTER("maria_page_filler_set_normal");
|
2007-12-18 02:21:32 +01:00
|
|
|
DBUG_ASSERT(page_no != 0); /* Catches some simple bugs */
|
2007-12-16 14:26:22 +01:00
|
|
|
int4store_aligned(page + ((MARIA_SHARE *)data_ptr)->block_size - CRC_SIZE,
|
|
|
|
MARIA_NO_CRC_NORMAL_PAGE);
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
2007-12-18 02:21:32 +01:00
|
|
|
|
2007-12-16 14:26:22 +01:00
|
|
|
/**
|
|
|
|
@brief Maria pages write callback (sets the page filler for bitmap)
|
|
|
|
|
|
|
|
@param page The page data to set
|
|
|
|
@param page_no The page number (<offset>/<page length>)
|
|
|
|
@param data_ptr Write callback data pointer (pointer to MARIA_SHARE)
|
|
|
|
|
|
|
|
@retval 0 OK
|
|
|
|
*/
|
|
|
|
|
|
|
|
my_bool maria_page_filler_set_bitmap(uchar *page,
|
2007-12-18 02:21:32 +01:00
|
|
|
pgcache_page_no_t page_no
|
|
|
|
__attribute__((unused)),
|
|
|
|
uchar *data_ptr)
|
2007-12-16 14:26:22 +01:00
|
|
|
{
|
|
|
|
DBUG_ENTER("maria_page_filler_set_bitmap");
|
|
|
|
int4store_aligned(page + ((MARIA_SHARE *)data_ptr)->block_size - CRC_SIZE,
|
|
|
|
MARIA_NO_CRC_BITMAP_PAGE);
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
2007-12-18 02:21:32 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@brief Maria pages dummy write callback for temporary tables
|
|
|
|
|
|
|
|
@retval 0 OK
|
|
|
|
*/
|
|
|
|
|
|
|
|
my_bool maria_page_filler_set_none(uchar *page __attribute__((unused)),
|
|
|
|
pgcache_page_no_t page_no
|
|
|
|
__attribute__((unused)),
|
|
|
|
uchar *data_ptr __attribute__((unused)))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2007-12-20 11:24:03 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
@brief Write failure callback (mark table as corrupted)
|
|
|
|
|
|
|
|
@param data_ptr Write callback data pointer (pointer to MARIA_SHARE)
|
|
|
|
*/
|
|
|
|
void maria_page_write_failure (uchar* data_ptr)
|
|
|
|
{
|
|
|
|
maria_mark_crashed_share((MARIA_SHARE *)data_ptr);
|
|
|
|
}
|