From 9a601a1c8babe41aa66aacda6947d904873b67d5 Mon Sep 17 00:00:00 2001 From: marko <> Date: Thu, 2 Mar 2006 14:05:32 +0000 Subject: [PATCH] branches/zip: Fix some bugs in incremental compression. btr_create(): page_zip_compress() returns FALSE on failure. page_zip_write_header(): Write to page_zip->data[] instead of page_zip[]. buf_flush_init_for_writing(): Add parameter page_zip and set the fields also in the header of the compressed page. btr_cur_search_to_nth_level(): Add ut_ad() on page_zip_validate(). --- btr/btr0btr.c | 2 +- btr/btr0cur.c | 8 +++++++- buf/buf0flu.c | 19 ++++++++++++++++--- fil/fil0fil.c | 8 +++++--- include/buf0flu.h | 3 ++- include/page0zip.ic | 2 +- log/log0recv.c | 1 + 7 files changed, 33 insertions(+), 10 deletions(-) diff --git a/btr/btr0btr.c b/btr/btr0btr.c index a81057ccedc..e06fe5cf33e 100644 --- a/btr/btr0btr.c +++ b/btr/btr0btr.c @@ -763,7 +763,7 @@ btr_create( page_zip = buf_block_get_page_zip(buf_block_align(page)); if (UNIV_LIKELY_NULL(page_zip)) { - if (UNIV_UNLIKELY(page_zip_compress( + if (UNIV_UNLIKELY(!page_zip_compress( page_zip, page, index, mtr))) { /* An empty page should always be compressible */ ut_error; diff --git a/btr/btr0cur.c b/btr/btr0cur.c index d20c2ae7fe9..f6570f2bf4d 100644 --- a/btr/btr0cur.c +++ b/btr/btr0cur.c @@ -450,6 +450,7 @@ btr_cur_search_to_nth_level( /* Loop and search until we arrive at the desired level */ for (;;) { + buf_block_t* block; retry_page_get: page = buf_page_get_gen(space, page_no, rw_latch, guess, buf_mode, @@ -482,7 +483,12 @@ retry_page_get: goto retry_page_get; } - buf_block_align(page)->check_index_page_at_flush = TRUE; + block = buf_block_align(page); + + ut_ad(!buf_block_get_page_zip(block) || page_zip_validate( + buf_block_get_page_zip(block), page)); + + block->check_index_page_at_flush = TRUE; #ifdef UNIV_SYNC_DEBUG if (rw_latch != RW_NO_LATCH) { diff --git a/buf/buf0flu.c b/buf/buf0flu.c index a3f820029e6..9c68bffa0f2 100644 --- a/buf/buf0flu.c +++ b/buf/buf0flu.c @@ -447,11 +447,14 @@ Initializes a page for writing to the tablespace. */ void buf_flush_init_for_writing( /*=======================*/ - byte* page, /* in: page */ + byte* page, /* in/out: page */ + void* page_zip_, /* in/out: compressed page, or NULL */ dulint newest_lsn, /* in: newest modification lsn to the page */ ulint space, /* in: space id */ ulint page_no) /* in: page number */ { + page_zip_des_t* page_zip = page_zip_; + /* Write the newest modification lsn to the page header and trailer */ mach_write_to_8(page + FIL_PAGE_LSN, newest_lsn); @@ -468,6 +471,14 @@ buf_flush_init_for_writing( srv_use_checksums ? buf_calc_page_new_checksum(page) : BUF_NO_CHECKSUM_MAGIC); + if (UNIV_LIKELY_NULL(page_zip)) { + /* Copy FIL_PAGE_SPACE_OR_CHKSUM and FIL_PAGE_OFFSET */ + memcpy(page_zip->data, page, FIL_PAGE_PREV); + /* Copy FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID */ + memcpy(page_zip->data + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID, + page + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID, 4); + } + /* We overwrite the first 4 bytes of the end lsn field to store the old formula checksum. Since it depends also on the field FIL_PAGE_SPACE_OR_CHKSUM, it has to be calculated after storing the @@ -510,8 +521,10 @@ buf_flush_write_block_low( /* Force the log to the disk before writing the modified block */ log_write_up_to(block->newest_modification, LOG_WAIT_ALL_GROUPS, TRUE); #endif - buf_flush_init_for_writing(block->frame, block->newest_modification, - block->space, block->offset); + buf_flush_init_for_writing(block->frame, + buf_block_get_page_zip(block), + block->newest_modification, + block->space, block->offset); if (!srv_use_doublewrite_buf || !trx_doublewrite) { fil_io(OS_FILE_WRITE | OS_AIO_SIMULATED_WAKE_LATER, FALSE, block->space, block->offset, 0, UNIV_PAGE_SIZE, diff --git a/fil/fil0fil.c b/fil/fil0fil.c index 7418420628e..3c6a00a02d0 100644 --- a/fil/fil0fil.c +++ b/fil/fil0fil.c @@ -2432,7 +2432,8 @@ fil_create_new_single_table_tablespace( fsp_header_write_space_id(page, *space_id); - buf_flush_init_for_writing(page, ut_dulint_zero, *space_id, 0); + buf_flush_init_for_writing(page, NULL/* TODO: page_zip */, + ut_dulint_zero, *space_id, 0); ret = os_file_write(path, file, page, 0, 0, UNIV_PAGE_SIZE); @@ -2594,8 +2595,9 @@ fil_reset_too_high_lsns( + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID); page_no = mach_read_from_4(page + FIL_PAGE_OFFSET); - buf_flush_init_for_writing(page, current_lsn, space_id, - page_no); + buf_flush_init_for_writing(page, + NULL/* TODO: page_zip */, + current_lsn, space_id, page_no); success = os_file_write(filepath, file, page, (ulint)(offset & 0xFFFFFFFFUL), (ulint)(offset >> 32), UNIV_PAGE_SIZE); diff --git a/include/buf0flu.h b/include/buf0flu.h index 322848509f4..27217944e6f 100644 --- a/include/buf0flu.h +++ b/include/buf0flu.h @@ -34,7 +34,8 @@ Initializes a page for writing to the tablespace. */ void buf_flush_init_for_writing( /*=======================*/ - byte* page, /* in: page */ + byte* page, /* in/out: page */ + void* page_zip, /* in/out: compressed page, or NULL */ dulint newest_lsn, /* in: newest modification lsn to the page */ ulint space, /* in: space id */ ulint page_no); /* in: page number */ diff --git a/include/page0zip.ic b/include/page0zip.ic index 5460f434ee3..1db03f68253 100644 --- a/include/page0zip.ic +++ b/include/page0zip.ic @@ -272,7 +272,7 @@ page_zip_write_header( ut_ad(pos < PAGE_DATA); - memcpy(page_zip + pos, str, length); + memcpy(page_zip->data + pos, str, length); /* The following would fail in page_cur_insert_rec_low(). */ /* ut_ad(page_zip_validate(page_zip, str - pos)); */ diff --git a/log/log0recv.c b/log/log0recv.c index 45eccbf4de1..6f82e9c524f 100644 --- a/log/log0recv.c +++ b/log/log0recv.c @@ -1612,6 +1612,7 @@ recv_addr->space, recv_addr->page_no); fil0fil.c routines */ buf_flush_init_for_writing(page, + NULL,/* TODO: page_zip */ mach_read_from_8(page + FIL_PAGE_LSN), recv_addr->space, recv_addr->page_no);