2014-02-26 19:11:54 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
|
2016-06-21 14:21:03 +02:00
|
|
|
Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved.
|
2020-02-06 09:00:19 +02:00
|
|
|
Copyright (c) 2013, 2020, MariaDB Corporation.
|
2014-02-26 19:11:54 +01: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.,
|
2019-05-11 18:08:32 +03:00
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
/**************************************************//**
|
|
|
|
@file include/buf0buf.h
|
|
|
|
The database buffer pool high-level routines
|
|
|
|
|
|
|
|
Created 11/5/1995 Heikki Tuuri
|
|
|
|
*******************************************************/
|
|
|
|
|
|
|
|
#ifndef buf0buf_h
|
|
|
|
#define buf0buf_h
|
|
|
|
|
2016-12-30 15:04:10 +02:00
|
|
|
/** Magic value to use instead of checksums when they are disabled */
|
|
|
|
#define BUF_NO_CHECKSUM_MAGIC 0xDEADBEEFUL
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
#include "fil0fil.h"
|
|
|
|
#include "mtr0types.h"
|
|
|
|
#include "buf0types.h"
|
2016-08-12 11:17:45 +03:00
|
|
|
#ifndef UNIV_INNOCHECKSUM
|
2014-02-26 19:11:54 +01:00
|
|
|
#include "hash0hash.h"
|
|
|
|
#include "ut0byte.h"
|
|
|
|
#include "page0types.h"
|
|
|
|
#include "ut0rbt.h"
|
|
|
|
#include "os0proc.h"
|
|
|
|
#include "log0log.h"
|
2016-08-12 11:17:45 +03:00
|
|
|
#include "srv0srv.h"
|
|
|
|
#include <ostream>
|
|
|
|
|
|
|
|
// Forward declaration
|
|
|
|
struct fil_addr_t;
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
/** @name Modes for buf_page_get_gen */
|
|
|
|
/* @{ */
|
|
|
|
#define BUF_GET 10 /*!< get always */
|
|
|
|
#define BUF_GET_IF_IN_POOL 11 /*!< get if in pool */
|
|
|
|
#define BUF_PEEK_IF_IN_POOL 12 /*!< get if in pool, do not make
|
|
|
|
the block young in the LRU list */
|
|
|
|
#define BUF_GET_NO_LATCH 14 /*!< get and bufferfix, but
|
|
|
|
set no latch; we have
|
|
|
|
separated this case, because
|
|
|
|
it is error-prone programming
|
|
|
|
not to set a latch, and it
|
|
|
|
should be used with care */
|
|
|
|
#define BUF_GET_IF_IN_POOL_OR_WATCH 15
|
|
|
|
/*!< Get the page only if it's in the
|
|
|
|
buffer pool, if not then set a watch
|
|
|
|
on the page. */
|
|
|
|
#define BUF_GET_POSSIBLY_FREED 16
|
|
|
|
/*!< Like BUF_GET, but do not mind
|
|
|
|
if the file page has been freed. */
|
MDEV-13328 ALTER TABLE…DISCARD TABLESPACE takes a lot of time
With a big buffer pool that contains many data pages,
DISCARD TABLESPACE took a long time, because it would scan the
entire buffer pool to remove any pages that belong to the tablespace.
With a large buffer pool, this would take a lot of time, especially
when the table-to-discard is empty.
The minimum amount of work that DISCARD TABLESPACE must do is to
remove the pages of the to-be-discarded table from the
buf_pool->flush_list because any writes to the data file must be
prevented before the file is deleted.
If DISCARD TABLESPACE does not evict the pages from the buffer pool,
then IMPORT TABLESPACE must do it, because we must prevent pre-DISCARD,
not-yet-evicted pages from being mistaken for pages of the imported
tablespace.
It would not be a useful fix to simply move the buffer pool scan to
the IMPORT TABLESPACE step. What we can do is to actively evict those
pages that could be mistaken for imported pages. In this way, when
importing a small table into a big buffer pool, the import should
still run relatively fast.
Import is bypassing the buffer pool when reading pages for the
adjustment phase. In the adjustment phase, if a page exists in
the buffer pool, we could replace it with the page from the imported
file. Unfortunately I did not get this to work properly, so instead
we will simply evict any matching page from the buffer pool.
buf_page_get_gen(): Implement BUF_EVICT_IF_IN_POOL, a new mode
where the requested page will be evicted if it is found. There
must be no unwritten changes for the page.
buf_remove_t: Remove. Instead, use trx!=NULL to signify that a write
to file is desired, and use a separate parameter bool drop_ahi.
buf_LRU_flush_or_remove_pages(), fil_delete_tablespace():
Replace buf_remove_t.
buf_LRU_remove_pages(), buf_LRU_remove_all_pages(): Remove.
PageConverter::m_mtr: A dummy mini-transaction buffer
PageConverter::PageConverter(): Complete the member initialization list.
PageConverter::operator()(): Evict any 'shadow' pages from the
buffer pool so that pre-existing (garbage) pages cannot be mistaken
for pages that exist in the being-imported file.
row_discard_tablespace(): Remove a bogus comment that seems to
refer to IMPORT TABLESPACE, not DISCARD TABLESPACE.
2017-11-02 22:38:37 +02:00
|
|
|
#define BUF_EVICT_IF_IN_POOL 20 /*!< evict a clean block if found */
|
2014-02-26 19:11:54 +01:00
|
|
|
/* @} */
|
|
|
|
|
|
|
|
#define BUF_POOL_WATCH_SIZE (srv_n_purge_threads + 1)
|
|
|
|
/*!< Maximum number of concurrent
|
|
|
|
buffer pool watches */
|
|
|
|
#define MAX_PAGE_HASH_LOCKS 1024 /*!< The maximum number of
|
|
|
|
page_hash locks */
|
|
|
|
|
2020-02-12 14:45:21 +02:00
|
|
|
extern buf_pool_t* buf_pool; /*!< The buffer pools
|
2014-02-26 19:11:54 +01:00
|
|
|
of the database */
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
extern volatile bool buf_pool_withdrawing; /*!< true when withdrawing buffer
|
|
|
|
pool pages might cause page relocation */
|
|
|
|
|
|
|
|
extern volatile ulint buf_withdraw_clock; /*!< the clock is incremented
|
|
|
|
every time a pointer to a page may
|
|
|
|
become obsolete */
|
|
|
|
|
2016-12-30 15:04:10 +02:00
|
|
|
# ifdef UNIV_DEBUG
|
2016-08-12 11:17:45 +03:00
|
|
|
extern my_bool buf_disable_resize_buffer_pool_debug; /*!< if TRUE, resizing
|
|
|
|
buffer pool is not allowed. */
|
2016-12-30 15:04:10 +02:00
|
|
|
# endif /* UNIV_DEBUG */
|
2016-09-06 09:43:16 +03:00
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
/** @brief States of a control block
|
|
|
|
@see buf_page_t
|
|
|
|
|
|
|
|
The enumeration values must be 0..7. */
|
|
|
|
enum buf_page_state {
|
|
|
|
BUF_BLOCK_POOL_WATCH, /*!< a sentinel for the buffer pool
|
|
|
|
watch, element of buf_pool->watch[] */
|
|
|
|
BUF_BLOCK_ZIP_PAGE, /*!< contains a clean
|
|
|
|
compressed page */
|
|
|
|
BUF_BLOCK_ZIP_DIRTY, /*!< contains a compressed
|
|
|
|
page that is in the
|
|
|
|
buf_pool->flush_list */
|
|
|
|
|
|
|
|
BUF_BLOCK_NOT_USED, /*!< is in the free list;
|
|
|
|
must be after the BUF_BLOCK_ZIP_
|
|
|
|
constants for compressed-only pages
|
|
|
|
@see buf_block_state_valid() */
|
|
|
|
BUF_BLOCK_READY_FOR_USE, /*!< when buf_LRU_get_free_block
|
|
|
|
returns a block, it is in this state */
|
|
|
|
BUF_BLOCK_FILE_PAGE, /*!< contains a buffered file page */
|
|
|
|
BUF_BLOCK_MEMORY, /*!< contains some main memory
|
|
|
|
object */
|
|
|
|
BUF_BLOCK_REMOVE_HASH /*!< hash index should be removed
|
|
|
|
before putting to the free list */
|
|
|
|
};
|
|
|
|
|
|
|
|
/** This structure defines information we will fetch from each buffer pool. It
|
|
|
|
will be used to print table IO stats */
|
2020-02-12 14:45:21 +02:00
|
|
|
struct buf_pool_info_t
|
|
|
|
{
|
2014-02-26 19:11:54 +01:00
|
|
|
/* General buffer pool info */
|
|
|
|
ulint pool_size; /*!< Buffer Pool size in pages */
|
|
|
|
ulint lru_len; /*!< Length of buf_pool->LRU */
|
|
|
|
ulint old_lru_len; /*!< buf_pool->LRU_old_len */
|
|
|
|
ulint free_list_len; /*!< Length of buf_pool->free list */
|
|
|
|
ulint flush_list_len; /*!< Length of buf_pool->flush_list */
|
|
|
|
ulint n_pend_unzip; /*!< buf_pool->n_pend_unzip, pages
|
|
|
|
pending decompress */
|
|
|
|
ulint n_pend_reads; /*!< buf_pool->n_pend_reads, pages
|
|
|
|
pending read */
|
|
|
|
ulint n_pending_flush_lru; /*!< Pages pending flush in LRU */
|
|
|
|
ulint n_pending_flush_single_page;/*!< Pages pending to be
|
|
|
|
flushed as part of single page
|
|
|
|
flushes issued by various user
|
|
|
|
threads */
|
|
|
|
ulint n_pending_flush_list; /*!< Pages pending flush in FLUSH
|
|
|
|
LIST */
|
|
|
|
ulint n_pages_made_young; /*!< number of pages made young */
|
|
|
|
ulint n_pages_not_made_young; /*!< number of pages not made young */
|
|
|
|
ulint n_pages_read; /*!< buf_pool->n_pages_read */
|
|
|
|
ulint n_pages_created; /*!< buf_pool->n_pages_created */
|
|
|
|
ulint n_pages_written; /*!< buf_pool->n_pages_written */
|
|
|
|
ulint n_page_gets; /*!< buf_pool->n_page_gets */
|
|
|
|
ulint n_ra_pages_read_rnd; /*!< buf_pool->n_ra_pages_read_rnd,
|
|
|
|
number of pages readahead */
|
|
|
|
ulint n_ra_pages_read; /*!< buf_pool->n_ra_pages_read, number
|
|
|
|
of pages readahead */
|
|
|
|
ulint n_ra_pages_evicted; /*!< buf_pool->n_ra_pages_evicted,
|
|
|
|
number of readahead pages evicted
|
|
|
|
without access */
|
|
|
|
ulint n_page_get_delta; /*!< num of buffer pool page gets since
|
|
|
|
last printout */
|
|
|
|
|
|
|
|
/* Buffer pool access stats */
|
|
|
|
double page_made_young_rate; /*!< page made young rate in pages
|
|
|
|
per second */
|
|
|
|
double page_not_made_young_rate;/*!< page not made young rate
|
|
|
|
in pages per second */
|
|
|
|
double pages_read_rate; /*!< num of pages read per second */
|
|
|
|
double pages_created_rate; /*!< num of pages create per second */
|
|
|
|
double pages_written_rate; /*!< num of pages written per second */
|
|
|
|
ulint page_read_delta; /*!< num of pages read since last
|
|
|
|
printout */
|
|
|
|
ulint young_making_delta; /*!< num of pages made young since
|
|
|
|
last printout */
|
|
|
|
ulint not_young_making_delta; /*!< num of pages not make young since
|
|
|
|
last printout */
|
|
|
|
|
|
|
|
/* Statistics about read ahead algorithm. */
|
|
|
|
double pages_readahead_rnd_rate;/*!< random readahead rate in pages per
|
|
|
|
second */
|
|
|
|
double pages_readahead_rate; /*!< readahead rate in pages per
|
|
|
|
second */
|
|
|
|
double pages_evicted_rate; /*!< rate of readahead page evicted
|
|
|
|
without access, in pages per second */
|
|
|
|
|
|
|
|
/* Stats about LRU eviction */
|
|
|
|
ulint unzip_lru_len; /*!< length of buf_pool->unzip_LRU
|
|
|
|
list */
|
|
|
|
/* Counters for LRU policy */
|
|
|
|
ulint io_sum; /*!< buf_LRU_stat_sum.io */
|
|
|
|
ulint io_cur; /*!< buf_LRU_stat_cur.io, num of IO
|
|
|
|
for current interval */
|
|
|
|
ulint unzip_sum; /*!< buf_LRU_stat_sum.unzip */
|
|
|
|
ulint unzip_cur; /*!< buf_LRU_stat_cur.unzip, num
|
|
|
|
pages decompressed in current
|
|
|
|
interval */
|
|
|
|
};
|
2017-08-04 13:57:26 +03:00
|
|
|
#endif /* !UNIV_INNOCHECKSUM */
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/** Print the given page_id_t object.
|
|
|
|
@param[in,out] out the output stream
|
|
|
|
@param[in] page_id the page_id_t object to be printed
|
|
|
|
@return the output stream */
|
|
|
|
std::ostream&
|
|
|
|
operator<<(
|
|
|
|
std::ostream& out,
|
2018-10-18 18:23:12 +03:00
|
|
|
const page_id_t page_id);
|
2016-08-12 11:17:45 +03:00
|
|
|
|
2017-08-04 13:57:26 +03:00
|
|
|
#ifndef UNIV_INNOCHECKSUM
|
2020-02-12 14:45:21 +02:00
|
|
|
/** Create the buffer pool.
|
|
|
|
@return whether the creation failed */
|
|
|
|
bool buf_pool_init();
|
|
|
|
/** Free the buffer pool at shutdown.
|
|
|
|
This must not be invoked before freeing all mutexes. */
|
|
|
|
void buf_pool_free();
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/** Determines if a block is intended to be withdrawn.
|
|
|
|
@param[in] block pointer to control block
|
|
|
|
@retval true if will be withdrawn */
|
2020-02-12 14:45:21 +02:00
|
|
|
bool buf_block_will_be_withdrawn(const buf_block_t* block);
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
/** Determines if a frame is intended to be withdrawn.
|
|
|
|
@param[in] ptr pointer to a frame
|
|
|
|
@retval true if will be withdrawn */
|
2020-02-12 14:45:21 +02:00
|
|
|
bool buf_frame_will_be_withdrawn(const byte* ptr);
|
2016-08-12 11:17:45 +03:00
|
|
|
|
2017-02-23 23:05:12 +02:00
|
|
|
#ifdef BTR_CUR_HASH_ADAPT
|
|
|
|
/** Clear the adaptive hash index on all pages in the buffer pool. */
|
2020-02-12 14:45:21 +02:00
|
|
|
void buf_pool_clear_hash_index();
|
2017-02-23 23:05:12 +02:00
|
|
|
#endif /* BTR_CUR_HASH_ADAPT */
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
/*********************************************************************//**
|
|
|
|
Gets the current size of buffer buf_pool in bytes.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return size in bytes */
|
2014-02-26 19:11:54 +01:00
|
|
|
UNIV_INLINE
|
|
|
|
ulint
|
|
|
|
buf_pool_get_curr_size(void);
|
|
|
|
/*========================*/
|
|
|
|
/*********************************************************************//**
|
|
|
|
Gets the current size of buffer buf_pool in frames.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return size in pages */
|
2014-02-26 19:11:54 +01:00
|
|
|
UNIV_INLINE
|
|
|
|
ulint
|
|
|
|
buf_pool_get_n_pages(void);
|
|
|
|
/*=======================*/
|
2020-02-12 14:45:21 +02:00
|
|
|
/**
|
|
|
|
@return the smallest oldest_modification lsn for any page.
|
|
|
|
@retval 0 if all modified persistent pages have been flushed */
|
2014-02-26 19:11:54 +01:00
|
|
|
lsn_t
|
2020-02-12 14:45:21 +02:00
|
|
|
buf_pool_get_oldest_modification();
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
/********************************************************************//**
|
|
|
|
Allocates a buf_page_t descriptor. This function must succeed. In case
|
|
|
|
of failure we assert in this function. */
|
|
|
|
UNIV_INLINE
|
|
|
|
buf_page_t*
|
|
|
|
buf_page_alloc_descriptor(void)
|
|
|
|
/*===========================*/
|
2016-06-21 14:21:03 +02:00
|
|
|
MY_ATTRIBUTE((malloc));
|
2014-02-26 19:11:54 +01:00
|
|
|
/********************************************************************//**
|
|
|
|
Free a buf_page_t descriptor. */
|
|
|
|
UNIV_INLINE
|
|
|
|
void
|
|
|
|
buf_page_free_descriptor(
|
|
|
|
/*=====================*/
|
|
|
|
buf_page_t* bpage) /*!< in: bpage descriptor to free. */
|
2016-06-21 14:21:03 +02:00
|
|
|
MY_ATTRIBUTE((nonnull));
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2020-02-12 14:45:21 +02:00
|
|
|
/** Allocate a buffer block.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return own: the allocated block, in state BUF_BLOCK_MEMORY */
|
2014-02-26 19:11:54 +01:00
|
|
|
buf_block_t*
|
2020-02-12 14:45:21 +02:00
|
|
|
buf_block_alloc();
|
2014-02-26 19:11:54 +01:00
|
|
|
/********************************************************************//**
|
|
|
|
Frees a buffer block which does not contain a file page. */
|
|
|
|
UNIV_INLINE
|
|
|
|
void
|
|
|
|
buf_block_free(
|
|
|
|
/*===========*/
|
|
|
|
buf_block_t* block); /*!< in, own: block to be freed */
|
2016-12-30 15:04:10 +02:00
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
/**************************************************************//**
|
|
|
|
NOTE! The following macros should be used instead of buf_page_get_gen,
|
|
|
|
to improve debugging. Only values RW_S_LATCH and RW_X_LATCH are allowed
|
|
|
|
in LA! */
|
2016-08-12 11:17:45 +03:00
|
|
|
#define buf_page_get(ID, SIZE, LA, MTR) \
|
MDEV-19514 Defer change buffer merge until pages are requested
We will remove the InnoDB background operation of merging buffered
changes to secondary index leaf pages. Changes will only be merged as a
result of an operation that accesses a secondary index leaf page,
such as a SQL statement that performs a lookup via that index,
or is modifying the index. Also ROLLBACK and some background operations,
such as purging the history of committed transactions, or computing
index cardinality statistics, can cause change buffer merge.
Encryption key rotation will not perform change buffer merge.
The motivation of this change is to simplify the I/O logic and to
allow crash recovery to happen in the background (MDEV-14481).
We also hope that this will reduce the number of "mystery" crashes
due to corrupted data. Because change buffer merge will typically
take place as a result of executing SQL statements, there should be
a clearer connection between the crash and the SQL statements that
were executed when the server crashed.
In many cases, a slight performance improvement was observed.
This is joint work with Thirunarayanan Balathandayuthapani
and was tested by Axel Schwenke and Matthias Leich.
The InnoDB monitor counter innodb_ibuf_merge_usec will be removed.
On slow shutdown (innodb_fast_shutdown=0), we will continue to
merge all buffered changes (and purge all undo log history).
Two InnoDB configuration parameters will be changed as follows:
innodb_disable_background_merge: Removed.
This parameter existed only in debug builds.
All change buffer merges will use synchronous reads.
innodb_force_recovery will be changed as follows:
* innodb_force_recovery=4 will be the same as innodb_force_recovery=3
(the change buffer merge cannot be disabled; it can only happen as
a result of an operation that accesses a secondary index leaf page).
The option used to be capable of corrupting secondary index leaf pages.
Now that capability is removed, and innodb_force_recovery=4 becomes 'safe'.
* innodb_force_recovery=5 (which essentially hard-wires
SET GLOBAL TRANSACTION ISOLATION LEVEL READ UNCOMMITTED)
becomes safe to use. Bogus data can be returned to SQL, but
persistent InnoDB data files will not be corrupted further.
* innodb_force_recovery=6 (ignore the redo log files)
will be the only option that can potentially cause
persistent corruption of InnoDB data files.
Code changes:
buf_page_t::ibuf_exist: New flag, to indicate whether buffered
changes exist for a buffer pool page. Pages with pending changes
can be returned by buf_page_get_gen(). Previously, the changes
were always merged inside buf_page_get_gen() if needed.
ibuf_page_exists(const buf_page_t&): Check if a buffered changes
exist for an X-latched or read-fixed page.
buf_page_get_gen(): Add the parameter allow_ibuf_merge=false.
All callers that know that they may be accessing a secondary index
leaf page must pass this parameter as allow_ibuf_merge=true,
unless it does not matter for that caller whether all buffered
changes have been applied. Assert that whenever allow_ibuf_merge
holds, the page actually is a leaf page. Attempt change buffer
merge only to secondary B-tree index leaf pages.
btr_block_get(): Add parameter 'bool merge'.
All callers of btr_block_get() should know whether the page could be
a secondary index leaf page. If it is not, we should avoid consulting
the change buffer bitmap to even consider a merge. This is the main
interface to requesting index pages from the buffer pool.
ibuf_merge_or_delete_for_page(), recv_recover_page(): Replace
buf_page_get_known_nowait() with much simpler logic, because
it is now guaranteed that that the block is x-latched or read-fixed.
mlog_init_t::mark_ibuf_exist(): Renamed from mlog_init_t::ibuf_merge().
On crash recovery, we will no longer merge any buffered changes
for the pages that we read into the buffer pool during the last batch
of applying log records.
buf_page_get_gen_known_nowait(), BUF_MAKE_YOUNG, BUF_KEEP_OLD: Remove.
btr_search_guess_on_hash(): Merge buf_page_get_gen_known_nowait()
to its only remaining caller.
buf_page_make_young_if_needed(): Define as an inline function.
Add the parameter buf_pool.
buf_page_peek_if_young(), buf_page_peek_if_too_old(): Add the
parameter buf_pool.
fil_space_validate_for_mtr_commit(): Remove a bogus comment
about background merge of the change buffer.
btr_cur_open_at_rnd_pos_func(), btr_cur_search_to_nth_level_func(),
btr_cur_open_at_index_side_func(): Use narrower data types and scopes.
ibuf_read_merge_pages(): Replaces buf_read_ibuf_merge_pages().
Merge the change buffer by invoking buf_page_get_gen().
2019-10-11 17:28:15 +03:00
|
|
|
buf_page_get_gen(ID, SIZE, LA, NULL, BUF_GET, __FILE__, __LINE__, MTR)
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
/**************************************************************//**
|
|
|
|
Use these macros to bufferfix a page with no latching. Remember not to
|
|
|
|
read the contents of the page unless you know it is safe. Do not modify
|
|
|
|
the contents of the page! We have separated this case, because it is
|
|
|
|
error-prone programming not to set a latch, and it should be used
|
|
|
|
with care. */
|
2016-08-12 11:17:45 +03:00
|
|
|
#define buf_page_get_with_no_latch(ID, SIZE, MTR) \
|
|
|
|
buf_page_get_gen(ID, SIZE, RW_NO_LATCH, NULL, BUF_GET_NO_LATCH, \
|
MDEV-19514 Defer change buffer merge until pages are requested
We will remove the InnoDB background operation of merging buffered
changes to secondary index leaf pages. Changes will only be merged as a
result of an operation that accesses a secondary index leaf page,
such as a SQL statement that performs a lookup via that index,
or is modifying the index. Also ROLLBACK and some background operations,
such as purging the history of committed transactions, or computing
index cardinality statistics, can cause change buffer merge.
Encryption key rotation will not perform change buffer merge.
The motivation of this change is to simplify the I/O logic and to
allow crash recovery to happen in the background (MDEV-14481).
We also hope that this will reduce the number of "mystery" crashes
due to corrupted data. Because change buffer merge will typically
take place as a result of executing SQL statements, there should be
a clearer connection between the crash and the SQL statements that
were executed when the server crashed.
In many cases, a slight performance improvement was observed.
This is joint work with Thirunarayanan Balathandayuthapani
and was tested by Axel Schwenke and Matthias Leich.
The InnoDB monitor counter innodb_ibuf_merge_usec will be removed.
On slow shutdown (innodb_fast_shutdown=0), we will continue to
merge all buffered changes (and purge all undo log history).
Two InnoDB configuration parameters will be changed as follows:
innodb_disable_background_merge: Removed.
This parameter existed only in debug builds.
All change buffer merges will use synchronous reads.
innodb_force_recovery will be changed as follows:
* innodb_force_recovery=4 will be the same as innodb_force_recovery=3
(the change buffer merge cannot be disabled; it can only happen as
a result of an operation that accesses a secondary index leaf page).
The option used to be capable of corrupting secondary index leaf pages.
Now that capability is removed, and innodb_force_recovery=4 becomes 'safe'.
* innodb_force_recovery=5 (which essentially hard-wires
SET GLOBAL TRANSACTION ISOLATION LEVEL READ UNCOMMITTED)
becomes safe to use. Bogus data can be returned to SQL, but
persistent InnoDB data files will not be corrupted further.
* innodb_force_recovery=6 (ignore the redo log files)
will be the only option that can potentially cause
persistent corruption of InnoDB data files.
Code changes:
buf_page_t::ibuf_exist: New flag, to indicate whether buffered
changes exist for a buffer pool page. Pages with pending changes
can be returned by buf_page_get_gen(). Previously, the changes
were always merged inside buf_page_get_gen() if needed.
ibuf_page_exists(const buf_page_t&): Check if a buffered changes
exist for an X-latched or read-fixed page.
buf_page_get_gen(): Add the parameter allow_ibuf_merge=false.
All callers that know that they may be accessing a secondary index
leaf page must pass this parameter as allow_ibuf_merge=true,
unless it does not matter for that caller whether all buffered
changes have been applied. Assert that whenever allow_ibuf_merge
holds, the page actually is a leaf page. Attempt change buffer
merge only to secondary B-tree index leaf pages.
btr_block_get(): Add parameter 'bool merge'.
All callers of btr_block_get() should know whether the page could be
a secondary index leaf page. If it is not, we should avoid consulting
the change buffer bitmap to even consider a merge. This is the main
interface to requesting index pages from the buffer pool.
ibuf_merge_or_delete_for_page(), recv_recover_page(): Replace
buf_page_get_known_nowait() with much simpler logic, because
it is now guaranteed that that the block is x-latched or read-fixed.
mlog_init_t::mark_ibuf_exist(): Renamed from mlog_init_t::ibuf_merge().
On crash recovery, we will no longer merge any buffered changes
for the pages that we read into the buffer pool during the last batch
of applying log records.
buf_page_get_gen_known_nowait(), BUF_MAKE_YOUNG, BUF_KEEP_OLD: Remove.
btr_search_guess_on_hash(): Merge buf_page_get_gen_known_nowait()
to its only remaining caller.
buf_page_make_young_if_needed(): Define as an inline function.
Add the parameter buf_pool.
buf_page_peek_if_young(), buf_page_peek_if_too_old(): Add the
parameter buf_pool.
fil_space_validate_for_mtr_commit(): Remove a bogus comment
about background merge of the change buffer.
btr_cur_open_at_rnd_pos_func(), btr_cur_search_to_nth_level_func(),
btr_cur_open_at_index_side_func(): Use narrower data types and scopes.
ibuf_read_merge_pages(): Replaces buf_read_ibuf_merge_pages().
Merge the change buffer by invoking buf_page_get_gen().
2019-10-11 17:28:15 +03:00
|
|
|
__FILE__, __LINE__, MTR)
|
2014-02-26 19:11:54 +01:00
|
|
|
/********************************************************************//**
|
|
|
|
This is the general function used to get optimistic access to a database
|
|
|
|
page.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return TRUE if success */
|
2014-02-26 19:11:54 +01:00
|
|
|
ibool
|
|
|
|
buf_page_optimistic_get(
|
|
|
|
/*====================*/
|
|
|
|
ulint rw_latch,/*!< in: RW_S_LATCH, RW_X_LATCH */
|
|
|
|
buf_block_t* block, /*!< in: guessed block */
|
|
|
|
ib_uint64_t modify_clock,/*!< in: modify clock value */
|
|
|
|
const char* file, /*!< in: file name */
|
2017-03-01 08:27:39 +02:00
|
|
|
unsigned line, /*!< in: line where called */
|
2014-02-26 19:11:54 +01:00
|
|
|
mtr_t* mtr); /*!< in: mini-transaction */
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/** Given a tablespace id and page number tries to get that page. If the
|
2014-02-26 19:11:54 +01:00
|
|
|
page is not in the buffer pool it is not loaded and NULL is returned.
|
2016-08-12 11:17:45 +03:00
|
|
|
Suitable for using when holding the lock_sys_t::mutex.
|
|
|
|
@param[in] page_id page id
|
|
|
|
@param[in] file file name
|
|
|
|
@param[in] line line where called
|
|
|
|
@param[in] mtr mini-transaction
|
|
|
|
@return pointer to a page or NULL */
|
2014-12-22 16:53:17 +02:00
|
|
|
buf_block_t*
|
2014-02-26 19:11:54 +01:00
|
|
|
buf_page_try_get_func(
|
2018-10-18 18:23:12 +03:00
|
|
|
const page_id_t page_id,
|
2016-08-12 11:17:45 +03:00
|
|
|
const char* file,
|
2017-03-01 08:27:39 +02:00
|
|
|
unsigned line,
|
2016-08-12 11:17:45 +03:00
|
|
|
mtr_t* mtr);
|
|
|
|
|
|
|
|
/** Tries to get a page.
|
|
|
|
If the page is not in the buffer pool it is not loaded. Suitable for using
|
|
|
|
when holding the lock_sys_t::mutex.
|
|
|
|
@param[in] page_id page identifier
|
|
|
|
@param[in] mtr mini-transaction
|
|
|
|
@return the page if in buffer pool, NULL if not */
|
|
|
|
#define buf_page_try_get(page_id, mtr) \
|
|
|
|
buf_page_try_get_func((page_id), __FILE__, __LINE__, mtr);
|
|
|
|
|
|
|
|
/** Get read access to a compressed page (usually of type
|
2014-02-26 19:11:54 +01:00
|
|
|
FIL_PAGE_TYPE_ZBLOB or FIL_PAGE_TYPE_ZBLOB2).
|
|
|
|
The page must be released with buf_page_release_zip().
|
|
|
|
NOTE: the page is not protected by any latch. Mutual exclusion has to
|
|
|
|
be implemented at a higher level. In other words, all possible
|
|
|
|
accesses to a given page through this function must be protected by
|
|
|
|
the same set of mutexes or latches.
|
2016-08-12 11:17:45 +03:00
|
|
|
@param[in] page_id page id
|
2019-02-06 19:50:11 +02:00
|
|
|
@param[in] zip_size ROW_FORMAT=COMPRESSED page size
|
2016-08-12 11:17:45 +03:00
|
|
|
@return pointer to the block */
|
2019-02-06 19:50:11 +02:00
|
|
|
buf_page_t* buf_page_get_zip(const page_id_t page_id, ulint zip_size);
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
/** This is the general function used to get access to a database page.
|
MDEV-19514 Defer change buffer merge until pages are requested
We will remove the InnoDB background operation of merging buffered
changes to secondary index leaf pages. Changes will only be merged as a
result of an operation that accesses a secondary index leaf page,
such as a SQL statement that performs a lookup via that index,
or is modifying the index. Also ROLLBACK and some background operations,
such as purging the history of committed transactions, or computing
index cardinality statistics, can cause change buffer merge.
Encryption key rotation will not perform change buffer merge.
The motivation of this change is to simplify the I/O logic and to
allow crash recovery to happen in the background (MDEV-14481).
We also hope that this will reduce the number of "mystery" crashes
due to corrupted data. Because change buffer merge will typically
take place as a result of executing SQL statements, there should be
a clearer connection between the crash and the SQL statements that
were executed when the server crashed.
In many cases, a slight performance improvement was observed.
This is joint work with Thirunarayanan Balathandayuthapani
and was tested by Axel Schwenke and Matthias Leich.
The InnoDB monitor counter innodb_ibuf_merge_usec will be removed.
On slow shutdown (innodb_fast_shutdown=0), we will continue to
merge all buffered changes (and purge all undo log history).
Two InnoDB configuration parameters will be changed as follows:
innodb_disable_background_merge: Removed.
This parameter existed only in debug builds.
All change buffer merges will use synchronous reads.
innodb_force_recovery will be changed as follows:
* innodb_force_recovery=4 will be the same as innodb_force_recovery=3
(the change buffer merge cannot be disabled; it can only happen as
a result of an operation that accesses a secondary index leaf page).
The option used to be capable of corrupting secondary index leaf pages.
Now that capability is removed, and innodb_force_recovery=4 becomes 'safe'.
* innodb_force_recovery=5 (which essentially hard-wires
SET GLOBAL TRANSACTION ISOLATION LEVEL READ UNCOMMITTED)
becomes safe to use. Bogus data can be returned to SQL, but
persistent InnoDB data files will not be corrupted further.
* innodb_force_recovery=6 (ignore the redo log files)
will be the only option that can potentially cause
persistent corruption of InnoDB data files.
Code changes:
buf_page_t::ibuf_exist: New flag, to indicate whether buffered
changes exist for a buffer pool page. Pages with pending changes
can be returned by buf_page_get_gen(). Previously, the changes
were always merged inside buf_page_get_gen() if needed.
ibuf_page_exists(const buf_page_t&): Check if a buffered changes
exist for an X-latched or read-fixed page.
buf_page_get_gen(): Add the parameter allow_ibuf_merge=false.
All callers that know that they may be accessing a secondary index
leaf page must pass this parameter as allow_ibuf_merge=true,
unless it does not matter for that caller whether all buffered
changes have been applied. Assert that whenever allow_ibuf_merge
holds, the page actually is a leaf page. Attempt change buffer
merge only to secondary B-tree index leaf pages.
btr_block_get(): Add parameter 'bool merge'.
All callers of btr_block_get() should know whether the page could be
a secondary index leaf page. If it is not, we should avoid consulting
the change buffer bitmap to even consider a merge. This is the main
interface to requesting index pages from the buffer pool.
ibuf_merge_or_delete_for_page(), recv_recover_page(): Replace
buf_page_get_known_nowait() with much simpler logic, because
it is now guaranteed that that the block is x-latched or read-fixed.
mlog_init_t::mark_ibuf_exist(): Renamed from mlog_init_t::ibuf_merge().
On crash recovery, we will no longer merge any buffered changes
for the pages that we read into the buffer pool during the last batch
of applying log records.
buf_page_get_gen_known_nowait(), BUF_MAKE_YOUNG, BUF_KEEP_OLD: Remove.
btr_search_guess_on_hash(): Merge buf_page_get_gen_known_nowait()
to its only remaining caller.
buf_page_make_young_if_needed(): Define as an inline function.
Add the parameter buf_pool.
buf_page_peek_if_young(), buf_page_peek_if_too_old(): Add the
parameter buf_pool.
fil_space_validate_for_mtr_commit(): Remove a bogus comment
about background merge of the change buffer.
btr_cur_open_at_rnd_pos_func(), btr_cur_search_to_nth_level_func(),
btr_cur_open_at_index_side_func(): Use narrower data types and scopes.
ibuf_read_merge_pages(): Replaces buf_read_ibuf_merge_pages().
Merge the change buffer by invoking buf_page_get_gen().
2019-10-11 17:28:15 +03:00
|
|
|
@param[in] page_id page id
|
|
|
|
@param[in] zip_size ROW_FORMAT=COMPRESSED page size, or 0
|
|
|
|
@param[in] rw_latch RW_S_LATCH, RW_X_LATCH, RW_NO_LATCH
|
|
|
|
@param[in] guess guessed block or NULL
|
|
|
|
@param[in] mode BUF_GET, BUF_GET_IF_IN_POOL,
|
2016-08-12 11:17:45 +03:00
|
|
|
BUF_PEEK_IF_IN_POOL, BUF_GET_NO_LATCH, or BUF_GET_IF_IN_POOL_OR_WATCH
|
MDEV-19514 Defer change buffer merge until pages are requested
We will remove the InnoDB background operation of merging buffered
changes to secondary index leaf pages. Changes will only be merged as a
result of an operation that accesses a secondary index leaf page,
such as a SQL statement that performs a lookup via that index,
or is modifying the index. Also ROLLBACK and some background operations,
such as purging the history of committed transactions, or computing
index cardinality statistics, can cause change buffer merge.
Encryption key rotation will not perform change buffer merge.
The motivation of this change is to simplify the I/O logic and to
allow crash recovery to happen in the background (MDEV-14481).
We also hope that this will reduce the number of "mystery" crashes
due to corrupted data. Because change buffer merge will typically
take place as a result of executing SQL statements, there should be
a clearer connection between the crash and the SQL statements that
were executed when the server crashed.
In many cases, a slight performance improvement was observed.
This is joint work with Thirunarayanan Balathandayuthapani
and was tested by Axel Schwenke and Matthias Leich.
The InnoDB monitor counter innodb_ibuf_merge_usec will be removed.
On slow shutdown (innodb_fast_shutdown=0), we will continue to
merge all buffered changes (and purge all undo log history).
Two InnoDB configuration parameters will be changed as follows:
innodb_disable_background_merge: Removed.
This parameter existed only in debug builds.
All change buffer merges will use synchronous reads.
innodb_force_recovery will be changed as follows:
* innodb_force_recovery=4 will be the same as innodb_force_recovery=3
(the change buffer merge cannot be disabled; it can only happen as
a result of an operation that accesses a secondary index leaf page).
The option used to be capable of corrupting secondary index leaf pages.
Now that capability is removed, and innodb_force_recovery=4 becomes 'safe'.
* innodb_force_recovery=5 (which essentially hard-wires
SET GLOBAL TRANSACTION ISOLATION LEVEL READ UNCOMMITTED)
becomes safe to use. Bogus data can be returned to SQL, but
persistent InnoDB data files will not be corrupted further.
* innodb_force_recovery=6 (ignore the redo log files)
will be the only option that can potentially cause
persistent corruption of InnoDB data files.
Code changes:
buf_page_t::ibuf_exist: New flag, to indicate whether buffered
changes exist for a buffer pool page. Pages with pending changes
can be returned by buf_page_get_gen(). Previously, the changes
were always merged inside buf_page_get_gen() if needed.
ibuf_page_exists(const buf_page_t&): Check if a buffered changes
exist for an X-latched or read-fixed page.
buf_page_get_gen(): Add the parameter allow_ibuf_merge=false.
All callers that know that they may be accessing a secondary index
leaf page must pass this parameter as allow_ibuf_merge=true,
unless it does not matter for that caller whether all buffered
changes have been applied. Assert that whenever allow_ibuf_merge
holds, the page actually is a leaf page. Attempt change buffer
merge only to secondary B-tree index leaf pages.
btr_block_get(): Add parameter 'bool merge'.
All callers of btr_block_get() should know whether the page could be
a secondary index leaf page. If it is not, we should avoid consulting
the change buffer bitmap to even consider a merge. This is the main
interface to requesting index pages from the buffer pool.
ibuf_merge_or_delete_for_page(), recv_recover_page(): Replace
buf_page_get_known_nowait() with much simpler logic, because
it is now guaranteed that that the block is x-latched or read-fixed.
mlog_init_t::mark_ibuf_exist(): Renamed from mlog_init_t::ibuf_merge().
On crash recovery, we will no longer merge any buffered changes
for the pages that we read into the buffer pool during the last batch
of applying log records.
buf_page_get_gen_known_nowait(), BUF_MAKE_YOUNG, BUF_KEEP_OLD: Remove.
btr_search_guess_on_hash(): Merge buf_page_get_gen_known_nowait()
to its only remaining caller.
buf_page_make_young_if_needed(): Define as an inline function.
Add the parameter buf_pool.
buf_page_peek_if_young(), buf_page_peek_if_too_old(): Add the
parameter buf_pool.
fil_space_validate_for_mtr_commit(): Remove a bogus comment
about background merge of the change buffer.
btr_cur_open_at_rnd_pos_func(), btr_cur_search_to_nth_level_func(),
btr_cur_open_at_index_side_func(): Use narrower data types and scopes.
ibuf_read_merge_pages(): Replaces buf_read_ibuf_merge_pages().
Merge the change buffer by invoking buf_page_get_gen().
2019-10-11 17:28:15 +03:00
|
|
|
@param[in] file file name
|
|
|
|
@param[in] line line where called
|
|
|
|
@param[in] mtr mini-transaction
|
|
|
|
@param[out] err DB_SUCCESS or error code
|
|
|
|
@param[in] allow_ibuf_merge Allow change buffer merge while
|
|
|
|
reading the pages from file.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return pointer to the block or NULL */
|
2014-02-26 19:11:54 +01:00
|
|
|
buf_block_t*
|
|
|
|
buf_page_get_gen(
|
2018-10-18 18:23:12 +03:00
|
|
|
const page_id_t page_id,
|
2019-02-06 19:50:11 +02:00
|
|
|
ulint zip_size,
|
2016-08-12 11:17:45 +03:00
|
|
|
ulint rw_latch,
|
|
|
|
buf_block_t* guess,
|
|
|
|
ulint mode,
|
|
|
|
const char* file,
|
2017-03-01 08:27:39 +02:00
|
|
|
unsigned line,
|
2016-08-12 11:17:45 +03:00
|
|
|
mtr_t* mtr,
|
MDEV-19514 Defer change buffer merge until pages are requested
We will remove the InnoDB background operation of merging buffered
changes to secondary index leaf pages. Changes will only be merged as a
result of an operation that accesses a secondary index leaf page,
such as a SQL statement that performs a lookup via that index,
or is modifying the index. Also ROLLBACK and some background operations,
such as purging the history of committed transactions, or computing
index cardinality statistics, can cause change buffer merge.
Encryption key rotation will not perform change buffer merge.
The motivation of this change is to simplify the I/O logic and to
allow crash recovery to happen in the background (MDEV-14481).
We also hope that this will reduce the number of "mystery" crashes
due to corrupted data. Because change buffer merge will typically
take place as a result of executing SQL statements, there should be
a clearer connection between the crash and the SQL statements that
were executed when the server crashed.
In many cases, a slight performance improvement was observed.
This is joint work with Thirunarayanan Balathandayuthapani
and was tested by Axel Schwenke and Matthias Leich.
The InnoDB monitor counter innodb_ibuf_merge_usec will be removed.
On slow shutdown (innodb_fast_shutdown=0), we will continue to
merge all buffered changes (and purge all undo log history).
Two InnoDB configuration parameters will be changed as follows:
innodb_disable_background_merge: Removed.
This parameter existed only in debug builds.
All change buffer merges will use synchronous reads.
innodb_force_recovery will be changed as follows:
* innodb_force_recovery=4 will be the same as innodb_force_recovery=3
(the change buffer merge cannot be disabled; it can only happen as
a result of an operation that accesses a secondary index leaf page).
The option used to be capable of corrupting secondary index leaf pages.
Now that capability is removed, and innodb_force_recovery=4 becomes 'safe'.
* innodb_force_recovery=5 (which essentially hard-wires
SET GLOBAL TRANSACTION ISOLATION LEVEL READ UNCOMMITTED)
becomes safe to use. Bogus data can be returned to SQL, but
persistent InnoDB data files will not be corrupted further.
* innodb_force_recovery=6 (ignore the redo log files)
will be the only option that can potentially cause
persistent corruption of InnoDB data files.
Code changes:
buf_page_t::ibuf_exist: New flag, to indicate whether buffered
changes exist for a buffer pool page. Pages with pending changes
can be returned by buf_page_get_gen(). Previously, the changes
were always merged inside buf_page_get_gen() if needed.
ibuf_page_exists(const buf_page_t&): Check if a buffered changes
exist for an X-latched or read-fixed page.
buf_page_get_gen(): Add the parameter allow_ibuf_merge=false.
All callers that know that they may be accessing a secondary index
leaf page must pass this parameter as allow_ibuf_merge=true,
unless it does not matter for that caller whether all buffered
changes have been applied. Assert that whenever allow_ibuf_merge
holds, the page actually is a leaf page. Attempt change buffer
merge only to secondary B-tree index leaf pages.
btr_block_get(): Add parameter 'bool merge'.
All callers of btr_block_get() should know whether the page could be
a secondary index leaf page. If it is not, we should avoid consulting
the change buffer bitmap to even consider a merge. This is the main
interface to requesting index pages from the buffer pool.
ibuf_merge_or_delete_for_page(), recv_recover_page(): Replace
buf_page_get_known_nowait() with much simpler logic, because
it is now guaranteed that that the block is x-latched or read-fixed.
mlog_init_t::mark_ibuf_exist(): Renamed from mlog_init_t::ibuf_merge().
On crash recovery, we will no longer merge any buffered changes
for the pages that we read into the buffer pool during the last batch
of applying log records.
buf_page_get_gen_known_nowait(), BUF_MAKE_YOUNG, BUF_KEEP_OLD: Remove.
btr_search_guess_on_hash(): Merge buf_page_get_gen_known_nowait()
to its only remaining caller.
buf_page_make_young_if_needed(): Define as an inline function.
Add the parameter buf_pool.
buf_page_peek_if_young(), buf_page_peek_if_too_old(): Add the
parameter buf_pool.
fil_space_validate_for_mtr_commit(): Remove a bogus comment
about background merge of the change buffer.
btr_cur_open_at_rnd_pos_func(), btr_cur_search_to_nth_level_func(),
btr_cur_open_at_index_side_func(): Use narrower data types and scopes.
ibuf_read_merge_pages(): Replaces buf_read_ibuf_merge_pages().
Merge the change buffer by invoking buf_page_get_gen().
2019-10-11 17:28:15 +03:00
|
|
|
dberr_t* err = NULL,
|
|
|
|
bool allow_ibuf_merge = false);
|
2016-08-12 11:17:45 +03:00
|
|
|
|
2019-02-06 19:50:11 +02:00
|
|
|
/** Initialize a page in the buffer pool. The page is usually not read
|
2014-02-26 19:11:54 +01:00
|
|
|
from a file even if it cannot be found in the buffer buf_pool. This is one
|
|
|
|
of the functions which perform to a block a state transition NOT_USED =>
|
|
|
|
FILE_PAGE (the other is buf_page_get_gen).
|
2016-08-12 11:17:45 +03:00
|
|
|
@param[in] page_id page id
|
2019-02-06 19:50:11 +02:00
|
|
|
@param[in] zip_size ROW_FORMAT=COMPRESSED page size, or 0
|
|
|
|
@param[in,out] mtr mini-transaction
|
2016-08-12 11:17:45 +03:00
|
|
|
@return pointer to the block, page bufferfixed */
|
2014-02-26 19:11:54 +01:00
|
|
|
buf_block_t*
|
|
|
|
buf_page_create(
|
2018-10-18 18:23:12 +03:00
|
|
|
const page_id_t page_id,
|
2019-02-06 19:50:11 +02:00
|
|
|
ulint zip_size,
|
2016-08-12 11:17:45 +03:00
|
|
|
mtr_t* mtr);
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
/********************************************************************//**
|
|
|
|
Releases a compressed-only page acquired with buf_page_get_zip(). */
|
|
|
|
UNIV_INLINE
|
|
|
|
void
|
|
|
|
buf_page_release_zip(
|
|
|
|
/*=================*/
|
|
|
|
buf_page_t* bpage); /*!< in: buffer block */
|
|
|
|
/********************************************************************//**
|
2016-08-12 11:17:45 +03:00
|
|
|
Releases a latch, if specified. */
|
2014-02-26 19:11:54 +01:00
|
|
|
UNIV_INLINE
|
|
|
|
void
|
2016-08-12 11:17:45 +03:00
|
|
|
buf_page_release_latch(
|
|
|
|
/*=====================*/
|
2014-02-26 19:11:54 +01:00
|
|
|
buf_block_t* block, /*!< in: buffer block */
|
|
|
|
ulint rw_latch); /*!< in: RW_S_LATCH, RW_X_LATCH,
|
|
|
|
RW_NO_LATCH */
|
|
|
|
/********************************************************************//**
|
|
|
|
Moves a page to the start of the buffer pool LRU list. This high-level
|
|
|
|
function can be used to prevent an important page from slipping out of
|
|
|
|
the buffer pool. */
|
|
|
|
void
|
|
|
|
buf_page_make_young(
|
|
|
|
/*================*/
|
|
|
|
buf_page_t* bpage); /*!< in: buffer block of a file page */
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
#ifdef UNIV_DEBUG
|
|
|
|
/** Sets file_page_was_freed TRUE if the page is found in the buffer pool.
|
2014-02-26 19:11:54 +01:00
|
|
|
This function should be called when we free a file page and want the
|
|
|
|
debug version to check that it is not accessed any more unless
|
|
|
|
reallocated.
|
2016-08-12 11:17:45 +03:00
|
|
|
@param[in] page_id page id
|
|
|
|
@return control block if found in page hash table, otherwise NULL */
|
2018-10-18 18:23:12 +03:00
|
|
|
buf_page_t* buf_page_set_file_page_was_freed(const page_id_t page_id);
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
/** Sets file_page_was_freed FALSE if the page is found in the buffer pool.
|
2014-02-26 19:11:54 +01:00
|
|
|
This function should be called when we free a file page and want the
|
|
|
|
debug version to check that it is not accessed any more unless
|
|
|
|
reallocated.
|
2016-08-12 11:17:45 +03:00
|
|
|
@param[in] page_id page id
|
|
|
|
@return control block if found in page hash table, otherwise NULL */
|
2018-10-18 18:23:12 +03:00
|
|
|
buf_page_t* buf_page_reset_file_page_was_freed(const page_id_t page_id);
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
#endif /* UNIV_DEBUG */
|
2014-02-26 19:11:54 +01:00
|
|
|
/********************************************************************//**
|
|
|
|
Reads the freed_page_clock of a buffer block.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return freed_page_clock */
|
2014-02-26 19:11:54 +01:00
|
|
|
UNIV_INLINE
|
2017-03-01 08:27:39 +02:00
|
|
|
unsigned
|
2014-02-26 19:11:54 +01:00
|
|
|
buf_page_get_freed_page_clock(
|
|
|
|
/*==========================*/
|
|
|
|
const buf_page_t* bpage) /*!< in: block */
|
2016-09-06 09:43:16 +03:00
|
|
|
MY_ATTRIBUTE((warn_unused_result));
|
2014-02-26 19:11:54 +01:00
|
|
|
/********************************************************************//**
|
|
|
|
Reads the freed_page_clock of a buffer block.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return freed_page_clock */
|
2014-02-26 19:11:54 +01:00
|
|
|
UNIV_INLINE
|
2017-03-01 08:27:39 +02:00
|
|
|
unsigned
|
2014-02-26 19:11:54 +01:00
|
|
|
buf_block_get_freed_page_clock(
|
|
|
|
/*===========================*/
|
|
|
|
const buf_block_t* block) /*!< in: block */
|
2016-09-06 09:43:16 +03:00
|
|
|
MY_ATTRIBUTE((warn_unused_result));
|
2014-02-26 19:11:54 +01:00
|
|
|
|
MDEV-19514 Defer change buffer merge until pages are requested
We will remove the InnoDB background operation of merging buffered
changes to secondary index leaf pages. Changes will only be merged as a
result of an operation that accesses a secondary index leaf page,
such as a SQL statement that performs a lookup via that index,
or is modifying the index. Also ROLLBACK and some background operations,
such as purging the history of committed transactions, or computing
index cardinality statistics, can cause change buffer merge.
Encryption key rotation will not perform change buffer merge.
The motivation of this change is to simplify the I/O logic and to
allow crash recovery to happen in the background (MDEV-14481).
We also hope that this will reduce the number of "mystery" crashes
due to corrupted data. Because change buffer merge will typically
take place as a result of executing SQL statements, there should be
a clearer connection between the crash and the SQL statements that
were executed when the server crashed.
In many cases, a slight performance improvement was observed.
This is joint work with Thirunarayanan Balathandayuthapani
and was tested by Axel Schwenke and Matthias Leich.
The InnoDB monitor counter innodb_ibuf_merge_usec will be removed.
On slow shutdown (innodb_fast_shutdown=0), we will continue to
merge all buffered changes (and purge all undo log history).
Two InnoDB configuration parameters will be changed as follows:
innodb_disable_background_merge: Removed.
This parameter existed only in debug builds.
All change buffer merges will use synchronous reads.
innodb_force_recovery will be changed as follows:
* innodb_force_recovery=4 will be the same as innodb_force_recovery=3
(the change buffer merge cannot be disabled; it can only happen as
a result of an operation that accesses a secondary index leaf page).
The option used to be capable of corrupting secondary index leaf pages.
Now that capability is removed, and innodb_force_recovery=4 becomes 'safe'.
* innodb_force_recovery=5 (which essentially hard-wires
SET GLOBAL TRANSACTION ISOLATION LEVEL READ UNCOMMITTED)
becomes safe to use. Bogus data can be returned to SQL, but
persistent InnoDB data files will not be corrupted further.
* innodb_force_recovery=6 (ignore the redo log files)
will be the only option that can potentially cause
persistent corruption of InnoDB data files.
Code changes:
buf_page_t::ibuf_exist: New flag, to indicate whether buffered
changes exist for a buffer pool page. Pages with pending changes
can be returned by buf_page_get_gen(). Previously, the changes
were always merged inside buf_page_get_gen() if needed.
ibuf_page_exists(const buf_page_t&): Check if a buffered changes
exist for an X-latched or read-fixed page.
buf_page_get_gen(): Add the parameter allow_ibuf_merge=false.
All callers that know that they may be accessing a secondary index
leaf page must pass this parameter as allow_ibuf_merge=true,
unless it does not matter for that caller whether all buffered
changes have been applied. Assert that whenever allow_ibuf_merge
holds, the page actually is a leaf page. Attempt change buffer
merge only to secondary B-tree index leaf pages.
btr_block_get(): Add parameter 'bool merge'.
All callers of btr_block_get() should know whether the page could be
a secondary index leaf page. If it is not, we should avoid consulting
the change buffer bitmap to even consider a merge. This is the main
interface to requesting index pages from the buffer pool.
ibuf_merge_or_delete_for_page(), recv_recover_page(): Replace
buf_page_get_known_nowait() with much simpler logic, because
it is now guaranteed that that the block is x-latched or read-fixed.
mlog_init_t::mark_ibuf_exist(): Renamed from mlog_init_t::ibuf_merge().
On crash recovery, we will no longer merge any buffered changes
for the pages that we read into the buffer pool during the last batch
of applying log records.
buf_page_get_gen_known_nowait(), BUF_MAKE_YOUNG, BUF_KEEP_OLD: Remove.
btr_search_guess_on_hash(): Merge buf_page_get_gen_known_nowait()
to its only remaining caller.
buf_page_make_young_if_needed(): Define as an inline function.
Add the parameter buf_pool.
buf_page_peek_if_young(), buf_page_peek_if_too_old(): Add the
parameter buf_pool.
fil_space_validate_for_mtr_commit(): Remove a bogus comment
about background merge of the change buffer.
btr_cur_open_at_rnd_pos_func(), btr_cur_search_to_nth_level_func(),
btr_cur_open_at_index_side_func(): Use narrower data types and scopes.
ibuf_read_merge_pages(): Replaces buf_read_ibuf_merge_pages().
Merge the change buffer by invoking buf_page_get_gen().
2019-10-11 17:28:15 +03:00
|
|
|
/** Determine if a block is still close enough to the MRU end of the LRU list
|
2014-02-26 19:11:54 +01:00
|
|
|
meaning that it is not in danger of getting evicted and also implying
|
|
|
|
that it has been accessed recently.
|
|
|
|
Note that this is for heuristics only and does not reserve buffer pool
|
|
|
|
mutex.
|
MDEV-19514 Defer change buffer merge until pages are requested
We will remove the InnoDB background operation of merging buffered
changes to secondary index leaf pages. Changes will only be merged as a
result of an operation that accesses a secondary index leaf page,
such as a SQL statement that performs a lookup via that index,
or is modifying the index. Also ROLLBACK and some background operations,
such as purging the history of committed transactions, or computing
index cardinality statistics, can cause change buffer merge.
Encryption key rotation will not perform change buffer merge.
The motivation of this change is to simplify the I/O logic and to
allow crash recovery to happen in the background (MDEV-14481).
We also hope that this will reduce the number of "mystery" crashes
due to corrupted data. Because change buffer merge will typically
take place as a result of executing SQL statements, there should be
a clearer connection between the crash and the SQL statements that
were executed when the server crashed.
In many cases, a slight performance improvement was observed.
This is joint work with Thirunarayanan Balathandayuthapani
and was tested by Axel Schwenke and Matthias Leich.
The InnoDB monitor counter innodb_ibuf_merge_usec will be removed.
On slow shutdown (innodb_fast_shutdown=0), we will continue to
merge all buffered changes (and purge all undo log history).
Two InnoDB configuration parameters will be changed as follows:
innodb_disable_background_merge: Removed.
This parameter existed only in debug builds.
All change buffer merges will use synchronous reads.
innodb_force_recovery will be changed as follows:
* innodb_force_recovery=4 will be the same as innodb_force_recovery=3
(the change buffer merge cannot be disabled; it can only happen as
a result of an operation that accesses a secondary index leaf page).
The option used to be capable of corrupting secondary index leaf pages.
Now that capability is removed, and innodb_force_recovery=4 becomes 'safe'.
* innodb_force_recovery=5 (which essentially hard-wires
SET GLOBAL TRANSACTION ISOLATION LEVEL READ UNCOMMITTED)
becomes safe to use. Bogus data can be returned to SQL, but
persistent InnoDB data files will not be corrupted further.
* innodb_force_recovery=6 (ignore the redo log files)
will be the only option that can potentially cause
persistent corruption of InnoDB data files.
Code changes:
buf_page_t::ibuf_exist: New flag, to indicate whether buffered
changes exist for a buffer pool page. Pages with pending changes
can be returned by buf_page_get_gen(). Previously, the changes
were always merged inside buf_page_get_gen() if needed.
ibuf_page_exists(const buf_page_t&): Check if a buffered changes
exist for an X-latched or read-fixed page.
buf_page_get_gen(): Add the parameter allow_ibuf_merge=false.
All callers that know that they may be accessing a secondary index
leaf page must pass this parameter as allow_ibuf_merge=true,
unless it does not matter for that caller whether all buffered
changes have been applied. Assert that whenever allow_ibuf_merge
holds, the page actually is a leaf page. Attempt change buffer
merge only to secondary B-tree index leaf pages.
btr_block_get(): Add parameter 'bool merge'.
All callers of btr_block_get() should know whether the page could be
a secondary index leaf page. If it is not, we should avoid consulting
the change buffer bitmap to even consider a merge. This is the main
interface to requesting index pages from the buffer pool.
ibuf_merge_or_delete_for_page(), recv_recover_page(): Replace
buf_page_get_known_nowait() with much simpler logic, because
it is now guaranteed that that the block is x-latched or read-fixed.
mlog_init_t::mark_ibuf_exist(): Renamed from mlog_init_t::ibuf_merge().
On crash recovery, we will no longer merge any buffered changes
for the pages that we read into the buffer pool during the last batch
of applying log records.
buf_page_get_gen_known_nowait(), BUF_MAKE_YOUNG, BUF_KEEP_OLD: Remove.
btr_search_guess_on_hash(): Merge buf_page_get_gen_known_nowait()
to its only remaining caller.
buf_page_make_young_if_needed(): Define as an inline function.
Add the parameter buf_pool.
buf_page_peek_if_young(), buf_page_peek_if_too_old(): Add the
parameter buf_pool.
fil_space_validate_for_mtr_commit(): Remove a bogus comment
about background merge of the change buffer.
btr_cur_open_at_rnd_pos_func(), btr_cur_search_to_nth_level_func(),
btr_cur_open_at_index_side_func(): Use narrower data types and scopes.
ibuf_read_merge_pages(): Replaces buf_read_ibuf_merge_pages().
Merge the change buffer by invoking buf_page_get_gen().
2019-10-11 17:28:15 +03:00
|
|
|
@param[in] bpage buffer pool page
|
|
|
|
@return whether bpage is close to MRU end of LRU */
|
2020-02-12 14:45:21 +02:00
|
|
|
inline bool buf_page_peek_if_young(const buf_page_t *bpage);
|
MDEV-19514 Defer change buffer merge until pages are requested
We will remove the InnoDB background operation of merging buffered
changes to secondary index leaf pages. Changes will only be merged as a
result of an operation that accesses a secondary index leaf page,
such as a SQL statement that performs a lookup via that index,
or is modifying the index. Also ROLLBACK and some background operations,
such as purging the history of committed transactions, or computing
index cardinality statistics, can cause change buffer merge.
Encryption key rotation will not perform change buffer merge.
The motivation of this change is to simplify the I/O logic and to
allow crash recovery to happen in the background (MDEV-14481).
We also hope that this will reduce the number of "mystery" crashes
due to corrupted data. Because change buffer merge will typically
take place as a result of executing SQL statements, there should be
a clearer connection between the crash and the SQL statements that
were executed when the server crashed.
In many cases, a slight performance improvement was observed.
This is joint work with Thirunarayanan Balathandayuthapani
and was tested by Axel Schwenke and Matthias Leich.
The InnoDB monitor counter innodb_ibuf_merge_usec will be removed.
On slow shutdown (innodb_fast_shutdown=0), we will continue to
merge all buffered changes (and purge all undo log history).
Two InnoDB configuration parameters will be changed as follows:
innodb_disable_background_merge: Removed.
This parameter existed only in debug builds.
All change buffer merges will use synchronous reads.
innodb_force_recovery will be changed as follows:
* innodb_force_recovery=4 will be the same as innodb_force_recovery=3
(the change buffer merge cannot be disabled; it can only happen as
a result of an operation that accesses a secondary index leaf page).
The option used to be capable of corrupting secondary index leaf pages.
Now that capability is removed, and innodb_force_recovery=4 becomes 'safe'.
* innodb_force_recovery=5 (which essentially hard-wires
SET GLOBAL TRANSACTION ISOLATION LEVEL READ UNCOMMITTED)
becomes safe to use. Bogus data can be returned to SQL, but
persistent InnoDB data files will not be corrupted further.
* innodb_force_recovery=6 (ignore the redo log files)
will be the only option that can potentially cause
persistent corruption of InnoDB data files.
Code changes:
buf_page_t::ibuf_exist: New flag, to indicate whether buffered
changes exist for a buffer pool page. Pages with pending changes
can be returned by buf_page_get_gen(). Previously, the changes
were always merged inside buf_page_get_gen() if needed.
ibuf_page_exists(const buf_page_t&): Check if a buffered changes
exist for an X-latched or read-fixed page.
buf_page_get_gen(): Add the parameter allow_ibuf_merge=false.
All callers that know that they may be accessing a secondary index
leaf page must pass this parameter as allow_ibuf_merge=true,
unless it does not matter for that caller whether all buffered
changes have been applied. Assert that whenever allow_ibuf_merge
holds, the page actually is a leaf page. Attempt change buffer
merge only to secondary B-tree index leaf pages.
btr_block_get(): Add parameter 'bool merge'.
All callers of btr_block_get() should know whether the page could be
a secondary index leaf page. If it is not, we should avoid consulting
the change buffer bitmap to even consider a merge. This is the main
interface to requesting index pages from the buffer pool.
ibuf_merge_or_delete_for_page(), recv_recover_page(): Replace
buf_page_get_known_nowait() with much simpler logic, because
it is now guaranteed that that the block is x-latched or read-fixed.
mlog_init_t::mark_ibuf_exist(): Renamed from mlog_init_t::ibuf_merge().
On crash recovery, we will no longer merge any buffered changes
for the pages that we read into the buffer pool during the last batch
of applying log records.
buf_page_get_gen_known_nowait(), BUF_MAKE_YOUNG, BUF_KEEP_OLD: Remove.
btr_search_guess_on_hash(): Merge buf_page_get_gen_known_nowait()
to its only remaining caller.
buf_page_make_young_if_needed(): Define as an inline function.
Add the parameter buf_pool.
buf_page_peek_if_young(), buf_page_peek_if_too_old(): Add the
parameter buf_pool.
fil_space_validate_for_mtr_commit(): Remove a bogus comment
about background merge of the change buffer.
btr_cur_open_at_rnd_pos_func(), btr_cur_search_to_nth_level_func(),
btr_cur_open_at_index_side_func(): Use narrower data types and scopes.
ibuf_read_merge_pages(): Replaces buf_read_ibuf_merge_pages().
Merge the change buffer by invoking buf_page_get_gen().
2019-10-11 17:28:15 +03:00
|
|
|
|
|
|
|
/** Determine if a block should be moved to the start of the LRU list if
|
|
|
|
there is danger of dropping from the buffer pool.
|
|
|
|
@param[in] bpage buffer pool page
|
|
|
|
@return true if bpage should be made younger */
|
2020-02-12 14:45:21 +02:00
|
|
|
inline bool buf_page_peek_if_too_old(const buf_page_t *bpage);
|
MDEV-19514 Defer change buffer merge until pages are requested
We will remove the InnoDB background operation of merging buffered
changes to secondary index leaf pages. Changes will only be merged as a
result of an operation that accesses a secondary index leaf page,
such as a SQL statement that performs a lookup via that index,
or is modifying the index. Also ROLLBACK and some background operations,
such as purging the history of committed transactions, or computing
index cardinality statistics, can cause change buffer merge.
Encryption key rotation will not perform change buffer merge.
The motivation of this change is to simplify the I/O logic and to
allow crash recovery to happen in the background (MDEV-14481).
We also hope that this will reduce the number of "mystery" crashes
due to corrupted data. Because change buffer merge will typically
take place as a result of executing SQL statements, there should be
a clearer connection between the crash and the SQL statements that
were executed when the server crashed.
In many cases, a slight performance improvement was observed.
This is joint work with Thirunarayanan Balathandayuthapani
and was tested by Axel Schwenke and Matthias Leich.
The InnoDB monitor counter innodb_ibuf_merge_usec will be removed.
On slow shutdown (innodb_fast_shutdown=0), we will continue to
merge all buffered changes (and purge all undo log history).
Two InnoDB configuration parameters will be changed as follows:
innodb_disable_background_merge: Removed.
This parameter existed only in debug builds.
All change buffer merges will use synchronous reads.
innodb_force_recovery will be changed as follows:
* innodb_force_recovery=4 will be the same as innodb_force_recovery=3
(the change buffer merge cannot be disabled; it can only happen as
a result of an operation that accesses a secondary index leaf page).
The option used to be capable of corrupting secondary index leaf pages.
Now that capability is removed, and innodb_force_recovery=4 becomes 'safe'.
* innodb_force_recovery=5 (which essentially hard-wires
SET GLOBAL TRANSACTION ISOLATION LEVEL READ UNCOMMITTED)
becomes safe to use. Bogus data can be returned to SQL, but
persistent InnoDB data files will not be corrupted further.
* innodb_force_recovery=6 (ignore the redo log files)
will be the only option that can potentially cause
persistent corruption of InnoDB data files.
Code changes:
buf_page_t::ibuf_exist: New flag, to indicate whether buffered
changes exist for a buffer pool page. Pages with pending changes
can be returned by buf_page_get_gen(). Previously, the changes
were always merged inside buf_page_get_gen() if needed.
ibuf_page_exists(const buf_page_t&): Check if a buffered changes
exist for an X-latched or read-fixed page.
buf_page_get_gen(): Add the parameter allow_ibuf_merge=false.
All callers that know that they may be accessing a secondary index
leaf page must pass this parameter as allow_ibuf_merge=true,
unless it does not matter for that caller whether all buffered
changes have been applied. Assert that whenever allow_ibuf_merge
holds, the page actually is a leaf page. Attempt change buffer
merge only to secondary B-tree index leaf pages.
btr_block_get(): Add parameter 'bool merge'.
All callers of btr_block_get() should know whether the page could be
a secondary index leaf page. If it is not, we should avoid consulting
the change buffer bitmap to even consider a merge. This is the main
interface to requesting index pages from the buffer pool.
ibuf_merge_or_delete_for_page(), recv_recover_page(): Replace
buf_page_get_known_nowait() with much simpler logic, because
it is now guaranteed that that the block is x-latched or read-fixed.
mlog_init_t::mark_ibuf_exist(): Renamed from mlog_init_t::ibuf_merge().
On crash recovery, we will no longer merge any buffered changes
for the pages that we read into the buffer pool during the last batch
of applying log records.
buf_page_get_gen_known_nowait(), BUF_MAKE_YOUNG, BUF_KEEP_OLD: Remove.
btr_search_guess_on_hash(): Merge buf_page_get_gen_known_nowait()
to its only remaining caller.
buf_page_make_young_if_needed(): Define as an inline function.
Add the parameter buf_pool.
buf_page_peek_if_young(), buf_page_peek_if_too_old(): Add the
parameter buf_pool.
fil_space_validate_for_mtr_commit(): Remove a bogus comment
about background merge of the change buffer.
btr_cur_open_at_rnd_pos_func(), btr_cur_search_to_nth_level_func(),
btr_cur_open_at_index_side_func(): Use narrower data types and scopes.
ibuf_read_merge_pages(): Replaces buf_read_ibuf_merge_pages().
Merge the change buffer by invoking buf_page_get_gen().
2019-10-11 17:28:15 +03:00
|
|
|
|
|
|
|
/** Move a page to the start of the buffer pool LRU list if it is too old.
|
|
|
|
@param[in,out] bpage buffer pool page */
|
2020-02-12 14:45:21 +02:00
|
|
|
inline void buf_page_make_young_if_needed(buf_page_t *bpage)
|
MDEV-19514 Defer change buffer merge until pages are requested
We will remove the InnoDB background operation of merging buffered
changes to secondary index leaf pages. Changes will only be merged as a
result of an operation that accesses a secondary index leaf page,
such as a SQL statement that performs a lookup via that index,
or is modifying the index. Also ROLLBACK and some background operations,
such as purging the history of committed transactions, or computing
index cardinality statistics, can cause change buffer merge.
Encryption key rotation will not perform change buffer merge.
The motivation of this change is to simplify the I/O logic and to
allow crash recovery to happen in the background (MDEV-14481).
We also hope that this will reduce the number of "mystery" crashes
due to corrupted data. Because change buffer merge will typically
take place as a result of executing SQL statements, there should be
a clearer connection between the crash and the SQL statements that
were executed when the server crashed.
In many cases, a slight performance improvement was observed.
This is joint work with Thirunarayanan Balathandayuthapani
and was tested by Axel Schwenke and Matthias Leich.
The InnoDB monitor counter innodb_ibuf_merge_usec will be removed.
On slow shutdown (innodb_fast_shutdown=0), we will continue to
merge all buffered changes (and purge all undo log history).
Two InnoDB configuration parameters will be changed as follows:
innodb_disable_background_merge: Removed.
This parameter existed only in debug builds.
All change buffer merges will use synchronous reads.
innodb_force_recovery will be changed as follows:
* innodb_force_recovery=4 will be the same as innodb_force_recovery=3
(the change buffer merge cannot be disabled; it can only happen as
a result of an operation that accesses a secondary index leaf page).
The option used to be capable of corrupting secondary index leaf pages.
Now that capability is removed, and innodb_force_recovery=4 becomes 'safe'.
* innodb_force_recovery=5 (which essentially hard-wires
SET GLOBAL TRANSACTION ISOLATION LEVEL READ UNCOMMITTED)
becomes safe to use. Bogus data can be returned to SQL, but
persistent InnoDB data files will not be corrupted further.
* innodb_force_recovery=6 (ignore the redo log files)
will be the only option that can potentially cause
persistent corruption of InnoDB data files.
Code changes:
buf_page_t::ibuf_exist: New flag, to indicate whether buffered
changes exist for a buffer pool page. Pages with pending changes
can be returned by buf_page_get_gen(). Previously, the changes
were always merged inside buf_page_get_gen() if needed.
ibuf_page_exists(const buf_page_t&): Check if a buffered changes
exist for an X-latched or read-fixed page.
buf_page_get_gen(): Add the parameter allow_ibuf_merge=false.
All callers that know that they may be accessing a secondary index
leaf page must pass this parameter as allow_ibuf_merge=true,
unless it does not matter for that caller whether all buffered
changes have been applied. Assert that whenever allow_ibuf_merge
holds, the page actually is a leaf page. Attempt change buffer
merge only to secondary B-tree index leaf pages.
btr_block_get(): Add parameter 'bool merge'.
All callers of btr_block_get() should know whether the page could be
a secondary index leaf page. If it is not, we should avoid consulting
the change buffer bitmap to even consider a merge. This is the main
interface to requesting index pages from the buffer pool.
ibuf_merge_or_delete_for_page(), recv_recover_page(): Replace
buf_page_get_known_nowait() with much simpler logic, because
it is now guaranteed that that the block is x-latched or read-fixed.
mlog_init_t::mark_ibuf_exist(): Renamed from mlog_init_t::ibuf_merge().
On crash recovery, we will no longer merge any buffered changes
for the pages that we read into the buffer pool during the last batch
of applying log records.
buf_page_get_gen_known_nowait(), BUF_MAKE_YOUNG, BUF_KEEP_OLD: Remove.
btr_search_guess_on_hash(): Merge buf_page_get_gen_known_nowait()
to its only remaining caller.
buf_page_make_young_if_needed(): Define as an inline function.
Add the parameter buf_pool.
buf_page_peek_if_young(), buf_page_peek_if_too_old(): Add the
parameter buf_pool.
fil_space_validate_for_mtr_commit(): Remove a bogus comment
about background merge of the change buffer.
btr_cur_open_at_rnd_pos_func(), btr_cur_search_to_nth_level_func(),
btr_cur_open_at_index_side_func(): Use narrower data types and scopes.
ibuf_read_merge_pages(): Replaces buf_read_ibuf_merge_pages().
Merge the change buffer by invoking buf_page_get_gen().
2019-10-11 17:28:15 +03:00
|
|
|
{
|
2020-02-12 14:45:21 +02:00
|
|
|
if (UNIV_UNLIKELY(buf_page_peek_if_too_old(bpage))) {
|
MDEV-19514 Defer change buffer merge until pages are requested
We will remove the InnoDB background operation of merging buffered
changes to secondary index leaf pages. Changes will only be merged as a
result of an operation that accesses a secondary index leaf page,
such as a SQL statement that performs a lookup via that index,
or is modifying the index. Also ROLLBACK and some background operations,
such as purging the history of committed transactions, or computing
index cardinality statistics, can cause change buffer merge.
Encryption key rotation will not perform change buffer merge.
The motivation of this change is to simplify the I/O logic and to
allow crash recovery to happen in the background (MDEV-14481).
We also hope that this will reduce the number of "mystery" crashes
due to corrupted data. Because change buffer merge will typically
take place as a result of executing SQL statements, there should be
a clearer connection between the crash and the SQL statements that
were executed when the server crashed.
In many cases, a slight performance improvement was observed.
This is joint work with Thirunarayanan Balathandayuthapani
and was tested by Axel Schwenke and Matthias Leich.
The InnoDB monitor counter innodb_ibuf_merge_usec will be removed.
On slow shutdown (innodb_fast_shutdown=0), we will continue to
merge all buffered changes (and purge all undo log history).
Two InnoDB configuration parameters will be changed as follows:
innodb_disable_background_merge: Removed.
This parameter existed only in debug builds.
All change buffer merges will use synchronous reads.
innodb_force_recovery will be changed as follows:
* innodb_force_recovery=4 will be the same as innodb_force_recovery=3
(the change buffer merge cannot be disabled; it can only happen as
a result of an operation that accesses a secondary index leaf page).
The option used to be capable of corrupting secondary index leaf pages.
Now that capability is removed, and innodb_force_recovery=4 becomes 'safe'.
* innodb_force_recovery=5 (which essentially hard-wires
SET GLOBAL TRANSACTION ISOLATION LEVEL READ UNCOMMITTED)
becomes safe to use. Bogus data can be returned to SQL, but
persistent InnoDB data files will not be corrupted further.
* innodb_force_recovery=6 (ignore the redo log files)
will be the only option that can potentially cause
persistent corruption of InnoDB data files.
Code changes:
buf_page_t::ibuf_exist: New flag, to indicate whether buffered
changes exist for a buffer pool page. Pages with pending changes
can be returned by buf_page_get_gen(). Previously, the changes
were always merged inside buf_page_get_gen() if needed.
ibuf_page_exists(const buf_page_t&): Check if a buffered changes
exist for an X-latched or read-fixed page.
buf_page_get_gen(): Add the parameter allow_ibuf_merge=false.
All callers that know that they may be accessing a secondary index
leaf page must pass this parameter as allow_ibuf_merge=true,
unless it does not matter for that caller whether all buffered
changes have been applied. Assert that whenever allow_ibuf_merge
holds, the page actually is a leaf page. Attempt change buffer
merge only to secondary B-tree index leaf pages.
btr_block_get(): Add parameter 'bool merge'.
All callers of btr_block_get() should know whether the page could be
a secondary index leaf page. If it is not, we should avoid consulting
the change buffer bitmap to even consider a merge. This is the main
interface to requesting index pages from the buffer pool.
ibuf_merge_or_delete_for_page(), recv_recover_page(): Replace
buf_page_get_known_nowait() with much simpler logic, because
it is now guaranteed that that the block is x-latched or read-fixed.
mlog_init_t::mark_ibuf_exist(): Renamed from mlog_init_t::ibuf_merge().
On crash recovery, we will no longer merge any buffered changes
for the pages that we read into the buffer pool during the last batch
of applying log records.
buf_page_get_gen_known_nowait(), BUF_MAKE_YOUNG, BUF_KEEP_OLD: Remove.
btr_search_guess_on_hash(): Merge buf_page_get_gen_known_nowait()
to its only remaining caller.
buf_page_make_young_if_needed(): Define as an inline function.
Add the parameter buf_pool.
buf_page_peek_if_young(), buf_page_peek_if_too_old(): Add the
parameter buf_pool.
fil_space_validate_for_mtr_commit(): Remove a bogus comment
about background merge of the change buffer.
btr_cur_open_at_rnd_pos_func(), btr_cur_search_to_nth_level_func(),
btr_cur_open_at_index_side_func(): Use narrower data types and scopes.
ibuf_read_merge_pages(): Replaces buf_read_ibuf_merge_pages().
Merge the change buffer by invoking buf_page_get_gen().
2019-10-11 17:28:15 +03:00
|
|
|
buf_page_make_young(bpage);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
/********************************************************************//**
|
|
|
|
Increments the modify clock of a frame by 1. The caller must (1) own the
|
|
|
|
buf_pool->mutex and block bufferfix count has to be zero, (2) or own an x-lock
|
|
|
|
on the block. */
|
|
|
|
UNIV_INLINE
|
|
|
|
void
|
|
|
|
buf_block_modify_clock_inc(
|
|
|
|
/*=======================*/
|
|
|
|
buf_block_t* block); /*!< in: block */
|
|
|
|
/********************************************************************//**
|
|
|
|
Returns the value of the modify clock. The caller must have an s-lock
|
|
|
|
or x-lock on the block.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return value */
|
2014-02-26 19:11:54 +01:00
|
|
|
UNIV_INLINE
|
|
|
|
ib_uint64_t
|
|
|
|
buf_block_get_modify_clock(
|
|
|
|
/*=======================*/
|
|
|
|
buf_block_t* block); /*!< in: block */
|
|
|
|
/*******************************************************************//**
|
|
|
|
Increments the bufferfix count. */
|
|
|
|
UNIV_INLINE
|
|
|
|
void
|
|
|
|
buf_block_buf_fix_inc_func(
|
|
|
|
/*=======================*/
|
2016-08-12 11:17:45 +03:00
|
|
|
# ifdef UNIV_DEBUG
|
2014-02-26 19:11:54 +01:00
|
|
|
const char* file, /*!< in: file name */
|
2017-03-01 08:27:39 +02:00
|
|
|
unsigned line, /*!< in: line */
|
2016-08-12 11:17:45 +03:00
|
|
|
# endif /* UNIV_DEBUG */
|
2014-02-26 19:11:54 +01:00
|
|
|
buf_block_t* block) /*!< in/out: block to bufferfix */
|
2016-06-21 14:21:03 +02:00
|
|
|
MY_ATTRIBUTE((nonnull));
|
2014-05-05 18:20:28 +02:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
# ifdef UNIV_DEBUG
|
2014-02-26 19:11:54 +01:00
|
|
|
/** Increments the bufferfix count.
|
2016-08-12 11:17:45 +03:00
|
|
|
@param[in,out] b block to bufferfix
|
|
|
|
@param[in] f file name where requested
|
|
|
|
@param[in] l line number where requested */
|
2016-12-30 15:04:10 +02:00
|
|
|
# define buf_block_buf_fix_inc(b,f,l) buf_block_buf_fix_inc_func(f,l,b)
|
2016-08-12 11:17:45 +03:00
|
|
|
# else /* UNIV_DEBUG */
|
2014-02-26 19:11:54 +01:00
|
|
|
/** Increments the bufferfix count.
|
2016-08-12 11:17:45 +03:00
|
|
|
@param[in,out] b block to bufferfix
|
|
|
|
@param[in] f file name where requested
|
|
|
|
@param[in] l line number where requested */
|
2016-12-30 15:04:10 +02:00
|
|
|
# define buf_block_buf_fix_inc(b,f,l) buf_block_buf_fix_inc_func(b)
|
2016-08-12 11:17:45 +03:00
|
|
|
# endif /* UNIV_DEBUG */
|
|
|
|
#endif /* !UNIV_INNOCHECKSUM */
|
|
|
|
|
MDEV-18644: Support full_crc32 for page_compressed
This is a follow-up task to MDEV-12026, which introduced
innodb_checksum_algorithm=full_crc32 and a simpler page format.
MDEV-12026 did not enable full_crc32 for page_compressed tables,
which we will be doing now.
This is joint work with Thirunarayanan Balathandayuthapani.
For innodb_checksum_algorithm=full_crc32 we change the
page_compressed format as follows:
FIL_PAGE_TYPE: The most significant bit will be set to indicate
page_compressed format. The least significant bits will contain
the compressed page size, rounded up to a multiple of 256 bytes.
The checksum will be stored in the last 4 bytes of the page
(whether it is the full page or a page_compressed page whose
size is determined by FIL_PAGE_TYPE), covering all preceding
bytes of the page. If encryption is used, then the page will
be encrypted between compression and computing the checksum.
For page_compressed, FIL_PAGE_LSN will not be repeated at
the end of the page.
FSP_SPACE_FLAGS (already implemented as part of MDEV-12026):
We will store the innodb_compression_algorithm that may be used
to compress pages. Previously, the choice of algorithm was written
to each compressed data page separately, and one would be unable
to know in advance which compression algorithm(s) are used.
fil_space_t::full_crc32_page_compressed_len(): Determine if the
page_compressed algorithm of the tablespace needs to know the
exact length of the compressed data. If yes, we will reserve and
write an extra byte for this right before the checksum.
buf_page_is_compressed(): Determine if a page uses page_compressed
(in any innodb_checksum_algorithm).
fil_page_decompress(): Pass also fil_space_t::flags so that the
format can be determined.
buf_page_is_zeroes(): Check if a page is full of zero bytes.
buf_page_full_crc32_is_corrupted(): Renamed from
buf_encrypted_full_crc32_page_is_corrupted(). For full_crc32,
we always simply validate the checksum to the page contents,
while the physical page size is explicitly specified by an
unencrypted part of the page header.
buf_page_full_crc32_size(): Determine the size of a full_crc32 page.
buf_dblwr_check_page_lsn(): Make this a debug-only function, because
it involves potentially costly lookups of fil_space_t.
create_table_info_t::check_table_options(),
ha_innobase::check_if_supported_inplace_alter(): Do allow the creation
of SPATIAL INDEX with full_crc32 also when page_compressed is used.
commit_cache_norebuild(): Preserve the compression algorithm when
updating the page_compression_level.
dict_tf_to_fsp_flags(): Set the flags for page compression algorithm.
FIXME: Maybe there should be a table option page_compression_algorithm
and a session variable to back it?
2019-03-18 14:08:43 +02:00
|
|
|
/** Check if a page is all zeroes.
|
|
|
|
@param[in] read_buf database page
|
|
|
|
@param[in] page_size page frame size
|
|
|
|
@return whether the page is all zeroes */
|
|
|
|
bool buf_page_is_zeroes(const void* read_buf, size_t page_size);
|
|
|
|
|
MDEV-11759: Encryption code in MariaDB 10.1/10.2 causes
compatibility problems
Pages that are encrypted contain post encryption checksum on
different location that normal checksum fields. Therefore,
we should before decryption check this checksum to avoid
unencrypting corrupted pages. After decryption we can use
traditional checksum check to detect if page is corrupted
or unencryption was done using incorrect key.
Pages that are page compressed do not contain any checksum,
here we need to fist unencrypt, decompress and finally
use tradional checksum check to detect page corruption
or that we used incorrect key in unencryption.
buf0buf.cc: buf_page_is_corrupted() mofified so that
compressed pages are skipped.
buf0buf.h, buf_block_init(), buf_page_init_low():
removed unnecessary page_encrypted, page_compressed,
stored_checksum, valculated_checksum fields from
buf_page_t
buf_page_get_gen(): use new buf_page_check_corrupt() function
to detect corrupted pages.
buf_page_check_corrupt(): If page was not yet decrypted
check if post encryption checksum still matches.
If page is not anymore encrypted, use buf_page_is_corrupted()
traditional checksum method.
If page is detected as corrupted and it is not encrypted
we print corruption message to error log.
If page is still encrypted or it was encrypted and now
corrupted, we will print message that page is
encrypted to error log.
buf_page_io_complete(): use new buf_page_check_corrupt()
function to detect corrupted pages.
buf_page_decrypt_after_read(): Verify post encryption
checksum before tring to decrypt.
fil0crypt.cc: fil_encrypt_buf() verify post encryption
checksum and ind fil_space_decrypt() return true
if we really decrypted the page.
fil_space_verify_crypt_checksum(): rewrite to use
the method used when calculating post encryption
checksum. We also check if post encryption checksum
matches that traditional checksum check does not
match.
fil0fil.ic: Add missed page type encrypted and page
compressed to fil_get_page_type_name()
Note that this change does not yet fix innochecksum tool,
that will be done in separate MDEV.
Fix test failures caused by buf page corruption injection.
2017-02-06 10:47:55 +02:00
|
|
|
/** Checks if the page is in crc32 checksum format.
|
2017-03-30 12:48:42 +02:00
|
|
|
@param[in] read_buf database page
|
|
|
|
@param[in] checksum_field1 new checksum field
|
|
|
|
@param[in] checksum_field2 old checksum field
|
|
|
|
@return true if the page is in crc32 checksum format. */
|
MDEV-11759: Encryption code in MariaDB 10.1/10.2 causes
compatibility problems
Pages that are encrypted contain post encryption checksum on
different location that normal checksum fields. Therefore,
we should before decryption check this checksum to avoid
unencrypting corrupted pages. After decryption we can use
traditional checksum check to detect if page is corrupted
or unencryption was done using incorrect key.
Pages that are page compressed do not contain any checksum,
here we need to fist unencrypt, decompress and finally
use tradional checksum check to detect page corruption
or that we used incorrect key in unencryption.
buf0buf.cc: buf_page_is_corrupted() mofified so that
compressed pages are skipped.
buf0buf.h, buf_block_init(), buf_page_init_low():
removed unnecessary page_encrypted, page_compressed,
stored_checksum, valculated_checksum fields from
buf_page_t
buf_page_get_gen(): use new buf_page_check_corrupt() function
to detect corrupted pages.
buf_page_check_corrupt(): If page was not yet decrypted
check if post encryption checksum still matches.
If page is not anymore encrypted, use buf_page_is_corrupted()
traditional checksum method.
If page is detected as corrupted and it is not encrypted
we print corruption message to error log.
If page is still encrypted or it was encrypted and now
corrupted, we will print message that page is
encrypted to error log.
buf_page_io_complete(): use new buf_page_check_corrupt()
function to detect corrupted pages.
buf_page_decrypt_after_read(): Verify post encryption
checksum before tring to decrypt.
fil0crypt.cc: fil_encrypt_buf() verify post encryption
checksum and ind fil_space_decrypt() return true
if we really decrypted the page.
fil_space_verify_crypt_checksum(): rewrite to use
the method used when calculating post encryption
checksum. We also check if post encryption checksum
matches that traditional checksum check does not
match.
fil0fil.ic: Add missed page type encrypted and page
compressed to fil_get_page_type_name()
Note that this change does not yet fix innochecksum tool,
that will be done in separate MDEV.
Fix test failures caused by buf page corruption injection.
2017-02-06 10:47:55 +02:00
|
|
|
bool
|
|
|
|
buf_page_is_checksum_valid_crc32(
|
2017-03-30 12:48:42 +02:00
|
|
|
const byte* read_buf,
|
|
|
|
ulint checksum_field1,
|
MDEV-17958 Make bug-endian innodb_checksum_algorithm=crc32 optional
In MySQL 5.7, it was noticed that files are not portable between
big-endian and little-endian processor architectures
(such as SPARC and x86), because the original implementation of
innodb_checksum_algorithm=crc32 was not byte order agnostic.
A byte order agnostic implementation of innodb_checksum_algorithm=crc32
was only added to MySQL 5.7, not backported to 5.6. Consequently,
MariaDB Server versions 10.0 and 10.1 only contain the CRC-32C
implementation that works incorrectly on big-endian architectures,
and MariaDB Server 10.2.2 got the byte-order agnostic CRC-32C
implementation from MySQL 5.7.
MySQL 5.7 introduced a "legacy crc32" variant that is functionally
equivalent to the big-endian version of the original crc32 implementation.
Thanks to this variant, old data files can be transferred from big-endian
systems to newer versions.
Introducing new variants of checksum algorithms (without introducing
new names for them, or something on the pages themselves to identify
the algorithm) generally is a bad idea, because each checksum algorithm
is like a lottery ticket. The more algorithms you try, the more likely
it will be for the checksum to match on a corrupted page.
So, essentially MySQL 5.7 weakened innodb_checksum_algorithm=crc32,
and MariaDB 10.2.2 inherited this weakening.
We introduce a build option that together with MDEV-17957
makes innodb_checksum_algorithm=strict_crc32 strict again
by only allowing one variant of the checksum to match.
WITH_INNODB_BUG_ENDIAN_CRC32: A new cmake option for enabling the
bug-compatible "legacy crc32" checksum. This is only enabled on
big-endian systems by default, to facilitate an upgrade from
MariaDB 10.0 or 10.1. Checked by #ifdef INNODB_BUG_ENDIAN_CRC32.
ut_crc32_byte_by_byte: Remove (unused function).
legacy_big_endian_checksum: Remove. This variable seems to have
unnecessarily complicated the logic. When the weakening is enabled,
we must always fall back to the buggy checksum.
buf_page_check_crc32(): A helper function to compute one or
two CRC-32C variants.
2018-12-13 17:57:10 +02:00
|
|
|
ulint checksum_field2)
|
2017-03-30 12:48:42 +02:00
|
|
|
MY_ATTRIBUTE((nonnull(1), warn_unused_result));
|
MDEV-11759: Encryption code in MariaDB 10.1/10.2 causes
compatibility problems
Pages that are encrypted contain post encryption checksum on
different location that normal checksum fields. Therefore,
we should before decryption check this checksum to avoid
unencrypting corrupted pages. After decryption we can use
traditional checksum check to detect if page is corrupted
or unencryption was done using incorrect key.
Pages that are page compressed do not contain any checksum,
here we need to fist unencrypt, decompress and finally
use tradional checksum check to detect page corruption
or that we used incorrect key in unencryption.
buf0buf.cc: buf_page_is_corrupted() mofified so that
compressed pages are skipped.
buf0buf.h, buf_block_init(), buf_page_init_low():
removed unnecessary page_encrypted, page_compressed,
stored_checksum, valculated_checksum fields from
buf_page_t
buf_page_get_gen(): use new buf_page_check_corrupt() function
to detect corrupted pages.
buf_page_check_corrupt(): If page was not yet decrypted
check if post encryption checksum still matches.
If page is not anymore encrypted, use buf_page_is_corrupted()
traditional checksum method.
If page is detected as corrupted and it is not encrypted
we print corruption message to error log.
If page is still encrypted or it was encrypted and now
corrupted, we will print message that page is
encrypted to error log.
buf_page_io_complete(): use new buf_page_check_corrupt()
function to detect corrupted pages.
buf_page_decrypt_after_read(): Verify post encryption
checksum before tring to decrypt.
fil0crypt.cc: fil_encrypt_buf() verify post encryption
checksum and ind fil_space_decrypt() return true
if we really decrypted the page.
fil_space_verify_crypt_checksum(): rewrite to use
the method used when calculating post encryption
checksum. We also check if post encryption checksum
matches that traditional checksum check does not
match.
fil0fil.ic: Add missed page type encrypted and page
compressed to fil_get_page_type_name()
Note that this change does not yet fix innochecksum tool,
that will be done in separate MDEV.
Fix test failures caused by buf page corruption injection.
2017-02-06 10:47:55 +02:00
|
|
|
|
|
|
|
/** Checks if the page is in innodb checksum format.
|
|
|
|
@param[in] read_buf database page
|
|
|
|
@param[in] checksum_field1 new checksum field
|
|
|
|
@param[in] checksum_field2 old checksum field
|
2017-03-30 12:48:42 +02:00
|
|
|
@return true if the page is in innodb checksum format. */
|
MDEV-11759: Encryption code in MariaDB 10.1/10.2 causes
compatibility problems
Pages that are encrypted contain post encryption checksum on
different location that normal checksum fields. Therefore,
we should before decryption check this checksum to avoid
unencrypting corrupted pages. After decryption we can use
traditional checksum check to detect if page is corrupted
or unencryption was done using incorrect key.
Pages that are page compressed do not contain any checksum,
here we need to fist unencrypt, decompress and finally
use tradional checksum check to detect page corruption
or that we used incorrect key in unencryption.
buf0buf.cc: buf_page_is_corrupted() mofified so that
compressed pages are skipped.
buf0buf.h, buf_block_init(), buf_page_init_low():
removed unnecessary page_encrypted, page_compressed,
stored_checksum, valculated_checksum fields from
buf_page_t
buf_page_get_gen(): use new buf_page_check_corrupt() function
to detect corrupted pages.
buf_page_check_corrupt(): If page was not yet decrypted
check if post encryption checksum still matches.
If page is not anymore encrypted, use buf_page_is_corrupted()
traditional checksum method.
If page is detected as corrupted and it is not encrypted
we print corruption message to error log.
If page is still encrypted or it was encrypted and now
corrupted, we will print message that page is
encrypted to error log.
buf_page_io_complete(): use new buf_page_check_corrupt()
function to detect corrupted pages.
buf_page_decrypt_after_read(): Verify post encryption
checksum before tring to decrypt.
fil0crypt.cc: fil_encrypt_buf() verify post encryption
checksum and ind fil_space_decrypt() return true
if we really decrypted the page.
fil_space_verify_crypt_checksum(): rewrite to use
the method used when calculating post encryption
checksum. We also check if post encryption checksum
matches that traditional checksum check does not
match.
fil0fil.ic: Add missed page type encrypted and page
compressed to fil_get_page_type_name()
Note that this change does not yet fix innochecksum tool,
that will be done in separate MDEV.
Fix test failures caused by buf page corruption injection.
2017-02-06 10:47:55 +02:00
|
|
|
bool
|
|
|
|
buf_page_is_checksum_valid_innodb(
|
2017-03-30 12:48:42 +02:00
|
|
|
const byte* read_buf,
|
|
|
|
ulint checksum_field1,
|
2017-04-07 15:01:27 +02:00
|
|
|
ulint checksum_field2)
|
2017-03-30 12:48:42 +02:00
|
|
|
MY_ATTRIBUTE((nonnull(1), warn_unused_result));
|
MDEV-11759: Encryption code in MariaDB 10.1/10.2 causes
compatibility problems
Pages that are encrypted contain post encryption checksum on
different location that normal checksum fields. Therefore,
we should before decryption check this checksum to avoid
unencrypting corrupted pages. After decryption we can use
traditional checksum check to detect if page is corrupted
or unencryption was done using incorrect key.
Pages that are page compressed do not contain any checksum,
here we need to fist unencrypt, decompress and finally
use tradional checksum check to detect page corruption
or that we used incorrect key in unencryption.
buf0buf.cc: buf_page_is_corrupted() mofified so that
compressed pages are skipped.
buf0buf.h, buf_block_init(), buf_page_init_low():
removed unnecessary page_encrypted, page_compressed,
stored_checksum, valculated_checksum fields from
buf_page_t
buf_page_get_gen(): use new buf_page_check_corrupt() function
to detect corrupted pages.
buf_page_check_corrupt(): If page was not yet decrypted
check if post encryption checksum still matches.
If page is not anymore encrypted, use buf_page_is_corrupted()
traditional checksum method.
If page is detected as corrupted and it is not encrypted
we print corruption message to error log.
If page is still encrypted or it was encrypted and now
corrupted, we will print message that page is
encrypted to error log.
buf_page_io_complete(): use new buf_page_check_corrupt()
function to detect corrupted pages.
buf_page_decrypt_after_read(): Verify post encryption
checksum before tring to decrypt.
fil0crypt.cc: fil_encrypt_buf() verify post encryption
checksum and ind fil_space_decrypt() return true
if we really decrypted the page.
fil_space_verify_crypt_checksum(): rewrite to use
the method used when calculating post encryption
checksum. We also check if post encryption checksum
matches that traditional checksum check does not
match.
fil0fil.ic: Add missed page type encrypted and page
compressed to fil_get_page_type_name()
Note that this change does not yet fix innochecksum tool,
that will be done in separate MDEV.
Fix test failures caused by buf page corruption injection.
2017-02-06 10:47:55 +02:00
|
|
|
|
|
|
|
/** Checks if the page is in none checksum format.
|
|
|
|
@param[in] read_buf database page
|
|
|
|
@param[in] checksum_field1 new checksum field
|
|
|
|
@param[in] checksum_field2 old checksum field
|
2017-03-30 12:48:42 +02:00
|
|
|
@return true if the page is in none checksum format. */
|
MDEV-11759: Encryption code in MariaDB 10.1/10.2 causes
compatibility problems
Pages that are encrypted contain post encryption checksum on
different location that normal checksum fields. Therefore,
we should before decryption check this checksum to avoid
unencrypting corrupted pages. After decryption we can use
traditional checksum check to detect if page is corrupted
or unencryption was done using incorrect key.
Pages that are page compressed do not contain any checksum,
here we need to fist unencrypt, decompress and finally
use tradional checksum check to detect page corruption
or that we used incorrect key in unencryption.
buf0buf.cc: buf_page_is_corrupted() mofified so that
compressed pages are skipped.
buf0buf.h, buf_block_init(), buf_page_init_low():
removed unnecessary page_encrypted, page_compressed,
stored_checksum, valculated_checksum fields from
buf_page_t
buf_page_get_gen(): use new buf_page_check_corrupt() function
to detect corrupted pages.
buf_page_check_corrupt(): If page was not yet decrypted
check if post encryption checksum still matches.
If page is not anymore encrypted, use buf_page_is_corrupted()
traditional checksum method.
If page is detected as corrupted and it is not encrypted
we print corruption message to error log.
If page is still encrypted or it was encrypted and now
corrupted, we will print message that page is
encrypted to error log.
buf_page_io_complete(): use new buf_page_check_corrupt()
function to detect corrupted pages.
buf_page_decrypt_after_read(): Verify post encryption
checksum before tring to decrypt.
fil0crypt.cc: fil_encrypt_buf() verify post encryption
checksum and ind fil_space_decrypt() return true
if we really decrypted the page.
fil_space_verify_crypt_checksum(): rewrite to use
the method used when calculating post encryption
checksum. We also check if post encryption checksum
matches that traditional checksum check does not
match.
fil0fil.ic: Add missed page type encrypted and page
compressed to fil_get_page_type_name()
Note that this change does not yet fix innochecksum tool,
that will be done in separate MDEV.
Fix test failures caused by buf page corruption injection.
2017-02-06 10:47:55 +02:00
|
|
|
bool
|
|
|
|
buf_page_is_checksum_valid_none(
|
2017-03-30 12:48:42 +02:00
|
|
|
const byte* read_buf,
|
|
|
|
ulint checksum_field1,
|
2017-04-07 15:01:27 +02:00
|
|
|
ulint checksum_field2)
|
2017-03-30 12:48:42 +02:00
|
|
|
MY_ATTRIBUTE((nonnull(1), warn_unused_result));
|
MDEV-11759: Encryption code in MariaDB 10.1/10.2 causes
compatibility problems
Pages that are encrypted contain post encryption checksum on
different location that normal checksum fields. Therefore,
we should before decryption check this checksum to avoid
unencrypting corrupted pages. After decryption we can use
traditional checksum check to detect if page is corrupted
or unencryption was done using incorrect key.
Pages that are page compressed do not contain any checksum,
here we need to fist unencrypt, decompress and finally
use tradional checksum check to detect page corruption
or that we used incorrect key in unencryption.
buf0buf.cc: buf_page_is_corrupted() mofified so that
compressed pages are skipped.
buf0buf.h, buf_block_init(), buf_page_init_low():
removed unnecessary page_encrypted, page_compressed,
stored_checksum, valculated_checksum fields from
buf_page_t
buf_page_get_gen(): use new buf_page_check_corrupt() function
to detect corrupted pages.
buf_page_check_corrupt(): If page was not yet decrypted
check if post encryption checksum still matches.
If page is not anymore encrypted, use buf_page_is_corrupted()
traditional checksum method.
If page is detected as corrupted and it is not encrypted
we print corruption message to error log.
If page is still encrypted or it was encrypted and now
corrupted, we will print message that page is
encrypted to error log.
buf_page_io_complete(): use new buf_page_check_corrupt()
function to detect corrupted pages.
buf_page_decrypt_after_read(): Verify post encryption
checksum before tring to decrypt.
fil0crypt.cc: fil_encrypt_buf() verify post encryption
checksum and ind fil_space_decrypt() return true
if we really decrypted the page.
fil_space_verify_crypt_checksum(): rewrite to use
the method used when calculating post encryption
checksum. We also check if post encryption checksum
matches that traditional checksum check does not
match.
fil0fil.ic: Add missed page type encrypted and page
compressed to fil_get_page_type_name()
Note that this change does not yet fix innochecksum tool,
that will be done in separate MDEV.
Fix test failures caused by buf page corruption injection.
2017-02-06 10:47:55 +02:00
|
|
|
|
MDEV-12602 InnoDB: Failing assertion: space->n_pending_ops == 0
This fixes a regression caused by MDEV-12428.
When we introduced a variant of fil_space_acquire() that could
increment space->n_pending_ops after space->stop_new_ops was set,
the logic of fil_check_pending_operations() was broken.
fil_space_t::n_pending_ios: A new field to track read or write
access from the buffer pool routines immediately before a block
write or after a block read in the file system.
fil_space_acquire_for_io(), fil_space_release_for_io(): Similar
to fil_space_acquire_silent() and fil_space_release(), but
modify fil_space_t::n_pending_ios instead of fil_space_t::n_pending_ops.
Adjust a number of places accordingly, and remove some redundant
tablespace lookups.
The following parts of this fix differ from the 10.2 version of this fix:
buf_page_get_corrupt(): Add a tablespace parameter.
In 10.2, we already had a two-phase process of freeing fil_space objects
(first, fil_space_detach(), then release fil_system->mutex, and finally
free the fil_space and fil_node objects).
fil_space_free_and_mutex_exit(): Renamed from fil_space_free().
Detach the tablespace from the fil_system cache, release the
fil_system->mutex, and then wait for space->n_pending_ios to reach 0,
to avoid accessing freed data in a concurrent thread.
During the wait, future calls to fil_space_acquire_for_io() will
not find this tablespace, and the count can only be decremented to 0,
at which point it is safe to free the objects.
fil_node_free_part1(), fil_node_free_part2(): Refactored from
fil_node_free().
2017-04-28 03:20:49 +03:00
|
|
|
/** Check if a page is corrupt.
|
2017-05-06 14:36:46 +03:00
|
|
|
@param[in] check_lsn whether the LSN should be checked
|
2016-08-12 11:17:45 +03:00
|
|
|
@param[in] read_buf database page
|
MDEV-12026: Implement innodb_checksum_algorithm=full_crc32
MariaDB data-at-rest encryption (innodb_encrypt_tables)
had repurposed the same unused data field that was repurposed
in MySQL 5.7 (and MariaDB 10.2) for the Split Sequence Number (SSN)
field of SPATIAL INDEX. Because of this, MariaDB was unable to
support encryption on SPATIAL INDEX pages.
Furthermore, InnoDB page checksums skipped some bytes, and there
are multiple variations and checksum algorithms. By default,
InnoDB accepts all variations of all algorithms that ever existed.
This unnecessarily weakens the page checksums.
We hereby introduce two more innodb_checksum_algorithm variants
(full_crc32, strict_full_crc32) that are special in a way:
When either setting is active, newly created data files will
carry a flag (fil_space_t::full_crc32()) that indicates that
all pages of the file will use a full CRC-32C checksum over the
entire page contents (excluding the bytes where the checksum
is stored, at the very end of the page). Such files will always
use that checksum, no matter what the parameter
innodb_checksum_algorithm is assigned to.
For old files, the old checksum algorithms will continue to be
used. The value strict_full_crc32 will be equivalent to strict_crc32
and the value full_crc32 will be equivalent to crc32.
ROW_FORMAT=COMPRESSED tables will only use the old format.
These tables do not support new features, such as larger
innodb_page_size or instant ADD/DROP COLUMN. They may be
deprecated in the future. We do not want an unnecessary
file format change for them.
The new full_crc32() format also cleans up the MariaDB tablespace
flags. We will reserve flags to store the page_compressed
compression algorithm, and to store the compressed payload length,
so that checksum can be computed over the compressed (and
possibly encrypted) stream and can be validated without
decrypting or decompressing the page.
In the full_crc32 format, there no longer are separate before-encryption
and after-encryption checksums for pages. The single checksum is
computed on the page contents that is written to the file.
We do not make the new algorithm the default for two reasons.
First, MariaDB 10.4.2 was a beta release, and the default values
of parameters should not change after beta. Second, we did not
yet implement the full_crc32 format for page_compressed pages.
This will be fixed in MDEV-18644.
This is joint work with Marko Mäkelä.
2019-02-19 21:00:00 +02:00
|
|
|
@param[in] fsp_flags tablespace flags
|
2017-03-30 12:48:42 +02:00
|
|
|
@return whether the page is corrupted */
|
|
|
|
bool
|
2016-08-12 11:17:45 +03:00
|
|
|
buf_page_is_corrupted(
|
|
|
|
bool check_lsn,
|
|
|
|
const byte* read_buf,
|
MDEV-12026: Implement innodb_checksum_algorithm=full_crc32
MariaDB data-at-rest encryption (innodb_encrypt_tables)
had repurposed the same unused data field that was repurposed
in MySQL 5.7 (and MariaDB 10.2) for the Split Sequence Number (SSN)
field of SPATIAL INDEX. Because of this, MariaDB was unable to
support encryption on SPATIAL INDEX pages.
Furthermore, InnoDB page checksums skipped some bytes, and there
are multiple variations and checksum algorithms. By default,
InnoDB accepts all variations of all algorithms that ever existed.
This unnecessarily weakens the page checksums.
We hereby introduce two more innodb_checksum_algorithm variants
(full_crc32, strict_full_crc32) that are special in a way:
When either setting is active, newly created data files will
carry a flag (fil_space_t::full_crc32()) that indicates that
all pages of the file will use a full CRC-32C checksum over the
entire page contents (excluding the bytes where the checksum
is stored, at the very end of the page). Such files will always
use that checksum, no matter what the parameter
innodb_checksum_algorithm is assigned to.
For old files, the old checksum algorithms will continue to be
used. The value strict_full_crc32 will be equivalent to strict_crc32
and the value full_crc32 will be equivalent to crc32.
ROW_FORMAT=COMPRESSED tables will only use the old format.
These tables do not support new features, such as larger
innodb_page_size or instant ADD/DROP COLUMN. They may be
deprecated in the future. We do not want an unnecessary
file format change for them.
The new full_crc32() format also cleans up the MariaDB tablespace
flags. We will reserve flags to store the page_compressed
compression algorithm, and to store the compressed payload length,
so that checksum can be computed over the compressed (and
possibly encrypted) stream and can be validated without
decrypting or decompressing the page.
In the full_crc32 format, there no longer are separate before-encryption
and after-encryption checksums for pages. The single checksum is
computed on the page contents that is written to the file.
We do not make the new algorithm the default for two reasons.
First, MariaDB 10.4.2 was a beta release, and the default values
of parameters should not change after beta. Second, we did not
yet implement the full_crc32 format for page_compressed pages.
This will be fixed in MDEV-18644.
This is joint work with Marko Mäkelä.
2019-02-19 21:00:00 +02:00
|
|
|
ulint fsp_flags)
|
MDEV-11759: Encryption code in MariaDB 10.1/10.2 causes
compatibility problems
Pages that are encrypted contain post encryption checksum on
different location that normal checksum fields. Therefore,
we should before decryption check this checksum to avoid
unencrypting corrupted pages. After decryption we can use
traditional checksum check to detect if page is corrupted
or unencryption was done using incorrect key.
Pages that are page compressed do not contain any checksum,
here we need to fist unencrypt, decompress and finally
use tradional checksum check to detect page corruption
or that we used incorrect key in unencryption.
buf0buf.cc: buf_page_is_corrupted() mofified so that
compressed pages are skipped.
buf0buf.h, buf_block_init(), buf_page_init_low():
removed unnecessary page_encrypted, page_compressed,
stored_checksum, valculated_checksum fields from
buf_page_t
buf_page_get_gen(): use new buf_page_check_corrupt() function
to detect corrupted pages.
buf_page_check_corrupt(): If page was not yet decrypted
check if post encryption checksum still matches.
If page is not anymore encrypted, use buf_page_is_corrupted()
traditional checksum method.
If page is detected as corrupted and it is not encrypted
we print corruption message to error log.
If page is still encrypted or it was encrypted and now
corrupted, we will print message that page is
encrypted to error log.
buf_page_io_complete(): use new buf_page_check_corrupt()
function to detect corrupted pages.
buf_page_decrypt_after_read(): Verify post encryption
checksum before tring to decrypt.
fil0crypt.cc: fil_encrypt_buf() verify post encryption
checksum and ind fil_space_decrypt() return true
if we really decrypted the page.
fil_space_verify_crypt_checksum(): rewrite to use
the method used when calculating post encryption
checksum. We also check if post encryption checksum
matches that traditional checksum check does not
match.
fil0fil.ic: Add missed page type encrypted and page
compressed to fil_get_page_type_name()
Note that this change does not yet fix innochecksum tool,
that will be done in separate MDEV.
Fix test failures caused by buf page corruption injection.
2017-02-06 10:47:55 +02:00
|
|
|
MY_ATTRIBUTE((warn_unused_result));
|
2017-08-04 13:57:26 +03:00
|
|
|
|
2019-12-23 07:14:51 +02:00
|
|
|
inline void *aligned_malloc(size_t size, size_t align)
|
|
|
|
{
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
return _aligned_malloc(size, align);
|
|
|
|
#else
|
|
|
|
void *result;
|
|
|
|
if (posix_memalign(&result, align, size))
|
|
|
|
result= NULL;
|
|
|
|
return result;
|
|
|
|
#endif
|
|
|
|
}
|
2017-08-03 08:29:36 +03:00
|
|
|
|
2019-12-23 07:14:51 +02:00
|
|
|
inline void aligned_free(void *ptr)
|
|
|
|
{
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
_aligned_free(ptr);
|
|
|
|
#else
|
|
|
|
free(ptr);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
MDEV-12026: Implement innodb_checksum_algorithm=full_crc32
MariaDB data-at-rest encryption (innodb_encrypt_tables)
had repurposed the same unused data field that was repurposed
in MySQL 5.7 (and MariaDB 10.2) for the Split Sequence Number (SSN)
field of SPATIAL INDEX. Because of this, MariaDB was unable to
support encryption on SPATIAL INDEX pages.
Furthermore, InnoDB page checksums skipped some bytes, and there
are multiple variations and checksum algorithms. By default,
InnoDB accepts all variations of all algorithms that ever existed.
This unnecessarily weakens the page checksums.
We hereby introduce two more innodb_checksum_algorithm variants
(full_crc32, strict_full_crc32) that are special in a way:
When either setting is active, newly created data files will
carry a flag (fil_space_t::full_crc32()) that indicates that
all pages of the file will use a full CRC-32C checksum over the
entire page contents (excluding the bytes where the checksum
is stored, at the very end of the page). Such files will always
use that checksum, no matter what the parameter
innodb_checksum_algorithm is assigned to.
For old files, the old checksum algorithms will continue to be
used. The value strict_full_crc32 will be equivalent to strict_crc32
and the value full_crc32 will be equivalent to crc32.
ROW_FORMAT=COMPRESSED tables will only use the old format.
These tables do not support new features, such as larger
innodb_page_size or instant ADD/DROP COLUMN. They may be
deprecated in the future. We do not want an unnecessary
file format change for them.
The new full_crc32() format also cleans up the MariaDB tablespace
flags. We will reserve flags to store the page_compressed
compression algorithm, and to store the compressed payload length,
so that checksum can be computed over the compressed (and
possibly encrypted) stream and can be validated without
decrypting or decompressing the page.
In the full_crc32 format, there no longer are separate before-encryption
and after-encryption checksums for pages. The single checksum is
computed on the page contents that is written to the file.
We do not make the new algorithm the default for two reasons.
First, MariaDB 10.4.2 was a beta release, and the default values
of parameters should not change after beta. Second, we did not
yet implement the full_crc32 format for page_compressed pages.
This will be fixed in MDEV-18644.
This is joint work with Marko Mäkelä.
2019-02-19 21:00:00 +02:00
|
|
|
/** Read the key version from the page. In full crc32 format,
|
|
|
|
key version is stored at {0-3th} bytes. In other format, it is
|
|
|
|
stored in 26th position.
|
|
|
|
@param[in] read_buf database page
|
|
|
|
@param[in] fsp_flags tablespace flags
|
|
|
|
@return key version of the page. */
|
|
|
|
inline uint32_t buf_page_get_key_version(const byte* read_buf, ulint fsp_flags)
|
|
|
|
{
|
MDEV-18644: Support full_crc32 for page_compressed
This is a follow-up task to MDEV-12026, which introduced
innodb_checksum_algorithm=full_crc32 and a simpler page format.
MDEV-12026 did not enable full_crc32 for page_compressed tables,
which we will be doing now.
This is joint work with Thirunarayanan Balathandayuthapani.
For innodb_checksum_algorithm=full_crc32 we change the
page_compressed format as follows:
FIL_PAGE_TYPE: The most significant bit will be set to indicate
page_compressed format. The least significant bits will contain
the compressed page size, rounded up to a multiple of 256 bytes.
The checksum will be stored in the last 4 bytes of the page
(whether it is the full page or a page_compressed page whose
size is determined by FIL_PAGE_TYPE), covering all preceding
bytes of the page. If encryption is used, then the page will
be encrypted between compression and computing the checksum.
For page_compressed, FIL_PAGE_LSN will not be repeated at
the end of the page.
FSP_SPACE_FLAGS (already implemented as part of MDEV-12026):
We will store the innodb_compression_algorithm that may be used
to compress pages. Previously, the choice of algorithm was written
to each compressed data page separately, and one would be unable
to know in advance which compression algorithm(s) are used.
fil_space_t::full_crc32_page_compressed_len(): Determine if the
page_compressed algorithm of the tablespace needs to know the
exact length of the compressed data. If yes, we will reserve and
write an extra byte for this right before the checksum.
buf_page_is_compressed(): Determine if a page uses page_compressed
(in any innodb_checksum_algorithm).
fil_page_decompress(): Pass also fil_space_t::flags so that the
format can be determined.
buf_page_is_zeroes(): Check if a page is full of zero bytes.
buf_page_full_crc32_is_corrupted(): Renamed from
buf_encrypted_full_crc32_page_is_corrupted(). For full_crc32,
we always simply validate the checksum to the page contents,
while the physical page size is explicitly specified by an
unencrypted part of the page header.
buf_page_full_crc32_size(): Determine the size of a full_crc32 page.
buf_dblwr_check_page_lsn(): Make this a debug-only function, because
it involves potentially costly lookups of fil_space_t.
create_table_info_t::check_table_options(),
ha_innobase::check_if_supported_inplace_alter(): Do allow the creation
of SPATIAL INDEX with full_crc32 also when page_compressed is used.
commit_cache_norebuild(): Preserve the compression algorithm when
updating the page_compression_level.
dict_tf_to_fsp_flags(): Set the flags for page compression algorithm.
FIXME: Maybe there should be a table option page_compression_algorithm
and a session variable to back it?
2019-03-18 14:08:43 +02:00
|
|
|
return fil_space_t::full_crc32(fsp_flags)
|
MDEV-12026: Implement innodb_checksum_algorithm=full_crc32
MariaDB data-at-rest encryption (innodb_encrypt_tables)
had repurposed the same unused data field that was repurposed
in MySQL 5.7 (and MariaDB 10.2) for the Split Sequence Number (SSN)
field of SPATIAL INDEX. Because of this, MariaDB was unable to
support encryption on SPATIAL INDEX pages.
Furthermore, InnoDB page checksums skipped some bytes, and there
are multiple variations and checksum algorithms. By default,
InnoDB accepts all variations of all algorithms that ever existed.
This unnecessarily weakens the page checksums.
We hereby introduce two more innodb_checksum_algorithm variants
(full_crc32, strict_full_crc32) that are special in a way:
When either setting is active, newly created data files will
carry a flag (fil_space_t::full_crc32()) that indicates that
all pages of the file will use a full CRC-32C checksum over the
entire page contents (excluding the bytes where the checksum
is stored, at the very end of the page). Such files will always
use that checksum, no matter what the parameter
innodb_checksum_algorithm is assigned to.
For old files, the old checksum algorithms will continue to be
used. The value strict_full_crc32 will be equivalent to strict_crc32
and the value full_crc32 will be equivalent to crc32.
ROW_FORMAT=COMPRESSED tables will only use the old format.
These tables do not support new features, such as larger
innodb_page_size or instant ADD/DROP COLUMN. They may be
deprecated in the future. We do not want an unnecessary
file format change for them.
The new full_crc32() format also cleans up the MariaDB tablespace
flags. We will reserve flags to store the page_compressed
compression algorithm, and to store the compressed payload length,
so that checksum can be computed over the compressed (and
possibly encrypted) stream and can be validated without
decrypting or decompressing the page.
In the full_crc32 format, there no longer are separate before-encryption
and after-encryption checksums for pages. The single checksum is
computed on the page contents that is written to the file.
We do not make the new algorithm the default for two reasons.
First, MariaDB 10.4.2 was a beta release, and the default values
of parameters should not change after beta. Second, we did not
yet implement the full_crc32 format for page_compressed pages.
This will be fixed in MDEV-18644.
This is joint work with Marko Mäkelä.
2019-02-19 21:00:00 +02:00
|
|
|
? 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);
|
|
|
|
}
|
|
|
|
|
MDEV-18644: Support full_crc32 for page_compressed
This is a follow-up task to MDEV-12026, which introduced
innodb_checksum_algorithm=full_crc32 and a simpler page format.
MDEV-12026 did not enable full_crc32 for page_compressed tables,
which we will be doing now.
This is joint work with Thirunarayanan Balathandayuthapani.
For innodb_checksum_algorithm=full_crc32 we change the
page_compressed format as follows:
FIL_PAGE_TYPE: The most significant bit will be set to indicate
page_compressed format. The least significant bits will contain
the compressed page size, rounded up to a multiple of 256 bytes.
The checksum will be stored in the last 4 bytes of the page
(whether it is the full page or a page_compressed page whose
size is determined by FIL_PAGE_TYPE), covering all preceding
bytes of the page. If encryption is used, then the page will
be encrypted between compression and computing the checksum.
For page_compressed, FIL_PAGE_LSN will not be repeated at
the end of the page.
FSP_SPACE_FLAGS (already implemented as part of MDEV-12026):
We will store the innodb_compression_algorithm that may be used
to compress pages. Previously, the choice of algorithm was written
to each compressed data page separately, and one would be unable
to know in advance which compression algorithm(s) are used.
fil_space_t::full_crc32_page_compressed_len(): Determine if the
page_compressed algorithm of the tablespace needs to know the
exact length of the compressed data. If yes, we will reserve and
write an extra byte for this right before the checksum.
buf_page_is_compressed(): Determine if a page uses page_compressed
(in any innodb_checksum_algorithm).
fil_page_decompress(): Pass also fil_space_t::flags so that the
format can be determined.
buf_page_is_zeroes(): Check if a page is full of zero bytes.
buf_page_full_crc32_is_corrupted(): Renamed from
buf_encrypted_full_crc32_page_is_corrupted(). For full_crc32,
we always simply validate the checksum to the page contents,
while the physical page size is explicitly specified by an
unencrypted part of the page header.
buf_page_full_crc32_size(): Determine the size of a full_crc32 page.
buf_dblwr_check_page_lsn(): Make this a debug-only function, because
it involves potentially costly lookups of fil_space_t.
create_table_info_t::check_table_options(),
ha_innobase::check_if_supported_inplace_alter(): Do allow the creation
of SPATIAL INDEX with full_crc32 also when page_compressed is used.
commit_cache_norebuild(): Preserve the compression algorithm when
updating the page_compression_level.
dict_tf_to_fsp_flags(): Set the flags for page compression algorithm.
FIXME: Maybe there should be a table option page_compression_algorithm
and a session variable to back it?
2019-03-18 14:08:43 +02:00
|
|
|
/** Read the compression info from the page. In full crc32 format,
|
|
|
|
compression info is at MSB of page type. In other format, it is
|
|
|
|
stored in page type.
|
|
|
|
@param[in] read_buf database page
|
|
|
|
@param[in] fsp_flags tablespace flags
|
|
|
|
@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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Get the compressed or uncompressed size of a full_crc32 page.
|
|
|
|
@param[in] buf page_compressed or uncompressed page
|
|
|
|
@param[out] comp whether the page could be compressed
|
|
|
|
@param[out] cr whether the page could be corrupted
|
|
|
|
@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 page_size = uint(srv_page_size);
|
|
|
|
|
|
|
|
if (!(t & 1U << FIL_PAGE_COMPRESS_FCRC32_MARKER)) {
|
|
|
|
return page_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
t &= ~(1U << FIL_PAGE_COMPRESS_FCRC32_MARKER);
|
|
|
|
t <<= 8;
|
|
|
|
|
|
|
|
if (t < page_size) {
|
|
|
|
page_size = t;
|
|
|
|
if (comp) {
|
|
|
|
*comp = true;
|
|
|
|
}
|
|
|
|
} else if (cr) {
|
|
|
|
*cr = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return page_size;
|
|
|
|
}
|
|
|
|
|
2019-12-05 06:42:31 +02:00
|
|
|
#ifndef UNIV_INNOCHECKSUM
|
2014-02-26 19:11:54 +01:00
|
|
|
/**********************************************************************//**
|
|
|
|
Gets the hash value of a block. This can be used in searches in the
|
|
|
|
lock hash table.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return lock hash value */
|
2014-02-26 19:11:54 +01:00
|
|
|
UNIV_INLINE
|
2017-03-01 08:27:39 +02:00
|
|
|
unsigned
|
2014-02-26 19:11:54 +01:00
|
|
|
buf_block_get_lock_hash_val(
|
|
|
|
/*========================*/
|
|
|
|
const buf_block_t* block) /*!< in: block */
|
2016-09-06 09:43:16 +03:00
|
|
|
MY_ATTRIBUTE((warn_unused_result));
|
2014-02-26 19:11:54 +01:00
|
|
|
#ifdef UNIV_DEBUG
|
2020-02-12 14:45:21 +02:00
|
|
|
/** Find a block in the buffer pool that points to a given compressed page.
|
|
|
|
@param[in] data pointer to compressed page
|
|
|
|
@return buffer block pointing to the compressed page
|
|
|
|
@retval NULL if not found */
|
|
|
|
buf_block_t* buf_pool_contains_zip(const void* data);
|
2014-02-26 19:11:54 +01:00
|
|
|
#endif /* UNIV_DEBUG */
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
FIXME_FTS: Gets the frame the pointer is pointing to. */
|
|
|
|
UNIV_INLINE
|
|
|
|
buf_frame_t*
|
|
|
|
buf_frame_align(
|
|
|
|
/*============*/
|
|
|
|
/* out: pointer to frame */
|
|
|
|
byte* ptr); /* in: pointer to a frame */
|
|
|
|
|
|
|
|
|
|
|
|
#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
|
2020-02-12 14:45:21 +02:00
|
|
|
/** Validate the buffer pool. */
|
|
|
|
void buf_validate();
|
2014-02-26 19:11:54 +01:00
|
|
|
#endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */
|
|
|
|
#if defined UNIV_DEBUG_PRINT || defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
|
2020-02-12 14:45:21 +02:00
|
|
|
/** Write information of the buf_pool to the error log. */
|
|
|
|
void buf_print();
|
2014-02-26 19:11:54 +01:00
|
|
|
#endif /* UNIV_DEBUG_PRINT || UNIV_DEBUG || UNIV_BUF_DEBUG */
|
2016-12-30 15:04:10 +02:00
|
|
|
|
2017-09-06 14:01:15 +03:00
|
|
|
/** Dump a page to stderr.
|
|
|
|
@param[in] read_buf database page
|
2019-02-06 19:50:11 +02:00
|
|
|
@param[in] zip_size compressed page size, or 0 */
|
|
|
|
void buf_page_print(const byte* read_buf, ulint zip_size = 0)
|
2017-09-06 19:28:51 +03:00
|
|
|
ATTRIBUTE_COLD __attribute__((nonnull));
|
2014-02-26 19:11:54 +01:00
|
|
|
/********************************************************************//**
|
|
|
|
Decompress a block.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return TRUE if successful */
|
2014-02-26 19:11:54 +01:00
|
|
|
ibool
|
|
|
|
buf_zip_decompress(
|
|
|
|
/*===============*/
|
|
|
|
buf_block_t* block, /*!< in/out: block */
|
|
|
|
ibool check); /*!< in: TRUE=verify the page checksum */
|
2016-12-30 15:04:10 +02:00
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
#ifdef UNIV_DEBUG
|
2020-02-12 14:45:21 +02:00
|
|
|
/** @return the number of latched pages in the buffer pool */
|
|
|
|
ulint buf_get_latched_pages_number();
|
2014-02-26 19:11:54 +01:00
|
|
|
#endif /* UNIV_DEBUG */
|
|
|
|
/*********************************************************************//**
|
|
|
|
Prints info of the buffer i/o. */
|
|
|
|
void
|
|
|
|
buf_print_io(
|
|
|
|
/*=========*/
|
|
|
|
FILE* file); /*!< in: file where to print */
|
2020-02-12 14:45:21 +02:00
|
|
|
/** Collect buffer pool metadata.
|
|
|
|
@param[out] pool_info buffer pool metadata */
|
|
|
|
void buf_stats_get_pool_info(buf_pool_info_t *pool_info);
|
|
|
|
|
2015-05-26 10:01:12 +03:00
|
|
|
/** Refresh the statistics used to print per-second averages. */
|
2020-02-12 14:45:21 +02:00
|
|
|
void buf_refresh_io_stats();
|
|
|
|
|
|
|
|
/** Assert that all buffer pool pages are in a replaceable state */
|
|
|
|
void buf_assert_all_freed();
|
|
|
|
|
|
|
|
/** Check that there currently are no I/O operations pending.
|
|
|
|
@return number of pending i/o */
|
|
|
|
ulint buf_pool_check_no_pending_io();
|
|
|
|
|
|
|
|
/** Invalidate all pages in the buffer pool.
|
|
|
|
All pages must be in a replaceable state (not modified or latched). */
|
|
|
|
void buf_pool_invalidate();
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
/*========================================================================
|
|
|
|
--------------------------- LOWER LEVEL ROUTINES -------------------------
|
|
|
|
=========================================================================*/
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
#ifdef UNIV_DEBUG
|
2014-02-26 19:11:54 +01:00
|
|
|
/*********************************************************************//**
|
|
|
|
Adds latch level info for the rw-lock protecting the buffer frame. This
|
|
|
|
should be called in the debug version after a successful latching of a
|
|
|
|
page if we know the latching order level of the acquired latch. */
|
|
|
|
UNIV_INLINE
|
|
|
|
void
|
|
|
|
buf_block_dbg_add_level(
|
|
|
|
/*====================*/
|
|
|
|
buf_block_t* block, /*!< in: buffer page
|
|
|
|
where we have acquired latch */
|
2016-08-12 11:17:45 +03:00
|
|
|
latch_level_t level); /*!< in: latching order level */
|
|
|
|
#else /* UNIV_DEBUG */
|
2014-02-26 19:11:54 +01:00
|
|
|
# define buf_block_dbg_add_level(block, level) /* nothing */
|
2016-08-12 11:17:45 +03:00
|
|
|
#endif /* UNIV_DEBUG */
|
2014-02-26 19:11:54 +01:00
|
|
|
/*********************************************************************//**
|
|
|
|
Gets the state of a block.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return state */
|
2014-02-26 19:11:54 +01:00
|
|
|
UNIV_INLINE
|
|
|
|
enum buf_page_state
|
|
|
|
buf_page_get_state(
|
|
|
|
/*===============*/
|
2015-12-17 19:45:42 +02:00
|
|
|
const buf_page_t* bpage); /*!< in: pointer to the control
|
|
|
|
block */
|
|
|
|
/*********************************************************************//**
|
2014-02-26 19:11:54 +01:00
|
|
|
Gets the state of a block.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return state */
|
2014-02-26 19:11:54 +01:00
|
|
|
UNIV_INLINE
|
|
|
|
enum buf_page_state
|
|
|
|
buf_block_get_state(
|
|
|
|
/*================*/
|
|
|
|
const buf_block_t* block) /*!< in: pointer to the control block */
|
2016-09-06 09:43:16 +03:00
|
|
|
MY_ATTRIBUTE((warn_unused_result));
|
2014-02-26 19:11:54 +01:00
|
|
|
/*********************************************************************//**
|
|
|
|
Sets the state of a block. */
|
|
|
|
UNIV_INLINE
|
|
|
|
void
|
|
|
|
buf_page_set_state(
|
|
|
|
/*===============*/
|
|
|
|
buf_page_t* bpage, /*!< in/out: pointer to control block */
|
|
|
|
enum buf_page_state state); /*!< in: state */
|
|
|
|
/*********************************************************************//**
|
|
|
|
Sets the state of a block. */
|
|
|
|
UNIV_INLINE
|
|
|
|
void
|
|
|
|
buf_block_set_state(
|
|
|
|
/*================*/
|
|
|
|
buf_block_t* block, /*!< in/out: pointer to control block */
|
|
|
|
enum buf_page_state state); /*!< in: state */
|
|
|
|
/*********************************************************************//**
|
|
|
|
Determines if a block is mapped to a tablespace.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return TRUE if mapped */
|
2014-02-26 19:11:54 +01:00
|
|
|
UNIV_INLINE
|
|
|
|
ibool
|
|
|
|
buf_page_in_file(
|
|
|
|
/*=============*/
|
|
|
|
const buf_page_t* bpage) /*!< in: pointer to control block */
|
2016-09-06 09:43:16 +03:00
|
|
|
MY_ATTRIBUTE((warn_unused_result));
|
2016-12-30 15:04:10 +02:00
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
/*********************************************************************//**
|
|
|
|
Determines if a block should be on unzip_LRU list.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return TRUE if block belongs to unzip_LRU */
|
2014-02-26 19:11:54 +01:00
|
|
|
UNIV_INLINE
|
|
|
|
ibool
|
|
|
|
buf_page_belongs_to_unzip_LRU(
|
|
|
|
/*==========================*/
|
|
|
|
const buf_page_t* bpage) /*!< in: pointer to control block */
|
2016-09-06 09:43:16 +03:00
|
|
|
MY_ATTRIBUTE((warn_unused_result));
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
/*********************************************************************//**
|
|
|
|
Gets the mutex of a block.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return pointer to mutex protecting bpage */
|
2014-02-26 19:11:54 +01:00
|
|
|
UNIV_INLINE
|
2016-08-12 11:17:45 +03:00
|
|
|
BPageMutex*
|
2014-02-26 19:11:54 +01:00
|
|
|
buf_page_get_mutex(
|
|
|
|
/*===============*/
|
|
|
|
const buf_page_t* bpage) /*!< in: pointer to control block */
|
2016-09-06 09:43:16 +03:00
|
|
|
MY_ATTRIBUTE((warn_unused_result));
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
/*********************************************************************//**
|
|
|
|
Get the flush type of a page.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return flush type */
|
2014-02-26 19:11:54 +01:00
|
|
|
UNIV_INLINE
|
|
|
|
buf_flush_t
|
|
|
|
buf_page_get_flush_type(
|
|
|
|
/*====================*/
|
|
|
|
const buf_page_t* bpage) /*!< in: buffer page */
|
2016-09-06 09:43:16 +03:00
|
|
|
MY_ATTRIBUTE((warn_unused_result));
|
2014-02-26 19:11:54 +01:00
|
|
|
/*********************************************************************//**
|
|
|
|
Set the flush type of a page. */
|
|
|
|
UNIV_INLINE
|
|
|
|
void
|
|
|
|
buf_page_set_flush_type(
|
|
|
|
/*====================*/
|
|
|
|
buf_page_t* bpage, /*!< in: buffer page */
|
|
|
|
buf_flush_t flush_type); /*!< in: flush type */
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
/** Map a block to a file page.
|
|
|
|
@param[in,out] block pointer to control block
|
|
|
|
@param[in] page_id page id */
|
2014-02-26 19:11:54 +01:00
|
|
|
UNIV_INLINE
|
|
|
|
void
|
|
|
|
buf_block_set_file_page(
|
2016-08-12 11:17:45 +03:00
|
|
|
buf_block_t* block,
|
2018-10-18 18:23:12 +03:00
|
|
|
const page_id_t page_id);
|
2016-08-12 11:17:45 +03:00
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
/*********************************************************************//**
|
|
|
|
Gets the io_fix state of a block.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return io_fix state */
|
2014-02-26 19:11:54 +01:00
|
|
|
UNIV_INLINE
|
|
|
|
enum buf_io_fix
|
|
|
|
buf_page_get_io_fix(
|
|
|
|
/*================*/
|
|
|
|
const buf_page_t* bpage) /*!< in: pointer to the control block */
|
2016-09-06 09:43:16 +03:00
|
|
|
MY_ATTRIBUTE((warn_unused_result));
|
2014-02-26 19:11:54 +01:00
|
|
|
/*********************************************************************//**
|
|
|
|
Gets the io_fix state of a block.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return io_fix state */
|
2014-02-26 19:11:54 +01:00
|
|
|
UNIV_INLINE
|
|
|
|
enum buf_io_fix
|
|
|
|
buf_block_get_io_fix(
|
|
|
|
/*================*/
|
|
|
|
const buf_block_t* block) /*!< in: pointer to the control block */
|
2016-09-06 09:43:16 +03:00
|
|
|
MY_ATTRIBUTE((warn_unused_result));
|
2014-02-26 19:11:54 +01:00
|
|
|
/*********************************************************************//**
|
|
|
|
Sets the io_fix state of a block. */
|
|
|
|
UNIV_INLINE
|
|
|
|
void
|
|
|
|
buf_page_set_io_fix(
|
|
|
|
/*================*/
|
|
|
|
buf_page_t* bpage, /*!< in/out: control block */
|
|
|
|
enum buf_io_fix io_fix);/*!< in: io_fix state */
|
|
|
|
/*********************************************************************//**
|
|
|
|
Sets the io_fix state of a block. */
|
|
|
|
UNIV_INLINE
|
|
|
|
void
|
|
|
|
buf_block_set_io_fix(
|
|
|
|
/*=================*/
|
|
|
|
buf_block_t* block, /*!< in/out: control block */
|
|
|
|
enum buf_io_fix io_fix);/*!< in: io_fix state */
|
|
|
|
/*********************************************************************//**
|
|
|
|
Makes a block sticky. A sticky block implies that even after we release
|
|
|
|
the buf_pool->mutex and the block->mutex:
|
|
|
|
* it cannot be removed from the flush_list
|
|
|
|
* the block descriptor cannot be relocated
|
|
|
|
* it cannot be removed from the LRU list
|
|
|
|
Note that:
|
|
|
|
* the block can still change its position in the LRU list
|
|
|
|
* the next and previous pointers can change. */
|
|
|
|
UNIV_INLINE
|
|
|
|
void
|
|
|
|
buf_page_set_sticky(
|
|
|
|
/*================*/
|
|
|
|
buf_page_t* bpage); /*!< in/out: control block */
|
|
|
|
/*********************************************************************//**
|
|
|
|
Removes stickiness of a block. */
|
|
|
|
UNIV_INLINE
|
|
|
|
void
|
|
|
|
buf_page_unset_sticky(
|
|
|
|
/*==================*/
|
|
|
|
buf_page_t* bpage); /*!< in/out: control block */
|
|
|
|
/********************************************************************//**
|
|
|
|
Determine if a buffer block can be relocated in memory. The block
|
|
|
|
can be dirty, but it must not be I/O-fixed or bufferfixed. */
|
|
|
|
UNIV_INLINE
|
|
|
|
ibool
|
|
|
|
buf_page_can_relocate(
|
|
|
|
/*==================*/
|
|
|
|
const buf_page_t* bpage) /*!< control block being relocated */
|
2016-09-06 09:43:16 +03:00
|
|
|
MY_ATTRIBUTE((warn_unused_result));
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
/*********************************************************************//**
|
|
|
|
Determine if a block has been flagged old.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return TRUE if old */
|
2014-02-26 19:11:54 +01:00
|
|
|
UNIV_INLINE
|
|
|
|
ibool
|
|
|
|
buf_page_is_old(
|
|
|
|
/*============*/
|
|
|
|
const buf_page_t* bpage) /*!< in: control block */
|
2016-09-06 09:43:16 +03:00
|
|
|
MY_ATTRIBUTE((warn_unused_result));
|
2014-02-26 19:11:54 +01:00
|
|
|
/*********************************************************************//**
|
|
|
|
Flag a block old. */
|
|
|
|
UNIV_INLINE
|
|
|
|
void
|
|
|
|
buf_page_set_old(
|
|
|
|
/*=============*/
|
|
|
|
buf_page_t* bpage, /*!< in/out: control block */
|
2017-03-01 08:27:39 +02:00
|
|
|
bool old); /*!< in: old */
|
2014-02-26 19:11:54 +01:00
|
|
|
/*********************************************************************//**
|
|
|
|
Determine the time of first access of a block in the buffer pool.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return ut_time_ms() at the time of first access, 0 if not accessed */
|
2014-02-26 19:11:54 +01:00
|
|
|
UNIV_INLINE
|
|
|
|
unsigned
|
|
|
|
buf_page_is_accessed(
|
|
|
|
/*=================*/
|
|
|
|
const buf_page_t* bpage) /*!< in: control block */
|
2016-09-06 09:43:16 +03:00
|
|
|
MY_ATTRIBUTE((warn_unused_result));
|
2014-02-26 19:11:54 +01:00
|
|
|
/*********************************************************************//**
|
|
|
|
Flag a block accessed. */
|
|
|
|
UNIV_INLINE
|
|
|
|
void
|
|
|
|
buf_page_set_accessed(
|
|
|
|
/*==================*/
|
|
|
|
buf_page_t* bpage) /*!< in/out: control block */
|
2016-06-21 14:21:03 +02:00
|
|
|
MY_ATTRIBUTE((nonnull));
|
2014-02-26 19:11:54 +01:00
|
|
|
/*********************************************************************//**
|
|
|
|
Gets the buf_block_t handle of a buffered file block if an uncompressed
|
|
|
|
page frame exists, or NULL. Note: even though bpage is not declared a
|
2016-08-12 11:17:45 +03:00
|
|
|
const we don't update its value.
|
|
|
|
@return control block, or NULL */
|
2014-02-26 19:11:54 +01:00
|
|
|
UNIV_INLINE
|
|
|
|
buf_block_t*
|
|
|
|
buf_page_get_block(
|
|
|
|
/*===============*/
|
|
|
|
buf_page_t* bpage) /*!< in: control block, or NULL */
|
2016-09-06 09:43:16 +03:00
|
|
|
MY_ATTRIBUTE((warn_unused_result));
|
2016-12-30 15:04:10 +02:00
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
#ifdef UNIV_DEBUG
|
|
|
|
/*********************************************************************//**
|
|
|
|
Gets a pointer to the memory frame of a block.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return pointer to the frame */
|
2014-02-26 19:11:54 +01:00
|
|
|
UNIV_INLINE
|
|
|
|
buf_frame_t*
|
|
|
|
buf_block_get_frame(
|
|
|
|
/*================*/
|
|
|
|
const buf_block_t* block) /*!< in: pointer to the control block */
|
2016-09-06 09:43:16 +03:00
|
|
|
MY_ATTRIBUTE((warn_unused_result));
|
2014-02-26 19:11:54 +01:00
|
|
|
#else /* UNIV_DEBUG */
|
|
|
|
# define buf_block_get_frame(block) (block)->frame
|
|
|
|
#endif /* UNIV_DEBUG */
|
2016-08-12 11:17:45 +03:00
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
/*********************************************************************//**
|
|
|
|
Gets the compressed page descriptor corresponding to an uncompressed page
|
|
|
|
if applicable. */
|
|
|
|
#define buf_block_get_page_zip(block) \
|
2019-12-03 10:19:45 +02:00
|
|
|
(UNIV_LIKELY_NULL((block)->page.zip.data) ? &(block)->page.zip : NULL)
|
2019-08-08 22:53:33 +03:00
|
|
|
#define is_buf_block_get_page_zip(block) \
|
2019-12-03 10:19:45 +02:00
|
|
|
UNIV_LIKELY_NULL((block)->page.zip.data)
|
2016-09-06 09:43:16 +03:00
|
|
|
|
2017-02-23 23:05:12 +02:00
|
|
|
#ifdef BTR_CUR_HASH_ADAPT
|
2016-09-06 09:43:16 +03:00
|
|
|
/** Get a buffer block from an adaptive hash index pointer.
|
|
|
|
This function does not return if the block is not identified.
|
|
|
|
@param[in] ptr pointer to within a page frame
|
2016-08-12 11:17:45 +03:00
|
|
|
@return pointer to block, never NULL */
|
2014-02-26 19:11:54 +01:00
|
|
|
buf_block_t*
|
2016-09-06 09:43:16 +03:00
|
|
|
buf_block_from_ahi(const byte* ptr);
|
2017-02-23 23:05:12 +02:00
|
|
|
#endif /* BTR_CUR_HASH_ADAPT */
|
2016-09-06 09:43:16 +03:00
|
|
|
|
2020-02-12 14:45:21 +02:00
|
|
|
/** Determine if a pointer belongs to a buf_block_t. It can be a pointer to
|
|
|
|
the buf_block_t itself or a member of it.
|
|
|
|
@param ptr a pointer that will not be dereferenced
|
|
|
|
@return whether the ptr belongs to a buf_block_t struct */
|
|
|
|
bool buf_pointer_is_block_field(const void* ptr);
|
2014-02-26 19:11:54 +01:00
|
|
|
/** Find out if a pointer corresponds to a buf_block_t::mutex.
|
2016-08-12 11:17:45 +03:00
|
|
|
@param m in: mutex candidate
|
|
|
|
@return TRUE if m is a buf_block_t::mutex */
|
2014-02-26 19:11:54 +01:00
|
|
|
#define buf_pool_is_block_mutex(m) \
|
|
|
|
buf_pointer_is_block_field((const void*)(m))
|
|
|
|
/** Find out if a pointer corresponds to a buf_block_t::lock.
|
2016-08-12 11:17:45 +03:00
|
|
|
@param l in: rw-lock candidate
|
|
|
|
@return TRUE if l is a buf_block_t::lock */
|
2014-02-26 19:11:54 +01:00
|
|
|
#define buf_pool_is_block_lock(l) \
|
|
|
|
buf_pointer_is_block_field((const void*)(l))
|
|
|
|
|
2017-05-06 14:36:46 +03:00
|
|
|
/** Initialize a page for read to the buffer buf_pool. If the page is
|
2014-02-26 19:11:54 +01:00
|
|
|
(1) already in buf_pool, or
|
|
|
|
(2) if we specify to read only ibuf pages and the page is not an ibuf page, or
|
|
|
|
(3) if the space is deleted or being deleted,
|
|
|
|
then this function does nothing.
|
|
|
|
Sets the io_fix flag to BUF_IO_READ and sets a non-recursive exclusive lock
|
|
|
|
on the buffer frame. The io-handler must take care that the flag is cleared
|
|
|
|
and the lock released later.
|
2016-08-12 11:17:45 +03:00
|
|
|
@param[out] err DB_SUCCESS or DB_TABLESPACE_DELETED
|
|
|
|
@param[in] mode BUF_READ_IBUF_PAGES_ONLY, ...
|
|
|
|
@param[in] page_id page id
|
2019-02-06 19:50:11 +02:00
|
|
|
@param[in] zip_size ROW_FORMAT=COMPRESSED page size, or 0
|
2017-05-06 14:36:46 +03:00
|
|
|
@param[in] unzip whether the uncompressed page is
|
|
|
|
requested (for ROW_FORMAT=COMPRESSED)
|
|
|
|
@return pointer to the block
|
|
|
|
@retval NULL in case of an error */
|
2014-02-26 19:11:54 +01:00
|
|
|
buf_page_t*
|
|
|
|
buf_page_init_for_read(
|
2016-08-12 11:17:45 +03:00
|
|
|
dberr_t* err,
|
|
|
|
ulint mode,
|
2018-10-18 18:23:12 +03:00
|
|
|
const page_id_t page_id,
|
2019-02-06 19:50:11 +02:00
|
|
|
ulint zip_size,
|
2017-05-06 14:36:46 +03:00
|
|
|
bool unzip);
|
2016-08-12 11:17:45 +03:00
|
|
|
|
2017-05-05 10:25:29 +03:00
|
|
|
/** Complete a read or write request of a file page to or from the buffer pool.
|
2018-03-09 21:25:20 +02:00
|
|
|
@param[in,out] bpage page to complete
|
|
|
|
@param[in] dblwr whether the doublewrite buffer was used (on write)
|
|
|
|
@param[in] evict whether or not to evict the page from LRU list
|
2017-05-05 10:25:29 +03:00
|
|
|
@return whether the operation succeeded
|
|
|
|
@retval DB_SUCCESS always when writing, or if a read page was OK
|
|
|
|
@retval DB_PAGE_CORRUPTED if the checksum fails on a page read
|
|
|
|
@retval DB_DECRYPTION_FAILED if page post encryption checksum matches but
|
|
|
|
after decryption normal page checksum does
|
|
|
|
not match */
|
2014-02-26 19:11:54 +01:00
|
|
|
UNIV_INTERN
|
MDEV-12253: Buffer pool blocks are accessed after they have been freed
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.
2017-04-26 15:19:16 +03:00
|
|
|
dberr_t
|
MDEV-19514 Defer change buffer merge until pages are requested
We will remove the InnoDB background operation of merging buffered
changes to secondary index leaf pages. Changes will only be merged as a
result of an operation that accesses a secondary index leaf page,
such as a SQL statement that performs a lookup via that index,
or is modifying the index. Also ROLLBACK and some background operations,
such as purging the history of committed transactions, or computing
index cardinality statistics, can cause change buffer merge.
Encryption key rotation will not perform change buffer merge.
The motivation of this change is to simplify the I/O logic and to
allow crash recovery to happen in the background (MDEV-14481).
We also hope that this will reduce the number of "mystery" crashes
due to corrupted data. Because change buffer merge will typically
take place as a result of executing SQL statements, there should be
a clearer connection between the crash and the SQL statements that
were executed when the server crashed.
In many cases, a slight performance improvement was observed.
This is joint work with Thirunarayanan Balathandayuthapani
and was tested by Axel Schwenke and Matthias Leich.
The InnoDB monitor counter innodb_ibuf_merge_usec will be removed.
On slow shutdown (innodb_fast_shutdown=0), we will continue to
merge all buffered changes (and purge all undo log history).
Two InnoDB configuration parameters will be changed as follows:
innodb_disable_background_merge: Removed.
This parameter existed only in debug builds.
All change buffer merges will use synchronous reads.
innodb_force_recovery will be changed as follows:
* innodb_force_recovery=4 will be the same as innodb_force_recovery=3
(the change buffer merge cannot be disabled; it can only happen as
a result of an operation that accesses a secondary index leaf page).
The option used to be capable of corrupting secondary index leaf pages.
Now that capability is removed, and innodb_force_recovery=4 becomes 'safe'.
* innodb_force_recovery=5 (which essentially hard-wires
SET GLOBAL TRANSACTION ISOLATION LEVEL READ UNCOMMITTED)
becomes safe to use. Bogus data can be returned to SQL, but
persistent InnoDB data files will not be corrupted further.
* innodb_force_recovery=6 (ignore the redo log files)
will be the only option that can potentially cause
persistent corruption of InnoDB data files.
Code changes:
buf_page_t::ibuf_exist: New flag, to indicate whether buffered
changes exist for a buffer pool page. Pages with pending changes
can be returned by buf_page_get_gen(). Previously, the changes
were always merged inside buf_page_get_gen() if needed.
ibuf_page_exists(const buf_page_t&): Check if a buffered changes
exist for an X-latched or read-fixed page.
buf_page_get_gen(): Add the parameter allow_ibuf_merge=false.
All callers that know that they may be accessing a secondary index
leaf page must pass this parameter as allow_ibuf_merge=true,
unless it does not matter for that caller whether all buffered
changes have been applied. Assert that whenever allow_ibuf_merge
holds, the page actually is a leaf page. Attempt change buffer
merge only to secondary B-tree index leaf pages.
btr_block_get(): Add parameter 'bool merge'.
All callers of btr_block_get() should know whether the page could be
a secondary index leaf page. If it is not, we should avoid consulting
the change buffer bitmap to even consider a merge. This is the main
interface to requesting index pages from the buffer pool.
ibuf_merge_or_delete_for_page(), recv_recover_page(): Replace
buf_page_get_known_nowait() with much simpler logic, because
it is now guaranteed that that the block is x-latched or read-fixed.
mlog_init_t::mark_ibuf_exist(): Renamed from mlog_init_t::ibuf_merge().
On crash recovery, we will no longer merge any buffered changes
for the pages that we read into the buffer pool during the last batch
of applying log records.
buf_page_get_gen_known_nowait(), BUF_MAKE_YOUNG, BUF_KEEP_OLD: Remove.
btr_search_guess_on_hash(): Merge buf_page_get_gen_known_nowait()
to its only remaining caller.
buf_page_make_young_if_needed(): Define as an inline function.
Add the parameter buf_pool.
buf_page_peek_if_young(), buf_page_peek_if_too_old(): Add the
parameter buf_pool.
fil_space_validate_for_mtr_commit(): Remove a bogus comment
about background merge of the change buffer.
btr_cur_open_at_rnd_pos_func(), btr_cur_search_to_nth_level_func(),
btr_cur_open_at_index_side_func(): Use narrower data types and scopes.
ibuf_read_merge_pages(): Replaces buf_read_ibuf_merge_pages().
Merge the change buffer by invoking buf_page_get_gen().
2019-10-11 17:28:15 +03:00
|
|
|
buf_page_io_complete(
|
|
|
|
buf_page_t* bpage,
|
|
|
|
bool dblwr = false,
|
|
|
|
bool evict = false)
|
2017-05-05 10:25:29 +03:00
|
|
|
MY_ATTRIBUTE((nonnull));
|
MDEV-12253: Buffer pool blocks are accessed after they have been freed
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.
2017-04-26 15:19:16 +03:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/** Returns the control block of a file page, NULL if not found.
|
|
|
|
@param[in] page_id page id
|
|
|
|
@return block, NULL if not found */
|
2020-02-12 14:45:21 +02:00
|
|
|
inline buf_page_t *buf_page_hash_get_low(const page_id_t page_id);
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
/** Returns the control block of a file page, NULL if not found.
|
2014-02-26 19:11:54 +01:00
|
|
|
If the block is found and lock is not NULL then the appropriate
|
|
|
|
page_hash lock is acquired in the specified lock mode. Otherwise,
|
|
|
|
mode value is ignored. It is up to the caller to release the
|
|
|
|
lock. If the block is found and the lock is NULL then the page_hash
|
|
|
|
lock is released by this function.
|
2016-08-12 11:17:45 +03:00
|
|
|
@param[in] page_id page id
|
|
|
|
@param[in,out] lock lock of the page hash acquired if bpage is
|
|
|
|
found, NULL otherwise. If NULL is passed then the hash_lock is released by
|
|
|
|
this function.
|
|
|
|
@param[in] lock_mode RW_LOCK_X or RW_LOCK_S. Ignored if
|
|
|
|
lock == NULL
|
|
|
|
@param[in] watch if true, return watch sentinel also.
|
|
|
|
@return pointer to the bpage or NULL; if NULL, lock is also NULL or
|
|
|
|
a watch sentinel. */
|
2014-02-26 19:11:54 +01:00
|
|
|
UNIV_INLINE
|
|
|
|
buf_page_t*
|
|
|
|
buf_page_hash_get_locked(
|
2018-10-18 18:23:12 +03:00
|
|
|
const page_id_t page_id,
|
2016-08-12 11:17:45 +03:00
|
|
|
rw_lock_t** lock,
|
|
|
|
ulint lock_mode,
|
|
|
|
bool watch = false);
|
|
|
|
|
|
|
|
/** Returns the control block of a file page, NULL if not found.
|
2014-02-26 19:11:54 +01:00
|
|
|
If the block is found and lock is not NULL then the appropriate
|
|
|
|
page_hash lock is acquired in the specified lock mode. Otherwise,
|
|
|
|
mode value is ignored. It is up to the caller to release the
|
|
|
|
lock. If the block is found and the lock is NULL then the page_hash
|
|
|
|
lock is released by this function.
|
2016-08-12 11:17:45 +03:00
|
|
|
@param[in] page_id page id
|
|
|
|
@param[in,out] lock lock of the page hash acquired if bpage is
|
|
|
|
found, NULL otherwise. If NULL is passed then the hash_lock is released by
|
|
|
|
this function.
|
|
|
|
@param[in] lock_mode RW_LOCK_X or RW_LOCK_S. Ignored if
|
|
|
|
lock == NULL
|
|
|
|
@return pointer to the block or NULL; if NULL, lock is also NULL. */
|
2014-02-26 19:11:54 +01:00
|
|
|
UNIV_INLINE
|
|
|
|
buf_block_t*
|
|
|
|
buf_block_hash_get_locked(
|
2018-10-18 18:23:12 +03:00
|
|
|
const page_id_t page_id,
|
2016-08-12 11:17:45 +03:00
|
|
|
rw_lock_t** lock,
|
|
|
|
ulint lock_mode);
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
/* There are four different ways we can try to get a bpage or block
|
|
|
|
from the page hash:
|
|
|
|
1) Caller already holds the appropriate page hash lock: in the case call
|
|
|
|
buf_page_hash_get_low() function.
|
|
|
|
2) Caller wants to hold page hash lock in x-mode
|
|
|
|
3) Caller wants to hold page hash lock in s-mode
|
|
|
|
4) Caller doesn't want to hold page hash lock */
|
2020-02-12 14:45:21 +02:00
|
|
|
#define buf_page_hash_get_s_locked(page_id, l) \
|
|
|
|
buf_page_hash_get_locked(page_id, l, RW_LOCK_S)
|
|
|
|
#define buf_page_hash_get_x_locked(page_id, l) \
|
|
|
|
buf_page_hash_get_locked(page_id, l, RW_LOCK_X)
|
|
|
|
#define buf_page_hash_get(page_id) \
|
|
|
|
buf_page_hash_get_locked(page_id, NULL, 0)
|
|
|
|
#define buf_page_get_also_watch(page_id) \
|
|
|
|
buf_page_hash_get_locked(page_id, NULL, 0, true)
|
|
|
|
|
|
|
|
#define buf_block_hash_get_s_locked(page_id, l) \
|
|
|
|
buf_block_hash_get_locked(page_id, l, RW_LOCK_S)
|
|
|
|
#define buf_block_hash_get_x_locked(page_id, l) \
|
|
|
|
buf_block_hash_get_locked(page_id, l, RW_LOCK_X)
|
|
|
|
#define buf_block_hash_get(page_id) \
|
|
|
|
buf_block_hash_get_locked(page_id, NULL, 0)
|
|
|
|
|
|
|
|
/** Determine if a block is a sentinel for a buffer pool watch.
|
|
|
|
@param[in] bpage block
|
|
|
|
@return whether bpage a sentinel for a buffer pool watch */
|
|
|
|
bool buf_pool_watch_is_sentinel(const buf_page_t* bpage)
|
2016-06-21 14:21:03 +02:00
|
|
|
MY_ATTRIBUTE((nonnull, warn_unused_result));
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
/** Stop watching if the page has been read in.
|
|
|
|
buf_pool_watch_set(space,offset) must have returned NULL before.
|
|
|
|
@param[in] page_id page id */
|
2018-10-18 18:23:12 +03:00
|
|
|
void buf_pool_watch_unset(const page_id_t page_id);
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
/** Check if the page has been read in.
|
2014-02-26 19:11:54 +01:00
|
|
|
This may only be called after buf_pool_watch_set(space,offset)
|
|
|
|
has returned NULL and before invoking buf_pool_watch_unset(space,offset).
|
2016-08-12 11:17:45 +03:00
|
|
|
@param[in] page_id page id
|
|
|
|
@return FALSE if the given page was not read in, TRUE if it was */
|
2018-10-18 18:23:12 +03:00
|
|
|
bool buf_pool_watch_occurred(const page_id_t page_id)
|
2016-09-06 09:43:16 +03:00
|
|
|
MY_ATTRIBUTE((warn_unused_result));
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
/** Verify the possibility that a stored page is not in buffer pool.
|
|
|
|
@param[in] withdraw_clock withdraw clock when stored the page
|
|
|
|
@retval true if the page might be relocated */
|
|
|
|
UNIV_INLINE
|
|
|
|
bool
|
|
|
|
buf_pool_is_obsolete(
|
|
|
|
ulint withdraw_clock);
|
|
|
|
|
|
|
|
/** Calculate aligned buffer pool size based on srv_buf_pool_chunk_unit,
|
|
|
|
if needed.
|
|
|
|
@param[in] size size in bytes
|
|
|
|
@return aligned size */
|
|
|
|
UNIV_INLINE
|
|
|
|
ulint
|
|
|
|
buf_pool_size_align(
|
|
|
|
ulint size);
|
|
|
|
|
MDEV-12026: Implement innodb_checksum_algorithm=full_crc32
MariaDB data-at-rest encryption (innodb_encrypt_tables)
had repurposed the same unused data field that was repurposed
in MySQL 5.7 (and MariaDB 10.2) for the Split Sequence Number (SSN)
field of SPATIAL INDEX. Because of this, MariaDB was unable to
support encryption on SPATIAL INDEX pages.
Furthermore, InnoDB page checksums skipped some bytes, and there
are multiple variations and checksum algorithms. By default,
InnoDB accepts all variations of all algorithms that ever existed.
This unnecessarily weakens the page checksums.
We hereby introduce two more innodb_checksum_algorithm variants
(full_crc32, strict_full_crc32) that are special in a way:
When either setting is active, newly created data files will
carry a flag (fil_space_t::full_crc32()) that indicates that
all pages of the file will use a full CRC-32C checksum over the
entire page contents (excluding the bytes where the checksum
is stored, at the very end of the page). Such files will always
use that checksum, no matter what the parameter
innodb_checksum_algorithm is assigned to.
For old files, the old checksum algorithms will continue to be
used. The value strict_full_crc32 will be equivalent to strict_crc32
and the value full_crc32 will be equivalent to crc32.
ROW_FORMAT=COMPRESSED tables will only use the old format.
These tables do not support new features, such as larger
innodb_page_size or instant ADD/DROP COLUMN. They may be
deprecated in the future. We do not want an unnecessary
file format change for them.
The new full_crc32() format also cleans up the MariaDB tablespace
flags. We will reserve flags to store the page_compressed
compression algorithm, and to store the compressed payload length,
so that checksum can be computed over the compressed (and
possibly encrypted) stream and can be validated without
decrypting or decompressing the page.
In the full_crc32 format, there no longer are separate before-encryption
and after-encryption checksums for pages. The single checksum is
computed on the page contents that is written to the file.
We do not make the new algorithm the default for two reasons.
First, MariaDB 10.4.2 was a beta release, and the default values
of parameters should not change after beta. Second, we did not
yet implement the full_crc32 format for page_compressed pages.
This will be fixed in MDEV-18644.
This is joint work with Marko Mäkelä.
2019-02-19 21:00:00 +02:00
|
|
|
/** Verify that post encryption checksum match with the calculated checksum.
|
|
|
|
This function should be called only if tablespace contains crypt data metadata.
|
|
|
|
@param[in] page page frame
|
|
|
|
@param[in] fsp_flags tablespace flags
|
|
|
|
@return true if page is encrypted and OK, false otherwise */
|
|
|
|
bool buf_page_verify_crypt_checksum(
|
|
|
|
const byte* page,
|
|
|
|
ulint fsp_flags);
|
|
|
|
|
MDEV-21132 Remove buf_page_t::newest_modification
At each mini-transaction commit, the log sequence number of the
mini-transaction must be written to each modified page, so that
it will be available in the FIL_PAGE_LSN field when the page is
being read in crash recovery.
InnoDB was unnecessarily allocating redundant storage for the
field, in buf_page_t::newest_modification. Let us access
FIL_PAGE_LSN directly.
Furthermore, on ALTER TABLE...IMPORT TABLESPACE, let us write
0 to FIL_PAGE_LSN instead of using log_sys.lsn.
buf_flush_init_for_writing(), buf_flush_update_zip_checksum(),
fil_encrypt_buf_for_full_crc32(), fil_encrypt_buf(),
fil_space_encrypt(): Remove the parameter lsn.
buf_page_get_newest_modification(): Merge with the only caller.
buf_tmp_reserve_compression_buf(), buf_tmp_page_encrypt(),
buf_page_encrypt(): Define static in the same compilation unit
with the only caller.
PageConverter::m_current_lsn: Remove. Write 0 to FIL_PAGE_LSN
on ALTER TABLE...IMPORT TABLESPACE.
2019-11-25 09:39:51 +02:00
|
|
|
/** Calculate a ROW_FORMAT=COMPRESSED page checksum and update the page.
|
|
|
|
@param[in,out] page page to update
|
|
|
|
@param[in] size compressed page size */
|
|
|
|
void buf_flush_update_zip_checksum(buf_frame_t* page, ulint size);
|
2014-12-22 16:53:17 +02:00
|
|
|
|
2015-04-01 19:37:00 +03:00
|
|
|
/** @brief The temporary memory structure.
|
2014-12-22 16:53:17 +02:00
|
|
|
|
2015-04-01 19:37:00 +03:00
|
|
|
NOTE! The definition appears here only for other modules of this
|
|
|
|
directory (buf) to see it. Do not use from outside! */
|
|
|
|
|
2018-10-13 23:22:05 +04:00
|
|
|
class buf_tmp_buffer_t {
|
|
|
|
/** whether this slot is reserved */
|
|
|
|
std::atomic<bool> reserved;
|
2018-06-13 16:15:21 +03:00
|
|
|
public:
|
2015-04-01 19:37:00 +03:00
|
|
|
byte* crypt_buf; /*!< for encryption the data needs to be
|
|
|
|
copied to a separate buffer before it's
|
|
|
|
encrypted&written. this as a page can be
|
|
|
|
read while it's being flushed */
|
|
|
|
byte* comp_buf; /*!< for compression we need
|
|
|
|
temporal buffer because page
|
|
|
|
can be read while it's being flushed */
|
2015-06-03 13:10:18 +03:00
|
|
|
byte* out_buf; /*!< resulting buffer after
|
|
|
|
encryption/compression. This is a
|
|
|
|
pointer and not allocated. */
|
2018-06-13 16:15:21 +03:00
|
|
|
|
|
|
|
/** Release the slot */
|
|
|
|
void release()
|
|
|
|
{
|
2018-10-13 23:22:05 +04:00
|
|
|
reserved.store(false, std::memory_order_relaxed);
|
2018-06-13 16:15:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Acquire the slot
|
|
|
|
@return whether the slot was acquired */
|
|
|
|
bool acquire()
|
|
|
|
{
|
2018-10-13 23:22:05 +04:00
|
|
|
return !reserved.exchange(true, std::memory_order_relaxed);
|
2018-06-13 16:15:21 +03:00
|
|
|
}
|
MDEV-21132 Remove buf_page_t::newest_modification
At each mini-transaction commit, the log sequence number of the
mini-transaction must be written to each modified page, so that
it will be available in the FIL_PAGE_LSN field when the page is
being read in crash recovery.
InnoDB was unnecessarily allocating redundant storage for the
field, in buf_page_t::newest_modification. Let us access
FIL_PAGE_LSN directly.
Furthermore, on ALTER TABLE...IMPORT TABLESPACE, let us write
0 to FIL_PAGE_LSN instead of using log_sys.lsn.
buf_flush_init_for_writing(), buf_flush_update_zip_checksum(),
fil_encrypt_buf_for_full_crc32(), fil_encrypt_buf(),
fil_space_encrypt(): Remove the parameter lsn.
buf_page_get_newest_modification(): Merge with the only caller.
buf_tmp_reserve_compression_buf(), buf_tmp_page_encrypt(),
buf_page_encrypt(): Define static in the same compilation unit
with the only caller.
PageConverter::m_current_lsn: Remove. Write 0 to FIL_PAGE_LSN
on ALTER TABLE...IMPORT TABLESPACE.
2019-11-25 09:39:51 +02:00
|
|
|
|
|
|
|
/** Allocate a buffer for encryption, decryption or decompression. */
|
|
|
|
void allocate()
|
|
|
|
{
|
|
|
|
if (!crypt_buf) {
|
|
|
|
crypt_buf= static_cast<byte*>(
|
|
|
|
aligned_malloc(srv_page_size, srv_page_size));
|
|
|
|
}
|
|
|
|
}
|
2018-10-13 23:22:05 +04:00
|
|
|
};
|
2014-12-22 16:53:17 +02:00
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
/** The common buffer control block structure
|
|
|
|
for compressed and uncompressed frames */
|
|
|
|
|
|
|
|
/** Number of bits used for buffer page states. */
|
|
|
|
#define BUF_PAGE_STATE_BITS 3
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
class buf_page_t {
|
|
|
|
public:
|
2014-02-26 19:11:54 +01:00
|
|
|
/** @name General fields
|
|
|
|
None of these bit-fields must be modified without holding
|
|
|
|
buf_page_get_mutex() [buf_block_t::mutex or
|
|
|
|
buf_pool->zip_mutex], since they can be stored in the same
|
|
|
|
machine word. Some of these fields are additionally protected
|
|
|
|
by buf_pool->mutex. */
|
|
|
|
/* @{ */
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/** Page id. Protected by buf_pool mutex. */
|
|
|
|
page_id_t id;
|
2019-01-14 22:14:56 +03:00
|
|
|
buf_page_t* hash; /*!< node used in chaining to
|
|
|
|
buf_pool->page_hash or
|
|
|
|
buf_pool->zip_hash */
|
2014-05-05 18:20:28 +02:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/** Count of how manyfold this block is currently bufferfixed. */
|
2019-01-07 01:18:19 +04:00
|
|
|
Atomic_counter<uint32_t> buf_fix_count;
|
2014-05-05 18:20:28 +02:00
|
|
|
|
|
|
|
/** type of pending I/O operation; also protected by
|
2016-08-12 11:17:45 +03:00
|
|
|
buf_pool->mutex for writes only */
|
|
|
|
buf_io_fix io_fix;
|
2014-05-05 18:20:28 +02:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/** Block state. @see buf_page_in_file */
|
|
|
|
buf_page_state state;
|
2014-05-05 18:20:28 +02:00
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
unsigned flush_type:2; /*!< if this block is currently being
|
|
|
|
flushed to disk, this tells the
|
|
|
|
flush_type.
|
|
|
|
@see buf_flush_t */
|
|
|
|
/* @} */
|
|
|
|
page_zip_des_t zip; /*!< compressed page; zip.data
|
|
|
|
(but not the data it points to) is
|
|
|
|
also protected by buf_pool->mutex;
|
|
|
|
state == BUF_BLOCK_ZIP_PAGE and
|
|
|
|
zip.data == NULL means an active
|
|
|
|
buf_pool->watch */
|
2013-12-19 14:36:38 +02:00
|
|
|
|
2014-12-22 16:53:17 +02:00
|
|
|
ulint write_size; /* Write size is set when this
|
2013-12-19 14:36:38 +02:00
|
|
|
page is first time written and then
|
|
|
|
if written again we check is TRIM
|
|
|
|
operation needed. */
|
2014-12-22 16:53:17 +02:00
|
|
|
|
2019-06-12 19:36:54 +03:00
|
|
|
/** whether the page will be (re)initialized at the time it will
|
|
|
|
be written to the file, that is, whether the doublewrite buffer
|
|
|
|
can be safely skipped. Protected under similar conditions as
|
|
|
|
buf_block_t::frame. Can be set while holding buf_block_t::lock
|
|
|
|
X-latch and reset during page flush, while io_fix is in effect. */
|
|
|
|
bool init_on_flush;
|
|
|
|
|
2015-04-01 19:37:00 +03:00
|
|
|
ulint real_size; /*!< Real size of the page
|
2018-04-27 13:49:25 +03:00
|
|
|
Normal pages == srv_page_size
|
2015-04-01 19:37:00 +03:00
|
|
|
page compressed pages, payload
|
|
|
|
size alligned to sector boundary.
|
|
|
|
*/
|
|
|
|
|
|
|
|
buf_tmp_buffer_t* slot; /*!< Slot for temporary memory
|
|
|
|
used for encryption/compression
|
|
|
|
or NULL */
|
2014-02-26 19:11:54 +01:00
|
|
|
#ifdef UNIV_DEBUG
|
|
|
|
ibool in_page_hash; /*!< TRUE if in buf_pool->page_hash */
|
|
|
|
ibool in_zip_hash; /*!< TRUE if in buf_pool->zip_hash */
|
|
|
|
#endif /* UNIV_DEBUG */
|
|
|
|
|
|
|
|
/** @name Page flushing fields
|
|
|
|
All these are protected by buf_pool->mutex. */
|
|
|
|
/* @{ */
|
|
|
|
|
|
|
|
UT_LIST_NODE_T(buf_page_t) list;
|
|
|
|
/*!< based on state, this is a
|
|
|
|
list node, protected either by
|
|
|
|
buf_pool->mutex or by
|
|
|
|
buf_pool->flush_list_mutex,
|
|
|
|
in one of the following lists in
|
|
|
|
buf_pool:
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
- BUF_BLOCK_NOT_USED: free, withdraw
|
2014-02-26 19:11:54 +01:00
|
|
|
- BUF_BLOCK_FILE_PAGE: flush_list
|
|
|
|
- BUF_BLOCK_ZIP_DIRTY: flush_list
|
|
|
|
- BUF_BLOCK_ZIP_PAGE: zip_clean
|
|
|
|
|
|
|
|
If bpage is part of flush_list
|
|
|
|
then the node pointers are
|
|
|
|
covered by buf_pool->flush_list_mutex.
|
|
|
|
Otherwise these pointers are
|
|
|
|
protected by buf_pool->mutex.
|
|
|
|
|
|
|
|
The contents of the list node
|
|
|
|
is undefined if !in_flush_list
|
|
|
|
&& state == BUF_BLOCK_FILE_PAGE,
|
|
|
|
or if state is one of
|
|
|
|
BUF_BLOCK_MEMORY,
|
|
|
|
BUF_BLOCK_REMOVE_HASH or
|
|
|
|
BUF_BLOCK_READY_IN_USE. */
|
|
|
|
|
|
|
|
#ifdef UNIV_DEBUG
|
|
|
|
ibool in_flush_list; /*!< TRUE if in buf_pool->flush_list;
|
|
|
|
when buf_pool->flush_list_mutex is
|
|
|
|
free, the following should hold:
|
|
|
|
in_flush_list
|
|
|
|
== (state == BUF_BLOCK_FILE_PAGE
|
|
|
|
|| state == BUF_BLOCK_ZIP_DIRTY)
|
|
|
|
Writes to this field must be
|
|
|
|
covered by both block->mutex
|
|
|
|
and buf_pool->flush_list_mutex. Hence
|
|
|
|
reads can happen while holding
|
|
|
|
any one of the two mutexes */
|
|
|
|
ibool in_free_list; /*!< TRUE if in buf_pool->free; when
|
|
|
|
buf_pool->mutex is free, the following
|
|
|
|
should hold: in_free_list
|
|
|
|
== (state == BUF_BLOCK_NOT_USED) */
|
|
|
|
#endif /* UNIV_DEBUG */
|
2016-08-12 11:17:45 +03:00
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
lsn_t oldest_modification;
|
|
|
|
/*!< log sequence number of
|
|
|
|
the START of the log entry
|
|
|
|
written of the oldest
|
|
|
|
modification to this block
|
|
|
|
which has not yet been flushed
|
|
|
|
on disk; zero if all
|
|
|
|
modifications are on disk.
|
|
|
|
Writes to this field must be
|
|
|
|
covered by both block->mutex
|
|
|
|
and buf_pool->flush_list_mutex. Hence
|
|
|
|
reads can happen while holding
|
|
|
|
any one of the two mutexes */
|
|
|
|
/* @} */
|
|
|
|
/** @name LRU replacement algorithm fields
|
|
|
|
These fields are protected by buf_pool->mutex only (not
|
|
|
|
buf_pool->zip_mutex or buf_block_t::mutex). */
|
|
|
|
/* @{ */
|
|
|
|
|
|
|
|
UT_LIST_NODE_T(buf_page_t) LRU;
|
|
|
|
/*!< node of the LRU list */
|
|
|
|
#ifdef UNIV_DEBUG
|
|
|
|
ibool in_LRU_list; /*!< TRUE if the page is in
|
|
|
|
the LRU list; used in
|
|
|
|
debugging */
|
|
|
|
#endif /* UNIV_DEBUG */
|
|
|
|
unsigned old:1; /*!< TRUE if the block is in the old
|
|
|
|
blocks in buf_pool->LRU_old */
|
|
|
|
unsigned freed_page_clock:31;/*!< the value of
|
|
|
|
buf_pool->freed_page_clock
|
|
|
|
when this block was the last
|
|
|
|
time put to the head of the
|
|
|
|
LRU list; a thread is allowed
|
|
|
|
to read this for heuristic
|
|
|
|
purposes without holding any
|
|
|
|
mutex or latch */
|
|
|
|
/* @} */
|
|
|
|
unsigned access_time; /*!< time of first access, or
|
|
|
|
0 if the block was never accessed
|
|
|
|
in the buffer pool. Protected by
|
2020-02-06 09:00:19 +02:00
|
|
|
block mutex for buf_page_in_file()
|
|
|
|
blocks.
|
|
|
|
|
|
|
|
For state==BUF_BLOCK_MEMORY
|
|
|
|
blocks, this field can be repurposed
|
|
|
|
for something else.
|
|
|
|
|
|
|
|
When this field counts log records
|
|
|
|
and bytes allocated for recv_sys.pages,
|
|
|
|
the field is protected by
|
|
|
|
recv_sys_t::mutex. */
|
2016-08-12 11:17:45 +03:00
|
|
|
# ifdef UNIV_DEBUG
|
2014-02-26 19:11:54 +01:00
|
|
|
ibool file_page_was_freed;
|
|
|
|
/*!< this is set to TRUE when
|
|
|
|
fsp frees a page in buffer pool;
|
|
|
|
protected by buf_pool->zip_mutex
|
|
|
|
or buf_block_t::mutex. */
|
2016-08-12 11:17:45 +03:00
|
|
|
# endif /* UNIV_DEBUG */
|
MDEV-19514 Defer change buffer merge until pages are requested
We will remove the InnoDB background operation of merging buffered
changes to secondary index leaf pages. Changes will only be merged as a
result of an operation that accesses a secondary index leaf page,
such as a SQL statement that performs a lookup via that index,
or is modifying the index. Also ROLLBACK and some background operations,
such as purging the history of committed transactions, or computing
index cardinality statistics, can cause change buffer merge.
Encryption key rotation will not perform change buffer merge.
The motivation of this change is to simplify the I/O logic and to
allow crash recovery to happen in the background (MDEV-14481).
We also hope that this will reduce the number of "mystery" crashes
due to corrupted data. Because change buffer merge will typically
take place as a result of executing SQL statements, there should be
a clearer connection between the crash and the SQL statements that
were executed when the server crashed.
In many cases, a slight performance improvement was observed.
This is joint work with Thirunarayanan Balathandayuthapani
and was tested by Axel Schwenke and Matthias Leich.
The InnoDB monitor counter innodb_ibuf_merge_usec will be removed.
On slow shutdown (innodb_fast_shutdown=0), we will continue to
merge all buffered changes (and purge all undo log history).
Two InnoDB configuration parameters will be changed as follows:
innodb_disable_background_merge: Removed.
This parameter existed only in debug builds.
All change buffer merges will use synchronous reads.
innodb_force_recovery will be changed as follows:
* innodb_force_recovery=4 will be the same as innodb_force_recovery=3
(the change buffer merge cannot be disabled; it can only happen as
a result of an operation that accesses a secondary index leaf page).
The option used to be capable of corrupting secondary index leaf pages.
Now that capability is removed, and innodb_force_recovery=4 becomes 'safe'.
* innodb_force_recovery=5 (which essentially hard-wires
SET GLOBAL TRANSACTION ISOLATION LEVEL READ UNCOMMITTED)
becomes safe to use. Bogus data can be returned to SQL, but
persistent InnoDB data files will not be corrupted further.
* innodb_force_recovery=6 (ignore the redo log files)
will be the only option that can potentially cause
persistent corruption of InnoDB data files.
Code changes:
buf_page_t::ibuf_exist: New flag, to indicate whether buffered
changes exist for a buffer pool page. Pages with pending changes
can be returned by buf_page_get_gen(). Previously, the changes
were always merged inside buf_page_get_gen() if needed.
ibuf_page_exists(const buf_page_t&): Check if a buffered changes
exist for an X-latched or read-fixed page.
buf_page_get_gen(): Add the parameter allow_ibuf_merge=false.
All callers that know that they may be accessing a secondary index
leaf page must pass this parameter as allow_ibuf_merge=true,
unless it does not matter for that caller whether all buffered
changes have been applied. Assert that whenever allow_ibuf_merge
holds, the page actually is a leaf page. Attempt change buffer
merge only to secondary B-tree index leaf pages.
btr_block_get(): Add parameter 'bool merge'.
All callers of btr_block_get() should know whether the page could be
a secondary index leaf page. If it is not, we should avoid consulting
the change buffer bitmap to even consider a merge. This is the main
interface to requesting index pages from the buffer pool.
ibuf_merge_or_delete_for_page(), recv_recover_page(): Replace
buf_page_get_known_nowait() with much simpler logic, because
it is now guaranteed that that the block is x-latched or read-fixed.
mlog_init_t::mark_ibuf_exist(): Renamed from mlog_init_t::ibuf_merge().
On crash recovery, we will no longer merge any buffered changes
for the pages that we read into the buffer pool during the last batch
of applying log records.
buf_page_get_gen_known_nowait(), BUF_MAKE_YOUNG, BUF_KEEP_OLD: Remove.
btr_search_guess_on_hash(): Merge buf_page_get_gen_known_nowait()
to its only remaining caller.
buf_page_make_young_if_needed(): Define as an inline function.
Add the parameter buf_pool.
buf_page_peek_if_young(), buf_page_peek_if_too_old(): Add the
parameter buf_pool.
fil_space_validate_for_mtr_commit(): Remove a bogus comment
about background merge of the change buffer.
btr_cur_open_at_rnd_pos_func(), btr_cur_search_to_nth_level_func(),
btr_cur_open_at_index_side_func(): Use narrower data types and scopes.
ibuf_read_merge_pages(): Replaces buf_read_ibuf_merge_pages().
Merge the change buffer by invoking buf_page_get_gen().
2019-10-11 17:28:15 +03:00
|
|
|
/** Change buffer entries for the page exist.
|
|
|
|
Protected by io_fix==BUF_IO_READ or by buf_block_t::lock. */
|
|
|
|
bool ibuf_exist;
|
2019-01-07 01:18:19 +04:00
|
|
|
|
|
|
|
void fix() { buf_fix_count++; }
|
|
|
|
uint32_t unfix()
|
|
|
|
{
|
|
|
|
uint32_t count= buf_fix_count--;
|
|
|
|
ut_ad(count != 0);
|
|
|
|
return count - 1;
|
|
|
|
}
|
2019-02-06 19:50:11 +02:00
|
|
|
|
|
|
|
/** @return the physical size, in bytes */
|
|
|
|
ulint physical_size() const
|
|
|
|
{
|
|
|
|
return zip.ssize ? (UNIV_ZIP_SIZE_MIN >> 1) << zip.ssize : srv_page_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @return the ROW_FORMAT=COMPRESSED physical size, in bytes
|
|
|
|
@retval 0 if not compressed */
|
|
|
|
ulint zip_size() const
|
|
|
|
{
|
|
|
|
return zip.ssize ? (UNIV_ZIP_SIZE_MIN >> 1) << zip.ssize : 0;
|
|
|
|
}
|
2014-02-26 19:11:54 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/** The buffer control block structure */
|
|
|
|
|
|
|
|
struct buf_block_t{
|
|
|
|
|
|
|
|
/** @name General fields */
|
|
|
|
/* @{ */
|
|
|
|
|
|
|
|
buf_page_t page; /*!< page information; this must
|
|
|
|
be the first field, so that
|
|
|
|
buf_pool->page_hash can point
|
|
|
|
to buf_page_t or buf_block_t */
|
|
|
|
byte* frame; /*!< pointer to buffer frame which
|
2018-04-27 13:49:25 +03:00
|
|
|
is of size srv_page_size, and
|
2014-02-26 19:11:54 +01:00
|
|
|
aligned to an address divisible by
|
2018-04-27 13:49:25 +03:00
|
|
|
srv_page_size */
|
2016-08-12 11:17:45 +03:00
|
|
|
BPageLock lock; /*!< read-write lock of the buffer
|
|
|
|
frame */
|
2014-02-26 19:11:54 +01:00
|
|
|
UT_LIST_NODE_T(buf_block_t) unzip_LRU;
|
|
|
|
/*!< node of the decompressed LRU list;
|
|
|
|
a block is in the unzip_LRU list
|
|
|
|
if page.state == BUF_BLOCK_FILE_PAGE
|
|
|
|
and page.zip.data != NULL */
|
|
|
|
#ifdef UNIV_DEBUG
|
|
|
|
ibool in_unzip_LRU_list;/*!< TRUE if the page is in the
|
|
|
|
decompressed LRU list;
|
|
|
|
used in debugging */
|
2016-08-12 11:17:45 +03:00
|
|
|
ibool in_withdraw_list;
|
2014-02-26 19:11:54 +01:00
|
|
|
#endif /* UNIV_DEBUG */
|
2018-02-13 23:08:38 +03:00
|
|
|
uint32_t lock_hash_val; /*!< hashed value of the page address
|
2014-02-26 19:11:54 +01:00
|
|
|
in the record lock hash table;
|
|
|
|
protected by buf_block_t::lock
|
|
|
|
(or buf_block_t::mutex, buf_pool->mutex
|
|
|
|
in buf_page_get_gen(),
|
|
|
|
buf_page_init_for_read()
|
|
|
|
and buf_page_create()) */
|
|
|
|
/* @} */
|
|
|
|
/** @name Optimistic search field */
|
|
|
|
/* @{ */
|
|
|
|
|
|
|
|
ib_uint64_t modify_clock; /*!< this clock is incremented every
|
|
|
|
time a pointer to a record on the
|
|
|
|
page may become obsolete; this is
|
|
|
|
used in the optimistic cursor
|
|
|
|
positioning: if the modify clock has
|
|
|
|
not changed, we know that the pointer
|
|
|
|
is still valid; this field may be
|
|
|
|
changed if the thread (1) owns the
|
|
|
|
pool mutex and the page is not
|
|
|
|
bufferfixed, or (2) the thread has an
|
|
|
|
x-latch on the block */
|
|
|
|
/* @} */
|
2017-02-23 23:05:12 +02:00
|
|
|
#ifdef BTR_CUR_HASH_ADAPT
|
2014-02-26 19:11:54 +01:00
|
|
|
/** @name Hash search fields (unprotected)
|
|
|
|
NOTE that these fields are NOT protected by any semaphore! */
|
|
|
|
/* @{ */
|
|
|
|
|
|
|
|
ulint n_hash_helps; /*!< counter which controls building
|
|
|
|
of a new hash index for the page */
|
2016-08-12 11:17:45 +03:00
|
|
|
volatile ulint n_bytes; /*!< recommended prefix length for hash
|
|
|
|
search: number of bytes in
|
|
|
|
an incomplete last field */
|
|
|
|
volatile ulint n_fields; /*!< recommended prefix length for hash
|
2014-02-26 19:11:54 +01:00
|
|
|
search: number of full fields */
|
2016-08-12 11:17:45 +03:00
|
|
|
volatile bool left_side; /*!< true or false, depending on
|
2014-02-26 19:11:54 +01:00
|
|
|
whether the leftmost record of several
|
|
|
|
records with the same prefix should be
|
|
|
|
indexed in the hash index */
|
|
|
|
/* @} */
|
|
|
|
|
|
|
|
/** @name Hash search fields
|
2016-09-02 17:28:54 +03:00
|
|
|
These 5 fields may only be modified when:
|
|
|
|
we are holding the appropriate x-latch in btr_search_latches[], and
|
|
|
|
one of the following holds:
|
|
|
|
(1) the block state is BUF_BLOCK_FILE_PAGE, and
|
|
|
|
we are holding an s-latch or x-latch on buf_block_t::lock, or
|
|
|
|
(2) buf_block_t::buf_fix_count == 0, or
|
|
|
|
(3) the block state is BUF_BLOCK_REMOVE_HASH.
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
An exception to this is when we init or create a page
|
|
|
|
in the buffer pool in buf0buf.cc.
|
|
|
|
|
2016-09-02 17:28:54 +03:00
|
|
|
Another exception for buf_pool_clear_hash_index() is that
|
|
|
|
assigning block->index = NULL (and block->n_pointers = 0)
|
|
|
|
is allowed whenever btr_search_own_all(RW_LOCK_X).
|
|
|
|
|
|
|
|
Another exception is that ha_insert_for_fold_func() may
|
|
|
|
decrement n_pointers without holding the appropriate latch
|
|
|
|
in btr_search_latches[]. Thus, n_pointers must be
|
|
|
|
protected by atomic memory access.
|
|
|
|
|
|
|
|
This implies that the fields may be read without race
|
|
|
|
condition whenever any of the following hold:
|
|
|
|
- the btr_search_latches[] s-latch or x-latch is being held, or
|
|
|
|
- the block state is not BUF_BLOCK_FILE_PAGE or BUF_BLOCK_REMOVE_HASH,
|
|
|
|
and holding some latch prevents the state from changing to that.
|
|
|
|
|
|
|
|
Some use of assert_block_ahi_empty() or assert_block_ahi_valid()
|
|
|
|
is prone to race conditions while buf_pool_clear_hash_index() is
|
|
|
|
executing (the adaptive hash index is being disabled). Such use
|
|
|
|
is explicitly commented. */
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
/* @{ */
|
|
|
|
|
2017-02-23 23:05:12 +02:00
|
|
|
# if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
|
2018-12-28 17:53:50 +04:00
|
|
|
Atomic_counter<ulint>
|
|
|
|
n_pointers; /*!< used in debugging: the number of
|
2014-02-26 19:11:54 +01:00
|
|
|
pointers in the adaptive hash index
|
2016-09-02 17:28:54 +03:00
|
|
|
pointing to this frame;
|
|
|
|
protected by atomic memory access
|
|
|
|
or btr_search_own_all(). */
|
|
|
|
# define assert_block_ahi_empty(block) \
|
2018-12-28 17:53:50 +04:00
|
|
|
ut_a((block)->n_pointers == 0)
|
2016-09-06 14:57:16 +03:00
|
|
|
# define assert_block_ahi_empty_on_init(block) do { \
|
|
|
|
UNIV_MEM_VALID(&(block)->n_pointers, sizeof (block)->n_pointers); \
|
|
|
|
assert_block_ahi_empty(block); \
|
|
|
|
} while (0)
|
2016-09-02 17:28:54 +03:00
|
|
|
# define assert_block_ahi_valid(block) \
|
2018-12-28 17:53:50 +04:00
|
|
|
ut_a((block)->index || (block)->n_pointers == 0)
|
2016-09-02 17:28:54 +03:00
|
|
|
# else /* UNIV_AHI_DEBUG || UNIV_DEBUG */
|
|
|
|
# define assert_block_ahi_empty(block) /* nothing */
|
2016-09-06 14:57:16 +03:00
|
|
|
# define assert_block_ahi_empty_on_init(block) /* nothing */
|
2016-09-02 17:28:54 +03:00
|
|
|
# define assert_block_ahi_valid(block) /* nothing */
|
2017-02-23 23:05:12 +02:00
|
|
|
# endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
|
2014-02-26 19:11:54 +01:00
|
|
|
unsigned curr_n_fields:10;/*!< prefix length for hash indexing:
|
|
|
|
number of full fields */
|
|
|
|
unsigned curr_n_bytes:15;/*!< number of bytes in hash
|
|
|
|
indexing */
|
|
|
|
unsigned curr_left_side:1;/*!< TRUE or FALSE in hash indexing */
|
|
|
|
dict_index_t* index; /*!< Index for which the
|
|
|
|
adaptive hash index has been
|
|
|
|
created, or NULL if the page
|
|
|
|
does not exist in the
|
|
|
|
index. Note that it does not
|
|
|
|
guarantee that the index is
|
|
|
|
complete, though: there may
|
|
|
|
have been hash collisions,
|
|
|
|
record deletions, etc. */
|
2016-09-02 17:28:54 +03:00
|
|
|
/* @} */
|
|
|
|
#else /* BTR_CUR_HASH_ADAPT */
|
|
|
|
# define assert_block_ahi_empty(block) /* nothing */
|
2016-09-06 14:57:16 +03:00
|
|
|
# define assert_block_ahi_empty_on_init(block) /* nothing */
|
2016-09-02 17:28:54 +03:00
|
|
|
# define assert_block_ahi_valid(block) /* nothing */
|
2017-02-23 23:05:12 +02:00
|
|
|
#endif /* BTR_CUR_HASH_ADAPT */
|
2016-08-12 11:17:45 +03:00
|
|
|
bool skip_flush_check;
|
|
|
|
/*!< Skip check in buf_dblwr_check_block
|
|
|
|
during bulk load, protected by lock.*/
|
|
|
|
# ifdef UNIV_DEBUG
|
2014-02-26 19:11:54 +01:00
|
|
|
/** @name Debug fields */
|
|
|
|
/* @{ */
|
2018-12-28 09:56:46 +02:00
|
|
|
rw_lock_t* debug_latch; /*!< in the debug version, each thread
|
2014-02-26 19:11:54 +01:00
|
|
|
which bufferfixes the block acquires
|
|
|
|
an s-latch here; so we can use the
|
|
|
|
debug utilities in sync0rw */
|
|
|
|
/* @} */
|
|
|
|
# endif
|
2016-08-12 11:17:45 +03:00
|
|
|
BPageMutex mutex; /*!< mutex protecting this block:
|
|
|
|
state (also protected by the buffer
|
|
|
|
pool mutex), io_fix, buf_fix_count,
|
|
|
|
and accessed; we introduce this new
|
|
|
|
mutex in InnoDB-5.1 to relieve
|
|
|
|
contention on the buffer pool mutex */
|
2019-01-07 01:18:19 +04:00
|
|
|
|
|
|
|
void fix() { page.fix(); }
|
|
|
|
uint32_t unfix() { return page.unfix(); }
|
2019-02-06 19:50:11 +02:00
|
|
|
|
|
|
|
/** @return the physical size, in bytes */
|
|
|
|
ulint physical_size() const { return page.physical_size(); }
|
|
|
|
|
|
|
|
/** @return the ROW_FORMAT=COMPRESSED physical size, in bytes
|
|
|
|
@retval 0 if not compressed */
|
|
|
|
ulint zip_size() const { return page.zip_size(); }
|
2014-02-26 19:11:54 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Check if a buf_block_t object is in a valid state
|
2016-08-12 11:17:45 +03:00
|
|
|
@param block buffer block
|
|
|
|
@return TRUE if valid */
|
2014-02-26 19:11:54 +01:00
|
|
|
#define buf_block_state_valid(block) \
|
|
|
|
(buf_block_get_state(block) >= BUF_BLOCK_NOT_USED \
|
|
|
|
&& (buf_block_get_state(block) <= BUF_BLOCK_REMOVE_HASH))
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
/**********************************************************************//**
|
|
|
|
Compute the hash fold value for blocks in buf_pool->zip_hash. */
|
|
|
|
/* @{ */
|
2018-04-27 14:26:43 +03:00
|
|
|
#define BUF_POOL_ZIP_FOLD_PTR(ptr) (ulint(ptr) >> srv_page_size_shift)
|
2014-02-26 19:11:54 +01:00
|
|
|
#define BUF_POOL_ZIP_FOLD(b) BUF_POOL_ZIP_FOLD_PTR((b)->frame)
|
|
|
|
#define BUF_POOL_ZIP_FOLD_BPAGE(b) BUF_POOL_ZIP_FOLD((buf_block_t*) (b))
|
|
|
|
/* @} */
|
|
|
|
|
2014-11-06 13:17:11 +02:00
|
|
|
/** A "Hazard Pointer" class used to iterate over page lists
|
|
|
|
inside the buffer pool. A hazard pointer is a buf_page_t pointer
|
|
|
|
which we intend to iterate over next and we want it remain valid
|
|
|
|
even after we release the buffer pool mutex. */
|
2020-02-12 14:45:21 +02:00
|
|
|
class HazardPointer
|
|
|
|
{
|
2014-11-06 13:17:11 +02:00
|
|
|
public:
|
|
|
|
/** Constructor
|
|
|
|
@param mutex mutex that is protecting the hp. */
|
2020-02-12 14:45:21 +02:00
|
|
|
HazardPointer(const ib_mutex_t* ut_d(mutex)) :
|
2014-11-06 13:17:11 +02:00
|
|
|
#ifdef UNIV_DEBUG
|
2020-02-12 14:45:21 +02:00
|
|
|
m_mutex(mutex),
|
|
|
|
#endif
|
|
|
|
m_hp() {}
|
2014-11-06 13:17:11 +02:00
|
|
|
|
|
|
|
/** Destructor */
|
|
|
|
virtual ~HazardPointer() {}
|
|
|
|
|
|
|
|
/** Get current value */
|
2016-08-12 11:17:45 +03:00
|
|
|
buf_page_t* get() const
|
2014-11-06 13:17:11 +02:00
|
|
|
{
|
|
|
|
ut_ad(mutex_own(m_mutex));
|
|
|
|
return(m_hp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Set current value
|
|
|
|
@param bpage buffer block to be set as hp */
|
|
|
|
void set(buf_page_t* bpage);
|
|
|
|
|
|
|
|
/** Checks if a bpage is the hp
|
|
|
|
@param bpage buffer block to be compared
|
|
|
|
@return true if it is hp */
|
2020-02-12 14:45:21 +02:00
|
|
|
bool is_hp(const buf_page_t* bpage) const
|
|
|
|
{
|
|
|
|
ut_ad(mutex_own(m_mutex));
|
|
|
|
return bpage == m_hp;
|
|
|
|
}
|
2014-11-06 13:17:11 +02:00
|
|
|
|
|
|
|
/** Adjust the value of hp. This happens when some
|
|
|
|
other thread working on the same list attempts to
|
|
|
|
remove the hp from the list. Must be implemented
|
|
|
|
by the derived classes.
|
|
|
|
@param bpage buffer block to be compared */
|
|
|
|
virtual void adjust(const buf_page_t*) = 0;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/** Disable copying */
|
|
|
|
HazardPointer(const HazardPointer&);
|
|
|
|
HazardPointer& operator=(const HazardPointer&);
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
#ifdef UNIV_DEBUG
|
2014-11-06 13:17:11 +02:00
|
|
|
/** mutex that protects access to the m_hp. */
|
|
|
|
const ib_mutex_t* m_mutex;
|
|
|
|
#endif /* UNIV_DEBUG */
|
|
|
|
|
|
|
|
/** hazard pointer. */
|
|
|
|
buf_page_t* m_hp;
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Class implementing buf_pool->flush_list hazard pointer */
|
|
|
|
class FlushHp: public HazardPointer {
|
|
|
|
|
|
|
|
public:
|
|
|
|
/** Constructor
|
|
|
|
@param mutex mutex that is protecting the hp. */
|
2020-02-12 14:45:21 +02:00
|
|
|
FlushHp(const ib_mutex_t* mutex) : HazardPointer(mutex) {}
|
2014-11-06 13:17:11 +02:00
|
|
|
|
|
|
|
/** Destructor */
|
2019-07-04 12:06:48 +03:00
|
|
|
~FlushHp() override {}
|
2014-11-06 13:17:11 +02:00
|
|
|
|
|
|
|
/** Adjust the value of hp. This happens when some
|
|
|
|
other thread working on the same list attempts to
|
|
|
|
remove the hp from the list.
|
|
|
|
@param bpage buffer block to be compared */
|
2019-07-04 12:06:48 +03:00
|
|
|
void adjust(const buf_page_t* bpage) override;
|
2014-11-06 13:17:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Class implementing buf_pool->LRU hazard pointer */
|
|
|
|
class LRUHp: public HazardPointer {
|
|
|
|
|
|
|
|
public:
|
|
|
|
/** Constructor
|
|
|
|
@param mutex mutex that is protecting the hp. */
|
2020-02-12 14:45:21 +02:00
|
|
|
LRUHp(const ib_mutex_t* mutex) : HazardPointer(mutex) {}
|
2014-11-06 13:17:11 +02:00
|
|
|
|
|
|
|
/** Destructor */
|
2019-07-04 12:06:48 +03:00
|
|
|
~LRUHp() override {}
|
2014-11-06 13:17:11 +02:00
|
|
|
|
|
|
|
/** Adjust the value of hp. This happens when some
|
|
|
|
other thread working on the same list attempts to
|
|
|
|
remove the hp from the list.
|
|
|
|
@param bpage buffer block to be compared */
|
2019-07-04 12:06:48 +03:00
|
|
|
void adjust(const buf_page_t* bpage) override;
|
2014-11-06 13:17:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Special purpose iterators to be used when scanning the LRU list.
|
|
|
|
The idea is that when one thread finishes the scan it leaves the
|
|
|
|
itr in that position and the other thread can start scan from
|
|
|
|
there */
|
|
|
|
class LRUItr: public LRUHp {
|
|
|
|
public:
|
|
|
|
/** Constructor
|
|
|
|
@param mutex mutex that is protecting the hp. */
|
2020-02-12 14:45:21 +02:00
|
|
|
LRUItr(const ib_mutex_t* mutex) : LRUHp(mutex) {}
|
2014-11-06 13:17:11 +02:00
|
|
|
|
|
|
|
/** Destructor */
|
2019-07-04 12:06:48 +03:00
|
|
|
~LRUItr() override {}
|
2014-11-06 13:17:11 +02:00
|
|
|
|
2020-02-12 14:45:21 +02:00
|
|
|
/** Select from where to start a scan. If we have scanned
|
2014-11-06 13:17:11 +02:00
|
|
|
too deep into the LRU list it resets the value to the tail
|
|
|
|
of the LRU list.
|
|
|
|
@return buf_page_t from where to start scan. */
|
2020-02-12 14:45:21 +02:00
|
|
|
inline buf_page_t* start();
|
2014-11-06 13:17:11 +02:00
|
|
|
};
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
/** Struct that is embedded in the free zip blocks */
|
|
|
|
struct buf_buddy_free_t {
|
|
|
|
union {
|
|
|
|
ulint size; /*!< size of the block */
|
|
|
|
byte bytes[FIL_PAGE_DATA];
|
|
|
|
/*!< stamp[FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID]
|
|
|
|
== BUF_BUDDY_FREE_STAMP denotes a free
|
|
|
|
block. If the space_id field of buddy
|
|
|
|
block != BUF_BUDDY_FREE_STAMP, the block
|
|
|
|
is not in any zip_free list. If the
|
|
|
|
space_id is BUF_BUDDY_FREE_STAMP then
|
|
|
|
stamp[0] will contain the
|
|
|
|
buddy block size. */
|
|
|
|
} stamp;
|
|
|
|
|
|
|
|
buf_page_t bpage; /*!< Embedded bpage descriptor */
|
|
|
|
UT_LIST_NODE_T(buf_buddy_free_t) list;
|
|
|
|
/*!< Node of zip_free list */
|
|
|
|
};
|
|
|
|
|
|
|
|
/** @brief The buffer pool statistics structure. */
|
|
|
|
struct buf_pool_stat_t{
|
|
|
|
ulint n_page_gets; /*!< number of page gets performed;
|
|
|
|
also successful searches through
|
|
|
|
the adaptive hash index are
|
|
|
|
counted as page gets; this field
|
|
|
|
is NOT protected by the buffer
|
|
|
|
pool mutex */
|
|
|
|
ulint n_pages_read; /*!< number read operations */
|
|
|
|
ulint n_pages_written;/*!< number write operations */
|
|
|
|
ulint n_pages_created;/*!< number of pages created
|
|
|
|
in the pool with no read */
|
|
|
|
ulint n_ra_pages_read_rnd;/*!< number of pages read in
|
|
|
|
as part of random read ahead */
|
|
|
|
ulint n_ra_pages_read;/*!< number of pages read in
|
|
|
|
as part of read ahead */
|
|
|
|
ulint n_ra_pages_evicted;/*!< number of read ahead
|
|
|
|
pages that are evicted without
|
|
|
|
being accessed */
|
|
|
|
ulint n_pages_made_young; /*!< number of pages made young, in
|
|
|
|
calls to buf_LRU_make_block_young() */
|
|
|
|
ulint n_pages_not_made_young; /*!< number of pages not made
|
|
|
|
young because the first access
|
|
|
|
was not long enough ago, in
|
|
|
|
buf_page_peek_if_too_old() */
|
|
|
|
ulint LRU_bytes; /*!< LRU size in bytes */
|
|
|
|
ulint flush_list_bytes;/*!< flush_list size in bytes */
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Statistics of buddy blocks of a given size. */
|
|
|
|
struct buf_buddy_stat_t {
|
|
|
|
/** Number of blocks allocated from the buddy system. */
|
|
|
|
ulint used;
|
|
|
|
/** Number of blocks relocated by the buddy system. */
|
|
|
|
ib_uint64_t relocated;
|
|
|
|
/** Total duration of block relocations, in microseconds. */
|
|
|
|
ib_uint64_t relocated_usec;
|
|
|
|
};
|
|
|
|
|
2020-02-12 14:45:21 +02:00
|
|
|
/** The buffer pool */
|
|
|
|
struct buf_pool_t
|
|
|
|
{
|
2014-02-26 19:11:54 +01:00
|
|
|
/** @name General fields */
|
|
|
|
/* @{ */
|
2020-02-12 14:45:21 +02:00
|
|
|
BufPoolMutex mutex; /*!< Buffer pool mutex */
|
|
|
|
BufPoolZipMutex zip_mutex; /*!< Zip mutex, protects compressed
|
2014-02-26 19:11:54 +01:00
|
|
|
only pages (of type buf_page_t, not
|
|
|
|
buf_block_t */
|
|
|
|
ulint curr_pool_size; /*!< Current pool size in bytes */
|
|
|
|
ulint LRU_old_ratio; /*!< Reserve this much of the buffer
|
|
|
|
pool for "old" blocks */
|
|
|
|
#ifdef UNIV_DEBUG
|
|
|
|
ulint buddy_n_frames; /*!< Number of frames allocated from
|
|
|
|
the buffer pool to the buddy system */
|
|
|
|
#endif
|
|
|
|
#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
|
|
|
|
ulint mutex_exit_forbidden; /*!< Forbid release mutex */
|
|
|
|
#endif
|
2016-08-12 11:17:45 +03:00
|
|
|
ut_allocator<unsigned char> allocator; /*!< Allocator used for
|
|
|
|
allocating memory for the the "chunks"
|
|
|
|
member. */
|
|
|
|
volatile ulint n_chunks; /*!< number of buffer pool chunks */
|
|
|
|
volatile ulint n_chunks_new; /*!< new number of buffer pool chunks */
|
2014-02-26 19:11:54 +01:00
|
|
|
buf_chunk_t* chunks; /*!< buffer pool chunks */
|
2016-08-12 11:17:45 +03:00
|
|
|
buf_chunk_t* chunks_old; /*!< old buffer pool chunks to be freed
|
|
|
|
after resizing buffer pool */
|
2014-02-26 19:11:54 +01:00
|
|
|
ulint curr_size; /*!< current pool size in pages */
|
2016-08-12 11:17:45 +03:00
|
|
|
ulint old_size; /*!< previous pool size in pages */
|
|
|
|
ulint read_ahead_area;/*!< size in pages of the area which
|
|
|
|
the read-ahead algorithms read if
|
|
|
|
invoked */
|
2014-02-26 19:11:54 +01:00
|
|
|
hash_table_t* page_hash; /*!< hash table of buf_page_t or
|
|
|
|
buf_block_t file pages,
|
|
|
|
buf_page_in_file() == TRUE,
|
|
|
|
indexed by (space_id, offset).
|
|
|
|
page_hash is protected by an
|
|
|
|
array of mutexes.
|
|
|
|
Changes in page_hash are protected
|
|
|
|
by buf_pool->mutex and the relevant
|
|
|
|
page_hash mutex. Lookups can happen
|
|
|
|
while holding the buf_pool->mutex or
|
|
|
|
the relevant page_hash mutex. */
|
2016-08-12 11:17:45 +03:00
|
|
|
hash_table_t* page_hash_old; /*!< old pointer to page_hash to be
|
|
|
|
freed after resizing buffer pool */
|
2014-02-26 19:11:54 +01:00
|
|
|
hash_table_t* zip_hash; /*!< hash table of buf_block_t blocks
|
|
|
|
whose frames are allocated to the
|
|
|
|
zip buddy system,
|
|
|
|
indexed by block->frame */
|
|
|
|
ulint n_pend_reads; /*!< number of pending read
|
|
|
|
operations */
|
2018-12-28 23:51:15 +04:00
|
|
|
Atomic_counter<ulint>
|
|
|
|
n_pend_unzip; /*!< number of pending decompressions */
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
time_t last_printout_time;
|
|
|
|
/*!< when buf_print_io was last time
|
|
|
|
called */
|
|
|
|
buf_buddy_stat_t buddy_stat[BUF_BUDDY_SIZES_MAX + 1];
|
|
|
|
/*!< Statistics of buddy system,
|
|
|
|
indexed by block size */
|
|
|
|
buf_pool_stat_t stat; /*!< current statistics */
|
|
|
|
buf_pool_stat_t old_stat; /*!< old statistics */
|
|
|
|
|
|
|
|
/* @} */
|
|
|
|
|
|
|
|
/** @name Page flushing algorithm fields */
|
|
|
|
|
|
|
|
/* @{ */
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
FlushListMutex flush_list_mutex;/*!< mutex protecting the
|
2014-02-26 19:11:54 +01:00
|
|
|
flush list access. This mutex
|
|
|
|
protects flush_list, flush_rbt
|
|
|
|
and bpage::list pointers when
|
|
|
|
the bpage is on flush_list. It
|
|
|
|
also protects writes to
|
|
|
|
bpage::oldest_modification and
|
|
|
|
flush_list_hp */
|
2014-11-06 13:17:11 +02:00
|
|
|
FlushHp flush_hp;/*!< "hazard pointer"
|
2014-02-26 19:11:54 +01:00
|
|
|
used during scan of flush_list
|
|
|
|
while doing flush list batch.
|
|
|
|
Protected by flush_list_mutex */
|
|
|
|
UT_LIST_BASE_NODE_T(buf_page_t) flush_list;
|
|
|
|
/*!< base node of the modified block
|
|
|
|
list */
|
|
|
|
ibool init_flush[BUF_FLUSH_N_TYPES];
|
|
|
|
/*!< this is TRUE when a flush of the
|
|
|
|
given type is being initialized */
|
|
|
|
ulint n_flush[BUF_FLUSH_N_TYPES];
|
|
|
|
/*!< this is the number of pending
|
|
|
|
writes in the given flush type */
|
|
|
|
os_event_t no_flush[BUF_FLUSH_N_TYPES];
|
|
|
|
/*!< this is in the set state
|
|
|
|
when there is no flush batch
|
2017-02-17 10:32:21 +02:00
|
|
|
of the given type running;
|
|
|
|
os_event_set() and os_event_reset()
|
|
|
|
are protected by buf_pool_t::mutex */
|
2014-02-26 19:11:54 +01:00
|
|
|
ib_rbt_t* flush_rbt; /*!< a red-black tree is used
|
|
|
|
exclusively during recovery to
|
|
|
|
speed up insertions in the
|
|
|
|
flush_list. This tree contains
|
|
|
|
blocks in order of
|
|
|
|
oldest_modification LSN and is
|
|
|
|
kept in sync with the
|
|
|
|
flush_list.
|
|
|
|
Each member of the tree MUST
|
|
|
|
also be on the flush_list.
|
|
|
|
This tree is relevant only in
|
|
|
|
recovery and is set to NULL
|
|
|
|
once the recovery is over.
|
|
|
|
Protected by flush_list_mutex */
|
2017-03-01 08:27:39 +02:00
|
|
|
unsigned freed_page_clock;/*!< a sequence number used
|
2014-02-26 19:11:54 +01:00
|
|
|
to count the number of buffer
|
|
|
|
blocks removed from the end of
|
|
|
|
the LRU list; NOTE that this
|
|
|
|
counter may wrap around at 4
|
|
|
|
billion! A thread is allowed
|
|
|
|
to read this for heuristic
|
|
|
|
purposes without holding any
|
|
|
|
mutex or latch */
|
|
|
|
ibool try_LRU_scan; /*!< Set to FALSE when an LRU
|
|
|
|
scan for free block fails. This
|
|
|
|
flag is used to avoid repeated
|
|
|
|
scans of LRU list when we know
|
|
|
|
that there is no free block
|
|
|
|
available in the scan depth for
|
|
|
|
eviction. Set to TRUE whenever
|
|
|
|
we flush a batch from the
|
|
|
|
buffer pool. Protected by the
|
|
|
|
buf_pool->mutex */
|
|
|
|
/* @} */
|
|
|
|
|
|
|
|
/** @name LRU replacement algorithm fields */
|
|
|
|
/* @{ */
|
|
|
|
|
|
|
|
UT_LIST_BASE_NODE_T(buf_page_t) free;
|
|
|
|
/*!< base node of the free
|
|
|
|
block list */
|
2014-11-06 13:17:11 +02:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
UT_LIST_BASE_NODE_T(buf_page_t) withdraw;
|
|
|
|
/*!< base node of the withdraw
|
|
|
|
block list. It is only used during
|
|
|
|
shrinking buffer pool size, not to
|
|
|
|
reuse the blocks will be removed */
|
|
|
|
|
|
|
|
ulint withdraw_target;/*!< target length of withdraw
|
|
|
|
block list, when withdrawing */
|
|
|
|
|
2014-11-06 13:17:11 +02:00
|
|
|
/** "hazard pointer" used during scan of LRU while doing
|
|
|
|
LRU list batch. Protected by buf_pool::mutex */
|
|
|
|
LRUHp lru_hp;
|
|
|
|
|
|
|
|
/** Iterator used to scan the LRU list when searching for
|
|
|
|
replacable victim. Protected by buf_pool::mutex. */
|
|
|
|
LRUItr lru_scan_itr;
|
|
|
|
|
|
|
|
/** Iterator used to scan the LRU list when searching for
|
|
|
|
single page flushing victim. Protected by buf_pool::mutex. */
|
|
|
|
LRUItr single_scan_itr;
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
UT_LIST_BASE_NODE_T(buf_page_t) LRU;
|
|
|
|
/*!< base node of the LRU list */
|
2016-08-12 11:17:45 +03:00
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
buf_page_t* LRU_old; /*!< pointer to the about
|
|
|
|
LRU_old_ratio/BUF_LRU_OLD_RATIO_DIV
|
|
|
|
oldest blocks in the LRU list;
|
|
|
|
NULL if LRU length less than
|
|
|
|
BUF_LRU_OLD_MIN_LEN;
|
|
|
|
NOTE: when LRU_old != NULL, its length
|
|
|
|
should always equal LRU_old_len */
|
|
|
|
ulint LRU_old_len; /*!< length of the LRU list from
|
|
|
|
the block to which LRU_old points
|
|
|
|
onward, including that block;
|
|
|
|
see buf0lru.cc for the restrictions
|
|
|
|
on this value; 0 if LRU_old == NULL;
|
|
|
|
NOTE: LRU_old_len must be adjusted
|
|
|
|
whenever LRU_old shrinks or grows! */
|
|
|
|
|
|
|
|
UT_LIST_BASE_NODE_T(buf_block_t) unzip_LRU;
|
|
|
|
/*!< base node of the
|
|
|
|
unzip_LRU list */
|
|
|
|
|
|
|
|
/* @} */
|
|
|
|
/** @name Buddy allocator fields
|
|
|
|
The buddy allocator is used for allocating compressed page
|
|
|
|
frames and buf_page_t descriptors of blocks that exist
|
|
|
|
in the buffer pool only in compressed form. */
|
|
|
|
/* @{ */
|
|
|
|
#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
|
|
|
|
UT_LIST_BASE_NODE_T(buf_page_t) zip_clean;
|
|
|
|
/*!< unmodified compressed pages */
|
|
|
|
#endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */
|
|
|
|
UT_LIST_BASE_NODE_T(buf_buddy_free_t) zip_free[BUF_BUDDY_SIZES_MAX];
|
|
|
|
/*!< buddy free lists */
|
2019-03-21 12:05:04 +02:00
|
|
|
#if BUF_BUDDY_LOW > UNIV_ZIP_SIZE_MIN
|
|
|
|
# error "BUF_BUDDY_LOW > UNIV_ZIP_SIZE_MIN"
|
|
|
|
#endif
|
|
|
|
/* @} */
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
buf_page_t* watch;
|
|
|
|
/*!< Sentinel records for buffer
|
|
|
|
pool watches. Protected by
|
|
|
|
buf_pool->mutex. */
|
|
|
|
|
2019-03-21 12:05:04 +02:00
|
|
|
/** Temporary memory for page_compressed and encrypted I/O */
|
|
|
|
struct io_buf_t {
|
|
|
|
/** number of elements in slots[] */
|
|
|
|
const ulint n_slots;
|
|
|
|
/** array of slots */
|
|
|
|
buf_tmp_buffer_t* const slots;
|
|
|
|
|
|
|
|
io_buf_t() = delete;
|
|
|
|
|
|
|
|
/** Constructor */
|
|
|
|
explicit io_buf_t(ulint n_slots) :
|
|
|
|
n_slots(n_slots),
|
|
|
|
slots(static_cast<buf_tmp_buffer_t*>(
|
|
|
|
ut_malloc_nokey(n_slots
|
|
|
|
* sizeof *slots)))
|
|
|
|
{
|
|
|
|
memset((void*) slots, 0, n_slots * sizeof *slots);
|
|
|
|
}
|
2015-04-01 19:37:00 +03:00
|
|
|
|
MDEV-21132 Remove buf_page_t::newest_modification
At each mini-transaction commit, the log sequence number of the
mini-transaction must be written to each modified page, so that
it will be available in the FIL_PAGE_LSN field when the page is
being read in crash recovery.
InnoDB was unnecessarily allocating redundant storage for the
field, in buf_page_t::newest_modification. Let us access
FIL_PAGE_LSN directly.
Furthermore, on ALTER TABLE...IMPORT TABLESPACE, let us write
0 to FIL_PAGE_LSN instead of using log_sys.lsn.
buf_flush_init_for_writing(), buf_flush_update_zip_checksum(),
fil_encrypt_buf_for_full_crc32(), fil_encrypt_buf(),
fil_space_encrypt(): Remove the parameter lsn.
buf_page_get_newest_modification(): Merge with the only caller.
buf_tmp_reserve_compression_buf(), buf_tmp_page_encrypt(),
buf_page_encrypt(): Define static in the same compilation unit
with the only caller.
PageConverter::m_current_lsn: Remove. Write 0 to FIL_PAGE_LSN
on ALTER TABLE...IMPORT TABLESPACE.
2019-11-25 09:39:51 +02:00
|
|
|
~io_buf_t()
|
|
|
|
{
|
|
|
|
for (buf_tmp_buffer_t *s= slots, *e= slots + n_slots;
|
|
|
|
s != e; s++) {
|
|
|
|
aligned_free(s->crypt_buf);
|
|
|
|
aligned_free(s->comp_buf);
|
|
|
|
}
|
|
|
|
ut_free(slots);
|
|
|
|
}
|
2019-03-21 12:05:04 +02:00
|
|
|
|
|
|
|
/** Reserve a buffer */
|
|
|
|
buf_tmp_buffer_t* reserve()
|
|
|
|
{
|
|
|
|
for (buf_tmp_buffer_t* s = slots, *e = slots + n_slots;
|
|
|
|
s != e; s++) {
|
|
|
|
if (s->acquire()) return s;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
} io_buf;
|
2014-02-26 19:11:54 +01:00
|
|
|
};
|
|
|
|
|
2020-02-12 14:45:21 +02:00
|
|
|
/** @name Accessors for buffer pool mutexes
|
|
|
|
Use these instead of accessing buffer pool mutexes directly. */
|
2014-02-26 19:11:54 +01:00
|
|
|
/* @{ */
|
|
|
|
|
2014-05-05 18:20:28 +02:00
|
|
|
/** Test if block->mutex is owned. */
|
2016-08-12 11:17:45 +03:00
|
|
|
#define buf_page_mutex_own(b) (b)->mutex.is_owned()
|
2014-05-05 18:20:28 +02:00
|
|
|
|
|
|
|
/** Acquire the block->mutex. */
|
2016-08-12 11:17:45 +03:00
|
|
|
#define buf_page_mutex_enter(b) do { \
|
2014-05-05 18:20:28 +02:00
|
|
|
mutex_enter(&(b)->mutex); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/** Release the trx->mutex. */
|
2016-08-12 11:17:45 +03:00
|
|
|
#define buf_page_mutex_exit(b) do { \
|
|
|
|
(b)->mutex.exit(); \
|
2014-05-05 18:20:28 +02:00
|
|
|
} while (0)
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
|
|
|
|
/** Get appropriate page_hash_lock. */
|
2018-02-16 22:15:51 +03:00
|
|
|
UNIV_INLINE
|
|
|
|
rw_lock_t*
|
2020-02-12 14:45:21 +02:00
|
|
|
buf_page_hash_lock_get(const page_id_t& page_id)
|
2018-02-13 23:22:20 +03:00
|
|
|
{
|
|
|
|
return hash_get_lock(buf_pool->page_hash, page_id.fold());
|
|
|
|
}
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
/** If not appropriate page_hash_lock, relock until appropriate. */
|
2020-02-12 14:45:21 +02:00
|
|
|
# define buf_page_hash_lock_s_confirm(hash_lock, page_id)\
|
|
|
|
hash_lock_s_confirm(hash_lock, buf_pool->page_hash, (page_id).fold())
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2020-02-12 14:45:21 +02:00
|
|
|
# define buf_page_hash_lock_x_confirm(hash_lock, page_id)\
|
|
|
|
hash_lock_x_confirm(hash_lock, buf_pool->page_hash, (page_id).fold())
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
#ifdef UNIV_DEBUG
|
2014-02-26 19:11:54 +01:00
|
|
|
/** Test if page_hash lock is held in s-mode. */
|
2020-02-12 14:45:21 +02:00
|
|
|
# define buf_page_hash_lock_held_s(bpage) \
|
|
|
|
rw_lock_own(buf_page_hash_lock_get((bpage)->id), RW_LOCK_S)
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
/** Test if page_hash lock is held in x-mode. */
|
2020-02-12 14:45:21 +02:00
|
|
|
# define buf_page_hash_lock_held_x(bpage) \
|
|
|
|
rw_lock_own(buf_page_hash_lock_get((bpage)->id), RW_LOCK_X)
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
/** Test if page_hash lock is held in x or s-mode. */
|
2020-02-12 14:45:21 +02:00
|
|
|
# define buf_page_hash_lock_held_s_or_x(bpage)\
|
|
|
|
(buf_page_hash_lock_held_s(bpage) \
|
|
|
|
|| buf_page_hash_lock_held_x(bpage))
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2020-02-12 14:45:21 +02:00
|
|
|
# define buf_block_hash_lock_held_s(block) \
|
|
|
|
buf_page_hash_lock_held_s(&(block)->page)
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2020-02-12 14:45:21 +02:00
|
|
|
# define buf_block_hash_lock_held_x(block) \
|
|
|
|
buf_page_hash_lock_held_x(&(block)->page)
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2020-02-12 14:45:21 +02:00
|
|
|
# define buf_block_hash_lock_held_s_or_x(block) \
|
|
|
|
buf_page_hash_lock_held_s_or_x(&(block)->page)
|
2016-08-12 11:17:45 +03:00
|
|
|
#else /* UNIV_DEBUG */
|
2020-02-12 14:45:21 +02:00
|
|
|
# define buf_page_hash_lock_held_s(p) (TRUE)
|
|
|
|
# define buf_page_hash_lock_held_x(p) (TRUE)
|
|
|
|
# define buf_page_hash_lock_held_s_or_x(p) (TRUE)
|
|
|
|
# define buf_block_hash_lock_held_s(p) (TRUE)
|
|
|
|
# define buf_block_hash_lock_held_x(p) (TRUE)
|
|
|
|
# define buf_block_hash_lock_held_s_or_x(p) (TRUE)
|
2016-08-12 11:17:45 +03:00
|
|
|
#endif /* UNIV_DEBUG */
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
|
|
|
|
/** Forbid the release of the buffer pool mutex. */
|
2020-02-12 14:45:21 +02:00
|
|
|
# define buf_pool_mutex_exit_forbid() do { \
|
|
|
|
ut_ad(mutex_own(&buf_pool->mutex)); \
|
|
|
|
buf_pool->mutex_exit_forbidden++; \
|
2014-02-26 19:11:54 +01:00
|
|
|
} while (0)
|
|
|
|
/** Allow the release of the buffer pool mutex. */
|
2020-02-12 14:45:21 +02:00
|
|
|
# define buf_pool_mutex_exit_allow() do { \
|
|
|
|
ut_ad(mutex_own(&buf_pool->mutex)); \
|
|
|
|
ut_ad(buf_pool->mutex_exit_forbidden--); \
|
2014-02-26 19:11:54 +01:00
|
|
|
} while (0)
|
|
|
|
#else
|
|
|
|
/** Forbid the release of the buffer pool mutex. */
|
2020-02-12 14:45:21 +02:00
|
|
|
# define buf_pool_mutex_exit_forbid() ((void) 0)
|
2014-02-26 19:11:54 +01:00
|
|
|
/** Allow the release of the buffer pool mutex. */
|
2020-02-12 14:45:21 +02:00
|
|
|
# define buf_pool_mutex_exit_allow() ((void) 0)
|
2014-02-26 19:11:54 +01:00
|
|
|
#endif
|
|
|
|
/* @} */
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
Let us list the consistency conditions for different control block states.
|
|
|
|
|
|
|
|
NOT_USED: is in free list, not in LRU list, not in flush list, nor
|
|
|
|
page hash table
|
|
|
|
READY_FOR_USE: is not in free list, LRU list, or flush list, nor page
|
|
|
|
hash table
|
|
|
|
MEMORY: is not in free list, LRU list, or flush list, nor page
|
|
|
|
hash table
|
|
|
|
FILE_PAGE: space and offset are defined, is in page hash table
|
|
|
|
if io_fix == BUF_IO_WRITE,
|
|
|
|
pool: no_flush[flush_type] is in reset state,
|
|
|
|
pool: n_flush[flush_type] > 0
|
|
|
|
|
|
|
|
(1) if buf_fix_count == 0, then
|
|
|
|
is in LRU list, not in free list
|
|
|
|
is in flush list,
|
|
|
|
if and only if oldest_modification > 0
|
|
|
|
is x-locked,
|
|
|
|
if and only if io_fix == BUF_IO_READ
|
|
|
|
is s-locked,
|
|
|
|
if and only if io_fix == BUF_IO_WRITE
|
|
|
|
|
|
|
|
(2) if buf_fix_count > 0, then
|
|
|
|
is not in LRU list, not in free list
|
|
|
|
is in flush list,
|
|
|
|
if and only if oldest_modification > 0
|
|
|
|
if io_fix == BUF_IO_READ,
|
|
|
|
is x-locked
|
|
|
|
if io_fix == BUF_IO_WRITE,
|
|
|
|
is s-locked
|
|
|
|
|
|
|
|
State transitions:
|
|
|
|
|
|
|
|
NOT_USED => READY_FOR_USE
|
|
|
|
READY_FOR_USE => MEMORY
|
|
|
|
READY_FOR_USE => FILE_PAGE
|
|
|
|
MEMORY => NOT_USED
|
|
|
|
FILE_PAGE => NOT_USED NOTE: This transition is allowed if and only if
|
|
|
|
(1) buf_fix_count == 0,
|
|
|
|
(2) oldest_modification == 0, and
|
|
|
|
(3) io_fix == 0.
|
|
|
|
*/
|
|
|
|
|
2020-02-12 14:45:21 +02:00
|
|
|
/** Select from where to start a scan. If we have scanned
|
|
|
|
too deep into the LRU list it resets the value to the tail
|
|
|
|
of the LRU list.
|
|
|
|
@return buf_page_t from where to start scan. */
|
|
|
|
inline buf_page_t* LRUItr::start()
|
|
|
|
{
|
|
|
|
ut_ad(mutex_own(m_mutex));
|
|
|
|
|
|
|
|
if (!m_hp || m_hp->old) {
|
|
|
|
m_hp = UT_LIST_GET_LAST(buf_pool->LRU);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(m_hp);
|
|
|
|
}
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
|
|
|
|
/** Functor to validate the LRU list. */
|
|
|
|
struct CheckInLRUList {
|
|
|
|
void operator()(const buf_page_t* elem) const
|
|
|
|
{
|
|
|
|
ut_a(elem->in_LRU_list);
|
|
|
|
}
|
2016-08-12 11:17:45 +03:00
|
|
|
|
2020-02-12 14:45:21 +02:00
|
|
|
static void validate()
|
2016-08-12 11:17:45 +03:00
|
|
|
{
|
2019-04-29 14:33:46 +03:00
|
|
|
ut_list_validate(buf_pool->LRU, CheckInLRUList());
|
2016-08-12 11:17:45 +03:00
|
|
|
}
|
2014-02-26 19:11:54 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Functor to validate the LRU list. */
|
|
|
|
struct CheckInFreeList {
|
|
|
|
void operator()(const buf_page_t* elem) const
|
|
|
|
{
|
|
|
|
ut_a(elem->in_free_list);
|
|
|
|
}
|
2016-08-12 11:17:45 +03:00
|
|
|
|
2020-02-12 14:45:21 +02:00
|
|
|
static void validate()
|
2016-08-12 11:17:45 +03:00
|
|
|
{
|
2019-04-29 14:33:46 +03:00
|
|
|
ut_list_validate(buf_pool->free, CheckInFreeList());
|
2016-08-12 11:17:45 +03:00
|
|
|
}
|
2014-02-26 19:11:54 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct CheckUnzipLRUAndLRUList {
|
|
|
|
void operator()(const buf_block_t* elem) const
|
|
|
|
{
|
|
|
|
ut_a(elem->page.in_LRU_list);
|
|
|
|
ut_a(elem->in_unzip_LRU_list);
|
|
|
|
}
|
2016-08-12 11:17:45 +03:00
|
|
|
|
2020-02-12 14:45:21 +02:00
|
|
|
static void validate()
|
2016-08-12 11:17:45 +03:00
|
|
|
{
|
2019-04-29 14:33:46 +03:00
|
|
|
ut_list_validate(buf_pool->unzip_LRU,
|
|
|
|
CheckUnzipLRUAndLRUList());
|
2016-08-12 11:17:45 +03:00
|
|
|
}
|
2014-02-26 19:11:54 +01:00
|
|
|
};
|
|
|
|
#endif /* UNIV_DEBUG || defined UNIV_BUF_DEBUG */
|
|
|
|
|
|
|
|
#include "buf0buf.ic"
|
2016-04-22 10:50:45 +02:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
#endif /* !UNIV_INNOCHECKSUM */
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
#endif
|