mirror of
https://github.com/MariaDB/server.git
synced 2025-01-21 14:32:34 +01:00
f9cc391863
This only merges MDEV-12253, adapting it to MDEV-12602 which is already present in 10.2 but not yet in the 10.1 revision that is being merged. TODO: Error handling in crash recovery needs to be improved. If a page cannot be decrypted (or read), we should cleanly abort the startup. If innodb_force_recovery is specified, we should ignore the problematic page and apply redo log to other pages. Currently, the test encryption.innodb-redo-badkey randomly fails like this (the last messages are from cmake -DWITH_ASAN): 2017-05-05 10:19:40 140037071685504 [Note] InnoDB: Starting crash recovery from checkpoint LSN=1635994 2017-05-05 10:19:40 140037071685504 [ERROR] InnoDB: Missing MLOG_FILE_NAME or MLOG_FILE_DELETE before MLOG_CHECKPOINT for tablespace 1 2017-05-05 10:19:40 140037071685504 [ERROR] InnoDB: Plugin initialization aborted at srv0start.cc[2201] with error Data structure corruption 2017-05-05 10:19:41 140037071685504 [Note] InnoDB: Starting shutdown... i================================================================= ==5226==ERROR: AddressSanitizer: attempting free on address which was not malloc()-ed: 0x612000018588 in thread T0 #0 0x736750 in operator delete(void*) (/mariadb/server/build/sql/mysqld+0x736750) #1 0x1e4833f in LatchCounter::~LatchCounter() /mariadb/server/storage/innobase/include/sync0types.h:599:4 #2 0x1e480b8 in LatchMeta<LatchCounter>::~LatchMeta() /mariadb/server/storage/innobase/include/sync0types.h:786:17 #3 0x1e35509 in sync_latch_meta_destroy() /mariadb/server/storage/innobase/sync/sync0debug.cc:1622:3 #4 0x1e35314 in sync_check_close() /mariadb/server/storage/innobase/sync/sync0debug.cc:1839:2 #5 0x1dfdc18 in innodb_shutdown() /mariadb/server/storage/innobase/srv/srv0start.cc:2888:2 #6 0x197e5e6 in innobase_init(void*) /mariadb/server/storage/innobase/handler/ha_innodb.cc:4475:3
164 lines
6.8 KiB
C
164 lines
6.8 KiB
C
/*****************************************************************************
|
|
|
|
Copyright (c) 1995, 2015, 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 "buf0buf.h"
|
|
#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] page_id page id
|
|
@param[in] page_size page size
|
|
@retval DB_SUCCESS if the page was 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 */
|
|
dberr_t
|
|
buf_read_page(
|
|
const page_id_t& page_id,
|
|
const page_size_t& page_size);
|
|
|
|
/********************************************************************//**
|
|
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] page_id page id
|
|
@param[in] page_size page size
|
|
@param[in] sync true if synchronous aio is desired */
|
|
void
|
|
buf_read_page_background(
|
|
const page_id_t& page_id,
|
|
const page_size_t& page_size,
|
|
bool sync);
|
|
|
|
/** 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.
|
|
@param[in] page_id page id of a page which the current thread
|
|
wants to access
|
|
@param[in] page_size page size
|
|
@param[in] inside_ibuf TRUE if we are inside ibuf routine
|
|
@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! */
|
|
ulint
|
|
buf_read_ahead_random(
|
|
const page_id_t& page_id,
|
|
const page_size_t& page_size,
|
|
ibool inside_ibuf);
|
|
|
|
/** 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.
|
|
@param[in] page_id page id; see NOTE 3 above
|
|
@param[in] page_size page size
|
|
@param[in] inside_ibuf TRUE if we are inside ibuf routine
|
|
@return number of page read requests issued */
|
|
ulint
|
|
buf_read_ahead_linear(
|
|
const page_id_t& page_id,
|
|
const page_size_t& page_size,
|
|
ibool inside_ibuf);
|
|
|
|
/********************************************************************//**
|
|
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. */
|
|
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 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.
|
|
@param[in] sync true if the caller wants this function to wait
|
|
for the highest address page to get read in, before this function returns
|
|
@param[in] space_id tablespace id
|
|
@param[in] page_nos array of page numbers to read, with the
|
|
highest page number the last in the array
|
|
@param[in] n_stored number of page numbers in the array */
|
|
|
|
void
|
|
buf_read_recv_pages(
|
|
bool sync,
|
|
ulint space_id,
|
|
const ulint* page_nos,
|
|
ulint n_stored);
|
|
|
|
/** 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
|
|
/* @} */
|
|
|
|
#endif
|