Commit ba573c47 authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-21133 follow-up: More my_assume_aligned hints

fsp0pagecompress.h: Remove.
Invoke fil_page_get_type() and FSP_FLAGS_GET_PAGE_COMPRESSION_LEVEL
directly.

log_block_get_flush_bit(), log_block_set_flush_bit():
Access the byte directly.

dict_sys_read_row_id(): Remove (unused function).
parent 0781c91d
/*
Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2014, 2019, MariaDB Corporation.
Copyright (c) 2014, 2020, MariaDB Corporation.
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
......@@ -49,7 +49,6 @@ The parts not included are excluded by #ifndef UNIV_INNOCHECKSUM. */
#include "page0zip.h" /* page_zip_*() */
#include "trx0undo.h" /* TRX_* */
#include "ut0crc32.h" /* ut_crc32_init() */
#include "fsp0pagecompress.h" /* fil_get_compression_alg_name */
#include "fil0crypt.h" /* fil_space_verify_crypt_checksum */
#include <string.h>
......
......@@ -61,7 +61,6 @@ Created 11/5/1995 Heikki Tuuri
#include "srv0mon.h"
#include "log0crypt.h"
#include "fil0pagecompress.h"
#include "fsp0pagecompress.h"
#endif /* !UNIV_INNOCHECKSUM */
#include "page0zip.h"
#include "sync0sync.h"
......@@ -470,12 +469,14 @@ static bool buf_page_decrypt_after_read(buf_page_t* bpage, fil_space_t* space)
ut_d(fil_page_type_validate(space, dst_frame));
if ((space->full_crc32() && page_compressed)
|| fil_page_is_compressed_encrypted(dst_frame)) {
|| fil_page_get_type(dst_frame)
== FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED) {
goto decompress_with_slot;
}
slot->release();
} else if (fil_page_is_compressed_encrypted(dst_frame)) {
} else if (fil_page_get_type(dst_frame)
== FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED) {
goto decompress;
}
......
/*****************************************************************************
Copyright (C) 2013, 2019, MariaDB Corporation.
Copyright (C) 2013, 2020, MariaDB Corporation.
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
......@@ -201,7 +201,7 @@ static ulint fil_page_compress_for_full_crc32(
ulint block_size,
bool encrypted)
{
ulint comp_level = fsp_flags_get_page_compression_level(flags);
ulint comp_level = FSP_FLAGS_GET_PAGE_COMPRESSION_LEVEL(flags);
if (comp_level == 0) {
comp_level = page_zip_level;
......@@ -284,7 +284,8 @@ static ulint fil_page_compress_for_non_full_crc32(
ulint block_size,
bool encrypted)
{
int comp_level = int(fsp_flags_get_page_compression_level(flags));
uint comp_level = static_cast<uint>(
FSP_FLAGS_GET_PAGE_COMPRESSION_LEVEL(flags));
ulint header_len = FIL_PAGE_DATA + FIL_PAGE_COMP_METADATA_LEN;
/* Cache to avoid change during function execution */
ulint comp_algo = innodb_compression_algorithm;
......@@ -296,7 +297,7 @@ static ulint fil_page_compress_for_non_full_crc32(
/* If no compression level was provided to this table, use system
default level */
if (comp_level == 0) {
comp_level = int(page_zip_level);
comp_level = page_zip_level;
}
ulint write_size = fil_page_compress_low(
......@@ -334,8 +335,14 @@ static ulint fil_page_compress_for_non_full_crc32(
#ifdef UNIV_DEBUG
/* Verify */
ut_ad(fil_page_is_compressed(out_buf)
|| fil_page_is_compressed_encrypted(out_buf));
switch (fil_page_get_type(out_buf)) {
case FIL_PAGE_PAGE_COMPRESSED:
case FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED:
break;
default:
ut_ad("wrong page type" == 0);
break;
}
ut_ad(mach_read_from_4(out_buf + FIL_PAGE_SPACE_OR_CHKSUM)
== BUF_NO_CHECKSUM_MAGIC);
......
......@@ -282,7 +282,8 @@ btr_page_get_index_id(
@retval 0 for leaf pages */
inline uint16_t btr_page_get_level(const page_t *page)
{
uint16_t level = mach_read_from_2(page + PAGE_HEADER + PAGE_LEVEL);
uint16_t level= mach_read_from_2(my_assume_aligned<2>
(PAGE_HEADER + PAGE_LEVEL + page));
ut_ad(level <= BTR_MAX_NODE_LEVEL);
return level;
} MY_ATTRIBUTE((warn_unused_result))
......@@ -292,7 +293,7 @@ inline uint16_t btr_page_get_level(const page_t *page)
@return previous page number */
inline uint32_t btr_page_get_next(const page_t* page)
{
return mach_read_from_4(page + FIL_PAGE_NEXT);
return mach_read_from_4(my_assume_aligned<4>(page + FIL_PAGE_NEXT));
}
/** Read FIL_PAGE_PREV.
......@@ -300,7 +301,7 @@ inline uint32_t btr_page_get_next(const page_t* page)
@return previous page number */
inline uint32_t btr_page_get_prev(const page_t* page)
{
return mach_read_from_4(page + FIL_PAGE_PREV);
return mach_read_from_4(my_assume_aligned<4>(page + FIL_PAGE_PREV));
}
/**************************************************************//**
......
......@@ -34,6 +34,7 @@ Created 11/5/1995 Heikki Tuuri
#include "mtr0types.h"
#include "buf0types.h"
#include "span.h"
#include "assume_aligned.h"
#ifndef UNIV_INNOCHECKSUM
#include "hash0hash.h"
#include "ut0byte.h"
......@@ -572,10 +573,11 @@ stored in 26th position.
@return key version of the page. */
inline uint32_t buf_page_get_key_version(const byte* read_buf, ulint fsp_flags)
{
return fil_space_t::full_crc32(fsp_flags)
? mach_read_from_4(read_buf + FIL_PAGE_FCRC32_KEY_VERSION)
: mach_read_from_4(read_buf
+ FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION);
static_assert(FIL_PAGE_FCRC32_KEY_VERSION == 0, "compatibility");
return fil_space_t::full_crc32(fsp_flags)
? mach_read_from_4(my_assume_aligned<4>(read_buf))
: mach_read_from_4(my_assume_aligned<2>
(read_buf + FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION));
}
/** Read the compression info from the page. In full crc32 format,
......@@ -586,10 +588,11 @@ stored in page type.
@return true if page is compressed. */
inline bool buf_page_is_compressed(const byte* read_buf, ulint fsp_flags)
{
ulint page_type = mach_read_from_2(read_buf + FIL_PAGE_TYPE);
return fil_space_t::full_crc32(fsp_flags)
? !!(page_type & 1U << FIL_PAGE_COMPRESS_FCRC32_MARKER)
: page_type == FIL_PAGE_PAGE_COMPRESSED;
uint16_t page_type= mach_read_from_2(my_assume_aligned<2>
(read_buf + FIL_PAGE_TYPE));
return fil_space_t::full_crc32(fsp_flags)
? !!(page_type & 1U << FIL_PAGE_COMPRESS_FCRC32_MARKER)
: page_type == FIL_PAGE_PAGE_COMPRESSED;
}
/** Get the compressed or uncompressed size of a full_crc32 page.
......@@ -599,7 +602,7 @@ inline bool buf_page_is_compressed(const byte* read_buf, ulint fsp_flags)
@return the payload size in the file page */
inline uint buf_page_full_crc32_size(const byte* buf, bool* comp, bool* cr)
{
uint t = mach_read_from_2(buf + FIL_PAGE_TYPE);
uint t = mach_read_from_2(my_assume_aligned<2>(buf + FIL_PAGE_TYPE));
uint page_size = uint(srv_page_size);
if (!(t & 1U << FIL_PAGE_COMPRESS_FCRC32_MARKER)) {
......
/*****************************************************************************
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2018, 2019, MariaDB Corporation.
Copyright (c) 2018, 2020, MariaDB Corporation.
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
......@@ -60,14 +60,6 @@ row_id_t
dict_sys_get_new_row_id(void);
/*=========================*/
/**********************************************************************//**
Reads a row id from a record or other 6-byte stored form.
@return row id */
UNIV_INLINE
row_id_t
dict_sys_read_row_id(
/*=================*/
const byte* field); /*!< in: record field */
/**********************************************************************//**
Writes a row id to a record or other 6-byte stored form. */
UNIV_INLINE
void
......
/*****************************************************************************
Copyright (c) 1996, 2013, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2020, MariaDB Corporation.
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
......@@ -49,19 +50,6 @@ dict_sys_get_new_row_id(void)
return(id);
}
/**********************************************************************//**
Reads a row id from a record or other 6-byte stored form.
@return row id */
UNIV_INLINE
row_id_t
dict_sys_read_row_id(
/*=================*/
const byte* field) /*!< in: record field */
{
compile_time_assert(DATA_ROW_ID_LEN == 6);
return(mach_read_from_6(field));
}
/**********************************************************************//**
Writes a row id to a record or other 6-byte stored form. */
UNIV_INLINE
......
......@@ -20,7 +20,6 @@ this program; if not, write to the Free Software Foundation, Inc.,
#define fil0pagecompress_h
#include "fsp0fsp.h"
#include "fsp0pagecompress.h"
/******************************************************************//**
@file include/fil0pagecompress.h
......
......@@ -307,11 +307,10 @@ inline bool xdes_is_free(const xdes_t *descr, ulint offset)
@param[in] page first page of a tablespace
@param[in] field the header field
@return the contents of the header field */
inline
ulint
fsp_header_get_field(const page_t* page, ulint field)
inline uint32_t fsp_header_get_field(const page_t* page, ulint field)
{
return(mach_read_from_4(FSP_HEADER_OFFSET + field + page));
return mach_read_from_4(FSP_HEADER_OFFSET + field +
my_assume_aligned<UNIV_ZIP_SIZE_MIN>(page));
}
/** Read the flags from the tablespace header page.
......
/*****************************************************************************
Copyright (C) 2013, 2017, MariaDB Corporation. All Rights Reserved.
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-1335 USA
*****************************************************************************/
/******************************************************************//**
@file include/fsp0pagecompress.h
Helper functions for extracting/storing page compression and
atomic writes information to file space.
Created 11/12/2013 Jan Lindström jan.lindstrom@skysql.com
***********************************************************************/
#ifndef fsp0pagecompress_h
#define fsp0pagecompress_h
/**********************************************************************//**
Reads the page compression level from the first page of a tablespace.
@return page compression level, or 0 if uncompressed */
UNIV_INTERN
ulint
fsp_header_get_compression_level(
/*=============================*/
const page_t* page); /*!< in: first page of a tablespace */
/********************************************************************//**
Extract the page compression level from tablespace flags.
A tablespace has only one physical page compression level
whether that page is compressed or not.
@return page compression level of the file-per-table tablespace,
or zero if the table is not compressed. */
UNIV_INLINE
ulint
fsp_flags_get_page_compression_level(
/*=================================*/
ulint flags); /*!< in: tablespace flags */
#include "fsp0pagecompress.ic"
#endif
/*****************************************************************************
Copyright (C) 2013, 2018, MariaDB Corporation.
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-1335 USA
*****************************************************************************/
/******************************************************************//**
@file include/fsp0pagecompress.ic
Implementation for helper functions for extracting/storing page
compression and atomic writes information to file space.
Created 11/12/2013 Jan Lindström jan.lindstrom@mariadb.com
***********************************************************************/
/********************************************************************//**
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));
}
/*******************************************************************//**
Find out wheather the page is page compressed
@return true if page is page compressed, false if not */
UNIV_INLINE
bool
fil_page_is_compressed(
/*===================*/
const byte* buf) /*!< in: page */
{
return(mach_read_from_2(buf+FIL_PAGE_TYPE) == FIL_PAGE_PAGE_COMPRESSED);
}
/*******************************************************************//**
Find out wheather the page is page compressed
@return true if page is page compressed, false if not */
UNIV_INLINE
bool
fil_page_is_compressed_encrypted(
/*=============================*/
const byte* buf) /*!< in: page */
{
return(mach_read_from_2(buf+FIL_PAGE_TYPE) == FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED);
}
......@@ -25,7 +25,7 @@ Created 12/9/1995 Heikki Tuuri
*******************************************************/
#include "mach0data.h"
#include "srv0mon.h"
#include "assume_aligned.h"
#include "ut0crc32.h"
extern ulong srv_log_buffer_size;
......@@ -39,13 +39,10 @@ log_block_get_flush_bit(
/*====================*/
const byte* log_block) /*!< in: log block */
{
if (LOG_BLOCK_FLUSH_BIT_MASK
& mach_read_from_4(log_block + LOG_BLOCK_HDR_NO)) {
static_assert(LOG_BLOCK_HDR_NO == 0, "compatibility");
static_assert(LOG_BLOCK_FLUSH_BIT_MASK == 0x80000000, "compatibility");
return(TRUE);
}
return(FALSE);
return *log_block & 0x80;
}
/************************************************************//**
......@@ -57,17 +54,13 @@ log_block_set_flush_bit(
byte* log_block, /*!< in/out: log block */
ibool val) /*!< in: value to set */
{
ulint field;
field = mach_read_from_4(log_block + LOG_BLOCK_HDR_NO);
if (val) {
field = field | LOG_BLOCK_FLUSH_BIT_MASK;
} else {
field = field & ~LOG_BLOCK_FLUSH_BIT_MASK;
}
static_assert(LOG_BLOCK_HDR_NO == 0, "compatibility");
static_assert(LOG_BLOCK_FLUSH_BIT_MASK == 0x80000000, "compatibility");
mach_write_to_4(log_block + LOG_BLOCK_HDR_NO, field);
if (val)
*log_block|= 0x80;
else
*log_block&= 0x7f;
}
/************************************************************//**
......@@ -79,8 +72,9 @@ log_block_get_hdr_no(
/*=================*/
const byte* log_block) /*!< in: log block */
{
return(~LOG_BLOCK_FLUSH_BIT_MASK
& mach_read_from_4(log_block + LOG_BLOCK_HDR_NO));
static_assert(LOG_BLOCK_HDR_NO == 0, "compatibility");
return mach_read_from_4(my_assume_aligned<4>(log_block)) &
~LOG_BLOCK_FLUSH_BIT_MASK;
}
/************************************************************//**
......@@ -94,10 +88,11 @@ log_block_set_hdr_no(
ulint n) /*!< in: log block number: must be > 0 and
< LOG_BLOCK_FLUSH_BIT_MASK */
{
ut_ad(n > 0);
ut_ad(n < LOG_BLOCK_FLUSH_BIT_MASK);
static_assert(LOG_BLOCK_HDR_NO == 0, "compatibility");
ut_ad(n > 0);
ut_ad(n < LOG_BLOCK_FLUSH_BIT_MASK);
mach_write_to_4(log_block + LOG_BLOCK_HDR_NO, n);
mach_write_to_4(my_assume_aligned<4>(log_block), n);
}
/************************************************************//**
......@@ -109,7 +104,8 @@ log_block_get_data_len(
/*===================*/
const byte* log_block) /*!< in: log block */
{
return(mach_read_from_2(log_block + LOG_BLOCK_HDR_DATA_LEN));
return mach_read_from_2(my_assume_aligned<2>
(log_block + LOG_BLOCK_HDR_DATA_LEN));
}
/************************************************************//**
......@@ -121,7 +117,8 @@ log_block_set_data_len(
byte* log_block, /*!< in/out: log block */
ulint len) /*!< in: data length */
{
mach_write_to_2(log_block + LOG_BLOCK_HDR_DATA_LEN, len);
mach_write_to_2(my_assume_aligned<2>(log_block + LOG_BLOCK_HDR_DATA_LEN),
len);
}
/************************************************************//**
......@@ -134,7 +131,8 @@ log_block_get_first_rec_group(
/*==========================*/
const byte* log_block) /*!< in: log block */
{
return(mach_read_from_2(log_block + LOG_BLOCK_FIRST_REC_GROUP));
return mach_read_from_2(my_assume_aligned<2>
(log_block + LOG_BLOCK_FIRST_REC_GROUP));
}
/************************************************************//**
......@@ -146,7 +144,8 @@ log_block_set_first_rec_group(
byte* log_block, /*!< in/out: log block */
ulint offset) /*!< in: offset, 0 if none */
{
mach_write_to_2(log_block + LOG_BLOCK_FIRST_REC_GROUP, offset);
mach_write_to_2(my_assume_aligned<2>
(log_block + LOG_BLOCK_FIRST_REC_GROUP), offset);
}
/************************************************************//**
......@@ -158,7 +157,8 @@ log_block_get_checkpoint_no(
/*========================*/
const byte* log_block) /*!< in: log block */
{
return(mach_read_from_4(log_block + LOG_BLOCK_CHECKPOINT_NO));
return mach_read_from_4(my_assume_aligned<4>
(log_block + LOG_BLOCK_CHECKPOINT_NO));
}
/************************************************************//**
......@@ -170,7 +170,8 @@ log_block_set_checkpoint_no(
byte* log_block, /*!< in/out: log block */
ib_uint64_t no) /*!< in: checkpoint no */
{
mach_write_to_4(log_block + LOG_BLOCK_CHECKPOINT_NO, (ulint) no);
mach_write_to_4(my_assume_aligned<4>(log_block + LOG_BLOCK_CHECKPOINT_NO),
static_cast<uint32_t>(no));
}
/************************************************************//**
......@@ -204,8 +205,9 @@ log_block_get_checksum(
/*===================*/
const byte* log_block) /*!< in: log block */
{
return(mach_read_from_4(log_block + OS_FILE_LOG_BLOCK_SIZE
- LOG_BLOCK_CHECKSUM));
return mach_read_from_4(my_assume_aligned<4>
(OS_FILE_LOG_BLOCK_SIZE - LOG_BLOCK_CHECKSUM +
log_block));
}
/************************************************************//**
......@@ -217,9 +219,9 @@ log_block_set_checksum(
byte* log_block, /*!< in/out: log block */
ulint checksum) /*!< in: checksum */
{
mach_write_to_4(log_block + OS_FILE_LOG_BLOCK_SIZE
- LOG_BLOCK_CHECKSUM,
checksum);
mach_write_to_4(my_assume_aligned<4>
(OS_FILE_LOG_BLOCK_SIZE - LOG_BLOCK_CHECKSUM +
log_block), checksum);
}
/************************************************************//**
......
......@@ -305,8 +305,8 @@ page_get_page_no(
/*=============*/
const page_t* page) /*!< in: page */
{
ut_ad(page == page_align((page_t*) page));
return(mach_read_from_4(page + FIL_PAGE_OFFSET));
ut_ad(page == page_align((page_t*) page));
return mach_read_from_4(my_assume_aligned<4>(page + FIL_PAGE_OFFSET));
}
#ifndef UNIV_INNOCHECKSUM
......@@ -319,8 +319,9 @@ page_get_space_id(
/*==============*/
const page_t* page) /*!< in: page */
{
ut_ad(page == page_align((page_t*) page));
return(mach_read_from_4(page + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID));
ut_ad(page == page_align((page_t*) page));
return mach_read_from_4(my_assume_aligned<2>
(page + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID));
}
#endif /* !UNIV_INNOCHECKSUM */
......
......@@ -3500,14 +3500,15 @@ fil_iterate(
src + FIL_PAGE_SPACE_ID);
}
const uint16_t type = fil_page_get_type(src);
const bool page_compressed =
(full_crc32
&& fil_space_t::is_compressed(
callback.get_space_flags())
&& buf_page_is_compressed(
src, callback.get_space_flags()))
|| (fil_page_is_compressed_encrypted(src)
|| fil_page_is_compressed(src));
|| type == FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED
|| type == FIL_PAGE_PAGE_COMPRESSED;
if (page_compressed && block->page.zip.data) {
goto page_corrupted;
......
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