2014-02-26 19:11:54 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
|
2017-05-15 16:17:16 +02:00
|
|
|
Copyright (c) 1995, 2017, Oracle and/or its affiliates. All Rights Reserved.
|
2018-12-17 18:00:35 +01:00
|
|
|
Copyright (c) 2013, 2018, 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.,
|
|
|
|
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
|
|
|
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
/**************************************************//**
|
|
|
|
@file buf/buf0dblwr.cc
|
|
|
|
Doublwrite buffer module
|
|
|
|
|
|
|
|
Created 2011/12/19
|
|
|
|
*******************************************************/
|
|
|
|
|
|
|
|
#include "buf0dblwr.h"
|
|
|
|
#include "buf0buf.h"
|
|
|
|
#include "buf0checksum.h"
|
|
|
|
#include "srv0start.h"
|
|
|
|
#include "srv0srv.h"
|
|
|
|
#include "page0zip.h"
|
|
|
|
#include "trx0sys.h"
|
2015-04-01 10:50:21 +02:00
|
|
|
#include "fil0crypt.h"
|
2016-04-29 11:32:35 +02:00
|
|
|
#include "fil0pagecompress.h"
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
/** The doublewrite buffer */
|
2016-08-12 10:17:45 +02:00
|
|
|
buf_dblwr_t* buf_dblwr = NULL;
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
/** Set to TRUE when the doublewrite buffer is being created */
|
2016-08-12 10:17:45 +02:00
|
|
|
ibool buf_dblwr_being_created = FALSE;
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2014-12-22 15:53:17 +01:00
|
|
|
#define TRX_SYS_DOUBLEWRITE_BLOCKS 2
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
/****************************************************************//**
|
|
|
|
Determines if a page number is located inside the doublewrite buffer.
|
|
|
|
@return TRUE if the location is inside the two blocks of the
|
|
|
|
doublewrite buffer */
|
|
|
|
ibool
|
|
|
|
buf_dblwr_page_inside(
|
|
|
|
/*==================*/
|
|
|
|
ulint page_no) /*!< in: page number */
|
|
|
|
{
|
|
|
|
if (buf_dblwr == NULL) {
|
|
|
|
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (page_no >= buf_dblwr->block1
|
|
|
|
&& page_no < buf_dblwr->block1
|
|
|
|
+ TRX_SYS_DOUBLEWRITE_BLOCK_SIZE) {
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (page_no >= buf_dblwr->block2
|
|
|
|
&& page_no < buf_dblwr->block2
|
|
|
|
+ TRX_SYS_DOUBLEWRITE_BLOCK_SIZE) {
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************//**
|
|
|
|
Calls buf_page_get() on the TRX_SYS_PAGE and returns a pointer to the
|
|
|
|
doublewrite buffer within it.
|
2016-08-12 10:17:45 +02:00
|
|
|
@return pointer to the doublewrite buffer within the filespace header
|
2014-02-26 19:11:54 +01:00
|
|
|
page. */
|
|
|
|
UNIV_INLINE
|
|
|
|
byte*
|
|
|
|
buf_dblwr_get(
|
|
|
|
/*==========*/
|
|
|
|
mtr_t* mtr) /*!< in/out: MTR to hold the page latch */
|
|
|
|
{
|
|
|
|
buf_block_t* block;
|
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
block = buf_page_get(page_id_t(TRX_SYS_SPACE, TRX_SYS_PAGE_NO),
|
|
|
|
univ_page_size, RW_X_LATCH, mtr);
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
buf_block_dbg_add_level(block, SYNC_NO_ORDER_CHECK);
|
|
|
|
|
|
|
|
return(buf_block_get_frame(block) + TRX_SYS_DOUBLEWRITE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************//**
|
|
|
|
Flush a batch of writes to the datafiles that have already been
|
|
|
|
written to the dblwr buffer on disk. */
|
|
|
|
void
|
|
|
|
buf_dblwr_sync_datafiles()
|
|
|
|
/*======================*/
|
|
|
|
{
|
|
|
|
/* Wake possible simulated aio thread to actually post the
|
|
|
|
writes to the operating system */
|
|
|
|
os_aio_simulated_wake_handler_threads();
|
|
|
|
|
|
|
|
/* Wait that all async writes to tablespaces have been posted to
|
|
|
|
the OS */
|
|
|
|
os_aio_wait_until_no_pending_writes();
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************//**
|
|
|
|
Creates or initialializes the doublewrite buffer at a database start. */
|
|
|
|
static
|
|
|
|
void
|
|
|
|
buf_dblwr_init(
|
|
|
|
/*===========*/
|
|
|
|
byte* doublewrite) /*!< in: pointer to the doublewrite buf
|
|
|
|
header on trx sys page */
|
|
|
|
{
|
|
|
|
ulint buf_size;
|
|
|
|
|
|
|
|
buf_dblwr = static_cast<buf_dblwr_t*>(
|
2016-08-12 10:17:45 +02:00
|
|
|
ut_zalloc_nokey(sizeof(buf_dblwr_t)));
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
/* There are two blocks of same size in the doublewrite
|
|
|
|
buffer. */
|
2014-12-22 15:53:17 +01:00
|
|
|
buf_size = TRX_SYS_DOUBLEWRITE_BLOCKS * TRX_SYS_DOUBLEWRITE_BLOCK_SIZE;
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
/* There must be atleast one buffer for single page writes
|
|
|
|
and one buffer for batch writes. */
|
|
|
|
ut_a(srv_doublewrite_batch_size > 0
|
|
|
|
&& srv_doublewrite_batch_size < buf_size);
|
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
mutex_create(LATCH_ID_BUF_DBLWR, &buf_dblwr->mutex);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
buf_dblwr->b_event = os_event_create("dblwr_batch_event");
|
|
|
|
buf_dblwr->s_event = os_event_create("dblwr_single_event");
|
2014-02-26 19:11:54 +01:00
|
|
|
buf_dblwr->first_free = 0;
|
|
|
|
buf_dblwr->s_reserved = 0;
|
|
|
|
buf_dblwr->b_reserved = 0;
|
|
|
|
|
|
|
|
buf_dblwr->block1 = mach_read_from_4(
|
|
|
|
doublewrite + TRX_SYS_DOUBLEWRITE_BLOCK1);
|
|
|
|
buf_dblwr->block2 = mach_read_from_4(
|
|
|
|
doublewrite + TRX_SYS_DOUBLEWRITE_BLOCK2);
|
|
|
|
|
|
|
|
buf_dblwr->in_use = static_cast<bool*>(
|
2016-08-12 10:17:45 +02:00
|
|
|
ut_zalloc_nokey(buf_size * sizeof(bool)));
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
buf_dblwr->write_buf_unaligned = static_cast<byte*>(
|
2018-04-27 13:26:43 +02:00
|
|
|
ut_malloc_nokey((1 + buf_size) << srv_page_size_shift));
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
buf_dblwr->write_buf = static_cast<byte*>(
|
|
|
|
ut_align(buf_dblwr->write_buf_unaligned,
|
2018-04-27 12:49:25 +02:00
|
|
|
srv_page_size));
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
buf_dblwr->buf_block_arr = static_cast<buf_page_t**>(
|
2016-08-12 10:17:45 +02:00
|
|
|
ut_zalloc_nokey(buf_size * sizeof(void*)));
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
2017-06-06 13:59:42 +02:00
|
|
|
/** Create the doublewrite buffer if the doublewrite buffer header
|
|
|
|
is not present in the TRX_SYS page.
|
|
|
|
@return whether the operation succeeded
|
|
|
|
@retval true if the doublewrite buffer exists or was created
|
|
|
|
@retval false if the creation failed (too small first data file) */
|
2016-08-12 10:17:45 +02:00
|
|
|
bool
|
2017-04-25 14:39:06 +02:00
|
|
|
buf_dblwr_create()
|
2014-02-26 19:11:54 +01:00
|
|
|
{
|
|
|
|
buf_block_t* block2;
|
|
|
|
buf_block_t* new_block;
|
|
|
|
byte* doublewrite;
|
|
|
|
byte* fseg_header;
|
|
|
|
ulint page_no;
|
|
|
|
ulint prev_page_no;
|
|
|
|
ulint i;
|
|
|
|
mtr_t mtr;
|
|
|
|
|
|
|
|
if (buf_dblwr) {
|
|
|
|
/* Already inited */
|
2016-08-12 10:17:45 +02:00
|
|
|
return(true);
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
start_again:
|
2017-06-08 11:45:08 +02:00
|
|
|
mtr.start();
|
2014-02-26 19:11:54 +01:00
|
|
|
buf_dblwr_being_created = TRUE;
|
|
|
|
|
|
|
|
doublewrite = buf_dblwr_get(&mtr);
|
|
|
|
|
|
|
|
if (mach_read_from_4(doublewrite + TRX_SYS_DOUBLEWRITE_MAGIC)
|
|
|
|
== TRX_SYS_DOUBLEWRITE_MAGIC_N) {
|
|
|
|
/* The doublewrite buffer has already been created:
|
|
|
|
just read in some numbers */
|
|
|
|
|
|
|
|
buf_dblwr_init(doublewrite);
|
|
|
|
|
2017-06-08 11:45:08 +02:00
|
|
|
mtr.commit();
|
2014-02-26 19:11:54 +01:00
|
|
|
buf_dblwr_being_created = FALSE;
|
2016-08-12 10:17:45 +02:00
|
|
|
return(true);
|
2017-06-06 13:59:42 +02:00
|
|
|
} else {
|
MDEV-12266: Change dict_table_t::space to fil_space_t*
InnoDB always keeps all tablespaces in the fil_system cache.
The fil_system.LRU is only for closing file handles; the
fil_space_t and fil_node_t for all data files will remain
in main memory. Between startup to shutdown, they can only be
created and removed by DDL statements. Therefore, we can
let dict_table_t::space point directly to the fil_space_t.
dict_table_t::space_id: A numeric tablespace ID for the corner cases
where we do not have a tablespace. The most prominent examples are
ALTER TABLE...DISCARD TABLESPACE or a missing or corrupted file.
There are a few functional differences; most notably:
(1) DROP TABLE will delete matching .ibd and .cfg files,
even if they were not attached to the data dictionary.
(2) Some error messages will report file names instead of numeric IDs.
There still are many functions that use numeric tablespace IDs instead
of fil_space_t*, and many functions could be converted to fil_space_t
member functions. Also, Tablespace and Datafile should be merged with
fil_space_t and fil_node_t. page_id_t and buf_page_get_gen() could use
fil_space_t& instead of a numeric ID, and after moving to a single
buffer pool (MDEV-15058), buf_pool_t::page_hash could be moved to
fil_space_t::page_hash.
FilSpace: Remove. Only few calls to fil_space_acquire() will remain,
and gradually they should be removed.
mtr_t::set_named_space_id(ulint): Renamed from set_named_space(),
to prevent accidental calls to this slower function. Very few
callers remain.
fseg_create(), fsp_reserve_free_extents(): Take fil_space_t*
as a parameter instead of a space_id.
fil_space_t::rename(): Wrapper for fil_rename_tablespace_check(),
fil_name_write_rename(), fil_rename_tablespace(). Mariabackup
passes the parameter log=false; InnoDB passes log=true.
dict_mem_table_create(): Take fil_space_t* instead of space_id
as parameter.
dict_process_sys_tables_rec_and_mtr_commit(): Replace the parameter
'status' with 'bool cached'.
dict_get_and_save_data_dir_path(): Avoid copying the fil_node_t::name.
fil_ibd_open(): Return the tablespace.
fil_space_t::set_imported(): Replaces fil_space_set_imported().
truncate_t: Change many member function parameters to fil_space_t*,
and remove page_size parameters.
row_truncate_prepare(): Merge to its only caller.
row_drop_table_from_cache(): Assert that the table is persistent.
dict_create_sys_indexes_tuple(): Write SYS_INDEXES.SPACE=FIL_NULL
if the tablespace has been discarded.
row_import_update_discarded_flag(): Remove a constant parameter.
2018-03-27 15:31:10 +02:00
|
|
|
if (UT_LIST_GET_FIRST(fil_system.sys_space->chain)->size
|
|
|
|
< 3 * FSP_EXTENT_SIZE) {
|
2017-06-06 13:59:42 +02:00
|
|
|
goto too_small;
|
|
|
|
}
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
MDEV-12266: Change dict_table_t::space to fil_space_t*
InnoDB always keeps all tablespaces in the fil_system cache.
The fil_system.LRU is only for closing file handles; the
fil_space_t and fil_node_t for all data files will remain
in main memory. Between startup to shutdown, they can only be
created and removed by DDL statements. Therefore, we can
let dict_table_t::space point directly to the fil_space_t.
dict_table_t::space_id: A numeric tablespace ID for the corner cases
where we do not have a tablespace. The most prominent examples are
ALTER TABLE...DISCARD TABLESPACE or a missing or corrupted file.
There are a few functional differences; most notably:
(1) DROP TABLE will delete matching .ibd and .cfg files,
even if they were not attached to the data dictionary.
(2) Some error messages will report file names instead of numeric IDs.
There still are many functions that use numeric tablespace IDs instead
of fil_space_t*, and many functions could be converted to fil_space_t
member functions. Also, Tablespace and Datafile should be merged with
fil_space_t and fil_node_t. page_id_t and buf_page_get_gen() could use
fil_space_t& instead of a numeric ID, and after moving to a single
buffer pool (MDEV-15058), buf_pool_t::page_hash could be moved to
fil_space_t::page_hash.
FilSpace: Remove. Only few calls to fil_space_acquire() will remain,
and gradually they should be removed.
mtr_t::set_named_space_id(ulint): Renamed from set_named_space(),
to prevent accidental calls to this slower function. Very few
callers remain.
fseg_create(), fsp_reserve_free_extents(): Take fil_space_t*
as a parameter instead of a space_id.
fil_space_t::rename(): Wrapper for fil_rename_tablespace_check(),
fil_name_write_rename(), fil_rename_tablespace(). Mariabackup
passes the parameter log=false; InnoDB passes log=true.
dict_mem_table_create(): Take fil_space_t* instead of space_id
as parameter.
dict_process_sys_tables_rec_and_mtr_commit(): Replace the parameter
'status' with 'bool cached'.
dict_get_and_save_data_dir_path(): Avoid copying the fil_node_t::name.
fil_ibd_open(): Return the tablespace.
fil_space_t::set_imported(): Replaces fil_space_set_imported().
truncate_t: Change many member function parameters to fil_space_t*,
and remove page_size parameters.
row_truncate_prepare(): Merge to its only caller.
row_drop_table_from_cache(): Assert that the table is persistent.
dict_create_sys_indexes_tuple(): Write SYS_INDEXES.SPACE=FIL_NULL
if the tablespace has been discarded.
row_import_update_discarded_flag(): Remove a constant parameter.
2018-03-27 15:31:10 +02:00
|
|
|
block2 = fseg_create(fil_system.sys_space, TRX_SYS_PAGE_NO,
|
2014-02-26 19:11:54 +01:00
|
|
|
TRX_SYS_DOUBLEWRITE
|
|
|
|
+ TRX_SYS_DOUBLEWRITE_FSEG, &mtr);
|
|
|
|
|
|
|
|
if (block2 == NULL) {
|
2017-06-06 13:59:42 +02:00
|
|
|
too_small:
|
2017-06-08 11:45:08 +02:00
|
|
|
ib::error()
|
|
|
|
<< "Cannot create doublewrite buffer: "
|
2017-06-06 13:59:42 +02:00
|
|
|
"the first file in innodb_data_file_path"
|
2017-06-08 11:45:08 +02:00
|
|
|
" must be at least "
|
2018-04-27 13:26:43 +02:00
|
|
|
<< (3 * (FSP_EXTENT_SIZE
|
|
|
|
>> (20U - srv_page_size_shift)))
|
2017-06-08 11:45:08 +02:00
|
|
|
<< "M.";
|
2017-04-05 15:24:44 +02:00
|
|
|
mtr.commit();
|
2016-08-12 10:17:45 +02:00
|
|
|
return(false);
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
2017-06-08 11:45:08 +02:00
|
|
|
ib::info() << "Doublewrite buffer not found: creating new";
|
2017-06-06 13:59:42 +02:00
|
|
|
|
|
|
|
/* FIXME: After this point, the doublewrite buffer creation
|
|
|
|
is not atomic. The doublewrite buffer should not exist in
|
|
|
|
the InnoDB system tablespace file in the first place.
|
|
|
|
It could be located in separate optional file(s) in a
|
|
|
|
user-specified location. */
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
/* fseg_create acquires a second latch on the page,
|
|
|
|
therefore we must declare it: */
|
|
|
|
|
|
|
|
buf_block_dbg_add_level(block2, SYNC_NO_ORDER_CHECK);
|
|
|
|
|
|
|
|
fseg_header = doublewrite + TRX_SYS_DOUBLEWRITE_FSEG;
|
|
|
|
prev_page_no = 0;
|
|
|
|
|
2014-12-22 15:53:17 +01:00
|
|
|
for (i = 0; i < TRX_SYS_DOUBLEWRITE_BLOCKS * TRX_SYS_DOUBLEWRITE_BLOCK_SIZE
|
2014-02-26 19:11:54 +01:00
|
|
|
+ FSP_EXTENT_SIZE / 2; i++) {
|
|
|
|
new_block = fseg_alloc_free_page(
|
|
|
|
fseg_header, prev_page_no + 1, FSP_UP, &mtr);
|
|
|
|
if (new_block == NULL) {
|
2016-08-12 10:17:45 +02:00
|
|
|
ib::error() << "Cannot create doublewrite buffer: "
|
|
|
|
" you must increase your tablespace size."
|
|
|
|
" Cannot continue operation.";
|
2017-04-05 15:24:44 +02:00
|
|
|
/* This may essentially corrupt the doublewrite
|
|
|
|
buffer. However, usually the doublewrite buffer
|
|
|
|
is created at database initialization, and it
|
|
|
|
should not matter (just remove all newly created
|
|
|
|
InnoDB files and restart). */
|
|
|
|
mtr.commit();
|
2016-08-12 10:17:45 +02:00
|
|
|
return(false);
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* We read the allocated pages to the buffer pool;
|
|
|
|
when they are written to disk in a flush, the space
|
|
|
|
id and page number fields are also written to the
|
|
|
|
pages. When we at database startup read pages
|
|
|
|
from the doublewrite buffer, we know that if the
|
|
|
|
space id and page number in them are the same as
|
|
|
|
the page position in the tablespace, then the page
|
|
|
|
has not been written to in doublewrite. */
|
|
|
|
|
|
|
|
ut_ad(rw_lock_get_x_lock_count(&new_block->lock) == 1);
|
2016-08-12 10:17:45 +02:00
|
|
|
page_no = new_block->page.id.page_no();
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
if (i == FSP_EXTENT_SIZE / 2) {
|
|
|
|
ut_a(page_no == FSP_EXTENT_SIZE);
|
|
|
|
mlog_write_ulint(doublewrite
|
|
|
|
+ TRX_SYS_DOUBLEWRITE_BLOCK1,
|
|
|
|
page_no, MLOG_4BYTES, &mtr);
|
|
|
|
mlog_write_ulint(doublewrite
|
|
|
|
+ TRX_SYS_DOUBLEWRITE_REPEAT
|
|
|
|
+ TRX_SYS_DOUBLEWRITE_BLOCK1,
|
|
|
|
page_no, MLOG_4BYTES, &mtr);
|
|
|
|
|
|
|
|
} else if (i == FSP_EXTENT_SIZE / 2
|
|
|
|
+ TRX_SYS_DOUBLEWRITE_BLOCK_SIZE) {
|
|
|
|
ut_a(page_no == 2 * FSP_EXTENT_SIZE);
|
|
|
|
mlog_write_ulint(doublewrite
|
|
|
|
+ TRX_SYS_DOUBLEWRITE_BLOCK2,
|
|
|
|
page_no, MLOG_4BYTES, &mtr);
|
|
|
|
mlog_write_ulint(doublewrite
|
|
|
|
+ TRX_SYS_DOUBLEWRITE_REPEAT
|
|
|
|
+ TRX_SYS_DOUBLEWRITE_BLOCK2,
|
|
|
|
page_no, MLOG_4BYTES, &mtr);
|
|
|
|
|
|
|
|
} else if (i > FSP_EXTENT_SIZE / 2) {
|
|
|
|
ut_a(page_no == prev_page_no + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (((i + 1) & 15) == 0) {
|
|
|
|
/* rw_locks can only be recursively x-locked
|
|
|
|
2048 times. (on 32 bit platforms,
|
|
|
|
(lint) 0 - (X_LOCK_DECR * 2049)
|
|
|
|
is no longer a negative number, and thus
|
|
|
|
lock_word becomes like a shared lock).
|
|
|
|
For 4k page size this loop will
|
|
|
|
lock the fseg header too many times. Since
|
|
|
|
this code is not done while any other threads
|
|
|
|
are active, restart the MTR occasionally. */
|
|
|
|
mtr_commit(&mtr);
|
|
|
|
mtr_start(&mtr);
|
|
|
|
doublewrite = buf_dblwr_get(&mtr);
|
|
|
|
fseg_header = doublewrite
|
|
|
|
+ TRX_SYS_DOUBLEWRITE_FSEG;
|
|
|
|
}
|
|
|
|
|
|
|
|
prev_page_no = page_no;
|
|
|
|
}
|
|
|
|
|
|
|
|
mlog_write_ulint(doublewrite + TRX_SYS_DOUBLEWRITE_MAGIC,
|
|
|
|
TRX_SYS_DOUBLEWRITE_MAGIC_N,
|
|
|
|
MLOG_4BYTES, &mtr);
|
|
|
|
mlog_write_ulint(doublewrite + TRX_SYS_DOUBLEWRITE_MAGIC
|
|
|
|
+ TRX_SYS_DOUBLEWRITE_REPEAT,
|
|
|
|
TRX_SYS_DOUBLEWRITE_MAGIC_N,
|
|
|
|
MLOG_4BYTES, &mtr);
|
|
|
|
|
|
|
|
mlog_write_ulint(doublewrite
|
|
|
|
+ TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED,
|
|
|
|
TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED_N,
|
|
|
|
MLOG_4BYTES, &mtr);
|
|
|
|
mtr_commit(&mtr);
|
|
|
|
|
|
|
|
/* Flush the modified pages to disk and make a checkpoint */
|
|
|
|
log_make_checkpoint_at(LSN_MAX, TRUE);
|
|
|
|
|
|
|
|
/* Remove doublewrite pages from LRU */
|
|
|
|
buf_pool_invalidate();
|
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
ib::info() << "Doublewrite buffer created";
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
goto start_again;
|
|
|
|
}
|
|
|
|
|
2018-12-17 18:00:35 +01:00
|
|
|
/** Check if a page is all zeroes.
|
|
|
|
@param[in] read_buf database page
|
2018-12-17 19:04:03 +01:00
|
|
|
@param[in] page_size page frame size
|
2018-12-17 18:00:35 +01:00
|
|
|
@return whether the page is all zeroes */
|
2018-12-17 19:04:03 +01:00
|
|
|
static bool buf_page_is_zeroes(const byte* read_buf, size_t page_size)
|
2018-12-17 18:00:35 +01:00
|
|
|
{
|
|
|
|
for (ulint i = 0; i < page_size; i++) {
|
|
|
|
if (read_buf[i] != 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
/**
|
|
|
|
At database startup initializes the doublewrite buffer memory structure if
|
2014-02-26 19:11:54 +01:00
|
|
|
we already have a doublewrite buffer created in the data files. If we are
|
|
|
|
upgrading to an InnoDB version which supports multiple tablespaces, then this
|
|
|
|
function performs the necessary update operations. If we are in a crash
|
2016-08-12 10:17:45 +02:00
|
|
|
recovery, this function loads the pages from double write buffer into memory.
|
|
|
|
@param[in] file File handle
|
|
|
|
@param[in] path Path name of file
|
|
|
|
@return DB_SUCCESS or error code */
|
|
|
|
dberr_t
|
2014-05-05 18:20:28 +02:00
|
|
|
buf_dblwr_init_or_load_pages(
|
2017-05-15 16:17:16 +02:00
|
|
|
pfs_os_file_t file,
|
2016-08-12 10:17:45 +02:00
|
|
|
const char* path)
|
2014-02-26 19:11:54 +01:00
|
|
|
{
|
2016-08-12 10:17:45 +02:00
|
|
|
byte* buf;
|
|
|
|
byte* page;
|
|
|
|
ulint block1;
|
|
|
|
ulint block2;
|
|
|
|
ulint space_id;
|
|
|
|
byte* read_buf;
|
|
|
|
byte* doublewrite;
|
|
|
|
byte* unaligned_read_buf;
|
|
|
|
ibool reset_space_ids = FALSE;
|
|
|
|
recv_dblwr_t& recv_dblwr = recv_sys->dblwr;
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
/* We do the file i/o past the buffer pool */
|
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
unaligned_read_buf = static_cast<byte*>(
|
2018-04-27 13:26:43 +02:00
|
|
|
ut_malloc_nokey(3U << srv_page_size_shift));
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
read_buf = static_cast<byte*>(
|
2018-04-27 12:49:25 +02:00
|
|
|
ut_align(unaligned_read_buf, srv_page_size));
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
/* Read the trx sys header to check if we are using the doublewrite
|
|
|
|
buffer */
|
2016-08-12 10:17:45 +02:00
|
|
|
dberr_t err;
|
|
|
|
|
|
|
|
IORequest read_request(IORequest::READ);
|
|
|
|
|
|
|
|
err = os_file_read(
|
|
|
|
read_request,
|
2018-04-27 13:26:43 +02:00
|
|
|
file, read_buf, TRX_SYS_PAGE_NO << srv_page_size_shift,
|
2018-04-27 12:49:25 +02:00
|
|
|
srv_page_size);
|
2016-08-12 10:17:45 +02:00
|
|
|
|
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
|
|
|
|
ib::error()
|
|
|
|
<< "Failed to read the system tablespace header page";
|
|
|
|
|
|
|
|
ut_free(unaligned_read_buf);
|
|
|
|
|
|
|
|
return(err);
|
|
|
|
}
|
2014-03-03 13:27:56 +01:00
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
doublewrite = read_buf + TRX_SYS_DOUBLEWRITE;
|
|
|
|
|
2017-02-10 15:05:37 +01:00
|
|
|
/* TRX_SYS_PAGE_NO is not encrypted see fil_crypt_rotate_page() */
|
2014-12-22 15:53:17 +01:00
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
if (mach_read_from_4(doublewrite + TRX_SYS_DOUBLEWRITE_MAGIC)
|
|
|
|
== TRX_SYS_DOUBLEWRITE_MAGIC_N) {
|
|
|
|
/* The doublewrite buffer has been created */
|
|
|
|
|
|
|
|
buf_dblwr_init(doublewrite);
|
|
|
|
|
|
|
|
block1 = buf_dblwr->block1;
|
|
|
|
block2 = buf_dblwr->block2;
|
|
|
|
|
|
|
|
buf = buf_dblwr->write_buf;
|
|
|
|
} else {
|
2016-08-12 10:17:45 +02:00
|
|
|
ut_free(unaligned_read_buf);
|
|
|
|
return(DB_SUCCESS);
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mach_read_from_4(doublewrite + TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED)
|
|
|
|
!= TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED_N) {
|
|
|
|
|
|
|
|
/* We are upgrading from a version < 4.1.x to a version where
|
|
|
|
multiple tablespaces are supported. We must reset the space id
|
|
|
|
field in the pages in the doublewrite buffer because starting
|
|
|
|
from this version the space id is stored to
|
|
|
|
FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID. */
|
|
|
|
|
|
|
|
reset_space_ids = TRUE;
|
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
ib::info() << "Resetting space id's in the doublewrite buffer";
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Read the pages from the doublewrite buffer to memory */
|
2016-08-12 10:17:45 +02:00
|
|
|
err = os_file_read(
|
|
|
|
read_request,
|
2018-04-27 13:26:43 +02:00
|
|
|
file, buf, block1 << srv_page_size_shift,
|
|
|
|
TRX_SYS_DOUBLEWRITE_BLOCK_SIZE << srv_page_size_shift);
|
2016-08-12 10:17:45 +02:00
|
|
|
|
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
|
|
|
|
ib::error()
|
|
|
|
<< "Failed to read the first double write buffer "
|
|
|
|
"extent";
|
|
|
|
|
|
|
|
ut_free(unaligned_read_buf);
|
|
|
|
|
|
|
|
return(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
err = os_file_read(
|
|
|
|
read_request,
|
|
|
|
file,
|
2018-04-27 13:26:43 +02:00
|
|
|
buf + (TRX_SYS_DOUBLEWRITE_BLOCK_SIZE << srv_page_size_shift),
|
|
|
|
block2 << srv_page_size_shift,
|
|
|
|
TRX_SYS_DOUBLEWRITE_BLOCK_SIZE << srv_page_size_shift);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
if (err != DB_SUCCESS) {
|
2014-05-06 21:13:16 +02:00
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
ib::error()
|
|
|
|
<< "Failed to read the second double write buffer "
|
|
|
|
"extent";
|
|
|
|
|
|
|
|
ut_free(unaligned_read_buf);
|
|
|
|
|
|
|
|
return(err);
|
|
|
|
}
|
2014-03-03 13:27:56 +01:00
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
/* Check if any of these pages is half-written in data files, in the
|
|
|
|
intended position */
|
|
|
|
|
|
|
|
page = buf;
|
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
for (ulint i = 0; i < TRX_SYS_DOUBLEWRITE_BLOCK_SIZE * 2; i++) {
|
2014-02-26 19:11:54 +01:00
|
|
|
if (reset_space_ids) {
|
2016-08-12 10:17:45 +02:00
|
|
|
ulint source_page_no;
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
space_id = 0;
|
2016-08-12 10:17:45 +02:00
|
|
|
mach_write_to_4(page + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID,
|
|
|
|
space_id);
|
2014-02-26 19:11:54 +01:00
|
|
|
/* We do not need to calculate new checksums for the
|
|
|
|
pages because the field .._SPACE_ID does not affect
|
|
|
|
them. Write the page back to where we read it from. */
|
|
|
|
|
|
|
|
if (i < TRX_SYS_DOUBLEWRITE_BLOCK_SIZE) {
|
|
|
|
source_page_no = block1 + i;
|
|
|
|
} else {
|
|
|
|
source_page_no = block2
|
|
|
|
+ i - TRX_SYS_DOUBLEWRITE_BLOCK_SIZE;
|
|
|
|
}
|
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
IORequest write_request(IORequest::WRITE);
|
|
|
|
|
|
|
|
err = os_file_write(
|
|
|
|
write_request, path, file, page,
|
2018-04-27 13:26:43 +02:00
|
|
|
source_page_no << srv_page_size_shift,
|
2018-04-27 12:49:25 +02:00
|
|
|
srv_page_size);
|
2016-08-12 10:17:45 +02:00
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
|
|
|
|
ib::error()
|
|
|
|
<< "Failed to write to the double write"
|
|
|
|
" buffer";
|
|
|
|
|
|
|
|
ut_free(unaligned_read_buf);
|
|
|
|
|
|
|
|
return(err);
|
|
|
|
}
|
|
|
|
|
2017-01-19 11:06:13 +01:00
|
|
|
} else if (memcmp(field_ref_zero, page + FIL_PAGE_LSN, 8)) {
|
|
|
|
/* Each valid page header must contain
|
|
|
|
a nonzero FIL_PAGE_LSN field. */
|
2014-05-05 18:20:28 +02:00
|
|
|
recv_dblwr.add(page);
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
2018-04-27 12:49:25 +02:00
|
|
|
page += srv_page_size;
|
2014-05-05 18:20:28 +02:00
|
|
|
}
|
|
|
|
|
2014-05-06 21:13:16 +02:00
|
|
|
if (reset_space_ids) {
|
|
|
|
os_file_flush(file);
|
|
|
|
}
|
2014-05-05 18:20:28 +02:00
|
|
|
|
|
|
|
ut_free(unaligned_read_buf);
|
2016-08-12 10:17:45 +02:00
|
|
|
|
|
|
|
return(DB_SUCCESS);
|
2014-05-05 18:20:28 +02:00
|
|
|
}
|
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
/** Process and remove the double write buffer pages for all tablespaces. */
|
2014-05-05 18:20:28 +02:00
|
|
|
void
|
2017-04-25 14:39:06 +02:00
|
|
|
buf_dblwr_process()
|
2014-05-05 18:20:28 +02:00
|
|
|
{
|
2016-08-12 10:17:45 +02:00
|
|
|
ulint page_no_dblwr = 0;
|
|
|
|
byte* read_buf;
|
|
|
|
byte* unaligned_read_buf;
|
|
|
|
recv_dblwr_t& recv_dblwr = recv_sys->dblwr;
|
2014-05-05 18:20:28 +02:00
|
|
|
|
2017-06-06 13:59:42 +02:00
|
|
|
if (!buf_dblwr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
unaligned_read_buf = static_cast<byte*>(
|
2018-06-18 11:40:53 +02:00
|
|
|
ut_malloc_nokey(3U << srv_page_size_shift));
|
2014-05-05 18:20:28 +02:00
|
|
|
|
|
|
|
read_buf = static_cast<byte*>(
|
2018-04-27 12:49:25 +02:00
|
|
|
ut_align(unaligned_read_buf, srv_page_size));
|
2018-06-18 11:40:53 +02:00
|
|
|
byte* const buf = read_buf + srv_page_size;
|
2014-05-05 18:20:28 +02:00
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
for (recv_dblwr_t::list::iterator i = recv_dblwr.pages.begin();
|
|
|
|
i != recv_dblwr.pages.end();
|
|
|
|
++i, ++page_no_dblwr) {
|
2017-01-19 11:06:13 +01:00
|
|
|
byte* page = *i;
|
|
|
|
ulint space_id = page_get_space_id(page);
|
2016-08-12 10:17:45 +02:00
|
|
|
fil_space_t* space = fil_space_get(space_id);
|
2014-05-05 18:20:28 +02:00
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
if (space == NULL) {
|
|
|
|
/* Maybe we have dropped the tablespace
|
2014-02-26 19:11:54 +01:00
|
|
|
and this page once belonged to it: do nothing */
|
2016-08-12 10:17:45 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
fil_space_open_if_needed(space);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2017-04-25 14:39:06 +02:00
|
|
|
const ulint page_no = page_get_page_no(page);
|
2017-01-19 11:06:13 +01:00
|
|
|
const page_id_t page_id(space_id, page_no);
|
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
if (page_no >= space->size) {
|
|
|
|
|
2018-09-10 17:01:54 +02:00
|
|
|
/* Do not report the warning for undo
|
|
|
|
tablespaces, because they can be truncated in place. */
|
|
|
|
if (!srv_is_undo_tablespace(space_id)) {
|
2017-01-19 11:06:13 +01:00
|
|
|
ib::warn() << "A copy of page " << page_id
|
|
|
|
<< " in the doublewrite buffer slot "
|
|
|
|
<< page_no_dblwr
|
|
|
|
<< " is not within space bounds";
|
2016-08-12 10:17:45 +02:00
|
|
|
}
|
2017-01-15 13:20:16 +01:00
|
|
|
continue;
|
|
|
|
}
|
2016-08-12 10:17:45 +02:00
|
|
|
|
2017-01-19 11:06:13 +01:00
|
|
|
const page_size_t page_size(space->flags);
|
2018-12-17 19:04:03 +01:00
|
|
|
ut_ad(!buf_page_is_zeroes(page, page_size.physical()));
|
2016-08-12 10:17:45 +02:00
|
|
|
|
2017-01-19 11:06:13 +01:00
|
|
|
/* We want to ensure that for partial reads the
|
|
|
|
unread portion of the page is NUL. */
|
|
|
|
memset(read_buf, 0x0, page_size.physical());
|
2016-08-12 10:17:45 +02:00
|
|
|
|
2017-01-19 11:06:13 +01:00
|
|
|
IORequest request;
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2017-01-19 11:06:13 +01:00
|
|
|
request.dblwr_recover();
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2017-01-15 13:20:16 +01:00
|
|
|
/* Read in the actual page from the file */
|
2017-01-19 11:06:13 +01:00
|
|
|
dberr_t err = fil_io(
|
|
|
|
request, true,
|
|
|
|
page_id, page_size,
|
MDEV-11254: innodb-use-trim has no effect in 10.2
Problem was that implementation merged from 10.1 was incompatible
with InnoDB 5.7.
buf0buf.cc: Add functions to return should we punch hole and
how big.
buf0flu.cc: Add written page to IORequest
fil0fil.cc: Remove unneeded status call and add test is
sparse files and punch hole supported by file system when
tablespace is created. Add call to get file system
block size. Used file node is added to IORequest. Added
functions to check is punch hole supported and setting
punch hole.
ha_innodb.cc: Remove unneeded status variables (trim512-32768)
and trim_op_saved. Deprecate innodb_use_trim and
set it ON by default. Add function to set innodb-use-trim
dynamically.
dberr.h: Add error code DB_IO_NO_PUNCH_HOLE
if punch hole operation fails.
fil0fil.h: Add punch_hole variable to fil_space_t and
block size to fil_node_t.
os0api.h: Header to helper functions on buf0buf.cc and
fil0fil.cc for os0file.h
os0file.h: Remove unneeded m_block_size from IORequest
and add bpage to IORequest to know actual size of
the block and m_fil_node to know tablespace file
system block size and does it support punch hole.
os0file.cc: Add function punch_hole() to IORequest
to do punch_hole operation,
get the file system block size and determine
does file system support sparse files (for punch hole).
page0size.h: remove implicit copy disable and
use this implicit copy to implement copy_from()
function.
buf0dblwr.cc, buf0flu.cc, buf0rea.cc, fil0fil.cc, fil0fil.h,
os0file.h, os0file.cc, log0log.cc, log0recv.cc:
Remove unneeded write_size parameter from fil_io
calls.
srv0mon.h, srv0srv.h, srv0mon.cc: Remove unneeded
trim512-trim32678 status variables. Removed
these from monitor tests.
2017-01-24 13:40:58 +01:00
|
|
|
0, page_size.physical(), read_buf, NULL);
|
2016-09-06 08:43:16 +02:00
|
|
|
|
2017-01-19 11:06:13 +01:00
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
ib::warn()
|
|
|
|
<< "Double write buffer recovery: "
|
|
|
|
<< page_id << " read failed with "
|
|
|
|
<< "error: " << ut_strerr(err);
|
|
|
|
}
|
2016-09-06 08:43:16 +02:00
|
|
|
|
2017-01-15 13:20:16 +01:00
|
|
|
const bool is_all_zero = buf_page_is_zeroes(
|
2018-12-17 19:04:03 +01:00
|
|
|
read_buf, page_size.physical());
|
|
|
|
const bool expect_encrypted = space->crypt_data
|
|
|
|
&& space->crypt_data->type != CRYPT_SCHEME_UNENCRYPTED;
|
2016-04-29 11:32:35 +02:00
|
|
|
|
2017-01-15 13:20:16 +01:00
|
|
|
if (is_all_zero) {
|
|
|
|
/* We will check if the copy in the
|
|
|
|
doublewrite buffer is valid. If not, we will
|
|
|
|
ignore this page (there should be redo log
|
|
|
|
records to initialize it). */
|
2014-02-26 19:11:54 +01:00
|
|
|
} else {
|
2018-06-13 15:15:21 +02:00
|
|
|
/* Decompress the page before
|
|
|
|
validating the checksum. */
|
|
|
|
ulint decomp = fil_page_decompress(buf, read_buf);
|
|
|
|
if (!decomp || (decomp != srv_page_size
|
|
|
|
&& page_size.is_compressed())) {
|
|
|
|
goto bad;
|
2016-04-29 11:32:35 +02:00
|
|
|
}
|
2016-08-12 10:17:45 +02:00
|
|
|
|
2018-12-17 18:00:35 +01:00
|
|
|
if (expect_encrypted && mach_read_from_4(
|
|
|
|
read_buf
|
|
|
|
+ FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION)
|
|
|
|
? fil_space_verify_crypt_checksum(read_buf,
|
2018-12-17 19:04:03 +01:00
|
|
|
page_size)
|
2018-12-17 18:00:35 +01:00
|
|
|
: !buf_page_is_corrupted(true, read_buf,
|
2018-12-17 19:04:03 +01:00
|
|
|
page_size, space)) {
|
2017-01-15 13:20:16 +01:00
|
|
|
/* The page is good; there is no need
|
|
|
|
to consult the doublewrite buffer. */
|
|
|
|
continue;
|
2016-08-12 10:17:45 +02:00
|
|
|
}
|
|
|
|
|
2018-06-13 15:15:21 +02:00
|
|
|
bad:
|
2017-01-15 13:20:16 +01:00
|
|
|
/* We intentionally skip this message for
|
|
|
|
is_all_zero pages. */
|
2017-01-19 11:06:13 +01:00
|
|
|
ib::info()
|
|
|
|
<< "Trying to recover page " << page_id
|
|
|
|
<< " from the doublewrite buffer.";
|
2017-01-15 13:20:16 +01:00
|
|
|
}
|
2014-05-06 21:13:16 +02:00
|
|
|
|
2018-06-13 15:15:21 +02:00
|
|
|
ulint decomp = fil_page_decompress(buf, page);
|
|
|
|
if (!decomp || (decomp != srv_page_size
|
|
|
|
&& page_size.is_compressed())) {
|
|
|
|
goto bad_doublewrite;
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
2018-12-17 18:00:35 +01:00
|
|
|
|
|
|
|
if (expect_encrypted && mach_read_from_4(
|
|
|
|
page + FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION)
|
2018-12-17 19:04:03 +01:00
|
|
|
? !fil_space_verify_crypt_checksum(page, page_size)
|
|
|
|
: buf_page_is_corrupted(true, page, page_size, space)) {
|
2017-01-15 13:20:16 +01:00
|
|
|
if (!is_all_zero) {
|
2018-06-13 15:15:21 +02:00
|
|
|
bad_doublewrite:
|
2017-01-19 11:06:13 +01:00
|
|
|
ib::warn() << "A doublewrite copy of page "
|
|
|
|
<< page_id << " is corrupted.";
|
2017-01-15 13:20:16 +01:00
|
|
|
}
|
|
|
|
/* Theoretically we could have another good
|
|
|
|
copy for this page in the doublewrite
|
|
|
|
buffer. If not, we will report a fatal error
|
|
|
|
for a corrupted page somewhere else if that
|
|
|
|
page was truly needed. */
|
|
|
|
continue;
|
|
|
|
}
|
2014-05-06 21:13:16 +02:00
|
|
|
|
MDEV-11623 MariaDB 10.1 fails to start datadir created with
MariaDB 10.0/MySQL 5.6 using innodb-page-size!=16K
The storage format of FSP_SPACE_FLAGS was accidentally broken
already in MariaDB 10.1.0. This fix is bringing the format in
line with other MySQL and MariaDB release series.
Please refer to the comments that were added to fsp0fsp.h
for details.
This is an INCOMPATIBLE CHANGE that affects users of
page_compression and non-default innodb_page_size. Upgrading
to this release will correct the flags in the data files.
If you want to downgrade to earlier MariaDB 10.1.x, please refer
to the test innodb.101_compatibility how to reset the
FSP_SPACE_FLAGS in the files.
NOTE: MariaDB 10.1.0 to 10.1.20 can misinterpret
uncompressed data files with innodb_page_size=4k or 64k as
compressed innodb_page_size=16k files, and then probably fail
when trying to access the pages. See the comments in the
function fsp_flags_convert_from_101() for detailed analysis.
Move PAGE_COMPRESSION to FSP_SPACE_FLAGS bit position 16.
In this way, compressed innodb_page_size=16k tablespaces will not
be mistaken for uncompressed ones by MariaDB 10.1.0 to 10.1.20.
Derive PAGE_COMPRESSION_LEVEL, ATOMIC_WRITES and DATA_DIR from the
dict_table_t::flags when the table is available, in
fil_space_for_table_exists_in_mem() or fil_open_single_table_tablespace().
During crash recovery, fil_load_single_table_tablespace() will use
innodb_compression_level for the PAGE_COMPRESSION_LEVEL.
FSP_FLAGS_MEM_MASK: A bitmap of the memory-only fil_space_t::flags
that are not to be written to FSP_SPACE_FLAGS. Currently, these will
include PAGE_COMPRESSION_LEVEL, ATOMIC_WRITES and DATA_DIR.
Introduce the macro FSP_FLAGS_PAGE_SSIZE(). We only support
one innodb_page_size for the whole instance.
When creating a dummy tablespace for the redo log, use
fil_space_t::flags=0. The flags are never written to the redo log files.
Remove many FSP_FLAGS_SET_ macros.
dict_tf_verify_flags(): Remove. This is basically only duplicating
the logic of dict_tf_to_fsp_flags(), used in a debug assertion.
fil_space_t::mark: Remove. This flag was not used for anything.
fil_space_for_table_exists_in_mem(): Remove the unnecessary parameter
mark_space, and add a parameter for table flags. Check that
fil_space_t::flags match the table flags, and adjust the (memory-only)
flags based on the table flags.
fil_node_open_file(): Remove some redundant or unreachable conditions,
do not use stderr for output, and avoid unnecessary server aborts.
fil_user_tablespace_restore_page(): Convert the flags, so that the
correct page_size will be used when restoring a page from the
doublewrite buffer.
fil_space_get_page_compressed(), fsp_flags_is_page_compressed(): Remove.
It suffices to have fil_space_is_page_compressed().
FSP_FLAGS_WIDTH_DATA_DIR, FSP_FLAGS_WIDTH_PAGE_COMPRESSION_LEVEL,
FSP_FLAGS_WIDTH_ATOMIC_WRITES: Remove, because these flags do not
exist in the FSP_SPACE_FLAGS but only in memory.
fsp_flags_try_adjust(): New function, to adjust the FSP_SPACE_FLAGS
in page 0. Called by fil_open_single_table_tablespace(),
fil_space_for_table_exists_in_mem(), innobase_start_or_create_for_mysql()
except if --innodb-read-only is active.
fsp_flags_is_valid(ulint): Reimplement from the scratch, with
accurate comments. Do not display any details of detected
inconsistencies, because the output could be confusing when
dealing with MariaDB 10.1.x data files.
fsp_flags_convert_from_101(ulint): Convert flags from buggy
MariaDB 10.1.x format, or return ULINT_UNDEFINED if the flags
cannot be in MariaDB 10.1.x format.
fsp_flags_match(): Check the flags when probing files.
Implemented based on fsp_flags_is_valid()
and fsp_flags_convert_from_101().
dict_check_tablespaces_and_store_max_id(): Do not access the
page after committing the mini-transaction.
IMPORT TABLESPACE fixes:
AbstractCallback::init(): Convert the flags.
FetchIndexRootPages::operator(): Check that the tablespace flags match the
table flags. Do not attempt to convert tablespace flags to table flags,
because the conversion would necessarily be lossy.
PageConverter::update_header(): Write back the correct flags.
This takes care of the flags in IMPORT TABLESPACE.
2017-01-13 23:13:16 +01:00
|
|
|
if (page_no == 0) {
|
|
|
|
/* Check the FSP_SPACE_FLAGS. */
|
|
|
|
ulint flags = fsp_header_get_flags(page);
|
2017-07-05 13:35:55 +02:00
|
|
|
if (!fsp_flags_is_valid(flags, space_id)
|
MDEV-11623 MariaDB 10.1 fails to start datadir created with
MariaDB 10.0/MySQL 5.6 using innodb-page-size!=16K
The storage format of FSP_SPACE_FLAGS was accidentally broken
already in MariaDB 10.1.0. This fix is bringing the format in
line with other MySQL and MariaDB release series.
Please refer to the comments that were added to fsp0fsp.h
for details.
This is an INCOMPATIBLE CHANGE that affects users of
page_compression and non-default innodb_page_size. Upgrading
to this release will correct the flags in the data files.
If you want to downgrade to earlier MariaDB 10.1.x, please refer
to the test innodb.101_compatibility how to reset the
FSP_SPACE_FLAGS in the files.
NOTE: MariaDB 10.1.0 to 10.1.20 can misinterpret
uncompressed data files with innodb_page_size=4k or 64k as
compressed innodb_page_size=16k files, and then probably fail
when trying to access the pages. See the comments in the
function fsp_flags_convert_from_101() for detailed analysis.
Move PAGE_COMPRESSION to FSP_SPACE_FLAGS bit position 16.
In this way, compressed innodb_page_size=16k tablespaces will not
be mistaken for uncompressed ones by MariaDB 10.1.0 to 10.1.20.
Derive PAGE_COMPRESSION_LEVEL, ATOMIC_WRITES and DATA_DIR from the
dict_table_t::flags when the table is available, in
fil_space_for_table_exists_in_mem() or fil_open_single_table_tablespace().
During crash recovery, fil_load_single_table_tablespace() will use
innodb_compression_level for the PAGE_COMPRESSION_LEVEL.
FSP_FLAGS_MEM_MASK: A bitmap of the memory-only fil_space_t::flags
that are not to be written to FSP_SPACE_FLAGS. Currently, these will
include PAGE_COMPRESSION_LEVEL, ATOMIC_WRITES and DATA_DIR.
Introduce the macro FSP_FLAGS_PAGE_SSIZE(). We only support
one innodb_page_size for the whole instance.
When creating a dummy tablespace for the redo log, use
fil_space_t::flags=0. The flags are never written to the redo log files.
Remove many FSP_FLAGS_SET_ macros.
dict_tf_verify_flags(): Remove. This is basically only duplicating
the logic of dict_tf_to_fsp_flags(), used in a debug assertion.
fil_space_t::mark: Remove. This flag was not used for anything.
fil_space_for_table_exists_in_mem(): Remove the unnecessary parameter
mark_space, and add a parameter for table flags. Check that
fil_space_t::flags match the table flags, and adjust the (memory-only)
flags based on the table flags.
fil_node_open_file(): Remove some redundant or unreachable conditions,
do not use stderr for output, and avoid unnecessary server aborts.
fil_user_tablespace_restore_page(): Convert the flags, so that the
correct page_size will be used when restoring a page from the
doublewrite buffer.
fil_space_get_page_compressed(), fsp_flags_is_page_compressed(): Remove.
It suffices to have fil_space_is_page_compressed().
FSP_FLAGS_WIDTH_DATA_DIR, FSP_FLAGS_WIDTH_PAGE_COMPRESSION_LEVEL,
FSP_FLAGS_WIDTH_ATOMIC_WRITES: Remove, because these flags do not
exist in the FSP_SPACE_FLAGS but only in memory.
fsp_flags_try_adjust(): New function, to adjust the FSP_SPACE_FLAGS
in page 0. Called by fil_open_single_table_tablespace(),
fil_space_for_table_exists_in_mem(), innobase_start_or_create_for_mysql()
except if --innodb-read-only is active.
fsp_flags_is_valid(ulint): Reimplement from the scratch, with
accurate comments. Do not display any details of detected
inconsistencies, because the output could be confusing when
dealing with MariaDB 10.1.x data files.
fsp_flags_convert_from_101(ulint): Convert flags from buggy
MariaDB 10.1.x format, or return ULINT_UNDEFINED if the flags
cannot be in MariaDB 10.1.x format.
fsp_flags_match(): Check the flags when probing files.
Implemented based on fsp_flags_is_valid()
and fsp_flags_convert_from_101().
dict_check_tablespaces_and_store_max_id(): Do not access the
page after committing the mini-transaction.
IMPORT TABLESPACE fixes:
AbstractCallback::init(): Convert the flags.
FetchIndexRootPages::operator(): Check that the tablespace flags match the
table flags. Do not attempt to convert tablespace flags to table flags,
because the conversion would necessarily be lossy.
PageConverter::update_header(): Write back the correct flags.
This takes care of the flags in IMPORT TABLESPACE.
2017-01-13 23:13:16 +01:00
|
|
|
&& fsp_flags_convert_from_101(flags)
|
|
|
|
== ULINT_UNDEFINED) {
|
2017-01-19 11:06:13 +01:00
|
|
|
ib::warn() << "Ignoring a doublewrite copy"
|
|
|
|
" of page " << page_id
|
|
|
|
<< " due to invalid flags "
|
|
|
|
<< ib::hex(flags);
|
MDEV-11623 MariaDB 10.1 fails to start datadir created with
MariaDB 10.0/MySQL 5.6 using innodb-page-size!=16K
The storage format of FSP_SPACE_FLAGS was accidentally broken
already in MariaDB 10.1.0. This fix is bringing the format in
line with other MySQL and MariaDB release series.
Please refer to the comments that were added to fsp0fsp.h
for details.
This is an INCOMPATIBLE CHANGE that affects users of
page_compression and non-default innodb_page_size. Upgrading
to this release will correct the flags in the data files.
If you want to downgrade to earlier MariaDB 10.1.x, please refer
to the test innodb.101_compatibility how to reset the
FSP_SPACE_FLAGS in the files.
NOTE: MariaDB 10.1.0 to 10.1.20 can misinterpret
uncompressed data files with innodb_page_size=4k or 64k as
compressed innodb_page_size=16k files, and then probably fail
when trying to access the pages. See the comments in the
function fsp_flags_convert_from_101() for detailed analysis.
Move PAGE_COMPRESSION to FSP_SPACE_FLAGS bit position 16.
In this way, compressed innodb_page_size=16k tablespaces will not
be mistaken for uncompressed ones by MariaDB 10.1.0 to 10.1.20.
Derive PAGE_COMPRESSION_LEVEL, ATOMIC_WRITES and DATA_DIR from the
dict_table_t::flags when the table is available, in
fil_space_for_table_exists_in_mem() or fil_open_single_table_tablespace().
During crash recovery, fil_load_single_table_tablespace() will use
innodb_compression_level for the PAGE_COMPRESSION_LEVEL.
FSP_FLAGS_MEM_MASK: A bitmap of the memory-only fil_space_t::flags
that are not to be written to FSP_SPACE_FLAGS. Currently, these will
include PAGE_COMPRESSION_LEVEL, ATOMIC_WRITES and DATA_DIR.
Introduce the macro FSP_FLAGS_PAGE_SSIZE(). We only support
one innodb_page_size for the whole instance.
When creating a dummy tablespace for the redo log, use
fil_space_t::flags=0. The flags are never written to the redo log files.
Remove many FSP_FLAGS_SET_ macros.
dict_tf_verify_flags(): Remove. This is basically only duplicating
the logic of dict_tf_to_fsp_flags(), used in a debug assertion.
fil_space_t::mark: Remove. This flag was not used for anything.
fil_space_for_table_exists_in_mem(): Remove the unnecessary parameter
mark_space, and add a parameter for table flags. Check that
fil_space_t::flags match the table flags, and adjust the (memory-only)
flags based on the table flags.
fil_node_open_file(): Remove some redundant or unreachable conditions,
do not use stderr for output, and avoid unnecessary server aborts.
fil_user_tablespace_restore_page(): Convert the flags, so that the
correct page_size will be used when restoring a page from the
doublewrite buffer.
fil_space_get_page_compressed(), fsp_flags_is_page_compressed(): Remove.
It suffices to have fil_space_is_page_compressed().
FSP_FLAGS_WIDTH_DATA_DIR, FSP_FLAGS_WIDTH_PAGE_COMPRESSION_LEVEL,
FSP_FLAGS_WIDTH_ATOMIC_WRITES: Remove, because these flags do not
exist in the FSP_SPACE_FLAGS but only in memory.
fsp_flags_try_adjust(): New function, to adjust the FSP_SPACE_FLAGS
in page 0. Called by fil_open_single_table_tablespace(),
fil_space_for_table_exists_in_mem(), innobase_start_or_create_for_mysql()
except if --innodb-read-only is active.
fsp_flags_is_valid(ulint): Reimplement from the scratch, with
accurate comments. Do not display any details of detected
inconsistencies, because the output could be confusing when
dealing with MariaDB 10.1.x data files.
fsp_flags_convert_from_101(ulint): Convert flags from buggy
MariaDB 10.1.x format, or return ULINT_UNDEFINED if the flags
cannot be in MariaDB 10.1.x format.
fsp_flags_match(): Check the flags when probing files.
Implemented based on fsp_flags_is_valid()
and fsp_flags_convert_from_101().
dict_check_tablespaces_and_store_max_id(): Do not access the
page after committing the mini-transaction.
IMPORT TABLESPACE fixes:
AbstractCallback::init(): Convert the flags.
FetchIndexRootPages::operator(): Check that the tablespace flags match the
table flags. Do not attempt to convert tablespace flags to table flags,
because the conversion would necessarily be lossy.
PageConverter::update_header(): Write back the correct flags.
This takes care of the flags in IMPORT TABLESPACE.
2017-01-13 23:13:16 +01:00
|
|
|
continue;
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
MDEV-11623 MariaDB 10.1 fails to start datadir created with
MariaDB 10.0/MySQL 5.6 using innodb-page-size!=16K
The storage format of FSP_SPACE_FLAGS was accidentally broken
already in MariaDB 10.1.0. This fix is bringing the format in
line with other MySQL and MariaDB release series.
Please refer to the comments that were added to fsp0fsp.h
for details.
This is an INCOMPATIBLE CHANGE that affects users of
page_compression and non-default innodb_page_size. Upgrading
to this release will correct the flags in the data files.
If you want to downgrade to earlier MariaDB 10.1.x, please refer
to the test innodb.101_compatibility how to reset the
FSP_SPACE_FLAGS in the files.
NOTE: MariaDB 10.1.0 to 10.1.20 can misinterpret
uncompressed data files with innodb_page_size=4k or 64k as
compressed innodb_page_size=16k files, and then probably fail
when trying to access the pages. See the comments in the
function fsp_flags_convert_from_101() for detailed analysis.
Move PAGE_COMPRESSION to FSP_SPACE_FLAGS bit position 16.
In this way, compressed innodb_page_size=16k tablespaces will not
be mistaken for uncompressed ones by MariaDB 10.1.0 to 10.1.20.
Derive PAGE_COMPRESSION_LEVEL, ATOMIC_WRITES and DATA_DIR from the
dict_table_t::flags when the table is available, in
fil_space_for_table_exists_in_mem() or fil_open_single_table_tablespace().
During crash recovery, fil_load_single_table_tablespace() will use
innodb_compression_level for the PAGE_COMPRESSION_LEVEL.
FSP_FLAGS_MEM_MASK: A bitmap of the memory-only fil_space_t::flags
that are not to be written to FSP_SPACE_FLAGS. Currently, these will
include PAGE_COMPRESSION_LEVEL, ATOMIC_WRITES and DATA_DIR.
Introduce the macro FSP_FLAGS_PAGE_SSIZE(). We only support
one innodb_page_size for the whole instance.
When creating a dummy tablespace for the redo log, use
fil_space_t::flags=0. The flags are never written to the redo log files.
Remove many FSP_FLAGS_SET_ macros.
dict_tf_verify_flags(): Remove. This is basically only duplicating
the logic of dict_tf_to_fsp_flags(), used in a debug assertion.
fil_space_t::mark: Remove. This flag was not used for anything.
fil_space_for_table_exists_in_mem(): Remove the unnecessary parameter
mark_space, and add a parameter for table flags. Check that
fil_space_t::flags match the table flags, and adjust the (memory-only)
flags based on the table flags.
fil_node_open_file(): Remove some redundant or unreachable conditions,
do not use stderr for output, and avoid unnecessary server aborts.
fil_user_tablespace_restore_page(): Convert the flags, so that the
correct page_size will be used when restoring a page from the
doublewrite buffer.
fil_space_get_page_compressed(), fsp_flags_is_page_compressed(): Remove.
It suffices to have fil_space_is_page_compressed().
FSP_FLAGS_WIDTH_DATA_DIR, FSP_FLAGS_WIDTH_PAGE_COMPRESSION_LEVEL,
FSP_FLAGS_WIDTH_ATOMIC_WRITES: Remove, because these flags do not
exist in the FSP_SPACE_FLAGS but only in memory.
fsp_flags_try_adjust(): New function, to adjust the FSP_SPACE_FLAGS
in page 0. Called by fil_open_single_table_tablespace(),
fil_space_for_table_exists_in_mem(), innobase_start_or_create_for_mysql()
except if --innodb-read-only is active.
fsp_flags_is_valid(ulint): Reimplement from the scratch, with
accurate comments. Do not display any details of detected
inconsistencies, because the output could be confusing when
dealing with MariaDB 10.1.x data files.
fsp_flags_convert_from_101(ulint): Convert flags from buggy
MariaDB 10.1.x format, or return ULINT_UNDEFINED if the flags
cannot be in MariaDB 10.1.x format.
fsp_flags_match(): Check the flags when probing files.
Implemented based on fsp_flags_is_valid()
and fsp_flags_convert_from_101().
dict_check_tablespaces_and_store_max_id(): Do not access the
page after committing the mini-transaction.
IMPORT TABLESPACE fixes:
AbstractCallback::init(): Convert the flags.
FetchIndexRootPages::operator(): Check that the tablespace flags match the
table flags. Do not attempt to convert tablespace flags to table flags,
because the conversion would necessarily be lossy.
PageConverter::update_header(): Write back the correct flags.
This takes care of the flags in IMPORT TABLESPACE.
2017-01-13 23:13:16 +01:00
|
|
|
/* The flags on the page should be converted later. */
|
|
|
|
}
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2017-01-15 13:20:16 +01:00
|
|
|
/* Write the good page from the doublewrite buffer to
|
|
|
|
the intended position. */
|
2014-12-22 15:53:17 +01:00
|
|
|
|
2017-01-19 11:06:13 +01:00
|
|
|
IORequest write_request(IORequest::WRITE);
|
2014-12-22 15:53:17 +01:00
|
|
|
|
2017-01-19 11:06:13 +01:00
|
|
|
fil_io(write_request, true, page_id, page_size,
|
|
|
|
0, page_size.physical(),
|
MDEV-11254: innodb-use-trim has no effect in 10.2
Problem was that implementation merged from 10.1 was incompatible
with InnoDB 5.7.
buf0buf.cc: Add functions to return should we punch hole and
how big.
buf0flu.cc: Add written page to IORequest
fil0fil.cc: Remove unneeded status call and add test is
sparse files and punch hole supported by file system when
tablespace is created. Add call to get file system
block size. Used file node is added to IORequest. Added
functions to check is punch hole supported and setting
punch hole.
ha_innodb.cc: Remove unneeded status variables (trim512-32768)
and trim_op_saved. Deprecate innodb_use_trim and
set it ON by default. Add function to set innodb-use-trim
dynamically.
dberr.h: Add error code DB_IO_NO_PUNCH_HOLE
if punch hole operation fails.
fil0fil.h: Add punch_hole variable to fil_space_t and
block size to fil_node_t.
os0api.h: Header to helper functions on buf0buf.cc and
fil0fil.cc for os0file.h
os0file.h: Remove unneeded m_block_size from IORequest
and add bpage to IORequest to know actual size of
the block and m_fil_node to know tablespace file
system block size and does it support punch hole.
os0file.cc: Add function punch_hole() to IORequest
to do punch_hole operation,
get the file system block size and determine
does file system support sparse files (for punch hole).
page0size.h: remove implicit copy disable and
use this implicit copy to implement copy_from()
function.
buf0dblwr.cc, buf0flu.cc, buf0rea.cc, fil0fil.cc, fil0fil.h,
os0file.h, os0file.cc, log0log.cc, log0recv.cc:
Remove unneeded write_size parameter from fil_io
calls.
srv0mon.h, srv0srv.h, srv0mon.cc: Remove unneeded
trim512-trim32678 status variables. Removed
these from monitor tests.
2017-01-24 13:40:58 +01:00
|
|
|
const_cast<byte*>(page), NULL);
|
2016-08-12 10:17:45 +02:00
|
|
|
|
2017-01-19 11:06:13 +01:00
|
|
|
ib::info() << "Recovered page " << page_id
|
|
|
|
<< " from the doublewrite buffer.";
|
2016-08-12 10:17:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
recv_dblwr.pages.clear();
|
|
|
|
|
|
|
|
fil_flush_file_spaces(FIL_TYPE_TABLESPACE);
|
|
|
|
ut_free(unaligned_read_buf);
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************//**
|
|
|
|
Frees doublewrite buffer. */
|
|
|
|
void
|
2017-04-25 14:39:06 +02:00
|
|
|
buf_dblwr_free()
|
2014-02-26 19:11:54 +01:00
|
|
|
{
|
|
|
|
/* Free the double write data structures. */
|
|
|
|
ut_a(buf_dblwr != NULL);
|
|
|
|
ut_ad(buf_dblwr->s_reserved == 0);
|
|
|
|
ut_ad(buf_dblwr->b_reserved == 0);
|
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
os_event_destroy(buf_dblwr->b_event);
|
|
|
|
os_event_destroy(buf_dblwr->s_event);
|
2014-02-26 19:11:54 +01:00
|
|
|
ut_free(buf_dblwr->write_buf_unaligned);
|
|
|
|
buf_dblwr->write_buf_unaligned = NULL;
|
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
ut_free(buf_dblwr->buf_block_arr);
|
2014-02-26 19:11:54 +01:00
|
|
|
buf_dblwr->buf_block_arr = NULL;
|
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
ut_free(buf_dblwr->in_use);
|
2014-02-26 19:11:54 +01:00
|
|
|
buf_dblwr->in_use = NULL;
|
|
|
|
|
|
|
|
mutex_free(&buf_dblwr->mutex);
|
2016-08-12 10:17:45 +02:00
|
|
|
ut_free(buf_dblwr);
|
2014-02-26 19:11:54 +01:00
|
|
|
buf_dblwr = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************//**
|
|
|
|
Updates the doublewrite buffer when an IO request is completed. */
|
|
|
|
void
|
|
|
|
buf_dblwr_update(
|
|
|
|
/*=============*/
|
|
|
|
const buf_page_t* bpage, /*!< in: buffer block descriptor */
|
|
|
|
buf_flush_t flush_type)/*!< in: flush type */
|
|
|
|
{
|
2018-03-09 20:25:20 +01:00
|
|
|
ut_ad(srv_use_doublewrite_buf);
|
|
|
|
ut_ad(buf_dblwr);
|
|
|
|
ut_ad(!fsp_is_system_temporary(bpage->id.space()));
|
2016-08-12 10:17:45 +02:00
|
|
|
ut_ad(!srv_read_only_mode);
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
switch (flush_type) {
|
|
|
|
case BUF_FLUSH_LIST:
|
|
|
|
case BUF_FLUSH_LRU:
|
|
|
|
mutex_enter(&buf_dblwr->mutex);
|
|
|
|
|
|
|
|
ut_ad(buf_dblwr->batch_running);
|
|
|
|
ut_ad(buf_dblwr->b_reserved > 0);
|
|
|
|
ut_ad(buf_dblwr->b_reserved <= buf_dblwr->first_free);
|
|
|
|
|
|
|
|
buf_dblwr->b_reserved--;
|
|
|
|
|
|
|
|
if (buf_dblwr->b_reserved == 0) {
|
|
|
|
mutex_exit(&buf_dblwr->mutex);
|
|
|
|
/* This will finish the batch. Sync data files
|
|
|
|
to the disk. */
|
2016-08-12 10:17:45 +02:00
|
|
|
fil_flush_file_spaces(FIL_TYPE_TABLESPACE);
|
2014-02-26 19:11:54 +01:00
|
|
|
mutex_enter(&buf_dblwr->mutex);
|
|
|
|
|
|
|
|
/* We can now reuse the doublewrite memory buffer: */
|
|
|
|
buf_dblwr->first_free = 0;
|
|
|
|
buf_dblwr->batch_running = false;
|
|
|
|
os_event_set(buf_dblwr->b_event);
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_exit(&buf_dblwr->mutex);
|
|
|
|
break;
|
|
|
|
case BUF_FLUSH_SINGLE_PAGE:
|
|
|
|
{
|
2014-12-22 15:53:17 +01:00
|
|
|
const ulint size = TRX_SYS_DOUBLEWRITE_BLOCKS * TRX_SYS_DOUBLEWRITE_BLOCK_SIZE;
|
2014-02-26 19:11:54 +01:00
|
|
|
ulint i;
|
|
|
|
mutex_enter(&buf_dblwr->mutex);
|
|
|
|
for (i = srv_doublewrite_batch_size; i < size; ++i) {
|
|
|
|
if (buf_dblwr->buf_block_arr[i] == bpage) {
|
|
|
|
buf_dblwr->s_reserved--;
|
|
|
|
buf_dblwr->buf_block_arr[i] = NULL;
|
|
|
|
buf_dblwr->in_use[i] = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The block we are looking for must exist as a
|
|
|
|
reserved block. */
|
|
|
|
ut_a(i < size);
|
|
|
|
}
|
|
|
|
os_event_set(buf_dblwr->s_event);
|
|
|
|
mutex_exit(&buf_dblwr->mutex);
|
|
|
|
break;
|
|
|
|
case BUF_FLUSH_N_TYPES:
|
|
|
|
ut_error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************//**
|
|
|
|
Check the LSN values on the page. */
|
|
|
|
static
|
|
|
|
void
|
|
|
|
buf_dblwr_check_page_lsn(
|
|
|
|
/*=====================*/
|
|
|
|
const page_t* page) /*!< in: page to check */
|
|
|
|
{
|
2015-05-26 13:59:39 +02:00
|
|
|
ibool page_compressed = (mach_read_from_2(page+FIL_PAGE_TYPE) == FIL_PAGE_PAGE_COMPRESSED);
|
|
|
|
uint key_version = mach_read_from_4(page + FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION);
|
|
|
|
|
|
|
|
/* Ignore page compressed or encrypted pages */
|
|
|
|
if (page_compressed || key_version) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
if (memcmp(page + (FIL_PAGE_LSN + 4),
|
2018-04-27 12:49:25 +02:00
|
|
|
page + (srv_page_size
|
2014-02-26 19:11:54 +01:00
|
|
|
- FIL_PAGE_END_LSN_OLD_CHKSUM + 4),
|
|
|
|
4)) {
|
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
const ulint lsn1 = mach_read_from_4(
|
|
|
|
page + FIL_PAGE_LSN + 4);
|
|
|
|
const ulint lsn2 = mach_read_from_4(
|
2018-04-27 12:49:25 +02:00
|
|
|
page + srv_page_size - FIL_PAGE_END_LSN_OLD_CHKSUM
|
2016-08-12 10:17:45 +02:00
|
|
|
+ 4);
|
|
|
|
|
|
|
|
ib::error() << "The page to be written seems corrupt!"
|
|
|
|
" The low 4 bytes of LSN fields do not match"
|
|
|
|
" (" << lsn1 << " != " << lsn2 << ")!"
|
|
|
|
" Noticed in the buffer pool.";
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************//**
|
|
|
|
Asserts when a corrupt block is find during writing out data to the
|
|
|
|
disk. */
|
|
|
|
static
|
|
|
|
void
|
|
|
|
buf_dblwr_assert_on_corrupt_block(
|
|
|
|
/*==============================*/
|
|
|
|
const buf_block_t* block) /*!< in: block to check */
|
|
|
|
{
|
2017-09-06 18:28:51 +02:00
|
|
|
buf_page_print(block->frame, univ_page_size);
|
2016-08-12 10:17:45 +02:00
|
|
|
|
|
|
|
ib::fatal() << "Apparent corruption of an index page "
|
|
|
|
<< block->page.id
|
|
|
|
<< " to be written to data file. We intentionally crash"
|
|
|
|
" the server to prevent corrupt data from ending up in"
|
|
|
|
" data files.";
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************//**
|
|
|
|
Check the LSN values on the page with which this block is associated.
|
|
|
|
Also validate the page if the option is set. */
|
|
|
|
static
|
|
|
|
void
|
|
|
|
buf_dblwr_check_block(
|
|
|
|
/*==================*/
|
|
|
|
const buf_block_t* block) /*!< in: block to check */
|
|
|
|
{
|
2016-08-12 10:17:45 +02:00
|
|
|
ut_ad(buf_block_get_state(block) == BUF_BLOCK_FILE_PAGE);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
if (block->skip_flush_check) {
|
2014-02-26 19:11:54 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
switch (fil_page_get_type(block->frame)) {
|
|
|
|
case FIL_PAGE_INDEX:
|
MDEV-11369 Instant ADD COLUMN for InnoDB
For InnoDB tables, adding, dropping and reordering columns has
required a rebuild of the table and all its indexes. Since MySQL 5.6
(and MariaDB 10.0) this has been supported online (LOCK=NONE), allowing
concurrent modification of the tables.
This work revises the InnoDB ROW_FORMAT=REDUNDANT, ROW_FORMAT=COMPACT
and ROW_FORMAT=DYNAMIC so that columns can be appended instantaneously,
with only minor changes performed to the table structure. The counter
innodb_instant_alter_column in INFORMATION_SCHEMA.GLOBAL_STATUS
is incremented whenever a table rebuild operation is converted into
an instant ADD COLUMN operation.
ROW_FORMAT=COMPRESSED tables will not support instant ADD COLUMN.
Some usability limitations will be addressed in subsequent work:
MDEV-13134 Introduce ALTER TABLE attributes ALGORITHM=NOCOPY
and ALGORITHM=INSTANT
MDEV-14016 Allow instant ADD COLUMN, ADD INDEX, LOCK=NONE
The format of the clustered index (PRIMARY KEY) is changed as follows:
(1) The FIL_PAGE_TYPE of the root page will be FIL_PAGE_TYPE_INSTANT,
and a new field PAGE_INSTANT will contain the original number of fields
in the clustered index ('core' fields).
If instant ADD COLUMN has not been used or the table becomes empty,
or the very first instant ADD COLUMN operation is rolled back,
the fields PAGE_INSTANT and FIL_PAGE_TYPE will be reset
to 0 and FIL_PAGE_INDEX.
(2) A special 'default row' record is inserted into the leftmost leaf,
between the page infimum and the first user record. This record is
distinguished by the REC_INFO_MIN_REC_FLAG, and it is otherwise in the
same format as records that contain values for the instantly added
columns. This 'default row' always has the same number of fields as
the clustered index according to the table definition. The values of
'core' fields are to be ignored. For other fields, the 'default row'
will contain the default values as they were during the ALTER TABLE
statement. (If the column default values are changed later, those
values will only be stored in the .frm file. The 'default row' will
contain the original evaluated values, which must be the same for
every row.) The 'default row' must be completely hidden from
higher-level access routines. Assertions have been added to ensure
that no 'default row' is ever present in the adaptive hash index
or in locked records. The 'default row' is never delete-marked.
(3) In clustered index leaf page records, the number of fields must
reside between the number of 'core' fields (dict_index_t::n_core_fields
introduced in this work) and dict_index_t::n_fields. If the number
of fields is less than dict_index_t::n_fields, the missing fields
are replaced with the column value of the 'default row'.
Note: The number of fields in the record may shrink if some of the
last instantly added columns are updated to the value that is
in the 'default row'. The function btr_cur_trim() implements this
'compression' on update and rollback; dtuple::trim() implements it
on insert.
(4) In ROW_FORMAT=COMPACT and ROW_FORMAT=DYNAMIC records, the new
status value REC_STATUS_COLUMNS_ADDED will indicate the presence of
a new record header that will encode n_fields-n_core_fields-1 in
1 or 2 bytes. (In ROW_FORMAT=REDUNDANT records, the record header
always explicitly encodes the number of fields.)
We introduce the undo log record type TRX_UNDO_INSERT_DEFAULT for
covering the insert of the 'default row' record when instant ADD COLUMN
is used for the first time. Subsequent instant ADD COLUMN can use
TRX_UNDO_UPD_EXIST_REC.
This is joint work with Vin Chen (陈福荣) from Tencent. The design
that was discussed in April 2017 would not have allowed import or
export of data files, because instead of the 'default row' it would
have introduced a data dictionary table. The test
rpl.rpl_alter_instant is exactly as contributed in pull request #408.
The test innodb.instant_alter is based on a contributed test.
The redo log record format changes for ROW_FORMAT=DYNAMIC and
ROW_FORMAT=COMPACT are as contributed. (With this change present,
crash recovery from MariaDB 10.3.1 will fail in spectacular ways!)
Also the semantics of higher-level redo log records that modify the
PAGE_INSTANT field is changed. The redo log format version identifier
was already changed to LOG_HEADER_FORMAT_CURRENT=103 in MariaDB 10.3.1.
Everything else has been rewritten by me. Thanks to Elena Stepanova,
the code has been tested extensively.
When rolling back an instant ADD COLUMN operation, we must empty the
PAGE_FREE list after deleting or shortening the 'default row' record,
by calling either btr_page_empty() or btr_page_reorganize(). We must
know the size of each entry in the PAGE_FREE list. If rollback left a
freed copy of the 'default row' in the PAGE_FREE list, we would be
unable to determine its size (if it is in ROW_FORMAT=COMPACT or
ROW_FORMAT=DYNAMIC) because it would contain more fields than the
rolled-back definition of the clustered index.
UNIV_SQL_DEFAULT: A new special constant that designates an instantly
added column that is not present in the clustered index record.
len_is_stored(): Check if a length is an actual length. There are
two magic length values: UNIV_SQL_DEFAULT, UNIV_SQL_NULL.
dict_col_t::def_val: The 'default row' value of the column. If the
column is not added instantly, def_val.len will be UNIV_SQL_DEFAULT.
dict_col_t: Add the accessors is_virtual(), is_nullable(), is_instant(),
instant_value().
dict_col_t::remove_instant(): Remove the 'instant ADD' status of
a column.
dict_col_t::name(const dict_table_t& table): Replaces
dict_table_get_col_name().
dict_index_t::n_core_fields: The original number of fields.
For secondary indexes and if instant ADD COLUMN has not been used,
this will be equal to dict_index_t::n_fields.
dict_index_t::n_core_null_bytes: Number of bytes needed to
represent the null flags; usually equal to UT_BITS_IN_BYTES(n_nullable).
dict_index_t::NO_CORE_NULL_BYTES: Magic value signalling that
n_core_null_bytes was not initialized yet from the clustered index
root page.
dict_index_t: Add the accessors is_instant(), is_clust(),
get_n_nullable(), instant_field_value().
dict_index_t::instant_add_field(): Adjust clustered index metadata
for instant ADD COLUMN.
dict_index_t::remove_instant(): Remove the 'instant ADD' status
of a clustered index when the table becomes empty, or the very first
instant ADD COLUMN operation is rolled back.
dict_table_t: Add the accessors is_instant(), is_temporary(),
supports_instant().
dict_table_t::instant_add_column(): Adjust metadata for
instant ADD COLUMN.
dict_table_t::rollback_instant(): Adjust metadata on the rollback
of instant ADD COLUMN.
prepare_inplace_alter_table_dict(): First create the ctx->new_table,
and only then decide if the table really needs to be rebuilt.
We must split the creation of table or index metadata from the
creation of the dictionary table records and the creation of
the data. In this way, we can transform a table-rebuilding operation
into an instant ADD COLUMN operation. Dictionary objects will only
be added to cache when table rebuilding or index creation is needed.
The ctx->instant_table will never be added to cache.
dict_table_t::add_to_cache(): Modified and renamed from
dict_table_add_to_cache(). Do not modify the table metadata.
Let the callers invoke dict_table_add_system_columns() and if needed,
set can_be_evicted.
dict_create_sys_tables_tuple(), dict_create_table_step(): Omit the
system columns (which will now exist in the dict_table_t object
already at this point).
dict_create_table_step(): Expect the callers to invoke
dict_table_add_system_columns().
pars_create_table(): Before creating the table creation execution
graph, invoke dict_table_add_system_columns().
row_create_table_for_mysql(): Expect all callers to invoke
dict_table_add_system_columns().
create_index_dict(): Replaces row_merge_create_index_graph().
innodb_update_n_cols(): Renamed from innobase_update_n_virtual().
Call my_error() if an error occurs.
btr_cur_instant_init(), btr_cur_instant_init_low(),
btr_cur_instant_root_init():
Load additional metadata from the clustered index and set
dict_index_t::n_core_null_bytes. This is invoked
when table metadata is first loaded into the data dictionary.
dict_boot(): Initialize n_core_null_bytes for the four hard-coded
dictionary tables.
dict_create_index_step(): Initialize n_core_null_bytes. This is
executed as part of CREATE TABLE.
dict_index_build_internal_clust(): Initialize n_core_null_bytes to
NO_CORE_NULL_BYTES if table->supports_instant().
row_create_index_for_mysql(): Initialize n_core_null_bytes for
CREATE TEMPORARY TABLE.
commit_cache_norebuild(): Call the code to rename or enlarge columns
in the cache only if instant ADD COLUMN is not being used.
(Instant ADD COLUMN would copy all column metadata from
instant_table to old_table, including the names and lengths.)
PAGE_INSTANT: A new 13-bit field for storing dict_index_t::n_core_fields.
This is repurposing the 16-bit field PAGE_DIRECTION, of which only the
least significant 3 bits were used. The original byte containing
PAGE_DIRECTION will be accessible via the new constant PAGE_DIRECTION_B.
page_get_instant(), page_set_instant(): Accessors for the PAGE_INSTANT.
page_ptr_get_direction(), page_get_direction(),
page_ptr_set_direction(): Accessors for PAGE_DIRECTION.
page_direction_reset(): Reset PAGE_DIRECTION, PAGE_N_DIRECTION.
page_direction_increment(): Increment PAGE_N_DIRECTION
and set PAGE_DIRECTION.
rec_get_offsets(): Use the 'leaf' parameter for non-debug purposes,
and assume that heap_no is always set.
Initialize all dict_index_t::n_fields for ROW_FORMAT=REDUNDANT records,
even if the record contains fewer fields.
rec_offs_make_valid(): Add the parameter 'leaf'.
rec_copy_prefix_to_dtuple(): Assert that the tuple is only built
on the core fields. Instant ADD COLUMN only applies to the
clustered index, and we should never build a search key that has
more than the PRIMARY KEY and possibly DB_TRX_ID,DB_ROLL_PTR.
All these columns are always present.
dict_index_build_data_tuple(): Remove assertions that would be
duplicated in rec_copy_prefix_to_dtuple().
rec_init_offsets(): Support ROW_FORMAT=REDUNDANT records whose
number of fields is between n_core_fields and n_fields.
cmp_rec_rec_with_match(): Implement the comparison between two
MIN_REC_FLAG records.
trx_t::in_rollback: Make the field available in non-debug builds.
trx_start_for_ddl_low(): Remove dangerous error-tolerance.
A dictionary transaction must be flagged as such before it has generated
any undo log records. This is because trx_undo_assign_undo() will mark
the transaction as a dictionary transaction in the undo log header
right before the very first undo log record is being written.
btr_index_rec_validate(): Account for instant ADD COLUMN
row_undo_ins_remove_clust_rec(): On the rollback of an insert into
SYS_COLUMNS, revert instant ADD COLUMN in the cache by removing the
last column from the table and the clustered index.
row_search_on_row_ref(), row_undo_mod_parse_undo_rec(), row_undo_mod(),
trx_undo_update_rec_get_update(): Handle the 'default row'
as a special case.
dtuple_t::trim(index): Omit a redundant suffix of an index tuple right
before insert or update. After instant ADD COLUMN, if the last fields
of a clustered index tuple match the 'default row', there is no
need to store them. While trimming the entry, we must hold a page latch,
so that the table cannot be emptied and the 'default row' be deleted.
btr_cur_optimistic_update(), btr_cur_pessimistic_update(),
row_upd_clust_rec_by_insert(), row_ins_clust_index_entry_low():
Invoke dtuple_t::trim() if needed.
row_ins_clust_index_entry(): Restore dtuple_t::n_fields after calling
row_ins_clust_index_entry_low().
rec_get_converted_size(), rec_get_converted_size_comp(): Allow the number
of fields to be between n_core_fields and n_fields. Do not support
infimum,supremum. They are never supposed to be stored in dtuple_t,
because page creation nowadays uses a lower-level method for initializing
them.
rec_convert_dtuple_to_rec_comp(): Assign the status bits based on the
number of fields.
btr_cur_trim(): In an update, trim the index entry as needed. For the
'default row', handle rollback specially. For user records, omit
fields that match the 'default row'.
btr_cur_optimistic_delete_func(), btr_cur_pessimistic_delete():
Skip locking and adaptive hash index for the 'default row'.
row_log_table_apply_convert_mrec(): Replace 'default row' values if needed.
In the temporary file that is applied by row_log_table_apply(),
we must identify whether the records contain the extra header for
instantly added columns. For now, we will allocate an additional byte
for this for ROW_T_INSERT and ROW_T_UPDATE records when the source table
has been subject to instant ADD COLUMN. The ROW_T_DELETE records are
fine, as they will be converted and will only contain 'core' columns
(PRIMARY KEY and some system columns) that are converted from dtuple_t.
rec_get_converted_size_temp(), rec_init_offsets_temp(),
rec_convert_dtuple_to_temp(): Add the parameter 'status'.
REC_INFO_DEFAULT_ROW = REC_INFO_MIN_REC_FLAG | REC_STATUS_COLUMNS_ADDED:
An info_bits constant for distinguishing the 'default row' record.
rec_comp_status_t: An enum of the status bit values.
rec_leaf_format: An enum that replaces the bool parameter of
rec_init_offsets_comp_ordinary().
2017-10-06 06:00:05 +02:00
|
|
|
case FIL_PAGE_TYPE_INSTANT:
|
2016-08-12 10:17:45 +02:00
|
|
|
case FIL_PAGE_RTREE:
|
|
|
|
if (page_is_comp(block->frame)) {
|
|
|
|
if (page_simple_validate_new(block->frame)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (page_simple_validate_old(block->frame)) {
|
|
|
|
return;
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
2016-08-12 10:17:45 +02:00
|
|
|
/* While it is possible that this is not an index page
|
|
|
|
but just happens to have wrongly set FIL_PAGE_TYPE,
|
|
|
|
such pages should never be modified to without also
|
|
|
|
adjusting the page type during page allocation or
|
2018-10-29 10:26:23 +01:00
|
|
|
buf_flush_init_for_writing() or fil_block_reset_type(). */
|
2016-08-12 10:17:45 +02:00
|
|
|
break;
|
|
|
|
case FIL_PAGE_TYPE_FSP_HDR:
|
|
|
|
case FIL_PAGE_IBUF_BITMAP:
|
|
|
|
case FIL_PAGE_TYPE_UNKNOWN:
|
|
|
|
/* Do not complain again, we already reset this field. */
|
|
|
|
case FIL_PAGE_UNDO_LOG:
|
|
|
|
case FIL_PAGE_INODE:
|
|
|
|
case FIL_PAGE_IBUF_FREE_LIST:
|
|
|
|
case FIL_PAGE_TYPE_SYS:
|
|
|
|
case FIL_PAGE_TYPE_TRX_SYS:
|
|
|
|
case FIL_PAGE_TYPE_XDES:
|
|
|
|
case FIL_PAGE_TYPE_BLOB:
|
|
|
|
case FIL_PAGE_TYPE_ZBLOB:
|
|
|
|
case FIL_PAGE_TYPE_ZBLOB2:
|
|
|
|
/* TODO: validate also non-index pages */
|
|
|
|
return;
|
|
|
|
case FIL_PAGE_TYPE_ALLOCATED:
|
|
|
|
/* empty pages should never be flushed */
|
|
|
|
return;
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
2016-08-12 10:17:45 +02:00
|
|
|
|
|
|
|
buf_dblwr_assert_on_corrupt_block(block);
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************//**
|
|
|
|
Writes a page that has already been written to the doublewrite buffer
|
|
|
|
to the datafile. It is the job of the caller to sync the datafile. */
|
|
|
|
static
|
|
|
|
void
|
|
|
|
buf_dblwr_write_block_to_datafile(
|
|
|
|
/*==============================*/
|
|
|
|
const buf_page_t* bpage, /*!< in: page to write */
|
|
|
|
bool sync) /*!< in: true if sync IO
|
|
|
|
is requested */
|
|
|
|
{
|
|
|
|
ut_a(buf_page_in_file(bpage));
|
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
ulint type = IORequest::WRITE;
|
|
|
|
|
|
|
|
if (sync) {
|
|
|
|
type |= IORequest::DO_NOT_WAKE;
|
|
|
|
}
|
|
|
|
|
MDEV-11254: innodb-use-trim has no effect in 10.2
Problem was that implementation merged from 10.1 was incompatible
with InnoDB 5.7.
buf0buf.cc: Add functions to return should we punch hole and
how big.
buf0flu.cc: Add written page to IORequest
fil0fil.cc: Remove unneeded status call and add test is
sparse files and punch hole supported by file system when
tablespace is created. Add call to get file system
block size. Used file node is added to IORequest. Added
functions to check is punch hole supported and setting
punch hole.
ha_innodb.cc: Remove unneeded status variables (trim512-32768)
and trim_op_saved. Deprecate innodb_use_trim and
set it ON by default. Add function to set innodb-use-trim
dynamically.
dberr.h: Add error code DB_IO_NO_PUNCH_HOLE
if punch hole operation fails.
fil0fil.h: Add punch_hole variable to fil_space_t and
block size to fil_node_t.
os0api.h: Header to helper functions on buf0buf.cc and
fil0fil.cc for os0file.h
os0file.h: Remove unneeded m_block_size from IORequest
and add bpage to IORequest to know actual size of
the block and m_fil_node to know tablespace file
system block size and does it support punch hole.
os0file.cc: Add function punch_hole() to IORequest
to do punch_hole operation,
get the file system block size and determine
does file system support sparse files (for punch hole).
page0size.h: remove implicit copy disable and
use this implicit copy to implement copy_from()
function.
buf0dblwr.cc, buf0flu.cc, buf0rea.cc, fil0fil.cc, fil0fil.h,
os0file.h, os0file.cc, log0log.cc, log0recv.cc:
Remove unneeded write_size parameter from fil_io
calls.
srv0mon.h, srv0srv.h, srv0mon.cc: Remove unneeded
trim512-trim32678 status variables. Removed
these from monitor tests.
2017-01-24 13:40:58 +01:00
|
|
|
IORequest request(type, const_cast<buf_page_t*>(bpage));
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
/* We request frame here to get correct buffer in case of
|
|
|
|
encryption and/or page compression */
|
2014-12-22 15:53:17 +01:00
|
|
|
void * frame = buf_page_get_frame(bpage);
|
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
if (bpage->zip.data != NULL) {
|
|
|
|
ut_ad(bpage->size.is_compressed());
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
fil_io(request, sync, bpage->id, bpage->size, 0,
|
|
|
|
bpage->size.physical(),
|
|
|
|
(void*) frame,
|
MDEV-11254: innodb-use-trim has no effect in 10.2
Problem was that implementation merged from 10.1 was incompatible
with InnoDB 5.7.
buf0buf.cc: Add functions to return should we punch hole and
how big.
buf0flu.cc: Add written page to IORequest
fil0fil.cc: Remove unneeded status call and add test is
sparse files and punch hole supported by file system when
tablespace is created. Add call to get file system
block size. Used file node is added to IORequest. Added
functions to check is punch hole supported and setting
punch hole.
ha_innodb.cc: Remove unneeded status variables (trim512-32768)
and trim_op_saved. Deprecate innodb_use_trim and
set it ON by default. Add function to set innodb-use-trim
dynamically.
dberr.h: Add error code DB_IO_NO_PUNCH_HOLE
if punch hole operation fails.
fil0fil.h: Add punch_hole variable to fil_space_t and
block size to fil_node_t.
os0api.h: Header to helper functions on buf0buf.cc and
fil0fil.cc for os0file.h
os0file.h: Remove unneeded m_block_size from IORequest
and add bpage to IORequest to know actual size of
the block and m_fil_node to know tablespace file
system block size and does it support punch hole.
os0file.cc: Add function punch_hole() to IORequest
to do punch_hole operation,
get the file system block size and determine
does file system support sparse files (for punch hole).
page0size.h: remove implicit copy disable and
use this implicit copy to implement copy_from()
function.
buf0dblwr.cc, buf0flu.cc, buf0rea.cc, fil0fil.cc, fil0fil.h,
os0file.h, os0file.cc, log0log.cc, log0recv.cc:
Remove unneeded write_size parameter from fil_io
calls.
srv0mon.h, srv0srv.h, srv0mon.cc: Remove unneeded
trim512-trim32678 status variables. Removed
these from monitor tests.
2017-01-24 13:40:58 +01:00
|
|
|
(void*) bpage);
|
2016-08-12 10:17:45 +02:00
|
|
|
} else {
|
|
|
|
ut_ad(!bpage->size.is_compressed());
|
|
|
|
|
|
|
|
/* Our IO API is common for both reads and writes and is
|
|
|
|
therefore geared towards a non-const parameter. */
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
buf_block_t* block = reinterpret_cast<buf_block_t*>(
|
|
|
|
const_cast<buf_page_t*>(bpage));
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
ut_a(buf_block_get_state(block) == BUF_BLOCK_FILE_PAGE);
|
|
|
|
buf_dblwr_check_page_lsn(block->frame);
|
|
|
|
|
|
|
|
fil_io(request,
|
MDEV-11254: innodb-use-trim has no effect in 10.2
Problem was that implementation merged from 10.1 was incompatible
with InnoDB 5.7.
buf0buf.cc: Add functions to return should we punch hole and
how big.
buf0flu.cc: Add written page to IORequest
fil0fil.cc: Remove unneeded status call and add test is
sparse files and punch hole supported by file system when
tablespace is created. Add call to get file system
block size. Used file node is added to IORequest. Added
functions to check is punch hole supported and setting
punch hole.
ha_innodb.cc: Remove unneeded status variables (trim512-32768)
and trim_op_saved. Deprecate innodb_use_trim and
set it ON by default. Add function to set innodb-use-trim
dynamically.
dberr.h: Add error code DB_IO_NO_PUNCH_HOLE
if punch hole operation fails.
fil0fil.h: Add punch_hole variable to fil_space_t and
block size to fil_node_t.
os0api.h: Header to helper functions on buf0buf.cc and
fil0fil.cc for os0file.h
os0file.h: Remove unneeded m_block_size from IORequest
and add bpage to IORequest to know actual size of
the block and m_fil_node to know tablespace file
system block size and does it support punch hole.
os0file.cc: Add function punch_hole() to IORequest
to do punch_hole operation,
get the file system block size and determine
does file system support sparse files (for punch hole).
page0size.h: remove implicit copy disable and
use this implicit copy to implement copy_from()
function.
buf0dblwr.cc, buf0flu.cc, buf0rea.cc, fil0fil.cc, fil0fil.h,
os0file.h, os0file.cc, log0log.cc, log0recv.cc:
Remove unneeded write_size parameter from fil_io
calls.
srv0mon.h, srv0srv.h, srv0mon.cc: Remove unneeded
trim512-trim32678 status variables. Removed
these from monitor tests.
2017-01-24 13:40:58 +01:00
|
|
|
sync, bpage->id, bpage->size, 0, bpage->real_size,
|
|
|
|
frame, block);
|
2016-08-12 10:17:45 +02:00
|
|
|
}
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************//**
|
|
|
|
Flushes possible buffered writes from the doublewrite memory buffer to disk,
|
|
|
|
and also wakes up the aio thread if simulated aio is used. It is very
|
|
|
|
important to call this function after a batch of writes has been posted,
|
|
|
|
and also when we may have to wait for a page latch! Otherwise a deadlock
|
|
|
|
of threads can occur. */
|
|
|
|
void
|
2017-04-25 14:39:06 +02:00
|
|
|
buf_dblwr_flush_buffered_writes()
|
2014-02-26 19:11:54 +01:00
|
|
|
{
|
|
|
|
byte* write_buf;
|
|
|
|
ulint first_free;
|
|
|
|
ulint len;
|
|
|
|
|
|
|
|
if (!srv_use_doublewrite_buf || buf_dblwr == NULL) {
|
|
|
|
/* Sync the writes to the disk. */
|
|
|
|
buf_dblwr_sync_datafiles();
|
2018-03-09 20:25:20 +01:00
|
|
|
/* Now we flush the data to disk (for example, with fsync) */
|
|
|
|
fil_flush_file_spaces(FIL_TYPE_TABLESPACE);
|
2014-02-26 19:11:54 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
ut_ad(!srv_read_only_mode);
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
try_again:
|
|
|
|
mutex_enter(&buf_dblwr->mutex);
|
|
|
|
|
|
|
|
/* Write first to doublewrite buffer blocks. We use synchronous
|
|
|
|
aio and thus know that file write has been completed when the
|
|
|
|
control returns. */
|
|
|
|
|
|
|
|
if (buf_dblwr->first_free == 0) {
|
|
|
|
|
|
|
|
mutex_exit(&buf_dblwr->mutex);
|
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
/* Wake possible simulated aio thread as there could be
|
|
|
|
system temporary tablespace pages active for flushing.
|
|
|
|
Note: system temporary tablespace pages are not scheduled
|
|
|
|
for doublewrite. */
|
|
|
|
os_aio_simulated_wake_handler_threads();
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buf_dblwr->batch_running) {
|
|
|
|
/* Another thread is running the batch right now. Wait
|
|
|
|
for it to finish. */
|
2016-08-12 10:17:45 +02:00
|
|
|
int64_t sig_count = os_event_reset(buf_dblwr->b_event);
|
2014-02-26 19:11:54 +01:00
|
|
|
mutex_exit(&buf_dblwr->mutex);
|
|
|
|
|
|
|
|
os_event_wait_low(buf_dblwr->b_event, sig_count);
|
|
|
|
goto try_again;
|
|
|
|
}
|
|
|
|
|
|
|
|
ut_ad(buf_dblwr->first_free == buf_dblwr->b_reserved);
|
|
|
|
|
|
|
|
/* Disallow anyone else to post to doublewrite buffer or to
|
|
|
|
start another batch of flushing. */
|
|
|
|
buf_dblwr->batch_running = true;
|
|
|
|
first_free = buf_dblwr->first_free;
|
|
|
|
|
|
|
|
/* Now safe to release the mutex. Note that though no other
|
|
|
|
thread is allowed to post to the doublewrite batch flushing
|
|
|
|
but any threads working on single page flushes are allowed
|
|
|
|
to proceed. */
|
|
|
|
mutex_exit(&buf_dblwr->mutex);
|
|
|
|
|
|
|
|
write_buf = buf_dblwr->write_buf;
|
|
|
|
|
|
|
|
for (ulint len2 = 0, i = 0;
|
|
|
|
i < buf_dblwr->first_free;
|
2018-04-27 12:49:25 +02:00
|
|
|
len2 += srv_page_size, i++) {
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
const buf_block_t* block;
|
|
|
|
|
|
|
|
block = (buf_block_t*) buf_dblwr->buf_block_arr[i];
|
|
|
|
|
|
|
|
if (buf_block_get_state(block) != BUF_BLOCK_FILE_PAGE
|
|
|
|
|| block->page.zip.data) {
|
|
|
|
/* No simple validate for compressed
|
|
|
|
pages exists. */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check that the actual page in the buffer pool is
|
|
|
|
not corrupt and the LSN values are sane. */
|
|
|
|
buf_dblwr_check_block(block);
|
|
|
|
|
|
|
|
/* Check that the page as written to the doublewrite
|
|
|
|
buffer has sane LSN values. */
|
|
|
|
buf_dblwr_check_page_lsn(write_buf + len2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write out the first block of the doublewrite buffer */
|
2018-04-27 13:26:43 +02:00
|
|
|
len = std::min<ulint>(TRX_SYS_DOUBLEWRITE_BLOCK_SIZE,
|
|
|
|
buf_dblwr->first_free) << srv_page_size_shift;
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
fil_io(IORequestWrite, true,
|
|
|
|
page_id_t(TRX_SYS_SPACE, buf_dblwr->block1), univ_page_size,
|
MDEV-11254: innodb-use-trim has no effect in 10.2
Problem was that implementation merged from 10.1 was incompatible
with InnoDB 5.7.
buf0buf.cc: Add functions to return should we punch hole and
how big.
buf0flu.cc: Add written page to IORequest
fil0fil.cc: Remove unneeded status call and add test is
sparse files and punch hole supported by file system when
tablespace is created. Add call to get file system
block size. Used file node is added to IORequest. Added
functions to check is punch hole supported and setting
punch hole.
ha_innodb.cc: Remove unneeded status variables (trim512-32768)
and trim_op_saved. Deprecate innodb_use_trim and
set it ON by default. Add function to set innodb-use-trim
dynamically.
dberr.h: Add error code DB_IO_NO_PUNCH_HOLE
if punch hole operation fails.
fil0fil.h: Add punch_hole variable to fil_space_t and
block size to fil_node_t.
os0api.h: Header to helper functions on buf0buf.cc and
fil0fil.cc for os0file.h
os0file.h: Remove unneeded m_block_size from IORequest
and add bpage to IORequest to know actual size of
the block and m_fil_node to know tablespace file
system block size and does it support punch hole.
os0file.cc: Add function punch_hole() to IORequest
to do punch_hole operation,
get the file system block size and determine
does file system support sparse files (for punch hole).
page0size.h: remove implicit copy disable and
use this implicit copy to implement copy_from()
function.
buf0dblwr.cc, buf0flu.cc, buf0rea.cc, fil0fil.cc, fil0fil.h,
os0file.h, os0file.cc, log0log.cc, log0recv.cc:
Remove unneeded write_size parameter from fil_io
calls.
srv0mon.h, srv0srv.h, srv0mon.cc: Remove unneeded
trim512-trim32678 status variables. Removed
these from monitor tests.
2017-01-24 13:40:58 +01:00
|
|
|
0, len, (void*) write_buf, NULL);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
if (buf_dblwr->first_free <= TRX_SYS_DOUBLEWRITE_BLOCK_SIZE) {
|
|
|
|
/* No unwritten pages in the second block. */
|
|
|
|
goto flush;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write out the second block of the doublewrite buffer. */
|
|
|
|
len = (buf_dblwr->first_free - TRX_SYS_DOUBLEWRITE_BLOCK_SIZE)
|
2018-04-27 13:26:43 +02:00
|
|
|
<< srv_page_size_shift;
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
write_buf = buf_dblwr->write_buf
|
2018-04-27 13:26:43 +02:00
|
|
|
+ (TRX_SYS_DOUBLEWRITE_BLOCK_SIZE << srv_page_size_shift);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
fil_io(IORequestWrite, true,
|
|
|
|
page_id_t(TRX_SYS_SPACE, buf_dblwr->block2), univ_page_size,
|
MDEV-11254: innodb-use-trim has no effect in 10.2
Problem was that implementation merged from 10.1 was incompatible
with InnoDB 5.7.
buf0buf.cc: Add functions to return should we punch hole and
how big.
buf0flu.cc: Add written page to IORequest
fil0fil.cc: Remove unneeded status call and add test is
sparse files and punch hole supported by file system when
tablespace is created. Add call to get file system
block size. Used file node is added to IORequest. Added
functions to check is punch hole supported and setting
punch hole.
ha_innodb.cc: Remove unneeded status variables (trim512-32768)
and trim_op_saved. Deprecate innodb_use_trim and
set it ON by default. Add function to set innodb-use-trim
dynamically.
dberr.h: Add error code DB_IO_NO_PUNCH_HOLE
if punch hole operation fails.
fil0fil.h: Add punch_hole variable to fil_space_t and
block size to fil_node_t.
os0api.h: Header to helper functions on buf0buf.cc and
fil0fil.cc for os0file.h
os0file.h: Remove unneeded m_block_size from IORequest
and add bpage to IORequest to know actual size of
the block and m_fil_node to know tablespace file
system block size and does it support punch hole.
os0file.cc: Add function punch_hole() to IORequest
to do punch_hole operation,
get the file system block size and determine
does file system support sparse files (for punch hole).
page0size.h: remove implicit copy disable and
use this implicit copy to implement copy_from()
function.
buf0dblwr.cc, buf0flu.cc, buf0rea.cc, fil0fil.cc, fil0fil.h,
os0file.h, os0file.cc, log0log.cc, log0recv.cc:
Remove unneeded write_size parameter from fil_io
calls.
srv0mon.h, srv0srv.h, srv0mon.cc: Remove unneeded
trim512-trim32678 status variables. Removed
these from monitor tests.
2017-01-24 13:40:58 +01:00
|
|
|
0, len, (void*) write_buf, NULL);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
flush:
|
|
|
|
/* increment the doublewrite flushed pages counter */
|
|
|
|
srv_stats.dblwr_pages_written.add(buf_dblwr->first_free);
|
|
|
|
srv_stats.dblwr_writes.inc();
|
|
|
|
|
|
|
|
/* Now flush the doublewrite buffer data to disk */
|
|
|
|
fil_flush(TRX_SYS_SPACE);
|
|
|
|
|
|
|
|
/* We know that the writes have been flushed to disk now
|
|
|
|
and in recovery we will find them in the doublewrite buffer
|
|
|
|
blocks. Next do the writes to the intended positions. */
|
|
|
|
|
|
|
|
/* Up to this point first_free and buf_dblwr->first_free are
|
|
|
|
same because we have set the buf_dblwr->batch_running flag
|
|
|
|
disallowing any other thread to post any request but we
|
|
|
|
can't safely access buf_dblwr->first_free in the loop below.
|
|
|
|
This is so because it is possible that after we are done with
|
|
|
|
the last iteration and before we terminate the loop, the batch
|
|
|
|
gets finished in the IO helper thread and another thread posts
|
|
|
|
a new batch setting buf_dblwr->first_free to a higher value.
|
|
|
|
If this happens and we are using buf_dblwr->first_free in the
|
|
|
|
loop termination condition then we'll end up dispatching
|
|
|
|
the same block twice from two different threads. */
|
|
|
|
ut_ad(first_free == buf_dblwr->first_free);
|
|
|
|
for (ulint i = 0; i < first_free; i++) {
|
|
|
|
buf_dblwr_write_block_to_datafile(
|
|
|
|
buf_dblwr->buf_block_arr[i], false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Wake possible simulated aio thread to actually post the
|
|
|
|
writes to the operating system. We don't flush the files
|
|
|
|
at this point. We leave it to the IO helper thread to flush
|
|
|
|
datafiles when the whole batch has been processed. */
|
|
|
|
os_aio_simulated_wake_handler_threads();
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************//**
|
|
|
|
Posts a buffer page for writing. If the doublewrite memory buffer is
|
|
|
|
full, calls buf_dblwr_flush_buffered_writes and waits for for free
|
|
|
|
space to appear. */
|
|
|
|
void
|
|
|
|
buf_dblwr_add_to_batch(
|
|
|
|
/*====================*/
|
|
|
|
buf_page_t* bpage) /*!< in: buffer block to write */
|
|
|
|
{
|
|
|
|
ut_a(buf_page_in_file(bpage));
|
|
|
|
|
|
|
|
try_again:
|
|
|
|
mutex_enter(&buf_dblwr->mutex);
|
|
|
|
|
|
|
|
ut_a(buf_dblwr->first_free <= srv_doublewrite_batch_size);
|
|
|
|
|
|
|
|
if (buf_dblwr->batch_running) {
|
|
|
|
|
|
|
|
/* This not nearly as bad as it looks. There is only
|
|
|
|
page_cleaner thread which does background flushing
|
|
|
|
in batches therefore it is unlikely to be a contention
|
|
|
|
point. The only exception is when a user thread is
|
|
|
|
forced to do a flush batch because of a sync
|
|
|
|
checkpoint. */
|
2016-08-12 10:17:45 +02:00
|
|
|
int64_t sig_count = os_event_reset(buf_dblwr->b_event);
|
2014-02-26 19:11:54 +01:00
|
|
|
mutex_exit(&buf_dblwr->mutex);
|
|
|
|
|
|
|
|
os_event_wait_low(buf_dblwr->b_event, sig_count);
|
|
|
|
goto try_again;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buf_dblwr->first_free == srv_doublewrite_batch_size) {
|
|
|
|
mutex_exit(&(buf_dblwr->mutex));
|
|
|
|
|
|
|
|
buf_dblwr_flush_buffered_writes();
|
|
|
|
|
|
|
|
goto try_again;
|
|
|
|
}
|
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
byte* p = buf_dblwr->write_buf
|
2018-04-27 12:49:25 +02:00
|
|
|
+ srv_page_size * buf_dblwr->first_free;
|
2016-08-12 10:17:45 +02:00
|
|
|
|
|
|
|
/* We request frame here to get correct buffer in case of
|
|
|
|
encryption and/or page compression */
|
2014-12-22 15:53:17 +01:00
|
|
|
void * frame = buf_page_get_frame(bpage);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
if (bpage->size.is_compressed()) {
|
|
|
|
UNIV_MEM_ASSERT_RW(bpage->zip.data, bpage->size.physical());
|
2014-02-26 19:11:54 +01:00
|
|
|
/* Copy the compressed page and clear the rest. */
|
2016-08-12 10:17:45 +02:00
|
|
|
|
|
|
|
memcpy(p, frame, bpage->size.physical());
|
|
|
|
|
|
|
|
memset(p + bpage->size.physical(), 0x0,
|
2018-04-27 12:49:25 +02:00
|
|
|
srv_page_size - bpage->size.physical());
|
2014-02-26 19:11:54 +01:00
|
|
|
} else {
|
|
|
|
ut_a(buf_page_get_state(bpage) == BUF_BLOCK_FILE_PAGE);
|
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
UNIV_MEM_ASSERT_RW(frame,
|
|
|
|
bpage->size.logical());
|
|
|
|
|
|
|
|
memcpy(p, frame, bpage->size.logical());
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
buf_dblwr->buf_block_arr[buf_dblwr->first_free] = bpage;
|
|
|
|
|
|
|
|
buf_dblwr->first_free++;
|
|
|
|
buf_dblwr->b_reserved++;
|
|
|
|
|
|
|
|
ut_ad(!buf_dblwr->batch_running);
|
|
|
|
ut_ad(buf_dblwr->first_free == buf_dblwr->b_reserved);
|
|
|
|
ut_ad(buf_dblwr->b_reserved <= srv_doublewrite_batch_size);
|
|
|
|
|
|
|
|
if (buf_dblwr->first_free == srv_doublewrite_batch_size) {
|
|
|
|
mutex_exit(&(buf_dblwr->mutex));
|
|
|
|
|
|
|
|
buf_dblwr_flush_buffered_writes();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_exit(&(buf_dblwr->mutex));
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************//**
|
|
|
|
Writes a page to the doublewrite buffer on disk, sync it, then write
|
|
|
|
the page to the datafile and sync the datafile. This function is used
|
|
|
|
for single page flushes. If all the buffers allocated for single page
|
|
|
|
flushes in the doublewrite buffer are in use we wait here for one to
|
|
|
|
become free. We are guaranteed that a slot will become free because any
|
|
|
|
thread that is using a slot must also release the slot before leaving
|
|
|
|
this function. */
|
|
|
|
void
|
|
|
|
buf_dblwr_write_single_page(
|
|
|
|
/*========================*/
|
|
|
|
buf_page_t* bpage, /*!< in: buffer block to write */
|
|
|
|
bool sync) /*!< in: true if sync IO requested */
|
|
|
|
{
|
|
|
|
ulint n_slots;
|
|
|
|
ulint size;
|
|
|
|
ulint offset;
|
|
|
|
ulint i;
|
|
|
|
|
|
|
|
ut_a(buf_page_in_file(bpage));
|
|
|
|
ut_a(srv_use_doublewrite_buf);
|
|
|
|
ut_a(buf_dblwr != NULL);
|
|
|
|
|
|
|
|
/* total number of slots available for single page flushes
|
|
|
|
starts from srv_doublewrite_batch_size to the end of the
|
|
|
|
buffer. */
|
2014-12-22 15:53:17 +01:00
|
|
|
size = TRX_SYS_DOUBLEWRITE_BLOCKS * TRX_SYS_DOUBLEWRITE_BLOCK_SIZE;
|
2014-02-26 19:11:54 +01:00
|
|
|
ut_a(size > srv_doublewrite_batch_size);
|
|
|
|
n_slots = size - srv_doublewrite_batch_size;
|
|
|
|
|
|
|
|
if (buf_page_get_state(bpage) == BUF_BLOCK_FILE_PAGE) {
|
|
|
|
|
|
|
|
/* Check that the actual page in the buffer pool is
|
|
|
|
not corrupt and the LSN values are sane. */
|
|
|
|
buf_dblwr_check_block((buf_block_t*) bpage);
|
|
|
|
|
|
|
|
/* Check that the page as written to the doublewrite
|
|
|
|
buffer has sane LSN values. */
|
|
|
|
if (!bpage->zip.data) {
|
|
|
|
buf_dblwr_check_page_lsn(
|
|
|
|
((buf_block_t*) bpage)->frame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
retry:
|
|
|
|
mutex_enter(&buf_dblwr->mutex);
|
|
|
|
if (buf_dblwr->s_reserved == n_slots) {
|
|
|
|
|
|
|
|
/* All slots are reserved. */
|
2016-08-12 10:17:45 +02:00
|
|
|
int64_t sig_count = os_event_reset(buf_dblwr->s_event);
|
2014-02-26 19:11:54 +01:00
|
|
|
mutex_exit(&buf_dblwr->mutex);
|
|
|
|
os_event_wait_low(buf_dblwr->s_event, sig_count);
|
|
|
|
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = srv_doublewrite_batch_size; i < size; ++i) {
|
|
|
|
|
|
|
|
if (!buf_dblwr->in_use[i]) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We are guaranteed to find a slot. */
|
|
|
|
ut_a(i < size);
|
|
|
|
buf_dblwr->in_use[i] = true;
|
|
|
|
buf_dblwr->s_reserved++;
|
|
|
|
buf_dblwr->buf_block_arr[i] = bpage;
|
|
|
|
|
|
|
|
/* increment the doublewrite flushed pages counter */
|
|
|
|
srv_stats.dblwr_pages_written.inc();
|
|
|
|
srv_stats.dblwr_writes.inc();
|
|
|
|
|
|
|
|
mutex_exit(&buf_dblwr->mutex);
|
|
|
|
|
|
|
|
/* Lets see if we are going to write in the first or second
|
|
|
|
block of the doublewrite buffer. */
|
|
|
|
if (i < TRX_SYS_DOUBLEWRITE_BLOCK_SIZE) {
|
|
|
|
offset = buf_dblwr->block1 + i;
|
|
|
|
} else {
|
|
|
|
offset = buf_dblwr->block2 + i
|
|
|
|
- TRX_SYS_DOUBLEWRITE_BLOCK_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We deal with compressed and uncompressed pages a little
|
|
|
|
differently here. In case of uncompressed pages we can
|
|
|
|
directly write the block to the allocated slot in the
|
|
|
|
doublewrite buffer in the system tablespace and then after
|
|
|
|
syncing the system table space we can proceed to write the page
|
|
|
|
in the datafile.
|
|
|
|
In case of compressed page we first do a memcpy of the block
|
|
|
|
to the in-memory buffer of doublewrite before proceeding to
|
|
|
|
write it. This is so because we want to pad the remaining
|
|
|
|
bytes in the doublewrite page with zeros. */
|
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
/* We request frame here to get correct buffer in case of
|
|
|
|
encryption and/or page compression */
|
2014-12-22 15:53:17 +01:00
|
|
|
void * frame = buf_page_get_frame(bpage);
|
|
|
|
|
2016-08-12 10:17:45 +02:00
|
|
|
if (bpage->size.is_compressed()) {
|
2018-04-27 12:49:25 +02:00
|
|
|
memcpy(buf_dblwr->write_buf + srv_page_size * i,
|
2016-08-12 10:17:45 +02:00
|
|
|
frame, bpage->size.physical());
|
|
|
|
|
2018-04-27 12:49:25 +02:00
|
|
|
memset(buf_dblwr->write_buf + srv_page_size * i
|
2016-08-12 10:17:45 +02:00
|
|
|
+ bpage->size.physical(), 0x0,
|
2018-04-27 12:49:25 +02:00
|
|
|
srv_page_size - bpage->size.physical());
|
2016-08-12 10:17:45 +02:00
|
|
|
|
|
|
|
fil_io(IORequestWrite,
|
|
|
|
true,
|
|
|
|
page_id_t(TRX_SYS_SPACE, offset),
|
|
|
|
univ_page_size,
|
|
|
|
0,
|
2018-04-27 12:49:25 +02:00
|
|
|
srv_page_size,
|
|
|
|
(void *)(buf_dblwr->write_buf + srv_page_size * i),
|
2016-08-12 10:17:45 +02:00
|
|
|
NULL);
|
2014-02-26 19:11:54 +01:00
|
|
|
} else {
|
|
|
|
/* It is a regular page. Write it directly to the
|
|
|
|
doublewrite buffer */
|
2016-08-12 10:17:45 +02:00
|
|
|
fil_io(IORequestWrite,
|
|
|
|
true,
|
|
|
|
page_id_t(TRX_SYS_SPACE, offset),
|
|
|
|
univ_page_size,
|
|
|
|
0,
|
2018-04-27 12:49:25 +02:00
|
|
|
srv_page_size,
|
2016-08-12 10:17:45 +02:00
|
|
|
(void*) frame,
|
|
|
|
NULL);
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Now flush the doublewrite buffer data to disk */
|
|
|
|
fil_flush(TRX_SYS_SPACE);
|
|
|
|
|
|
|
|
/* We know that the write has been flushed to disk now
|
|
|
|
and during recovery we will find it in the doublewrite buffer
|
|
|
|
blocks. Next do the write to the intended position. */
|
|
|
|
buf_dblwr_write_block_to_datafile(bpage, sync);
|
|
|
|
}
|