2014-02-26 19:11:54 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
|
2017-05-15 17:17:16 +03:00
|
|
|
Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved.
|
2014-02-26 19:11:54 +01:00
|
|
|
Copyright (c) 2008, Google Inc.
|
|
|
|
Copyright (c) 2009, Percona Inc.
|
2018-01-10 13:18:02 +02:00
|
|
|
Copyright (c) 2013, 2018, MariaDB Corporation.
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
Portions of this file contain modifications contributed and copyrighted by
|
|
|
|
Google, Inc. Those modifications are gratefully acknowledged and are described
|
|
|
|
briefly in the InnoDB documentation. The contributions by Google are
|
|
|
|
incorporated with their permission, and subject to the conditions contained in
|
|
|
|
the file COPYING.Google.
|
|
|
|
|
|
|
|
Portions of this file contain modifications contributed and copyrighted
|
|
|
|
by Percona Inc.. Those modifications are
|
|
|
|
gratefully acknowledged and are described briefly in the InnoDB
|
|
|
|
documentation. The contributions by Percona Inc. are incorporated with
|
|
|
|
their permission, and subject to the conditions contained in the file
|
|
|
|
COPYING.Percona.
|
|
|
|
|
|
|
|
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 srv/srv0start.cc
|
|
|
|
Starts the InnoDB database server
|
|
|
|
|
|
|
|
Created 2/16/1996 Heikki Tuuri
|
|
|
|
*************************************************************************/
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
#include "my_global.h"
|
|
|
|
|
|
|
|
#include "ha_prototypes.h"
|
|
|
|
|
2014-02-26 19:23:04 +01:00
|
|
|
#include "mysqld.h"
|
2016-08-12 11:17:45 +03:00
|
|
|
#include "mysql/psi/mysql_stage.h"
|
|
|
|
#include "mysql/psi/psi.h"
|
|
|
|
|
2014-02-26 19:23:04 +01:00
|
|
|
#include "row0ftsort.h"
|
2014-02-26 19:11:54 +01:00
|
|
|
#include "ut0mem.h"
|
2014-08-06 15:28:58 +03:00
|
|
|
#include "ut0timer.h"
|
2014-02-26 19:11:54 +01:00
|
|
|
#include "mem0mem.h"
|
|
|
|
#include "data0data.h"
|
|
|
|
#include "data0type.h"
|
|
|
|
#include "dict0dict.h"
|
|
|
|
#include "buf0buf.h"
|
|
|
|
#include "buf0dump.h"
|
|
|
|
#include "os0file.h"
|
|
|
|
#include "os0thread.h"
|
|
|
|
#include "fil0fil.h"
|
2015-04-01 11:50:21 +03:00
|
|
|
#include "fil0crypt.h"
|
2014-02-26 19:11:54 +01:00
|
|
|
#include "fsp0fsp.h"
|
|
|
|
#include "rem0rec.h"
|
|
|
|
#include "mtr0mtr.h"
|
2017-02-10 12:11:42 +02:00
|
|
|
#include "log0crypt.h"
|
2014-02-26 19:11:54 +01:00
|
|
|
#include "log0recv.h"
|
|
|
|
#include "page0page.h"
|
|
|
|
#include "page0cur.h"
|
|
|
|
#include "trx0trx.h"
|
|
|
|
#include "trx0sys.h"
|
|
|
|
#include "btr0btr.h"
|
|
|
|
#include "btr0cur.h"
|
|
|
|
#include "rem0rec.h"
|
|
|
|
#include "ibuf0ibuf.h"
|
|
|
|
#include "srv0start.h"
|
|
|
|
#include "srv0srv.h"
|
2014-08-06 15:28:58 +03:00
|
|
|
#include "btr0defragment.h"
|
2016-08-12 11:17:45 +03:00
|
|
|
#include "fsp0sysspace.h"
|
|
|
|
#include "row0trunc.h"
|
2017-08-31 08:27:59 +03:00
|
|
|
#include "mysql/service_wsrep.h" /* wsrep_recovery */
|
2016-12-30 15:04:10 +02:00
|
|
|
#include "trx0rseg.h"
|
|
|
|
#include "os0proc.h"
|
|
|
|
#include "buf0flu.h"
|
|
|
|
#include "buf0rea.h"
|
|
|
|
#include "dict0boot.h"
|
|
|
|
#include "dict0load.h"
|
|
|
|
#include "dict0stats_bg.h"
|
|
|
|
#include "que0que.h"
|
|
|
|
#include "lock0lock.h"
|
|
|
|
#include "trx0roll.h"
|
|
|
|
#include "trx0purge.h"
|
|
|
|
#include "lock0lock.h"
|
|
|
|
#include "pars0pars.h"
|
|
|
|
#include "btr0sea.h"
|
|
|
|
#include "rem0cmp.h"
|
|
|
|
#include "dict0crea.h"
|
|
|
|
#include "row0ins.h"
|
|
|
|
#include "row0sel.h"
|
|
|
|
#include "row0upd.h"
|
|
|
|
#include "row0row.h"
|
|
|
|
#include "row0mysql.h"
|
|
|
|
#include "row0trunc.h"
|
|
|
|
#include "btr0pcur.h"
|
|
|
|
#include "os0event.h"
|
|
|
|
#include "zlib.h"
|
|
|
|
#include "ut0crc32.h"
|
|
|
|
#include "btr0scrub.h"
|
|
|
|
#include "ut0new.h"
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
#ifdef HAVE_LZO1X
|
|
|
|
#include <lzo/lzo1x.h>
|
|
|
|
extern bool srv_lzo_disabled;
|
|
|
|
#endif /* HAVE_LZO1X */
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
/** Log sequence number immediately after startup */
|
2016-08-12 11:17:45 +03:00
|
|
|
lsn_t srv_start_lsn;
|
2014-02-26 19:11:54 +01:00
|
|
|
/** Log sequence number at shutdown */
|
2016-08-12 11:17:45 +03:00
|
|
|
lsn_t srv_shutdown_lsn;
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
/** TRUE if a raw partition is in use */
|
2017-04-25 09:26:01 +03:00
|
|
|
ibool srv_start_raw_disk_in_use;
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
/** Number of IO threads to use */
|
2017-04-25 09:26:01 +03:00
|
|
|
ulint srv_n_file_io_threads;
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2017-05-15 17:17:16 +03:00
|
|
|
/** UNDO tablespaces starts with space id. */
|
|
|
|
ulint srv_undo_space_id_start;
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
/** TRUE if the server is being started, before rolling back any
|
|
|
|
incomplete transactions */
|
2017-04-25 09:26:01 +03:00
|
|
|
bool srv_startup_is_before_trx_rollback_phase;
|
2014-02-26 19:11:54 +01:00
|
|
|
/** TRUE if the server is being started */
|
2017-04-25 09:26:01 +03:00
|
|
|
bool srv_is_being_started;
|
2016-08-12 11:17:45 +03:00
|
|
|
/** TRUE if SYS_TABLESPACES is available for lookups */
|
2017-04-25 09:26:01 +03:00
|
|
|
bool srv_sys_tablespaces_open;
|
2014-02-26 19:11:54 +01:00
|
|
|
/** TRUE if the server was successfully started */
|
2017-04-25 09:26:01 +03:00
|
|
|
bool srv_was_started;
|
Reduce the granularity of innodb_log_file_size
In Mariabackup, we would want the backed-up redo log file size to be
a multiple of 512 bytes, or OS_FILE_LOG_BLOCK_SIZE. However, at startup,
InnoDB would be picky, requiring the file size to be a multiple of
innodb_page_size.
Furthermore, InnoDB would require the parameter to be a multiple of
one megabyte, while the minimum granularity is 512 bytes. Because
the data-file-oriented fil_io() API is being used for writing the
InnoDB redo log, writes will for now require innodb_log_file_size to
be a multiple of the maximum innodb_page_size (65536 bytes).
To complicate matters, InnoDB startup divided srv_log_file_size by
UNIV_PAGE_SIZE, so that initially, the unit was bytes, and later it
was innodb_page_size. We will simplify this and keep srv_log_file_size
in bytes at all times.
innobase_log_file_size: Remove. Remove some obsolete checks against
overflow on 32-bit systems. srv_log_file_size is always 64 bits, and
the maximum size 512GiB in multiples of innodb_page_size always fits
in ulint (which is 32 or 64 bits). 512GiB would be 8,388,608*64KiB or
134,217,728*4KiB.
log_init(): Remove the parameter file_size that was always passed as
srv_log_file_size.
log_set_capacity(): Add a parameter for passing the requested file size.
srv_log_file_size_requested: Declare static in srv0start.cc.
create_log_file(), create_log_files(),
innobase_start_or_create_for_mysql(): Invoke fil_node_create()
with srv_log_file_size expressed in multiples of innodb_page_size.
innobase_start_or_create_for_mysql(): Require the redo log file sizes
to be multiples of 512 bytes.
2017-06-05 22:47:20 +03:00
|
|
|
/** The original value of srv_log_file_size (innodb_log_file_size) */
|
|
|
|
static ulonglong srv_log_file_size_requested;
|
2014-02-26 19:11:54 +01:00
|
|
|
/** TRUE if innobase_start_or_create_for_mysql() has been called */
|
2017-06-12 17:43:07 +03:00
|
|
|
static bool srv_start_has_been_called;
|
MDEV-13039 innodb_fast_shutdown=0 may fail to purge all undo log
When a slow shutdown is performed soon after spawning some work for
background threads that can create or commit transactions, it is possible
that new transactions are started or committed after the purge has finished.
This is violating the specification of innodb_fast_shutdown=0, namely that
the purge must be completed. (None of the history of the recent transactions
would be purged.)
Also, it is possible that the purge threads would exit in slow shutdown
while there exist active transactions, such as recovered incomplete
transactions that are being rolled back. Thus, the slow shutdown could
fail to purge some undo log that becomes purgeable after the transaction
commit or rollback.
srv_undo_sources: A flag that indicates if undo log can be generated
or the persistent, whether by background threads or by user SQL.
Even when this flag is clear, active transactions that already exist
in the system may be committed or rolled back.
innodb_shutdown(): Renamed from innobase_shutdown_for_mysql().
Do not return an error code; the operation never fails.
Clear the srv_undo_sources flag, and also ensure that the background
DROP TABLE queue is empty.
srv_purge_should_exit(): Do not allow the purge to exit if
srv_undo_sources are active or the background DROP TABLE queue is not
empty, or in slow shutdown, if any active transactions exist
(and are being rolled back).
srv_purge_coordinator_thread(): Remove some previous workarounds
for this bug.
innobase_start_or_create_for_mysql(): Set buf_page_cleaner_is_active
and srv_dict_stats_thread_active directly. Set srv_undo_sources before
starting the purge subsystem, to prevent immediate shutdown of the purge.
Create dict_stats_thread and fts_optimize_thread immediately
after setting srv_undo_sources, so that shutdown can use this flag to
determine if these subsystems were started.
dict_stats_shutdown(): Shut down dict_stats_thread. Backported from 10.2.
srv_shutdown_table_bg_threads(): Remove (unused).
2017-06-08 15:43:06 +03:00
|
|
|
|
|
|
|
/** Whether any undo log records can be generated */
|
2017-06-12 14:26:32 +03:00
|
|
|
UNIV_INTERN bool srv_undo_sources;
|
|
|
|
|
MDEV-11556 InnoDB redo log apply fails to adjust data file sizes
fil_space_t::recv_size: New member: recovered tablespace size in pages;
0 if no size change was read from the redo log,
or if the size change was implemented.
fil_space_set_recv_size(): New function for setting space->recv_size.
innodb_data_file_size_debug: A debug parameter for setting the system
tablespace size in recovery even when the redo log does not contain
any size changes. It is hard to write a small test case that would
cause the system tablespace to be extended at the critical moment.
recv_parse_log_rec(): Note those tablespaces whose size is being changed
by the redo log, by invoking fil_space_set_recv_size().
innobase_init(): Correct an error message, and do not require a larger
innodb_buffer_pool_size when starting up with a smaller innodb_page_size.
innobase_start_or_create_for_mysql(): Allow startup with any initial
size of the ibdata1 file if the autoextend attribute is set. Require
the minimum size of fixed-size system tablespaces to be 640 pages,
not 10 megabytes. Implement innodb_data_file_size_debug.
open_or_create_data_files(): Round the system tablespace size down
to pages, not to full megabytes, (Our test truncates the system
tablespace to more than 800 pages with innodb_page_size=4k.
InnoDB should not imagine that it was truncated to 768 pages
and then overwrite good pages in the tablespace.)
fil_flush_low(): Refactored from fil_flush().
fil_space_extend_must_retry(): Refactored from
fil_extend_space_to_desired_size().
fil_mutex_enter_and_prepare_for_io(): Extend the tablespace if
fil_space_set_recv_size() was called.
The test case has been successfully run with all the
innodb_page_size values 4k, 8k, 16k, 32k, 64k.
2016-12-28 12:05:43 +02:00
|
|
|
#ifdef UNIV_DEBUG
|
|
|
|
/** InnoDB system tablespace to set during recovery */
|
2017-01-07 15:27:59 +02:00
|
|
|
UNIV_INTERN uint srv_sys_space_size_debug;
|
2017-06-28 11:58:43 +03:00
|
|
|
/** whether redo log files have been created at startup */
|
|
|
|
UNIV_INTERN bool srv_log_files_created;
|
MDEV-11556 InnoDB redo log apply fails to adjust data file sizes
fil_space_t::recv_size: New member: recovered tablespace size in pages;
0 if no size change was read from the redo log,
or if the size change was implemented.
fil_space_set_recv_size(): New function for setting space->recv_size.
innodb_data_file_size_debug: A debug parameter for setting the system
tablespace size in recovery even when the redo log does not contain
any size changes. It is hard to write a small test case that would
cause the system tablespace to be extended at the critical moment.
recv_parse_log_rec(): Note those tablespaces whose size is being changed
by the redo log, by invoking fil_space_set_recv_size().
innobase_init(): Correct an error message, and do not require a larger
innodb_buffer_pool_size when starting up with a smaller innodb_page_size.
innobase_start_or_create_for_mysql(): Allow startup with any initial
size of the ibdata1 file if the autoextend attribute is set. Require
the minimum size of fixed-size system tablespaces to be 640 pages,
not 10 megabytes. Implement innodb_data_file_size_debug.
open_or_create_data_files(): Round the system tablespace size down
to pages, not to full megabytes, (Our test truncates the system
tablespace to more than 800 pages with innodb_page_size=4k.
InnoDB should not imagine that it was truncated to 768 pages
and then overwrite good pages in the tablespace.)
fil_flush_low(): Refactored from fil_flush().
fil_space_extend_must_retry(): Refactored from
fil_extend_space_to_desired_size().
fil_mutex_enter_and_prepare_for_io(): Extend the tablespace if
fil_space_set_recv_size() was called.
The test case has been successfully run with all the
innodb_page_size values 4k, 8k, 16k, 32k, 64k.
2016-12-28 12:05:43 +02:00
|
|
|
#endif /* UNIV_DEBUG */
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
/** Bit flags for tracking background thread creation. They are used to
|
|
|
|
determine which threads need to be stopped if we need to abort during
|
|
|
|
the initialisation step. */
|
|
|
|
enum srv_start_state_t {
|
2017-06-08 15:43:06 +03:00
|
|
|
/** No thread started */
|
2016-08-12 11:17:45 +03:00
|
|
|
SRV_START_STATE_NONE = 0, /*!< No thread started */
|
2017-06-08 15:43:06 +03:00
|
|
|
/** lock_wait_timeout_thread started */
|
2016-08-12 11:17:45 +03:00
|
|
|
SRV_START_STATE_LOCK_SYS = 1, /*!< Started lock-timeout
|
|
|
|
thread. */
|
2017-06-08 15:43:06 +03:00
|
|
|
/** buf_flush_page_cleaner_coordinator,
|
|
|
|
buf_flush_page_cleaner_worker started */
|
|
|
|
SRV_START_STATE_IO = 2,
|
|
|
|
/** srv_error_monitor_thread, srv_monitor_thread started */
|
|
|
|
SRV_START_STATE_MONITOR = 4,
|
|
|
|
/** srv_master_thread started */
|
|
|
|
SRV_START_STATE_MASTER = 8,
|
|
|
|
/** srv_purge_coordinator_thread, srv_worker_thread started */
|
|
|
|
SRV_START_STATE_PURGE = 16,
|
|
|
|
/** fil_crypt_thread, btr_defragment_thread started
|
|
|
|
(all background threads that can generate redo log but not undo log */
|
|
|
|
SRV_START_STATE_REDO = 32
|
2016-08-12 11:17:45 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Track server thrd starting phases */
|
|
|
|
static ulint srv_start_state;
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
/** At a shutdown this value climbs from SRV_SHUTDOWN_NONE to
|
|
|
|
SRV_SHUTDOWN_CLEANUP and then to SRV_SHUTDOWN_LAST_PHASE, and so on */
|
2016-08-12 11:17:45 +03:00
|
|
|
enum srv_shutdown_t srv_shutdown_state = SRV_SHUTDOWN_NONE;
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
/** Files comprising the system tablespace */
|
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2
InnoDB I/O and buffer pool interfaces and the redo log format
have been changed between MariaDB 10.1 and 10.2, and the backup
code has to be adjusted accordingly.
The code has been simplified, and many memory leaks have been fixed.
Instead of the file name xtrabackup_logfile, the file name ib_logfile0
is being used for the copy of the redo log. Unnecessary InnoDB startup and
shutdown and some unnecessary threads have been removed.
Some help was provided by Vladislav Vaintroub.
Parameters have been cleaned up and aligned with those of MariaDB 10.2.
The --dbug option has been added, so that in debug builds,
--dbug=d,ib_log can be specified to enable diagnostic messages
for processing redo log entries.
By default, innodb_doublewrite=OFF, so that --prepare works faster.
If more crash-safety for --prepare is needed, double buffering
can be enabled.
The parameter innodb_log_checksums=OFF can be used to ignore redo log
checksums in --backup.
Some messages have been cleaned up.
Unless --export is specified, Mariabackup will not deal with undo log.
The InnoDB mini-transaction redo log is not only about user-level
transactions; it is actually about mini-transactions. To avoid confusion,
call it the redo log, not transaction log.
We disable any undo log processing in --prepare.
Because MariaDB 10.2 supports indexed virtual columns, the
undo log processing would need to be able to evaluate virtual column
expressions. To reduce the amount of code dependencies, we will not
process any undo log in prepare.
This means that the --export option must be disabled for now.
This also means that the following options are redundant
and have been removed:
xtrabackup --apply-log-only
innobackupex --redo-only
In addition to disabling any undo log processing, we will disable any
further changes to data pages during --prepare, including the change
buffer merge. This means that restoring incremental backups should
reliably work even when change buffering is being used on the server.
Because of this, preparing a backup will not generate any further
redo log, and the redo log file can be safely deleted. (If the
--export option is enabled in the future, it must generate redo log
when processing undo logs and buffered changes.)
In --prepare, we cannot easily know if a partial backup was used,
especially when restoring a series of incremental backups. So, we
simply warn about any missing files, and ignore the redo log for them.
FIXME: Enable the --export option.
FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write
a test that initiates a backup while an ALGORITHM=INPLACE operation
is creating indexes or rebuilding a table. An error should be detected
when preparing the backup.
FIXME: In --incremental --prepare, xtrabackup_apply_delta() should
ensure that if FSP_SIZE is modified, the file size will be adjusted
accordingly.
2017-06-30 10:49:37 +03:00
|
|
|
pfs_os_file_t files[1000];
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
/** io_handler_thread parameters for thread identification */
|
|
|
|
static ulint n[SRV_MAX_N_IO_THREADS + 6];
|
|
|
|
/** io_handler_thread identifiers, 32 is the maximum number of purge threads */
|
2014-02-04 14:52:02 +02:00
|
|
|
/** 6 is the ? */
|
|
|
|
#define START_OLD_THREAD_CNT (SRV_MAX_N_IO_THREADS + 6 + 32)
|
2017-09-01 18:33:46 +03:00
|
|
|
static os_thread_id_t thread_ids[SRV_MAX_N_IO_THREADS + 6 + 32];
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2015-01-06 16:08:42 +02:00
|
|
|
/** Thead handles */
|
|
|
|
static os_thread_t thread_handles[SRV_MAX_N_IO_THREADS + 6 + 32];
|
|
|
|
static os_thread_t buf_dump_thread_handle;
|
|
|
|
static os_thread_t dict_stats_thread_handle;
|
|
|
|
/** Status variables, is thread started ?*/
|
|
|
|
static bool thread_started[SRV_MAX_N_IO_THREADS + 6 + 32] = {false};
|
2014-02-26 19:11:54 +01:00
|
|
|
/** Name of srv_monitor_file */
|
|
|
|
static char* srv_monitor_file_name;
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/** Minimum expected tablespace size. (10M) */
|
|
|
|
static const ulint MIN_EXPECTED_TABLESPACE_SIZE = 5 * 1024 * 1024;
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
/** */
|
|
|
|
#define SRV_MAX_N_PENDING_SYNC_IOS 100
|
|
|
|
|
|
|
|
#ifdef UNIV_PFS_THREAD
|
|
|
|
/* Keys to register InnoDB threads with performance schema */
|
2016-08-12 11:17:45 +03:00
|
|
|
mysql_pfs_key_t buf_dump_thread_key;
|
|
|
|
mysql_pfs_key_t dict_stats_thread_key;
|
|
|
|
mysql_pfs_key_t io_handler_thread_key;
|
|
|
|
mysql_pfs_key_t io_ibuf_thread_key;
|
|
|
|
mysql_pfs_key_t io_log_thread_key;
|
|
|
|
mysql_pfs_key_t io_read_thread_key;
|
|
|
|
mysql_pfs_key_t io_write_thread_key;
|
|
|
|
mysql_pfs_key_t srv_error_monitor_thread_key;
|
|
|
|
mysql_pfs_key_t srv_lock_timeout_thread_key;
|
|
|
|
mysql_pfs_key_t srv_master_thread_key;
|
|
|
|
mysql_pfs_key_t srv_monitor_thread_key;
|
|
|
|
mysql_pfs_key_t srv_purge_thread_key;
|
2016-09-06 09:43:16 +03:00
|
|
|
mysql_pfs_key_t srv_worker_thread_key;
|
2014-02-26 19:11:54 +01:00
|
|
|
#endif /* UNIV_PFS_THREAD */
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
#ifdef HAVE_PSI_STAGE_INTERFACE
|
|
|
|
/** Array of all InnoDB stage events for monitoring activities via
|
|
|
|
performance schema. */
|
|
|
|
static PSI_stage_info* srv_stages[] =
|
2014-02-26 19:11:54 +01:00
|
|
|
{
|
2016-08-12 11:17:45 +03:00
|
|
|
&srv_stage_alter_table_end,
|
|
|
|
&srv_stage_alter_table_flush,
|
|
|
|
&srv_stage_alter_table_insert,
|
|
|
|
&srv_stage_alter_table_log_index,
|
|
|
|
&srv_stage_alter_table_log_table,
|
|
|
|
&srv_stage_alter_table_merge_sort,
|
|
|
|
&srv_stage_alter_table_read_pk_internal_sort,
|
|
|
|
&srv_stage_buffer_pool_load,
|
|
|
|
};
|
|
|
|
#endif /* HAVE_PSI_STAGE_INTERFACE */
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
/*********************************************************************//**
|
|
|
|
Check if a file can be opened in read-write mode.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return true if it doesn't exist or can be opened in rw mode. */
|
2014-02-26 19:11:54 +01:00
|
|
|
static
|
|
|
|
bool
|
|
|
|
srv_file_check_mode(
|
|
|
|
/*================*/
|
|
|
|
const char* name) /*!< in: filename to check */
|
|
|
|
{
|
|
|
|
os_file_stat_t stat;
|
|
|
|
|
|
|
|
memset(&stat, 0x0, sizeof(stat));
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
dberr_t err = os_file_get_status(
|
|
|
|
name, &stat, true, srv_read_only_mode);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
if (err == DB_FAIL) {
|
2016-08-12 11:17:45 +03:00
|
|
|
ib::error() << "os_file_get_status() failed on '" << name
|
|
|
|
<< "'. Can't determine file permissions.";
|
2014-02-26 19:11:54 +01:00
|
|
|
return(false);
|
|
|
|
|
|
|
|
} else if (err == DB_SUCCESS) {
|
|
|
|
|
|
|
|
/* Note: stat.rw_perm is only valid of files */
|
|
|
|
|
2015-06-16 10:57:05 +02:00
|
|
|
if (stat.type == OS_FILE_TYPE_FILE) {
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
if (!stat.rw_perm) {
|
2016-08-12 11:17:45 +03:00
|
|
|
const char* mode = srv_read_only_mode
|
|
|
|
? "read" : "read-write";
|
|
|
|
ib::error() << name << " can't be opened in "
|
|
|
|
<< mode << " mode.";
|
2014-02-26 19:11:54 +01:00
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Not a regular file, bail out. */
|
2016-08-12 11:17:45 +03:00
|
|
|
ib::error() << "'" << name << "' not a regular file.";
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
/* This is OK. If the file create fails on RO media, there
|
|
|
|
is nothing we can do. */
|
|
|
|
|
|
|
|
ut_a(err == DB_NOT_FOUND);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************//**
|
|
|
|
I/o-handler thread function.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return OS_THREAD_DUMMY_RETURN */
|
|
|
|
extern "C"
|
2014-02-26 19:11:54 +01:00
|
|
|
os_thread_ret_t
|
|
|
|
DECLARE_THREAD(io_handler_thread)(
|
|
|
|
/*==============================*/
|
|
|
|
void* arg) /*!< in: pointer to the number of the segment in
|
|
|
|
the aio array */
|
|
|
|
{
|
|
|
|
ulint segment;
|
|
|
|
|
|
|
|
segment = *((ulint*) arg);
|
|
|
|
|
|
|
|
#ifdef UNIV_DEBUG_THREAD_CREATION
|
2016-08-12 11:17:45 +03:00
|
|
|
ib::info() << "Io handler thread " << segment << " starts, id "
|
|
|
|
<< os_thread_pf(os_thread_get_curr_id());
|
2014-02-26 19:11:54 +01:00
|
|
|
#endif
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/* For read only mode, we don't need ibuf and log I/O thread.
|
|
|
|
Please see innobase_start_or_create_for_mysql() */
|
|
|
|
ulint start = (srv_read_only_mode) ? 0 : 2;
|
|
|
|
|
|
|
|
if (segment < start) {
|
|
|
|
if (segment == 0) {
|
|
|
|
pfs_register_thread(io_ibuf_thread_key);
|
|
|
|
} else {
|
|
|
|
ut_ad(segment == 1);
|
|
|
|
pfs_register_thread(io_log_thread_key);
|
|
|
|
}
|
|
|
|
} else if (segment >= start
|
|
|
|
&& segment < (start + srv_n_read_io_threads)) {
|
|
|
|
pfs_register_thread(io_read_thread_key);
|
|
|
|
|
|
|
|
} else if (segment >= (start + srv_n_read_io_threads)
|
|
|
|
&& segment < (start + srv_n_read_io_threads
|
|
|
|
+ srv_n_write_io_threads)) {
|
|
|
|
pfs_register_thread(io_write_thread_key);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
pfs_register_thread(io_handler_thread_key);
|
|
|
|
}
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
while (srv_shutdown_state != SRV_SHUTDOWN_EXIT_THREADS
|
|
|
|
|| buf_page_cleaner_is_active
|
|
|
|
|| !os_aio_all_slots_free()) {
|
2014-02-26 19:11:54 +01:00
|
|
|
fil_aio_wait(segment);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We count the number of threads in os_thread_exit(). A created
|
|
|
|
thread should always use that to exit and not use return() to exit.
|
|
|
|
The thread actually never comes here because it is exited in an
|
|
|
|
os_event_wait(). */
|
|
|
|
|
2016-09-06 09:43:16 +03:00
|
|
|
os_thread_exit();
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
OS_THREAD_DUMMY_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************//**
|
|
|
|
Creates a log file.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return DB_SUCCESS or error code */
|
2016-06-21 14:21:03 +02:00
|
|
|
static MY_ATTRIBUTE((nonnull, warn_unused_result))
|
2014-02-26 19:11:54 +01:00
|
|
|
dberr_t
|
|
|
|
create_log_file(
|
|
|
|
/*============*/
|
2017-05-15 17:17:16 +03:00
|
|
|
pfs_os_file_t* file, /*!< out: file handle */
|
2014-02-26 19:11:54 +01:00
|
|
|
const char* name) /*!< in: log file name */
|
|
|
|
{
|
2016-08-12 11:17:45 +03:00
|
|
|
bool ret;
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
*file = os_file_create(
|
2016-08-12 11:17:45 +03:00
|
|
|
innodb_log_file_key, name,
|
2014-02-26 19:11:54 +01:00
|
|
|
OS_FILE_CREATE|OS_FILE_ON_ERROR_NO_EXIT, OS_FILE_NORMAL,
|
2016-08-12 11:17:45 +03:00
|
|
|
OS_LOG_FILE, srv_read_only_mode, &ret);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
if (!ret) {
|
2016-08-12 11:17:45 +03:00
|
|
|
ib::error() << "Cannot create " << name;
|
2014-02-26 19:11:54 +01:00
|
|
|
return(DB_ERROR);
|
|
|
|
}
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
ib::info() << "Setting log file " << name << " size to "
|
Reduce the granularity of innodb_log_file_size
In Mariabackup, we would want the backed-up redo log file size to be
a multiple of 512 bytes, or OS_FILE_LOG_BLOCK_SIZE. However, at startup,
InnoDB would be picky, requiring the file size to be a multiple of
innodb_page_size.
Furthermore, InnoDB would require the parameter to be a multiple of
one megabyte, while the minimum granularity is 512 bytes. Because
the data-file-oriented fil_io() API is being used for writing the
InnoDB redo log, writes will for now require innodb_log_file_size to
be a multiple of the maximum innodb_page_size (65536 bytes).
To complicate matters, InnoDB startup divided srv_log_file_size by
UNIV_PAGE_SIZE, so that initially, the unit was bytes, and later it
was innodb_page_size. We will simplify this and keep srv_log_file_size
in bytes at all times.
innobase_log_file_size: Remove. Remove some obsolete checks against
overflow on 32-bit systems. srv_log_file_size is always 64 bits, and
the maximum size 512GiB in multiples of innodb_page_size always fits
in ulint (which is 32 or 64 bits). 512GiB would be 8,388,608*64KiB or
134,217,728*4KiB.
log_init(): Remove the parameter file_size that was always passed as
srv_log_file_size.
log_set_capacity(): Add a parameter for passing the requested file size.
srv_log_file_size_requested: Declare static in srv0start.cc.
create_log_file(), create_log_files(),
innobase_start_or_create_for_mysql(): Invoke fil_node_create()
with srv_log_file_size expressed in multiples of innodb_page_size.
innobase_start_or_create_for_mysql(): Require the redo log file sizes
to be multiples of 512 bytes.
2017-06-05 22:47:20 +03:00
|
|
|
<< srv_log_file_size << " bytes";
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2017-10-08 00:13:05 +00:00
|
|
|
ret = os_file_set_size(name, *file, srv_log_file_size);
|
2014-02-26 19:11:54 +01:00
|
|
|
if (!ret) {
|
Reduce the granularity of innodb_log_file_size
In Mariabackup, we would want the backed-up redo log file size to be
a multiple of 512 bytes, or OS_FILE_LOG_BLOCK_SIZE. However, at startup,
InnoDB would be picky, requiring the file size to be a multiple of
innodb_page_size.
Furthermore, InnoDB would require the parameter to be a multiple of
one megabyte, while the minimum granularity is 512 bytes. Because
the data-file-oriented fil_io() API is being used for writing the
InnoDB redo log, writes will for now require innodb_log_file_size to
be a multiple of the maximum innodb_page_size (65536 bytes).
To complicate matters, InnoDB startup divided srv_log_file_size by
UNIV_PAGE_SIZE, so that initially, the unit was bytes, and later it
was innodb_page_size. We will simplify this and keep srv_log_file_size
in bytes at all times.
innobase_log_file_size: Remove. Remove some obsolete checks against
overflow on 32-bit systems. srv_log_file_size is always 64 bits, and
the maximum size 512GiB in multiples of innodb_page_size always fits
in ulint (which is 32 or 64 bits). 512GiB would be 8,388,608*64KiB or
134,217,728*4KiB.
log_init(): Remove the parameter file_size that was always passed as
srv_log_file_size.
log_set_capacity(): Add a parameter for passing the requested file size.
srv_log_file_size_requested: Declare static in srv0start.cc.
create_log_file(), create_log_files(),
innobase_start_or_create_for_mysql(): Invoke fil_node_create()
with srv_log_file_size expressed in multiples of innodb_page_size.
innobase_start_or_create_for_mysql(): Require the redo log file sizes
to be multiples of 512 bytes.
2017-06-05 22:47:20 +03:00
|
|
|
ib::error() << "Cannot set log file " << name << " size to "
|
|
|
|
<< srv_log_file_size << " bytes";
|
2014-02-26 19:11:54 +01:00
|
|
|
return(DB_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = os_file_close(*file);
|
|
|
|
ut_a(ret);
|
|
|
|
|
|
|
|
return(DB_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Initial number of the first redo log file */
|
|
|
|
#define INIT_LOG_FILE0 (SRV_N_LOG_FILES_MAX + 1)
|
|
|
|
|
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2
InnoDB I/O and buffer pool interfaces and the redo log format
have been changed between MariaDB 10.1 and 10.2, and the backup
code has to be adjusted accordingly.
The code has been simplified, and many memory leaks have been fixed.
Instead of the file name xtrabackup_logfile, the file name ib_logfile0
is being used for the copy of the redo log. Unnecessary InnoDB startup and
shutdown and some unnecessary threads have been removed.
Some help was provided by Vladislav Vaintroub.
Parameters have been cleaned up and aligned with those of MariaDB 10.2.
The --dbug option has been added, so that in debug builds,
--dbug=d,ib_log can be specified to enable diagnostic messages
for processing redo log entries.
By default, innodb_doublewrite=OFF, so that --prepare works faster.
If more crash-safety for --prepare is needed, double buffering
can be enabled.
The parameter innodb_log_checksums=OFF can be used to ignore redo log
checksums in --backup.
Some messages have been cleaned up.
Unless --export is specified, Mariabackup will not deal with undo log.
The InnoDB mini-transaction redo log is not only about user-level
transactions; it is actually about mini-transactions. To avoid confusion,
call it the redo log, not transaction log.
We disable any undo log processing in --prepare.
Because MariaDB 10.2 supports indexed virtual columns, the
undo log processing would need to be able to evaluate virtual column
expressions. To reduce the amount of code dependencies, we will not
process any undo log in prepare.
This means that the --export option must be disabled for now.
This also means that the following options are redundant
and have been removed:
xtrabackup --apply-log-only
innobackupex --redo-only
In addition to disabling any undo log processing, we will disable any
further changes to data pages during --prepare, including the change
buffer merge. This means that restoring incremental backups should
reliably work even when change buffering is being used on the server.
Because of this, preparing a backup will not generate any further
redo log, and the redo log file can be safely deleted. (If the
--export option is enabled in the future, it must generate redo log
when processing undo logs and buffered changes.)
In --prepare, we cannot easily know if a partial backup was used,
especially when restoring a series of incremental backups. So, we
simply warn about any missing files, and ignore the redo log for them.
FIXME: Enable the --export option.
FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write
a test that initiates a backup while an ALGORITHM=INPLACE operation
is creating indexes or rebuilding a table. An error should be detected
when preparing the backup.
FIXME: In --incremental --prepare, xtrabackup_apply_delta() should
ensure that if FSP_SIZE is modified, the file size will be adjusted
accordingly.
2017-06-30 10:49:37 +03:00
|
|
|
/** Delete all log files.
|
|
|
|
@param[in,out] logfilename buffer for log file name
|
|
|
|
@param[in] dirnamelen length of the directory path
|
2017-10-10 10:28:54 +03:00
|
|
|
@param[in] n_files number of files to delete
|
|
|
|
@param[in] i first file to delete */
|
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2
InnoDB I/O and buffer pool interfaces and the redo log format
have been changed between MariaDB 10.1 and 10.2, and the backup
code has to be adjusted accordingly.
The code has been simplified, and many memory leaks have been fixed.
Instead of the file name xtrabackup_logfile, the file name ib_logfile0
is being used for the copy of the redo log. Unnecessary InnoDB startup and
shutdown and some unnecessary threads have been removed.
Some help was provided by Vladislav Vaintroub.
Parameters have been cleaned up and aligned with those of MariaDB 10.2.
The --dbug option has been added, so that in debug builds,
--dbug=d,ib_log can be specified to enable diagnostic messages
for processing redo log entries.
By default, innodb_doublewrite=OFF, so that --prepare works faster.
If more crash-safety for --prepare is needed, double buffering
can be enabled.
The parameter innodb_log_checksums=OFF can be used to ignore redo log
checksums in --backup.
Some messages have been cleaned up.
Unless --export is specified, Mariabackup will not deal with undo log.
The InnoDB mini-transaction redo log is not only about user-level
transactions; it is actually about mini-transactions. To avoid confusion,
call it the redo log, not transaction log.
We disable any undo log processing in --prepare.
Because MariaDB 10.2 supports indexed virtual columns, the
undo log processing would need to be able to evaluate virtual column
expressions. To reduce the amount of code dependencies, we will not
process any undo log in prepare.
This means that the --export option must be disabled for now.
This also means that the following options are redundant
and have been removed:
xtrabackup --apply-log-only
innobackupex --redo-only
In addition to disabling any undo log processing, we will disable any
further changes to data pages during --prepare, including the change
buffer merge. This means that restoring incremental backups should
reliably work even when change buffering is being used on the server.
Because of this, preparing a backup will not generate any further
redo log, and the redo log file can be safely deleted. (If the
--export option is enabled in the future, it must generate redo log
when processing undo logs and buffered changes.)
In --prepare, we cannot easily know if a partial backup was used,
especially when restoring a series of incremental backups. So, we
simply warn about any missing files, and ignore the redo log for them.
FIXME: Enable the --export option.
FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write
a test that initiates a backup while an ALGORITHM=INPLACE operation
is creating indexes or rebuilding a table. An error should be detected
when preparing the backup.
FIXME: In --incremental --prepare, xtrabackup_apply_delta() should
ensure that if FSP_SIZE is modified, the file size will be adjusted
accordingly.
2017-06-30 10:49:37 +03:00
|
|
|
static
|
|
|
|
void
|
2017-10-10 10:28:54 +03:00
|
|
|
delete_log_files(char* logfilename, size_t dirnamelen, uint n_files, uint i=0)
|
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2
InnoDB I/O and buffer pool interfaces and the redo log format
have been changed between MariaDB 10.1 and 10.2, and the backup
code has to be adjusted accordingly.
The code has been simplified, and many memory leaks have been fixed.
Instead of the file name xtrabackup_logfile, the file name ib_logfile0
is being used for the copy of the redo log. Unnecessary InnoDB startup and
shutdown and some unnecessary threads have been removed.
Some help was provided by Vladislav Vaintroub.
Parameters have been cleaned up and aligned with those of MariaDB 10.2.
The --dbug option has been added, so that in debug builds,
--dbug=d,ib_log can be specified to enable diagnostic messages
for processing redo log entries.
By default, innodb_doublewrite=OFF, so that --prepare works faster.
If more crash-safety for --prepare is needed, double buffering
can be enabled.
The parameter innodb_log_checksums=OFF can be used to ignore redo log
checksums in --backup.
Some messages have been cleaned up.
Unless --export is specified, Mariabackup will not deal with undo log.
The InnoDB mini-transaction redo log is not only about user-level
transactions; it is actually about mini-transactions. To avoid confusion,
call it the redo log, not transaction log.
We disable any undo log processing in --prepare.
Because MariaDB 10.2 supports indexed virtual columns, the
undo log processing would need to be able to evaluate virtual column
expressions. To reduce the amount of code dependencies, we will not
process any undo log in prepare.
This means that the --export option must be disabled for now.
This also means that the following options are redundant
and have been removed:
xtrabackup --apply-log-only
innobackupex --redo-only
In addition to disabling any undo log processing, we will disable any
further changes to data pages during --prepare, including the change
buffer merge. This means that restoring incremental backups should
reliably work even when change buffering is being used on the server.
Because of this, preparing a backup will not generate any further
redo log, and the redo log file can be safely deleted. (If the
--export option is enabled in the future, it must generate redo log
when processing undo logs and buffered changes.)
In --prepare, we cannot easily know if a partial backup was used,
especially when restoring a series of incremental backups. So, we
simply warn about any missing files, and ignore the redo log for them.
FIXME: Enable the --export option.
FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write
a test that initiates a backup while an ALGORITHM=INPLACE operation
is creating indexes or rebuilding a table. An error should be detected
when preparing the backup.
FIXME: In --incremental --prepare, xtrabackup_apply_delta() should
ensure that if FSP_SIZE is modified, the file size will be adjusted
accordingly.
2017-06-30 10:49:37 +03:00
|
|
|
{
|
|
|
|
/* Remove any old log files. */
|
2017-10-10 10:28:54 +03:00
|
|
|
for (; i < n_files; i++) {
|
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2
InnoDB I/O and buffer pool interfaces and the redo log format
have been changed between MariaDB 10.1 and 10.2, and the backup
code has to be adjusted accordingly.
The code has been simplified, and many memory leaks have been fixed.
Instead of the file name xtrabackup_logfile, the file name ib_logfile0
is being used for the copy of the redo log. Unnecessary InnoDB startup and
shutdown and some unnecessary threads have been removed.
Some help was provided by Vladislav Vaintroub.
Parameters have been cleaned up and aligned with those of MariaDB 10.2.
The --dbug option has been added, so that in debug builds,
--dbug=d,ib_log can be specified to enable diagnostic messages
for processing redo log entries.
By default, innodb_doublewrite=OFF, so that --prepare works faster.
If more crash-safety for --prepare is needed, double buffering
can be enabled.
The parameter innodb_log_checksums=OFF can be used to ignore redo log
checksums in --backup.
Some messages have been cleaned up.
Unless --export is specified, Mariabackup will not deal with undo log.
The InnoDB mini-transaction redo log is not only about user-level
transactions; it is actually about mini-transactions. To avoid confusion,
call it the redo log, not transaction log.
We disable any undo log processing in --prepare.
Because MariaDB 10.2 supports indexed virtual columns, the
undo log processing would need to be able to evaluate virtual column
expressions. To reduce the amount of code dependencies, we will not
process any undo log in prepare.
This means that the --export option must be disabled for now.
This also means that the following options are redundant
and have been removed:
xtrabackup --apply-log-only
innobackupex --redo-only
In addition to disabling any undo log processing, we will disable any
further changes to data pages during --prepare, including the change
buffer merge. This means that restoring incremental backups should
reliably work even when change buffering is being used on the server.
Because of this, preparing a backup will not generate any further
redo log, and the redo log file can be safely deleted. (If the
--export option is enabled in the future, it must generate redo log
when processing undo logs and buffered changes.)
In --prepare, we cannot easily know if a partial backup was used,
especially when restoring a series of incremental backups. So, we
simply warn about any missing files, and ignore the redo log for them.
FIXME: Enable the --export option.
FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write
a test that initiates a backup while an ALGORITHM=INPLACE operation
is creating indexes or rebuilding a table. An error should be detected
when preparing the backup.
FIXME: In --incremental --prepare, xtrabackup_apply_delta() should
ensure that if FSP_SIZE is modified, the file size will be adjusted
accordingly.
2017-06-30 10:49:37 +03:00
|
|
|
sprintf(logfilename + dirnamelen, "ib_logfile%u", i);
|
|
|
|
|
|
|
|
/* Ignore errors about non-existent files or files
|
|
|
|
that cannot be removed. The create_log_file() will
|
|
|
|
return an error when the file exists. */
|
|
|
|
#ifdef _WIN32
|
|
|
|
DeleteFile((LPCTSTR) logfilename);
|
|
|
|
#else
|
|
|
|
unlink(logfilename);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
/*********************************************************************//**
|
|
|
|
Creates all log files.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return DB_SUCCESS or error code */
|
2014-02-26 19:11:54 +01:00
|
|
|
static
|
|
|
|
dberr_t
|
|
|
|
create_log_files(
|
|
|
|
/*=============*/
|
|
|
|
char* logfilename, /*!< in/out: buffer for log file name */
|
|
|
|
size_t dirnamelen, /*!< in: length of the directory path */
|
|
|
|
lsn_t lsn, /*!< in: FIL_PAGE_FILE_FLUSH_LSN value */
|
|
|
|
char*& logfile0) /*!< out: name of the first log file */
|
|
|
|
{
|
2016-08-12 11:17:45 +03:00
|
|
|
dberr_t err;
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
if (srv_read_only_mode) {
|
2016-08-12 11:17:45 +03:00
|
|
|
ib::error() << "Cannot create log files in read-only mode";
|
2014-02-26 19:11:54 +01:00
|
|
|
return(DB_READ_ONLY);
|
|
|
|
}
|
|
|
|
|
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2
InnoDB I/O and buffer pool interfaces and the redo log format
have been changed between MariaDB 10.1 and 10.2, and the backup
code has to be adjusted accordingly.
The code has been simplified, and many memory leaks have been fixed.
Instead of the file name xtrabackup_logfile, the file name ib_logfile0
is being used for the copy of the redo log. Unnecessary InnoDB startup and
shutdown and some unnecessary threads have been removed.
Some help was provided by Vladislav Vaintroub.
Parameters have been cleaned up and aligned with those of MariaDB 10.2.
The --dbug option has been added, so that in debug builds,
--dbug=d,ib_log can be specified to enable diagnostic messages
for processing redo log entries.
By default, innodb_doublewrite=OFF, so that --prepare works faster.
If more crash-safety for --prepare is needed, double buffering
can be enabled.
The parameter innodb_log_checksums=OFF can be used to ignore redo log
checksums in --backup.
Some messages have been cleaned up.
Unless --export is specified, Mariabackup will not deal with undo log.
The InnoDB mini-transaction redo log is not only about user-level
transactions; it is actually about mini-transactions. To avoid confusion,
call it the redo log, not transaction log.
We disable any undo log processing in --prepare.
Because MariaDB 10.2 supports indexed virtual columns, the
undo log processing would need to be able to evaluate virtual column
expressions. To reduce the amount of code dependencies, we will not
process any undo log in prepare.
This means that the --export option must be disabled for now.
This also means that the following options are redundant
and have been removed:
xtrabackup --apply-log-only
innobackupex --redo-only
In addition to disabling any undo log processing, we will disable any
further changes to data pages during --prepare, including the change
buffer merge. This means that restoring incremental backups should
reliably work even when change buffering is being used on the server.
Because of this, preparing a backup will not generate any further
redo log, and the redo log file can be safely deleted. (If the
--export option is enabled in the future, it must generate redo log
when processing undo logs and buffered changes.)
In --prepare, we cannot easily know if a partial backup was used,
especially when restoring a series of incremental backups. So, we
simply warn about any missing files, and ignore the redo log for them.
FIXME: Enable the --export option.
FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write
a test that initiates a backup while an ALGORITHM=INPLACE operation
is creating indexes or rebuilding a table. An error should be detected
when preparing the backup.
FIXME: In --incremental --prepare, xtrabackup_apply_delta() should
ensure that if FSP_SIZE is modified, the file size will be adjusted
accordingly.
2017-06-30 10:49:37 +03:00
|
|
|
/* Crashing after deleting the first file should be
|
|
|
|
recoverable. The buffer pool was clean, and we can simply
|
|
|
|
create all log files from the scratch. */
|
|
|
|
DBUG_EXECUTE_IF("innodb_log_abort_6",
|
|
|
|
delete_log_files(logfilename, dirnamelen, 1);
|
|
|
|
return(DB_ERROR););
|
2014-02-26 19:11:54 +01:00
|
|
|
|
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2
InnoDB I/O and buffer pool interfaces and the redo log format
have been changed between MariaDB 10.1 and 10.2, and the backup
code has to be adjusted accordingly.
The code has been simplified, and many memory leaks have been fixed.
Instead of the file name xtrabackup_logfile, the file name ib_logfile0
is being used for the copy of the redo log. Unnecessary InnoDB startup and
shutdown and some unnecessary threads have been removed.
Some help was provided by Vladislav Vaintroub.
Parameters have been cleaned up and aligned with those of MariaDB 10.2.
The --dbug option has been added, so that in debug builds,
--dbug=d,ib_log can be specified to enable diagnostic messages
for processing redo log entries.
By default, innodb_doublewrite=OFF, so that --prepare works faster.
If more crash-safety for --prepare is needed, double buffering
can be enabled.
The parameter innodb_log_checksums=OFF can be used to ignore redo log
checksums in --backup.
Some messages have been cleaned up.
Unless --export is specified, Mariabackup will not deal with undo log.
The InnoDB mini-transaction redo log is not only about user-level
transactions; it is actually about mini-transactions. To avoid confusion,
call it the redo log, not transaction log.
We disable any undo log processing in --prepare.
Because MariaDB 10.2 supports indexed virtual columns, the
undo log processing would need to be able to evaluate virtual column
expressions. To reduce the amount of code dependencies, we will not
process any undo log in prepare.
This means that the --export option must be disabled for now.
This also means that the following options are redundant
and have been removed:
xtrabackup --apply-log-only
innobackupex --redo-only
In addition to disabling any undo log processing, we will disable any
further changes to data pages during --prepare, including the change
buffer merge. This means that restoring incremental backups should
reliably work even when change buffering is being used on the server.
Because of this, preparing a backup will not generate any further
redo log, and the redo log file can be safely deleted. (If the
--export option is enabled in the future, it must generate redo log
when processing undo logs and buffered changes.)
In --prepare, we cannot easily know if a partial backup was used,
especially when restoring a series of incremental backups. So, we
simply warn about any missing files, and ignore the redo log for them.
FIXME: Enable the --export option.
FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write
a test that initiates a backup while an ALGORITHM=INPLACE operation
is creating indexes or rebuilding a table. An error should be detected
when preparing the backup.
FIXME: In --incremental --prepare, xtrabackup_apply_delta() should
ensure that if FSP_SIZE is modified, the file size will be adjusted
accordingly.
2017-06-30 10:49:37 +03:00
|
|
|
delete_log_files(logfilename, dirnamelen, INIT_LOG_FILE0 + 1);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2017-02-16 09:18:46 +02:00
|
|
|
DBUG_PRINT("ib_log", ("After innodb_log_abort_6"));
|
2014-02-26 19:11:54 +01:00
|
|
|
ut_ad(!buf_pool_check_no_pending_io());
|
|
|
|
|
2017-01-30 17:00:51 +02:00
|
|
|
DBUG_EXECUTE_IF("innodb_log_abort_7", return(DB_ERROR););
|
2017-02-16 09:18:46 +02:00
|
|
|
DBUG_PRINT("ib_log", ("After innodb_log_abort_7"));
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
for (unsigned i = 0; i < srv_n_log_files; i++) {
|
|
|
|
sprintf(logfilename + dirnamelen,
|
|
|
|
"ib_logfile%u", i ? i : INIT_LOG_FILE0);
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
err = create_log_file(&files[i], logfilename);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
return(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-30 17:00:51 +02:00
|
|
|
DBUG_EXECUTE_IF("innodb_log_abort_8", return(DB_ERROR););
|
2017-02-16 09:18:46 +02:00
|
|
|
DBUG_PRINT("ib_log", ("After innodb_log_abort_8"));
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
/* We did not create the first log file initially as
|
|
|
|
ib_logfile0, so that crash recovery cannot find it until it
|
|
|
|
has been completed and renamed. */
|
|
|
|
sprintf(logfilename + dirnamelen, "ib_logfile%u", INIT_LOG_FILE0);
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
fil_space_t* log_space = fil_space_create(
|
2017-01-19 12:06:13 +02:00
|
|
|
"innodb_redo_log", SRV_LOG_SPACE_FIRST_ID, 0, FIL_TYPE_LOG,
|
2017-06-12 17:43:07 +03:00
|
|
|
NULL/* innodb_encrypt_log works at a different level */);
|
2017-03-14 12:56:01 +02:00
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
ut_a(fil_validate());
|
2016-08-12 11:17:45 +03:00
|
|
|
ut_a(log_space != NULL);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
Reduce the granularity of innodb_log_file_size
In Mariabackup, we would want the backed-up redo log file size to be
a multiple of 512 bytes, or OS_FILE_LOG_BLOCK_SIZE. However, at startup,
InnoDB would be picky, requiring the file size to be a multiple of
innodb_page_size.
Furthermore, InnoDB would require the parameter to be a multiple of
one megabyte, while the minimum granularity is 512 bytes. Because
the data-file-oriented fil_io() API is being used for writing the
InnoDB redo log, writes will for now require innodb_log_file_size to
be a multiple of the maximum innodb_page_size (65536 bytes).
To complicate matters, InnoDB startup divided srv_log_file_size by
UNIV_PAGE_SIZE, so that initially, the unit was bytes, and later it
was innodb_page_size. We will simplify this and keep srv_log_file_size
in bytes at all times.
innobase_log_file_size: Remove. Remove some obsolete checks against
overflow on 32-bit systems. srv_log_file_size is always 64 bits, and
the maximum size 512GiB in multiples of innodb_page_size always fits
in ulint (which is 32 or 64 bits). 512GiB would be 8,388,608*64KiB or
134,217,728*4KiB.
log_init(): Remove the parameter file_size that was always passed as
srv_log_file_size.
log_set_capacity(): Add a parameter for passing the requested file size.
srv_log_file_size_requested: Declare static in srv0start.cc.
create_log_file(), create_log_files(),
innobase_start_or_create_for_mysql(): Invoke fil_node_create()
with srv_log_file_size expressed in multiples of innodb_page_size.
innobase_start_or_create_for_mysql(): Require the redo log file sizes
to be multiples of 512 bytes.
2017-06-05 22:47:20 +03:00
|
|
|
const ulint size = ulint(srv_log_file_size >> srv_page_size_shift);
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
logfile0 = fil_node_create(
|
Reduce the granularity of innodb_log_file_size
In Mariabackup, we would want the backed-up redo log file size to be
a multiple of 512 bytes, or OS_FILE_LOG_BLOCK_SIZE. However, at startup,
InnoDB would be picky, requiring the file size to be a multiple of
innodb_page_size.
Furthermore, InnoDB would require the parameter to be a multiple of
one megabyte, while the minimum granularity is 512 bytes. Because
the data-file-oriented fil_io() API is being used for writing the
InnoDB redo log, writes will for now require innodb_log_file_size to
be a multiple of the maximum innodb_page_size (65536 bytes).
To complicate matters, InnoDB startup divided srv_log_file_size by
UNIV_PAGE_SIZE, so that initially, the unit was bytes, and later it
was innodb_page_size. We will simplify this and keep srv_log_file_size
in bytes at all times.
innobase_log_file_size: Remove. Remove some obsolete checks against
overflow on 32-bit systems. srv_log_file_size is always 64 bits, and
the maximum size 512GiB in multiples of innodb_page_size always fits
in ulint (which is 32 or 64 bits). 512GiB would be 8,388,608*64KiB or
134,217,728*4KiB.
log_init(): Remove the parameter file_size that was always passed as
srv_log_file_size.
log_set_capacity(): Add a parameter for passing the requested file size.
srv_log_file_size_requested: Declare static in srv0start.cc.
create_log_file(), create_log_files(),
innobase_start_or_create_for_mysql(): Invoke fil_node_create()
with srv_log_file_size expressed in multiples of innodb_page_size.
innobase_start_or_create_for_mysql(): Require the redo log file sizes
to be multiples of 512 bytes.
2017-06-05 22:47:20 +03:00
|
|
|
logfilename, size, log_space, false, false);
|
2014-02-26 19:11:54 +01:00
|
|
|
ut_a(logfile0);
|
|
|
|
|
|
|
|
for (unsigned i = 1; i < srv_n_log_files; i++) {
|
2016-08-12 11:17:45 +03:00
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
sprintf(logfilename + dirnamelen, "ib_logfile%u", i);
|
|
|
|
|
Reduce the granularity of innodb_log_file_size
In Mariabackup, we would want the backed-up redo log file size to be
a multiple of 512 bytes, or OS_FILE_LOG_BLOCK_SIZE. However, at startup,
InnoDB would be picky, requiring the file size to be a multiple of
innodb_page_size.
Furthermore, InnoDB would require the parameter to be a multiple of
one megabyte, while the minimum granularity is 512 bytes. Because
the data-file-oriented fil_io() API is being used for writing the
InnoDB redo log, writes will for now require innodb_log_file_size to
be a multiple of the maximum innodb_page_size (65536 bytes).
To complicate matters, InnoDB startup divided srv_log_file_size by
UNIV_PAGE_SIZE, so that initially, the unit was bytes, and later it
was innodb_page_size. We will simplify this and keep srv_log_file_size
in bytes at all times.
innobase_log_file_size: Remove. Remove some obsolete checks against
overflow on 32-bit systems. srv_log_file_size is always 64 bits, and
the maximum size 512GiB in multiples of innodb_page_size always fits
in ulint (which is 32 or 64 bits). 512GiB would be 8,388,608*64KiB or
134,217,728*4KiB.
log_init(): Remove the parameter file_size that was always passed as
srv_log_file_size.
log_set_capacity(): Add a parameter for passing the requested file size.
srv_log_file_size_requested: Declare static in srv0start.cc.
create_log_file(), create_log_files(),
innobase_start_or_create_for_mysql(): Invoke fil_node_create()
with srv_log_file_size expressed in multiples of innodb_page_size.
innobase_start_or_create_for_mysql(): Require the redo log file sizes
to be multiples of 512 bytes.
2017-06-05 22:47:20 +03:00
|
|
|
if (!fil_node_create(logfilename, size,
|
2016-08-12 11:17:45 +03:00
|
|
|
log_space, false, false)) {
|
|
|
|
|
|
|
|
ib::error()
|
|
|
|
<< "Cannot create file node for log file "
|
|
|
|
<< logfilename;
|
|
|
|
|
|
|
|
return(DB_ERROR);
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Reduce the granularity of innodb_log_file_size
In Mariabackup, we would want the backed-up redo log file size to be
a multiple of 512 bytes, or OS_FILE_LOG_BLOCK_SIZE. However, at startup,
InnoDB would be picky, requiring the file size to be a multiple of
innodb_page_size.
Furthermore, InnoDB would require the parameter to be a multiple of
one megabyte, while the minimum granularity is 512 bytes. Because
the data-file-oriented fil_io() API is being used for writing the
InnoDB redo log, writes will for now require innodb_log_file_size to
be a multiple of the maximum innodb_page_size (65536 bytes).
To complicate matters, InnoDB startup divided srv_log_file_size by
UNIV_PAGE_SIZE, so that initially, the unit was bytes, and later it
was innodb_page_size. We will simplify this and keep srv_log_file_size
in bytes at all times.
innobase_log_file_size: Remove. Remove some obsolete checks against
overflow on 32-bit systems. srv_log_file_size is always 64 bits, and
the maximum size 512GiB in multiples of innodb_page_size always fits
in ulint (which is 32 or 64 bits). 512GiB would be 8,388,608*64KiB or
134,217,728*4KiB.
log_init(): Remove the parameter file_size that was always passed as
srv_log_file_size.
log_set_capacity(): Add a parameter for passing the requested file size.
srv_log_file_size_requested: Declare static in srv0start.cc.
create_log_file(), create_log_files(),
innobase_start_or_create_for_mysql(): Invoke fil_node_create()
with srv_log_file_size expressed in multiples of innodb_page_size.
innobase_start_or_create_for_mysql(): Require the redo log file sizes
to be multiples of 512 bytes.
2017-06-05 22:47:20 +03:00
|
|
|
log_init(srv_n_log_files);
|
|
|
|
if (!log_set_capacity(srv_log_file_size_requested)) {
|
2016-08-12 11:17:45 +03:00
|
|
|
return(DB_ERROR);
|
|
|
|
}
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
fil_open_log_and_system_tablespace_files();
|
|
|
|
|
|
|
|
/* Create a log checkpoint. */
|
2016-08-12 11:17:45 +03:00
|
|
|
log_mutex_enter();
|
2017-02-10 12:11:42 +02:00
|
|
|
if (log_sys->is_encrypted() && !log_crypt_init()) {
|
|
|
|
return(DB_ERROR);
|
|
|
|
}
|
2016-08-12 11:17:45 +03:00
|
|
|
ut_d(recv_no_log_write = false);
|
2014-02-26 19:11:54 +01:00
|
|
|
recv_reset_logs(lsn);
|
2016-08-12 11:17:45 +03:00
|
|
|
log_mutex_exit();
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
return(DB_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2017-01-30 17:00:51 +02:00
|
|
|
/** Rename the first redo log file.
|
|
|
|
@param[in,out] logfilename buffer for the log file name
|
|
|
|
@param[in] dirnamelen length of the directory path
|
|
|
|
@param[in] lsn FIL_PAGE_FILE_FLUSH_LSN value
|
|
|
|
@param[in,out] logfile0 name of the first log file
|
|
|
|
@return error code
|
|
|
|
@retval DB_SUCCESS on successful operation */
|
|
|
|
MY_ATTRIBUTE((warn_unused_result, nonnull))
|
2014-02-26 19:11:54 +01:00
|
|
|
static
|
2017-01-30 17:00:51 +02:00
|
|
|
dberr_t
|
2014-02-26 19:11:54 +01:00
|
|
|
create_log_files_rename(
|
|
|
|
/*====================*/
|
|
|
|
char* logfilename, /*!< in/out: buffer for log file name */
|
|
|
|
size_t dirnamelen, /*!< in: length of the directory path */
|
|
|
|
lsn_t lsn, /*!< in: FIL_PAGE_FILE_FLUSH_LSN value */
|
|
|
|
char* logfile0) /*!< in/out: name of the first log file */
|
|
|
|
{
|
|
|
|
/* If innodb_flush_method=O_DSYNC,
|
|
|
|
we need to explicitly flush the log buffers. */
|
|
|
|
fil_flush(SRV_LOG_SPACE_FIRST_ID);
|
2017-01-30 17:00:51 +02:00
|
|
|
|
2017-06-28 11:58:43 +03:00
|
|
|
ut_ad(!srv_log_files_created);
|
|
|
|
ut_d(srv_log_files_created = true);
|
|
|
|
|
2017-01-30 17:00:51 +02:00
|
|
|
DBUG_EXECUTE_IF("innodb_log_abort_9", return(DB_ERROR););
|
2017-02-16 09:18:46 +02:00
|
|
|
DBUG_PRINT("ib_log", ("After innodb_log_abort_9"));
|
2017-01-30 17:00:51 +02:00
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
/* Close the log files, so that we can rename
|
|
|
|
the first one. */
|
|
|
|
fil_close_log_files(false);
|
|
|
|
|
|
|
|
/* Rename the first log file, now that a log
|
|
|
|
checkpoint has been created. */
|
|
|
|
sprintf(logfilename + dirnamelen, "ib_logfile%u", 0);
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
ib::info() << "Renaming log file " << logfile0 << " to "
|
|
|
|
<< logfilename;
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
log_mutex_enter();
|
2014-02-26 19:11:54 +01:00
|
|
|
ut_ad(strlen(logfile0) == 2 + strlen(logfilename));
|
2017-01-30 17:00:51 +02:00
|
|
|
dberr_t err = os_file_rename(
|
|
|
|
innodb_log_file_key, logfile0, logfilename)
|
|
|
|
? DB_SUCCESS : DB_ERROR;
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
/* Replace the first file with ib_logfile0. */
|
|
|
|
strcpy(logfile0, logfilename);
|
2016-08-12 11:17:45 +03:00
|
|
|
log_mutex_exit();
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2017-01-30 17:00:51 +02:00
|
|
|
DBUG_EXECUTE_IF("innodb_log_abort_10", err = DB_ERROR;);
|
|
|
|
|
2017-01-30 17:00:51 +02:00
|
|
|
if (err == DB_SUCCESS) {
|
|
|
|
fil_open_log_and_system_tablespace_files();
|
2017-03-30 12:48:42 +02:00
|
|
|
ib::info() << "New log files created, LSN=" << lsn;
|
2017-01-30 17:00:51 +02:00
|
|
|
}
|
2017-01-30 17:00:51 +02:00
|
|
|
|
|
|
|
return(err);
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************//**
|
|
|
|
Opens a log file.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return DB_SUCCESS or error code */
|
2016-06-21 14:21:03 +02:00
|
|
|
static MY_ATTRIBUTE((nonnull, warn_unused_result))
|
2014-02-26 19:11:54 +01:00
|
|
|
dberr_t
|
|
|
|
open_log_file(
|
|
|
|
/*==========*/
|
2017-05-15 17:17:16 +03:00
|
|
|
pfs_os_file_t* file, /*!< out: file handle */
|
2014-02-26 19:11:54 +01:00
|
|
|
const char* name, /*!< in: log file name */
|
|
|
|
os_offset_t* size) /*!< out: file size */
|
|
|
|
{
|
2016-08-12 11:17:45 +03:00
|
|
|
bool ret;
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
*file = os_file_create(innodb_log_file_key, name,
|
2014-02-26 19:11:54 +01:00
|
|
|
OS_FILE_OPEN, OS_FILE_AIO,
|
2016-08-12 11:17:45 +03:00
|
|
|
OS_LOG_FILE, srv_read_only_mode, &ret);
|
2014-02-26 19:11:54 +01:00
|
|
|
if (!ret) {
|
2016-08-12 11:17:45 +03:00
|
|
|
ib::error() << "Unable to open '" << name << "'";
|
2014-02-26 19:11:54 +01:00
|
|
|
return(DB_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
*size = os_file_get_size(*file);
|
|
|
|
|
|
|
|
ret = os_file_close(*file);
|
|
|
|
ut_a(ret);
|
|
|
|
return(DB_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************//**
|
2016-08-12 11:17:45 +03:00
|
|
|
Create undo tablespace.
|
|
|
|
@return DB_SUCCESS or error code */
|
|
|
|
static
|
2014-02-26 19:11:54 +01:00
|
|
|
dberr_t
|
2016-08-12 11:17:45 +03:00
|
|
|
srv_undo_tablespace_create(
|
|
|
|
/*=======================*/
|
|
|
|
const char* name, /*!< in: tablespace name */
|
|
|
|
ulint size) /*!< in: tablespace size in pages */
|
2014-02-26 19:11:54 +01:00
|
|
|
{
|
2017-05-15 17:17:16 +03:00
|
|
|
pfs_os_file_t fh;
|
2016-08-12 11:17:45 +03:00
|
|
|
bool ret;
|
|
|
|
dberr_t err = DB_SUCCESS;
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
os_file_create_subdirs_if_needed(name);
|
|
|
|
|
|
|
|
fh = os_file_create(
|
|
|
|
innodb_data_file_key,
|
|
|
|
name,
|
|
|
|
srv_read_only_mode ? OS_FILE_OPEN : OS_FILE_CREATE,
|
|
|
|
OS_FILE_NORMAL, OS_DATA_FILE, srv_read_only_mode, &ret);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
if (srv_read_only_mode && ret) {
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
ib::info() << name << " opened in read-only mode";
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
} else if (ret == FALSE) {
|
|
|
|
if (os_file_get_last_error(false) != OS_FILE_ALREADY_EXISTS
|
|
|
|
#ifdef UNIV_AIX
|
|
|
|
/* AIX 5.1 after security patch ML7 may have
|
|
|
|
errno set to 0 here, which causes our function
|
|
|
|
to return 100; work around that AIX problem */
|
|
|
|
&& os_file_get_last_error(false) != 100
|
|
|
|
#endif /* UNIV_AIX */
|
|
|
|
) {
|
|
|
|
ib::error() << "Can't create UNDO tablespace "
|
|
|
|
<< name;
|
|
|
|
}
|
|
|
|
err = DB_ERROR;
|
|
|
|
} else {
|
|
|
|
ut_a(!srv_read_only_mode);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/* We created the data file and now write it full of zeros */
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
ib::info() << "Data file " << name << " did not exist: new to"
|
|
|
|
" be created";
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
ib::info() << "Setting file " << name << " size to "
|
|
|
|
<< (size >> (20 - UNIV_PAGE_SIZE_SHIFT)) << " MB";
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
ib::info() << "Database physically writes the file full: "
|
|
|
|
<< "wait...";
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
ret = os_file_set_size(
|
2017-10-08 00:13:05 +00:00
|
|
|
name, fh, os_offset_t(size) << UNIV_PAGE_SIZE_SHIFT);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
if (!ret) {
|
|
|
|
ib::info() << "Error in creating " << name
|
|
|
|
<< ": probably out of disk space";
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
err = DB_ERROR;
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
os_file_close(fh);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(err);
|
|
|
|
}
|
|
|
|
/*********************************************************************//**
|
|
|
|
Open an undo tablespace.
|
|
|
|
@return DB_SUCCESS or error code */
|
|
|
|
static
|
|
|
|
dberr_t
|
|
|
|
srv_undo_tablespace_open(
|
|
|
|
/*=====================*/
|
|
|
|
const char* name, /*!< in: tablespace file name */
|
|
|
|
ulint space_id) /*!< in: tablespace id */
|
|
|
|
{
|
2017-05-15 17:17:16 +03:00
|
|
|
pfs_os_file_t fh;
|
2016-08-12 11:17:45 +03:00
|
|
|
bool ret;
|
|
|
|
dberr_t err = DB_ERROR;
|
|
|
|
char undo_name[sizeof "innodb_undo000"];
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2017-11-11 23:07:24 +02:00
|
|
|
snprintf(undo_name, sizeof(undo_name),
|
|
|
|
"innodb_undo%03u", static_cast<unsigned>(space_id));
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
if (!srv_file_check_mode(name)) {
|
|
|
|
ib::error() << "UNDO tablespaces must be " <<
|
|
|
|
(srv_read_only_mode ? "writable" : "readable") << "!";
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
return(DB_ERROR);
|
|
|
|
}
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
fh = os_file_create(
|
|
|
|
innodb_data_file_key, name,
|
|
|
|
OS_FILE_OPEN_RETRY
|
|
|
|
| OS_FILE_ON_ERROR_NO_EXIT
|
|
|
|
| OS_FILE_ON_ERROR_SILENT,
|
|
|
|
OS_FILE_NORMAL,
|
|
|
|
OS_DATA_FILE,
|
|
|
|
srv_read_only_mode,
|
|
|
|
&ret);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/* If the file open was successful then load the tablespace. */
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
if (ret) {
|
|
|
|
os_offset_t size;
|
|
|
|
fil_space_t* space;
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
size = os_file_get_size(fh);
|
|
|
|
ut_a(size != (os_offset_t) -1);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
ret = os_file_close(fh);
|
|
|
|
ut_a(ret);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/* Load the tablespace into InnoDB's internal
|
|
|
|
data structures. */
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/* We set the biggest space id to the undo tablespace
|
|
|
|
because InnoDB hasn't opened any other tablespace apart
|
|
|
|
from the system tablespace. */
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
fil_set_max_space_id_if_bigger(space_id);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
space = fil_space_create(
|
2017-01-19 12:06:13 +02:00
|
|
|
undo_name, space_id, FSP_FLAGS_PAGE_SSIZE(),
|
2017-06-12 17:43:07 +03:00
|
|
|
FIL_TYPE_TABLESPACE, NULL);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
ut_a(fil_validate());
|
|
|
|
ut_a(space);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
os_offset_t n_pages = size / UNIV_PAGE_SIZE;
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/* On 32-bit platforms, ulint is 32 bits and os_offset_t
|
|
|
|
is 64 bits. It is OK to cast the n_pages to ulint because
|
|
|
|
the unit has been scaled to pages and page number is always
|
|
|
|
32 bits. */
|
|
|
|
if (fil_node_create(
|
2016-12-31 15:11:52 +01:00
|
|
|
name, (ulint) n_pages, space, false, TRUE)) {
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
err = DB_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
return(err);
|
|
|
|
}
|
2015-06-16 10:57:05 +02:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/** Check if undo tablespaces and redo log files exist before creating a
|
|
|
|
new system tablespace
|
|
|
|
@retval DB_SUCCESS if all undo and redo logs are not found
|
|
|
|
@retval DB_ERROR if any undo and redo logs are found */
|
|
|
|
static
|
|
|
|
dberr_t
|
|
|
|
srv_check_undo_redo_logs_exists()
|
|
|
|
{
|
|
|
|
bool ret;
|
|
|
|
os_file_t fh;
|
|
|
|
char name[OS_FILE_MAX_PATH];
|
2015-06-16 10:57:05 +02:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/* Check if any undo tablespaces exist */
|
|
|
|
for (ulint i = 1; i <= srv_undo_tablespaces; ++i) {
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2017-11-11 23:07:24 +02:00
|
|
|
snprintf(
|
2016-08-12 11:17:45 +03:00
|
|
|
name, sizeof(name),
|
2017-04-21 05:51:27 +03:00
|
|
|
"%s%cundo%03zu",
|
2016-08-12 11:17:45 +03:00
|
|
|
srv_undo_dir, OS_PATH_SEPARATOR,
|
|
|
|
i);
|
|
|
|
|
|
|
|
fh = os_file_create(
|
|
|
|
innodb_data_file_key, name,
|
|
|
|
OS_FILE_OPEN_RETRY
|
|
|
|
| OS_FILE_ON_ERROR_NO_EXIT
|
|
|
|
| OS_FILE_ON_ERROR_SILENT,
|
|
|
|
OS_FILE_NORMAL,
|
|
|
|
OS_DATA_FILE,
|
|
|
|
srv_read_only_mode,
|
|
|
|
&ret);
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
os_file_close(fh);
|
|
|
|
ib::error()
|
|
|
|
<< "undo tablespace '" << name << "' exists."
|
|
|
|
" Creating system tablespace with existing undo"
|
|
|
|
" tablespaces is not supported. Please delete"
|
|
|
|
" all undo tablespaces before creating new"
|
|
|
|
" system tablespace.";
|
|
|
|
return(DB_ERROR);
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
2016-08-12 11:17:45 +03:00
|
|
|
}
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/* Check if any redo log files exist */
|
|
|
|
char logfilename[OS_FILE_MAX_PATH];
|
|
|
|
size_t dirnamelen = strlen(srv_log_group_home_dir);
|
|
|
|
memcpy(logfilename, srv_log_group_home_dir, dirnamelen);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
for (unsigned i = 0; i < srv_n_log_files; i++) {
|
|
|
|
sprintf(logfilename + dirnamelen,
|
|
|
|
"ib_logfile%u", i);
|
|
|
|
|
|
|
|
fh = os_file_create(
|
|
|
|
innodb_log_file_key, logfilename,
|
|
|
|
OS_FILE_OPEN_RETRY
|
|
|
|
| OS_FILE_ON_ERROR_NO_EXIT
|
|
|
|
| OS_FILE_ON_ERROR_SILENT,
|
|
|
|
OS_FILE_NORMAL,
|
|
|
|
OS_LOG_FILE,
|
|
|
|
srv_read_only_mode,
|
|
|
|
&ret);
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
os_file_close(fh);
|
|
|
|
ib::error() << "redo log file '" << logfilename
|
|
|
|
<< "' exists. Creating system tablespace with"
|
|
|
|
" existing redo log files is not recommended."
|
|
|
|
" Please delete all redo log files before"
|
|
|
|
" creating new system tablespace.";
|
|
|
|
return(DB_ERROR);
|
|
|
|
}
|
|
|
|
}
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
return(DB_SUCCESS);
|
|
|
|
}
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
undo::undo_spaces_t undo::Truncate::s_fix_up_spaces;
|
2014-02-26 19:11:54 +01:00
|
|
|
|
MDEV-12289 Keep 128 persistent rollback segments for compatibility and performance
InnoDB divides the allocation of undo logs into rollback segments.
The DB_ROLL_PTR system column of clustered indexes can address up to
128 rollback segments (TRX_SYS_N_RSEGS). Originally, InnoDB only
created one rollback segment. In MySQL 5.5 or in the InnoDB Plugin
for MySQL 5.1, all 128 rollback segments were created.
MySQL 5.7 hard-codes the rollback segment IDs 1..32 for temporary undo logs.
On upgrade, unless a slow shutdown (innodb_fast_shutdown=0)
was performed on the old server instance, these rollback segments
could be in use by transactions that are in XA PREPARE state or
transactions that were left behind by a server kill followed by a
normal shutdown immediately after restart.
Persistent tables cannot refer to temporary undo logs or vice versa.
Therefore, we should keep two distinct sets of rollback segments:
one for persistent tables and another for temporary tables. In this way,
all 128 rollback segments will be available for both types of tables,
which could improve performance. Also, MariaDB 10.2 will remain more
compatible than MySQL 5.7 with data files from earlier versions of
MySQL or MariaDB.
trx_sys_t::temp_rsegs[TRX_SYS_N_RSEGS]: A new array of temporary
rollback segments. The trx_sys_t::rseg_array[TRX_SYS_N_RSEGS] will
be solely for persistent undo logs.
srv_tmp_undo_logs. Remove. Use the constant TRX_SYS_N_RSEGS.
srv_available_undo_logs: Change the type to ulong.
trx_rseg_get_on_id(): Remove. Instead, let the callers refer to
trx_sys directly.
trx_rseg_create(), trx_sysf_rseg_find_free(): Remove unneeded parameters.
These functions only deal with persistent undo logs.
trx_temp_rseg_create(): New function, to create all temporary rollback
segments at server startup.
trx_rseg_t::is_persistent(): Determine if the rollback segment is for
persistent tables.
trx_sys_is_noredo_rseg_slot(): Remove. The callers must know based on
context (such as table handle) whether the DB_ROLL_PTR is referring to
a persistent undo log.
trx_sys_create_rsegs(): Remove all parameters, which were always passed
as global variables. Instead, modify the global variables directly.
enum trx_rseg_type_t: Remove.
trx_t::get_temp_rseg(): A method to ensure that a temporary
rollback segment has been assigned for the transaction.
trx_t::assign_temp_rseg(): Replaces trx_assign_rseg().
trx_purge_free_segment(), trx_purge_truncate_rseg_history():
Remove the redundant variable noredo=false.
Temporary undo logs are discarded immediately at transaction commit
or rollback, not lazily by purge.
trx_purge_mark_undo_for_truncate(): Remove references to the
temporary rollback segments.
trx_purge_mark_undo_for_truncate(): Remove a check for temporary
rollback segments. Only the dedicated persistent undo log tablespaces
can be truncated.
trx_undo_get_undo_rec_low(), trx_undo_get_undo_rec(): Add the
parameter is_temp.
trx_rseg_mem_restore(): Split from trx_rseg_mem_create().
Initialize the undo log and the rollback segment from the file
data structures.
trx_sysf_get_n_rseg_slots(): Renamed from
trx_sysf_used_slots_for_redo_rseg(). Count the persistent
rollback segment headers that have been initialized.
trx_sys_close(): Also free trx_sys->temp_rsegs[].
get_next_redo_rseg(): Merged to trx_assign_rseg_low().
trx_assign_rseg_low(): Remove the parameters and access the
global variables directly. Revert to simple round-robin, now that
the whole trx_sys->rseg_array[] is for persistent undo log again.
get_next_noredo_rseg(): Moved to trx_t::assign_temp_rseg().
srv_undo_tablespaces_init(): Remove some parameters and use the
global variables directly. Clarify some error messages.
Adjust the test innodb.log_file. Apparently, before these changes,
InnoDB somehow ignored missing dedicated undo tablespace files that
are pointed by the TRX_SYS header page, possibly losing part of
essential transaction system state.
2017-03-30 13:11:34 +03:00
|
|
|
/** Open the configured number of dedicated undo tablespaces.
|
|
|
|
@param[in] create_new_db whether the database is being initialized
|
2016-08-12 11:17:45 +03:00
|
|
|
@return DB_SUCCESS or error code */
|
2014-02-26 19:11:54 +01:00
|
|
|
dberr_t
|
MDEV-12289 Keep 128 persistent rollback segments for compatibility and performance
InnoDB divides the allocation of undo logs into rollback segments.
The DB_ROLL_PTR system column of clustered indexes can address up to
128 rollback segments (TRX_SYS_N_RSEGS). Originally, InnoDB only
created one rollback segment. In MySQL 5.5 or in the InnoDB Plugin
for MySQL 5.1, all 128 rollback segments were created.
MySQL 5.7 hard-codes the rollback segment IDs 1..32 for temporary undo logs.
On upgrade, unless a slow shutdown (innodb_fast_shutdown=0)
was performed on the old server instance, these rollback segments
could be in use by transactions that are in XA PREPARE state or
transactions that were left behind by a server kill followed by a
normal shutdown immediately after restart.
Persistent tables cannot refer to temporary undo logs or vice versa.
Therefore, we should keep two distinct sets of rollback segments:
one for persistent tables and another for temporary tables. In this way,
all 128 rollback segments will be available for both types of tables,
which could improve performance. Also, MariaDB 10.2 will remain more
compatible than MySQL 5.7 with data files from earlier versions of
MySQL or MariaDB.
trx_sys_t::temp_rsegs[TRX_SYS_N_RSEGS]: A new array of temporary
rollback segments. The trx_sys_t::rseg_array[TRX_SYS_N_RSEGS] will
be solely for persistent undo logs.
srv_tmp_undo_logs. Remove. Use the constant TRX_SYS_N_RSEGS.
srv_available_undo_logs: Change the type to ulong.
trx_rseg_get_on_id(): Remove. Instead, let the callers refer to
trx_sys directly.
trx_rseg_create(), trx_sysf_rseg_find_free(): Remove unneeded parameters.
These functions only deal with persistent undo logs.
trx_temp_rseg_create(): New function, to create all temporary rollback
segments at server startup.
trx_rseg_t::is_persistent(): Determine if the rollback segment is for
persistent tables.
trx_sys_is_noredo_rseg_slot(): Remove. The callers must know based on
context (such as table handle) whether the DB_ROLL_PTR is referring to
a persistent undo log.
trx_sys_create_rsegs(): Remove all parameters, which were always passed
as global variables. Instead, modify the global variables directly.
enum trx_rseg_type_t: Remove.
trx_t::get_temp_rseg(): A method to ensure that a temporary
rollback segment has been assigned for the transaction.
trx_t::assign_temp_rseg(): Replaces trx_assign_rseg().
trx_purge_free_segment(), trx_purge_truncate_rseg_history():
Remove the redundant variable noredo=false.
Temporary undo logs are discarded immediately at transaction commit
or rollback, not lazily by purge.
trx_purge_mark_undo_for_truncate(): Remove references to the
temporary rollback segments.
trx_purge_mark_undo_for_truncate(): Remove a check for temporary
rollback segments. Only the dedicated persistent undo log tablespaces
can be truncated.
trx_undo_get_undo_rec_low(), trx_undo_get_undo_rec(): Add the
parameter is_temp.
trx_rseg_mem_restore(): Split from trx_rseg_mem_create().
Initialize the undo log and the rollback segment from the file
data structures.
trx_sysf_get_n_rseg_slots(): Renamed from
trx_sysf_used_slots_for_redo_rseg(). Count the persistent
rollback segment headers that have been initialized.
trx_sys_close(): Also free trx_sys->temp_rsegs[].
get_next_redo_rseg(): Merged to trx_assign_rseg_low().
trx_assign_rseg_low(): Remove the parameters and access the
global variables directly. Revert to simple round-robin, now that
the whole trx_sys->rseg_array[] is for persistent undo log again.
get_next_noredo_rseg(): Moved to trx_t::assign_temp_rseg().
srv_undo_tablespaces_init(): Remove some parameters and use the
global variables directly. Clarify some error messages.
Adjust the test innodb.log_file. Apparently, before these changes,
InnoDB somehow ignored missing dedicated undo tablespace files that
are pointed by the TRX_SYS header page, possibly losing part of
essential transaction system state.
2017-03-30 13:11:34 +03:00
|
|
|
srv_undo_tablespaces_init(bool create_new_db)
|
2014-02-26 19:11:54 +01:00
|
|
|
{
|
2016-08-12 11:17:45 +03:00
|
|
|
ulint i;
|
|
|
|
dberr_t err = DB_SUCCESS;
|
|
|
|
ulint prev_space_id = 0;
|
|
|
|
ulint n_undo_tablespaces;
|
|
|
|
ulint undo_tablespace_ids[TRX_SYS_N_RSEGS + 1];
|
2014-02-26 19:11:54 +01:00
|
|
|
|
MDEV-12289 Keep 128 persistent rollback segments for compatibility and performance
InnoDB divides the allocation of undo logs into rollback segments.
The DB_ROLL_PTR system column of clustered indexes can address up to
128 rollback segments (TRX_SYS_N_RSEGS). Originally, InnoDB only
created one rollback segment. In MySQL 5.5 or in the InnoDB Plugin
for MySQL 5.1, all 128 rollback segments were created.
MySQL 5.7 hard-codes the rollback segment IDs 1..32 for temporary undo logs.
On upgrade, unless a slow shutdown (innodb_fast_shutdown=0)
was performed on the old server instance, these rollback segments
could be in use by transactions that are in XA PREPARE state or
transactions that were left behind by a server kill followed by a
normal shutdown immediately after restart.
Persistent tables cannot refer to temporary undo logs or vice versa.
Therefore, we should keep two distinct sets of rollback segments:
one for persistent tables and another for temporary tables. In this way,
all 128 rollback segments will be available for both types of tables,
which could improve performance. Also, MariaDB 10.2 will remain more
compatible than MySQL 5.7 with data files from earlier versions of
MySQL or MariaDB.
trx_sys_t::temp_rsegs[TRX_SYS_N_RSEGS]: A new array of temporary
rollback segments. The trx_sys_t::rseg_array[TRX_SYS_N_RSEGS] will
be solely for persistent undo logs.
srv_tmp_undo_logs. Remove. Use the constant TRX_SYS_N_RSEGS.
srv_available_undo_logs: Change the type to ulong.
trx_rseg_get_on_id(): Remove. Instead, let the callers refer to
trx_sys directly.
trx_rseg_create(), trx_sysf_rseg_find_free(): Remove unneeded parameters.
These functions only deal with persistent undo logs.
trx_temp_rseg_create(): New function, to create all temporary rollback
segments at server startup.
trx_rseg_t::is_persistent(): Determine if the rollback segment is for
persistent tables.
trx_sys_is_noredo_rseg_slot(): Remove. The callers must know based on
context (such as table handle) whether the DB_ROLL_PTR is referring to
a persistent undo log.
trx_sys_create_rsegs(): Remove all parameters, which were always passed
as global variables. Instead, modify the global variables directly.
enum trx_rseg_type_t: Remove.
trx_t::get_temp_rseg(): A method to ensure that a temporary
rollback segment has been assigned for the transaction.
trx_t::assign_temp_rseg(): Replaces trx_assign_rseg().
trx_purge_free_segment(), trx_purge_truncate_rseg_history():
Remove the redundant variable noredo=false.
Temporary undo logs are discarded immediately at transaction commit
or rollback, not lazily by purge.
trx_purge_mark_undo_for_truncate(): Remove references to the
temporary rollback segments.
trx_purge_mark_undo_for_truncate(): Remove a check for temporary
rollback segments. Only the dedicated persistent undo log tablespaces
can be truncated.
trx_undo_get_undo_rec_low(), trx_undo_get_undo_rec(): Add the
parameter is_temp.
trx_rseg_mem_restore(): Split from trx_rseg_mem_create().
Initialize the undo log and the rollback segment from the file
data structures.
trx_sysf_get_n_rseg_slots(): Renamed from
trx_sysf_used_slots_for_redo_rseg(). Count the persistent
rollback segment headers that have been initialized.
trx_sys_close(): Also free trx_sys->temp_rsegs[].
get_next_redo_rseg(): Merged to trx_assign_rseg_low().
trx_assign_rseg_low(): Remove the parameters and access the
global variables directly. Revert to simple round-robin, now that
the whole trx_sys->rseg_array[] is for persistent undo log again.
get_next_noredo_rseg(): Moved to trx_t::assign_temp_rseg().
srv_undo_tablespaces_init(): Remove some parameters and use the
global variables directly. Clarify some error messages.
Adjust the test innodb.log_file. Apparently, before these changes,
InnoDB somehow ignored missing dedicated undo tablespace files that
are pointed by the TRX_SYS header page, possibly losing part of
essential transaction system state.
2017-03-30 13:11:34 +03:00
|
|
|
srv_undo_tablespaces_open = 0;
|
2014-02-26 19:11:54 +01:00
|
|
|
|
MDEV-12289 Keep 128 persistent rollback segments for compatibility and performance
InnoDB divides the allocation of undo logs into rollback segments.
The DB_ROLL_PTR system column of clustered indexes can address up to
128 rollback segments (TRX_SYS_N_RSEGS). Originally, InnoDB only
created one rollback segment. In MySQL 5.5 or in the InnoDB Plugin
for MySQL 5.1, all 128 rollback segments were created.
MySQL 5.7 hard-codes the rollback segment IDs 1..32 for temporary undo logs.
On upgrade, unless a slow shutdown (innodb_fast_shutdown=0)
was performed on the old server instance, these rollback segments
could be in use by transactions that are in XA PREPARE state or
transactions that were left behind by a server kill followed by a
normal shutdown immediately after restart.
Persistent tables cannot refer to temporary undo logs or vice versa.
Therefore, we should keep two distinct sets of rollback segments:
one for persistent tables and another for temporary tables. In this way,
all 128 rollback segments will be available for both types of tables,
which could improve performance. Also, MariaDB 10.2 will remain more
compatible than MySQL 5.7 with data files from earlier versions of
MySQL or MariaDB.
trx_sys_t::temp_rsegs[TRX_SYS_N_RSEGS]: A new array of temporary
rollback segments. The trx_sys_t::rseg_array[TRX_SYS_N_RSEGS] will
be solely for persistent undo logs.
srv_tmp_undo_logs. Remove. Use the constant TRX_SYS_N_RSEGS.
srv_available_undo_logs: Change the type to ulong.
trx_rseg_get_on_id(): Remove. Instead, let the callers refer to
trx_sys directly.
trx_rseg_create(), trx_sysf_rseg_find_free(): Remove unneeded parameters.
These functions only deal with persistent undo logs.
trx_temp_rseg_create(): New function, to create all temporary rollback
segments at server startup.
trx_rseg_t::is_persistent(): Determine if the rollback segment is for
persistent tables.
trx_sys_is_noredo_rseg_slot(): Remove. The callers must know based on
context (such as table handle) whether the DB_ROLL_PTR is referring to
a persistent undo log.
trx_sys_create_rsegs(): Remove all parameters, which were always passed
as global variables. Instead, modify the global variables directly.
enum trx_rseg_type_t: Remove.
trx_t::get_temp_rseg(): A method to ensure that a temporary
rollback segment has been assigned for the transaction.
trx_t::assign_temp_rseg(): Replaces trx_assign_rseg().
trx_purge_free_segment(), trx_purge_truncate_rseg_history():
Remove the redundant variable noredo=false.
Temporary undo logs are discarded immediately at transaction commit
or rollback, not lazily by purge.
trx_purge_mark_undo_for_truncate(): Remove references to the
temporary rollback segments.
trx_purge_mark_undo_for_truncate(): Remove a check for temporary
rollback segments. Only the dedicated persistent undo log tablespaces
can be truncated.
trx_undo_get_undo_rec_low(), trx_undo_get_undo_rec(): Add the
parameter is_temp.
trx_rseg_mem_restore(): Split from trx_rseg_mem_create().
Initialize the undo log and the rollback segment from the file
data structures.
trx_sysf_get_n_rseg_slots(): Renamed from
trx_sysf_used_slots_for_redo_rseg(). Count the persistent
rollback segment headers that have been initialized.
trx_sys_close(): Also free trx_sys->temp_rsegs[].
get_next_redo_rseg(): Merged to trx_assign_rseg_low().
trx_assign_rseg_low(): Remove the parameters and access the
global variables directly. Revert to simple round-robin, now that
the whole trx_sys->rseg_array[] is for persistent undo log again.
get_next_noredo_rseg(): Moved to trx_t::assign_temp_rseg().
srv_undo_tablespaces_init(): Remove some parameters and use the
global variables directly. Clarify some error messages.
Adjust the test innodb.log_file. Apparently, before these changes,
InnoDB somehow ignored missing dedicated undo tablespace files that
are pointed by the TRX_SYS header page, possibly losing part of
essential transaction system state.
2017-03-30 13:11:34 +03:00
|
|
|
ut_a(srv_undo_tablespaces <= TRX_SYS_N_RSEGS);
|
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2
InnoDB I/O and buffer pool interfaces and the redo log format
have been changed between MariaDB 10.1 and 10.2, and the backup
code has to be adjusted accordingly.
The code has been simplified, and many memory leaks have been fixed.
Instead of the file name xtrabackup_logfile, the file name ib_logfile0
is being used for the copy of the redo log. Unnecessary InnoDB startup and
shutdown and some unnecessary threads have been removed.
Some help was provided by Vladislav Vaintroub.
Parameters have been cleaned up and aligned with those of MariaDB 10.2.
The --dbug option has been added, so that in debug builds,
--dbug=d,ib_log can be specified to enable diagnostic messages
for processing redo log entries.
By default, innodb_doublewrite=OFF, so that --prepare works faster.
If more crash-safety for --prepare is needed, double buffering
can be enabled.
The parameter innodb_log_checksums=OFF can be used to ignore redo log
checksums in --backup.
Some messages have been cleaned up.
Unless --export is specified, Mariabackup will not deal with undo log.
The InnoDB mini-transaction redo log is not only about user-level
transactions; it is actually about mini-transactions. To avoid confusion,
call it the redo log, not transaction log.
We disable any undo log processing in --prepare.
Because MariaDB 10.2 supports indexed virtual columns, the
undo log processing would need to be able to evaluate virtual column
expressions. To reduce the amount of code dependencies, we will not
process any undo log in prepare.
This means that the --export option must be disabled for now.
This also means that the following options are redundant
and have been removed:
xtrabackup --apply-log-only
innobackupex --redo-only
In addition to disabling any undo log processing, we will disable any
further changes to data pages during --prepare, including the change
buffer merge. This means that restoring incremental backups should
reliably work even when change buffering is being used on the server.
Because of this, preparing a backup will not generate any further
redo log, and the redo log file can be safely deleted. (If the
--export option is enabled in the future, it must generate redo log
when processing undo logs and buffered changes.)
In --prepare, we cannot easily know if a partial backup was used,
especially when restoring a series of incremental backups. So, we
simply warn about any missing files, and ignore the redo log for them.
FIXME: Enable the --export option.
FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write
a test that initiates a backup while an ALGORITHM=INPLACE operation
is creating indexes or rebuilding a table. An error should be detected
when preparing the backup.
FIXME: In --incremental --prepare, xtrabackup_apply_delta() should
ensure that if FSP_SIZE is modified, the file size will be adjusted
accordingly.
2017-06-30 10:49:37 +03:00
|
|
|
ut_a(!create_new_db || srv_operation == SRV_OPERATION_NORMAL);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
memset(undo_tablespace_ids, 0x0, sizeof(undo_tablespace_ids));
|
|
|
|
|
|
|
|
/* Create the undo spaces only if we are creating a new
|
|
|
|
instance. We don't allow creating of new undo tablespaces
|
|
|
|
in an existing instance (yet). This restriction exists because
|
|
|
|
we check in several places for SYSTEM tablespaces to be less than
|
|
|
|
the min of user defined tablespace ids. Once we implement saving
|
|
|
|
the location of the undo tablespaces and their space ids this
|
|
|
|
restriction will/should be lifted. */
|
|
|
|
|
MDEV-12289 Keep 128 persistent rollback segments for compatibility and performance
InnoDB divides the allocation of undo logs into rollback segments.
The DB_ROLL_PTR system column of clustered indexes can address up to
128 rollback segments (TRX_SYS_N_RSEGS). Originally, InnoDB only
created one rollback segment. In MySQL 5.5 or in the InnoDB Plugin
for MySQL 5.1, all 128 rollback segments were created.
MySQL 5.7 hard-codes the rollback segment IDs 1..32 for temporary undo logs.
On upgrade, unless a slow shutdown (innodb_fast_shutdown=0)
was performed on the old server instance, these rollback segments
could be in use by transactions that are in XA PREPARE state or
transactions that were left behind by a server kill followed by a
normal shutdown immediately after restart.
Persistent tables cannot refer to temporary undo logs or vice versa.
Therefore, we should keep two distinct sets of rollback segments:
one for persistent tables and another for temporary tables. In this way,
all 128 rollback segments will be available for both types of tables,
which could improve performance. Also, MariaDB 10.2 will remain more
compatible than MySQL 5.7 with data files from earlier versions of
MySQL or MariaDB.
trx_sys_t::temp_rsegs[TRX_SYS_N_RSEGS]: A new array of temporary
rollback segments. The trx_sys_t::rseg_array[TRX_SYS_N_RSEGS] will
be solely for persistent undo logs.
srv_tmp_undo_logs. Remove. Use the constant TRX_SYS_N_RSEGS.
srv_available_undo_logs: Change the type to ulong.
trx_rseg_get_on_id(): Remove. Instead, let the callers refer to
trx_sys directly.
trx_rseg_create(), trx_sysf_rseg_find_free(): Remove unneeded parameters.
These functions only deal with persistent undo logs.
trx_temp_rseg_create(): New function, to create all temporary rollback
segments at server startup.
trx_rseg_t::is_persistent(): Determine if the rollback segment is for
persistent tables.
trx_sys_is_noredo_rseg_slot(): Remove. The callers must know based on
context (such as table handle) whether the DB_ROLL_PTR is referring to
a persistent undo log.
trx_sys_create_rsegs(): Remove all parameters, which were always passed
as global variables. Instead, modify the global variables directly.
enum trx_rseg_type_t: Remove.
trx_t::get_temp_rseg(): A method to ensure that a temporary
rollback segment has been assigned for the transaction.
trx_t::assign_temp_rseg(): Replaces trx_assign_rseg().
trx_purge_free_segment(), trx_purge_truncate_rseg_history():
Remove the redundant variable noredo=false.
Temporary undo logs are discarded immediately at transaction commit
or rollback, not lazily by purge.
trx_purge_mark_undo_for_truncate(): Remove references to the
temporary rollback segments.
trx_purge_mark_undo_for_truncate(): Remove a check for temporary
rollback segments. Only the dedicated persistent undo log tablespaces
can be truncated.
trx_undo_get_undo_rec_low(), trx_undo_get_undo_rec(): Add the
parameter is_temp.
trx_rseg_mem_restore(): Split from trx_rseg_mem_create().
Initialize the undo log and the rollback segment from the file
data structures.
trx_sysf_get_n_rseg_slots(): Renamed from
trx_sysf_used_slots_for_redo_rseg(). Count the persistent
rollback segment headers that have been initialized.
trx_sys_close(): Also free trx_sys->temp_rsegs[].
get_next_redo_rseg(): Merged to trx_assign_rseg_low().
trx_assign_rseg_low(): Remove the parameters and access the
global variables directly. Revert to simple round-robin, now that
the whole trx_sys->rseg_array[] is for persistent undo log again.
get_next_noredo_rseg(): Moved to trx_t::assign_temp_rseg().
srv_undo_tablespaces_init(): Remove some parameters and use the
global variables directly. Clarify some error messages.
Adjust the test innodb.log_file. Apparently, before these changes,
InnoDB somehow ignored missing dedicated undo tablespace files that
are pointed by the TRX_SYS header page, possibly losing part of
essential transaction system state.
2017-03-30 13:11:34 +03:00
|
|
|
for (i = 0; create_new_db && i < srv_undo_tablespaces; ++i) {
|
2014-02-26 19:11:54 +01:00
|
|
|
char name[OS_FILE_MAX_PATH];
|
2017-05-15 17:17:16 +03:00
|
|
|
ulint space_id = i + 1;
|
|
|
|
|
|
|
|
DBUG_EXECUTE_IF("innodb_undo_upgrade",
|
|
|
|
space_id = i + 3;);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2017-11-11 23:07:24 +02:00
|
|
|
snprintf(
|
2014-02-26 19:11:54 +01:00
|
|
|
name, sizeof(name),
|
2017-04-21 05:51:27 +03:00
|
|
|
"%s%cundo%03zu",
|
2017-05-23 11:09:47 +03:00
|
|
|
srv_undo_dir, OS_PATH_SEPARATOR, space_id);
|
2017-05-15 17:17:16 +03:00
|
|
|
|
|
|
|
if (i == 0) {
|
|
|
|
srv_undo_space_id_start = space_id;
|
|
|
|
prev_space_id = srv_undo_space_id_start - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
undo_tablespace_ids[i] = space_id;
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
err = srv_undo_tablespace_create(
|
|
|
|
name, SRV_UNDO_TABLESPACE_SIZE_IN_PAGES);
|
|
|
|
|
|
|
|
if (err != DB_SUCCESS) {
|
2016-08-12 11:17:45 +03:00
|
|
|
ib::error() << "Could not create undo tablespace '"
|
|
|
|
<< name << "'.";
|
2014-02-26 19:11:54 +01:00
|
|
|
return(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the tablespace ids of all the undo segments excluding
|
|
|
|
the system tablespace (0). If we are creating a new instance then
|
|
|
|
we build the undo_tablespace_ids ourselves since they don't
|
|
|
|
already exist. */
|
2017-08-17 15:38:41 +03:00
|
|
|
n_undo_tablespaces = create_new_db
|
|
|
|
|| srv_operation == SRV_OPERATION_BACKUP
|
Follow-up fix to MDEV-12988 backup fails if innodb_undo_tablespaces>0
The fix broke mariabackup --prepare --incremental.
The restore of an incremental backup starts up (parts of) InnoDB twice.
First, all data files are discovered for applying .delta files. Then,
after the .delta files have been applied, InnoDB will be restarted
more completely, so that the redo log records will be applied via the
buffer pool.
During the first startup, the buffer pool is not initialized, and thus
trx_rseg_get_n_undo_tablespaces() must not be invoked. The apply of
the .delta files will currently assume that the --innodb-undo-tablespaces
option correctly specifies the number of undo tablespace files, just
like --backup does.
The second InnoDB startup of --prepare for applying the redo log will
properly invoke trx_rseg_get_n_undo_tablespaces().
enum srv_operation_mode: Add SRV_OPERATION_RESTORE_DELTA for
distinguishing the apply of .delta files from SRV_OPERATION_RESTORE.
srv_undo_tablespaces_init(): In mariabackup --prepare --incremental,
in the initial SRV_OPERATION_RESTORE_DELTA phase, do not invoke
trx_rseg_get_n_undo_tablespaces() because the buffer pool or the
redo logs are not available. Instead, blindly rely on the parameter
--innodb-undo-tablespaces.
2017-08-18 08:52:41 +03:00
|
|
|
|| srv_operation == SRV_OPERATION_RESTORE_DELTA
|
2017-08-17 15:38:41 +03:00
|
|
|
? srv_undo_tablespaces
|
|
|
|
: trx_rseg_get_n_undo_tablespaces(undo_tablespace_ids);
|
|
|
|
srv_undo_tablespaces_active = srv_undo_tablespaces;
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2017-08-17 15:38:41 +03:00
|
|
|
switch (srv_operation) {
|
Follow-up fix to MDEV-12988 backup fails if innodb_undo_tablespaces>0
The fix broke mariabackup --prepare --incremental.
The restore of an incremental backup starts up (parts of) InnoDB twice.
First, all data files are discovered for applying .delta files. Then,
after the .delta files have been applied, InnoDB will be restarted
more completely, so that the redo log records will be applied via the
buffer pool.
During the first startup, the buffer pool is not initialized, and thus
trx_rseg_get_n_undo_tablespaces() must not be invoked. The apply of
the .delta files will currently assume that the --innodb-undo-tablespaces
option correctly specifies the number of undo tablespace files, just
like --backup does.
The second InnoDB startup of --prepare for applying the redo log will
properly invoke trx_rseg_get_n_undo_tablespaces().
enum srv_operation_mode: Add SRV_OPERATION_RESTORE_DELTA for
distinguishing the apply of .delta files from SRV_OPERATION_RESTORE.
srv_undo_tablespaces_init(): In mariabackup --prepare --incremental,
in the initial SRV_OPERATION_RESTORE_DELTA phase, do not invoke
trx_rseg_get_n_undo_tablespaces() because the buffer pool or the
redo logs are not available. Instead, blindly rely on the parameter
--innodb-undo-tablespaces.
2017-08-18 08:52:41 +03:00
|
|
|
case SRV_OPERATION_RESTORE_DELTA:
|
2017-08-17 15:38:41 +03:00
|
|
|
case SRV_OPERATION_BACKUP:
|
|
|
|
/* MDEV-13561 FIXME: Determine srv_undo_space_id_start
|
|
|
|
from the undo001 file. */
|
|
|
|
srv_undo_space_id_start = 1;
|
|
|
|
for (i = 0; i < n_undo_tablespaces; i++) {
|
|
|
|
undo_tablespace_ids[i] = i + srv_undo_space_id_start;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SRV_OPERATION_NORMAL:
|
|
|
|
if (create_new_db) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* fall through */
|
|
|
|
case SRV_OPERATION_RESTORE:
|
2017-10-10 10:28:54 +03:00
|
|
|
case SRV_OPERATION_RESTORE_EXPORT:
|
2017-08-17 15:38:41 +03:00
|
|
|
ut_ad(!create_new_db);
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
/* Check if any of the UNDO tablespace needs fix-up because
|
|
|
|
server crashed while truncate was active on UNDO tablespace.*/
|
|
|
|
for (i = 0; i < n_undo_tablespaces; ++i) {
|
|
|
|
|
|
|
|
undo::Truncate undo_trunc;
|
|
|
|
|
|
|
|
if (undo_trunc.needs_fix_up(undo_tablespace_ids[i])) {
|
|
|
|
|
|
|
|
char name[OS_FILE_MAX_PATH];
|
|
|
|
|
2017-11-11 23:07:24 +02:00
|
|
|
snprintf(name, sizeof(name),
|
|
|
|
"%s%cundo%03zu",
|
|
|
|
srv_undo_dir, OS_PATH_SEPARATOR,
|
|
|
|
undo_tablespace_ids[i]);
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
os_file_delete(innodb_data_file_key, name);
|
|
|
|
|
|
|
|
err = srv_undo_tablespace_create(
|
|
|
|
name,
|
|
|
|
SRV_UNDO_TABLESPACE_SIZE_IN_PAGES);
|
|
|
|
|
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
ib::error() << "Could not fix-up undo "
|
|
|
|
" tablespace truncate '"
|
|
|
|
<< name << "'.";
|
|
|
|
return(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
undo::Truncate::s_fix_up_spaces.push_back(
|
|
|
|
undo_tablespace_ids[i]);
|
|
|
|
}
|
|
|
|
}
|
2017-08-17 15:38:41 +03:00
|
|
|
break;
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Open all the undo tablespaces that are currently in use. If we
|
|
|
|
fail to open any of these it is a fatal error. The tablespace ids
|
|
|
|
should be contiguous. It is a fatal error because they are required
|
|
|
|
for recovery and are referenced by the UNDO logs (a.k.a RBS). */
|
|
|
|
|
|
|
|
for (i = 0; i < n_undo_tablespaces; ++i) {
|
|
|
|
char name[OS_FILE_MAX_PATH];
|
|
|
|
|
2017-11-11 23:07:24 +02:00
|
|
|
snprintf(
|
2014-02-26 19:11:54 +01:00
|
|
|
name, sizeof(name),
|
2017-04-21 05:51:27 +03:00
|
|
|
"%s%cundo%03zu",
|
2016-08-12 11:17:45 +03:00
|
|
|
srv_undo_dir, OS_PATH_SEPARATOR,
|
2014-02-26 19:11:54 +01:00
|
|
|
undo_tablespace_ids[i]);
|
|
|
|
|
|
|
|
/* Should be no gaps in undo tablespace ids. */
|
|
|
|
ut_a(prev_space_id + 1 == undo_tablespace_ids[i]);
|
|
|
|
|
|
|
|
/* The system space id should not be in this array. */
|
|
|
|
ut_a(undo_tablespace_ids[i] != 0);
|
|
|
|
ut_a(undo_tablespace_ids[i] != ULINT_UNDEFINED);
|
|
|
|
|
|
|
|
err = srv_undo_tablespace_open(name, undo_tablespace_ids[i]);
|
|
|
|
|
|
|
|
if (err != DB_SUCCESS) {
|
2016-08-12 11:17:45 +03:00
|
|
|
ib::error() << "Unable to open undo tablespace '"
|
|
|
|
<< name << "'.";
|
2014-02-26 19:11:54 +01:00
|
|
|
return(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
prev_space_id = undo_tablespace_ids[i];
|
|
|
|
|
2017-05-23 11:09:47 +03:00
|
|
|
/* Note the first undo tablespace id in case of
|
|
|
|
no active undo tablespace. */
|
|
|
|
if (0 == srv_undo_tablespaces_open++) {
|
|
|
|
srv_undo_space_id_start = undo_tablespace_ids[i];
|
|
|
|
}
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Open any extra unused undo tablespaces. These must be contiguous.
|
|
|
|
We stop at the first failure. These are undo tablespaces that are
|
|
|
|
not in use and therefore not required by recovery. We only check
|
|
|
|
that there are no gaps. */
|
|
|
|
|
|
|
|
for (i = prev_space_id + 1; i < TRX_SYS_N_RSEGS; ++i) {
|
|
|
|
char name[OS_FILE_MAX_PATH];
|
|
|
|
|
2017-11-11 23:07:24 +02:00
|
|
|
snprintf(
|
2014-02-26 19:11:54 +01:00
|
|
|
name, sizeof(name),
|
2017-04-21 05:51:27 +03:00
|
|
|
"%s%cundo%03zu", srv_undo_dir, OS_PATH_SEPARATOR, i);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
/* Undo space ids start from 1. */
|
|
|
|
err = srv_undo_tablespace_open(name, i);
|
|
|
|
|
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
++n_undo_tablespaces;
|
|
|
|
|
MDEV-12289 Keep 128 persistent rollback segments for compatibility and performance
InnoDB divides the allocation of undo logs into rollback segments.
The DB_ROLL_PTR system column of clustered indexes can address up to
128 rollback segments (TRX_SYS_N_RSEGS). Originally, InnoDB only
created one rollback segment. In MySQL 5.5 or in the InnoDB Plugin
for MySQL 5.1, all 128 rollback segments were created.
MySQL 5.7 hard-codes the rollback segment IDs 1..32 for temporary undo logs.
On upgrade, unless a slow shutdown (innodb_fast_shutdown=0)
was performed on the old server instance, these rollback segments
could be in use by transactions that are in XA PREPARE state or
transactions that were left behind by a server kill followed by a
normal shutdown immediately after restart.
Persistent tables cannot refer to temporary undo logs or vice versa.
Therefore, we should keep two distinct sets of rollback segments:
one for persistent tables and another for temporary tables. In this way,
all 128 rollback segments will be available for both types of tables,
which could improve performance. Also, MariaDB 10.2 will remain more
compatible than MySQL 5.7 with data files from earlier versions of
MySQL or MariaDB.
trx_sys_t::temp_rsegs[TRX_SYS_N_RSEGS]: A new array of temporary
rollback segments. The trx_sys_t::rseg_array[TRX_SYS_N_RSEGS] will
be solely for persistent undo logs.
srv_tmp_undo_logs. Remove. Use the constant TRX_SYS_N_RSEGS.
srv_available_undo_logs: Change the type to ulong.
trx_rseg_get_on_id(): Remove. Instead, let the callers refer to
trx_sys directly.
trx_rseg_create(), trx_sysf_rseg_find_free(): Remove unneeded parameters.
These functions only deal with persistent undo logs.
trx_temp_rseg_create(): New function, to create all temporary rollback
segments at server startup.
trx_rseg_t::is_persistent(): Determine if the rollback segment is for
persistent tables.
trx_sys_is_noredo_rseg_slot(): Remove. The callers must know based on
context (such as table handle) whether the DB_ROLL_PTR is referring to
a persistent undo log.
trx_sys_create_rsegs(): Remove all parameters, which were always passed
as global variables. Instead, modify the global variables directly.
enum trx_rseg_type_t: Remove.
trx_t::get_temp_rseg(): A method to ensure that a temporary
rollback segment has been assigned for the transaction.
trx_t::assign_temp_rseg(): Replaces trx_assign_rseg().
trx_purge_free_segment(), trx_purge_truncate_rseg_history():
Remove the redundant variable noredo=false.
Temporary undo logs are discarded immediately at transaction commit
or rollback, not lazily by purge.
trx_purge_mark_undo_for_truncate(): Remove references to the
temporary rollback segments.
trx_purge_mark_undo_for_truncate(): Remove a check for temporary
rollback segments. Only the dedicated persistent undo log tablespaces
can be truncated.
trx_undo_get_undo_rec_low(), trx_undo_get_undo_rec(): Add the
parameter is_temp.
trx_rseg_mem_restore(): Split from trx_rseg_mem_create().
Initialize the undo log and the rollback segment from the file
data structures.
trx_sysf_get_n_rseg_slots(): Renamed from
trx_sysf_used_slots_for_redo_rseg(). Count the persistent
rollback segment headers that have been initialized.
trx_sys_close(): Also free trx_sys->temp_rsegs[].
get_next_redo_rseg(): Merged to trx_assign_rseg_low().
trx_assign_rseg_low(): Remove the parameters and access the
global variables directly. Revert to simple round-robin, now that
the whole trx_sys->rseg_array[] is for persistent undo log again.
get_next_noredo_rseg(): Moved to trx_t::assign_temp_rseg().
srv_undo_tablespaces_init(): Remove some parameters and use the
global variables directly. Clarify some error messages.
Adjust the test innodb.log_file. Apparently, before these changes,
InnoDB somehow ignored missing dedicated undo tablespace files that
are pointed by the TRX_SYS header page, possibly losing part of
essential transaction system state.
2017-03-30 13:11:34 +03:00
|
|
|
++srv_undo_tablespaces_open;
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
2017-05-23 11:09:47 +03:00
|
|
|
/* Initialize srv_undo_space_id_start=0 when there are no
|
|
|
|
dedicated undo tablespaces. */
|
|
|
|
if (n_undo_tablespaces == 0) {
|
|
|
|
srv_undo_space_id_start = 0;
|
|
|
|
}
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
/* If the user says that there are fewer than what we find we
|
|
|
|
tolerate that discrepancy but not the inverse. Because there could
|
|
|
|
be unused undo tablespaces for future use. */
|
|
|
|
|
MDEV-12289 Keep 128 persistent rollback segments for compatibility and performance
InnoDB divides the allocation of undo logs into rollback segments.
The DB_ROLL_PTR system column of clustered indexes can address up to
128 rollback segments (TRX_SYS_N_RSEGS). Originally, InnoDB only
created one rollback segment. In MySQL 5.5 or in the InnoDB Plugin
for MySQL 5.1, all 128 rollback segments were created.
MySQL 5.7 hard-codes the rollback segment IDs 1..32 for temporary undo logs.
On upgrade, unless a slow shutdown (innodb_fast_shutdown=0)
was performed on the old server instance, these rollback segments
could be in use by transactions that are in XA PREPARE state or
transactions that were left behind by a server kill followed by a
normal shutdown immediately after restart.
Persistent tables cannot refer to temporary undo logs or vice versa.
Therefore, we should keep two distinct sets of rollback segments:
one for persistent tables and another for temporary tables. In this way,
all 128 rollback segments will be available for both types of tables,
which could improve performance. Also, MariaDB 10.2 will remain more
compatible than MySQL 5.7 with data files from earlier versions of
MySQL or MariaDB.
trx_sys_t::temp_rsegs[TRX_SYS_N_RSEGS]: A new array of temporary
rollback segments. The trx_sys_t::rseg_array[TRX_SYS_N_RSEGS] will
be solely for persistent undo logs.
srv_tmp_undo_logs. Remove. Use the constant TRX_SYS_N_RSEGS.
srv_available_undo_logs: Change the type to ulong.
trx_rseg_get_on_id(): Remove. Instead, let the callers refer to
trx_sys directly.
trx_rseg_create(), trx_sysf_rseg_find_free(): Remove unneeded parameters.
These functions only deal with persistent undo logs.
trx_temp_rseg_create(): New function, to create all temporary rollback
segments at server startup.
trx_rseg_t::is_persistent(): Determine if the rollback segment is for
persistent tables.
trx_sys_is_noredo_rseg_slot(): Remove. The callers must know based on
context (such as table handle) whether the DB_ROLL_PTR is referring to
a persistent undo log.
trx_sys_create_rsegs(): Remove all parameters, which were always passed
as global variables. Instead, modify the global variables directly.
enum trx_rseg_type_t: Remove.
trx_t::get_temp_rseg(): A method to ensure that a temporary
rollback segment has been assigned for the transaction.
trx_t::assign_temp_rseg(): Replaces trx_assign_rseg().
trx_purge_free_segment(), trx_purge_truncate_rseg_history():
Remove the redundant variable noredo=false.
Temporary undo logs are discarded immediately at transaction commit
or rollback, not lazily by purge.
trx_purge_mark_undo_for_truncate(): Remove references to the
temporary rollback segments.
trx_purge_mark_undo_for_truncate(): Remove a check for temporary
rollback segments. Only the dedicated persistent undo log tablespaces
can be truncated.
trx_undo_get_undo_rec_low(), trx_undo_get_undo_rec(): Add the
parameter is_temp.
trx_rseg_mem_restore(): Split from trx_rseg_mem_create().
Initialize the undo log and the rollback segment from the file
data structures.
trx_sysf_get_n_rseg_slots(): Renamed from
trx_sysf_used_slots_for_redo_rseg(). Count the persistent
rollback segment headers that have been initialized.
trx_sys_close(): Also free trx_sys->temp_rsegs[].
get_next_redo_rseg(): Merged to trx_assign_rseg_low().
trx_assign_rseg_low(): Remove the parameters and access the
global variables directly. Revert to simple round-robin, now that
the whole trx_sys->rseg_array[] is for persistent undo log again.
get_next_noredo_rseg(): Moved to trx_t::assign_temp_rseg().
srv_undo_tablespaces_init(): Remove some parameters and use the
global variables directly. Clarify some error messages.
Adjust the test innodb.log_file. Apparently, before these changes,
InnoDB somehow ignored missing dedicated undo tablespace files that
are pointed by the TRX_SYS header page, possibly losing part of
essential transaction system state.
2017-03-30 13:11:34 +03:00
|
|
|
if (srv_undo_tablespaces > n_undo_tablespaces) {
|
|
|
|
ib::error() << "Expected to open innodb_undo_tablespaces="
|
|
|
|
<< srv_undo_tablespaces
|
|
|
|
<< " but was able to find only "
|
2016-08-12 11:17:45 +03:00
|
|
|
<< n_undo_tablespaces;
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
return(err != DB_SUCCESS ? err : DB_ERROR);
|
|
|
|
|
2017-04-25 09:26:01 +03:00
|
|
|
} else if (n_undo_tablespaces > 0) {
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
ib::info() << "Opened " << n_undo_tablespaces
|
2017-04-25 09:26:01 +03:00
|
|
|
<< " undo tablespaces";
|
2014-02-26 19:11:54 +01:00
|
|
|
|
MDEV-12289 Keep 128 persistent rollback segments for compatibility and performance
InnoDB divides the allocation of undo logs into rollback segments.
The DB_ROLL_PTR system column of clustered indexes can address up to
128 rollback segments (TRX_SYS_N_RSEGS). Originally, InnoDB only
created one rollback segment. In MySQL 5.5 or in the InnoDB Plugin
for MySQL 5.1, all 128 rollback segments were created.
MySQL 5.7 hard-codes the rollback segment IDs 1..32 for temporary undo logs.
On upgrade, unless a slow shutdown (innodb_fast_shutdown=0)
was performed on the old server instance, these rollback segments
could be in use by transactions that are in XA PREPARE state or
transactions that were left behind by a server kill followed by a
normal shutdown immediately after restart.
Persistent tables cannot refer to temporary undo logs or vice versa.
Therefore, we should keep two distinct sets of rollback segments:
one for persistent tables and another for temporary tables. In this way,
all 128 rollback segments will be available for both types of tables,
which could improve performance. Also, MariaDB 10.2 will remain more
compatible than MySQL 5.7 with data files from earlier versions of
MySQL or MariaDB.
trx_sys_t::temp_rsegs[TRX_SYS_N_RSEGS]: A new array of temporary
rollback segments. The trx_sys_t::rseg_array[TRX_SYS_N_RSEGS] will
be solely for persistent undo logs.
srv_tmp_undo_logs. Remove. Use the constant TRX_SYS_N_RSEGS.
srv_available_undo_logs: Change the type to ulong.
trx_rseg_get_on_id(): Remove. Instead, let the callers refer to
trx_sys directly.
trx_rseg_create(), trx_sysf_rseg_find_free(): Remove unneeded parameters.
These functions only deal with persistent undo logs.
trx_temp_rseg_create(): New function, to create all temporary rollback
segments at server startup.
trx_rseg_t::is_persistent(): Determine if the rollback segment is for
persistent tables.
trx_sys_is_noredo_rseg_slot(): Remove. The callers must know based on
context (such as table handle) whether the DB_ROLL_PTR is referring to
a persistent undo log.
trx_sys_create_rsegs(): Remove all parameters, which were always passed
as global variables. Instead, modify the global variables directly.
enum trx_rseg_type_t: Remove.
trx_t::get_temp_rseg(): A method to ensure that a temporary
rollback segment has been assigned for the transaction.
trx_t::assign_temp_rseg(): Replaces trx_assign_rseg().
trx_purge_free_segment(), trx_purge_truncate_rseg_history():
Remove the redundant variable noredo=false.
Temporary undo logs are discarded immediately at transaction commit
or rollback, not lazily by purge.
trx_purge_mark_undo_for_truncate(): Remove references to the
temporary rollback segments.
trx_purge_mark_undo_for_truncate(): Remove a check for temporary
rollback segments. Only the dedicated persistent undo log tablespaces
can be truncated.
trx_undo_get_undo_rec_low(), trx_undo_get_undo_rec(): Add the
parameter is_temp.
trx_rseg_mem_restore(): Split from trx_rseg_mem_create().
Initialize the undo log and the rollback segment from the file
data structures.
trx_sysf_get_n_rseg_slots(): Renamed from
trx_sysf_used_slots_for_redo_rseg(). Count the persistent
rollback segment headers that have been initialized.
trx_sys_close(): Also free trx_sys->temp_rsegs[].
get_next_redo_rseg(): Merged to trx_assign_rseg_low().
trx_assign_rseg_low(): Remove the parameters and access the
global variables directly. Revert to simple round-robin, now that
the whole trx_sys->rseg_array[] is for persistent undo log again.
get_next_noredo_rseg(): Moved to trx_t::assign_temp_rseg().
srv_undo_tablespaces_init(): Remove some parameters and use the
global variables directly. Clarify some error messages.
Adjust the test innodb.log_file. Apparently, before these changes,
InnoDB somehow ignored missing dedicated undo tablespace files that
are pointed by the TRX_SYS header page, possibly losing part of
essential transaction system state.
2017-03-30 13:11:34 +03:00
|
|
|
if (srv_undo_tablespaces == 0) {
|
|
|
|
ib::warn() << "innodb_undo_tablespaces=0 disables"
|
|
|
|
" dedicated undo log tablespaces";
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (create_new_db) {
|
|
|
|
mtr_t mtr;
|
|
|
|
|
|
|
|
mtr_start(&mtr);
|
|
|
|
|
|
|
|
/* The undo log tablespace */
|
2017-05-23 11:09:47 +03:00
|
|
|
for (i = 0; i < n_undo_tablespaces; ++i) {
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
fsp_header_init(
|
2017-05-23 11:09:47 +03:00
|
|
|
undo_tablespace_ids[i],
|
|
|
|
SRV_UNDO_TABLESPACE_SIZE_IN_PAGES, &mtr);
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
mtr_commit(&mtr);
|
|
|
|
}
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
if (!undo::Truncate::s_fix_up_spaces.empty()) {
|
|
|
|
|
|
|
|
/* Step-1: Initialize the tablespace header and rsegs header. */
|
|
|
|
mtr_t mtr;
|
|
|
|
|
|
|
|
mtr_start(&mtr);
|
|
|
|
/* Turn off REDO logging. We are in server start mode and fixing
|
|
|
|
UNDO tablespace even before REDO log is read. Let's say we
|
|
|
|
do REDO logging here then this REDO log record will be applied
|
|
|
|
as part of the current recovery process. We surely don't need
|
|
|
|
that as this is fix-up action parallel to REDO logging. */
|
|
|
|
mtr_set_log_mode(&mtr, MTR_LOG_NO_REDO);
|
2018-01-30 10:34:43 +02:00
|
|
|
buf_block_t* sys_header = trx_sysf_get(&mtr);
|
|
|
|
if (!sys_header) {
|
|
|
|
mtr.commit();
|
|
|
|
return DB_CORRUPTION;
|
|
|
|
}
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
for (undo::undo_spaces_t::const_iterator it
|
|
|
|
= undo::Truncate::s_fix_up_spaces.begin();
|
|
|
|
it != undo::Truncate::s_fix_up_spaces.end();
|
|
|
|
++it) {
|
|
|
|
|
|
|
|
undo::Truncate::add_space_to_trunc_list(*it);
|
|
|
|
|
|
|
|
fsp_header_init(
|
|
|
|
*it, SRV_UNDO_TABLESPACE_SIZE_IN_PAGES, &mtr);
|
|
|
|
|
|
|
|
mtr_x_lock(fil_space_get_latch(*it, NULL), &mtr);
|
|
|
|
|
|
|
|
for (ulint i = 0; i < TRX_SYS_N_RSEGS; i++) {
|
2018-01-30 10:34:43 +02:00
|
|
|
if (trx_sysf_rseg_get_space(sys_header, i)
|
|
|
|
== *it) {
|
2016-08-12 11:17:45 +03:00
|
|
|
trx_rseg_header_create(
|
MDEV-15132 Avoid accessing the TRX_SYS page
InnoDB maintains an internal persistent sequence of transaction
identifiers. This sequence is used for assigning both transaction
start identifiers (DB_TRX_ID=trx->id) and end identifiers (trx->no)
as well as end identifiers for the mysql.transaction_registry table
that was introduced in MDEV-12894.
TRX_SYS_TRX_ID_WRITE_MARGIN: Remove. After this many updates of
the sequence we used to update the TRX_SYS page. We can avoid accessing
the TRX_SYS page if we modify the InnoDB startup so that resurrecting
the sequence from other pages of the transaction system.
TRX_SYS_TRX_ID_STORE: Deprecate. The field only exists for the purpose
of upgrading from an earlier version of MySQL or MariaDB.
Starting with this fix, MariaDB will rely on the fields
TRX_UNDO_TRX_ID, TRX_UNDO_TRX_NO in the undo log header page of
each non-committed transaction, and on the new field
TRX_RSEG_MAX_TRX_ID in rollback segment header pages.
Because of this change, setting innodb_force_recovery=5 or 6 may cause
the system to recover with trx_sys.get_max_trx_id()==0. We must adjust
checks for invalid DB_TRX_ID and PAGE_MAX_TRX_ID accordingly.
We will change the startup and shutdown messages to display the
trx_sys.get_max_trx_id() in addition to the log sequence number.
trx_sys_t::flush_max_trx_id(): Remove.
trx_undo_mem_create_at_db_start(), trx_undo_lists_init():
Add an output parameter max_trx_id, to be updated from
TRX_UNDO_TRX_ID, TRX_UNDO_TRX_NO.
TRX_RSEG_MAX_TRX_ID: New field, for persisting
trx_sys.get_max_trx_id() at the time of the latest transaction commit.
Startup is not reading the undo log pages of committed transactions.
We want to avoid additional page accesses on startup, as well as
trouble when all undo logs have been emptied.
On startup, we will simply determine the maximum value from all pages
that are being read anyway.
TRX_RSEG_FORMAT: Redefined from TRX_RSEG_MAX_SIZE.
Old versions of InnoDB wrote uninitialized garbage to unused data fields.
Because of this, we cannot simply introduce a new field in the
rollback segment pages and expect it to be always zero, like it would
if the database was created by a recent enough InnoDB version.
Luckily, it looks like the field TRX_RSEG_MAX_SIZE was always written
as 0xfffffffe. We will indicate a new subformat of the page by writing
0 to this field. This has the nice side effect that after a downgrade
to older versions of InnoDB, transactions should fail to allocate any
undo log, that is, writes will be blocked. So, there is no problem of
getting corrupted transaction identifiers after downgrading.
trx_rseg_t::max_size: Remove.
trx_rseg_header_create(): Remove the parameter max_size=ULINT_MAX.
trx_purge_add_undo_to_history(): Update TRX_RSEG_MAX_SIZE
(and TRX_RSEG_FORMAT if needed). This is invoked on transaction commit.
trx_rseg_mem_restore(): If TRX_RSEG_FORMAT contains 0,
read TRX_RSEG_MAX_SIZE.
trx_rseg_array_init(): Invoke trx_sys.init_max_trx_id(max_trx_id + 1)
where max_trx_id was the maximum that was encountered in the rollback
segment pages and the undo log pages of recovered active, XA PREPARE,
or some committed transactions. (See trx_purge_add_undo_to_history()
which invokes trx_rsegf_set_nth_undo(..., FIL_NULL, ...);
not all committed transactions will be immediately detached from the
rollback segment header.)
2018-01-31 10:24:19 +02:00
|
|
|
*it, i, sys_header, &mtr);
|
2016-08-12 11:17:45 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
undo::Truncate::clear_trunc_list();
|
|
|
|
}
|
|
|
|
mtr_commit(&mtr);
|
|
|
|
|
|
|
|
/* Step-2: Flush the dirty pages from the buffer pool. */
|
|
|
|
for (undo::undo_spaces_t::const_iterator it
|
|
|
|
= undo::Truncate::s_fix_up_spaces.begin();
|
|
|
|
it != undo::Truncate::s_fix_up_spaces.end();
|
|
|
|
++it) {
|
2017-11-20 09:49:21 +02:00
|
|
|
FlushObserver dummy(TRX_SYS_SPACE, NULL, NULL);
|
|
|
|
buf_LRU_flush_or_remove_pages(TRX_SYS_SPACE, &dummy);
|
|
|
|
FlushObserver dummy2(*it, NULL, NULL);
|
|
|
|
buf_LRU_flush_or_remove_pages(*it, &dummy2);
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
/* Remove the truncate redo log file. */
|
|
|
|
undo::Truncate undo_trunc;
|
|
|
|
undo_trunc.done_logging(*it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
return(DB_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
Wait for the purge thread(s) to start up. */
|
|
|
|
static
|
|
|
|
void
|
|
|
|
srv_start_wait_for_purge_to_start()
|
|
|
|
/*===============================*/
|
|
|
|
{
|
|
|
|
/* Wait for the purge coordinator and master thread to startup. */
|
|
|
|
|
|
|
|
purge_state_t state = trx_purge_state();
|
|
|
|
|
|
|
|
ut_a(state != PURGE_STATE_DISABLED);
|
|
|
|
|
|
|
|
while (srv_shutdown_state == SRV_SHUTDOWN_NONE
|
|
|
|
&& srv_force_recovery < SRV_FORCE_NO_BACKGROUND
|
|
|
|
&& state == PURGE_STATE_INIT) {
|
|
|
|
|
|
|
|
switch (state = trx_purge_state()) {
|
|
|
|
case PURGE_STATE_RUN:
|
|
|
|
case PURGE_STATE_STOP:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PURGE_STATE_INIT:
|
2016-08-12 11:17:45 +03:00
|
|
|
ib::info() << "Waiting for purge to start";
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
os_thread_sleep(50000);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PURGE_STATE_EXIT:
|
|
|
|
case PURGE_STATE_DISABLED:
|
|
|
|
ut_error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/** Create the temporary file tablespace.
|
|
|
|
@param[in] create_new_db whether we are creating a new database
|
|
|
|
@return DB_SUCCESS or error code. */
|
|
|
|
static
|
|
|
|
dberr_t
|
2016-12-16 16:36:54 +02:00
|
|
|
srv_open_tmp_tablespace(bool create_new_db)
|
2016-08-12 11:17:45 +03:00
|
|
|
{
|
|
|
|
ulint sum_of_new_sizes;
|
|
|
|
|
|
|
|
/* Will try to remove if there is existing file left-over by last
|
|
|
|
unclean shutdown */
|
2016-12-16 16:36:54 +02:00
|
|
|
srv_tmp_space.set_sanity_check_status(true);
|
|
|
|
srv_tmp_space.delete_files();
|
|
|
|
srv_tmp_space.set_ignore_read_only(true);
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
ib::info() << "Creating shared tablespace for temporary tables";
|
|
|
|
|
|
|
|
bool create_new_temp_space;
|
|
|
|
|
2016-12-16 16:36:54 +02:00
|
|
|
srv_tmp_space.set_space_id(SRV_TMP_SPACE_ID);
|
2016-08-12 11:17:45 +03:00
|
|
|
|
2016-12-16 16:36:54 +02:00
|
|
|
dberr_t err = srv_tmp_space.check_file_spec(
|
|
|
|
&create_new_temp_space, 12 * 1024 * 1024);
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
if (err == DB_FAIL) {
|
|
|
|
|
2016-12-16 16:36:54 +02:00
|
|
|
ib::error() << "The " << srv_tmp_space.name()
|
2016-08-12 11:17:45 +03:00
|
|
|
<< " data file must be writable!";
|
|
|
|
|
|
|
|
err = DB_ERROR;
|
|
|
|
|
|
|
|
} else if (err != DB_SUCCESS) {
|
|
|
|
ib::error() << "Could not create the shared "
|
2016-12-16 16:36:54 +02:00
|
|
|
<< srv_tmp_space.name() << ".";
|
2016-08-12 11:17:45 +03:00
|
|
|
|
2016-12-16 16:36:54 +02:00
|
|
|
} else if ((err = srv_tmp_space.open_or_create(
|
2016-08-12 11:17:45 +03:00
|
|
|
true, create_new_db, &sum_of_new_sizes, NULL))
|
|
|
|
!= DB_SUCCESS) {
|
|
|
|
|
|
|
|
ib::error() << "Unable to create the shared "
|
2016-12-16 16:36:54 +02:00
|
|
|
<< srv_tmp_space.name();
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
mtr_t mtr;
|
2016-12-16 16:36:54 +02:00
|
|
|
ulint size = srv_tmp_space.get_sum_of_sizes();
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
/* Open this shared temp tablespace in the fil_system so that
|
|
|
|
it stays open until shutdown. */
|
2016-12-16 16:36:54 +02:00
|
|
|
if (fil_space_open(srv_tmp_space.name())) {
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
/* Initialize the header page */
|
|
|
|
mtr_start(&mtr);
|
|
|
|
mtr_set_log_mode(&mtr, MTR_LOG_NO_REDO);
|
|
|
|
|
2016-12-16 16:36:54 +02:00
|
|
|
fsp_header_init(SRV_TMP_SPACE_ID, size, &mtr);
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
mtr_commit(&mtr);
|
|
|
|
} else {
|
|
|
|
/* This file was just opened in the code above! */
|
2016-12-16 16:36:54 +02:00
|
|
|
ib::error() << "The " << srv_tmp_space.name()
|
2016-08-12 11:17:45 +03:00
|
|
|
<< " data file cannot be re-opened"
|
|
|
|
" after check_file_spec() succeeded!";
|
|
|
|
|
|
|
|
err = DB_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************//**
|
|
|
|
Set state to indicate start of particular group of threads in InnoDB. */
|
|
|
|
UNIV_INLINE
|
|
|
|
void
|
|
|
|
srv_start_state_set(
|
|
|
|
/*================*/
|
|
|
|
srv_start_state_t state) /*!< in: indicate current state of
|
|
|
|
thread startup */
|
|
|
|
{
|
|
|
|
srv_start_state |= state;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************//**
|
|
|
|
Check if following group of threads is started.
|
|
|
|
@return true if started */
|
|
|
|
UNIV_INLINE
|
|
|
|
bool
|
|
|
|
srv_start_state_is_set(
|
|
|
|
/*===================*/
|
|
|
|
srv_start_state_t state) /*!< in: state to check for */
|
|
|
|
{
|
|
|
|
return(srv_start_state & state);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Shutdown all background threads created by InnoDB. */
|
2017-01-05 10:48:03 +02:00
|
|
|
static
|
2016-08-12 11:17:45 +03:00
|
|
|
void
|
|
|
|
srv_shutdown_all_bg_threads()
|
|
|
|
{
|
2017-06-29 11:31:01 +03:00
|
|
|
ut_ad(!srv_undo_sources);
|
2016-08-12 11:17:45 +03:00
|
|
|
srv_shutdown_state = SRV_SHUTDOWN_EXIT_THREADS;
|
|
|
|
|
|
|
|
/* All threads end up waiting for certain events. Put those events
|
|
|
|
to the signaled state. Then the threads will exit themselves after
|
|
|
|
os_event_wait(). */
|
2017-01-05 10:48:03 +02:00
|
|
|
for (uint i = 0; i < 1000; ++i) {
|
2016-08-12 11:17:45 +03:00
|
|
|
/* NOTE: IF YOU CREATE THREADS IN INNODB, YOU MUST EXIT THEM
|
|
|
|
HERE OR EARLIER */
|
|
|
|
|
2016-12-05 21:04:30 +02:00
|
|
|
if (srv_start_state_is_set(SRV_START_STATE_LOCK_SYS)) {
|
|
|
|
/* a. Let the lock timeout thread exit */
|
|
|
|
os_event_set(lock_sys->timeout_event);
|
|
|
|
}
|
2016-08-12 11:17:45 +03:00
|
|
|
|
2016-12-05 21:04:30 +02:00
|
|
|
if (!srv_read_only_mode) {
|
2016-08-12 11:17:45 +03:00
|
|
|
/* b. srv error monitor thread exits automatically,
|
|
|
|
no need to do anything here */
|
|
|
|
|
|
|
|
if (srv_start_state_is_set(SRV_START_STATE_MASTER)) {
|
|
|
|
/* c. We wake the master thread so that
|
|
|
|
it exits */
|
|
|
|
srv_wake_master_thread();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (srv_start_state_is_set(SRV_START_STATE_PURGE)) {
|
|
|
|
/* d. Wakeup purge threads. */
|
|
|
|
srv_purge_wakeup();
|
|
|
|
}
|
2017-01-05 10:48:03 +02:00
|
|
|
|
|
|
|
if (srv_n_fil_crypt_threads_started) {
|
|
|
|
os_event_set(fil_crypt_threads_event);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (log_scrub_thread_active) {
|
|
|
|
os_event_set(log_scrub_event);
|
|
|
|
}
|
2016-08-12 11:17:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (srv_start_state_is_set(SRV_START_STATE_IO)) {
|
2016-12-05 21:04:30 +02:00
|
|
|
ut_ad(!srv_read_only_mode);
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/* e. Exit the i/o threads */
|
2016-12-05 21:04:30 +02:00
|
|
|
if (recv_sys->flush_start != NULL) {
|
|
|
|
os_event_set(recv_sys->flush_start);
|
|
|
|
}
|
|
|
|
if (recv_sys->flush_end != NULL) {
|
|
|
|
os_event_set(recv_sys->flush_end);
|
2016-08-12 11:17:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
os_event_set(buf_flush_event);
|
|
|
|
}
|
|
|
|
|
2017-06-29 11:31:01 +03:00
|
|
|
if (!os_thread_count) {
|
2017-01-05 10:48:03 +02:00
|
|
|
return;
|
2016-08-12 11:17:45 +03:00
|
|
|
}
|
2017-06-29 11:31:01 +03:00
|
|
|
|
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2
InnoDB I/O and buffer pool interfaces and the redo log format
have been changed between MariaDB 10.1 and 10.2, and the backup
code has to be adjusted accordingly.
The code has been simplified, and many memory leaks have been fixed.
Instead of the file name xtrabackup_logfile, the file name ib_logfile0
is being used for the copy of the redo log. Unnecessary InnoDB startup and
shutdown and some unnecessary threads have been removed.
Some help was provided by Vladislav Vaintroub.
Parameters have been cleaned up and aligned with those of MariaDB 10.2.
The --dbug option has been added, so that in debug builds,
--dbug=d,ib_log can be specified to enable diagnostic messages
for processing redo log entries.
By default, innodb_doublewrite=OFF, so that --prepare works faster.
If more crash-safety for --prepare is needed, double buffering
can be enabled.
The parameter innodb_log_checksums=OFF can be used to ignore redo log
checksums in --backup.
Some messages have been cleaned up.
Unless --export is specified, Mariabackup will not deal with undo log.
The InnoDB mini-transaction redo log is not only about user-level
transactions; it is actually about mini-transactions. To avoid confusion,
call it the redo log, not transaction log.
We disable any undo log processing in --prepare.
Because MariaDB 10.2 supports indexed virtual columns, the
undo log processing would need to be able to evaluate virtual column
expressions. To reduce the amount of code dependencies, we will not
process any undo log in prepare.
This means that the --export option must be disabled for now.
This also means that the following options are redundant
and have been removed:
xtrabackup --apply-log-only
innobackupex --redo-only
In addition to disabling any undo log processing, we will disable any
further changes to data pages during --prepare, including the change
buffer merge. This means that restoring incremental backups should
reliably work even when change buffering is being used on the server.
Because of this, preparing a backup will not generate any further
redo log, and the redo log file can be safely deleted. (If the
--export option is enabled in the future, it must generate redo log
when processing undo logs and buffered changes.)
In --prepare, we cannot easily know if a partial backup was used,
especially when restoring a series of incremental backups. So, we
simply warn about any missing files, and ignore the redo log for them.
FIXME: Enable the --export option.
FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write
a test that initiates a backup while an ALGORITHM=INPLACE operation
is creating indexes or rebuilding a table. An error should be detected
when preparing the backup.
FIXME: In --incremental --prepare, xtrabackup_apply_delta() should
ensure that if FSP_SIZE is modified, the file size will be adjusted
accordingly.
2017-06-30 10:49:37 +03:00
|
|
|
switch (srv_operation) {
|
|
|
|
case SRV_OPERATION_BACKUP:
|
Follow-up fix to MDEV-12988 backup fails if innodb_undo_tablespaces>0
The fix broke mariabackup --prepare --incremental.
The restore of an incremental backup starts up (parts of) InnoDB twice.
First, all data files are discovered for applying .delta files. Then,
after the .delta files have been applied, InnoDB will be restarted
more completely, so that the redo log records will be applied via the
buffer pool.
During the first startup, the buffer pool is not initialized, and thus
trx_rseg_get_n_undo_tablespaces() must not be invoked. The apply of
the .delta files will currently assume that the --innodb-undo-tablespaces
option correctly specifies the number of undo tablespace files, just
like --backup does.
The second InnoDB startup of --prepare for applying the redo log will
properly invoke trx_rseg_get_n_undo_tablespaces().
enum srv_operation_mode: Add SRV_OPERATION_RESTORE_DELTA for
distinguishing the apply of .delta files from SRV_OPERATION_RESTORE.
srv_undo_tablespaces_init(): In mariabackup --prepare --incremental,
in the initial SRV_OPERATION_RESTORE_DELTA phase, do not invoke
trx_rseg_get_n_undo_tablespaces() because the buffer pool or the
redo logs are not available. Instead, blindly rely on the parameter
--innodb-undo-tablespaces.
2017-08-18 08:52:41 +03:00
|
|
|
case SRV_OPERATION_RESTORE_DELTA:
|
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2
InnoDB I/O and buffer pool interfaces and the redo log format
have been changed between MariaDB 10.1 and 10.2, and the backup
code has to be adjusted accordingly.
The code has been simplified, and many memory leaks have been fixed.
Instead of the file name xtrabackup_logfile, the file name ib_logfile0
is being used for the copy of the redo log. Unnecessary InnoDB startup and
shutdown and some unnecessary threads have been removed.
Some help was provided by Vladislav Vaintroub.
Parameters have been cleaned up and aligned with those of MariaDB 10.2.
The --dbug option has been added, so that in debug builds,
--dbug=d,ib_log can be specified to enable diagnostic messages
for processing redo log entries.
By default, innodb_doublewrite=OFF, so that --prepare works faster.
If more crash-safety for --prepare is needed, double buffering
can be enabled.
The parameter innodb_log_checksums=OFF can be used to ignore redo log
checksums in --backup.
Some messages have been cleaned up.
Unless --export is specified, Mariabackup will not deal with undo log.
The InnoDB mini-transaction redo log is not only about user-level
transactions; it is actually about mini-transactions. To avoid confusion,
call it the redo log, not transaction log.
We disable any undo log processing in --prepare.
Because MariaDB 10.2 supports indexed virtual columns, the
undo log processing would need to be able to evaluate virtual column
expressions. To reduce the amount of code dependencies, we will not
process any undo log in prepare.
This means that the --export option must be disabled for now.
This also means that the following options are redundant
and have been removed:
xtrabackup --apply-log-only
innobackupex --redo-only
In addition to disabling any undo log processing, we will disable any
further changes to data pages during --prepare, including the change
buffer merge. This means that restoring incremental backups should
reliably work even when change buffering is being used on the server.
Because of this, preparing a backup will not generate any further
redo log, and the redo log file can be safely deleted. (If the
--export option is enabled in the future, it must generate redo log
when processing undo logs and buffered changes.)
In --prepare, we cannot easily know if a partial backup was used,
especially when restoring a series of incremental backups. So, we
simply warn about any missing files, and ignore the redo log for them.
FIXME: Enable the --export option.
FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write
a test that initiates a backup while an ALGORITHM=INPLACE operation
is creating indexes or rebuilding a table. An error should be detected
when preparing the backup.
FIXME: In --incremental --prepare, xtrabackup_apply_delta() should
ensure that if FSP_SIZE is modified, the file size will be adjusted
accordingly.
2017-06-30 10:49:37 +03:00
|
|
|
break;
|
|
|
|
case SRV_OPERATION_NORMAL:
|
|
|
|
case SRV_OPERATION_RESTORE:
|
2017-10-10 10:28:54 +03:00
|
|
|
case SRV_OPERATION_RESTORE_EXPORT:
|
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2
InnoDB I/O and buffer pool interfaces and the redo log format
have been changed between MariaDB 10.1 and 10.2, and the backup
code has to be adjusted accordingly.
The code has been simplified, and many memory leaks have been fixed.
Instead of the file name xtrabackup_logfile, the file name ib_logfile0
is being used for the copy of the redo log. Unnecessary InnoDB startup and
shutdown and some unnecessary threads have been removed.
Some help was provided by Vladislav Vaintroub.
Parameters have been cleaned up and aligned with those of MariaDB 10.2.
The --dbug option has been added, so that in debug builds,
--dbug=d,ib_log can be specified to enable diagnostic messages
for processing redo log entries.
By default, innodb_doublewrite=OFF, so that --prepare works faster.
If more crash-safety for --prepare is needed, double buffering
can be enabled.
The parameter innodb_log_checksums=OFF can be used to ignore redo log
checksums in --backup.
Some messages have been cleaned up.
Unless --export is specified, Mariabackup will not deal with undo log.
The InnoDB mini-transaction redo log is not only about user-level
transactions; it is actually about mini-transactions. To avoid confusion,
call it the redo log, not transaction log.
We disable any undo log processing in --prepare.
Because MariaDB 10.2 supports indexed virtual columns, the
undo log processing would need to be able to evaluate virtual column
expressions. To reduce the amount of code dependencies, we will not
process any undo log in prepare.
This means that the --export option must be disabled for now.
This also means that the following options are redundant
and have been removed:
xtrabackup --apply-log-only
innobackupex --redo-only
In addition to disabling any undo log processing, we will disable any
further changes to data pages during --prepare, including the change
buffer merge. This means that restoring incremental backups should
reliably work even when change buffering is being used on the server.
Because of this, preparing a backup will not generate any further
redo log, and the redo log file can be safely deleted. (If the
--export option is enabled in the future, it must generate redo log
when processing undo logs and buffered changes.)
In --prepare, we cannot easily know if a partial backup was used,
especially when restoring a series of incremental backups. So, we
simply warn about any missing files, and ignore the redo log for them.
FIXME: Enable the --export option.
FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write
a test that initiates a backup while an ALGORITHM=INPLACE operation
is creating indexes or rebuilding a table. An error should be detected
when preparing the backup.
FIXME: In --incremental --prepare, xtrabackup_apply_delta() should
ensure that if FSP_SIZE is modified, the file size will be adjusted
accordingly.
2017-06-30 10:49:37 +03:00
|
|
|
if (!buf_page_cleaner_is_active
|
|
|
|
&& os_aio_all_slots_free()) {
|
|
|
|
os_aio_wake_all_threads_at_shutdown();
|
|
|
|
}
|
2016-11-10 09:42:49 +02:00
|
|
|
}
|
|
|
|
|
2017-06-29 11:31:01 +03:00
|
|
|
os_thread_sleep(100000);
|
2016-08-12 11:17:45 +03:00
|
|
|
}
|
|
|
|
|
2017-01-05 10:48:03 +02:00
|
|
|
ib::warn() << os_thread_count << " threads created by InnoDB"
|
|
|
|
" had not exited at shutdown!";
|
|
|
|
ut_d(os_aio_print_pending_io(stderr));
|
|
|
|
ut_ad(0);
|
2016-08-12 11:17:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef UNIV_DEBUG
|
|
|
|
# define srv_init_abort(_db_err) \
|
|
|
|
srv_init_abort_low(create_new_db, __FILE__, __LINE__, _db_err)
|
|
|
|
#else
|
|
|
|
# define srv_init_abort(_db_err) \
|
|
|
|
srv_init_abort_low(create_new_db, _db_err)
|
|
|
|
#endif /* UNIV_DEBUG */
|
|
|
|
|
|
|
|
/** Innobase start-up aborted. Perform cleanup actions.
|
|
|
|
@param[in] create_new_db TRUE if new db is being created
|
|
|
|
@param[in] file File name
|
|
|
|
@param[in] line Line number
|
|
|
|
@param[in] err Reason for aborting InnoDB startup
|
|
|
|
@return DB_SUCCESS or error code. */
|
2017-01-25 15:11:46 +02:00
|
|
|
MY_ATTRIBUTE((warn_unused_result, nonnull))
|
2016-08-12 11:17:45 +03:00
|
|
|
static
|
|
|
|
dberr_t
|
|
|
|
srv_init_abort_low(
|
|
|
|
bool create_new_db,
|
|
|
|
#ifdef UNIV_DEBUG
|
|
|
|
const char* file,
|
2017-03-01 08:27:39 +02:00
|
|
|
unsigned line,
|
2016-08-12 11:17:45 +03:00
|
|
|
#endif /* UNIV_DEBUG */
|
|
|
|
dberr_t err)
|
|
|
|
{
|
|
|
|
if (create_new_db) {
|
2017-06-08 12:45:08 +03:00
|
|
|
ib::error() << "Database creation was aborted"
|
2016-08-12 11:17:45 +03:00
|
|
|
#ifdef UNIV_DEBUG
|
|
|
|
" at " << innobase_basename(file) << "[" << line << "]"
|
|
|
|
#endif /* UNIV_DEBUG */
|
|
|
|
" with error " << ut_strerr(err) << ". You may need"
|
|
|
|
" to delete the ibdata1 file before trying to start"
|
|
|
|
" up again.";
|
|
|
|
} else {
|
|
|
|
ib::error() << "Plugin initialization aborted"
|
|
|
|
#ifdef UNIV_DEBUG
|
|
|
|
" at " << innobase_basename(file) << "[" << line << "]"
|
|
|
|
#endif /* UNIV_DEBUG */
|
|
|
|
" with error " << ut_strerr(err);
|
|
|
|
}
|
|
|
|
|
2018-01-30 13:39:48 +02:00
|
|
|
srv_shutdown_bg_undo_sources();
|
2016-08-12 11:17:45 +03:00
|
|
|
srv_shutdown_all_bg_threads();
|
|
|
|
return(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Prepare to delete the redo log files. Flush the dirty pages from all the
|
|
|
|
buffer pools. Flush the redo log buffer to the redo log file.
|
|
|
|
@param[in] n_files number of old redo log files
|
|
|
|
@return lsn upto which data pages have been flushed. */
|
|
|
|
static
|
|
|
|
lsn_t
|
|
|
|
srv_prepare_to_delete_redo_log_files(
|
|
|
|
ulint n_files)
|
|
|
|
{
|
2017-02-16 09:18:46 +02:00
|
|
|
DBUG_ENTER("srv_prepare_to_delete_redo_log_files");
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
lsn_t flushed_lsn;
|
|
|
|
ulint pending_io = 0;
|
|
|
|
ulint count = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
/* Clean the buffer pool. */
|
|
|
|
buf_flush_sync_all_buf_pools();
|
|
|
|
|
2017-02-16 09:18:46 +02:00
|
|
|
DBUG_EXECUTE_IF("innodb_log_abort_1", DBUG_RETURN(0););
|
|
|
|
DBUG_PRINT("ib_log", ("After innodb_log_abort_1"));
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
log_mutex_enter();
|
|
|
|
|
|
|
|
fil_names_clear(log_sys->lsn, false);
|
|
|
|
|
|
|
|
flushed_lsn = log_sys->lsn;
|
|
|
|
|
|
|
|
{
|
2017-02-10 12:11:42 +02:00
|
|
|
ib::info info;
|
2018-01-03 15:22:52 +02:00
|
|
|
if (srv_log_file_size == 0
|
|
|
|
|| (log_sys->log.format
|
|
|
|
& ~LOG_HEADER_FORMAT_ENCRYPTED)
|
|
|
|
!= LOG_HEADER_FORMAT_CURRENT) {
|
2017-02-10 12:11:42 +02:00
|
|
|
info << "Upgrading redo log: ";
|
|
|
|
} else if (n_files != srv_n_log_files
|
|
|
|
|| srv_log_file_size
|
|
|
|
!= srv_log_file_size_requested) {
|
|
|
|
if (srv_encrypt_log
|
2018-02-06 17:14:05 +00:00
|
|
|
== (my_bool)log_sys->is_encrypted()) {
|
2017-02-10 12:11:42 +02:00
|
|
|
info << (srv_encrypt_log
|
|
|
|
? "Resizing encrypted"
|
|
|
|
: "Resizing");
|
|
|
|
} else if (srv_encrypt_log) {
|
|
|
|
info << "Encrypting and resizing";
|
|
|
|
} else {
|
|
|
|
info << "Removing encryption"
|
|
|
|
" and resizing";
|
|
|
|
}
|
|
|
|
|
|
|
|
info << " redo log from " << n_files
|
|
|
|
<< "*" << srv_log_file_size << " to ";
|
|
|
|
} else if (srv_encrypt_log) {
|
|
|
|
info << "Encrypting redo log: ";
|
2016-08-12 11:17:45 +03:00
|
|
|
} else {
|
2017-02-10 12:11:42 +02:00
|
|
|
info << "Removing redo log encryption: ";
|
2016-08-12 11:17:45 +03:00
|
|
|
}
|
2017-02-10 12:11:42 +02:00
|
|
|
|
|
|
|
info << srv_n_log_files << "*"
|
|
|
|
<< srv_log_file_size_requested
|
Reduce the granularity of innodb_log_file_size
In Mariabackup, we would want the backed-up redo log file size to be
a multiple of 512 bytes, or OS_FILE_LOG_BLOCK_SIZE. However, at startup,
InnoDB would be picky, requiring the file size to be a multiple of
innodb_page_size.
Furthermore, InnoDB would require the parameter to be a multiple of
one megabyte, while the minimum granularity is 512 bytes. Because
the data-file-oriented fil_io() API is being used for writing the
InnoDB redo log, writes will for now require innodb_log_file_size to
be a multiple of the maximum innodb_page_size (65536 bytes).
To complicate matters, InnoDB startup divided srv_log_file_size by
UNIV_PAGE_SIZE, so that initially, the unit was bytes, and later it
was innodb_page_size. We will simplify this and keep srv_log_file_size
in bytes at all times.
innobase_log_file_size: Remove. Remove some obsolete checks against
overflow on 32-bit systems. srv_log_file_size is always 64 bits, and
the maximum size 512GiB in multiples of innodb_page_size always fits
in ulint (which is 32 or 64 bits). 512GiB would be 8,388,608*64KiB or
134,217,728*4KiB.
log_init(): Remove the parameter file_size that was always passed as
srv_log_file_size.
log_set_capacity(): Add a parameter for passing the requested file size.
srv_log_file_size_requested: Declare static in srv0start.cc.
create_log_file(), create_log_files(),
innobase_start_or_create_for_mysql(): Invoke fil_node_create()
with srv_log_file_size expressed in multiples of innodb_page_size.
innobase_start_or_create_for_mysql(): Require the redo log file sizes
to be multiples of 512 bytes.
2017-06-05 22:47:20 +03:00
|
|
|
<< " bytes; LSN=" << flushed_lsn;
|
2016-08-12 11:17:45 +03:00
|
|
|
}
|
|
|
|
|
2018-01-16 20:02:38 +02:00
|
|
|
srv_start_lsn = flushed_lsn;
|
2016-08-12 11:17:45 +03:00
|
|
|
/* Flush the old log files. */
|
|
|
|
log_mutex_exit();
|
|
|
|
|
|
|
|
log_write_up_to(flushed_lsn, true);
|
|
|
|
|
|
|
|
/* If innodb_flush_method=O_DSYNC,
|
|
|
|
we need to explicitly flush the log buffers. */
|
|
|
|
fil_flush(SRV_LOG_SPACE_FIRST_ID);
|
|
|
|
|
|
|
|
ut_ad(flushed_lsn == log_get_lsn());
|
|
|
|
|
|
|
|
/* Check if the buffer pools are clean. If not
|
|
|
|
retry till it is clean. */
|
|
|
|
pending_io = buf_pool_check_no_pending_io();
|
|
|
|
|
|
|
|
if (pending_io > 0) {
|
|
|
|
count++;
|
|
|
|
/* Print a message every 60 seconds if we
|
|
|
|
are waiting to clean the buffer pools */
|
|
|
|
if (srv_print_verbose_log && count > 600) {
|
|
|
|
ib::info() << "Waiting for "
|
|
|
|
<< pending_io << " buffer "
|
|
|
|
<< "page I/Os to complete";
|
|
|
|
count = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
os_thread_sleep(100000);
|
|
|
|
|
|
|
|
} while (buf_pool_check_no_pending_io());
|
|
|
|
|
2017-02-16 09:18:46 +02:00
|
|
|
DBUG_RETURN(flushed_lsn);
|
2016-08-12 11:17:45 +03:00
|
|
|
}
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
/********************************************************************
|
|
|
|
Starts InnoDB and creates a new database if database files
|
|
|
|
are not found and the user wants.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return DB_SUCCESS or error code */
|
2014-02-26 19:11:54 +01:00
|
|
|
dberr_t
|
MDEV-13039 innodb_fast_shutdown=0 may fail to purge all undo log
When a slow shutdown is performed soon after spawning some work for
background threads that can create or commit transactions, it is possible
that new transactions are started or committed after the purge has finished.
This is violating the specification of innodb_fast_shutdown=0, namely that
the purge must be completed. (None of the history of the recent transactions
would be purged.)
Also, it is possible that the purge threads would exit in slow shutdown
while there exist active transactions, such as recovered incomplete
transactions that are being rolled back. Thus, the slow shutdown could
fail to purge some undo log that becomes purgeable after the transaction
commit or rollback.
srv_undo_sources: A flag that indicates if undo log can be generated
or the persistent, whether by background threads or by user SQL.
Even when this flag is clear, active transactions that already exist
in the system may be committed or rolled back.
innodb_shutdown(): Renamed from innobase_shutdown_for_mysql().
Do not return an error code; the operation never fails.
Clear the srv_undo_sources flag, and also ensure that the background
DROP TABLE queue is empty.
srv_purge_should_exit(): Do not allow the purge to exit if
srv_undo_sources are active or the background DROP TABLE queue is not
empty, or in slow shutdown, if any active transactions exist
(and are being rolled back).
srv_purge_coordinator_thread(): Remove some previous workarounds
for this bug.
innobase_start_or_create_for_mysql(): Set buf_page_cleaner_is_active
and srv_dict_stats_thread_active directly. Set srv_undo_sources before
starting the purge subsystem, to prevent immediate shutdown of the purge.
Create dict_stats_thread and fts_optimize_thread immediately
after setting srv_undo_sources, so that shutdown can use this flag to
determine if these subsystems were started.
dict_stats_shutdown(): Shut down dict_stats_thread. Backported from 10.2.
srv_shutdown_table_bg_threads(): Remove (unused).
2017-06-08 15:43:06 +03:00
|
|
|
innobase_start_or_create_for_mysql()
|
2014-02-26 19:11:54 +01:00
|
|
|
{
|
2016-08-12 11:17:45 +03:00
|
|
|
bool create_new_db = false;
|
|
|
|
lsn_t flushed_lsn;
|
2017-01-31 19:43:03 +02:00
|
|
|
dberr_t err = DB_SUCCESS;
|
2014-02-26 19:11:54 +01:00
|
|
|
ulint srv_n_log_files_found = srv_n_log_files;
|
|
|
|
mtr_t mtr;
|
|
|
|
char logfilename[10000];
|
|
|
|
char* logfile0 = NULL;
|
|
|
|
size_t dirnamelen;
|
2016-08-12 11:17:45 +03:00
|
|
|
unsigned i = 0;
|
2014-02-26 19:11:54 +01:00
|
|
|
|
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2
InnoDB I/O and buffer pool interfaces and the redo log format
have been changed between MariaDB 10.1 and 10.2, and the backup
code has to be adjusted accordingly.
The code has been simplified, and many memory leaks have been fixed.
Instead of the file name xtrabackup_logfile, the file name ib_logfile0
is being used for the copy of the redo log. Unnecessary InnoDB startup and
shutdown and some unnecessary threads have been removed.
Some help was provided by Vladislav Vaintroub.
Parameters have been cleaned up and aligned with those of MariaDB 10.2.
The --dbug option has been added, so that in debug builds,
--dbug=d,ib_log can be specified to enable diagnostic messages
for processing redo log entries.
By default, innodb_doublewrite=OFF, so that --prepare works faster.
If more crash-safety for --prepare is needed, double buffering
can be enabled.
The parameter innodb_log_checksums=OFF can be used to ignore redo log
checksums in --backup.
Some messages have been cleaned up.
Unless --export is specified, Mariabackup will not deal with undo log.
The InnoDB mini-transaction redo log is not only about user-level
transactions; it is actually about mini-transactions. To avoid confusion,
call it the redo log, not transaction log.
We disable any undo log processing in --prepare.
Because MariaDB 10.2 supports indexed virtual columns, the
undo log processing would need to be able to evaluate virtual column
expressions. To reduce the amount of code dependencies, we will not
process any undo log in prepare.
This means that the --export option must be disabled for now.
This also means that the following options are redundant
and have been removed:
xtrabackup --apply-log-only
innobackupex --redo-only
In addition to disabling any undo log processing, we will disable any
further changes to data pages during --prepare, including the change
buffer merge. This means that restoring incremental backups should
reliably work even when change buffering is being used on the server.
Because of this, preparing a backup will not generate any further
redo log, and the redo log file can be safely deleted. (If the
--export option is enabled in the future, it must generate redo log
when processing undo logs and buffered changes.)
In --prepare, we cannot easily know if a partial backup was used,
especially when restoring a series of incremental backups. So, we
simply warn about any missing files, and ignore the redo log for them.
FIXME: Enable the --export option.
FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write
a test that initiates a backup while an ALGORITHM=INPLACE operation
is creating indexes or rebuilding a table. An error should be detected
when preparing the backup.
FIXME: In --incremental --prepare, xtrabackup_apply_delta() should
ensure that if FSP_SIZE is modified, the file size will be adjusted
accordingly.
2017-06-30 10:49:37 +03:00
|
|
|
ut_ad(srv_operation == SRV_OPERATION_NORMAL
|
2017-10-10 10:28:54 +03:00
|
|
|
|| srv_operation == SRV_OPERATION_RESTORE
|
|
|
|
|| srv_operation == SRV_OPERATION_RESTORE_EXPORT);
|
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2
InnoDB I/O and buffer pool interfaces and the redo log format
have been changed between MariaDB 10.1 and 10.2, and the backup
code has to be adjusted accordingly.
The code has been simplified, and many memory leaks have been fixed.
Instead of the file name xtrabackup_logfile, the file name ib_logfile0
is being used for the copy of the redo log. Unnecessary InnoDB startup and
shutdown and some unnecessary threads have been removed.
Some help was provided by Vladislav Vaintroub.
Parameters have been cleaned up and aligned with those of MariaDB 10.2.
The --dbug option has been added, so that in debug builds,
--dbug=d,ib_log can be specified to enable diagnostic messages
for processing redo log entries.
By default, innodb_doublewrite=OFF, so that --prepare works faster.
If more crash-safety for --prepare is needed, double buffering
can be enabled.
The parameter innodb_log_checksums=OFF can be used to ignore redo log
checksums in --backup.
Some messages have been cleaned up.
Unless --export is specified, Mariabackup will not deal with undo log.
The InnoDB mini-transaction redo log is not only about user-level
transactions; it is actually about mini-transactions. To avoid confusion,
call it the redo log, not transaction log.
We disable any undo log processing in --prepare.
Because MariaDB 10.2 supports indexed virtual columns, the
undo log processing would need to be able to evaluate virtual column
expressions. To reduce the amount of code dependencies, we will not
process any undo log in prepare.
This means that the --export option must be disabled for now.
This also means that the following options are redundant
and have been removed:
xtrabackup --apply-log-only
innobackupex --redo-only
In addition to disabling any undo log processing, we will disable any
further changes to data pages during --prepare, including the change
buffer merge. This means that restoring incremental backups should
reliably work even when change buffering is being used on the server.
Because of this, preparing a backup will not generate any further
redo log, and the redo log file can be safely deleted. (If the
--export option is enabled in the future, it must generate redo log
when processing undo logs and buffered changes.)
In --prepare, we cannot easily know if a partial backup was used,
especially when restoring a series of incremental backups. So, we
simply warn about any missing files, and ignore the redo log for them.
FIXME: Enable the --export option.
FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write
a test that initiates a backup while an ALGORITHM=INPLACE operation
is creating indexes or rebuilding a table. An error should be detected
when preparing the backup.
FIXME: In --incremental --prepare, xtrabackup_apply_delta() should
ensure that if FSP_SIZE is modified, the file size will be adjusted
accordingly.
2017-06-30 10:49:37 +03:00
|
|
|
|
2017-02-01 16:03:57 +05:30
|
|
|
if (srv_force_recovery == SRV_FORCE_NO_LOG_REDO) {
|
|
|
|
srv_read_only_mode = true;
|
|
|
|
}
|
|
|
|
|
2015-10-09 17:21:46 +02:00
|
|
|
high_level_read_only = srv_read_only_mode
|
|
|
|
|| srv_force_recovery > SRV_FORCE_NO_TRX_UNDO;
|
2014-02-26 19:23:04 +01:00
|
|
|
|
2017-02-10 17:01:45 +01:00
|
|
|
/* Reset the start state. */
|
|
|
|
srv_start_state = SRV_START_STATE_NONE;
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
if (srv_read_only_mode) {
|
2016-08-12 11:17:45 +03:00
|
|
|
ib::info() << "Started in read only mode";
|
|
|
|
|
2016-12-05 21:04:30 +02:00
|
|
|
/* There is no write to InnoDB tablespaces (not even
|
|
|
|
temporary ones, because also CREATE TEMPORARY TABLE is
|
|
|
|
refused in read-only mode). */
|
2016-08-12 11:17:45 +03:00
|
|
|
srv_use_doublewrite_buf = FALSE;
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
#ifdef HAVE_LZO1X
|
|
|
|
if (lzo_init() != LZO_E_OK) {
|
|
|
|
ib::warn() << "lzo_init() failed, support disabled";
|
|
|
|
srv_lzo_disabled = true;
|
|
|
|
} else {
|
|
|
|
ib::info() << "LZO1X support available";
|
|
|
|
srv_lzo_disabled = false;
|
|
|
|
}
|
|
|
|
#endif /* HAVE_LZO1X */
|
2014-05-05 18:20:28 +02:00
|
|
|
|
2017-01-26 14:05:00 +02:00
|
|
|
compile_time_assert(sizeof(ulint) == sizeof(void*));
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
#ifdef UNIV_DEBUG
|
2016-08-12 11:17:45 +03:00
|
|
|
ib::info() << "!!!!!!!! UNIV_DEBUG switched on !!!!!!!!!";
|
2014-02-26 19:11:54 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef UNIV_IBUF_DEBUG
|
2016-08-12 11:17:45 +03:00
|
|
|
ib::info() << "!!!!!!!! UNIV_IBUF_DEBUG switched on !!!!!!!!!";
|
2014-02-26 19:11:54 +01:00
|
|
|
# ifdef UNIV_IBUF_COUNT_DEBUG
|
2016-08-12 11:17:45 +03:00
|
|
|
ib::info() << "!!!!!!!! UNIV_IBUF_COUNT_DEBUG switched on !!!!!!!!!";
|
|
|
|
ib::error() << "Crash recovery will fail with UNIV_IBUF_COUNT_DEBUG";
|
2014-02-26 19:11:54 +01:00
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef UNIV_LOG_LSN_DEBUG
|
2016-08-12 11:17:45 +03:00
|
|
|
ib::info() << "!!!!!!!! UNIV_LOG_LSN_DEBUG switched on !!!!!!!!!";
|
2014-02-26 19:11:54 +01:00
|
|
|
#endif /* UNIV_LOG_LSN_DEBUG */
|
|
|
|
|
|
|
|
#if defined(COMPILER_HINTS_ENABLED)
|
2016-08-12 11:17:45 +03:00
|
|
|
ib::info() << "Compiler hints enabled.";
|
2014-02-26 19:11:54 +01:00
|
|
|
#endif /* defined(COMPILER_HINTS_ENABLED) */
|
|
|
|
|
2016-09-09 15:05:59 +04:00
|
|
|
#ifdef _WIN32
|
|
|
|
ib::info() << "Mutexes and rw_locks use Windows interlocked functions";
|
|
|
|
#else
|
|
|
|
ib::info() << "Mutexes and rw_locks use GCC atomic builtins";
|
|
|
|
#endif
|
2016-08-12 11:17:45 +03:00
|
|
|
ib::info() << MUTEX_TYPE;
|
2014-09-11 10:13:35 +02:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
ib::info() << "Compressed tables use zlib " ZLIB_VERSION
|
2014-02-26 19:11:54 +01:00
|
|
|
#ifdef UNIV_ZIP_DEBUG
|
|
|
|
" with validation"
|
|
|
|
#endif /* UNIV_ZIP_DEBUG */
|
2016-08-12 11:17:45 +03:00
|
|
|
;
|
2014-02-26 19:11:54 +01:00
|
|
|
#ifdef UNIV_ZIP_COPY
|
2016-08-12 11:17:45 +03:00
|
|
|
ib::info() << "and extra copying";
|
2014-02-26 19:11:54 +01:00
|
|
|
#endif /* UNIV_ZIP_COPY */
|
|
|
|
|
|
|
|
/* Since InnoDB does not currently clean up all its internal data
|
|
|
|
structures in MySQL Embedded Server Library server_end(), we
|
|
|
|
print an error message if someone tries to start up InnoDB a
|
2016-08-12 11:17:45 +03:00
|
|
|
second time during the process lifetime. */
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
if (srv_start_has_been_called) {
|
|
|
|
ib::error() << "Startup called second time"
|
|
|
|
" during the process lifetime."
|
|
|
|
" In the MySQL Embedded Server Library"
|
|
|
|
" you cannot call server_init() more than"
|
|
|
|
" once during the process lifetime.";
|
|
|
|
}
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2017-04-25 09:26:01 +03:00
|
|
|
srv_start_has_been_called = true;
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
srv_is_being_started = true;
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
#ifdef _WIN32
|
|
|
|
srv_use_native_aio = TRUE;
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
#elif defined(LINUX_NATIVE_AIO)
|
|
|
|
|
|
|
|
if (srv_use_native_aio) {
|
2016-08-12 11:17:45 +03:00
|
|
|
ib::info() << "Using Linux native AIO";
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
/* Currently native AIO is supported only on windows and linux
|
|
|
|
and that also when the support is compiled in. In all other
|
|
|
|
cases, we ignore the setting of innodb_use_native_aio. */
|
|
|
|
srv_use_native_aio = FALSE;
|
2016-08-12 11:17:45 +03:00
|
|
|
#endif /* _WIN32 */
|
|
|
|
|
|
|
|
/* Register performance schema stages before any real work has been
|
|
|
|
started which may need to be instrumented. */
|
|
|
|
mysql_stage_register("innodb", srv_stages, UT_ARR_SIZE(srv_stages));
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
if (srv_file_flush_method_str == NULL) {
|
|
|
|
/* These are the default options */
|
2017-03-09 14:32:17 +00:00
|
|
|
srv_file_flush_method = IF_WIN(SRV_ALL_O_DIRECT_FSYNC,SRV_FSYNC);
|
2014-02-26 19:11:54 +01:00
|
|
|
} else if (0 == ut_strcmp(srv_file_flush_method_str, "fsync")) {
|
2017-03-09 14:32:17 +00:00
|
|
|
srv_file_flush_method = SRV_FSYNC;
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
} else if (0 == ut_strcmp(srv_file_flush_method_str, "O_DSYNC")) {
|
2017-03-09 14:32:17 +00:00
|
|
|
srv_file_flush_method = SRV_O_DSYNC;
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
} else if (0 == ut_strcmp(srv_file_flush_method_str, "O_DIRECT")) {
|
2017-03-09 14:32:17 +00:00
|
|
|
srv_file_flush_method = SRV_O_DIRECT;
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
} else if (0 == ut_strcmp(srv_file_flush_method_str, "O_DIRECT_NO_FSYNC")) {
|
2017-03-09 14:32:17 +00:00
|
|
|
srv_file_flush_method = SRV_O_DIRECT_NO_FSYNC;
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
} else if (0 == ut_strcmp(srv_file_flush_method_str, "littlesync")) {
|
2017-03-09 14:32:17 +00:00
|
|
|
srv_file_flush_method = SRV_LITTLESYNC;
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
} else if (0 == ut_strcmp(srv_file_flush_method_str, "nosync")) {
|
2017-03-09 14:32:17 +00:00
|
|
|
srv_file_flush_method = SRV_NOSYNC;
|
|
|
|
#ifdef _WIN32
|
2014-02-26 19:11:54 +01:00
|
|
|
} else if (0 == ut_strcmp(srv_file_flush_method_str, "normal")) {
|
2017-03-09 14:32:17 +00:00
|
|
|
srv_file_flush_method = SRV_FSYNC;
|
2014-02-26 19:11:54 +01:00
|
|
|
} else if (0 == ut_strcmp(srv_file_flush_method_str, "unbuffered")) {
|
|
|
|
} else if (0 == ut_strcmp(srv_file_flush_method_str,
|
|
|
|
"async_unbuffered")) {
|
2016-08-12 11:17:45 +03:00
|
|
|
#endif /* _WIN32 */
|
2014-02-26 19:11:54 +01:00
|
|
|
} else {
|
2016-08-12 11:17:45 +03:00
|
|
|
ib::error() << "Unrecognized value "
|
|
|
|
<< srv_file_flush_method_str
|
|
|
|
<< " for innodb_flush_method";
|
2017-01-31 19:43:03 +02:00
|
|
|
err = DB_ERROR;
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Note that the call srv_boot() also changes the values of
|
|
|
|
some variables to the units used by InnoDB internally */
|
|
|
|
|
|
|
|
/* Set the maximum number of threads which can wait for a semaphore
|
|
|
|
inside InnoDB: this is the 'sync wait array' size, as well as the
|
|
|
|
maximum number of threads that can wait in the 'srv_conc array' for
|
|
|
|
their time to enter InnoDB. */
|
|
|
|
|
2014-02-26 19:23:04 +01:00
|
|
|
srv_max_n_threads = 1 /* io_ibuf_thread */
|
|
|
|
+ 1 /* io_log_thread */
|
|
|
|
+ 1 /* lock_wait_timeout_thread */
|
|
|
|
+ 1 /* srv_error_monitor_thread */
|
|
|
|
+ 1 /* srv_monitor_thread */
|
|
|
|
+ 1 /* srv_master_thread */
|
|
|
|
+ 1 /* srv_purge_coordinator_thread */
|
|
|
|
+ 1 /* buf_dump_thread */
|
|
|
|
+ 1 /* dict_stats_thread */
|
|
|
|
+ 1 /* fts_optimize_thread */
|
|
|
|
+ 1 /* recv_writer_thread */
|
2017-12-21 15:45:40 +04:00
|
|
|
+ 1 /* trx_rollback_all_recovered */
|
2014-02-26 19:23:04 +01:00
|
|
|
+ 128 /* added as margin, for use of
|
|
|
|
InnoDB Memcached etc. */
|
|
|
|
+ max_connections
|
|
|
|
+ srv_n_read_io_threads
|
|
|
|
+ srv_n_write_io_threads
|
|
|
|
+ srv_n_purge_threads
|
2016-08-12 11:17:45 +03:00
|
|
|
+ srv_n_page_cleaners
|
2014-02-26 19:23:04 +01:00
|
|
|
/* FTS Parallel Sort */
|
|
|
|
+ fts_sort_pll_degree * FTS_NUM_AUX_INDEX
|
|
|
|
* max_connections;
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
if (srv_buf_pool_size >= BUF_POOL_SIZE_THRESHOLD) {
|
|
|
|
|
|
|
|
if (srv_buf_pool_instances == srv_buf_pool_instances_default) {
|
|
|
|
#if defined(_WIN32) && !defined(_WIN64)
|
|
|
|
/* Do not allocate too large of a buffer pool on
|
|
|
|
Windows 32-bit systems, which can have trouble
|
|
|
|
allocating larger single contiguous memory blocks. */
|
2017-06-30 15:19:26 +00:00
|
|
|
srv_buf_pool_size = static_cast<ulint>(ut_uint64_align_up(srv_buf_pool_size, srv_buf_pool_chunk_unit));
|
2016-08-12 11:17:45 +03:00
|
|
|
srv_buf_pool_instances = ut_min(
|
|
|
|
static_cast<ulong>(MAX_BUFFER_POOLS),
|
2017-06-30 15:19:26 +00:00
|
|
|
static_cast<ulong>(srv_buf_pool_size / srv_buf_pool_chunk_unit));
|
2016-08-12 11:17:45 +03:00
|
|
|
#else /* defined(_WIN32) && !defined(_WIN64) */
|
|
|
|
/* Default to 8 instances when size > 1GB. */
|
|
|
|
srv_buf_pool_instances = 8;
|
|
|
|
#endif /* defined(_WIN32) && !defined(_WIN64) */
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* If buffer pool is less than 1 GiB, assume fewer
|
|
|
|
threads. Also use only one buffer pool instance. */
|
|
|
|
if (srv_buf_pool_instances != srv_buf_pool_instances_default
|
|
|
|
&& srv_buf_pool_instances != 1) {
|
|
|
|
/* We can't distinguish whether the user has explicitly
|
|
|
|
started mysqld with --innodb-buffer-pool-instances=0,
|
|
|
|
(srv_buf_pool_instances_default is 0) or has not
|
|
|
|
specified that option at all. Thus we have the
|
|
|
|
limitation that if the user started with =0, we
|
|
|
|
will not emit a warning here, but we should actually
|
|
|
|
do so. */
|
|
|
|
ib::info()
|
|
|
|
<< "Adjusting innodb_buffer_pool_instances"
|
|
|
|
" from " << srv_buf_pool_instances << " to 1"
|
|
|
|
" since innodb_buffer_pool_size is less than "
|
|
|
|
<< BUF_POOL_SIZE_THRESHOLD / (1024 * 1024)
|
|
|
|
<< " MiB";
|
|
|
|
}
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
srv_buf_pool_instances = 1;
|
|
|
|
}
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
if (srv_buf_pool_chunk_unit * srv_buf_pool_instances
|
|
|
|
> srv_buf_pool_size) {
|
|
|
|
/* Size unit of buffer pool is larger than srv_buf_pool_size.
|
|
|
|
adjust srv_buf_pool_chunk_unit for srv_buf_pool_size. */
|
|
|
|
srv_buf_pool_chunk_unit
|
|
|
|
= static_cast<ulong>(srv_buf_pool_size)
|
|
|
|
/ srv_buf_pool_instances;
|
|
|
|
if (srv_buf_pool_size % srv_buf_pool_instances != 0) {
|
|
|
|
++srv_buf_pool_chunk_unit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
srv_buf_pool_size = buf_pool_size_align(srv_buf_pool_size);
|
|
|
|
|
|
|
|
if (srv_n_page_cleaners > srv_buf_pool_instances) {
|
|
|
|
/* limit of page_cleaner parallelizability
|
|
|
|
is number of buffer pool instances. */
|
|
|
|
srv_n_page_cleaners = srv_buf_pool_instances;
|
|
|
|
}
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
srv_boot();
|
|
|
|
|
2016-12-01 12:35:59 +11:00
|
|
|
ib::info() << ut_crc32_implementation;
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
if (!srv_read_only_mode) {
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
mutex_create(LATCH_ID_SRV_MONITOR_FILE,
|
|
|
|
&srv_monitor_file_mutex);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
if (srv_innodb_status) {
|
|
|
|
|
|
|
|
srv_monitor_file_name = static_cast<char*>(
|
2016-08-12 11:17:45 +03:00
|
|
|
ut_malloc_nokey(
|
2014-02-26 19:11:54 +01:00
|
|
|
strlen(fil_path_to_mysql_datadir)
|
|
|
|
+ 20 + sizeof "/innodb_status."));
|
|
|
|
|
2016-09-06 09:43:16 +03:00
|
|
|
sprintf(srv_monitor_file_name,
|
|
|
|
"%s/innodb_status." ULINTPF,
|
2014-02-26 19:11:54 +01:00
|
|
|
fil_path_to_mysql_datadir,
|
|
|
|
os_proc_get_number());
|
|
|
|
|
|
|
|
srv_monitor_file = fopen(srv_monitor_file_name, "w+");
|
|
|
|
|
|
|
|
if (!srv_monitor_file) {
|
2016-08-12 11:17:45 +03:00
|
|
|
ib::error() << "Unable to create "
|
|
|
|
<< srv_monitor_file_name << ": "
|
|
|
|
<< strerror(errno);
|
2017-03-08 22:36:10 +02:00
|
|
|
if (err == DB_SUCCESS) {
|
|
|
|
err = DB_ERROR;
|
|
|
|
}
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
} else {
|
2016-08-12 11:17:45 +03:00
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
srv_monitor_file_name = NULL;
|
2016-09-06 09:43:16 +03:00
|
|
|
srv_monitor_file = os_file_create_tmpfile(NULL);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2017-03-08 22:36:10 +02:00
|
|
|
if (!srv_monitor_file && err == DB_SUCCESS) {
|
|
|
|
err = DB_ERROR;
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
mutex_create(LATCH_ID_SRV_MISC_TMPFILE,
|
|
|
|
&srv_misc_tmpfile_mutex);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-09-06 09:43:16 +03:00
|
|
|
srv_misc_tmpfile = os_file_create_tmpfile(NULL);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2017-03-08 22:36:10 +02:00
|
|
|
if (!srv_misc_tmpfile && err == DB_SUCCESS) {
|
|
|
|
err = DB_ERROR;
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-08 22:36:10 +02:00
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
return(srv_init_abort(err));
|
|
|
|
}
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
srv_n_file_io_threads = srv_n_read_io_threads;
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
srv_n_file_io_threads += srv_n_write_io_threads;
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
if (!srv_read_only_mode) {
|
|
|
|
/* Add the log and ibuf IO threads. */
|
|
|
|
srv_n_file_io_threads += 2;
|
|
|
|
} else {
|
2016-08-12 11:17:45 +03:00
|
|
|
ib::info() << "Disabling background log and ibuf IO write"
|
|
|
|
<< " threads.";
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ut_a(srv_n_file_io_threads <= SRV_MAX_N_IO_THREADS);
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
if (!os_aio_init(srv_n_read_io_threads,
|
2014-02-26 19:11:54 +01:00
|
|
|
srv_n_write_io_threads,
|
|
|
|
SRV_MAX_N_PENDING_SYNC_IOS)) {
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
ib::error() << "Cannot initialize AIO sub-system";
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
return(srv_init_abort(DB_ERROR));
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fil_init(srv_file_per_table ? 50000 : 5000, srv_max_n_open_files);
|
|
|
|
|
|
|
|
double size;
|
|
|
|
char unit;
|
|
|
|
|
|
|
|
if (srv_buf_pool_size >= 1024 * 1024 * 1024) {
|
|
|
|
size = ((double) srv_buf_pool_size) / (1024 * 1024 * 1024);
|
|
|
|
unit = 'G';
|
|
|
|
} else {
|
|
|
|
size = ((double) srv_buf_pool_size) / (1024 * 1024);
|
|
|
|
unit = 'M';
|
|
|
|
}
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
double chunk_size;
|
|
|
|
char chunk_unit;
|
|
|
|
|
|
|
|
if (srv_buf_pool_chunk_unit >= 1024 * 1024 * 1024) {
|
|
|
|
chunk_size = srv_buf_pool_chunk_unit / 1024.0 / 1024 / 1024;
|
|
|
|
chunk_unit = 'G';
|
|
|
|
} else {
|
|
|
|
chunk_size = srv_buf_pool_chunk_unit / 1024.0 / 1024;
|
|
|
|
chunk_unit = 'M';
|
|
|
|
}
|
|
|
|
|
|
|
|
ib::info() << "Initializing buffer pool, total size = "
|
|
|
|
<< size << unit << ", instances = " << srv_buf_pool_instances
|
|
|
|
<< ", chunk size = " << chunk_size << chunk_unit;
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
err = buf_pool_init(srv_buf_pool_size, srv_buf_pool_instances);
|
|
|
|
|
|
|
|
if (err != DB_SUCCESS) {
|
2016-08-12 11:17:45 +03:00
|
|
|
ib::error() << "Cannot allocate memory for the buffer pool";
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
return(srv_init_abort(DB_ERROR));
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
ib::info() << "Completed initialization of buffer pool";
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
#ifdef UNIV_DEBUG
|
|
|
|
/* We have observed deadlocks with a 5MB buffer pool but
|
|
|
|
the actual lower limit could very well be a little higher. */
|
|
|
|
|
|
|
|
if (srv_buf_pool_size <= 5 * 1024 * 1024) {
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
ib::info() << "Small buffer pool size ("
|
|
|
|
<< srv_buf_pool_size / 1024 / 1024
|
|
|
|
<< "M), the flst_validate() debug function can cause a"
|
|
|
|
<< " deadlock if the buffer pool fills up.";
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
#endif /* UNIV_DEBUG */
|
|
|
|
|
|
|
|
fsp_init();
|
2017-05-26 14:04:19 +03:00
|
|
|
log_sys_init();
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2017-06-29 22:24:48 +03:00
|
|
|
recv_sys_init();
|
2014-02-26 19:11:54 +01:00
|
|
|
lock_sys_create(srv_lock_table_size);
|
|
|
|
|
|
|
|
/* Create i/o-handler threads: */
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
for (ulint t = 0; t < srv_n_file_io_threads; ++t) {
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
n[t] = t;
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
thread_handles[t] = os_thread_create(io_handler_thread, n + t, thread_ids + t);
|
|
|
|
thread_started[t] = true;
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
2016-12-05 21:04:30 +02:00
|
|
|
if (!srv_read_only_mode) {
|
|
|
|
buf_flush_page_cleaner_init();
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2017-06-12 17:43:07 +03:00
|
|
|
buf_page_cleaner_is_active = true;
|
2016-12-05 21:04:30 +02:00
|
|
|
os_thread_create(buf_flush_page_cleaner_coordinator,
|
|
|
|
NULL, NULL);
|
2016-08-12 11:17:45 +03:00
|
|
|
|
2017-09-09 11:34:12 +03:00
|
|
|
/* Create page cleaner workers if needed. For example
|
|
|
|
mariabackup could set srv_n_page_cleaners = 0. */
|
|
|
|
if (srv_n_page_cleaners > 1) {
|
|
|
|
buf_flush_set_page_cleaner_thread_cnt(srv_n_page_cleaners);
|
2016-12-05 21:04:30 +02:00
|
|
|
}
|
2016-08-12 11:17:45 +03:00
|
|
|
|
2017-06-23 22:54:42 +03:00
|
|
|
#ifdef UNIV_LINUX
|
|
|
|
/* Wait for the setpriority() call to finish. */
|
|
|
|
os_event_wait(recv_sys->flush_end);
|
|
|
|
#endif /* UNIV_LINUX */
|
2016-12-05 21:04:30 +02:00
|
|
|
srv_start_state_set(SRV_START_STATE_IO);
|
|
|
|
}
|
2014-02-26 19:11:54 +01:00
|
|
|
|
Reduce the granularity of innodb_log_file_size
In Mariabackup, we would want the backed-up redo log file size to be
a multiple of 512 bytes, or OS_FILE_LOG_BLOCK_SIZE. However, at startup,
InnoDB would be picky, requiring the file size to be a multiple of
innodb_page_size.
Furthermore, InnoDB would require the parameter to be a multiple of
one megabyte, while the minimum granularity is 512 bytes. Because
the data-file-oriented fil_io() API is being used for writing the
InnoDB redo log, writes will for now require innodb_log_file_size to
be a multiple of the maximum innodb_page_size (65536 bytes).
To complicate matters, InnoDB startup divided srv_log_file_size by
UNIV_PAGE_SIZE, so that initially, the unit was bytes, and later it
was innodb_page_size. We will simplify this and keep srv_log_file_size
in bytes at all times.
innobase_log_file_size: Remove. Remove some obsolete checks against
overflow on 32-bit systems. srv_log_file_size is always 64 bits, and
the maximum size 512GiB in multiples of innodb_page_size always fits
in ulint (which is 32 or 64 bits). 512GiB would be 8,388,608*64KiB or
134,217,728*4KiB.
log_init(): Remove the parameter file_size that was always passed as
srv_log_file_size.
log_set_capacity(): Add a parameter for passing the requested file size.
srv_log_file_size_requested: Declare static in srv0start.cc.
create_log_file(), create_log_files(),
innobase_start_or_create_for_mysql(): Invoke fil_node_create()
with srv_log_file_size expressed in multiples of innodb_page_size.
innobase_start_or_create_for_mysql(): Require the redo log file sizes
to be multiples of 512 bytes.
2017-06-05 22:47:20 +03:00
|
|
|
if (srv_n_log_files * srv_log_file_size >= 512ULL << 30) {
|
2014-02-26 19:11:54 +01:00
|
|
|
/* log_block_convert_lsn_to_no() limits the returned block
|
|
|
|
number to 1G and given that OS_FILE_LOG_BLOCK_SIZE is 512
|
|
|
|
bytes, then we have a limit of 512 GB. If that limit is to
|
|
|
|
be raised, then log_block_convert_lsn_to_no() must be
|
|
|
|
modified. */
|
2016-08-12 11:17:45 +03:00
|
|
|
ib::error() << "Combined size of log files must be < 512 GB";
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
return(srv_init_abort(DB_ERROR));
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
os_normalize_path(srv_data_home);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/* Check if the data files exist or not. */
|
|
|
|
err = srv_sys_space.check_file_spec(
|
|
|
|
&create_new_db, MIN_EXPECTED_TABLESPACE_SIZE);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
return(srv_init_abort(DB_ERROR));
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
srv_startup_is_before_trx_rollback_phase = !create_new_db;
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/* Check if undo tablespaces and redo log files exist before creating
|
|
|
|
a new system tablespace */
|
|
|
|
if (create_new_db) {
|
|
|
|
err = srv_check_undo_redo_logs_exists();
|
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
return(srv_init_abort(DB_ERROR));
|
|
|
|
}
|
|
|
|
recv_sys_debug_free();
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/* Open or create the data files. */
|
|
|
|
ulint sum_of_new_sizes;
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
err = srv_sys_space.open_or_create(
|
|
|
|
false, create_new_db, &sum_of_new_sizes, &flushed_lsn);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
switch (err) {
|
|
|
|
case DB_SUCCESS:
|
|
|
|
break;
|
|
|
|
case DB_CANNOT_OPEN_FILE:
|
|
|
|
ib::error()
|
|
|
|
<< "Could not open or create the system tablespace. If"
|
|
|
|
" you tried to add new data files to the system"
|
|
|
|
" tablespace, and it failed here, you should now"
|
|
|
|
" edit innodb_data_file_path in my.cnf back to what"
|
|
|
|
" it was, and remove the new ibdata files InnoDB"
|
|
|
|
" created in this failed attempt. InnoDB only wrote"
|
|
|
|
" those files full of zeros, but did not yet use"
|
|
|
|
" them in any way. But be careful: do not remove"
|
|
|
|
" old data files which contain your precious data!";
|
|
|
|
/* fall through */
|
|
|
|
default:
|
|
|
|
/* Other errors might come from Datafile::validate_first_page() */
|
|
|
|
return(srv_init_abort(err));
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
dirnamelen = strlen(srv_log_group_home_dir);
|
|
|
|
ut_a(dirnamelen < (sizeof logfilename) - 10 - sizeof "ib_logfile");
|
|
|
|
memcpy(logfilename, srv_log_group_home_dir, dirnamelen);
|
|
|
|
|
|
|
|
/* Add a path separator if needed. */
|
2016-08-12 11:17:45 +03:00
|
|
|
if (dirnamelen && logfilename[dirnamelen - 1] != OS_PATH_SEPARATOR) {
|
|
|
|
logfilename[dirnamelen++] = OS_PATH_SEPARATOR;
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
srv_log_file_size_requested = srv_log_file_size;
|
|
|
|
|
|
|
|
if (create_new_db) {
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
buf_flush_sync_all_buf_pools();
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
flushed_lsn = log_get_lsn();
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
err = create_log_files(
|
|
|
|
logfilename, dirnamelen, flushed_lsn, logfile0);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
if (err != DB_SUCCESS) {
|
2016-08-12 11:17:45 +03:00
|
|
|
return(srv_init_abort(err));
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < SRV_N_LOG_FILES_MAX; i++) {
|
|
|
|
os_offset_t size;
|
|
|
|
os_file_stat_t stat_info;
|
|
|
|
|
|
|
|
sprintf(logfilename + dirnamelen,
|
|
|
|
"ib_logfile%u", i);
|
|
|
|
|
|
|
|
err = os_file_get_status(
|
2016-08-12 11:17:45 +03:00
|
|
|
logfilename, &stat_info, false,
|
|
|
|
srv_read_only_mode);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
if (err == DB_NOT_FOUND) {
|
|
|
|
if (i == 0) {
|
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2
InnoDB I/O and buffer pool interfaces and the redo log format
have been changed between MariaDB 10.1 and 10.2, and the backup
code has to be adjusted accordingly.
The code has been simplified, and many memory leaks have been fixed.
Instead of the file name xtrabackup_logfile, the file name ib_logfile0
is being used for the copy of the redo log. Unnecessary InnoDB startup and
shutdown and some unnecessary threads have been removed.
Some help was provided by Vladislav Vaintroub.
Parameters have been cleaned up and aligned with those of MariaDB 10.2.
The --dbug option has been added, so that in debug builds,
--dbug=d,ib_log can be specified to enable diagnostic messages
for processing redo log entries.
By default, innodb_doublewrite=OFF, so that --prepare works faster.
If more crash-safety for --prepare is needed, double buffering
can be enabled.
The parameter innodb_log_checksums=OFF can be used to ignore redo log
checksums in --backup.
Some messages have been cleaned up.
Unless --export is specified, Mariabackup will not deal with undo log.
The InnoDB mini-transaction redo log is not only about user-level
transactions; it is actually about mini-transactions. To avoid confusion,
call it the redo log, not transaction log.
We disable any undo log processing in --prepare.
Because MariaDB 10.2 supports indexed virtual columns, the
undo log processing would need to be able to evaluate virtual column
expressions. To reduce the amount of code dependencies, we will not
process any undo log in prepare.
This means that the --export option must be disabled for now.
This also means that the following options are redundant
and have been removed:
xtrabackup --apply-log-only
innobackupex --redo-only
In addition to disabling any undo log processing, we will disable any
further changes to data pages during --prepare, including the change
buffer merge. This means that restoring incremental backups should
reliably work even when change buffering is being used on the server.
Because of this, preparing a backup will not generate any further
redo log, and the redo log file can be safely deleted. (If the
--export option is enabled in the future, it must generate redo log
when processing undo logs and buffered changes.)
In --prepare, we cannot easily know if a partial backup was used,
especially when restoring a series of incremental backups. So, we
simply warn about any missing files, and ignore the redo log for them.
FIXME: Enable the --export option.
FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write
a test that initiates a backup while an ALGORITHM=INPLACE operation
is creating indexes or rebuilding a table. An error should be detected
when preparing the backup.
FIXME: In --incremental --prepare, xtrabackup_apply_delta() should
ensure that if FSP_SIZE is modified, the file size will be adjusted
accordingly.
2017-06-30 10:49:37 +03:00
|
|
|
if (srv_operation
|
2017-10-10 10:28:54 +03:00
|
|
|
== SRV_OPERATION_RESTORE
|
|
|
|
|| srv_operation
|
|
|
|
== SRV_OPERATION_RESTORE_EXPORT) {
|
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2
InnoDB I/O and buffer pool interfaces and the redo log format
have been changed between MariaDB 10.1 and 10.2, and the backup
code has to be adjusted accordingly.
The code has been simplified, and many memory leaks have been fixed.
Instead of the file name xtrabackup_logfile, the file name ib_logfile0
is being used for the copy of the redo log. Unnecessary InnoDB startup and
shutdown and some unnecessary threads have been removed.
Some help was provided by Vladislav Vaintroub.
Parameters have been cleaned up and aligned with those of MariaDB 10.2.
The --dbug option has been added, so that in debug builds,
--dbug=d,ib_log can be specified to enable diagnostic messages
for processing redo log entries.
By default, innodb_doublewrite=OFF, so that --prepare works faster.
If more crash-safety for --prepare is needed, double buffering
can be enabled.
The parameter innodb_log_checksums=OFF can be used to ignore redo log
checksums in --backup.
Some messages have been cleaned up.
Unless --export is specified, Mariabackup will not deal with undo log.
The InnoDB mini-transaction redo log is not only about user-level
transactions; it is actually about mini-transactions. To avoid confusion,
call it the redo log, not transaction log.
We disable any undo log processing in --prepare.
Because MariaDB 10.2 supports indexed virtual columns, the
undo log processing would need to be able to evaluate virtual column
expressions. To reduce the amount of code dependencies, we will not
process any undo log in prepare.
This means that the --export option must be disabled for now.
This also means that the following options are redundant
and have been removed:
xtrabackup --apply-log-only
innobackupex --redo-only
In addition to disabling any undo log processing, we will disable any
further changes to data pages during --prepare, including the change
buffer merge. This means that restoring incremental backups should
reliably work even when change buffering is being used on the server.
Because of this, preparing a backup will not generate any further
redo log, and the redo log file can be safely deleted. (If the
--export option is enabled in the future, it must generate redo log
when processing undo logs and buffered changes.)
In --prepare, we cannot easily know if a partial backup was used,
especially when restoring a series of incremental backups. So, we
simply warn about any missing files, and ignore the redo log for them.
FIXME: Enable the --export option.
FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write
a test that initiates a backup while an ALGORITHM=INPLACE operation
is creating indexes or rebuilding a table. An error should be detected
when preparing the backup.
FIXME: In --incremental --prepare, xtrabackup_apply_delta() should
ensure that if FSP_SIZE is modified, the file size will be adjusted
accordingly.
2017-06-30 10:49:37 +03:00
|
|
|
return(DB_SUCCESS);
|
|
|
|
}
|
2016-08-12 11:17:45 +03:00
|
|
|
if (flushed_lsn
|
|
|
|
< static_cast<lsn_t>(1000)) {
|
|
|
|
ib::error()
|
|
|
|
<< "Cannot create"
|
2014-02-26 19:11:54 +01:00
|
|
|
" log files because"
|
|
|
|
" data files are"
|
|
|
|
" corrupt or the"
|
|
|
|
" database was not"
|
|
|
|
" shut down cleanly"
|
|
|
|
" after creating"
|
2016-08-12 11:17:45 +03:00
|
|
|
" the data files.";
|
|
|
|
return(srv_init_abort(
|
|
|
|
DB_ERROR));
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
err = create_log_files(
|
2016-08-12 11:17:45 +03:00
|
|
|
logfilename, dirnamelen,
|
|
|
|
flushed_lsn, logfile0);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2017-01-30 17:00:51 +02:00
|
|
|
if (err == DB_SUCCESS) {
|
|
|
|
err = create_log_files_rename(
|
|
|
|
logfilename,
|
|
|
|
dirnamelen,
|
|
|
|
flushed_lsn, logfile0);
|
|
|
|
}
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
if (err != DB_SUCCESS) {
|
2016-08-12 11:17:45 +03:00
|
|
|
return(srv_init_abort(err));
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Suppress the message about
|
|
|
|
crash recovery. */
|
2016-08-12 11:17:45 +03:00
|
|
|
flushed_lsn = log_get_lsn();
|
2014-02-26 19:11:54 +01:00
|
|
|
goto files_checked;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* opened all files */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!srv_file_check_mode(logfilename)) {
|
2016-08-12 11:17:45 +03:00
|
|
|
return(srv_init_abort(DB_ERROR));
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
err = open_log_file(&files[i], logfilename, &size);
|
|
|
|
|
|
|
|
if (err != DB_SUCCESS) {
|
2016-08-12 11:17:45 +03:00
|
|
|
return(srv_init_abort(err));
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ut_a(size != (os_offset_t) -1);
|
|
|
|
|
Reduce the granularity of innodb_log_file_size
In Mariabackup, we would want the backed-up redo log file size to be
a multiple of 512 bytes, or OS_FILE_LOG_BLOCK_SIZE. However, at startup,
InnoDB would be picky, requiring the file size to be a multiple of
innodb_page_size.
Furthermore, InnoDB would require the parameter to be a multiple of
one megabyte, while the minimum granularity is 512 bytes. Because
the data-file-oriented fil_io() API is being used for writing the
InnoDB redo log, writes will for now require innodb_log_file_size to
be a multiple of the maximum innodb_page_size (65536 bytes).
To complicate matters, InnoDB startup divided srv_log_file_size by
UNIV_PAGE_SIZE, so that initially, the unit was bytes, and later it
was innodb_page_size. We will simplify this and keep srv_log_file_size
in bytes at all times.
innobase_log_file_size: Remove. Remove some obsolete checks against
overflow on 32-bit systems. srv_log_file_size is always 64 bits, and
the maximum size 512GiB in multiples of innodb_page_size always fits
in ulint (which is 32 or 64 bits). 512GiB would be 8,388,608*64KiB or
134,217,728*4KiB.
log_init(): Remove the parameter file_size that was always passed as
srv_log_file_size.
log_set_capacity(): Add a parameter for passing the requested file size.
srv_log_file_size_requested: Declare static in srv0start.cc.
create_log_file(), create_log_files(),
innobase_start_or_create_for_mysql(): Invoke fil_node_create()
with srv_log_file_size expressed in multiples of innodb_page_size.
innobase_start_or_create_for_mysql(): Require the redo log file sizes
to be multiples of 512 bytes.
2017-06-05 22:47:20 +03:00
|
|
|
if (size & (OS_FILE_LOG_BLOCK_SIZE - 1)) {
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
ib::error() << "Log file " << logfilename
|
|
|
|
<< " size " << size << " is not a"
|
Reduce the granularity of innodb_log_file_size
In Mariabackup, we would want the backed-up redo log file size to be
a multiple of 512 bytes, or OS_FILE_LOG_BLOCK_SIZE. However, at startup,
InnoDB would be picky, requiring the file size to be a multiple of
innodb_page_size.
Furthermore, InnoDB would require the parameter to be a multiple of
one megabyte, while the minimum granularity is 512 bytes. Because
the data-file-oriented fil_io() API is being used for writing the
InnoDB redo log, writes will for now require innodb_log_file_size to
be a multiple of the maximum innodb_page_size (65536 bytes).
To complicate matters, InnoDB startup divided srv_log_file_size by
UNIV_PAGE_SIZE, so that initially, the unit was bytes, and later it
was innodb_page_size. We will simplify this and keep srv_log_file_size
in bytes at all times.
innobase_log_file_size: Remove. Remove some obsolete checks against
overflow on 32-bit systems. srv_log_file_size is always 64 bits, and
the maximum size 512GiB in multiples of innodb_page_size always fits
in ulint (which is 32 or 64 bits). 512GiB would be 8,388,608*64KiB or
134,217,728*4KiB.
log_init(): Remove the parameter file_size that was always passed as
srv_log_file_size.
log_set_capacity(): Add a parameter for passing the requested file size.
srv_log_file_size_requested: Declare static in srv0start.cc.
create_log_file(), create_log_files(),
innobase_start_or_create_for_mysql(): Invoke fil_node_create()
with srv_log_file_size expressed in multiples of innodb_page_size.
innobase_start_or_create_for_mysql(): Require the redo log file sizes
to be multiples of 512 bytes.
2017-06-05 22:47:20 +03:00
|
|
|
" multiple of 512 bytes";
|
2016-08-12 11:17:45 +03:00
|
|
|
return(srv_init_abort(DB_ERROR));
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (i == 0) {
|
2017-10-10 10:28:54 +03:00
|
|
|
if (size == 0
|
|
|
|
&& (srv_operation
|
|
|
|
== SRV_OPERATION_RESTORE
|
|
|
|
|| srv_operation
|
|
|
|
== SRV_OPERATION_RESTORE_EXPORT)) {
|
|
|
|
/* Tolerate an empty ib_logfile0
|
|
|
|
from a previous run of
|
|
|
|
mariabackup --prepare. */
|
|
|
|
return(DB_SUCCESS);
|
|
|
|
}
|
|
|
|
/* The first log file must consist of
|
|
|
|
at least the following 512-byte pages:
|
|
|
|
header, checkpoint page 1, empty,
|
|
|
|
checkpoint page 2, redo log page(s) */
|
|
|
|
if (size <= OS_FILE_LOG_BLOCK_SIZE * 4) {
|
|
|
|
ib::error() << "Log file "
|
|
|
|
<< logfilename << " size "
|
|
|
|
<< size << " is too small";
|
|
|
|
return(srv_init_abort(DB_ERROR));
|
|
|
|
}
|
2014-02-26 19:11:54 +01:00
|
|
|
srv_log_file_size = size;
|
|
|
|
} else if (size != srv_log_file_size) {
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
ib::error() << "Log file " << logfilename
|
Reduce the granularity of innodb_log_file_size
In Mariabackup, we would want the backed-up redo log file size to be
a multiple of 512 bytes, or OS_FILE_LOG_BLOCK_SIZE. However, at startup,
InnoDB would be picky, requiring the file size to be a multiple of
innodb_page_size.
Furthermore, InnoDB would require the parameter to be a multiple of
one megabyte, while the minimum granularity is 512 bytes. Because
the data-file-oriented fil_io() API is being used for writing the
InnoDB redo log, writes will for now require innodb_log_file_size to
be a multiple of the maximum innodb_page_size (65536 bytes).
To complicate matters, InnoDB startup divided srv_log_file_size by
UNIV_PAGE_SIZE, so that initially, the unit was bytes, and later it
was innodb_page_size. We will simplify this and keep srv_log_file_size
in bytes at all times.
innobase_log_file_size: Remove. Remove some obsolete checks against
overflow on 32-bit systems. srv_log_file_size is always 64 bits, and
the maximum size 512GiB in multiples of innodb_page_size always fits
in ulint (which is 32 or 64 bits). 512GiB would be 8,388,608*64KiB or
134,217,728*4KiB.
log_init(): Remove the parameter file_size that was always passed as
srv_log_file_size.
log_set_capacity(): Add a parameter for passing the requested file size.
srv_log_file_size_requested: Declare static in srv0start.cc.
create_log_file(), create_log_files(),
innobase_start_or_create_for_mysql(): Invoke fil_node_create()
with srv_log_file_size expressed in multiples of innodb_page_size.
innobase_start_or_create_for_mysql(): Require the redo log file sizes
to be multiples of 512 bytes.
2017-06-05 22:47:20 +03:00
|
|
|
<< " is of different size " << size
|
2016-08-12 11:17:45 +03:00
|
|
|
<< " bytes than other log files "
|
Reduce the granularity of innodb_log_file_size
In Mariabackup, we would want the backed-up redo log file size to be
a multiple of 512 bytes, or OS_FILE_LOG_BLOCK_SIZE. However, at startup,
InnoDB would be picky, requiring the file size to be a multiple of
innodb_page_size.
Furthermore, InnoDB would require the parameter to be a multiple of
one megabyte, while the minimum granularity is 512 bytes. Because
the data-file-oriented fil_io() API is being used for writing the
InnoDB redo log, writes will for now require innodb_log_file_size to
be a multiple of the maximum innodb_page_size (65536 bytes).
To complicate matters, InnoDB startup divided srv_log_file_size by
UNIV_PAGE_SIZE, so that initially, the unit was bytes, and later it
was innodb_page_size. We will simplify this and keep srv_log_file_size
in bytes at all times.
innobase_log_file_size: Remove. Remove some obsolete checks against
overflow on 32-bit systems. srv_log_file_size is always 64 bits, and
the maximum size 512GiB in multiples of innodb_page_size always fits
in ulint (which is 32 or 64 bits). 512GiB would be 8,388,608*64KiB or
134,217,728*4KiB.
log_init(): Remove the parameter file_size that was always passed as
srv_log_file_size.
log_set_capacity(): Add a parameter for passing the requested file size.
srv_log_file_size_requested: Declare static in srv0start.cc.
create_log_file(), create_log_files(),
innobase_start_or_create_for_mysql(): Invoke fil_node_create()
with srv_log_file_size expressed in multiples of innodb_page_size.
innobase_start_or_create_for_mysql(): Require the redo log file sizes
to be multiples of 512 bytes.
2017-06-05 22:47:20 +03:00
|
|
|
<< srv_log_file_size << " bytes!";
|
2016-08-12 11:17:45 +03:00
|
|
|
return(srv_init_abort(DB_ERROR));
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
srv_n_log_files_found = i;
|
|
|
|
|
|
|
|
/* Create the in-memory file space objects. */
|
|
|
|
|
|
|
|
sprintf(logfilename + dirnamelen, "ib_logfile%u", 0);
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/* Disable the doublewrite buffer for log files. */
|
|
|
|
fil_space_t* log_space = fil_space_create(
|
|
|
|
"innodb_redo_log",
|
2017-01-19 12:06:13 +02:00
|
|
|
SRV_LOG_SPACE_FIRST_ID, 0,
|
2016-08-12 11:17:45 +03:00
|
|
|
FIL_TYPE_LOG,
|
2017-06-12 17:43:07 +03:00
|
|
|
NULL /* no encryption yet */);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
ut_a(fil_validate());
|
2016-08-12 11:17:45 +03:00
|
|
|
ut_a(log_space);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
Reduce the granularity of innodb_log_file_size
In Mariabackup, we would want the backed-up redo log file size to be
a multiple of 512 bytes, or OS_FILE_LOG_BLOCK_SIZE. However, at startup,
InnoDB would be picky, requiring the file size to be a multiple of
innodb_page_size.
Furthermore, InnoDB would require the parameter to be a multiple of
one megabyte, while the minimum granularity is 512 bytes. Because
the data-file-oriented fil_io() API is being used for writing the
InnoDB redo log, writes will for now require innodb_log_file_size to
be a multiple of the maximum innodb_page_size (65536 bytes).
To complicate matters, InnoDB startup divided srv_log_file_size by
UNIV_PAGE_SIZE, so that initially, the unit was bytes, and later it
was innodb_page_size. We will simplify this and keep srv_log_file_size
in bytes at all times.
innobase_log_file_size: Remove. Remove some obsolete checks against
overflow on 32-bit systems. srv_log_file_size is always 64 bits, and
the maximum size 512GiB in multiples of innodb_page_size always fits
in ulint (which is 32 or 64 bits). 512GiB would be 8,388,608*64KiB or
134,217,728*4KiB.
log_init(): Remove the parameter file_size that was always passed as
srv_log_file_size.
log_set_capacity(): Add a parameter for passing the requested file size.
srv_log_file_size_requested: Declare static in srv0start.cc.
create_log_file(), create_log_files(),
innobase_start_or_create_for_mysql(): Invoke fil_node_create()
with srv_log_file_size expressed in multiples of innodb_page_size.
innobase_start_or_create_for_mysql(): Require the redo log file sizes
to be multiples of 512 bytes.
2017-06-05 22:47:20 +03:00
|
|
|
ut_a(srv_log_file_size <= 512ULL << 30);
|
|
|
|
|
|
|
|
const ulint size = 1 + ulint((srv_log_file_size - 1)
|
|
|
|
>> srv_page_size_shift);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
Reduce the granularity of innodb_log_file_size
In Mariabackup, we would want the backed-up redo log file size to be
a multiple of 512 bytes, or OS_FILE_LOG_BLOCK_SIZE. However, at startup,
InnoDB would be picky, requiring the file size to be a multiple of
innodb_page_size.
Furthermore, InnoDB would require the parameter to be a multiple of
one megabyte, while the minimum granularity is 512 bytes. Because
the data-file-oriented fil_io() API is being used for writing the
InnoDB redo log, writes will for now require innodb_log_file_size to
be a multiple of the maximum innodb_page_size (65536 bytes).
To complicate matters, InnoDB startup divided srv_log_file_size by
UNIV_PAGE_SIZE, so that initially, the unit was bytes, and later it
was innodb_page_size. We will simplify this and keep srv_log_file_size
in bytes at all times.
innobase_log_file_size: Remove. Remove some obsolete checks against
overflow on 32-bit systems. srv_log_file_size is always 64 bits, and
the maximum size 512GiB in multiples of innodb_page_size always fits
in ulint (which is 32 or 64 bits). 512GiB would be 8,388,608*64KiB or
134,217,728*4KiB.
log_init(): Remove the parameter file_size that was always passed as
srv_log_file_size.
log_set_capacity(): Add a parameter for passing the requested file size.
srv_log_file_size_requested: Declare static in srv0start.cc.
create_log_file(), create_log_files(),
innobase_start_or_create_for_mysql(): Invoke fil_node_create()
with srv_log_file_size expressed in multiples of innodb_page_size.
innobase_start_or_create_for_mysql(): Require the redo log file sizes
to be multiples of 512 bytes.
2017-06-05 22:47:20 +03:00
|
|
|
for (unsigned j = 0; j < srv_n_log_files_found; j++) {
|
2014-02-26 19:11:54 +01:00
|
|
|
sprintf(logfilename + dirnamelen, "ib_logfile%u", j);
|
|
|
|
|
Reduce the granularity of innodb_log_file_size
In Mariabackup, we would want the backed-up redo log file size to be
a multiple of 512 bytes, or OS_FILE_LOG_BLOCK_SIZE. However, at startup,
InnoDB would be picky, requiring the file size to be a multiple of
innodb_page_size.
Furthermore, InnoDB would require the parameter to be a multiple of
one megabyte, while the minimum granularity is 512 bytes. Because
the data-file-oriented fil_io() API is being used for writing the
InnoDB redo log, writes will for now require innodb_log_file_size to
be a multiple of the maximum innodb_page_size (65536 bytes).
To complicate matters, InnoDB startup divided srv_log_file_size by
UNIV_PAGE_SIZE, so that initially, the unit was bytes, and later it
was innodb_page_size. We will simplify this and keep srv_log_file_size
in bytes at all times.
innobase_log_file_size: Remove. Remove some obsolete checks against
overflow on 32-bit systems. srv_log_file_size is always 64 bits, and
the maximum size 512GiB in multiples of innodb_page_size always fits
in ulint (which is 32 or 64 bits). 512GiB would be 8,388,608*64KiB or
134,217,728*4KiB.
log_init(): Remove the parameter file_size that was always passed as
srv_log_file_size.
log_set_capacity(): Add a parameter for passing the requested file size.
srv_log_file_size_requested: Declare static in srv0start.cc.
create_log_file(), create_log_files(),
innobase_start_or_create_for_mysql(): Invoke fil_node_create()
with srv_log_file_size expressed in multiples of innodb_page_size.
innobase_start_or_create_for_mysql(): Require the redo log file sizes
to be multiples of 512 bytes.
2017-06-05 22:47:20 +03:00
|
|
|
if (!fil_node_create(logfilename, size,
|
2016-08-12 11:17:45 +03:00
|
|
|
log_space, false, false)) {
|
|
|
|
return(srv_init_abort(DB_ERROR));
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Reduce the granularity of innodb_log_file_size
In Mariabackup, we would want the backed-up redo log file size to be
a multiple of 512 bytes, or OS_FILE_LOG_BLOCK_SIZE. However, at startup,
InnoDB would be picky, requiring the file size to be a multiple of
innodb_page_size.
Furthermore, InnoDB would require the parameter to be a multiple of
one megabyte, while the minimum granularity is 512 bytes. Because
the data-file-oriented fil_io() API is being used for writing the
InnoDB redo log, writes will for now require innodb_log_file_size to
be a multiple of the maximum innodb_page_size (65536 bytes).
To complicate matters, InnoDB startup divided srv_log_file_size by
UNIV_PAGE_SIZE, so that initially, the unit was bytes, and later it
was innodb_page_size. We will simplify this and keep srv_log_file_size
in bytes at all times.
innobase_log_file_size: Remove. Remove some obsolete checks against
overflow on 32-bit systems. srv_log_file_size is always 64 bits, and
the maximum size 512GiB in multiples of innodb_page_size always fits
in ulint (which is 32 or 64 bits). 512GiB would be 8,388,608*64KiB or
134,217,728*4KiB.
log_init(): Remove the parameter file_size that was always passed as
srv_log_file_size.
log_set_capacity(): Add a parameter for passing the requested file size.
srv_log_file_size_requested: Declare static in srv0start.cc.
create_log_file(), create_log_files(),
innobase_start_or_create_for_mysql(): Invoke fil_node_create()
with srv_log_file_size expressed in multiples of innodb_page_size.
innobase_start_or_create_for_mysql(): Require the redo log file sizes
to be multiples of 512 bytes.
2017-06-05 22:47:20 +03:00
|
|
|
log_init(srv_n_log_files_found);
|
2017-05-26 14:04:19 +03:00
|
|
|
|
Reduce the granularity of innodb_log_file_size
In Mariabackup, we would want the backed-up redo log file size to be
a multiple of 512 bytes, or OS_FILE_LOG_BLOCK_SIZE. However, at startup,
InnoDB would be picky, requiring the file size to be a multiple of
innodb_page_size.
Furthermore, InnoDB would require the parameter to be a multiple of
one megabyte, while the minimum granularity is 512 bytes. Because
the data-file-oriented fil_io() API is being used for writing the
InnoDB redo log, writes will for now require innodb_log_file_size to
be a multiple of the maximum innodb_page_size (65536 bytes).
To complicate matters, InnoDB startup divided srv_log_file_size by
UNIV_PAGE_SIZE, so that initially, the unit was bytes, and later it
was innodb_page_size. We will simplify this and keep srv_log_file_size
in bytes at all times.
innobase_log_file_size: Remove. Remove some obsolete checks against
overflow on 32-bit systems. srv_log_file_size is always 64 bits, and
the maximum size 512GiB in multiples of innodb_page_size always fits
in ulint (which is 32 or 64 bits). 512GiB would be 8,388,608*64KiB or
134,217,728*4KiB.
log_init(): Remove the parameter file_size that was always passed as
srv_log_file_size.
log_set_capacity(): Add a parameter for passing the requested file size.
srv_log_file_size_requested: Declare static in srv0start.cc.
create_log_file(), create_log_files(),
innobase_start_or_create_for_mysql(): Invoke fil_node_create()
with srv_log_file_size expressed in multiples of innodb_page_size.
innobase_start_or_create_for_mysql(): Require the redo log file sizes
to be multiples of 512 bytes.
2017-06-05 22:47:20 +03:00
|
|
|
if (!log_set_capacity(srv_log_file_size_requested)) {
|
2016-08-12 11:17:45 +03:00
|
|
|
return(srv_init_abort(DB_ERROR));
|
|
|
|
}
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
files_checked:
|
|
|
|
/* Open all log files and data files in the system
|
|
|
|
tablespace: we keep them open until database
|
|
|
|
shutdown */
|
|
|
|
|
|
|
|
fil_open_log_and_system_tablespace_files();
|
2016-12-30 13:48:22 +02:00
|
|
|
ut_d(fil_space_get(0)->recv_size = srv_sys_space_size_debug);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
MDEV-12289 Keep 128 persistent rollback segments for compatibility and performance
InnoDB divides the allocation of undo logs into rollback segments.
The DB_ROLL_PTR system column of clustered indexes can address up to
128 rollback segments (TRX_SYS_N_RSEGS). Originally, InnoDB only
created one rollback segment. In MySQL 5.5 or in the InnoDB Plugin
for MySQL 5.1, all 128 rollback segments were created.
MySQL 5.7 hard-codes the rollback segment IDs 1..32 for temporary undo logs.
On upgrade, unless a slow shutdown (innodb_fast_shutdown=0)
was performed on the old server instance, these rollback segments
could be in use by transactions that are in XA PREPARE state or
transactions that were left behind by a server kill followed by a
normal shutdown immediately after restart.
Persistent tables cannot refer to temporary undo logs or vice versa.
Therefore, we should keep two distinct sets of rollback segments:
one for persistent tables and another for temporary tables. In this way,
all 128 rollback segments will be available for both types of tables,
which could improve performance. Also, MariaDB 10.2 will remain more
compatible than MySQL 5.7 with data files from earlier versions of
MySQL or MariaDB.
trx_sys_t::temp_rsegs[TRX_SYS_N_RSEGS]: A new array of temporary
rollback segments. The trx_sys_t::rseg_array[TRX_SYS_N_RSEGS] will
be solely for persistent undo logs.
srv_tmp_undo_logs. Remove. Use the constant TRX_SYS_N_RSEGS.
srv_available_undo_logs: Change the type to ulong.
trx_rseg_get_on_id(): Remove. Instead, let the callers refer to
trx_sys directly.
trx_rseg_create(), trx_sysf_rseg_find_free(): Remove unneeded parameters.
These functions only deal with persistent undo logs.
trx_temp_rseg_create(): New function, to create all temporary rollback
segments at server startup.
trx_rseg_t::is_persistent(): Determine if the rollback segment is for
persistent tables.
trx_sys_is_noredo_rseg_slot(): Remove. The callers must know based on
context (such as table handle) whether the DB_ROLL_PTR is referring to
a persistent undo log.
trx_sys_create_rsegs(): Remove all parameters, which were always passed
as global variables. Instead, modify the global variables directly.
enum trx_rseg_type_t: Remove.
trx_t::get_temp_rseg(): A method to ensure that a temporary
rollback segment has been assigned for the transaction.
trx_t::assign_temp_rseg(): Replaces trx_assign_rseg().
trx_purge_free_segment(), trx_purge_truncate_rseg_history():
Remove the redundant variable noredo=false.
Temporary undo logs are discarded immediately at transaction commit
or rollback, not lazily by purge.
trx_purge_mark_undo_for_truncate(): Remove references to the
temporary rollback segments.
trx_purge_mark_undo_for_truncate(): Remove a check for temporary
rollback segments. Only the dedicated persistent undo log tablespaces
can be truncated.
trx_undo_get_undo_rec_low(), trx_undo_get_undo_rec(): Add the
parameter is_temp.
trx_rseg_mem_restore(): Split from trx_rseg_mem_create().
Initialize the undo log and the rollback segment from the file
data structures.
trx_sysf_get_n_rseg_slots(): Renamed from
trx_sysf_used_slots_for_redo_rseg(). Count the persistent
rollback segment headers that have been initialized.
trx_sys_close(): Also free trx_sys->temp_rsegs[].
get_next_redo_rseg(): Merged to trx_assign_rseg_low().
trx_assign_rseg_low(): Remove the parameters and access the
global variables directly. Revert to simple round-robin, now that
the whole trx_sys->rseg_array[] is for persistent undo log again.
get_next_noredo_rseg(): Moved to trx_t::assign_temp_rseg().
srv_undo_tablespaces_init(): Remove some parameters and use the
global variables directly. Clarify some error messages.
Adjust the test innodb.log_file. Apparently, before these changes,
InnoDB somehow ignored missing dedicated undo tablespace files that
are pointed by the TRX_SYS header page, possibly losing part of
essential transaction system state.
2017-03-30 13:11:34 +03:00
|
|
|
err = srv_undo_tablespaces_init(create_new_db);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
/* If the force recovery is set very high then we carry on regardless
|
|
|
|
of all errors. Basically this is fingers crossed mode. */
|
|
|
|
|
|
|
|
if (err != DB_SUCCESS
|
|
|
|
&& srv_force_recovery < SRV_FORCE_NO_UNDO_LOG_SCAN) {
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
return(srv_init_abort(err));
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize objects used by dict stats gathering thread, which
|
|
|
|
can also be used by recovery if it tries to drop some table */
|
|
|
|
if (!srv_read_only_mode) {
|
|
|
|
dict_stats_thread_init();
|
|
|
|
}
|
|
|
|
|
2017-12-22 16:15:41 +02:00
|
|
|
trx_sys.create();
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
if (create_new_db) {
|
|
|
|
ut_a(!srv_read_only_mode);
|
|
|
|
|
|
|
|
mtr_start(&mtr);
|
|
|
|
|
2017-06-06 14:59:42 +03:00
|
|
|
fsp_header_init(0, sum_of_new_sizes, &mtr);
|
2017-06-08 12:45:08 +03:00
|
|
|
|
2017-06-06 14:59:42 +03:00
|
|
|
compile_time_assert(TRX_SYS_SPACE == 0);
|
|
|
|
compile_time_assert(IBUF_SPACE_ID == 0);
|
|
|
|
|
|
|
|
ulint ibuf_root = btr_create(
|
2017-09-19 21:53:08 +03:00
|
|
|
DICT_CLUSTERED | DICT_IBUF,
|
2017-06-08 12:45:08 +03:00
|
|
|
0, univ_page_size, DICT_IBUF_ID_MIN,
|
|
|
|
dict_ind_redundant, NULL, &mtr);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
mtr_commit(&mtr);
|
|
|
|
|
2017-06-08 12:45:08 +03:00
|
|
|
if (ibuf_root == FIL_NULL) {
|
2016-08-12 11:17:45 +03:00
|
|
|
return(srv_init_abort(DB_ERROR));
|
|
|
|
}
|
|
|
|
|
2017-06-08 12:45:08 +03:00
|
|
|
ut_ad(ibuf_root == IBUF_TREE_ROOT_PAGE_NO);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
/* To maintain backward compatibility we create only
|
|
|
|
the first rollback segment before the double write buffer.
|
|
|
|
All the remaining rollback segments will be created later,
|
|
|
|
after the double write buffer has been created. */
|
|
|
|
trx_sys_create_sys_pages();
|
2018-01-30 14:16:09 +02:00
|
|
|
trx_lists_init_at_db_start();
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
err = dict_create();
|
|
|
|
|
|
|
|
if (err != DB_SUCCESS) {
|
2016-08-12 11:17:45 +03:00
|
|
|
return(srv_init_abort(err));
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
buf_flush_sync_all_buf_pools();
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
flushed_lsn = log_get_lsn();
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-09-06 09:43:16 +03:00
|
|
|
err = fil_write_flushed_lsn(flushed_lsn);
|
|
|
|
|
2017-01-30 17:00:51 +02:00
|
|
|
if (err == DB_SUCCESS) {
|
|
|
|
err = create_log_files_rename(
|
|
|
|
logfilename, dirnamelen,
|
|
|
|
flushed_lsn, logfile0);
|
|
|
|
}
|
|
|
|
|
2016-09-06 09:43:16 +03:00
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
return(srv_init_abort(err));
|
|
|
|
}
|
2014-02-26 19:11:54 +01:00
|
|
|
} else {
|
|
|
|
/* Invalidate the buffer pool to ensure that we reread
|
|
|
|
the page that we read above, during recovery.
|
|
|
|
Note that this is not as heavy weight as it seems. At
|
|
|
|
this point there will be only ONE page in the buf_LRU
|
|
|
|
and there must be no page in the buf_flush list. */
|
|
|
|
buf_pool_invalidate();
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/* Scan and locate truncate log files. Parsed located files
|
|
|
|
and add table to truncate information to central vector for
|
|
|
|
truncate fix-up action post recovery. */
|
|
|
|
err = TruncateLogParser::scan_and_parse(srv_log_group_home_dir);
|
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
|
|
|
|
return(srv_init_abort(DB_ERROR));
|
|
|
|
}
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
/* We always try to do a recovery, even if the database had
|
|
|
|
been shut down normally: this is the normal startup path */
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
err = recv_recovery_from_checkpoint_start(flushed_lsn);
|
|
|
|
|
|
|
|
recv_sys->dblwr.pages.clear();
|
|
|
|
|
2017-01-26 14:05:00 +02:00
|
|
|
if (err != DB_SUCCESS) {
|
2016-12-30 08:56:13 +02:00
|
|
|
return(srv_init_abort(err));
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
2018-01-16 13:57:30 +02:00
|
|
|
switch (srv_operation) {
|
|
|
|
case SRV_OPERATION_NORMAL:
|
|
|
|
case SRV_OPERATION_RESTORE_EXPORT:
|
|
|
|
/* Initialize the change buffer. */
|
|
|
|
err = dict_boot();
|
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
return(srv_init_abort(err));
|
|
|
|
}
|
2018-02-20 15:10:03 +02:00
|
|
|
/* fall through */
|
|
|
|
case SRV_OPERATION_RESTORE:
|
2018-01-16 13:57:30 +02:00
|
|
|
/* This must precede
|
|
|
|
recv_apply_hashed_log_recs(true). */
|
2018-01-30 14:16:09 +02:00
|
|
|
trx_lists_init_at_db_start();
|
2018-01-16 13:57:30 +02:00
|
|
|
break;
|
|
|
|
case SRV_OPERATION_RESTORE_DELTA:
|
|
|
|
case SRV_OPERATION_BACKUP:
|
|
|
|
ut_ad(!"wrong mariabackup mode");
|
|
|
|
}
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
if (srv_force_recovery < SRV_FORCE_NO_LOG_REDO) {
|
|
|
|
/* Apply the hashed log records to the
|
|
|
|
respective file pages, for the last batch of
|
|
|
|
recv_group_scan_log_recs(). */
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2017-03-07 17:16:49 +02:00
|
|
|
recv_apply_hashed_log_recs(true);
|
MDEV-12253: Buffer pool blocks are accessed after they have been freed
Problem was that bpage was referenced after it was already freed
from LRU. Fixed by adding a new variable encrypted that is
passed down to buf_page_check_corrupt() and used in
buf_page_get_gen() to stop processing page read.
This patch should also address following test failures and
bugs:
MDEV-12419: IMPORT should not look up tablespace in
PageConverter::validate(). This is now removed.
MDEV-10099: encryption.innodb_onlinealter_encryption fails
sporadically in buildbot
MDEV-11420: encryption.innodb_encryption-page-compression
failed in buildbot
MDEV-11222: encryption.encrypt_and_grep failed in buildbot on P8
Removed dict_table_t::is_encrypted and dict_table_t::ibd_file_missing
and replaced these with dict_table_t::file_unreadable. Table
ibd file is missing if fil_get_space(space_id) returns NULL
and encrypted if not. Removed dict_table_t::is_corrupted field.
Ported FilSpace class from 10.2 and using that on buf_page_check_corrupt(),
buf_page_decrypt_after_read(), buf_page_encrypt_before_write(),
buf_dblwr_process(), buf_read_page(), dict_stats_save_defrag_stats().
Added test cases when enrypted page could be read while doing
redo log crash recovery. Also added test case for row compressed
blobs.
btr_cur_open_at_index_side_func(),
btr_cur_open_at_rnd_pos_func(): Avoid referencing block that is
NULL.
buf_page_get_zip(): Issue error if page read fails.
buf_page_get_gen(): Use dberr_t for error detection and
do not reference bpage after we hare freed it.
buf_mark_space_corrupt(): remove bpage from LRU also when
it is encrypted.
buf_page_check_corrupt(): @return DB_SUCCESS if page has
been read and is not corrupted,
DB_PAGE_CORRUPTED if page based on checksum check is corrupted,
DB_DECRYPTION_FAILED if page post encryption checksum matches but
after decryption normal page checksum does not match. In read
case only DB_SUCCESS is possible.
buf_page_io_complete(): use dberr_t for error handling.
buf_flush_write_block_low(),
buf_read_ahead_random(),
buf_read_page_async(),
buf_read_ahead_linear(),
buf_read_ibuf_merge_pages(),
buf_read_recv_pages(),
fil_aio_wait():
Issue error if page read fails.
btr_pcur_move_to_next_page(): Do not reference page if it is
NULL.
Introduced dict_table_t::is_readable() and dict_index_t::is_readable()
that will return true if tablespace exists and pages read from
tablespace are not corrupted or page decryption failed.
Removed buf_page_t::key_version. After page decryption the
key version is not removed from page frame. For unencrypted
pages, old key_version is removed at buf_page_encrypt_before_write()
dict_stats_update_transient_for_index(),
dict_stats_update_transient()
Do not continue if table decryption failed or table
is corrupted.
dict0stats.cc: Introduced a dict_stats_report_error function
to avoid code duplication.
fil_parse_write_crypt_data():
Check that key read from redo log entry is found from
encryption plugin and if it is not, refuse to start.
PageConverter::validate(): Removed access to fil_space_t as
tablespace is not available during import.
Fixed error code on innodb.innodb test.
Merged test cased innodb-bad-key-change5 and innodb-bad-key-shutdown
to innodb-bad-key-change2. Removed innodb-bad-key-change5 test.
Decreased unnecessary complexity on some long lasting tests.
Removed fil_inc_pending_ops(), fil_decr_pending_ops(),
fil_get_first_space(), fil_get_next_space(),
fil_get_first_space_safe(), fil_get_next_space_safe()
functions.
fil_space_verify_crypt_checksum(): Fixed bug found using ASAN
where FIL_PAGE_END_LSN_OLD_CHECKSUM field was incorrectly
accessed from row compressed tables. Fixed out of page frame
bug for row compressed tables in
fil_space_verify_crypt_checksum() found using ASAN. Incorrect
function was called for compressed table.
Added new tests for discard, rename table and drop (we should allow them
even when page decryption fails). Alter table rename is not allowed.
Added test for restart with innodb-force-recovery=1 when page read on
redo-recovery cant be decrypted. Added test for corrupted table where
both page data and FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION is corrupted.
Adjusted the test case innodb_bug14147491 so that it does not anymore
expect crash. Instead table is just mostly not usable.
fil0fil.h: fil_space_acquire_low is not visible function
and fil_space_acquire and fil_space_acquire_silent are
inline functions. FilSpace class uses fil_space_acquire_low
directly.
recv_apply_hashed_log_recs() does not return anything.
2017-04-26 15:19:16 +03:00
|
|
|
|
|
|
|
if (recv_sys->found_corrupt_log) {
|
2017-07-05 22:09:28 +03:00
|
|
|
return(srv_init_abort(DB_CORRUPTION));
|
MDEV-12253: Buffer pool blocks are accessed after they have been freed
Problem was that bpage was referenced after it was already freed
from LRU. Fixed by adding a new variable encrypted that is
passed down to buf_page_check_corrupt() and used in
buf_page_get_gen() to stop processing page read.
This patch should also address following test failures and
bugs:
MDEV-12419: IMPORT should not look up tablespace in
PageConverter::validate(). This is now removed.
MDEV-10099: encryption.innodb_onlinealter_encryption fails
sporadically in buildbot
MDEV-11420: encryption.innodb_encryption-page-compression
failed in buildbot
MDEV-11222: encryption.encrypt_and_grep failed in buildbot on P8
Removed dict_table_t::is_encrypted and dict_table_t::ibd_file_missing
and replaced these with dict_table_t::file_unreadable. Table
ibd file is missing if fil_get_space(space_id) returns NULL
and encrypted if not. Removed dict_table_t::is_corrupted field.
Ported FilSpace class from 10.2 and using that on buf_page_check_corrupt(),
buf_page_decrypt_after_read(), buf_page_encrypt_before_write(),
buf_dblwr_process(), buf_read_page(), dict_stats_save_defrag_stats().
Added test cases when enrypted page could be read while doing
redo log crash recovery. Also added test case for row compressed
blobs.
btr_cur_open_at_index_side_func(),
btr_cur_open_at_rnd_pos_func(): Avoid referencing block that is
NULL.
buf_page_get_zip(): Issue error if page read fails.
buf_page_get_gen(): Use dberr_t for error detection and
do not reference bpage after we hare freed it.
buf_mark_space_corrupt(): remove bpage from LRU also when
it is encrypted.
buf_page_check_corrupt(): @return DB_SUCCESS if page has
been read and is not corrupted,
DB_PAGE_CORRUPTED if page based on checksum check is corrupted,
DB_DECRYPTION_FAILED if page post encryption checksum matches but
after decryption normal page checksum does not match. In read
case only DB_SUCCESS is possible.
buf_page_io_complete(): use dberr_t for error handling.
buf_flush_write_block_low(),
buf_read_ahead_random(),
buf_read_page_async(),
buf_read_ahead_linear(),
buf_read_ibuf_merge_pages(),
buf_read_recv_pages(),
fil_aio_wait():
Issue error if page read fails.
btr_pcur_move_to_next_page(): Do not reference page if it is
NULL.
Introduced dict_table_t::is_readable() and dict_index_t::is_readable()
that will return true if tablespace exists and pages read from
tablespace are not corrupted or page decryption failed.
Removed buf_page_t::key_version. After page decryption the
key version is not removed from page frame. For unencrypted
pages, old key_version is removed at buf_page_encrypt_before_write()
dict_stats_update_transient_for_index(),
dict_stats_update_transient()
Do not continue if table decryption failed or table
is corrupted.
dict0stats.cc: Introduced a dict_stats_report_error function
to avoid code duplication.
fil_parse_write_crypt_data():
Check that key read from redo log entry is found from
encryption plugin and if it is not, refuse to start.
PageConverter::validate(): Removed access to fil_space_t as
tablespace is not available during import.
Fixed error code on innodb.innodb test.
Merged test cased innodb-bad-key-change5 and innodb-bad-key-shutdown
to innodb-bad-key-change2. Removed innodb-bad-key-change5 test.
Decreased unnecessary complexity on some long lasting tests.
Removed fil_inc_pending_ops(), fil_decr_pending_ops(),
fil_get_first_space(), fil_get_next_space(),
fil_get_first_space_safe(), fil_get_next_space_safe()
functions.
fil_space_verify_crypt_checksum(): Fixed bug found using ASAN
where FIL_PAGE_END_LSN_OLD_CHECKSUM field was incorrectly
accessed from row compressed tables. Fixed out of page frame
bug for row compressed tables in
fil_space_verify_crypt_checksum() found using ASAN. Incorrect
function was called for compressed table.
Added new tests for discard, rename table and drop (we should allow them
even when page decryption fails). Alter table rename is not allowed.
Added test for restart with innodb-force-recovery=1 when page read on
redo-recovery cant be decrypted. Added test for corrupted table where
both page data and FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION is corrupted.
Adjusted the test case innodb_bug14147491 so that it does not anymore
expect crash. Instead table is just mostly not usable.
fil0fil.h: fil_space_acquire_low is not visible function
and fil_space_acquire and fil_space_acquire_silent are
inline functions. FilSpace class uses fil_space_acquire_low
directly.
recv_apply_hashed_log_recs() does not return anything.
2017-04-26 15:19:16 +03:00
|
|
|
}
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
DBUG_PRINT("ib_log", ("apply completed"));
|
|
|
|
|
|
|
|
if (recv_needed_recovery) {
|
|
|
|
trx_sys_print_mysql_binlog_offset();
|
|
|
|
}
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
2017-01-26 14:05:00 +02:00
|
|
|
if (!srv_read_only_mode) {
|
|
|
|
const ulint flags = FSP_FLAGS_PAGE_SSIZE();
|
|
|
|
for (ulint id = 0; id <= srv_undo_tablespaces; id++) {
|
|
|
|
if (fil_space_get(id)) {
|
|
|
|
fsp_flags_try_adjust(id, flags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sum_of_new_sizes > 0) {
|
|
|
|
/* New data file(s) were added */
|
|
|
|
mtr.start();
|
|
|
|
fsp_header_inc_size(0, sum_of_new_sizes, &mtr);
|
|
|
|
mtr.commit();
|
|
|
|
/* Immediately write the log record about
|
|
|
|
increased tablespace size to disk, so that it
|
|
|
|
is durable even if mysqld would crash
|
|
|
|
quickly */
|
|
|
|
log_buffer_flush_to_disk();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const ulint tablespace_size_in_header
|
|
|
|
= fsp_header_get_tablespace_size();
|
|
|
|
const ulint sum_of_data_file_sizes
|
|
|
|
= srv_sys_space.get_sum_of_sizes();
|
|
|
|
/* Compare the system tablespace file size to what is
|
2017-06-08 12:45:08 +03:00
|
|
|
stored in FSP_SIZE. In srv_sys_space.open_or_create()
|
2017-01-26 14:05:00 +02:00
|
|
|
we already checked that the file sizes match the
|
|
|
|
innodb_data_file_path specification. */
|
|
|
|
if (srv_read_only_mode
|
|
|
|
|| sum_of_data_file_sizes == tablespace_size_in_header) {
|
|
|
|
/* Do not complain about the size. */
|
|
|
|
} else if (!srv_sys_space.can_auto_extend_last_file()
|
|
|
|
|| sum_of_data_file_sizes
|
|
|
|
< tablespace_size_in_header) {
|
|
|
|
ib::error() << "Tablespace size stored in header is "
|
|
|
|
<< tablespace_size_in_header
|
|
|
|
<< " pages, but the sum of data file sizes is "
|
|
|
|
<< sum_of_data_file_sizes << " pages";
|
|
|
|
|
|
|
|
if (srv_force_recovery == 0
|
|
|
|
&& sum_of_data_file_sizes
|
|
|
|
< tablespace_size_in_header) {
|
|
|
|
ib::error() <<
|
|
|
|
"Cannot start InnoDB. The tail of"
|
|
|
|
" the system tablespace is"
|
|
|
|
" missing. Have you edited"
|
|
|
|
" innodb_data_file_path in my.cnf"
|
|
|
|
" in an inappropriate way, removing"
|
|
|
|
" data files from there?"
|
|
|
|
" You can set innodb_force_recovery=1"
|
|
|
|
" in my.cnf to force"
|
|
|
|
" a startup if you are trying to"
|
|
|
|
" recover a badly corrupt database.";
|
|
|
|
|
|
|
|
return(srv_init_abort(DB_ERROR));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
/* recv_recovery_from_checkpoint_finish needs trx lists which
|
2018-01-30 14:16:09 +02:00
|
|
|
are initialized in trx_lists_init_at_db_start(). */
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
recv_recovery_from_checkpoint_finish();
|
|
|
|
|
2017-10-10 10:28:54 +03:00
|
|
|
if (srv_operation == SRV_OPERATION_RESTORE
|
|
|
|
|| srv_operation == SRV_OPERATION_RESTORE_EXPORT) {
|
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2
InnoDB I/O and buffer pool interfaces and the redo log format
have been changed between MariaDB 10.1 and 10.2, and the backup
code has to be adjusted accordingly.
The code has been simplified, and many memory leaks have been fixed.
Instead of the file name xtrabackup_logfile, the file name ib_logfile0
is being used for the copy of the redo log. Unnecessary InnoDB startup and
shutdown and some unnecessary threads have been removed.
Some help was provided by Vladislav Vaintroub.
Parameters have been cleaned up and aligned with those of MariaDB 10.2.
The --dbug option has been added, so that in debug builds,
--dbug=d,ib_log can be specified to enable diagnostic messages
for processing redo log entries.
By default, innodb_doublewrite=OFF, so that --prepare works faster.
If more crash-safety for --prepare is needed, double buffering
can be enabled.
The parameter innodb_log_checksums=OFF can be used to ignore redo log
checksums in --backup.
Some messages have been cleaned up.
Unless --export is specified, Mariabackup will not deal with undo log.
The InnoDB mini-transaction redo log is not only about user-level
transactions; it is actually about mini-transactions. To avoid confusion,
call it the redo log, not transaction log.
We disable any undo log processing in --prepare.
Because MariaDB 10.2 supports indexed virtual columns, the
undo log processing would need to be able to evaluate virtual column
expressions. To reduce the amount of code dependencies, we will not
process any undo log in prepare.
This means that the --export option must be disabled for now.
This also means that the following options are redundant
and have been removed:
xtrabackup --apply-log-only
innobackupex --redo-only
In addition to disabling any undo log processing, we will disable any
further changes to data pages during --prepare, including the change
buffer merge. This means that restoring incremental backups should
reliably work even when change buffering is being used on the server.
Because of this, preparing a backup will not generate any further
redo log, and the redo log file can be safely deleted. (If the
--export option is enabled in the future, it must generate redo log
when processing undo logs and buffered changes.)
In --prepare, we cannot easily know if a partial backup was used,
especially when restoring a series of incremental backups. So, we
simply warn about any missing files, and ignore the redo log for them.
FIXME: Enable the --export option.
FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write
a test that initiates a backup while an ALGORITHM=INPLACE operation
is creating indexes or rebuilding a table. An error should be detected
when preparing the backup.
FIXME: In --incremental --prepare, xtrabackup_apply_delta() should
ensure that if FSP_SIZE is modified, the file size will be adjusted
accordingly.
2017-06-30 10:49:37 +03:00
|
|
|
/* After applying the redo log from
|
|
|
|
SRV_OPERATION_BACKUP, flush the changes
|
2017-10-10 10:28:54 +03:00
|
|
|
to the data files and truncate or delete the log.
|
|
|
|
Unless --export is specified, no further change to
|
|
|
|
InnoDB files is needed. */
|
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2
InnoDB I/O and buffer pool interfaces and the redo log format
have been changed between MariaDB 10.1 and 10.2, and the backup
code has to be adjusted accordingly.
The code has been simplified, and many memory leaks have been fixed.
Instead of the file name xtrabackup_logfile, the file name ib_logfile0
is being used for the copy of the redo log. Unnecessary InnoDB startup and
shutdown and some unnecessary threads have been removed.
Some help was provided by Vladislav Vaintroub.
Parameters have been cleaned up and aligned with those of MariaDB 10.2.
The --dbug option has been added, so that in debug builds,
--dbug=d,ib_log can be specified to enable diagnostic messages
for processing redo log entries.
By default, innodb_doublewrite=OFF, so that --prepare works faster.
If more crash-safety for --prepare is needed, double buffering
can be enabled.
The parameter innodb_log_checksums=OFF can be used to ignore redo log
checksums in --backup.
Some messages have been cleaned up.
Unless --export is specified, Mariabackup will not deal with undo log.
The InnoDB mini-transaction redo log is not only about user-level
transactions; it is actually about mini-transactions. To avoid confusion,
call it the redo log, not transaction log.
We disable any undo log processing in --prepare.
Because MariaDB 10.2 supports indexed virtual columns, the
undo log processing would need to be able to evaluate virtual column
expressions. To reduce the amount of code dependencies, we will not
process any undo log in prepare.
This means that the --export option must be disabled for now.
This also means that the following options are redundant
and have been removed:
xtrabackup --apply-log-only
innobackupex --redo-only
In addition to disabling any undo log processing, we will disable any
further changes to data pages during --prepare, including the change
buffer merge. This means that restoring incremental backups should
reliably work even when change buffering is being used on the server.
Because of this, preparing a backup will not generate any further
redo log, and the redo log file can be safely deleted. (If the
--export option is enabled in the future, it must generate redo log
when processing undo logs and buffered changes.)
In --prepare, we cannot easily know if a partial backup was used,
especially when restoring a series of incremental backups. So, we
simply warn about any missing files, and ignore the redo log for them.
FIXME: Enable the --export option.
FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write
a test that initiates a backup while an ALGORITHM=INPLACE operation
is creating indexes or rebuilding a table. An error should be detected
when preparing the backup.
FIXME: In --incremental --prepare, xtrabackup_apply_delta() should
ensure that if FSP_SIZE is modified, the file size will be adjusted
accordingly.
2017-06-30 10:49:37 +03:00
|
|
|
ut_ad(!srv_force_recovery);
|
|
|
|
ut_ad(srv_n_log_files_found <= 1);
|
|
|
|
ut_ad(recv_no_log_write);
|
|
|
|
buf_flush_sync_all_buf_pools();
|
|
|
|
err = fil_write_flushed_lsn(log_get_lsn());
|
|
|
|
ut_ad(!buf_pool_check_no_pending_io());
|
|
|
|
fil_close_log_files(true);
|
|
|
|
log_group_close_all();
|
|
|
|
if (err == DB_SUCCESS) {
|
2017-10-10 10:28:54 +03:00
|
|
|
bool trunc = srv_operation
|
|
|
|
== SRV_OPERATION_RESTORE;
|
|
|
|
/* Delete subsequent log files. */
|
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2
InnoDB I/O and buffer pool interfaces and the redo log format
have been changed between MariaDB 10.1 and 10.2, and the backup
code has to be adjusted accordingly.
The code has been simplified, and many memory leaks have been fixed.
Instead of the file name xtrabackup_logfile, the file name ib_logfile0
is being used for the copy of the redo log. Unnecessary InnoDB startup and
shutdown and some unnecessary threads have been removed.
Some help was provided by Vladislav Vaintroub.
Parameters have been cleaned up and aligned with those of MariaDB 10.2.
The --dbug option has been added, so that in debug builds,
--dbug=d,ib_log can be specified to enable diagnostic messages
for processing redo log entries.
By default, innodb_doublewrite=OFF, so that --prepare works faster.
If more crash-safety for --prepare is needed, double buffering
can be enabled.
The parameter innodb_log_checksums=OFF can be used to ignore redo log
checksums in --backup.
Some messages have been cleaned up.
Unless --export is specified, Mariabackup will not deal with undo log.
The InnoDB mini-transaction redo log is not only about user-level
transactions; it is actually about mini-transactions. To avoid confusion,
call it the redo log, not transaction log.
We disable any undo log processing in --prepare.
Because MariaDB 10.2 supports indexed virtual columns, the
undo log processing would need to be able to evaluate virtual column
expressions. To reduce the amount of code dependencies, we will not
process any undo log in prepare.
This means that the --export option must be disabled for now.
This also means that the following options are redundant
and have been removed:
xtrabackup --apply-log-only
innobackupex --redo-only
In addition to disabling any undo log processing, we will disable any
further changes to data pages during --prepare, including the change
buffer merge. This means that restoring incremental backups should
reliably work even when change buffering is being used on the server.
Because of this, preparing a backup will not generate any further
redo log, and the redo log file can be safely deleted. (If the
--export option is enabled in the future, it must generate redo log
when processing undo logs and buffered changes.)
In --prepare, we cannot easily know if a partial backup was used,
especially when restoring a series of incremental backups. So, we
simply warn about any missing files, and ignore the redo log for them.
FIXME: Enable the --export option.
FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write
a test that initiates a backup while an ALGORITHM=INPLACE operation
is creating indexes or rebuilding a table. An error should be detected
when preparing the backup.
FIXME: In --incremental --prepare, xtrabackup_apply_delta() should
ensure that if FSP_SIZE is modified, the file size will be adjusted
accordingly.
2017-06-30 10:49:37 +03:00
|
|
|
delete_log_files(logfilename, dirnamelen,
|
2018-02-06 12:55:58 +00:00
|
|
|
(uint)srv_n_log_files_found, trunc);
|
2017-10-10 10:28:54 +03:00
|
|
|
if (trunc) {
|
|
|
|
/* Truncate the first log file. */
|
|
|
|
strcpy(logfilename + dirnamelen,
|
|
|
|
"ib_logfile0");
|
|
|
|
FILE* f = fopen(logfilename, "w");
|
|
|
|
fclose(f);
|
|
|
|
}
|
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2
InnoDB I/O and buffer pool interfaces and the redo log format
have been changed between MariaDB 10.1 and 10.2, and the backup
code has to be adjusted accordingly.
The code has been simplified, and many memory leaks have been fixed.
Instead of the file name xtrabackup_logfile, the file name ib_logfile0
is being used for the copy of the redo log. Unnecessary InnoDB startup and
shutdown and some unnecessary threads have been removed.
Some help was provided by Vladislav Vaintroub.
Parameters have been cleaned up and aligned with those of MariaDB 10.2.
The --dbug option has been added, so that in debug builds,
--dbug=d,ib_log can be specified to enable diagnostic messages
for processing redo log entries.
By default, innodb_doublewrite=OFF, so that --prepare works faster.
If more crash-safety for --prepare is needed, double buffering
can be enabled.
The parameter innodb_log_checksums=OFF can be used to ignore redo log
checksums in --backup.
Some messages have been cleaned up.
Unless --export is specified, Mariabackup will not deal with undo log.
The InnoDB mini-transaction redo log is not only about user-level
transactions; it is actually about mini-transactions. To avoid confusion,
call it the redo log, not transaction log.
We disable any undo log processing in --prepare.
Because MariaDB 10.2 supports indexed virtual columns, the
undo log processing would need to be able to evaluate virtual column
expressions. To reduce the amount of code dependencies, we will not
process any undo log in prepare.
This means that the --export option must be disabled for now.
This also means that the following options are redundant
and have been removed:
xtrabackup --apply-log-only
innobackupex --redo-only
In addition to disabling any undo log processing, we will disable any
further changes to data pages during --prepare, including the change
buffer merge. This means that restoring incremental backups should
reliably work even when change buffering is being used on the server.
Because of this, preparing a backup will not generate any further
redo log, and the redo log file can be safely deleted. (If the
--export option is enabled in the future, it must generate redo log
when processing undo logs and buffered changes.)
In --prepare, we cannot easily know if a partial backup was used,
especially when restoring a series of incremental backups. So, we
simply warn about any missing files, and ignore the redo log for them.
FIXME: Enable the --export option.
FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write
a test that initiates a backup while an ALGORITHM=INPLACE operation
is creating indexes or rebuilding a table. An error should be detected
when preparing the backup.
FIXME: In --incremental --prepare, xtrabackup_apply_delta() should
ensure that if FSP_SIZE is modified, the file size will be adjusted
accordingly.
2017-06-30 10:49:37 +03:00
|
|
|
}
|
|
|
|
return(err);
|
|
|
|
}
|
|
|
|
|
2017-02-10 12:11:42 +02:00
|
|
|
/* Upgrade or resize or rebuild the redo logs before
|
|
|
|
generating any dirty pages, so that the old redo log
|
|
|
|
files will not be written to. */
|
|
|
|
|
|
|
|
if (srv_force_recovery == SRV_FORCE_NO_LOG_REDO) {
|
|
|
|
/* Completely ignore the redo log. */
|
|
|
|
} else if (srv_read_only_mode) {
|
|
|
|
/* Leave the redo log alone. */
|
|
|
|
} else if (srv_log_file_size_requested == srv_log_file_size
|
|
|
|
&& srv_n_log_files_found == srv_n_log_files
|
2018-01-03 15:22:52 +02:00
|
|
|
&& log_sys->log.format
|
|
|
|
== (srv_encrypt_log
|
|
|
|
? LOG_HEADER_FORMAT_CURRENT
|
|
|
|
| LOG_HEADER_FORMAT_ENCRYPTED
|
|
|
|
: LOG_HEADER_FORMAT_CURRENT)) {
|
2017-02-10 12:11:42 +02:00
|
|
|
/* No need to upgrade or resize the redo log. */
|
|
|
|
} else {
|
|
|
|
/* Prepare to delete the old redo log files */
|
|
|
|
flushed_lsn = srv_prepare_to_delete_redo_log_files(i);
|
|
|
|
|
|
|
|
DBUG_EXECUTE_IF("innodb_log_abort_1",
|
|
|
|
return(srv_init_abort(DB_ERROR)););
|
|
|
|
/* Prohibit redo log writes from any other
|
|
|
|
threads until creating a log checkpoint at the
|
|
|
|
end of create_log_files(). */
|
|
|
|
ut_d(recv_no_log_write = true);
|
|
|
|
ut_ad(!buf_pool_check_no_pending_io());
|
|
|
|
|
|
|
|
DBUG_EXECUTE_IF("innodb_log_abort_3",
|
|
|
|
return(srv_init_abort(DB_ERROR)););
|
2017-02-16 09:18:46 +02:00
|
|
|
DBUG_PRINT("ib_log", ("After innodb_log_abort_3"));
|
2017-02-10 12:11:42 +02:00
|
|
|
|
|
|
|
/* Stamp the LSN to the data files. */
|
|
|
|
err = fil_write_flushed_lsn(flushed_lsn);
|
|
|
|
|
|
|
|
DBUG_EXECUTE_IF("innodb_log_abort_4", err = DB_ERROR;);
|
2017-02-16 09:18:46 +02:00
|
|
|
DBUG_PRINT("ib_log", ("After innodb_log_abort_4"));
|
2017-02-10 12:11:42 +02:00
|
|
|
|
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
return(srv_init_abort(err));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Close and free the redo log files, so that
|
|
|
|
we can replace them. */
|
|
|
|
fil_close_log_files(true);
|
|
|
|
|
|
|
|
DBUG_EXECUTE_IF("innodb_log_abort_5",
|
|
|
|
return(srv_init_abort(DB_ERROR)););
|
2017-02-16 09:18:46 +02:00
|
|
|
DBUG_PRINT("ib_log", ("After innodb_log_abort_5"));
|
2017-02-10 12:11:42 +02:00
|
|
|
|
|
|
|
/* Free the old log file space. */
|
|
|
|
log_group_close_all();
|
|
|
|
|
|
|
|
ib::info() << "Starting to delete and rewrite log"
|
|
|
|
" files.";
|
|
|
|
|
|
|
|
srv_log_file_size = srv_log_file_size_requested;
|
|
|
|
|
|
|
|
err = create_log_files(
|
|
|
|
logfilename, dirnamelen, flushed_lsn,
|
|
|
|
logfile0);
|
|
|
|
|
|
|
|
if (err == DB_SUCCESS) {
|
|
|
|
err = create_log_files_rename(
|
|
|
|
logfilename, dirnamelen, flushed_lsn,
|
|
|
|
logfile0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
return(srv_init_abort(err));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Validate a few system page types that were left
|
|
|
|
uninitialized by older versions of MySQL. */
|
|
|
|
if (!high_level_read_only) {
|
|
|
|
mtr_t mtr;
|
|
|
|
buf_block_t* block;
|
|
|
|
mtr.start();
|
|
|
|
mtr.set_sys_modified();
|
|
|
|
/* Bitmap page types will be reset in
|
|
|
|
buf_dblwr_check_block() without redo logging. */
|
|
|
|
block = buf_page_get(
|
|
|
|
page_id_t(IBUF_SPACE_ID,
|
|
|
|
FSP_IBUF_HEADER_PAGE_NO),
|
|
|
|
univ_page_size, RW_X_LATCH, &mtr);
|
|
|
|
fil_block_check_type(block, FIL_PAGE_TYPE_SYS, &mtr);
|
|
|
|
/* Already MySQL 3.23.53 initialized
|
|
|
|
FSP_IBUF_TREE_ROOT_PAGE_NO to
|
|
|
|
FIL_PAGE_INDEX. No need to reset that one. */
|
|
|
|
block = buf_page_get(
|
|
|
|
page_id_t(TRX_SYS_SPACE, TRX_SYS_PAGE_NO),
|
|
|
|
univ_page_size, RW_X_LATCH, &mtr);
|
|
|
|
fil_block_check_type(block, FIL_PAGE_TYPE_TRX_SYS,
|
|
|
|
&mtr);
|
|
|
|
block = buf_page_get(
|
|
|
|
page_id_t(TRX_SYS_SPACE,
|
|
|
|
FSP_FIRST_RSEG_PAGE_NO),
|
|
|
|
univ_page_size, RW_X_LATCH, &mtr);
|
|
|
|
fil_block_check_type(block, FIL_PAGE_TYPE_SYS, &mtr);
|
|
|
|
block = buf_page_get(
|
|
|
|
page_id_t(TRX_SYS_SPACE, FSP_DICT_HDR_PAGE_NO),
|
|
|
|
univ_page_size, RW_X_LATCH, &mtr);
|
|
|
|
fil_block_check_type(block, FIL_PAGE_TYPE_SYS, &mtr);
|
|
|
|
mtr.commit();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Roll back any recovered data dictionary transactions, so
|
|
|
|
that the data dictionary tables will be free of any locks.
|
|
|
|
The data dictionary latch should guarantee that there is at
|
|
|
|
most one data dictionary transaction active at a time. */
|
|
|
|
if (srv_force_recovery < SRV_FORCE_NO_TRX_UNDO) {
|
2017-12-21 15:45:40 +04:00
|
|
|
trx_rollback_recovered(false);
|
2017-02-10 12:11:42 +02:00
|
|
|
}
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/* Fix-up truncate of tables in the system tablespace
|
|
|
|
if server crashed while truncate was active. The non-
|
|
|
|
system tables are done after tablespace discovery. Do
|
|
|
|
this now because this procedure assumes that no pages
|
|
|
|
have changed since redo recovery. Tablespace discovery
|
|
|
|
can do updates to pages in the system tablespace.*/
|
|
|
|
err = truncate_t::fixup_tables_in_system_tablespace();
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
if (srv_force_recovery < SRV_FORCE_NO_IBUF_MERGE) {
|
2016-08-12 11:17:45 +03:00
|
|
|
/* Open or Create SYS_TABLESPACES and SYS_DATAFILES
|
|
|
|
so that tablespace names and other metadata can be
|
|
|
|
found. */
|
|
|
|
err = dict_create_or_check_sys_tablespace();
|
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
return(srv_init_abort(err));
|
|
|
|
}
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
/* The following call is necessary for the insert
|
|
|
|
buffer to work with multiple tablespaces. We must
|
|
|
|
know the mapping between space id's and .ibd file
|
|
|
|
names.
|
|
|
|
|
|
|
|
In a crash recovery, we check that the info in data
|
|
|
|
dictionary is consistent with what we already know
|
2016-08-12 11:17:45 +03:00
|
|
|
about space id's from the calls to fil_ibd_load().
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
In a normal startup, we create the space objects for
|
|
|
|
every table in the InnoDB data dictionary that has
|
|
|
|
an .ibd file.
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
We also determine the maximum tablespace id used.
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
The 'validate' flag indicates that when a tablespace
|
|
|
|
is opened, we also read the header page and validate
|
|
|
|
the contents to the data dictionary. This is time
|
|
|
|
consuming, especially for databases with lots of ibd
|
|
|
|
files. So only do it after a crash and not forcing
|
|
|
|
recovery. Open rw transactions at this point is not
|
|
|
|
a good reason to validate. */
|
|
|
|
bool validate = recv_needed_recovery
|
|
|
|
&& srv_force_recovery == 0;
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
dict_check_tablespaces_and_store_max_id(validate);
|
|
|
|
}
|
2014-08-25 13:35:33 +03:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/* Fix-up truncate of table if server crashed while truncate
|
|
|
|
was active. */
|
|
|
|
err = truncate_t::fixup_tables_in_non_system_tablespace();
|
2014-08-25 13:35:33 +03:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
return(srv_init_abort(err));
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
recv_recovery_rollback_active();
|
MDEV-13039 innodb_fast_shutdown=0 may fail to purge all undo log
When a slow shutdown is performed soon after spawning some work for
background threads that can create or commit transactions, it is possible
that new transactions are started or committed after the purge has finished.
This is violating the specification of innodb_fast_shutdown=0, namely that
the purge must be completed. (None of the history of the recent transactions
would be purged.)
Also, it is possible that the purge threads would exit in slow shutdown
while there exist active transactions, such as recovered incomplete
transactions that are being rolled back. Thus, the slow shutdown could
fail to purge some undo log that becomes purgeable after the transaction
commit or rollback.
srv_undo_sources: A flag that indicates if undo log can be generated
or the persistent, whether by background threads or by user SQL.
Even when this flag is clear, active transactions that already exist
in the system may be committed or rolled back.
innodb_shutdown(): Renamed from innobase_shutdown_for_mysql().
Do not return an error code; the operation never fails.
Clear the srv_undo_sources flag, and also ensure that the background
DROP TABLE queue is empty.
srv_purge_should_exit(): Do not allow the purge to exit if
srv_undo_sources are active or the background DROP TABLE queue is not
empty, or in slow shutdown, if any active transactions exist
(and are being rolled back).
srv_purge_coordinator_thread(): Remove some previous workarounds
for this bug.
innobase_start_or_create_for_mysql(): Set buf_page_cleaner_is_active
and srv_dict_stats_thread_active directly. Set srv_undo_sources before
starting the purge subsystem, to prevent immediate shutdown of the purge.
Create dict_stats_thread and fts_optimize_thread immediately
after setting srv_undo_sources, so that shutdown can use this flag to
determine if these subsystems were started.
dict_stats_shutdown(): Shut down dict_stats_thread. Backported from 10.2.
srv_shutdown_table_bg_threads(): Remove (unused).
2017-06-08 15:43:06 +03:00
|
|
|
srv_startup_is_before_trx_rollback_phase = FALSE;
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
2017-01-26 14:05:00 +02:00
|
|
|
ut_ad(err == DB_SUCCESS);
|
|
|
|
ut_a(sum_of_new_sizes != ULINT_UNDEFINED);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/* Create the doublewrite buffer to a new tablespace */
|
2017-02-01 15:47:33 +02:00
|
|
|
if (!srv_read_only_mode && srv_force_recovery < SRV_FORCE_NO_TRX_UNDO
|
|
|
|
&& !buf_dblwr_create()) {
|
2016-08-12 11:17:45 +03:00
|
|
|
return(srv_init_abort(DB_ERROR));
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Here the double write buffer has already been created and so
|
|
|
|
any new rollback segments will be allocated after the double
|
|
|
|
write buffer. The default segment should already exist.
|
|
|
|
We create the new segments only if it's a new database or
|
|
|
|
the database was shutdown cleanly. */
|
|
|
|
|
|
|
|
/* Note: When creating the extra rollback segments during an upgrade
|
|
|
|
we violate the latching order, even if the change buffer is empty.
|
|
|
|
We make an exception in sync0sync.cc and check srv_is_being_started
|
|
|
|
for that violation. It cannot create a deadlock because we are still
|
|
|
|
running in single threaded mode essentially. Only the IO threads
|
|
|
|
should be running at this stage. */
|
|
|
|
|
|
|
|
ut_a(srv_undo_logs > 0);
|
|
|
|
ut_a(srv_undo_logs <= TRX_SYS_N_RSEGS);
|
|
|
|
|
MDEV-12289 Keep 128 persistent rollback segments for compatibility and performance
InnoDB divides the allocation of undo logs into rollback segments.
The DB_ROLL_PTR system column of clustered indexes can address up to
128 rollback segments (TRX_SYS_N_RSEGS). Originally, InnoDB only
created one rollback segment. In MySQL 5.5 or in the InnoDB Plugin
for MySQL 5.1, all 128 rollback segments were created.
MySQL 5.7 hard-codes the rollback segment IDs 1..32 for temporary undo logs.
On upgrade, unless a slow shutdown (innodb_fast_shutdown=0)
was performed on the old server instance, these rollback segments
could be in use by transactions that are in XA PREPARE state or
transactions that were left behind by a server kill followed by a
normal shutdown immediately after restart.
Persistent tables cannot refer to temporary undo logs or vice versa.
Therefore, we should keep two distinct sets of rollback segments:
one for persistent tables and another for temporary tables. In this way,
all 128 rollback segments will be available for both types of tables,
which could improve performance. Also, MariaDB 10.2 will remain more
compatible than MySQL 5.7 with data files from earlier versions of
MySQL or MariaDB.
trx_sys_t::temp_rsegs[TRX_SYS_N_RSEGS]: A new array of temporary
rollback segments. The trx_sys_t::rseg_array[TRX_SYS_N_RSEGS] will
be solely for persistent undo logs.
srv_tmp_undo_logs. Remove. Use the constant TRX_SYS_N_RSEGS.
srv_available_undo_logs: Change the type to ulong.
trx_rseg_get_on_id(): Remove. Instead, let the callers refer to
trx_sys directly.
trx_rseg_create(), trx_sysf_rseg_find_free(): Remove unneeded parameters.
These functions only deal with persistent undo logs.
trx_temp_rseg_create(): New function, to create all temporary rollback
segments at server startup.
trx_rseg_t::is_persistent(): Determine if the rollback segment is for
persistent tables.
trx_sys_is_noredo_rseg_slot(): Remove. The callers must know based on
context (such as table handle) whether the DB_ROLL_PTR is referring to
a persistent undo log.
trx_sys_create_rsegs(): Remove all parameters, which were always passed
as global variables. Instead, modify the global variables directly.
enum trx_rseg_type_t: Remove.
trx_t::get_temp_rseg(): A method to ensure that a temporary
rollback segment has been assigned for the transaction.
trx_t::assign_temp_rseg(): Replaces trx_assign_rseg().
trx_purge_free_segment(), trx_purge_truncate_rseg_history():
Remove the redundant variable noredo=false.
Temporary undo logs are discarded immediately at transaction commit
or rollback, not lazily by purge.
trx_purge_mark_undo_for_truncate(): Remove references to the
temporary rollback segments.
trx_purge_mark_undo_for_truncate(): Remove a check for temporary
rollback segments. Only the dedicated persistent undo log tablespaces
can be truncated.
trx_undo_get_undo_rec_low(), trx_undo_get_undo_rec(): Add the
parameter is_temp.
trx_rseg_mem_restore(): Split from trx_rseg_mem_create().
Initialize the undo log and the rollback segment from the file
data structures.
trx_sysf_get_n_rseg_slots(): Renamed from
trx_sysf_used_slots_for_redo_rseg(). Count the persistent
rollback segment headers that have been initialized.
trx_sys_close(): Also free trx_sys->temp_rsegs[].
get_next_redo_rseg(): Merged to trx_assign_rseg_low().
trx_assign_rseg_low(): Remove the parameters and access the
global variables directly. Revert to simple round-robin, now that
the whole trx_sys->rseg_array[] is for persistent undo log again.
get_next_noredo_rseg(): Moved to trx_t::assign_temp_rseg().
srv_undo_tablespaces_init(): Remove some parameters and use the
global variables directly. Clarify some error messages.
Adjust the test innodb.log_file. Apparently, before these changes,
InnoDB somehow ignored missing dedicated undo tablespace files that
are pointed by the TRX_SYS header page, possibly losing part of
essential transaction system state.
2017-03-30 13:11:34 +03:00
|
|
|
if (!trx_sys_create_rsegs()) {
|
2016-08-12 11:17:45 +03:00
|
|
|
return(srv_init_abort(DB_ERROR));
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
srv_startup_is_before_trx_rollback_phase = false;
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
if (!srv_read_only_mode) {
|
|
|
|
/* Create the thread which watches the timeouts
|
|
|
|
for lock waits */
|
2015-01-06 16:08:42 +02:00
|
|
|
thread_handles[2 + SRV_MAX_N_IO_THREADS] = os_thread_create(
|
2014-02-26 19:11:54 +01:00
|
|
|
lock_wait_timeout_thread,
|
|
|
|
NULL, thread_ids + 2 + SRV_MAX_N_IO_THREADS);
|
2015-01-06 16:08:42 +02:00
|
|
|
thread_started[2 + SRV_MAX_N_IO_THREADS] = true;
|
MDEV-11638 Encryption causes race conditions in InnoDB shutdown
InnoDB shutdown failed to properly take fil_crypt_thread() into account.
The encryption threads were signalled to shut down together with other
non-critical tasks. This could be much too early in case of slow shutdown,
which could need minutes to complete the purge. Furthermore, InnoDB
failed to wait for the fil_crypt_thread() to actually exit before
proceeding to the final steps of shutdown, causing the race conditions.
Furthermore, the log_scrub_thread() was shut down way too early.
Also it should remain until the SRV_SHUTDOWN_FLUSH_PHASE.
fil_crypt_threads_end(): Remove. This would cause the threads to
be terminated way too early.
srv_buf_dump_thread_active, srv_dict_stats_thread_active,
lock_sys->timeout_thread_active, log_scrub_thread_active,
srv_monitor_active, srv_error_monitor_active: Remove a race condition
between startup and shutdown, by setting these in the startup thread
that creates threads, not in each created thread. In this way, once the
flag is cleared, it will remain cleared during shutdown.
srv_n_fil_crypt_threads_started, fil_crypt_threads_event: Declare in
global rather than static scope.
log_scrub_event, srv_log_scrub_thread_active, log_scrub_thread():
Declare in static rather than global scope. Let these be created by
log_init() and freed by log_shutdown().
rotate_thread_t::should_shutdown(): Do not shut down before the
SRV_SHUTDOWN_FLUSH_PHASE.
srv_any_background_threads_are_active(): Remove. These checks now
exist in logs_empty_and_mark_files_at_shutdown().
logs_empty_and_mark_files_at_shutdown(): Shut down the threads in
the proper order. Keep fil_crypt_thread() and log_scrub_thread() alive
until SRV_SHUTDOWN_FLUSH_PHASE, and check that they actually terminate.
2017-01-04 18:43:32 +02:00
|
|
|
lock_sys->timeout_thread_active = true;
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
/* Create the thread which warns of long semaphore waits */
|
MDEV-11638 Encryption causes race conditions in InnoDB shutdown
InnoDB shutdown failed to properly take fil_crypt_thread() into account.
The encryption threads were signalled to shut down together with other
non-critical tasks. This could be much too early in case of slow shutdown,
which could need minutes to complete the purge. Furthermore, InnoDB
failed to wait for the fil_crypt_thread() to actually exit before
proceeding to the final steps of shutdown, causing the race conditions.
Furthermore, the log_scrub_thread() was shut down way too early.
Also it should remain until the SRV_SHUTDOWN_FLUSH_PHASE.
fil_crypt_threads_end(): Remove. This would cause the threads to
be terminated way too early.
srv_buf_dump_thread_active, srv_dict_stats_thread_active,
lock_sys->timeout_thread_active, log_scrub_thread_active,
srv_monitor_active, srv_error_monitor_active: Remove a race condition
between startup and shutdown, by setting these in the startup thread
that creates threads, not in each created thread. In this way, once the
flag is cleared, it will remain cleared during shutdown.
srv_n_fil_crypt_threads_started, fil_crypt_threads_event: Declare in
global rather than static scope.
log_scrub_event, srv_log_scrub_thread_active, log_scrub_thread():
Declare in static rather than global scope. Let these be created by
log_init() and freed by log_shutdown().
rotate_thread_t::should_shutdown(): Do not shut down before the
SRV_SHUTDOWN_FLUSH_PHASE.
srv_any_background_threads_are_active(): Remove. These checks now
exist in logs_empty_and_mark_files_at_shutdown().
logs_empty_and_mark_files_at_shutdown(): Shut down the threads in
the proper order. Keep fil_crypt_thread() and log_scrub_thread() alive
until SRV_SHUTDOWN_FLUSH_PHASE, and check that they actually terminate.
2017-01-04 18:43:32 +02:00
|
|
|
srv_error_monitor_active = true;
|
2015-01-06 16:08:42 +02:00
|
|
|
thread_handles[3 + SRV_MAX_N_IO_THREADS] = os_thread_create(
|
2014-02-26 19:11:54 +01:00
|
|
|
srv_error_monitor_thread,
|
|
|
|
NULL, thread_ids + 3 + SRV_MAX_N_IO_THREADS);
|
2015-01-06 16:08:42 +02:00
|
|
|
thread_started[3 + SRV_MAX_N_IO_THREADS] = true;
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
/* Create the thread which prints InnoDB monitor info */
|
MDEV-11638 Encryption causes race conditions in InnoDB shutdown
InnoDB shutdown failed to properly take fil_crypt_thread() into account.
The encryption threads were signalled to shut down together with other
non-critical tasks. This could be much too early in case of slow shutdown,
which could need minutes to complete the purge. Furthermore, InnoDB
failed to wait for the fil_crypt_thread() to actually exit before
proceeding to the final steps of shutdown, causing the race conditions.
Furthermore, the log_scrub_thread() was shut down way too early.
Also it should remain until the SRV_SHUTDOWN_FLUSH_PHASE.
fil_crypt_threads_end(): Remove. This would cause the threads to
be terminated way too early.
srv_buf_dump_thread_active, srv_dict_stats_thread_active,
lock_sys->timeout_thread_active, log_scrub_thread_active,
srv_monitor_active, srv_error_monitor_active: Remove a race condition
between startup and shutdown, by setting these in the startup thread
that creates threads, not in each created thread. In this way, once the
flag is cleared, it will remain cleared during shutdown.
srv_n_fil_crypt_threads_started, fil_crypt_threads_event: Declare in
global rather than static scope.
log_scrub_event, srv_log_scrub_thread_active, log_scrub_thread():
Declare in static rather than global scope. Let these be created by
log_init() and freed by log_shutdown().
rotate_thread_t::should_shutdown(): Do not shut down before the
SRV_SHUTDOWN_FLUSH_PHASE.
srv_any_background_threads_are_active(): Remove. These checks now
exist in logs_empty_and_mark_files_at_shutdown().
logs_empty_and_mark_files_at_shutdown(): Shut down the threads in
the proper order. Keep fil_crypt_thread() and log_scrub_thread() alive
until SRV_SHUTDOWN_FLUSH_PHASE, and check that they actually terminate.
2017-01-04 18:43:32 +02:00
|
|
|
srv_monitor_active = true;
|
2015-01-06 16:08:42 +02:00
|
|
|
thread_handles[4 + SRV_MAX_N_IO_THREADS] = os_thread_create(
|
2014-02-26 19:11:54 +01:00
|
|
|
srv_monitor_thread,
|
|
|
|
NULL, thread_ids + 4 + SRV_MAX_N_IO_THREADS);
|
2015-01-06 16:08:42 +02:00
|
|
|
thread_started[4 + SRV_MAX_N_IO_THREADS] = true;
|
2017-06-08 15:43:06 +03:00
|
|
|
srv_start_state |= SRV_START_STATE_LOCK_SYS
|
|
|
|
| SRV_START_STATE_MONITOR;
|
MDEV-12288 Reset DB_TRX_ID when the history is removed, to speed up MVCC
Let InnoDB purge reset DB_TRX_ID,DB_ROLL_PTR when the history is removed.
[TODO: It appears that the resetting is not taking place as often as
it could be. We should test that a simple INSERT should eventually
cause row_purge_reset_trx_id() to be invoked unless DROP TABLE is
invoked soon enough.]
The InnoDB clustered index record system columns DB_TRX_ID,DB_ROLL_PTR
are used by multi-versioning. After the history is no longer needed, these
columns can safely be reset to 0 and 1<<55 (to indicate a fresh insert).
When a reader sees 0 in the DB_TRX_ID column, it can instantly determine
that the record is present the read view. There is no need to acquire
the transaction system mutex to check if the transaction exists, because
writes can never be conducted by a transaction whose ID is 0.
The persistent InnoDB undo log used to be split into two parts:
insert_undo and update_undo. The insert_undo log was discarded at
transaction commit or rollback, and the update_undo log was processed
by the purge subsystem. As part of this change, we will only generate
a single undo log for new transactions, and the purge subsystem will
reset the DB_TRX_ID whenever a clustered index record is touched.
That is, all persistent undo log will be preserved at transaction commit
or rollback, to be removed by purge.
The InnoDB redo log format is changed in two ways:
We remove the redo log record type MLOG_UNDO_HDR_REUSE, and
we introduce the MLOG_ZIP_WRITE_TRX_ID record for updating the
DB_TRX_ID,DB_ROLL_PTR in a ROW_FORMAT=COMPRESSED table.
This is also changing the format of persistent InnoDB data files:
undo log and clustered index leaf page records. It will still be
possible via import and export to exchange data files with earlier
versions of MariaDB. The change to clustered index leaf page records
is simple: we allow DB_TRX_ID to be 0.
When it comes to the undo log, we must be able to upgrade from earlier
MariaDB versions after a clean shutdown (no redo log to apply).
While it would be nice to perform a slow shutdown (innodb_fast_shutdown=0)
before an upgrade, to empty the undo logs, we cannot assume that this
has been done. So, separate insert_undo log may exist for recovered
uncommitted transactions. These transactions may be automatically
rolled back, or they may be in XA PREPARE state, in which case InnoDB
will preserve the transaction until an explicit XA COMMIT or XA ROLLBACK.
Upgrade has been tested by starting up MariaDB 10.2 with
./mysql-test-run --manual-gdb innodb.read_only_recovery
and then starting up this patched server with
and without --innodb-read-only.
trx_undo_ptr_t::undo: Renamed from update_undo.
trx_undo_ptr_t::old_insert: Renamed from insert_undo.
trx_rseg_t::undo_list: Renamed from update_undo_list.
trx_rseg_t::undo_cached: Merged from update_undo_cached
and insert_undo_cached.
trx_rseg_t::old_insert_list: Renamed from insert_undo_list.
row_purge_reset_trx_id(): New function to reset the columns.
This will be called for all undo processing in purge
that does not remove the clustered index record.
trx_undo_update_rec_get_update(): Allow trx_id=0 when copying the
old DB_TRX_ID of the record to the undo log.
ReadView::changes_visible(): Allow id==0. (Return true for it.
This is what speeds up the MVCC.)
row_vers_impl_x_locked_low(), row_vers_build_for_semi_consistent_read():
Implement a fast path for DB_TRX_ID=0.
Always initialize the TRX_UNDO_PAGE_TYPE to 0. Remove undo->type.
MLOG_UNDO_HDR_REUSE: Remove. This changes the redo log format!
innobase_start_or_create_for_mysql(): Set srv_undo_sources before
starting any transactions.
The parsing of the MLOG_ZIP_WRITE_TRX_ID record was successfully
tested by running the following:
./mtr --parallel=auto --mysqld=--debug=d,ib_log innodb_zip.bug56680
grep MLOG_ZIP_WRITE_TRX_ID var/*/log/mysqld.1.err
2017-07-07 13:08:16 +03:00
|
|
|
|
|
|
|
ut_a(trx_purge_state() == PURGE_STATE_INIT);
|
|
|
|
|
|
|
|
if (srv_force_recovery < SRV_FORCE_NO_BACKGROUND) {
|
|
|
|
srv_undo_sources = true;
|
|
|
|
/* Create the dict stats gathering thread */
|
|
|
|
srv_dict_stats_thread_active = true;
|
|
|
|
dict_stats_thread_handle = os_thread_create(
|
|
|
|
dict_stats_thread, NULL, NULL);
|
|
|
|
|
|
|
|
/* Create the thread that will optimize the
|
|
|
|
FULLTEXT search index subsystem. */
|
|
|
|
fts_optimize_init();
|
|
|
|
}
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Create the SYS_FOREIGN and SYS_FOREIGN_COLS system tables */
|
|
|
|
err = dict_create_or_check_foreign_constraint_tables();
|
2017-02-01 15:47:33 +02:00
|
|
|
if (err == DB_SUCCESS) {
|
|
|
|
err = dict_create_or_check_sys_tablespace();
|
|
|
|
if (err == DB_SUCCESS) {
|
|
|
|
err = dict_create_or_check_sys_virtual();
|
|
|
|
}
|
2016-08-12 11:17:45 +03:00
|
|
|
}
|
2017-02-01 15:47:33 +02:00
|
|
|
switch (err) {
|
|
|
|
case DB_SUCCESS:
|
|
|
|
break;
|
|
|
|
case DB_READ_ONLY:
|
|
|
|
if (srv_force_recovery >= SRV_FORCE_NO_TRX_UNDO) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ib::error() << "Cannot create system tables in read-only mode";
|
|
|
|
/* fall through */
|
|
|
|
default:
|
2016-08-12 11:17:45 +03:00
|
|
|
return(srv_init_abort(err));
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2
InnoDB I/O and buffer pool interfaces and the redo log format
have been changed between MariaDB 10.1 and 10.2, and the backup
code has to be adjusted accordingly.
The code has been simplified, and many memory leaks have been fixed.
Instead of the file name xtrabackup_logfile, the file name ib_logfile0
is being used for the copy of the redo log. Unnecessary InnoDB startup and
shutdown and some unnecessary threads have been removed.
Some help was provided by Vladislav Vaintroub.
Parameters have been cleaned up and aligned with those of MariaDB 10.2.
The --dbug option has been added, so that in debug builds,
--dbug=d,ib_log can be specified to enable diagnostic messages
for processing redo log entries.
By default, innodb_doublewrite=OFF, so that --prepare works faster.
If more crash-safety for --prepare is needed, double buffering
can be enabled.
The parameter innodb_log_checksums=OFF can be used to ignore redo log
checksums in --backup.
Some messages have been cleaned up.
Unless --export is specified, Mariabackup will not deal with undo log.
The InnoDB mini-transaction redo log is not only about user-level
transactions; it is actually about mini-transactions. To avoid confusion,
call it the redo log, not transaction log.
We disable any undo log processing in --prepare.
Because MariaDB 10.2 supports indexed virtual columns, the
undo log processing would need to be able to evaluate virtual column
expressions. To reduce the amount of code dependencies, we will not
process any undo log in prepare.
This means that the --export option must be disabled for now.
This also means that the following options are redundant
and have been removed:
xtrabackup --apply-log-only
innobackupex --redo-only
In addition to disabling any undo log processing, we will disable any
further changes to data pages during --prepare, including the change
buffer merge. This means that restoring incremental backups should
reliably work even when change buffering is being used on the server.
Because of this, preparing a backup will not generate any further
redo log, and the redo log file can be safely deleted. (If the
--export option is enabled in the future, it must generate redo log
when processing undo logs and buffered changes.)
In --prepare, we cannot easily know if a partial backup was used,
especially when restoring a series of incremental backups. So, we
simply warn about any missing files, and ignore the redo log for them.
FIXME: Enable the --export option.
FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write
a test that initiates a backup while an ALGORITHM=INPLACE operation
is creating indexes or rebuilding a table. An error should be detected
when preparing the backup.
FIXME: In --incremental --prepare, xtrabackup_apply_delta() should
ensure that if FSP_SIZE is modified, the file size will be adjusted
accordingly.
2017-06-30 10:49:37 +03:00
|
|
|
if (!srv_read_only_mode && srv_operation == SRV_OPERATION_NORMAL) {
|
2017-05-10 15:13:11 +03:00
|
|
|
/* Initialize the innodb_temporary tablespace and keep
|
|
|
|
it open until shutdown. */
|
|
|
|
err = srv_open_tmp_tablespace(create_new_db);
|
|
|
|
|
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
return(srv_init_abort(err));
|
|
|
|
}
|
|
|
|
|
|
|
|
trx_temp_rseg_create();
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2015-01-06 16:08:42 +02:00
|
|
|
thread_handles[1 + SRV_MAX_N_IO_THREADS] = os_thread_create(
|
2014-02-26 19:11:54 +01:00
|
|
|
srv_master_thread,
|
|
|
|
NULL, thread_ids + (1 + SRV_MAX_N_IO_THREADS));
|
2015-01-06 16:08:42 +02:00
|
|
|
thread_started[1 + SRV_MAX_N_IO_THREADS] = true;
|
2016-08-12 11:17:45 +03:00
|
|
|
srv_start_state_set(SRV_START_STATE_MASTER);
|
2017-06-21 12:22:02 +03:00
|
|
|
}
|
MDEV-13039 innodb_fast_shutdown=0 may fail to purge all undo log
When a slow shutdown is performed soon after spawning some work for
background threads that can create or commit transactions, it is possible
that new transactions are started or committed after the purge has finished.
This is violating the specification of innodb_fast_shutdown=0, namely that
the purge must be completed. (None of the history of the recent transactions
would be purged.)
Also, it is possible that the purge threads would exit in slow shutdown
while there exist active transactions, such as recovered incomplete
transactions that are being rolled back. Thus, the slow shutdown could
fail to purge some undo log that becomes purgeable after the transaction
commit or rollback.
srv_undo_sources: A flag that indicates if undo log can be generated
or the persistent, whether by background threads or by user SQL.
Even when this flag is clear, active transactions that already exist
in the system may be committed or rolled back.
innodb_shutdown(): Renamed from innobase_shutdown_for_mysql().
Do not return an error code; the operation never fails.
Clear the srv_undo_sources flag, and also ensure that the background
DROP TABLE queue is empty.
srv_purge_should_exit(): Do not allow the purge to exit if
srv_undo_sources are active or the background DROP TABLE queue is not
empty, or in slow shutdown, if any active transactions exist
(and are being rolled back).
srv_purge_coordinator_thread(): Remove some previous workarounds
for this bug.
innobase_start_or_create_for_mysql(): Set buf_page_cleaner_is_active
and srv_dict_stats_thread_active directly. Set srv_undo_sources before
starting the purge subsystem, to prevent immediate shutdown of the purge.
Create dict_stats_thread and fts_optimize_thread immediately
after setting srv_undo_sources, so that shutdown can use this flag to
determine if these subsystems were started.
dict_stats_shutdown(): Shut down dict_stats_thread. Backported from 10.2.
srv_shutdown_table_bg_threads(): Remove (unused).
2017-06-08 15:43:06 +03:00
|
|
|
|
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2
InnoDB I/O and buffer pool interfaces and the redo log format
have been changed between MariaDB 10.1 and 10.2, and the backup
code has to be adjusted accordingly.
The code has been simplified, and many memory leaks have been fixed.
Instead of the file name xtrabackup_logfile, the file name ib_logfile0
is being used for the copy of the redo log. Unnecessary InnoDB startup and
shutdown and some unnecessary threads have been removed.
Some help was provided by Vladislav Vaintroub.
Parameters have been cleaned up and aligned with those of MariaDB 10.2.
The --dbug option has been added, so that in debug builds,
--dbug=d,ib_log can be specified to enable diagnostic messages
for processing redo log entries.
By default, innodb_doublewrite=OFF, so that --prepare works faster.
If more crash-safety for --prepare is needed, double buffering
can be enabled.
The parameter innodb_log_checksums=OFF can be used to ignore redo log
checksums in --backup.
Some messages have been cleaned up.
Unless --export is specified, Mariabackup will not deal with undo log.
The InnoDB mini-transaction redo log is not only about user-level
transactions; it is actually about mini-transactions. To avoid confusion,
call it the redo log, not transaction log.
We disable any undo log processing in --prepare.
Because MariaDB 10.2 supports indexed virtual columns, the
undo log processing would need to be able to evaluate virtual column
expressions. To reduce the amount of code dependencies, we will not
process any undo log in prepare.
This means that the --export option must be disabled for now.
This also means that the following options are redundant
and have been removed:
xtrabackup --apply-log-only
innobackupex --redo-only
In addition to disabling any undo log processing, we will disable any
further changes to data pages during --prepare, including the change
buffer merge. This means that restoring incremental backups should
reliably work even when change buffering is being used on the server.
Because of this, preparing a backup will not generate any further
redo log, and the redo log file can be safely deleted. (If the
--export option is enabled in the future, it must generate redo log
when processing undo logs and buffered changes.)
In --prepare, we cannot easily know if a partial backup was used,
especially when restoring a series of incremental backups. So, we
simply warn about any missing files, and ignore the redo log for them.
FIXME: Enable the --export option.
FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write
a test that initiates a backup while an ALGORITHM=INPLACE operation
is creating indexes or rebuilding a table. An error should be detected
when preparing the backup.
FIXME: In --incremental --prepare, xtrabackup_apply_delta() should
ensure that if FSP_SIZE is modified, the file size will be adjusted
accordingly.
2017-06-30 10:49:37 +03:00
|
|
|
if (!srv_read_only_mode && srv_operation == SRV_OPERATION_NORMAL
|
2017-06-21 12:22:02 +03:00
|
|
|
&& srv_force_recovery < SRV_FORCE_NO_BACKGROUND) {
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2015-01-06 16:08:42 +02:00
|
|
|
thread_handles[5 + SRV_MAX_N_IO_THREADS] = os_thread_create(
|
2014-02-26 19:11:54 +01:00
|
|
|
srv_purge_coordinator_thread,
|
|
|
|
NULL, thread_ids + 5 + SRV_MAX_N_IO_THREADS);
|
|
|
|
|
2015-01-06 16:08:42 +02:00
|
|
|
thread_started[5 + SRV_MAX_N_IO_THREADS] = true;
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
ut_a(UT_ARR_SIZE(thread_ids)
|
|
|
|
> 5 + srv_n_purge_threads + SRV_MAX_N_IO_THREADS);
|
|
|
|
|
|
|
|
/* We've already created the purge coordinator thread above. */
|
|
|
|
for (i = 1; i < srv_n_purge_threads; ++i) {
|
2015-01-06 16:08:42 +02:00
|
|
|
thread_handles[5 + i + SRV_MAX_N_IO_THREADS] = os_thread_create(
|
2014-02-26 19:11:54 +01:00
|
|
|
srv_worker_thread, NULL,
|
|
|
|
thread_ids + 5 + i + SRV_MAX_N_IO_THREADS);
|
2015-01-06 16:08:42 +02:00
|
|
|
thread_started[5 + i + SRV_MAX_N_IO_THREADS] = true;
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
srv_start_wait_for_purge_to_start();
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
srv_start_state_set(SRV_START_STATE_PURGE);
|
2014-02-26 19:11:54 +01:00
|
|
|
} else {
|
2018-02-22 09:30:41 +02:00
|
|
|
purge_sys.state = PURGE_STATE_DISABLED;
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
2017-12-13 23:14:15 +02:00
|
|
|
srv_is_being_started = false;
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
if (!srv_read_only_mode) {
|
2016-12-05 21:04:30 +02:00
|
|
|
/* wake main loop of page cleaner up */
|
|
|
|
os_event_set(buf_flush_event);
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (srv_print_verbose_log) {
|
2016-08-12 11:17:45 +03:00
|
|
|
ib::info() << INNODB_VERSION_STR
|
MDEV-15132 Avoid accessing the TRX_SYS page
InnoDB maintains an internal persistent sequence of transaction
identifiers. This sequence is used for assigning both transaction
start identifiers (DB_TRX_ID=trx->id) and end identifiers (trx->no)
as well as end identifiers for the mysql.transaction_registry table
that was introduced in MDEV-12894.
TRX_SYS_TRX_ID_WRITE_MARGIN: Remove. After this many updates of
the sequence we used to update the TRX_SYS page. We can avoid accessing
the TRX_SYS page if we modify the InnoDB startup so that resurrecting
the sequence from other pages of the transaction system.
TRX_SYS_TRX_ID_STORE: Deprecate. The field only exists for the purpose
of upgrading from an earlier version of MySQL or MariaDB.
Starting with this fix, MariaDB will rely on the fields
TRX_UNDO_TRX_ID, TRX_UNDO_TRX_NO in the undo log header page of
each non-committed transaction, and on the new field
TRX_RSEG_MAX_TRX_ID in rollback segment header pages.
Because of this change, setting innodb_force_recovery=5 or 6 may cause
the system to recover with trx_sys.get_max_trx_id()==0. We must adjust
checks for invalid DB_TRX_ID and PAGE_MAX_TRX_ID accordingly.
We will change the startup and shutdown messages to display the
trx_sys.get_max_trx_id() in addition to the log sequence number.
trx_sys_t::flush_max_trx_id(): Remove.
trx_undo_mem_create_at_db_start(), trx_undo_lists_init():
Add an output parameter max_trx_id, to be updated from
TRX_UNDO_TRX_ID, TRX_UNDO_TRX_NO.
TRX_RSEG_MAX_TRX_ID: New field, for persisting
trx_sys.get_max_trx_id() at the time of the latest transaction commit.
Startup is not reading the undo log pages of committed transactions.
We want to avoid additional page accesses on startup, as well as
trouble when all undo logs have been emptied.
On startup, we will simply determine the maximum value from all pages
that are being read anyway.
TRX_RSEG_FORMAT: Redefined from TRX_RSEG_MAX_SIZE.
Old versions of InnoDB wrote uninitialized garbage to unused data fields.
Because of this, we cannot simply introduce a new field in the
rollback segment pages and expect it to be always zero, like it would
if the database was created by a recent enough InnoDB version.
Luckily, it looks like the field TRX_RSEG_MAX_SIZE was always written
as 0xfffffffe. We will indicate a new subformat of the page by writing
0 to this field. This has the nice side effect that after a downgrade
to older versions of InnoDB, transactions should fail to allocate any
undo log, that is, writes will be blocked. So, there is no problem of
getting corrupted transaction identifiers after downgrading.
trx_rseg_t::max_size: Remove.
trx_rseg_header_create(): Remove the parameter max_size=ULINT_MAX.
trx_purge_add_undo_to_history(): Update TRX_RSEG_MAX_SIZE
(and TRX_RSEG_FORMAT if needed). This is invoked on transaction commit.
trx_rseg_mem_restore(): If TRX_RSEG_FORMAT contains 0,
read TRX_RSEG_MAX_SIZE.
trx_rseg_array_init(): Invoke trx_sys.init_max_trx_id(max_trx_id + 1)
where max_trx_id was the maximum that was encountered in the rollback
segment pages and the undo log pages of recovered active, XA PREPARE,
or some committed transactions. (See trx_purge_add_undo_to_history()
which invokes trx_rsegf_set_nth_undo(..., FIL_NULL, ...);
not all committed transactions will be immediately detached from the
rollback segment header.)
2018-01-31 10:24:19 +02:00
|
|
|
<< " started; log sequence number "
|
|
|
|
<< srv_start_lsn
|
|
|
|
<< "; transaction id " << trx_sys.get_max_trx_id();
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (srv_force_recovery > 0) {
|
2016-08-12 11:17:45 +03:00
|
|
|
ib::info() << "!!! innodb_force_recovery is set to "
|
|
|
|
<< srv_force_recovery << " !!!";
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (srv_force_recovery == 0) {
|
|
|
|
/* In the insert buffer we may have even bigger tablespace
|
|
|
|
id's, because we may have dropped those tablespaces, but
|
|
|
|
insert buffer merge has not had time to clean the records from
|
|
|
|
the ibuf tree. */
|
|
|
|
|
|
|
|
ibuf_update_max_tablespace_id();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!srv_read_only_mode) {
|
2016-08-12 11:17:45 +03:00
|
|
|
if (create_new_db) {
|
|
|
|
srv_buffer_pool_load_at_startup = FALSE;
|
|
|
|
}
|
|
|
|
|
2015-07-14 16:05:29 -04:00
|
|
|
#ifdef WITH_WSREP
|
|
|
|
/*
|
|
|
|
Create the dump/load thread only when not running with
|
|
|
|
--wsrep-recover.
|
|
|
|
*/
|
|
|
|
if (!wsrep_recovery) {
|
|
|
|
#endif /* WITH_WSREP */
|
2017-08-31 08:27:59 +03:00
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
/* Create the buffer pool dump/load thread */
|
2017-06-12 14:26:32 +03:00
|
|
|
srv_buf_dump_thread_active = true;
|
2015-07-14 16:05:29 -04:00
|
|
|
buf_dump_thread_handle=
|
|
|
|
os_thread_create(buf_dump_thread, NULL, NULL);
|
MDEV-11638 Encryption causes race conditions in InnoDB shutdown
InnoDB shutdown failed to properly take fil_crypt_thread() into account.
The encryption threads were signalled to shut down together with other
non-critical tasks. This could be much too early in case of slow shutdown,
which could need minutes to complete the purge. Furthermore, InnoDB
failed to wait for the fil_crypt_thread() to actually exit before
proceeding to the final steps of shutdown, causing the race conditions.
Furthermore, the log_scrub_thread() was shut down way too early.
Also it should remain until the SRV_SHUTDOWN_FLUSH_PHASE.
fil_crypt_threads_end(): Remove. This would cause the threads to
be terminated way too early.
srv_buf_dump_thread_active, srv_dict_stats_thread_active,
lock_sys->timeout_thread_active, log_scrub_thread_active,
srv_monitor_active, srv_error_monitor_active: Remove a race condition
between startup and shutdown, by setting these in the startup thread
that creates threads, not in each created thread. In this way, once the
flag is cleared, it will remain cleared during shutdown.
srv_n_fil_crypt_threads_started, fil_crypt_threads_event: Declare in
global rather than static scope.
log_scrub_event, srv_log_scrub_thread_active, log_scrub_thread():
Declare in static rather than global scope. Let these be created by
log_init() and freed by log_shutdown().
rotate_thread_t::should_shutdown(): Do not shut down before the
SRV_SHUTDOWN_FLUSH_PHASE.
srv_any_background_threads_are_active(): Remove. These checks now
exist in logs_empty_and_mark_files_at_shutdown().
logs_empty_and_mark_files_at_shutdown(): Shut down the threads in
the proper order. Keep fil_crypt_thread() and log_scrub_thread() alive
until SRV_SHUTDOWN_FLUSH_PHASE, and check that they actually terminate.
2017-01-04 18:43:32 +02:00
|
|
|
|
2015-07-14 16:05:29 -04:00
|
|
|
#ifdef WITH_WSREP
|
|
|
|
} else {
|
2016-08-12 11:17:45 +03:00
|
|
|
ib::warn() <<
|
2015-07-14 16:05:29 -04:00
|
|
|
"Skipping buffer pool dump/restore during "
|
2016-08-12 11:17:45 +03:00
|
|
|
"wsrep recovery.";
|
2015-07-14 16:05:29 -04:00
|
|
|
}
|
|
|
|
#endif /* WITH_WSREP */
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2017-01-31 19:43:03 +02:00
|
|
|
/* Create thread(s) that handles key rotation. This is
|
|
|
|
needed already here as log_preflush_pool_modified_pages
|
|
|
|
will flush dirty pages and that might need e.g.
|
|
|
|
fil_crypt_threads_event. */
|
|
|
|
fil_system_enter();
|
2017-08-31 11:08:43 +03:00
|
|
|
btr_scrub_init();
|
2017-01-31 19:43:03 +02:00
|
|
|
fil_crypt_threads_init();
|
|
|
|
fil_system_exit();
|
|
|
|
|
|
|
|
/* Initialize online defragmentation. */
|
|
|
|
btr_defragment_init();
|
2017-05-23 12:17:43 +03:00
|
|
|
btr_defragment_thread_active = true;
|
|
|
|
os_thread_create(btr_defragment_thread, NULL, NULL);
|
2017-01-31 19:43:03 +02:00
|
|
|
|
2017-06-08 15:43:06 +03:00
|
|
|
srv_start_state |= SRV_START_STATE_REDO;
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
2016-09-06 09:43:16 +03:00
|
|
|
/* Create the buffer pool resize thread */
|
2017-01-05 10:48:03 +02:00
|
|
|
srv_buf_resize_thread_active = true;
|
2016-09-06 09:43:16 +03:00
|
|
|
os_thread_create(buf_resize_thread, NULL, NULL);
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
return(DB_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/********************************************************************
|
|
|
|
Sync all FTS cache before shutdown */
|
|
|
|
static
|
|
|
|
void
|
|
|
|
srv_fts_close(void)
|
|
|
|
/*===============*/
|
|
|
|
{
|
|
|
|
dict_table_t* table;
|
|
|
|
|
|
|
|
for (table = UT_LIST_GET_FIRST(dict_sys->table_LRU);
|
|
|
|
table; table = UT_LIST_GET_NEXT(table_LRU, table)) {
|
|
|
|
fts_t* fts = table->fts;
|
|
|
|
|
|
|
|
if (fts != NULL) {
|
|
|
|
fts_sync_table(table);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (table = UT_LIST_GET_FIRST(dict_sys->table_non_LRU);
|
|
|
|
table; table = UT_LIST_GET_NEXT(table_LRU, table)) {
|
|
|
|
fts_t* fts = table->fts;
|
|
|
|
|
|
|
|
if (fts != NULL) {
|
|
|
|
fts_sync_table(table);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-06-08 15:43:06 +03:00
|
|
|
/** Shut down background threads that can generate undo log. */
|
2016-12-14 17:46:58 +01:00
|
|
|
void
|
2017-06-12 17:43:07 +03:00
|
|
|
srv_shutdown_bg_undo_sources()
|
2016-12-14 17:46:58 +01:00
|
|
|
{
|
MDEV-13039 innodb_fast_shutdown=0 may fail to purge all undo log
When a slow shutdown is performed soon after spawning some work for
background threads that can create or commit transactions, it is possible
that new transactions are started or committed after the purge has finished.
This is violating the specification of innodb_fast_shutdown=0, namely that
the purge must be completed. (None of the history of the recent transactions
would be purged.)
Also, it is possible that the purge threads would exit in slow shutdown
while there exist active transactions, such as recovered incomplete
transactions that are being rolled back. Thus, the slow shutdown could
fail to purge some undo log that becomes purgeable after the transaction
commit or rollback.
srv_undo_sources: A flag that indicates if undo log can be generated
or the persistent, whether by background threads or by user SQL.
Even when this flag is clear, active transactions that already exist
in the system may be committed or rolled back.
innodb_shutdown(): Renamed from innobase_shutdown_for_mysql().
Do not return an error code; the operation never fails.
Clear the srv_undo_sources flag, and also ensure that the background
DROP TABLE queue is empty.
srv_purge_should_exit(): Do not allow the purge to exit if
srv_undo_sources are active or the background DROP TABLE queue is not
empty, or in slow shutdown, if any active transactions exist
(and are being rolled back).
srv_purge_coordinator_thread(): Remove some previous workarounds
for this bug.
innobase_start_or_create_for_mysql(): Set buf_page_cleaner_is_active
and srv_dict_stats_thread_active directly. Set srv_undo_sources before
starting the purge subsystem, to prevent immediate shutdown of the purge.
Create dict_stats_thread and fts_optimize_thread immediately
after setting srv_undo_sources, so that shutdown can use this flag to
determine if these subsystems were started.
dict_stats_shutdown(): Shut down dict_stats_thread. Backported from 10.2.
srv_shutdown_table_bg_threads(): Remove (unused).
2017-06-08 15:43:06 +03:00
|
|
|
if (srv_undo_sources) {
|
2017-01-31 19:43:03 +02:00
|
|
|
ut_ad(!srv_read_only_mode);
|
|
|
|
fts_optimize_shutdown();
|
|
|
|
dict_stats_shutdown();
|
MDEV-13039 innodb_fast_shutdown=0 may fail to purge all undo log
When a slow shutdown is performed soon after spawning some work for
background threads that can create or commit transactions, it is possible
that new transactions are started or committed after the purge has finished.
This is violating the specification of innodb_fast_shutdown=0, namely that
the purge must be completed. (None of the history of the recent transactions
would be purged.)
Also, it is possible that the purge threads would exit in slow shutdown
while there exist active transactions, such as recovered incomplete
transactions that are being rolled back. Thus, the slow shutdown could
fail to purge some undo log that becomes purgeable after the transaction
commit or rollback.
srv_undo_sources: A flag that indicates if undo log can be generated
or the persistent, whether by background threads or by user SQL.
Even when this flag is clear, active transactions that already exist
in the system may be committed or rolled back.
innodb_shutdown(): Renamed from innobase_shutdown_for_mysql().
Do not return an error code; the operation never fails.
Clear the srv_undo_sources flag, and also ensure that the background
DROP TABLE queue is empty.
srv_purge_should_exit(): Do not allow the purge to exit if
srv_undo_sources are active or the background DROP TABLE queue is not
empty, or in slow shutdown, if any active transactions exist
(and are being rolled back).
srv_purge_coordinator_thread(): Remove some previous workarounds
for this bug.
innobase_start_or_create_for_mysql(): Set buf_page_cleaner_is_active
and srv_dict_stats_thread_active directly. Set srv_undo_sources before
starting the purge subsystem, to prevent immediate shutdown of the purge.
Create dict_stats_thread and fts_optimize_thread immediately
after setting srv_undo_sources, so that shutdown can use this flag to
determine if these subsystems were started.
dict_stats_shutdown(): Shut down dict_stats_thread. Backported from 10.2.
srv_shutdown_table_bg_threads(): Remove (unused).
2017-06-08 15:43:06 +03:00
|
|
|
while (row_get_background_drop_list_len_low()) {
|
|
|
|
srv_wake_master_thread();
|
|
|
|
os_thread_yield();
|
|
|
|
}
|
|
|
|
srv_undo_sources = false;
|
2017-01-31 19:43:03 +02:00
|
|
|
}
|
2016-12-14 17:46:58 +01:00
|
|
|
}
|
|
|
|
|
2017-01-31 19:43:03 +02:00
|
|
|
/** Shut down InnoDB. */
|
|
|
|
void
|
|
|
|
innodb_shutdown()
|
2014-02-26 19:11:54 +01:00
|
|
|
{
|
2017-02-13 14:06:01 +02:00
|
|
|
ut_ad(!srv_running);
|
2017-06-08 15:43:06 +03:00
|
|
|
ut_ad(!srv_undo_sources);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2
InnoDB I/O and buffer pool interfaces and the redo log format
have been changed between MariaDB 10.1 and 10.2, and the backup
code has to be adjusted accordingly.
The code has been simplified, and many memory leaks have been fixed.
Instead of the file name xtrabackup_logfile, the file name ib_logfile0
is being used for the copy of the redo log. Unnecessary InnoDB startup and
shutdown and some unnecessary threads have been removed.
Some help was provided by Vladislav Vaintroub.
Parameters have been cleaned up and aligned with those of MariaDB 10.2.
The --dbug option has been added, so that in debug builds,
--dbug=d,ib_log can be specified to enable diagnostic messages
for processing redo log entries.
By default, innodb_doublewrite=OFF, so that --prepare works faster.
If more crash-safety for --prepare is needed, double buffering
can be enabled.
The parameter innodb_log_checksums=OFF can be used to ignore redo log
checksums in --backup.
Some messages have been cleaned up.
Unless --export is specified, Mariabackup will not deal with undo log.
The InnoDB mini-transaction redo log is not only about user-level
transactions; it is actually about mini-transactions. To avoid confusion,
call it the redo log, not transaction log.
We disable any undo log processing in --prepare.
Because MariaDB 10.2 supports indexed virtual columns, the
undo log processing would need to be able to evaluate virtual column
expressions. To reduce the amount of code dependencies, we will not
process any undo log in prepare.
This means that the --export option must be disabled for now.
This also means that the following options are redundant
and have been removed:
xtrabackup --apply-log-only
innobackupex --redo-only
In addition to disabling any undo log processing, we will disable any
further changes to data pages during --prepare, including the change
buffer merge. This means that restoring incremental backups should
reliably work even when change buffering is being used on the server.
Because of this, preparing a backup will not generate any further
redo log, and the redo log file can be safely deleted. (If the
--export option is enabled in the future, it must generate redo log
when processing undo logs and buffered changes.)
In --prepare, we cannot easily know if a partial backup was used,
especially when restoring a series of incremental backups. So, we
simply warn about any missing files, and ignore the redo log for them.
FIXME: Enable the --export option.
FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write
a test that initiates a backup while an ALGORITHM=INPLACE operation
is creating indexes or rebuilding a table. An error should be detected
when preparing the backup.
FIXME: In --incremental --prepare, xtrabackup_apply_delta() should
ensure that if FSP_SIZE is modified, the file size will be adjusted
accordingly.
2017-06-30 10:49:37 +03:00
|
|
|
switch (srv_operation) {
|
|
|
|
case SRV_OPERATION_BACKUP:
|
|
|
|
case SRV_OPERATION_RESTORE:
|
Follow-up fix to MDEV-12988 backup fails if innodb_undo_tablespaces>0
The fix broke mariabackup --prepare --incremental.
The restore of an incremental backup starts up (parts of) InnoDB twice.
First, all data files are discovered for applying .delta files. Then,
after the .delta files have been applied, InnoDB will be restarted
more completely, so that the redo log records will be applied via the
buffer pool.
During the first startup, the buffer pool is not initialized, and thus
trx_rseg_get_n_undo_tablespaces() must not be invoked. The apply of
the .delta files will currently assume that the --innodb-undo-tablespaces
option correctly specifies the number of undo tablespace files, just
like --backup does.
The second InnoDB startup of --prepare for applying the redo log will
properly invoke trx_rseg_get_n_undo_tablespaces().
enum srv_operation_mode: Add SRV_OPERATION_RESTORE_DELTA for
distinguishing the apply of .delta files from SRV_OPERATION_RESTORE.
srv_undo_tablespaces_init(): In mariabackup --prepare --incremental,
in the initial SRV_OPERATION_RESTORE_DELTA phase, do not invoke
trx_rseg_get_n_undo_tablespaces() because the buffer pool or the
redo logs are not available. Instead, blindly rely on the parameter
--innodb-undo-tablespaces.
2017-08-18 08:52:41 +03:00
|
|
|
case SRV_OPERATION_RESTORE_DELTA:
|
2017-10-10 10:28:54 +03:00
|
|
|
case SRV_OPERATION_RESTORE_EXPORT:
|
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2
InnoDB I/O and buffer pool interfaces and the redo log format
have been changed between MariaDB 10.1 and 10.2, and the backup
code has to be adjusted accordingly.
The code has been simplified, and many memory leaks have been fixed.
Instead of the file name xtrabackup_logfile, the file name ib_logfile0
is being used for the copy of the redo log. Unnecessary InnoDB startup and
shutdown and some unnecessary threads have been removed.
Some help was provided by Vladislav Vaintroub.
Parameters have been cleaned up and aligned with those of MariaDB 10.2.
The --dbug option has been added, so that in debug builds,
--dbug=d,ib_log can be specified to enable diagnostic messages
for processing redo log entries.
By default, innodb_doublewrite=OFF, so that --prepare works faster.
If more crash-safety for --prepare is needed, double buffering
can be enabled.
The parameter innodb_log_checksums=OFF can be used to ignore redo log
checksums in --backup.
Some messages have been cleaned up.
Unless --export is specified, Mariabackup will not deal with undo log.
The InnoDB mini-transaction redo log is not only about user-level
transactions; it is actually about mini-transactions. To avoid confusion,
call it the redo log, not transaction log.
We disable any undo log processing in --prepare.
Because MariaDB 10.2 supports indexed virtual columns, the
undo log processing would need to be able to evaluate virtual column
expressions. To reduce the amount of code dependencies, we will not
process any undo log in prepare.
This means that the --export option must be disabled for now.
This also means that the following options are redundant
and have been removed:
xtrabackup --apply-log-only
innobackupex --redo-only
In addition to disabling any undo log processing, we will disable any
further changes to data pages during --prepare, including the change
buffer merge. This means that restoring incremental backups should
reliably work even when change buffering is being used on the server.
Because of this, preparing a backup will not generate any further
redo log, and the redo log file can be safely deleted. (If the
--export option is enabled in the future, it must generate redo log
when processing undo logs and buffered changes.)
In --prepare, we cannot easily know if a partial backup was used,
especially when restoring a series of incremental backups. So, we
simply warn about any missing files, and ignore the redo log for them.
FIXME: Enable the --export option.
FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write
a test that initiates a backup while an ALGORITHM=INPLACE operation
is creating indexes or rebuilding a table. An error should be detected
when preparing the backup.
FIXME: In --incremental --prepare, xtrabackup_apply_delta() should
ensure that if FSP_SIZE is modified, the file size will be adjusted
accordingly.
2017-06-30 10:49:37 +03:00
|
|
|
fil_close_all_files();
|
|
|
|
break;
|
|
|
|
case SRV_OPERATION_NORMAL:
|
|
|
|
/* Shut down the persistent files. */
|
|
|
|
logs_empty_and_mark_files_at_shutdown();
|
2014-02-26 19:11:54 +01:00
|
|
|
|
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2
InnoDB I/O and buffer pool interfaces and the redo log format
have been changed between MariaDB 10.1 and 10.2, and the backup
code has to be adjusted accordingly.
The code has been simplified, and many memory leaks have been fixed.
Instead of the file name xtrabackup_logfile, the file name ib_logfile0
is being used for the copy of the redo log. Unnecessary InnoDB startup and
shutdown and some unnecessary threads have been removed.
Some help was provided by Vladislav Vaintroub.
Parameters have been cleaned up and aligned with those of MariaDB 10.2.
The --dbug option has been added, so that in debug builds,
--dbug=d,ib_log can be specified to enable diagnostic messages
for processing redo log entries.
By default, innodb_doublewrite=OFF, so that --prepare works faster.
If more crash-safety for --prepare is needed, double buffering
can be enabled.
The parameter innodb_log_checksums=OFF can be used to ignore redo log
checksums in --backup.
Some messages have been cleaned up.
Unless --export is specified, Mariabackup will not deal with undo log.
The InnoDB mini-transaction redo log is not only about user-level
transactions; it is actually about mini-transactions. To avoid confusion,
call it the redo log, not transaction log.
We disable any undo log processing in --prepare.
Because MariaDB 10.2 supports indexed virtual columns, the
undo log processing would need to be able to evaluate virtual column
expressions. To reduce the amount of code dependencies, we will not
process any undo log in prepare.
This means that the --export option must be disabled for now.
This also means that the following options are redundant
and have been removed:
xtrabackup --apply-log-only
innobackupex --redo-only
In addition to disabling any undo log processing, we will disable any
further changes to data pages during --prepare, including the change
buffer merge. This means that restoring incremental backups should
reliably work even when change buffering is being used on the server.
Because of this, preparing a backup will not generate any further
redo log, and the redo log file can be safely deleted. (If the
--export option is enabled in the future, it must generate redo log
when processing undo logs and buffered changes.)
In --prepare, we cannot easily know if a partial backup was used,
especially when restoring a series of incremental backups. So, we
simply warn about any missing files, and ignore the redo log for them.
FIXME: Enable the --export option.
FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write
a test that initiates a backup while an ALGORITHM=INPLACE operation
is creating indexes or rebuilding a table. An error should be detected
when preparing the backup.
FIXME: In --incremental --prepare, xtrabackup_apply_delta() should
ensure that if FSP_SIZE is modified, the file size will be adjusted
accordingly.
2017-06-30 10:49:37 +03:00
|
|
|
if (ulint n_threads = srv_conc_get_active_threads()) {
|
|
|
|
ib::warn() << "Query counter shows "
|
|
|
|
<< n_threads << " queries still"
|
|
|
|
" inside InnoDB at shutdown";
|
|
|
|
}
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
2017-06-29 23:10:46 +03:00
|
|
|
/* Exit any remaining threads. */
|
2016-08-12 11:17:45 +03:00
|
|
|
srv_shutdown_all_bg_threads();
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
if (srv_monitor_file) {
|
|
|
|
fclose(srv_monitor_file);
|
|
|
|
srv_monitor_file = 0;
|
|
|
|
if (srv_monitor_file_name) {
|
|
|
|
unlink(srv_monitor_file_name);
|
2016-08-12 11:17:45 +03:00
|
|
|
ut_free(srv_monitor_file_name);
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (srv_misc_tmpfile) {
|
|
|
|
fclose(srv_misc_tmpfile);
|
|
|
|
srv_misc_tmpfile = 0;
|
|
|
|
}
|
|
|
|
|
2017-01-31 19:43:03 +02:00
|
|
|
ut_ad(dict_stats_event || !srv_was_started || srv_read_only_mode);
|
|
|
|
ut_ad(dict_sys || !srv_was_started);
|
2018-01-17 19:43:08 +04:00
|
|
|
ut_ad(trx_sys.is_initialised() || !srv_was_started);
|
2017-02-01 15:47:33 +02:00
|
|
|
ut_ad(buf_dblwr || !srv_was_started || srv_read_only_mode
|
|
|
|
|| srv_force_recovery >= SRV_FORCE_NO_TRX_UNDO);
|
2017-01-31 19:43:03 +02:00
|
|
|
ut_ad(lock_sys || !srv_was_started);
|
2017-02-23 23:05:12 +02:00
|
|
|
#ifdef BTR_CUR_HASH_ADAPT
|
2017-01-31 19:43:03 +02:00
|
|
|
ut_ad(btr_search_sys || !srv_was_started);
|
2017-02-23 23:05:12 +02:00
|
|
|
#endif /* BTR_CUR_HASH_ADAPT */
|
2017-01-31 19:43:03 +02:00
|
|
|
ut_ad(ibuf || !srv_was_started);
|
|
|
|
ut_ad(log_sys || !srv_was_started);
|
|
|
|
|
|
|
|
if (dict_stats_event) {
|
2014-02-26 19:11:54 +01:00
|
|
|
dict_stats_thread_deinit();
|
2014-12-22 16:53:17 +02:00
|
|
|
}
|
|
|
|
|
2017-06-08 15:43:06 +03:00
|
|
|
if (srv_start_state_is_set(SRV_START_STATE_REDO)) {
|
2017-01-31 19:43:03 +02:00
|
|
|
ut_ad(!srv_read_only_mode);
|
|
|
|
/* srv_shutdown_bg_undo_sources() already invoked
|
|
|
|
fts_optimize_shutdown(); dict_stats_shutdown(); */
|
|
|
|
|
|
|
|
fil_crypt_threads_cleanup();
|
|
|
|
btr_scrub_cleanup();
|
2017-05-26 22:44:16 +03:00
|
|
|
btr_defragment_shutdown();
|
2017-01-31 19:43:03 +02:00
|
|
|
}
|
2015-12-20 12:33:58 +01:00
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
/* This must be disabled before closing the buffer pool
|
|
|
|
and closing the data dictionary. */
|
|
|
|
|
2017-02-23 23:05:12 +02:00
|
|
|
#ifdef BTR_CUR_HASH_ADAPT
|
2017-01-31 19:43:03 +02:00
|
|
|
if (dict_sys) {
|
|
|
|
btr_search_disable(true);
|
|
|
|
}
|
2017-02-23 23:05:12 +02:00
|
|
|
#endif /* BTR_CUR_HASH_ADAPT */
|
2017-01-31 19:43:03 +02:00
|
|
|
if (ibuf) {
|
|
|
|
ibuf_close();
|
|
|
|
}
|
|
|
|
if (log_sys) {
|
|
|
|
log_shutdown();
|
|
|
|
}
|
2017-12-22 16:15:41 +02:00
|
|
|
trx_sys.close();
|
2018-02-22 09:30:41 +02:00
|
|
|
purge_sys.close();
|
2017-01-31 19:43:03 +02:00
|
|
|
if (buf_dblwr) {
|
|
|
|
buf_dblwr_free();
|
|
|
|
}
|
|
|
|
if (lock_sys) {
|
|
|
|
lock_sys_close();
|
|
|
|
}
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
trx_pool_close();
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
/* We don't create these mutexes in RO mode because we don't create
|
|
|
|
the temp files that the cover. */
|
|
|
|
if (!srv_read_only_mode) {
|
|
|
|
mutex_free(&srv_monitor_file_mutex);
|
|
|
|
mutex_free(&srv_misc_tmpfile_mutex);
|
|
|
|
}
|
|
|
|
|
2017-01-31 19:43:03 +02:00
|
|
|
if (dict_sys) {
|
|
|
|
dict_close();
|
|
|
|
}
|
|
|
|
|
2017-02-23 23:05:12 +02:00
|
|
|
#ifdef BTR_CUR_HASH_ADAPT
|
2017-01-31 19:43:03 +02:00
|
|
|
if (btr_search_sys) {
|
|
|
|
btr_search_sys_free();
|
|
|
|
}
|
2017-02-23 23:05:12 +02:00
|
|
|
#endif /* BTR_CUR_HASH_ADAPT */
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
/* 3. Free all InnoDB's own mutexes and the os_fast_mutexes inside
|
|
|
|
them */
|
|
|
|
os_aio_free();
|
|
|
|
row_mysql_close();
|
|
|
|
srv_free();
|
|
|
|
fil_close();
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/* 4. Free all allocated memory */
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
pars_lexer_close();
|
2017-06-29 22:24:48 +03:00
|
|
|
recv_sys_close();
|
|
|
|
|
2017-03-08 22:36:10 +02:00
|
|
|
ut_ad(buf_pool_ptr || !srv_was_started);
|
|
|
|
if (buf_pool_ptr) {
|
|
|
|
buf_pool_free(srv_buf_pool_instances);
|
|
|
|
}
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
sync_check_close();
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
if (dict_foreign_err_file) {
|
|
|
|
fclose(dict_foreign_err_file);
|
|
|
|
}
|
|
|
|
|
2017-01-31 19:43:03 +02:00
|
|
|
if (srv_was_started && srv_print_verbose_log) {
|
2016-08-12 11:17:45 +03:00
|
|
|
ib::info() << "Shutdown completed; log sequence number "
|
MDEV-15132 Avoid accessing the TRX_SYS page
InnoDB maintains an internal persistent sequence of transaction
identifiers. This sequence is used for assigning both transaction
start identifiers (DB_TRX_ID=trx->id) and end identifiers (trx->no)
as well as end identifiers for the mysql.transaction_registry table
that was introduced in MDEV-12894.
TRX_SYS_TRX_ID_WRITE_MARGIN: Remove. After this many updates of
the sequence we used to update the TRX_SYS page. We can avoid accessing
the TRX_SYS page if we modify the InnoDB startup so that resurrecting
the sequence from other pages of the transaction system.
TRX_SYS_TRX_ID_STORE: Deprecate. The field only exists for the purpose
of upgrading from an earlier version of MySQL or MariaDB.
Starting with this fix, MariaDB will rely on the fields
TRX_UNDO_TRX_ID, TRX_UNDO_TRX_NO in the undo log header page of
each non-committed transaction, and on the new field
TRX_RSEG_MAX_TRX_ID in rollback segment header pages.
Because of this change, setting innodb_force_recovery=5 or 6 may cause
the system to recover with trx_sys.get_max_trx_id()==0. We must adjust
checks for invalid DB_TRX_ID and PAGE_MAX_TRX_ID accordingly.
We will change the startup and shutdown messages to display the
trx_sys.get_max_trx_id() in addition to the log sequence number.
trx_sys_t::flush_max_trx_id(): Remove.
trx_undo_mem_create_at_db_start(), trx_undo_lists_init():
Add an output parameter max_trx_id, to be updated from
TRX_UNDO_TRX_ID, TRX_UNDO_TRX_NO.
TRX_RSEG_MAX_TRX_ID: New field, for persisting
trx_sys.get_max_trx_id() at the time of the latest transaction commit.
Startup is not reading the undo log pages of committed transactions.
We want to avoid additional page accesses on startup, as well as
trouble when all undo logs have been emptied.
On startup, we will simply determine the maximum value from all pages
that are being read anyway.
TRX_RSEG_FORMAT: Redefined from TRX_RSEG_MAX_SIZE.
Old versions of InnoDB wrote uninitialized garbage to unused data fields.
Because of this, we cannot simply introduce a new field in the
rollback segment pages and expect it to be always zero, like it would
if the database was created by a recent enough InnoDB version.
Luckily, it looks like the field TRX_RSEG_MAX_SIZE was always written
as 0xfffffffe. We will indicate a new subformat of the page by writing
0 to this field. This has the nice side effect that after a downgrade
to older versions of InnoDB, transactions should fail to allocate any
undo log, that is, writes will be blocked. So, there is no problem of
getting corrupted transaction identifiers after downgrading.
trx_rseg_t::max_size: Remove.
trx_rseg_header_create(): Remove the parameter max_size=ULINT_MAX.
trx_purge_add_undo_to_history(): Update TRX_RSEG_MAX_SIZE
(and TRX_RSEG_FORMAT if needed). This is invoked on transaction commit.
trx_rseg_mem_restore(): If TRX_RSEG_FORMAT contains 0,
read TRX_RSEG_MAX_SIZE.
trx_rseg_array_init(): Invoke trx_sys.init_max_trx_id(max_trx_id + 1)
where max_trx_id was the maximum that was encountered in the rollback
segment pages and the undo log pages of recovered active, XA PREPARE,
or some committed transactions. (See trx_purge_add_undo_to_history()
which invokes trx_rsegf_set_nth_undo(..., FIL_NULL, ...);
not all committed transactions will be immediately detached from the
rollback segment header.)
2018-01-31 10:24:19 +02:00
|
|
|
<< srv_shutdown_lsn
|
|
|
|
<< "; transaction id " << trx_sys.get_max_trx_id();
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
2017-01-31 19:43:03 +02:00
|
|
|
srv_start_state = SRV_START_STATE_NONE;
|
2017-04-25 09:26:01 +03:00
|
|
|
srv_was_started = false;
|
|
|
|
srv_start_has_been_called = false;
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/** Get the meta-data filename from the table name for a
|
|
|
|
single-table tablespace.
|
|
|
|
@param[in] table table object
|
|
|
|
@param[out] filename filename
|
|
|
|
@param[in] max_len filename max length */
|
2014-02-26 19:11:54 +01:00
|
|
|
void
|
|
|
|
srv_get_meta_data_filename(
|
2016-09-06 09:43:16 +03:00
|
|
|
dict_table_t* table,
|
|
|
|
char* filename,
|
|
|
|
ulint max_len)
|
2014-02-26 19:11:54 +01:00
|
|
|
{
|
2016-08-12 11:17:45 +03:00
|
|
|
ulint len;
|
|
|
|
char* path;
|
|
|
|
|
|
|
|
/* Make sure the data_dir_path is set. */
|
|
|
|
dict_get_and_save_data_dir_path(table, false);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
if (DICT_TF_HAS_DATA_DIR(table->flags)) {
|
|
|
|
ut_a(table->data_dir_path);
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
path = fil_make_filepath(
|
|
|
|
table->data_dir_path, table->name.m_name, CFG, true);
|
2014-02-26 19:11:54 +01:00
|
|
|
} else {
|
2016-08-12 11:17:45 +03:00
|
|
|
path = fil_make_filepath(NULL, table->name.m_name, CFG, false);
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ut_a(path);
|
|
|
|
len = ut_strlen(path);
|
|
|
|
ut_a(max_len >= len);
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
strcpy(filename, path);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
ut_free(path);
|
2014-02-26 19:11:54 +01:00
|
|
|
}
|