mirror of
https://github.com/MariaDB/server.git
synced 2025-01-31 02:51:44 +01:00
765a43605a
Problem was that bpage was referenced after it was already freed from LRU. Fixed by adding a new variable encrypted that is passed down to buf_page_check_corrupt() and used in buf_page_get_gen() to stop processing page read. This patch should also address following test failures and bugs: MDEV-12419: IMPORT should not look up tablespace in PageConverter::validate(). This is now removed. MDEV-10099: encryption.innodb_onlinealter_encryption fails sporadically in buildbot MDEV-11420: encryption.innodb_encryption-page-compression failed in buildbot MDEV-11222: encryption.encrypt_and_grep failed in buildbot on P8 Removed dict_table_t::is_encrypted and dict_table_t::ibd_file_missing and replaced these with dict_table_t::file_unreadable. Table ibd file is missing if fil_get_space(space_id) returns NULL and encrypted if not. Removed dict_table_t::is_corrupted field. Ported FilSpace class from 10.2 and using that on buf_page_check_corrupt(), buf_page_decrypt_after_read(), buf_page_encrypt_before_write(), buf_dblwr_process(), buf_read_page(), dict_stats_save_defrag_stats(). Added test cases when enrypted page could be read while doing redo log crash recovery. Also added test case for row compressed blobs. btr_cur_open_at_index_side_func(), btr_cur_open_at_rnd_pos_func(): Avoid referencing block that is NULL. buf_page_get_zip(): Issue error if page read fails. buf_page_get_gen(): Use dberr_t for error detection and do not reference bpage after we hare freed it. buf_mark_space_corrupt(): remove bpage from LRU also when it is encrypted. buf_page_check_corrupt(): @return DB_SUCCESS if page has been read and is not corrupted, DB_PAGE_CORRUPTED if page based on checksum check is corrupted, DB_DECRYPTION_FAILED if page post encryption checksum matches but after decryption normal page checksum does not match. In read case only DB_SUCCESS is possible. buf_page_io_complete(): use dberr_t for error handling. buf_flush_write_block_low(), buf_read_ahead_random(), buf_read_page_async(), buf_read_ahead_linear(), buf_read_ibuf_merge_pages(), buf_read_recv_pages(), fil_aio_wait(): Issue error if page read fails. btr_pcur_move_to_next_page(): Do not reference page if it is NULL. Introduced dict_table_t::is_readable() and dict_index_t::is_readable() that will return true if tablespace exists and pages read from tablespace are not corrupted or page decryption failed. Removed buf_page_t::key_version. After page decryption the key version is not removed from page frame. For unencrypted pages, old key_version is removed at buf_page_encrypt_before_write() dict_stats_update_transient_for_index(), dict_stats_update_transient() Do not continue if table decryption failed or table is corrupted. dict0stats.cc: Introduced a dict_stats_report_error function to avoid code duplication. fil_parse_write_crypt_data(): Check that key read from redo log entry is found from encryption plugin and if it is not, refuse to start. PageConverter::validate(): Removed access to fil_space_t as tablespace is not available during import. Fixed error code on innodb.innodb test. Merged test cased innodb-bad-key-change5 and innodb-bad-key-shutdown to innodb-bad-key-change2. Removed innodb-bad-key-change5 test. Decreased unnecessary complexity on some long lasting tests. Removed fil_inc_pending_ops(), fil_decr_pending_ops(), fil_get_first_space(), fil_get_next_space(), fil_get_first_space_safe(), fil_get_next_space_safe() functions. fil_space_verify_crypt_checksum(): Fixed bug found using ASAN where FIL_PAGE_END_LSN_OLD_CHECKSUM field was incorrectly accessed from row compressed tables. Fixed out of page frame bug for row compressed tables in fil_space_verify_crypt_checksum() found using ASAN. Incorrect function was called for compressed table. Added new tests for discard, rename table and drop (we should allow them even when page decryption fails). Alter table rename is not allowed. Added test for restart with innodb-force-recovery=1 when page read on redo-recovery cant be decrypted. Added test for corrupted table where both page data and FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION is corrupted. Adjusted the test case innodb_bug14147491 so that it does not anymore expect crash. Instead table is just mostly not usable. fil0fil.h: fil_space_acquire_low is not visible function and fil_space_acquire and fil_space_acquire_silent are inline functions. FilSpace class uses fil_space_acquire_low directly. recv_apply_hashed_log_recs() does not return anything.
190 lines
7.7 KiB
C
190 lines
7.7 KiB
C
/*****************************************************************************
|
|
|
|
Copyright (c) 1995, 2013, Oracle and/or its affiliates. All Rights Reserved.
|
|
Copyright (c) 2015, 2017, 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 Street, Suite 500, Boston, MA 02110-1335 USA
|
|
|
|
*****************************************************************************/
|
|
|
|
/**************************************************//**
|
|
@file include/buf0rea.h
|
|
The database buffer read
|
|
|
|
Created 11/5/1995 Heikki Tuuri
|
|
*******************************************************/
|
|
|
|
#ifndef buf0rea_h
|
|
#define buf0rea_h
|
|
|
|
#include "univ.i"
|
|
#include "buf0types.h"
|
|
|
|
/********************************************************************//**
|
|
High-level function which reads a page asynchronously from a file to the
|
|
buffer buf_pool if it is not already there. Sets the io_fix flag and sets
|
|
an exclusive lock on the buffer frame. The flag is cleared and the x-lock
|
|
released by the i/o-handler thread.
|
|
|
|
@param[in] space space_id
|
|
@param[in] zip_size compressed page size in bytes, or 0
|
|
@param[in] offset page number
|
|
@param[in] trx transaction
|
|
@return DB_SUCCESS if page has been read and is not corrupted,
|
|
@retval DB_PAGE_CORRUPTED if page based on checksum check is corrupted,
|
|
@retval DB_DECRYPTION_FAILED if page post encryption checksum matches but
|
|
after decryption normal page checksum does not match.
|
|
@retval DB_TABLESPACE_DELETED if tablespace .ibd file is missing */
|
|
UNIV_INTERN
|
|
dberr_t
|
|
buf_read_page(
|
|
ulint space,
|
|
ulint zip_size,
|
|
ulint offset,
|
|
trx_t* trx);
|
|
|
|
/********************************************************************//**
|
|
High-level function which reads a page asynchronously from a file to the
|
|
buffer buf_pool if it is not already there. Sets the io_fix flag and sets
|
|
an exclusive lock on the buffer frame. The flag is cleared and the x-lock
|
|
released by the i/o-handler thread.
|
|
@param[in] space Tablespace id
|
|
@param[in] offset Page number */
|
|
UNIV_INTERN
|
|
void
|
|
buf_read_page_async(
|
|
ulint space,
|
|
ulint offset);
|
|
|
|
/********************************************************************//**
|
|
Applies a random read-ahead in buf_pool if there are at least a threshold
|
|
value of accessed pages from the random read-ahead area. Does not read any
|
|
page, not even the one at the position (space, offset), if the read-ahead
|
|
mechanism is not activated. NOTE 1: the calling thread may own latches on
|
|
pages: to avoid deadlocks this function must be written such that it cannot
|
|
end up waiting for these latches! NOTE 2: the calling thread must want
|
|
access to the page given: this rule is set to prevent unintended read-aheads
|
|
performed by ibuf routines, a situation which could result in a deadlock if
|
|
the OS does not support asynchronous i/o.
|
|
@return number of page read requests issued; NOTE that if we read ibuf
|
|
pages, it may happen that the page at the given page number does not
|
|
get read even if we return a positive value!
|
|
@return number of page read requests issued */
|
|
UNIV_INTERN
|
|
ulint
|
|
buf_read_ahead_random(
|
|
/*==================*/
|
|
ulint space, /*!< in: space id */
|
|
ulint zip_size, /*!< in: compressed page size in bytes,
|
|
or 0 */
|
|
ulint offset, /*!< in: page number of a page which
|
|
the current thread wants to access */
|
|
ibool inside_ibuf, /*!< in: TRUE if we are inside ibuf
|
|
routine */
|
|
trx_t* trx);
|
|
/********************************************************************//**
|
|
Applies linear read-ahead if in the buf_pool the page is a border page of
|
|
a linear read-ahead area and all the pages in the area have been accessed.
|
|
Does not read any page if the read-ahead mechanism is not activated. Note
|
|
that the algorithm looks at the 'natural' adjacent successor and
|
|
predecessor of the page, which on the leaf level of a B-tree are the next
|
|
and previous page in the chain of leaves. To know these, the page specified
|
|
in (space, offset) must already be present in the buf_pool. Thus, the
|
|
natural way to use this function is to call it when a page in the buf_pool
|
|
is accessed the first time, calling this function just after it has been
|
|
bufferfixed.
|
|
NOTE 1: as this function looks at the natural predecessor and successor
|
|
fields on the page, what happens, if these are not initialized to any
|
|
sensible value? No problem, before applying read-ahead we check that the
|
|
area to read is within the span of the space, if not, read-ahead is not
|
|
applied. An uninitialized value may result in a useless read operation, but
|
|
only very improbably.
|
|
NOTE 2: the calling thread may own latches on pages: to avoid deadlocks this
|
|
function must be written such that it cannot end up waiting for these
|
|
latches!
|
|
NOTE 3: the calling thread must want access to the page given: this rule is
|
|
set to prevent unintended read-aheads performed by ibuf routines, a situation
|
|
which could result in a deadlock if the OS does not support asynchronous io.
|
|
@return number of page read requests issued */
|
|
UNIV_INTERN
|
|
ulint
|
|
buf_read_ahead_linear(
|
|
/*==================*/
|
|
ulint space, /*!< in: space id */
|
|
ulint zip_size, /*!< in: compressed page size in bytes, or 0 */
|
|
ulint offset, /*!< in: page number; see NOTE 3 above */
|
|
ibool inside_ibuf, /*!< in: TRUE if we are inside ibuf routine */
|
|
trx_t* trx);
|
|
/********************************************************************//**
|
|
Issues read requests for pages which the ibuf module wants to read in, in
|
|
order to contract the insert buffer tree. Technically, this function is like
|
|
a read-ahead function. */
|
|
UNIV_INTERN
|
|
void
|
|
buf_read_ibuf_merge_pages(
|
|
/*======================*/
|
|
bool sync, /*!< in: true if the caller
|
|
wants this function to wait
|
|
for the highest address page
|
|
to get read in, before this
|
|
function returns */
|
|
const ulint* space_ids, /*!< in: array of space ids */
|
|
const ib_int64_t* space_versions,/*!< in: the spaces must have
|
|
this version number
|
|
(timestamp), otherwise we
|
|
discard the read; we use this
|
|
to cancel reads if DISCARD +
|
|
IMPORT may have changed the
|
|
tablespace size */
|
|
const ulint* page_nos, /*!< in: array of page numbers
|
|
to read, with the highest page
|
|
number the last in the
|
|
array */
|
|
ulint n_stored); /*!< in: number of elements
|
|
in the arrays */
|
|
/********************************************************************//**
|
|
Issues read requests for pages which recovery wants to read in. */
|
|
UNIV_INTERN
|
|
void
|
|
buf_read_recv_pages(
|
|
/*================*/
|
|
ibool sync, /*!< in: TRUE if the caller
|
|
wants this function to wait
|
|
for the highest address page
|
|
to get read in, before this
|
|
function returns */
|
|
ulint space, /*!< in: space id */
|
|
ulint zip_size, /*!< in: compressed page size in
|
|
bytes, or 0 */
|
|
const ulint* page_nos, /*!< in: array of page numbers
|
|
to read, with the highest page
|
|
number the last in the
|
|
array */
|
|
ulint n_stored); /*!< in: number of page numbers
|
|
in the array */
|
|
|
|
/** The size in pages of the area which the read-ahead algorithms read if
|
|
invoked */
|
|
#define BUF_READ_AHEAD_AREA(b) ((b)->read_ahead_area)
|
|
|
|
/** @name Modes used in read-ahead @{ */
|
|
/** read only pages belonging to the insert buffer tree */
|
|
#define BUF_READ_IBUF_PAGES_ONLY 131
|
|
/** read any page */
|
|
#define BUF_READ_ANY_PAGE 132
|
|
/** read any page, but ignore (return an error) if a page does not exist
|
|
instead of crashing like BUF_READ_ANY_PAGE does */
|
|
#define BUF_READ_IGNORE_NONEXISTENT_PAGES 1024
|
|
/* @} */
|
|
|
|
#endif
|