summaryrefslogtreecommitdiff
path: root/storage/innobase/include/page0zip.h
diff options
context:
space:
mode:
Diffstat (limited to 'storage/innobase/include/page0zip.h')
-rw-r--r--storage/innobase/include/page0zip.h224
1 files changed, 127 insertions, 97 deletions
diff --git a/storage/innobase/include/page0zip.h b/storage/innobase/include/page0zip.h
index 4e362cec641..20643b60bfa 100644
--- a/storage/innobase/include/page0zip.h
+++ b/storage/innobase/include/page0zip.h
@@ -1,4 +1,3 @@
-
/*****************************************************************************
Copyright (c) 2005, 2016, Oracle and/or its affiliates. All Rights Reserved.
@@ -34,30 +33,56 @@ Created June 2005 by Marko Makela
# define UNIV_INLINE
#endif
+#ifdef UNIV_INNOCHECKSUM
+#include "univ.i"
+#include "buf0buf.h"
+#include "ut0crc32.h"
+#include "buf0checksum.h"
+#include "mach0data.h"
+#include "zlib.h"
+#endif /* UNIV_INNOCHECKSUM */
+
+#ifndef UNIV_INNOCHECKSUM
+#include "mtr0types.h"
#include "page0types.h"
+#endif /* !UNIV_INNOCHECKSUM */
+
#include "buf0types.h"
+
#ifndef UNIV_INNOCHECKSUM
-#include "mtr0types.h"
#include "dict0types.h"
#include "srv0srv.h"
#include "trx0types.h"
#include "mem0mem.h"
-#endif /* !UNIV_INNOCHECKSUM */
/* Compression level to be used by zlib. Settable by user. */
extern uint page_zip_level;
/* Default compression level. */
#define DEFAULT_COMPRESSION_LEVEL 6
+/** Start offset of the area that will be compressed */
+#define PAGE_ZIP_START PAGE_NEW_SUPREMUM_END
+/** Size of an compressed page directory entry */
+#define PAGE_ZIP_DIR_SLOT_SIZE 2
+/** Predefine the sum of DIR_SLOT, TRX_ID & ROLL_PTR */
+#define PAGE_ZIP_CLUST_LEAF_SLOT_SIZE \
+ (PAGE_ZIP_DIR_SLOT_SIZE \
+ + DATA_TRX_ID_LEN \
+ + DATA_ROLL_PTR_LEN)
+/** Mask of record offsets */
+#define PAGE_ZIP_DIR_SLOT_MASK 0x3fff
+/** 'owned' flag */
+#define PAGE_ZIP_DIR_SLOT_OWNED 0x4000
+/** 'deleted' flag */
+#define PAGE_ZIP_DIR_SLOT_DEL 0x8000
/* Whether or not to log compressed page images to avoid possible
compression algorithm changes in zlib. */
extern my_bool page_zip_log_pages;
-#ifndef UNIV_INNOCHECKSUM
/**********************************************************************//**
Determine the size of a compressed page in bytes.
-@return size in bytes */
+@return size in bytes */
UNIV_INLINE
ulint
page_zip_get_size(
@@ -74,24 +99,25 @@ page_zip_set_size(
ulint size); /*!< in: size in bytes */
#ifndef UNIV_HOTBACKUP
-/**********************************************************************//**
-Determine if a record is so big that it needs to be stored externally.
-@return FALSE if the entire record can be stored locally on the page */
+/** Determine if a record is so big that it needs to be stored externally.
+@param[in] rec_size length of the record in bytes
+@param[in] comp nonzero=compact format
+@param[in] n_fields number of fields in the record; ignored if
+tablespace is not compressed
+@param[in] page_size page size
+@return FALSE if the entire record can be stored locally on the page */
UNIV_INLINE
ibool
page_zip_rec_needs_ext(
-/*===================*/
- ulint rec_size, /*!< in: length of the record in bytes */
- ulint comp, /*!< in: nonzero=compact format */
- ulint n_fields, /*!< in: number of fields in the record;
- ignored if zip_size == 0 */
- ulint zip_size) /*!< in: compressed page size in bytes, or 0 */
- MY_ATTRIBUTE((const));
+ ulint rec_size,
+ ulint comp,
+ ulint n_fields,
+ const page_size_t& page_size)
+ __attribute__((warn_unused_result));
/**********************************************************************//**
Determine the guaranteed free space on an empty page.
-@return minimum payload size on the page */
-UNIV_INTERN
+@return minimum payload size on the page */
ulint
page_zip_empty_size(
/*================*/
@@ -111,36 +137,54 @@ page_zip_des_init(
/**********************************************************************//**
Configure the zlib allocator to use the given memory heap. */
-UNIV_INTERN
void
page_zip_set_alloc(
/*===============*/
void* stream, /*!< in/out: zlib stream */
mem_heap_t* heap); /*!< in: memory heap to use */
-#endif /* !UNIV_INNOCHECKSUM */
/**********************************************************************//**
Compress a page.
@return TRUE on success, FALSE on failure; page_zip will be left
intact on failure. */
-UNIV_INTERN
ibool
page_zip_compress(
/*==============*/
- page_zip_des_t* page_zip,/*!< in: size; out: data, n_blobs,
- m_start, m_end, m_nonempty */
- const page_t* page, /*!< in: uncompressed page */
- dict_index_t* index, /*!< in: index of the B-tree node */
- ulint level, /*!< in: compression level */
- mtr_t* mtr) /*!< in: mini-transaction, or NULL */
- MY_ATTRIBUTE((nonnull(1,2,3)));
+ page_zip_des_t* page_zip, /*!< in: size; out: data,
+ n_blobs, m_start, m_end,
+ m_nonempty */
+ const page_t* page, /*!< in: uncompressed page */
+ dict_index_t* index, /*!< in: index of the B-tree
+ node */
+ ulint level, /*!< in: commpression level */
+ const redo_page_compress_t* page_comp_info,
+ /*!< in: used for applying
+ TRUNCATE log
+ record during recovery */
+ mtr_t* mtr); /*!< in/out: mini-transaction,
+ or NULL */
+
+/**********************************************************************//**
+Write the index information for the compressed page.
+@return used size of buf */
+ulint
+page_zip_fields_encode(
+/*===================*/
+ ulint n, /*!< in: number of fields
+ to compress */
+ const dict_index_t* index, /*!< in: index comprising
+ at least n fields */
+ ulint trx_id_pos,
+ /*!< in: position of the trx_id column
+ in the index, or ULINT_UNDEFINED if
+ this is a non-leaf page */
+ byte* buf); /*!< out: buffer of (n + 1) * 2 bytes */
/**********************************************************************//**
Decompress a page. This function should tolerate errors on the compressed
page. Instead of letting assertions fail, it will return FALSE if an
inconsistency is detected.
-@return TRUE on success, FALSE on failure */
-UNIV_INTERN
+@return TRUE on success, FALSE on failure */
ibool
page_zip_decompress(
/*================*/
@@ -153,11 +197,10 @@ page_zip_decompress(
after page creation */
MY_ATTRIBUTE((nonnull(1,2)));
-#ifndef UNIV_INNOCHECKSUM
#ifdef UNIV_DEBUG
/**********************************************************************//**
Validate a compressed page descriptor.
-@return TRUE if ok */
+@return TRUE if ok */
UNIV_INLINE
ibool
page_zip_simple_validate(
@@ -165,13 +208,11 @@ page_zip_simple_validate(
const page_zip_des_t* page_zip); /*!< in: compressed page
descriptor */
#endif /* UNIV_DEBUG */
-#endif /* !UNIV_INNOCHECKSUM */
#ifdef UNIV_ZIP_DEBUG
/**********************************************************************//**
Check that the compressed and decompressed pages match.
-@return TRUE if valid, FALSE if not */
-UNIV_INTERN
+@return TRUE if valid, FALSE if not */
ibool
page_zip_validate_low(
/*==================*/
@@ -183,7 +224,6 @@ page_zip_validate_low(
MY_ATTRIBUTE((nonnull(1,2)));
/**********************************************************************//**
Check that the compressed and decompressed pages match. */
-UNIV_INTERN
ibool
page_zip_validate(
/*==============*/
@@ -193,7 +233,6 @@ page_zip_validate(
MY_ATTRIBUTE((nonnull(1,2)));
#endif /* UNIV_ZIP_DEBUG */
-#ifndef UNIV_INNOCHECKSUM
/**********************************************************************//**
Determine how big record can be inserted without recompressing the page.
@return a positive number indicating the maximum size of a record
@@ -208,7 +247,7 @@ page_zip_max_ins_size(
/**********************************************************************//**
Determine if enough space is available in the modification log.
-@return TRUE if page_zip_write_rec() will succeed */
+@return TRUE if page_zip_write_rec() will succeed */
UNIV_INLINE
ibool
page_zip_available(
@@ -236,7 +275,6 @@ page_zip_write_header(
/**********************************************************************//**
Write an entire record on the compressed page. The data must already
have been written to the uncompressed page. */
-UNIV_INTERN
void
page_zip_write_rec(
/*===============*/
@@ -249,8 +287,7 @@ page_zip_write_rec(
/***********************************************************//**
Parses a log record of writing a BLOB pointer of a record.
-@return end of log record or NULL */
-UNIV_INTERN
+@return end of log record or NULL */
byte*
page_zip_parse_write_blob_ptr(
/*==========================*/
@@ -262,7 +299,6 @@ page_zip_parse_write_blob_ptr(
/**********************************************************************//**
Write a BLOB pointer of a record on the leaf page of a clustered index.
The information must already have been updated on the uncompressed page. */
-UNIV_INTERN
void
page_zip_write_blob_ptr(
/*====================*/
@@ -272,14 +308,12 @@ page_zip_write_blob_ptr(
dict_index_t* index, /*!< in: index of the page */
const ulint* offsets,/*!< in: rec_get_offsets(rec, index) */
ulint n, /*!< in: column index */
- mtr_t* mtr) /*!< in: mini-transaction handle,
+ mtr_t* mtr); /*!< in: mini-transaction handle,
or NULL if no logging is needed */
- MY_ATTRIBUTE((nonnull(1,2,3,4)));
/***********************************************************//**
Parses a log record of writing the node pointer of a record.
-@return end of log record or NULL */
-UNIV_INTERN
+@return end of log record or NULL */
byte*
page_zip_parse_write_node_ptr(
/*==========================*/
@@ -290,7 +324,6 @@ page_zip_parse_write_node_ptr(
/**********************************************************************//**
Write the node pointer of a record on a non-leaf compressed page. */
-UNIV_INTERN
void
page_zip_write_node_ptr(
/*====================*/
@@ -298,12 +331,10 @@ page_zip_write_node_ptr(
byte* rec, /*!< in/out: record */
ulint size, /*!< in: data size of rec */
ulint ptr, /*!< in: node pointer */
- mtr_t* mtr) /*!< in: mini-transaction, or NULL */
- MY_ATTRIBUTE((nonnull(1,2)));
+ mtr_t* mtr); /*!< in: mini-transaction, or NULL */
/**********************************************************************//**
Write the trx_id and roll_ptr of a record on a B-tree leaf node page. */
-UNIV_INTERN
void
page_zip_write_trx_id_and_roll_ptr(
/*===============================*/
@@ -318,7 +349,6 @@ page_zip_write_trx_id_and_roll_ptr(
/**********************************************************************//**
Write the "deleted" flag of a record on a compressed page. The flag must
already have been written on the uncompressed page. */
-UNIV_INTERN
void
page_zip_rec_set_deleted(
/*=====================*/
@@ -330,7 +360,6 @@ page_zip_rec_set_deleted(
/**********************************************************************//**
Write the "owned" flag of a record on a compressed page. The n_owned field
must already have been written on the uncompressed page. */
-UNIV_INTERN
void
page_zip_rec_set_owned(
/*===================*/
@@ -341,7 +370,6 @@ page_zip_rec_set_owned(
/**********************************************************************//**
Insert a record to the dense page directory. */
-UNIV_INTERN
void
page_zip_dir_insert(
/*================*/
@@ -354,7 +382,6 @@ page_zip_dir_insert(
/**********************************************************************//**
Shift the dense page directory and the array of BLOB pointers
when a record is deleted. */
-UNIV_INTERN
void
page_zip_dir_delete(
/*================*/
@@ -368,7 +395,6 @@ page_zip_dir_delete(
/**********************************************************************//**
Add a slot to the dense page directory. */
-UNIV_INTERN
void
page_zip_dir_add_slot(
/*==================*/
@@ -379,8 +405,7 @@ page_zip_dir_add_slot(
/***********************************************************//**
Parses a log record of writing to the header of a page.
-@return end of log record or NULL */
-UNIV_INTERN
+@return end of log record or NULL */
byte*
page_zip_parse_write_header(
/*========================*/
@@ -416,7 +441,6 @@ bits in the same mini-transaction in such a way that the modification
will be redo-logged.
@return TRUE on success, FALSE on failure; page_zip will be left
intact on failure, but page will be overwritten. */
-UNIV_INTERN
ibool
page_zip_reorganize(
/*================*/
@@ -427,15 +451,12 @@ page_zip_reorganize(
dict_index_t* index, /*!< in: index of the B-tree node */
mtr_t* mtr) /*!< in: mini-transaction */
MY_ATTRIBUTE((nonnull));
-#endif /* !UNIV_INNOCHECKSUM */
-
#ifndef UNIV_HOTBACKUP
/**********************************************************************//**
Copy the records of a page byte for byte. Do not copy the page header
or trailer, except those B-tree header fields that are directly
related to the storage of records. Also copy PAGE_MAX_TRX_ID.
NOTE: The caller must update the lock table and the adaptive hash index. */
-UNIV_INTERN
void
page_zip_copy_recs(
/*===============*/
@@ -446,45 +467,58 @@ page_zip_copy_recs(
const page_zip_des_t* src_zip, /*!< in: compressed page */
const page_t* src, /*!< in: page */
dict_index_t* index, /*!< in: index of the B-tree */
- mtr_t* mtr) /*!< in: mini-transaction */
- MY_ATTRIBUTE((nonnull));
+ mtr_t* mtr); /*!< in: mini-transaction */
#endif /* !UNIV_HOTBACKUP */
/**********************************************************************//**
Parses a log record of compressing an index page.
-@return end of log record or NULL */
-UNIV_INTERN
+@return end of log record or NULL */
byte*
page_zip_parse_compress(
/*====================*/
- byte* ptr, /*!< in: buffer */
- byte* end_ptr,/*!< in: buffer end */
- page_t* page, /*!< out: uncompressed page */
- page_zip_des_t* page_zip)/*!< out: compressed page */
- MY_ATTRIBUTE((nonnull(1,2)));
+ byte* ptr, /*!< in: buffer */
+ byte* end_ptr, /*!< in: buffer end */
+ page_t* page, /*!< out: uncompressed page */
+ page_zip_des_t* page_zip); /*!< out: compressed page */
-/**********************************************************************//**
-Calculate the compressed page checksum.
-@return page checksum */
-UNIV_INTERN
-ulint
+#endif /* !UNIV_INNOCHECKSUM */
+
+/** Calculate the compressed page checksum.
+@param[in] data compressed page
+@param[in] size size of compressed page
+@param[in] algo algorithm to use
+@param[in] use_legacy_big_endian only used if algo is
+SRV_CHECKSUM_ALGORITHM_CRC32 or SRV_CHECKSUM_ALGORITHM_STRICT_CRC32 - if true
+then use big endian byteorder when converting byte strings to integers.
+@return page checksum */
+uint32_t
page_zip_calc_checksum(
-/*===================*/
- const void* data, /*!< in: compressed page */
- ulint size, /*!< in: size of compressed page */
- srv_checksum_algorithm_t algo) /*!< in: algorithm to use */
- MY_ATTRIBUTE((nonnull));
+ const void* data,
+ ulint size,
+ srv_checksum_algorithm_t algo,
+ bool use_legacy_big_endian = false);
/**********************************************************************//**
Verify a compressed page's checksum.
-@return TRUE if the stored checksum is valid according to the value of
+@return TRUE if the stored checksum is valid according to the value of
innodb_checksum_algorithm */
-UNIV_INTERN
ibool
page_zip_verify_checksum(
/*=====================*/
const void* data, /*!< in: compressed page */
- ulint size); /*!< in: size of compressed page */
+ ulint size /*!< in: size of compressed page */
+#ifdef UNIV_INNOCHECKSUM
+ /* these variables are used only for innochecksum tool. */
+ ,uintmax_t page_no, /*!< in: page number of
+ given read_buf */
+ bool strict_check, /*!< in: true if strict-check
+ option is enable */
+ bool is_log_enabled, /*!< in: true if log option is
+ enable */
+ FILE* log_file /*!< in: file pointer to
+ log_file */
+#endif /* UNIV_INNOCHECKSUM */
+);
#ifndef UNIV_INNOCHECKSUM
/**********************************************************************//**
@@ -499,7 +533,7 @@ page_zip_compress_write_log_no_data(
mtr_t* mtr); /*!< in: mtr */
/**********************************************************************//**
Parses a log record of compressing an index page without the data.
-@return end of log record or NULL */
+@return end of log record or NULL */
UNIV_INLINE
byte*
page_zip_parse_compress_no_data(
@@ -519,24 +553,22 @@ void
page_zip_reset_stat_per_index();
/*===========================*/
-#endif /* !UNIV_INNOCHECKSUM */
-
#ifndef UNIV_HOTBACKUP
/** Check if a pointer to an uncompressed page matches a compressed page.
When we IMPORT a tablespace the blocks and accompanying frames are allocted
from outside the buffer pool.
-@param ptr pointer to an uncompressed page frame
-@param page_zip compressed page descriptor
-@return TRUE if ptr and page_zip refer to the same block */
+@param ptr pointer to an uncompressed page frame
+@param page_zip compressed page descriptor
+@return TRUE if ptr and page_zip refer to the same block */
# define PAGE_ZIP_MATCH(ptr, page_zip) \
(((page_zip)->m_external \
&& (page_align(ptr) + UNIV_PAGE_SIZE == (page_zip)->data)) \
|| buf_frame_get_page_zip(ptr) == (page_zip))
#else /* !UNIV_HOTBACKUP */
/** Check if a pointer to an uncompressed page matches a compressed page.
-@param ptr pointer to an uncompressed page frame
-@param page_zip compressed page descriptor
-@return TRUE if ptr and page_zip refer to the same block */
+@param ptr pointer to an uncompressed page frame
+@param page_zip compressed page descriptor
+@return TRUE if ptr and page_zip refer to the same block */
# define PAGE_ZIP_MATCH(ptr, page_zip) \
(page_align(ptr) + UNIV_PAGE_SIZE == (page_zip)->data)
#endif /* !UNIV_HOTBACKUP */
@@ -546,7 +578,10 @@ from outside the buffer pool.
# define UNIV_INLINE UNIV_INLINE_ORIGINAL
#endif
-#ifdef UNIV_INNOCHECKSUM
+#ifndef UNIV_NONINL
+# include "page0zip.ic"
+#endif
+
/** Issue a warning when the checksum that is stored in the page is valid,
but different than the global setting innodb_checksum_algorithm.
@param[in] current_algo current checksum algorithm
@@ -559,12 +594,7 @@ page_warn_strict_checksum(
srv_checksum_algorithm_t page_checksum,
ulint space_id,
ulint page_no);
-#endif /* UNIV_INNOCHECKSUM */
-#ifndef UNIV_INNOCHECKSUM
-#ifndef UNIV_NONINL
-# include "page0zip.ic"
-#endif
#endif /* !UNIV_INNOCHECKSUM */
#endif /* page0zip_h */