Commit 0d7111c9 authored by marko's avatar marko

branches/zip: page_zip_des_t: Rename "size" to "ssize" and reduce the

storage size from 16 to 3 bits.

page_zip_get_size(), page_zip_set_size(): New functions.

Replace direct references to page_zip_des_t:size with calls to
buf_block_get_zip_size(), page_zip_get_size(), and page_zip_set_size().
parent 7593a465
...@@ -1096,7 +1096,9 @@ btr_root_raise_and_insert( ...@@ -1096,7 +1096,9 @@ btr_root_raise_and_insert(
new_page = buf_block_get_frame(new_block); new_page = buf_block_get_frame(new_block);
new_page_zip = buf_block_get_page_zip(new_block); new_page_zip = buf_block_get_page_zip(new_block);
ut_a(!new_page_zip == !root_page_zip); ut_a(!new_page_zip == !root_page_zip);
ut_a(!new_page_zip || new_page_zip->size == root_page_zip->size); ut_a(!new_page_zip
|| page_zip_get_size(new_page_zip)
== page_zip_get_size(root_page_zip));
btr_page_create(new_block, new_page_zip, index, level, mtr); btr_page_create(new_block, new_page_zip, index, level, mtr);
...@@ -1335,7 +1337,8 @@ btr_page_get_sure_split_rec( ...@@ -1335,7 +1337,8 @@ btr_page_get_sure_split_rec(
if (UNIV_LIKELY_NULL(page_zip)) { if (UNIV_LIKELY_NULL(page_zip)) {
/* Estimate the free space of an empty compressed page. */ /* Estimate the free space of an empty compressed page. */
ulint free_space_zip = page_zip_empty_size( ulint free_space_zip = page_zip_empty_size(
cursor->index->n_fields, page_zip->size); cursor->index->n_fields,
page_zip_get_size(page_zip));
if (UNIV_LIKELY(free_space > (ulint) free_space_zip)) { if (UNIV_LIKELY(free_space > (ulint) free_space_zip)) {
free_space = (ulint) free_space_zip; free_space = (ulint) free_space_zip;
......
...@@ -1077,8 +1077,8 @@ btr_cur_optimistic_insert( ...@@ -1077,8 +1077,8 @@ btr_cur_optimistic_insert(
/* Calculate the record size when entry is converted to a record */ /* Calculate the record size when entry is converted to a record */
rec_size = rec_get_converted_size(index, entry, ext, n_ext); rec_size = rec_get_converted_size(index, entry, ext, n_ext);
if (page_zip_rec_needs_ext(rec_size, page_is_comp(page), if (page_zip_rec_needs_ext(rec_size, page_is_comp(page), page_zip
page_zip ? page_zip->size : 0)) { ? page_zip_get_size(page_zip) : 0)) {
/* The record is so big that we have to store some fields /* The record is so big that we have to store some fields
externally on separate database pages */ externally on separate database pages */
...@@ -2103,8 +2103,8 @@ btr_cur_pessimistic_update( ...@@ -2103,8 +2103,8 @@ btr_cur_pessimistic_update(
if (page_zip_rec_needs_ext(rec_get_converted_size(index, new_entry, if (page_zip_rec_needs_ext(rec_get_converted_size(index, new_entry,
ext_vect, ext_vect,
n_ext_vect), n_ext_vect),
page_is_comp(page), page_is_comp(page), page_zip
page_zip ? page_zip->size : 0)) { ? page_zip_get_size(page_zip) : 0)) {
big_rec_vec = dtuple_convert_big_rec(index, new_entry, big_rec_vec = dtuple_convert_big_rec(index, new_entry,
ext_vect, n_ext_vect); ext_vect, n_ext_vect);
if (UNIV_UNLIKELY(big_rec_vec == NULL)) { if (UNIV_UNLIKELY(big_rec_vec == NULL)) {
...@@ -3724,7 +3724,8 @@ btr_store_big_rec_extern_fields( ...@@ -3724,7 +3724,8 @@ btr_store_big_rec_extern_fields(
c_stream.next_out = page c_stream.next_out = page
+ FIL_PAGE_DATA; + FIL_PAGE_DATA;
c_stream.avail_out = page_zip->size c_stream.avail_out
= page_zip_get_size(page_zip)
- FIL_PAGE_DATA; - FIL_PAGE_DATA;
err = deflate(&c_stream, Z_FINISH); err = deflate(&c_stream, Z_FINISH);
...@@ -3759,20 +3760,22 @@ btr_store_big_rec_extern_fields( ...@@ -3759,20 +3760,22 @@ btr_store_big_rec_extern_fields(
MLOG_4BYTES, &mtr); MLOG_4BYTES, &mtr);
/* Zero out the unused part of the page. */ /* Zero out the unused part of the page. */
memset(page + page_zip->size memset(page + page_zip_get_size(page_zip)
- c_stream.avail_out, - c_stream.avail_out,
0, c_stream.avail_out); 0, c_stream.avail_out);
mlog_log_string(page + FIL_PAGE_TYPE, mlog_log_string(page + FIL_PAGE_TYPE,
page_zip->size - FIL_PAGE_TYPE, page_zip_get_size(page_zip)
- FIL_PAGE_TYPE,
&mtr); &mtr);
/* Copy the page to compressed storage, /* Copy the page to compressed storage,
because it will be flushed to disk because it will be flushed to disk
from there. */ from there. */
blob_page_zip = buf_block_get_page_zip(block); blob_page_zip = buf_block_get_page_zip(block);
ut_ad(blob_page_zip); ut_ad(blob_page_zip);
ut_ad(blob_page_zip->size == page_zip->size); ut_ad(page_zip_get_size(blob_page_zip)
== page_zip_get_size(page_zip));
memcpy(blob_page_zip->data, page, memcpy(blob_page_zip->data, page,
page_zip->size); page_zip_get_size(page_zip));
/* TODO: retain blob_page_zip, release page */ /* TODO: retain blob_page_zip, release page */
if (err == Z_OK && prev_page_no != FIL_NULL) { if (err == Z_OK && prev_page_no != FIL_NULL) {
......
...@@ -2126,7 +2126,7 @@ buf_page_io_complete( ...@@ -2126,7 +2126,7 @@ buf_page_io_complete(
ulint read_space_id; ulint read_space_id;
byte* frame; byte* frame;
if (block->page.zip.size) { if (buf_block_get_zip_size(block)) {
ut_a(buf_block_get_space(block) != 0); ut_a(buf_block_get_space(block) != 0);
frame = block->page.zip.data; frame = block->page.zip.data;
...@@ -2149,7 +2149,7 @@ buf_page_io_complete( ...@@ -2149,7 +2149,7 @@ buf_page_io_complete(
case FIL_PAGE_TYPE_ZBLOB: case FIL_PAGE_TYPE_ZBLOB:
/* Copy to uncompressed storage. */ /* Copy to uncompressed storage. */
memcpy(block->frame, frame, memcpy(block->frame, frame,
block->page.zip.size); buf_block_get_zip_size(block));
break; break;
default: default:
ut_print_timestamp(stderr); ut_print_timestamp(stderr);
...@@ -2204,7 +2204,8 @@ buf_page_io_complete( ...@@ -2204,7 +2204,8 @@ buf_page_io_complete(
/* From version 3.23.38 up we store the page checksum /* From version 3.23.38 up we store the page checksum
to the 4 first bytes of the page end lsn field */ to the 4 first bytes of the page end lsn field */
if (buf_page_is_corrupted(frame, block->page.zip.size)) { if (buf_page_is_corrupted(frame,
buf_block_get_zip_size(block))) {
corrupt: corrupt:
fprintf(stderr, fprintf(stderr,
"InnoDB: Database page corruption on disk" "InnoDB: Database page corruption on disk"
...@@ -2213,7 +2214,7 @@ buf_page_io_complete( ...@@ -2213,7 +2214,7 @@ buf_page_io_complete(
"InnoDB: You may have to recover" "InnoDB: You may have to recover"
" from a backup.\n", " from a backup.\n",
(ulong) block->page.offset); (ulong) block->page.offset);
buf_page_print(frame, block->page.zip.size); buf_page_print(frame, buf_block_get_zip_size(block));
fprintf(stderr, fprintf(stderr,
"InnoDB: Database page corruption on disk" "InnoDB: Database page corruption on disk"
" or a failed\n" " or a failed\n"
......
...@@ -381,12 +381,12 @@ buf_flush_buffered_writes(void) ...@@ -381,12 +381,12 @@ buf_flush_buffered_writes(void)
for (i = 0; i < trx_doublewrite->first_free; i++) { for (i = 0; i < trx_doublewrite->first_free; i++) {
block = trx_doublewrite->buf_block_arr[i]; block = trx_doublewrite->buf_block_arr[i];
ut_a(buf_block_get_state(block) == BUF_BLOCK_FILE_PAGE); ut_a(buf_block_get_state(block) == BUF_BLOCK_FILE_PAGE);
if (UNIV_UNLIKELY(block->page.zip.size)) { if (UNIV_UNLIKELY(buf_block_get_zip_size(block))) {
fil_io(OS_FILE_WRITE | OS_AIO_SIMULATED_WAKE_LATER, fil_io(OS_FILE_WRITE | OS_AIO_SIMULATED_WAKE_LATER,
FALSE, buf_block_get_space(block), FALSE, buf_block_get_space(block),
block->page.zip.size, buf_block_get_zip_size(block),
buf_block_get_page_no(block), 0, buf_block_get_page_no(block), 0,
block->page.zip.size, buf_block_get_zip_size(block),
(void*)block->page.zip.data, (void*)block->page.zip.data,
(void*)block); (void*)block);
continue; continue;
...@@ -463,7 +463,7 @@ buf_flush_post_to_doublewrite_buf( ...@@ -463,7 +463,7 @@ buf_flush_post_to_doublewrite_buf(
goto try_again; goto try_again;
} }
zip_size = block->page.zip.size; zip_size = buf_block_get_zip_size(block);
if (UNIV_UNLIKELY(zip_size)) { if (UNIV_UNLIKELY(zip_size)) {
/* Copy the compressed page and clear the rest. */ /* Copy the compressed page and clear the rest. */
...@@ -508,7 +508,7 @@ buf_flush_init_for_writing( ...@@ -508,7 +508,7 @@ buf_flush_init_for_writing(
{ {
if (page_zip_) { if (page_zip_) {
page_zip_des_t* page_zip = page_zip_; page_zip_des_t* page_zip = page_zip_;
ulint zip_size = page_zip->size; ulint zip_size = page_zip_get_size(page_zip);
ut_ad(zip_size); ut_ad(zip_size);
ut_ad(ut_is_2pow(zip_size)); ut_ad(ut_is_2pow(zip_size));
ut_ad(zip_size <= UNIV_PAGE_SIZE); ut_ad(zip_size <= UNIV_PAGE_SIZE);
...@@ -600,10 +600,12 @@ buf_flush_write_block_low( ...@@ -600,10 +600,12 @@ buf_flush_write_block_low(
buf_block_get_page_zip(block), buf_block_get_page_zip(block),
block->newest_modification); block->newest_modification);
if (!srv_use_doublewrite_buf || !trx_doublewrite) { if (!srv_use_doublewrite_buf || !trx_doublewrite) {
ulint zip_size = buf_block_get_zip_size(block);
fil_io(OS_FILE_WRITE | OS_AIO_SIMULATED_WAKE_LATER, fil_io(OS_FILE_WRITE | OS_AIO_SIMULATED_WAKE_LATER,
FALSE, buf_block_get_space(block), block->page.zip.size, FALSE, buf_block_get_space(block), zip_size,
buf_block_get_page_no(block), 0, block->page.zip.size buf_block_get_page_no(block), 0,
? block->page.zip.size : UNIV_PAGE_SIZE, zip_size ? zip_size : UNIV_PAGE_SIZE,
(void*)block->frame, (void*)block); (void*)block->frame, (void*)block);
} else { } else {
buf_flush_post_to_doublewrite_buf(block); buf_flush_post_to_doublewrite_buf(block);
......
...@@ -26,6 +26,7 @@ Created 11/5/1995 Heikki Tuuri ...@@ -26,6 +26,7 @@ Created 11/5/1995 Heikki Tuuri
#include "buf0rea.h" #include "buf0rea.h"
#include "btr0sea.h" #include "btr0sea.h"
#include "os0file.h" #include "os0file.h"
#include "page0zip.h"
#include "log0recv.h" #include "log0recv.h"
#include "srv0srv.h" #include "srv0srv.h"
...@@ -444,8 +445,8 @@ buf_LRU_get_free_block( ...@@ -444,8 +445,8 @@ buf_LRU_get_free_block(
ut_a(buf_block_get_state(block) != BUF_BLOCK_FILE_PAGE); ut_a(buf_block_get_state(block) != BUF_BLOCK_FILE_PAGE);
ut_a(!block->in_LRU_list); ut_a(!block->in_LRU_list);
if (block->page.zip.size != zip_size) { if (buf_block_get_zip_size(block) != zip_size) {
block->page.zip.size = zip_size; page_zip_set_size(&block->page.zip, zip_size);
block->page.zip.n_blobs = 0; block->page.zip.n_blobs = 0;
block->page.zip.m_start = 0; block->page.zip.m_start = 0;
block->page.zip.m_end = 0; block->page.zip.m_end = 0;
...@@ -882,7 +883,7 @@ buf_LRU_block_free_non_file_page( ...@@ -882,7 +883,7 @@ buf_LRU_block_free_non_file_page(
/* TODO: return zip to an aligned pool */ /* TODO: return zip to an aligned pool */
ut_free(block->page.zip.data); ut_free(block->page.zip.data);
block->page.zip.data = NULL; block->page.zip.data = NULL;
block->page.zip.size = 0; page_zip_set_size(&block->page.zip, 0);
} }
UT_LIST_ADD_FIRST(free, buf_pool->free, block); UT_LIST_ADD_FIRST(free, buf_pool->free, block);
......
...@@ -26,6 +26,7 @@ Created 10/25/1995 Heikki Tuuri ...@@ -26,6 +26,7 @@ Created 10/25/1995 Heikki Tuuri
#include "mtr0mtr.h" #include "mtr0mtr.h"
#include "mtr0log.h" #include "mtr0log.h"
#include "dict0dict.h" #include "dict0dict.h"
#include "page0zip.h"
/* /*
...@@ -2660,7 +2661,7 @@ fil_create_new_single_table_tablespace( ...@@ -2660,7 +2661,7 @@ fil_create_new_single_table_tablespace(
ret = os_file_write(path, file, page, 0, 0, UNIV_PAGE_SIZE); ret = os_file_write(path, file, page, 0, 0, UNIV_PAGE_SIZE);
} else { } else {
page_zip_des_t page_zip; page_zip_des_t page_zip;
page_zip.size = zip_size; page_zip_set_size(&page_zip, zip_size);
page_zip.data = page + UNIV_PAGE_SIZE; page_zip.data = page + UNIV_PAGE_SIZE;
page_zip.state = page_zip.n_blobs page_zip.state = page_zip.n_blobs
= page_zip.m_start = page_zip.m_end = 0; = page_zip.m_start = page_zip.m_end = 0;
......
...@@ -19,7 +19,7 @@ Created 11/29/1995 Heikki Tuuri ...@@ -19,7 +19,7 @@ Created 11/29/1995 Heikki Tuuri
#include "fut0fut.h" #include "fut0fut.h"
#include "ut0byte.h" #include "ut0byte.h"
#include "srv0srv.h" #include "srv0srv.h"
#include "page0types.h" #include "page0zip.h"
#include "ibuf0ibuf.h" #include "ibuf0ibuf.h"
#include "btr0btr.h" #include "btr0btr.h"
#include "btr0sea.h" #include "btr0sea.h"
...@@ -824,7 +824,7 @@ fsp_init_file_page_low( ...@@ -824,7 +824,7 @@ fsp_init_file_page_low(
if (UNIV_LIKELY_NULL(page_zip)) { if (UNIV_LIKELY_NULL(page_zip)) {
memset(page, 0, UNIV_PAGE_SIZE); memset(page, 0, UNIV_PAGE_SIZE);
memset(page_zip->data, 0, page_zip->size); memset(page_zip->data, 0, page_zip_get_size(page_zip));
mach_write_to_4(page + FIL_PAGE_OFFSET, mach_write_to_4(page + FIL_PAGE_OFFSET,
buf_block_get_page_no(block)); buf_block_get_page_no(block));
mach_write_to_4(page mach_write_to_4(page
......
...@@ -220,7 +220,7 @@ buf_block_get_zip_size( ...@@ -220,7 +220,7 @@ buf_block_get_zip_size(
/* out: compressed page size, or 0 */ /* out: compressed page size, or 0 */
const buf_block_t* block) /* in: pointer to the control block */ const buf_block_t* block) /* in: pointer to the control block */
{ {
return(block->page.zip.size); return(block->page.zip.ssize ? 512 << block->page.zip.ssize : 0);
} }
/************************************************************************* /*************************************************************************
......
...@@ -33,13 +33,12 @@ struct page_zip_des_struct ...@@ -33,13 +33,12 @@ struct page_zip_des_struct
page_zip_t* data; /* compressed page data */ page_zip_t* data; /* compressed page data */
ulint state:3; /* state of the control block ulint state:3; /* state of the control block
(cf. enum buf_page_state) */ (cf. enum buf_page_state) */
ulint :1; /* reserved */ ulint :11; /* reserved */
ulint n_blobs:12; /* number of externally stored ulint n_blobs:12; /* number of externally stored
columns on the page; the maximum columns on the page; the maximum
is 744 on a 16 KiB page */ is 744 on a 16 KiB page */
ulint size:16; /* compressed page size in bytes; ulint ssize:3; /* 0 or compressed page size;
must be a power of 2 and the size in bytes is 512<<ssize. */
at least PAGE_ZIP_MIN_SIZE */
ulint m_start:16; /* start offset of modification log */ ulint m_start:16; /* start offset of modification log */
ulint m_end:16; /* end offset of modification log */ ulint m_end:16; /* end offset of modification log */
}; };
......
...@@ -20,6 +20,24 @@ Created June 2005 by Marko Makela ...@@ -20,6 +20,24 @@ Created June 2005 by Marko Makela
#include "dict0types.h" #include "dict0types.h"
#include "ut0byte.h" #include "ut0byte.h"
/**************************************************************************
Determine the size of a compressed page in bytes. */
UNIV_INLINE
ulint
page_zip_get_size(
/*==============*/
/* out: size in bytes */
const page_zip_des_t* page_zip) /* in: compressed page */
__attribute__((nonnull, const));
/**************************************************************************
Set the size of a compressed page in bytes. */
UNIV_INLINE
void
page_zip_set_size(
/*==============*/
page_zip_des_t* page_zip, /* in/out: compressed page */
ulint size); /* in: size in bytes */
/************************************************************************** /**************************************************************************
Determine if a record is so big that it needs to be stored externally. */ Determine if a record is so big that it needs to be stored externally. */
UNIV_INLINE UNIV_INLINE
......
...@@ -92,6 +92,52 @@ In summary, the compressed page looks like this: ...@@ -92,6 +92,52 @@ In summary, the compressed page looks like this:
/* 'deleted' flag */ /* 'deleted' flag */
#define PAGE_ZIP_DIR_SLOT_DEL 0x8000 #define PAGE_ZIP_DIR_SLOT_DEL 0x8000
/**************************************************************************
Determine the size of a compressed page in bytes. */
UNIV_INLINE
ulint
page_zip_get_size(
/*==============*/
/* out: size in bytes */
const page_zip_des_t* page_zip) /* in: compressed page */
{
ulint size;
if (UNIV_UNLIKELY(!page_zip->ssize)) {
return(0);
}
size = 512 << page_zip->ssize;
ut_ad(size >= PAGE_ZIP_MIN_SIZE);
ut_ad(size <= UNIV_PAGE_SIZE);
return(size);
}
/**************************************************************************
Set the size of a compressed page in bytes. */
UNIV_INLINE
void
page_zip_set_size(
/*==============*/
page_zip_des_t* page_zip, /* in/out: compressed page */
ulint size) /* in: size in bytes */
{
if (size) {
int ssize;
ut_ad(ut_is_2pow(size));
for (ssize = 1; size > (ulint) (512 << ssize); ssize++);
page_zip->ssize = ssize;
} else {
page_zip->ssize = 0;
}
ut_ad(page_zip_get_size(page_zip) == size);
}
/************************************************************************** /**************************************************************************
Determine if a record is so big that it needs to be stored externally. */ Determine if a record is so big that it needs to be stored externally. */
UNIV_INLINE UNIV_INLINE
...@@ -142,12 +188,12 @@ page_zip_simple_validate( ...@@ -142,12 +188,12 @@ page_zip_simple_validate(
{ {
ut_ad(page_zip); ut_ad(page_zip);
ut_ad(page_zip->data); ut_ad(page_zip->data);
ut_ad(ut_is_2pow(page_zip->size)); ut_ad(page_zip_get_size(page_zip)
ut_ad(page_zip->size <= UNIV_PAGE_SIZE); > PAGE_DATA + PAGE_ZIP_DIR_SLOT_SIZE);
ut_ad(page_zip->size > PAGE_DATA + PAGE_ZIP_DIR_SLOT_SIZE);
ut_ad(page_zip->m_start <= page_zip->m_end); ut_ad(page_zip->m_start <= page_zip->m_end);
ut_ad(page_zip->m_end < page_zip->size); ut_ad(page_zip->m_end < page_zip_get_size(page_zip));
ut_ad(page_zip->n_blobs < page_zip->size / BTR_EXTERN_FIELD_REF_SIZE); ut_ad(page_zip->n_blobs
< page_zip_get_size(page_zip) / BTR_EXTERN_FIELD_REF_SIZE);
return(TRUE); return(TRUE);
} }
#endif /* UNIV_DEBUG */ #endif /* UNIV_DEBUG */
...@@ -231,7 +277,7 @@ page_zip_available( ...@@ -231,7 +277,7 @@ page_zip_available(
return(UNIV_LIKELY(length return(UNIV_LIKELY(length
+ trailer_len + trailer_len
+ page_zip->m_end + page_zip->m_end
< page_zip->size)); < page_zip_get_size(page_zip)));
} }
/************************************************************************** /**************************************************************************
......
This diff is collapsed.
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