From e77a82a05420a65ac51aff44dd57faaf1a014bcc Mon Sep 17 00:00:00 2001 From: marko Date: Tue, 16 Jan 2007 21:51:40 +0000 Subject: [PATCH] branches/zip: buf_flush_write_block_low(): Avoid recomputing the compressed page checksum of compressed-only blocks. Pass the compressed page frame to fil_io() when needed. page_zip_calc_checksum(): Skip also FIL_PAGE_LSN and FIL_PAGE_FILE_FLUSH_LSN. buf_flush_init_for_writing(): Expect page to be non-NULL. --- buf/buf0flu.c | 33 +++++++++++++++------------------ include/buf0flu.h | 3 +-- page/page0zip.c | 19 +++++++++++++++---- 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/buf/buf0flu.c b/buf/buf0flu.c index 7bbed196390..3e28b0c4e94 100644 --- a/buf/buf0flu.c +++ b/buf/buf0flu.c @@ -601,12 +601,13 @@ Initializes a page for writing to the tablespace. */ void buf_flush_init_for_writing( /*=======================*/ - byte* page, /* in/out: page, may be NULL - if page_zip_ is non-NULL */ + byte* page, /* in/out: page */ void* page_zip_, /* in/out: compressed page, or NULL */ ib_uint64_t newest_lsn) /* in: newest modification lsn to the page */ { + ut_ad(page); + if (page_zip_) { page_zip_des_t* page_zip = page_zip_; ulint zip_size = page_zip_get_size(page_zip); @@ -614,18 +615,14 @@ buf_flush_init_for_writing( ut_ad(ut_is_2pow(zip_size)); ut_ad(zip_size <= UNIV_PAGE_SIZE); - switch (UNIV_EXPECT(fil_page_get_type(page - ? page : page_zip->data), - FIL_PAGE_INDEX)) { + switch (UNIV_EXPECT(fil_page_get_type(page), FIL_PAGE_INDEX)) { case FIL_PAGE_TYPE_ALLOCATED: case FIL_PAGE_INODE: case FIL_PAGE_IBUF_BITMAP: case FIL_PAGE_TYPE_FSP_HDR: case FIL_PAGE_TYPE_XDES: /* These are essentially uncompressed pages. */ - if (page) { - memcpy(page_zip->data, page, zip_size); - } + memcpy(page_zip->data, page, zip_size); /* fall through */ case FIL_PAGE_TYPE_ZBLOB: case FIL_PAGE_INDEX: @@ -644,8 +641,6 @@ buf_flush_init_for_writing( ut_error; } - ut_ad(page); - /* Write the newest modification lsn to the page header and trailer */ mach_write_ull(page + FIL_PAGE_LSN, newest_lsn); @@ -715,22 +710,24 @@ buf_flush_write_block_low( ut_error; break; case BUF_BLOCK_ZIP_DIRTY: + frame = bpage->zip.data; if (UNIV_LIKELY(srv_use_checksums)) { - ut_a(mach_read_from_4(bpage->zip.data - + FIL_PAGE_SPACE_OR_CHKSUM) - == page_zip_calc_checksum(bpage->zip.data, - zip_size)); + ut_a(mach_read_from_4(frame + FIL_PAGE_SPACE_OR_CHKSUM) + == page_zip_calc_checksum(frame, zip_size)); } + mach_write_ull(frame + FIL_PAGE_LSN, + bpage->newest_modification); + memset(frame + FIL_PAGE_FILE_FLUSH_LSN, 0, 8); break; case BUF_BLOCK_FILE_PAGE: frame = ((buf_block_t*) bpage)->frame; + buf_flush_init_for_writing(frame, + bpage->zip.data + ? &bpage->zip : NULL, + bpage->newest_modification); break; } - buf_flush_init_for_writing(frame, - bpage->zip.data ? &bpage->zip : NULL, - bpage->newest_modification); - if (!srv_use_doublewrite_buf || !trx_doublewrite) { fil_io(OS_FILE_WRITE | OS_AIO_SIMULATED_WAKE_LATER, FALSE, buf_page_get_space(bpage), zip_size, diff --git a/include/buf0flu.h b/include/buf0flu.h index 598fdf87bdd..b419ac8b26b 100644 --- a/include/buf0flu.h +++ b/include/buf0flu.h @@ -48,8 +48,7 @@ Initializes a page for writing to the tablespace. */ void buf_flush_init_for_writing( /*=======================*/ - byte* page, /* in/out: page, may be NULL - if page_zip_ is non-NULL */ + byte* page, /* in/out: page */ void* page_zip_, /* in/out: compressed page, or NULL */ ib_uint64_t newest_lsn); /* in: newest modification lsn to the page */ diff --git a/page/page0zip.c b/page/page0zip.c index bb3020b406c..fbae3cf24a8 100644 --- a/page/page0zip.c +++ b/page/page0zip.c @@ -3729,8 +3729,19 @@ page_zip_calc_checksum( const void* data, /* in: compressed page */ ulint size) /* in: size of compressed page */ { - /* Exclude the 32-bit checksum field from the checksum. */ - return((ulint) adler32(0, - ((const Bytef*) data) + FIL_PAGE_OFFSET, - size - FIL_PAGE_OFFSET)); + /* Exclude FIL_PAGE_SPACE_OR_CHKSUM, FIL_PAGE_LSN, + and FIL_PAGE_FILE_FLUSH_LSN from the checksum. */ + + const Bytef* s = data; + uLong adler; + + ut_ad(size > FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID); + + adler = adler32(0L, s + FIL_PAGE_OFFSET, + FIL_PAGE_LSN - FIL_PAGE_OFFSET); + adler = adler32(adler, s + FIL_PAGE_TYPE, 2); + adler = adler32(adler, s + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID, + size - FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID); + + return((ulint) adler); }