Commit a9ee619a authored by marko's avatar marko

branches/zip: Minor improvements.

Introduce FIL_PAGE_ZBLOB_DATA as a synonym for FIL_PAGE_FILE_FLUSH_LSN.

btr_store_big_rec_extern_fields(): Make the assertion about
dict_table_zip_size() more accurate.

buf_LRU_get_free_block(), buf_block_alloc(): Add parameter zip_size.

buf_calc_zblob_page_checksum(): Remove. Replace with page_zip_calc_checksum().

buf_page_init(): Remove parameter zip_size.

buf_page_io_complete(): Add a placeholder for handling compressed pages.

trx_doublewrite_page_inside(): Remove redundant function.

page_zip_write_rec(): Relax an overly tight assertion about blob_no.
parent f118a9c1
......@@ -3515,7 +3515,8 @@ btr_store_big_rec_extern_fields(
space_id = buf_frame_get_space_id(rec);
page_zip = buf_block_get_page_zip(buf_block_align(rec));
ut_a(!dict_table_zip_size(index->table) == !page_zip);
ut_a(dict_table_zip_size(index->table)
== (page_zip ? page_zip->size : 0));
if (UNIV_LIKELY_NULL(page_zip)) {
int err;
......@@ -3609,9 +3610,9 @@ btr_store_big_rec_extern_fields(
FIL_PAGE_TYPE_ZBLOB);
c_stream.next_out = page
+ FIL_PAGE_FILE_FLUSH_LSN;
+ FIL_PAGE_ZBLOB_DATA;
c_stream.avail_out = page_zip->size
- FIL_PAGE_FILE_FLUSH_LSN;
- FIL_PAGE_ZBLOB_DATA;
err = deflate(&c_stream, Z_FINISH);
ut_a(err == Z_OK || err == Z_STREAM_END);
......@@ -4106,7 +4107,7 @@ btr_copy_externally_stored_field(
/* When the BLOB begins at page header,
the compressed data payload does not
immediately follow the next page pointer. */
offset = FIL_PAGE_FILE_FLUSH_LSN;
offset = FIL_PAGE_ZBLOB_DATA;
} else {
offset += 4;
}
......
......@@ -232,21 +232,6 @@ ibool buf_debug_prints = FALSE; /* If this is set TRUE,
the program prints info whenever
read-ahead or flush occurs */
#endif /* UNIV_DEBUG */
/************************************************************************
Calculates a compressed BLOB page checksum which is stored to the page
when it is written to a file. Note that we must be careful to calculate
the same value on 32-bit and 64-bit architectures. */
ulint
buf_calc_zblob_page_checksum(
/*=========================*/
/* out: checksum */
const byte* page, /* in: compressed BLOB page */
ulint zip_size) /* in: size of the page, in bytes */
{
return(ut_fold_binary(page + FIL_PAGE_OFFSET,
zip_size - FIL_PAGE_OFFSET) & 0xFFFFFFFFUL);
}
/************************************************************************
Calculates a page checksum which is stored to the page when it is written
......@@ -365,8 +350,7 @@ buf_page_is_corrupted(
if (UNIV_UNLIKELY(zip_size)) {
return(checksum_field != BUF_NO_CHECKSUM_MAGIC
&& checksum_field
!= buf_calc_zblob_page_checksum(
read_buf, zip_size));
!= page_zip_calc_checksum(read_buf, zip_size));
}
old_checksum_field = mach_read_from_4(read_buf + UNIV_PAGE_SIZE
......@@ -435,7 +419,7 @@ buf_page_print(
switch (fil_page_get_type(read_buf)) {
case FIL_PAGE_TYPE_ZBLOB:
checksum = srv_use_checksums
? buf_calc_zblob_page_checksum(
? page_zip_calc_checksum(
read_buf, zip_size)
: BUF_NO_CHECKSUM_MAGIC;
ut_print_timestamp(stderr);
......@@ -946,15 +930,17 @@ buf_awe_map_page_to_frame(
Allocates a buffer block. */
UNIV_INLINE
buf_block_t*
buf_block_alloc(void)
/*=================*/
buf_block_alloc(
/*============*/
/* out, own: the allocated block; also if AWE
is used it is guaranteed that the page is
mapped to a frame */
ulint zip_size) /* in: compressed page size in bytes,
or 0 if uncompressed tablespace */
{
buf_block_t* block;
block = buf_LRU_get_free_block();
block = buf_LRU_get_free_block(zip_size);
return(block);
}
......@@ -1026,7 +1012,7 @@ buf_frame_alloc(void)
/*=================*/
/* out: buffer frame */
{
return(buf_block_alloc()->frame);
return(buf_block_alloc(0)->frame);
}
/*************************************************************************
......@@ -1683,15 +1669,12 @@ buf_page_init(
ulint space, /* in: space id */
ulint offset, /* in: offset of the page within space
in units of a page */
ulint zip_size,/* in: compressed page size in bytes,
or 0 if uncompressed tablespace */
buf_block_t* block) /* in: block to init */
{
#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(buf_pool->mutex)));
#endif /* UNIV_SYNC_DEBUG */
ut_a(block->state != BUF_BLOCK_FILE_PAGE);
ut_a(space || !zip_size);
/* Set the state of the block */
block->magic_n = BUF_BLOCK_MAGIC_N;
......@@ -1706,14 +1689,6 @@ buf_page_init(
block->lock_hash_val = lock_rec_hash(space, offset);
block->lock_mutex = NULL;
block->page_zip.size = zip_size;
if (UNIV_UNLIKELY(zip_size)) {
/* TODO: allocate this from a separate pool */
block->page_zip.data = ut_malloc(zip_size);
} else {
block->page_zip.data = NULL;
}
/* Insert into the hash table of file pages */
if (UNIV_LIKELY_NULL(buf_page_hash_get(space, offset))) {
......@@ -1801,7 +1776,7 @@ buf_page_init_for_read(
ut_ad(mode == BUF_READ_ANY_PAGE);
}
block = buf_block_alloc();
block = buf_block_alloc(zip_size);
ut_a(block);
......@@ -1831,7 +1806,7 @@ buf_page_init_for_read(
ut_ad(block);
buf_page_init(space, offset, zip_size, block);
buf_page_init(space, offset, block);
/* The block must be put to the LRU list, to the old blocks */
......@@ -1882,7 +1857,7 @@ buf_page_create(
ut_ad(mtr);
ut_ad(space || !zip_size);
free_block = buf_LRU_get_free_block();
free_block = buf_LRU_get_free_block(zip_size);
mutex_enter(&(buf_pool->mutex));
......@@ -1915,7 +1890,7 @@ buf_page_create(
block = free_block;
buf_page_init(space, offset, zip_size, block);
buf_page_init(space, offset, block);
/* The block must be put to the LRU list */
buf_LRU_add_block(block, FALSE);
......@@ -1987,20 +1962,34 @@ buf_page_io_complete(
io_type = block->io_fix;
if (io_type == BUF_IO_READ) {
if (block->page_zip.size) {
ut_a(block->space);
switch (fil_page_get_type(block->page_zip.data)) {
case FIL_PAGE_INDEX:
case FIL_PAGE_TYPE_ZBLOB:
/* TODO: checksum, but do not decompress */
break;
default:
/* TODO: how to distinguish uncompressed
and compressed pages? */
break;
}
}
/* If this page is not uninitialized and not in the
doublewrite buffer, then the page number should be the
same as in block */
read_page_no = mach_read_from_4((block->frame)
+ FIL_PAGE_OFFSET);
if (read_page_no != 0
&& !trx_doublewrite_page_inside(read_page_no)
&& read_page_no != block->offset) {
if (read_page_no && read_page_no != block->offset) {
fprintf(stderr,
"InnoDB: Error: page n:o stored in the page read in is %lu, should be %lu!\n",
(ulong) read_page_no, (ulong) block->offset);
}
/* From version 3.23.38 up we store the page checksum
to the 4 first bytes of the page end lsn field */
......
......@@ -468,7 +468,7 @@ buf_flush_init_for_writing(
mach_write_to_8(page + FIL_PAGE_LSN, newest_lsn);
mach_write_to_4(page + FIL_PAGE_SPACE_OR_CHKSUM,
srv_use_checksums
? buf_calc_zblob_page_checksum(
? page_zip_calc_checksum(
page, zip_size)
: BUF_NO_CHECKSUM_MAGIC);
return;
......
......@@ -320,16 +320,18 @@ buf_LRU_buf_pool_running_out(void)
}
/**********************************************************************
Returns a free block from buf_pool. The block is taken off the free list.
If it is empty, blocks are moved from the end of the LRU list to the free
list. */
Returns a free block from the buf_pool. The block is taken off the
free list. If it is empty, blocks are moved from the end of the
LRU list to the free list. */
buf_block_t*
buf_LRU_get_free_block(void)
/*========================*/
buf_LRU_get_free_block(
/*===================*/
/* out: the free control block; also if AWE is
used, it is guaranteed that the block has its
page mapped to a frame when we return */
ulint zip_size) /* in: compressed page size in bytes,
or 0 if uncompressed tablespace */
{
buf_block_t* block = NULL;
ibool freed;
......@@ -415,6 +417,20 @@ buf_LRU_get_free_block(void)
}
}
if (block->page_zip.size != zip_size) {
block->page_zip.size = zip_size;
if (block->page_zip.data) {
ut_free(block->page_zip.data);
}
if (zip_size) {
/* TODO: allocate this from a separate pool */
block->page_zip.data = ut_malloc(zip_size);
} else {
block->page_zip.data = NULL;
}
}
block->state = BUF_BLOCK_READY_FOR_USE;
mutex_exit(&(buf_pool->mutex));
......@@ -832,6 +848,7 @@ buf_LRU_block_free_non_file_page(
#ifdef UNIV_DEBUG
/* Wipe contents of page to reveal possible stale pointers to it */
memset(block->frame, '\0', UNIV_PAGE_SIZE);
memset(block->page_zip.data, 0xff, block->page_zip.size);
#endif
UT_LIST_ADD_FIRST(free, buf_pool->free, block);
block->in_free_list = TRUE;
......
......@@ -391,17 +391,6 @@ buf_block_get_modify_clock(
/* out: value */
buf_block_t* block); /* in: block */
/************************************************************************
Calculates a compressed BLOB page checksum which is stored to the page
when it is written to a file. Note that we must be careful to calculate
the same value on 32-bit and 64-bit architectures. */
ulint
buf_calc_zblob_page_checksum(
/*=========================*/
/* out: checksum */
const byte* page, /* in: compressed BLOB page */
ulint zip_size); /* in: size of the page, in bytes */
/************************************************************************
Calculates a page checksum which is stored to the page when it is written
to a file. Note that we must be careful to calculate the same value
on 32-bit and 64-bit architectures. */
......
......@@ -85,11 +85,14 @@ free list. If it is empty, blocks are moved from the end of the
LRU list to the free list. */
buf_block_t*
buf_LRU_get_free_block(void);
/*=========================*/
buf_LRU_get_free_block(
/*===================*/
/* out: the free control block; also if AWE is
used, it is guaranteed that the block has its
page mapped to a frame when we return */
ulint zip_size); /* in: compressed page size in bytes,
or 0 if uncompressed tablespace */
/**********************************************************************
Puts a block back to the free list. */
......
......@@ -83,6 +83,8 @@ extern fil_addr_t fil_addr_null;
first page in a data file: the file
has been flushed to disk at least up
to this lsn */
#define FIL_PAGE_ZBLOB_DATA 26 /* start of data stream on a
FIL_PAGE_TYPE_ZBLOB page */
#define FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID 34 /* starting from 4.1.x this
contains the space id of the page */
#define FIL_PAGE_DATA 38 /* start of the data on the page */
......
......@@ -75,15 +75,6 @@ multiple tablespace format. */
void
trx_sys_mark_upgraded_to_multiple_tablespaces(void);
/*===============================================*/
/********************************************************************
Determines if a page number is located inside the doublewrite buffer. */
ibool
trx_doublewrite_page_inside(
/*========================*/
/* out: TRUE if the location is inside
the two blocks of the doublewrite buffer */
ulint page_no); /* in: page number */
/*******************************************************************
Checks if a page address is the trx sys header page. */
UNIV_INLINE
......
......@@ -2057,7 +2057,7 @@ page_zip_write_rec(
page_zip, rec, index);
byte* ext_end = externs - page_zip->n_blobs
* BTR_EXTERN_FIELD_REF_SIZE;
ut_ad(blob_no < page_zip->n_blobs);
ut_ad(blob_no <= page_zip->n_blobs);
externs -= blob_no * BTR_EXTERN_FIELD_REF_SIZE;
if (create) {
......
......@@ -54,36 +54,6 @@ char trx_sys_mysql_bin_log_name[TRX_SYS_MYSQL_LOG_NAME_LEN];
ib_longlong trx_sys_mysql_bin_log_pos = -1;
/********************************************************************
Determines if a page number is located inside the doublewrite buffer. */
ibool
trx_doublewrite_page_inside(
/*========================*/
/* out: TRUE if the location is inside
the two blocks of the doublewrite buffer */
ulint page_no) /* in: page number */
{
if (trx_doublewrite == NULL) {
return(FALSE);
}
if (page_no >= trx_doublewrite->block1
&& page_no < trx_doublewrite->block1
+ TRX_SYS_DOUBLEWRITE_BLOCK_SIZE) {
return(TRUE);
}
if (page_no >= trx_doublewrite->block2
&& page_no < trx_doublewrite->block2
+ TRX_SYS_DOUBLEWRITE_BLOCK_SIZE) {
return(TRUE);
}
return(FALSE);
}
/********************************************************************
Creates or initialializes the doublewrite buffer at a database start. */
static
......
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