1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

MDEV-33545: Improve innodb_doublewrite to cover NO_FSYNC

In commit 24648768b4 (MDEV-30136)
the parameter innodb_flush_method was deprecated, with no direct
replacement for innodb_flush_method=O_DIRECT_NO_FSYNC.

Let us change innodb_doublewrite from Boolean to ENUM that can
be changed while the server is running:

OFF: Assume that writes of innodb_page_size are atomic
ON: Prevent torn writes (the default)
fast: Like ON, but avoid synchronizing writes to data files

The deprecated start-up parameter innodb_flush_method=NO_FSYNC will cause
innodb_doublewrite=ON to be changed to innodb_doublewrite=fast,
which will prevent InnoDB from making any durable writes to data files.
This would normally be done right before the log checkpoint LSN is updated.
Depending on the file systems being used and their configuration,
this may or may not be safe.

The value innodb_doublewrite=fast differs from the previous combination of
innodb_doublewrite=ON and innodb_flush_method=O_DIRECT_NO_FSYNC by always
invoking os_file_flush() on the doublewrite buffer itself
in buf_dblwr_t::flush_buffered_writes_completed(). This should be safer
when there are multiple doublewrite batches between checkpoints.
Typically, once per second, buf_flush_page_cleaner() would write out
up to innodb_io_capacity pages and advance the log checkpoint.
Also typically, innodb_io_capacity>128, which is the size of the
doublewrite buffer in pages. Should os_file_flush_func() not be invoked
between doublewrite batches, writes could be reordered in an unsafe way.

The setting innodb_doublewrite=fast could be safe when the doublewrite
buffer (the first file of the system tablespace) and the data files
reside in the same file system.

This was tested by running "./mtr --rr innodb.alter_kill". On the first
server startup, with innodb_doublewrite=fast, os_file_flush_func()
would only be invoked on the ibdata1 file and possibly ib_logfile0.
On subsequent startups with innodb_doublewrite=OFF, os_file_flush_func()
will be invoked on the individual data files during log_checkpoint().

Note: The setting debug_no_sync (in the code, my_disable_sync) would
disable all durable writes to InnoDB files, which would be much less safe.

IORequest::Type: Introduce special values WRITE_DBL and PUNCH_DBL
for asynchronous writes that are submitted via the doublewrite buffer.
In this way, fil_space_t::use_doublewrite() or buf_dblwr.in_use()
will only be consulted during buf_page_t::flush() and the doublewrite
buffer can be enabled or disabled without any fear of inconsistency.

buf_dblwr_t::block_size: Replaces block_size().

buf_dblwr_t::flush_buffered_writes(): If !in_use() and the doublewrite
buffer is empty, just invoke fil_flush_file_spaces() and return. The
doublewrite buffer could have been disabled while a batch was in
progress.

innodb_init_params(): If innodb_flush_method=O_DIRECT_NO_FSYNC,
set innodb_doublewrite=fast or innodb_doublewrite=fearless.

Thanks to Mark Callaghan for reporting this, and Vladislav Vaintroub
for feedback.
This commit is contained in:
Marko Mäkelä
2024-04-04 08:12:54 +03:00
parent fec2fd6add
commit 1122ac978e
18 changed files with 193 additions and 172 deletions

View File

@@ -1,75 +1,20 @@
################## mysql-test\t\innodb_doublewrite_basic.test #################
# #
# Variable Name: innodb_doublewrite #
# Scope: Global #
# Access Type: Static #
# Data Type: boolean #
# #
# #
# Creation Date: 2008-02-07 #
# Author : Sharique Abdullah #
# #
# #
# Description:Test Cases of Dynamic System Variable innodb_doublewrite #
# that checks the behavior of this variable in the following ways #
# * Value Check #
# * Scope Check #
# #
# Reference: http://dev.mysql.com/doc/refman/5.1/en/ #
# server-system-variables.html #
# #
###############################################################################
--source include/have_innodb.inc
--echo '#---------------------BS_STVARS_026_01----------------------#'
####################################################################
# Displaying default value #
####################################################################
SELECT COUNT(@@GLOBAL.innodb_doublewrite);
--echo 1 Expected
SELECT @@GLOBAL.innodb_doublewrite;
SET @@GLOBAL.innodb_doublewrite=0;
SELECT @@GLOBAL.innodb_doublewrite;
--echo '#---------------------BS_STVARS_026_02----------------------#'
####################################################################
# Check if Value can set #
####################################################################
--error ER_INCORRECT_GLOBAL_LOCAL_VAR
SET @@GLOBAL.innodb_doublewrite=2;
--error ER_WRONG_VALUE_FOR_VAR
SET @@GLOBAL.innodb_doublewrite=3;
SELECT @@GLOBAL.innodb_doublewrite;
SET @@GLOBAL.innodb_doublewrite=1;
--echo Expected error 'Read only variable'
SELECT @@GLOBAL.innodb_doublewrite;
SELECT COUNT(@@GLOBAL.innodb_doublewrite);
--echo 1 Expected
--echo '#---------------------BS_STVARS_026_03----------------------#'
#################################################################
# Check if the value in GLOBAL Table matches value in variable #
#################################################################
--disable_warnings
SELECT IF(@@GLOBAL.innodb_doublewrite, "ON", "OFF") = VARIABLE_VALUE
SELECT COUNT(VARIABLE_VALUE)
FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
WHERE VARIABLE_NAME='innodb_doublewrite';
--enable_warnings
--echo 1 Expected
SELECT COUNT(@@GLOBAL.innodb_doublewrite);
--echo 1 Expected
--disable_warnings
SELECT COUNT(VARIABLE_VALUE)
FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
WHERE VARIABLE_NAME='innodb_doublewrite';
--enable_warnings
--echo 1 Expected
--echo '#---------------------BS_STVARS_026_04----------------------#'
################################################################################
@@ -78,8 +23,6 @@ WHERE VARIABLE_NAME='innodb_doublewrite';
SELECT @@innodb_doublewrite = @@GLOBAL.innodb_doublewrite;
--echo 1 Expected
--echo '#---------------------BS_STVARS_026_05----------------------#'
################################################################################
# Check if innodb_doublewrite can be accessed with and without @@ sign #
@@ -99,8 +42,5 @@ SELECT COUNT(@@SESSION.innodb_doublewrite);
SELECT COUNT(@@GLOBAL.innodb_doublewrite);
--echo 1 Expected
--Error ER_BAD_FIELD_ERROR
SELECT innodb_doublewrite = @@SESSION.innodb_doublewrite;
--echo Expected error 'Readonly variable'
--error ER_INCORRECT_GLOBAL_LOCAL_VAR
SELECT @@innodb_doublewrite = @@SESSION.innodb_doublewrite;