2013-12-19 14:36:38 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
|
2015-06-03 13:10:18 +03:00
|
|
|
Copyright (C) 2013, 2015, MariaDB Corporation. All Rights Reserved.
|
2013-12-19 14:36:38 +02:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU General Public License as published by the Free Software
|
|
|
|
Foundation; version 2 of the License.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
|
|
this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
/******************************************************************//**
|
|
|
|
@file include/fsp0pagecompress.ic
|
|
|
|
Implementation for helper functions for extracting/storing page
|
|
|
|
compression and atomic writes information to file space.
|
|
|
|
|
2015-09-21 11:24:08 +03:00
|
|
|
Created 11/12/2013 Jan Lindström jan.lindstrom@mariadb.com
|
|
|
|
|
2013-12-19 14:36:38 +02:00
|
|
|
***********************************************************************/
|
|
|
|
|
|
|
|
/********************************************************************//**
|
|
|
|
Determine if the tablespace is page compressed from dict_table_t::flags.
|
|
|
|
@return TRUE if page compressed, FALSE if not page compressed */
|
|
|
|
UNIV_INLINE
|
|
|
|
ibool
|
|
|
|
fsp_flags_is_page_compressed(
|
|
|
|
/*=========================*/
|
|
|
|
ulint flags) /*!< in: tablespace flags */
|
|
|
|
{
|
|
|
|
return(FSP_FLAGS_GET_PAGE_COMPRESSION(flags));
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************//**
|
|
|
|
Determine the tablespace is page compression level from dict_table_t::flags.
|
|
|
|
@return page compression level or 0 if not compressed*/
|
|
|
|
UNIV_INLINE
|
|
|
|
ulint
|
|
|
|
fsp_flags_get_page_compression_level(
|
|
|
|
/*=================================*/
|
|
|
|
ulint flags) /*!< in: tablespace flags */
|
|
|
|
{
|
|
|
|
return(FSP_FLAGS_GET_PAGE_COMPRESSION_LEVEL(flags));
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************//**
|
|
|
|
Determine the tablespace is using atomic writes from dict_table_t::flags.
|
|
|
|
@return true if atomic writes is used, false if not */
|
|
|
|
UNIV_INLINE
|
2014-01-10 12:11:36 +02:00
|
|
|
atomic_writes_t
|
2013-12-19 14:36:38 +02:00
|
|
|
fsp_flags_get_atomic_writes(
|
|
|
|
/*========================*/
|
|
|
|
ulint flags) /*!< in: tablespace flags */
|
|
|
|
{
|
2014-01-10 12:11:36 +02:00
|
|
|
return((atomic_writes_t)FSP_FLAGS_GET_ATOMIC_WRITES(flags));
|
2013-12-19 14:36:38 +02:00
|
|
|
}
|
2014-01-13 15:02:31 +02:00
|
|
|
|
|
|
|
/*******************************************************************//**
|
|
|
|
Find out wheather the page is index page or not
|
|
|
|
@return true if page type index page, false if not */
|
|
|
|
UNIV_INLINE
|
|
|
|
ibool
|
|
|
|
fil_page_is_index_page(
|
|
|
|
/*===================*/
|
2015-06-03 13:10:18 +03:00
|
|
|
byte* buf) /*!< in: page */
|
2014-01-13 15:02:31 +02:00
|
|
|
{
|
|
|
|
return(mach_read_from_2(buf+FIL_PAGE_TYPE) == FIL_PAGE_INDEX);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************//**
|
|
|
|
Find out wheather the page is page compressed
|
|
|
|
@return true if page is page compressed, false if not */
|
|
|
|
UNIV_INLINE
|
|
|
|
ibool
|
|
|
|
fil_page_is_compressed(
|
|
|
|
/*===================*/
|
2015-06-03 13:10:18 +03:00
|
|
|
byte* buf) /*!< in: page */
|
2014-01-13 15:02:31 +02:00
|
|
|
{
|
|
|
|
return(mach_read_from_2(buf+FIL_PAGE_TYPE) == FIL_PAGE_PAGE_COMPRESSED);
|
|
|
|
}
|
|
|
|
|
2015-06-03 13:10:18 +03:00
|
|
|
/*******************************************************************//**
|
|
|
|
Find out wheather the page is page compressed
|
|
|
|
@return true if page is page compressed, false if not */
|
|
|
|
UNIV_INLINE
|
|
|
|
ibool
|
|
|
|
fil_page_is_compressed_encrypted(
|
|
|
|
/*=============================*/
|
|
|
|
byte* buf) /*!< in: page */
|
|
|
|
{
|
|
|
|
return(mach_read_from_2(buf+FIL_PAGE_TYPE) == FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED);
|
|
|
|
}
|
|
|
|
|
2015-09-19 11:30:18 +03:00
|
|
|
#ifndef UNIV_INNOCHECKSUM
|
2014-01-13 15:02:31 +02:00
|
|
|
/*******************************************************************//**
|
|
|
|
Returns the page compression level of the space, or 0 if the space
|
|
|
|
is not compressed. The tablespace must be cached in the memory cache.
|
2015-09-21 11:24:08 +03:00
|
|
|
@return page compression level, 0 if space not found */
|
2014-01-13 15:02:31 +02:00
|
|
|
UNIV_INLINE
|
|
|
|
ulint
|
|
|
|
fil_space_get_page_compression_level(
|
|
|
|
/*=================================*/
|
|
|
|
ulint id) /*!< in: space id */
|
|
|
|
{
|
|
|
|
ulint flags;
|
|
|
|
|
|
|
|
flags = fil_space_get_flags(id);
|
|
|
|
|
|
|
|
if (flags && flags != ULINT_UNDEFINED) {
|
|
|
|
|
|
|
|
return(fsp_flags_get_page_compression_level(flags));
|
|
|
|
}
|
|
|
|
|
2015-09-21 11:24:08 +03:00
|
|
|
return(0);
|
2014-01-13 15:02:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************//**
|
|
|
|
Extract the page compression from space.
|
|
|
|
@return true if space is page compressed, false if space is not found
|
|
|
|
or space is not page compressed. */
|
|
|
|
UNIV_INLINE
|
|
|
|
ibool
|
|
|
|
fil_space_is_page_compressed(
|
|
|
|
/*=========================*/
|
|
|
|
ulint id) /*!< in: space id */
|
|
|
|
{
|
|
|
|
ulint flags;
|
|
|
|
|
|
|
|
flags = fil_space_get_flags(id);
|
|
|
|
|
|
|
|
if (flags && flags != ULINT_UNDEFINED) {
|
|
|
|
|
|
|
|
return(fsp_flags_is_page_compressed(flags));
|
|
|
|
}
|
|
|
|
|
2015-09-21 11:24:08 +03:00
|
|
|
return(0);
|
2014-01-13 15:02:31 +02:00
|
|
|
}
|
|
|
|
|
2015-09-19 11:30:18 +03:00
|
|
|
#endif /* UNIV_INNOCHECKSUM */
|
|
|
|
|
2014-01-13 15:02:31 +02:00
|
|
|
/****************************************************************//**
|
|
|
|
Get the name of the compression algorithm used for page
|
|
|
|
compression.
|
|
|
|
@return compression algorithm name or "UNKNOWN" if not known*/
|
|
|
|
UNIV_INLINE
|
|
|
|
const char*
|
|
|
|
fil_get_compression_alg_name(
|
|
|
|
/*=========================*/
|
2015-06-03 13:10:18 +03:00
|
|
|
ulint comp_alg) /*!<in: compression algorithm number */
|
2014-01-13 15:02:31 +02:00
|
|
|
{
|
|
|
|
switch(comp_alg) {
|
2014-05-22 14:24:00 +03:00
|
|
|
case PAGE_UNCOMPRESSED:
|
|
|
|
return ("uncompressed");
|
|
|
|
break;
|
|
|
|
case PAGE_ZLIB_ALGORITHM:
|
2014-01-13 15:02:31 +02:00
|
|
|
return ("ZLIB");
|
|
|
|
break;
|
2014-05-22 14:24:00 +03:00
|
|
|
case PAGE_LZ4_ALGORITHM:
|
2014-02-03 10:08:15 +02:00
|
|
|
return ("LZ4");
|
|
|
|
break;
|
2014-05-22 14:24:00 +03:00
|
|
|
case PAGE_LZO_ALGORITHM:
|
|
|
|
return ("LZO");
|
|
|
|
break;
|
2014-07-21 22:21:30 +03:00
|
|
|
case PAGE_LZMA_ALGORITHM:
|
|
|
|
return ("LZMA");
|
|
|
|
break;
|
2015-09-19 11:30:18 +03:00
|
|
|
case PAGE_BZIP2_ALGORITHM:
|
|
|
|
return ("BZIP2");
|
|
|
|
break;
|
|
|
|
case PAGE_SNAPPY_ALGORITHM:
|
|
|
|
return ("SNAPPY");
|
2014-01-13 15:02:31 +02:00
|
|
|
break;
|
2015-09-19 11:30:18 +03:00
|
|
|
/* No default to get compiler warning */
|
2014-01-13 15:02:31 +02:00
|
|
|
}
|
2015-09-19 11:30:18 +03:00
|
|
|
|
|
|
|
return ("NULL");
|
2014-01-13 15:02:31 +02:00
|
|
|
}
|
|
|
|
|
2015-09-19 11:30:18 +03:00
|
|
|
#ifndef UNIV_INNOCHECKSUM
|
2014-01-13 15:02:31 +02:00
|
|
|
/*******************************************************************//**
|
|
|
|
Returns the atomic writes flag of the space, or false if the space
|
|
|
|
is not using atomic writes. The tablespace must be cached in the memory cache.
|
|
|
|
@return atomic writes table option value */
|
|
|
|
UNIV_INLINE
|
|
|
|
atomic_writes_t
|
|
|
|
fil_space_get_atomic_writes(
|
|
|
|
/*========================*/
|
|
|
|
ulint id) /*!< in: space id */
|
|
|
|
{
|
|
|
|
ulint flags;
|
|
|
|
|
|
|
|
flags = fil_space_get_flags(id);
|
|
|
|
|
|
|
|
if (flags && flags != ULINT_UNDEFINED) {
|
|
|
|
|
|
|
|
return((atomic_writes_t)fsp_flags_get_atomic_writes(flags));
|
|
|
|
}
|
|
|
|
|
|
|
|
return((atomic_writes_t)0);
|
|
|
|
}
|
2014-12-03 10:41:52 +02:00
|
|
|
|
|
|
|
/*******************************************************************//**
|
|
|
|
Find out wheather the page is page compressed with lzo method
|
|
|
|
@return true if page is page compressed with lzo method, false if not */
|
|
|
|
UNIV_INLINE
|
|
|
|
ibool
|
|
|
|
fil_page_is_lzo_compressed(
|
|
|
|
/*=======================*/
|
2015-06-03 13:10:18 +03:00
|
|
|
byte* buf) /*!< in: page */
|
2014-12-03 10:41:52 +02:00
|
|
|
{
|
2015-06-03 13:10:18 +03:00
|
|
|
return((mach_read_from_2(buf+FIL_PAGE_TYPE) == FIL_PAGE_PAGE_COMPRESSED &&
|
|
|
|
mach_read_from_8(buf+FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION) == PAGE_LZO_ALGORITHM) ||
|
|
|
|
(mach_read_from_2(buf+FIL_PAGE_TYPE) == FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED &&
|
|
|
|
mach_read_from_2(buf+FIL_PAGE_DATA+FIL_PAGE_COMPRESSED_SIZE) == PAGE_LZO_ALGORITHM));
|
2014-12-03 10:41:52 +02:00
|
|
|
}
|
2015-09-19 11:30:18 +03:00
|
|
|
|
|
|
|
#endif /* UNIV_INNOCHECKSUM */
|