You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2959 lines
81 KiB

9 years ago
MDEV-23190 InnoDB data file extension is not crash-safe When InnoDB is extending a data file, it is updating the FSP_SIZE field in the first page of the data file. In commit 8451e09073e8b1a300f177d74a9e3a530776640a (MDEV-11556) we removed a work-around for this bug and made recovery stricter, by making it track changes to FSP_SIZE via redo log records, and extend the data files before any changes are being applied to them. It turns out that the function fsp_fill_free_list() is not crash-safe with respect to this when it is initializing the change buffer bitmap page (page 1, or generally, N*innodb_page_size+1). It uses a separate mini-transaction that is committed (and will be written to the redo log file) before the mini-transaction that actually extended the data file. Hence, recovery can observe a reference to a page that is beyond the current end of the data file. fsp_fill_free_list(): Initialize the change buffer bitmap page in the same mini-transaction. The rest of the changes are fixing a bug that the use of the separate mini-transaction was attempting to work around. Namely, we must ensure that no other thread will access the change buffer bitmap page before our mini-transaction has been committed and all page latches have been released. That is, for read-ahead as well as neighbour flushing, we must avoid accessing pages that might not yet be durably part of the tablespace. fil_space_t::committed_size: The size of the tablespace as persisted by mtr_commit(). fil_space_t::max_page_number_for_io(): Limit the highest page number for I/O batches to committed_size. MTR_MEMO_SPACE_X_LOCK: Replaces MTR_MEMO_X_LOCK for fil_space_t::latch. mtr_x_space_lock(): Replaces mtr_x_lock() for fil_space_t::latch. mtr_memo_slot_release_func(): When releasing MTR_MEMO_SPACE_X_LOCK, copy space->size to space->committed_size. In this way, read-ahead or flushing will never be invoked on pages that do not yet exist according to FSP_SIZE.
5 years ago
12 years ago
12 years ago
MDEV-11782: Redefine the innodb_encrypt_log format Write only one encryption key to the checkpoint page. Use 4 bytes of nonce. Encrypt more of each redo log block, only skipping the 4-byte field LOG_BLOCK_HDR_NO which the initialization vector is derived from. Issue notes, not warning messages for rewriting the redo log files. recv_recovery_from_checkpoint_finish(): Do not generate any redo log, because we must avoid that before rewriting the redo log files, or otherwise a crash during a redo log rewrite (removing or adding encryption) may end up making the database unrecoverable. Instead, do these tasks in innobase_start_or_create_for_mysql(). Issue a firm "Missing MLOG_CHECKPOINT" error message. Remove some unreachable code and duplicated error messages for log corruption. LOG_HEADER_FORMAT_ENCRYPTED: A flag for identifying an encrypted redo log format. log_group_t::is_encrypted(), log_t::is_encrypted(): Determine if the redo log is in encrypted format. recv_find_max_checkpoint(): Interpret LOG_HEADER_FORMAT_ENCRYPTED. srv_prepare_to_delete_redo_log_files(): Display NOTE messages about adding or removing encryption. Do not issue warnings for redo log resizing any more. innobase_start_or_create_for_mysql(): Rebuild the redo logs also when the encryption changes. innodb_log_checksums_func_update(): Always use the CRC-32C checksum if innodb_encrypt_log. If needed, issue a warning that innodb_encrypt_log implies innodb_log_checksums. log_group_write_buf(): Compute the checksum on the encrypted block contents, so that transmission errors or incomplete blocks can be detected without decrypting. Rewrite most of the redo log encryption code. Only remember one encryption key at a time (but remember up to 5 when upgrading from the MariaDB 10.1 format.)
9 years ago
9 years ago
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.
9 years ago
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).
9 years ago
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.
9 years ago
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.
9 years ago
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.
9 years ago
11 years ago
10 years ago
9 years ago
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.
9 years ago
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.
9 years ago
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.
9 years ago
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.
9 years ago
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.
9 years ago
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.
9 years ago
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.
9 years ago
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.
9 years ago
MDEV-11738: Mariadb uses 100% of several of my 8 cpus doing nothing MDEV-11581: Mariadb starts InnoDB encryption threads when key has not changed or data scrubbing turned off Background: Key rotation is based on background threads (innodb-encryption-threads) periodically going through all tablespaces on fil_system. For each tablespace current used key version is compared to max key age (innodb-encryption-rotate-key-age). This process naturally takes CPU. Similarly, in same time need for scrubbing is investigated. Currently, key rotation is fully supported on Amazon AWS key management plugin only but InnoDB does not have knowledge what key management plugin is used. This patch re-purposes innodb-encryption-rotate-key-age=0 to disable key rotation and background data scrubbing. All new tables are added to special list for key rotation and key rotation is based on sending a event to background encryption threads instead of using periodic checking (i.e. timeout). fil0fil.cc: Added functions fil_space_acquire_low() to acquire a tablespace when it could be dropped concurrently. This function is used from fil_space_acquire() or fil_space_acquire_silent() that will not print any messages if we try to acquire space that does not exist. fil_space_release() to release a acquired tablespace. fil_space_next() to iterate tablespaces in fil_system using fil_space_acquire() and fil_space_release(). Similarly, fil_space_keyrotation_next() to iterate new list fil_system->rotation_list where new tables. are added if key rotation is disabled. Removed unnecessary functions fil_get_first_space_safe() fil_get_next_space_safe() fil_node_open_file(): After page 0 is read read also crypt_info if it is not yet read. btr_scrub_lock_dict_func() buf_page_check_corrupt() buf_page_encrypt_before_write() buf_merge_or_delete_for_page() lock_print_info_all_transactions() row_fts_psort_info_init() row_truncate_table_for_mysql() row_drop_table_for_mysql() Use fil_space_acquire()/release() to access fil_space_t. buf_page_decrypt_after_read(): Use fil_space_get_crypt_data() because at this point we might not yet have read page 0. fil0crypt.cc/fil0fil.h: Lot of changes. Pass fil_space_t* directly to functions needing it and store fil_space_t* to rotation state. Use fil_space_acquire()/release() when iterating tablespaces and removed unnecessary is_closing from fil_crypt_t. Use fil_space_t::is_stopping() to detect when access to tablespace should be stopped. Removed unnecessary fil_space_get_crypt_data(). fil_space_create(): Inform key rotation that there could be something to do if key rotation is disabled and new table with encryption enabled is created. Remove unnecessary functions fil_get_first_space_safe() and fil_get_next_space_safe(). fil_space_acquire() and fil_space_release() are used instead. Moved fil_space_get_crypt_data() and fil_space_set_crypt_data() to fil0crypt.cc. fsp_header_init(): Acquire fil_space_t*, write crypt_data and release space. check_table_options() Renamed FIL_SPACE_ENCRYPTION_* TO FIL_ENCRYPTION_* i_s.cc: Added ROTATING_OR_FLUSHING field to information_schema.innodb_tablespace_encryption to show current status of key rotation.
9 years ago
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.
9 years ago
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.
9 years ago
9 years ago
9 years ago
11 years ago
11 years ago
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.
9 years ago
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.
9 years ago
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.
9 years ago
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.
9 years ago
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.
9 years ago
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.
9 years ago
9 years ago
9 years ago
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.
9 years ago
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.
9 years ago
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.
9 years ago
MDEV-13564 Mariabackup does not work with TRUNCATE Implement undo tablespace truncation via normal redo logging. Implement TRUNCATE TABLE as a combination of RENAME to #sql-ib name, CREATE, and DROP. Note: Orphan #sql-ib*.ibd may be left behind if MariaDB Server 10.2 is killed before the DROP operation is committed. If MariaDB Server 10.2 is killed during TRUNCATE, it is also possible that the old table was renamed to #sql-ib*.ibd but the data dictionary will refer to the table using the original name. In MariaDB Server 10.3, RENAME inside InnoDB is transactional, and #sql-* tables will be dropped on startup. So, this new TRUNCATE will be fully crash-safe in 10.3. ha_mroonga::wrapper_truncate(): Pass table options to the underlying storage engine, now that ha_innobase::truncate() will need them. rpl_slave_state::truncate_state_table(): Before truncating mysql.gtid_slave_pos, evict any cached table handles from the table definition cache, so that there will be no stale references to the old table after truncating. == TRUNCATE TABLE == WL#6501 in MySQL 5.7 introduced separate log files for implementing atomic and crash-safe TRUNCATE TABLE, instead of using the InnoDB undo and redo log. Some convoluted logic was added to the InnoDB crash recovery, and some extra synchronization (including a redo log checkpoint) was introduced to make this work. This synchronization has caused performance problems and race conditions, and the extra log files cannot be copied or applied by external backup programs. In order to support crash-upgrade from MariaDB 10.2, we will keep the logic for parsing and applying the extra log files, but we will no longer generate those files in TRUNCATE TABLE. A prerequisite for crash-safe TRUNCATE is a crash-safe RENAME TABLE (with full redo and undo logging and proper rollback). This will be implemented in MDEV-14717. ha_innobase::truncate(): Invoke RENAME, create(), delete_table(). Because RENAME cannot be fully rolled back before MariaDB 10.3 due to missing undo logging, add some explicit rename-back in case the operation fails. ha_innobase::delete(): Introduce a variant that takes sqlcom as a parameter. In TRUNCATE TABLE, we do not want to touch any FOREIGN KEY constraints. ha_innobase::create(): Add the parameters file_per_table, trx. In TRUNCATE, the new table must be created in the same transaction that renames the old table. create_table_info_t::create_table_info_t(): Add the parameters file_per_table, trx. row_drop_table_for_mysql(): Replace a bool parameter with sqlcom. row_drop_table_after_create_fail(): New function, wrapping row_drop_table_for_mysql(). dict_truncate_index_tree_in_mem(), fil_truncate_tablespace(), fil_prepare_for_truncate(), fil_reinit_space_header_for_table(), row_truncate_table_for_mysql(), TruncateLogger, row_truncate_prepare(), row_truncate_rollback(), row_truncate_complete(), row_truncate_fts(), row_truncate_update_system_tables(), row_truncate_foreign_key_checks(), row_truncate_sanity_checks(): Remove. row_upd_check_references_constraints(): Remove a check for TRUNCATE, now that the table is no longer truncated in place. The new test innodb.truncate_foreign uses DEBUG_SYNC to cover some race-condition like scenarios. The test innodb-innodb.truncate does not use any synchronization. We add a redo log subformat to indicate backup-friendly format. MariaDB 10.4 will remove support for the old TRUNCATE logging, so crash-upgrade from old 10.2 or 10.3 to 10.4 will involve limitations. == Undo tablespace truncation == MySQL 5.7 implements undo tablespace truncation. It is only possible when innodb_undo_tablespaces is set to at least 2. The logging is implemented similar to the WL#6501 TRUNCATE, that is, using separate log files and a redo log checkpoint. We can simply implement undo tablespace truncation within a single mini-transaction that reinitializes the undo log tablespace file. Unfortunately, due to the redo log format of some operations, currently, the total redo log written by undo tablespace truncation will be more than the combined size of the truncated undo tablespace. It should be acceptable to have a little more than 1 megabyte of log in a single mini-transaction. This will be fixed in MDEV-17138 in MariaDB Server 10.4. recv_sys_t: Add truncated_undo_spaces[] to remember for which undo tablespaces a MLOG_FILE_CREATE2 record was seen. namespace undo: Remove some unnecessary declarations. fil_space_t::is_being_truncated: Document that this flag now only applies to undo tablespaces. Remove some references. fil_space_t::is_stopping(): Do not refer to is_being_truncated. This check is for tablespaces of tables. Potentially used tablespaces are never truncated any more. buf_dblwr_process(): Suppress the out-of-bounds warning for undo tablespaces. fil_truncate_log(): Write a MLOG_FILE_CREATE2 with a nonzero page number (new size of the tablespace in pages) to inform crash recovery that the undo tablespace size has been reduced. fil_op_write_log(): Relax assertions, so that MLOG_FILE_CREATE2 can be written for undo tablespaces (without .ibd file suffix) for a nonzero page number. os_file_truncate(): Add the parameter allow_shrink=false so that undo tablespaces can actually be shrunk using this function. fil_name_parse(): For undo tablespace truncation, buffer MLOG_FILE_CREATE2 in truncated_undo_spaces[]. recv_read_in_area(): Avoid reading pages for which no redo log records remain buffered, after recv_addr_trim() removed them. trx_rseg_header_create(): Add a FIXME comment that we could write much less redo log. trx_undo_truncate_tablespace(): Reinitialize the undo tablespace in a single mini-transaction, which will be flushed to the redo log before the file size is trimmed. recv_addr_trim(): Discard any redo logs for pages that were logged after the new end of a file, before the truncation LSN. If the rec_list becomes empty, reduce n_addrs. After removing any affected records, actually truncate the file. recv_apply_hashed_log_recs(): Invoke recv_addr_trim() right before applying any log records. The undo tablespace files must be open at this point. buf_flush_or_remove_pages(), buf_flush_dirty_pages(), buf_LRU_flush_or_remove_pages(): Add a parameter for specifying the number of the first page to flush or remove (default 0). trx_purge_initiate_truncate(): Remove the log checkpoints, the extra logging, and some unnecessary crash points. Merge the code from trx_undo_truncate_tablespace(). First, flush all to-be-discarded pages (beyond the new end of the file), then trim the space->size to make the page allocation deterministic. At the only remaining crash injection point, flush the redo log, so that the recovery can be tested.
7 years ago
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.
9 years ago
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.
9 years ago
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.
9 years ago
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.
9 years ago
MDEV-13564: Implement innodb_unsafe_truncate=ON for compatibility While MariaDB Server 10.2 is not really guaranteed to be compatible with Percona XtraBackup 2.4 (for example, the MySQL 5.7 undo log format change that could be present in XtraBackup, but was reverted from MariaDB in MDEV-12289), we do not want to disrupt users who have deployed xtrabackup and MariaDB Server 10.2 in their environments. With this change, MariaDB 10.2 will continue to use the backup-unsafe TRUNCATE TABLE code, so that neither the undo log nor the redo log formats will change in an incompatible way. Undo tablespace truncation will keep using the redo log only. Recovery or backup with old code will fail to shrink the undo tablespace files, but the contents will be recovered just fine. In the MariaDB Server 10.2 series only, we introduce the configuration parameter innodb_unsafe_truncate and make it ON by default. To allow MariaDB Backup (mariabackup) to work properly with TRUNCATE TABLE operations, use loose_innodb_unsafe_truncate=OFF. MariaDB Server 10.3.10 and later releases will always use the backup-safe TRUNCATE TABLE, and this parameter will not be added there. recv_recovery_rollback_active(): Skip row_mysql_drop_garbage_tables() unless innodb_unsafe_truncate=OFF. It is too unsafe to drop orphan tables if RENAME operations are not transactional within InnoDB. LOG_HEADER_FORMAT_10_3: Replaces LOG_HEADER_FORMAT_CURRENT. log_init(), log_group_file_header_flush(), srv_prepare_to_delete_redo_log_files(), innobase_start_or_create_for_mysql(): Choose the redo log format and subformat based on the value of innodb_unsafe_truncate.
7 years ago
MDEV-13564: Implement innodb_unsafe_truncate=ON for compatibility While MariaDB Server 10.2 is not really guaranteed to be compatible with Percona XtraBackup 2.4 (for example, the MySQL 5.7 undo log format change that could be present in XtraBackup, but was reverted from MariaDB in MDEV-12289), we do not want to disrupt users who have deployed xtrabackup and MariaDB Server 10.2 in their environments. With this change, MariaDB 10.2 will continue to use the backup-unsafe TRUNCATE TABLE code, so that neither the undo log nor the redo log formats will change in an incompatible way. Undo tablespace truncation will keep using the redo log only. Recovery or backup with old code will fail to shrink the undo tablespace files, but the contents will be recovered just fine. In the MariaDB Server 10.2 series only, we introduce the configuration parameter innodb_unsafe_truncate and make it ON by default. To allow MariaDB Backup (mariabackup) to work properly with TRUNCATE TABLE operations, use loose_innodb_unsafe_truncate=OFF. MariaDB Server 10.3.10 and later releases will always use the backup-safe TRUNCATE TABLE, and this parameter will not be added there. recv_recovery_rollback_active(): Skip row_mysql_drop_garbage_tables() unless innodb_unsafe_truncate=OFF. It is too unsafe to drop orphan tables if RENAME operations are not transactional within InnoDB. LOG_HEADER_FORMAT_10_3: Replaces LOG_HEADER_FORMAT_CURRENT. log_init(), log_group_file_header_flush(), srv_prepare_to_delete_redo_log_files(), innobase_start_or_create_for_mysql(): Choose the redo log format and subformat based on the value of innodb_unsafe_truncate.
7 years ago
MDEV-13564: Implement innodb_unsafe_truncate=ON for compatibility While MariaDB Server 10.2 is not really guaranteed to be compatible with Percona XtraBackup 2.4 (for example, the MySQL 5.7 undo log format change that could be present in XtraBackup, but was reverted from MariaDB in MDEV-12289), we do not want to disrupt users who have deployed xtrabackup and MariaDB Server 10.2 in their environments. With this change, MariaDB 10.2 will continue to use the backup-unsafe TRUNCATE TABLE code, so that neither the undo log nor the redo log formats will change in an incompatible way. Undo tablespace truncation will keep using the redo log only. Recovery or backup with old code will fail to shrink the undo tablespace files, but the contents will be recovered just fine. In the MariaDB Server 10.2 series only, we introduce the configuration parameter innodb_unsafe_truncate and make it ON by default. To allow MariaDB Backup (mariabackup) to work properly with TRUNCATE TABLE operations, use loose_innodb_unsafe_truncate=OFF. MariaDB Server 10.3.10 and later releases will always use the backup-safe TRUNCATE TABLE, and this parameter will not be added there. recv_recovery_rollback_active(): Skip row_mysql_drop_garbage_tables() unless innodb_unsafe_truncate=OFF. It is too unsafe to drop orphan tables if RENAME operations are not transactional within InnoDB. LOG_HEADER_FORMAT_10_3: Replaces LOG_HEADER_FORMAT_CURRENT. log_init(), log_group_file_header_flush(), srv_prepare_to_delete_redo_log_files(), innobase_start_or_create_for_mysql(): Choose the redo log format and subformat based on the value of innodb_unsafe_truncate.
7 years ago
MDEV-14717: Prevent crash-downgrade to earlier MariaDB 10.2 A crash-downgrade of a RENAME (or TRUNCATE or table-rebuilding ALTER TABLE or OPTIMIZE TABLE) operation to an earlier 10.2 version would trigger a debug assertion failure during rollback, in trx_roll_pop_top_rec_of_trx(). In a non-debug build, the TRX_UNDO_RENAME_TABLE record would be misinterpreted as an update_undo log record, and typically the file name would be interpreted as DB_TRX_ID,DB_ROLL_PTR,PRIMARY KEY. If a matching record would be found, row_undo_mod() would hit ut_error in switch (node->rec_type). Typically, ut_a(table2 == NULL) would fail when opening the table from SQL. Because of this, we prevent a crash-downgrade to earlier MariaDB 10.2 versions by changing the InnoDB redo log format identifier to the 10.3 identifier, and by introducing a subformat identifier so that 10.2 can continue to refuse crash-downgrade from 10.3 or later. After a clean shutdown, a downgrade to MariaDB 10.2.13 or later would still be possible thanks to MDEV-14909. A downgrade to older 10.2 versions is only possible after removing the log files (not recommended). LOG_HEADER_FORMAT_CURRENT: Change to 103 (originally the 10.3 format). log_group_t: Add subformat. For 10.2, we will use subformat 1, and will refuse crash recovery from any other subformat of the 10.3 format, that is, a genuine 10.3 redo log. recv_find_max_checkpoint(): Allow startup after clean shutdown from a future LOG_HEADER_FORMAT_10_4 (unencrypted only). We cannot handle the encrypted 10.4 redo log block format, which was introduced in MDEV-12041. Allow crash recovery from the original 10.2 format as well as the new format. In Mariabackup --backup, do not allow any startup from 10.3 or 10.4 redo logs. recv_recovery_from_checkpoint_start(): Skip redo log apply for clean 10.3 redo log, but not for the new 10.2 redo log (10.3 format, subformat 1). srv_prepare_to_delete_redo_log_files(): On format or subformat mismatch, set srv_log_file_size = 0, so that we will display the correct message. innobase_start_or_create_for_mysql(): Check for format or subformat mismatch. xtrabackup_backup_func(): Remove debug assertions that were made redundant by the code changes in recv_find_max_checkpoint().
7 years ago
MDEV-11782: Redefine the innodb_encrypt_log format Write only one encryption key to the checkpoint page. Use 4 bytes of nonce. Encrypt more of each redo log block, only skipping the 4-byte field LOG_BLOCK_HDR_NO which the initialization vector is derived from. Issue notes, not warning messages for rewriting the redo log files. recv_recovery_from_checkpoint_finish(): Do not generate any redo log, because we must avoid that before rewriting the redo log files, or otherwise a crash during a redo log rewrite (removing or adding encryption) may end up making the database unrecoverable. Instead, do these tasks in innobase_start_or_create_for_mysql(). Issue a firm "Missing MLOG_CHECKPOINT" error message. Remove some unreachable code and duplicated error messages for log corruption. LOG_HEADER_FORMAT_ENCRYPTED: A flag for identifying an encrypted redo log format. log_group_t::is_encrypted(), log_t::is_encrypted(): Determine if the redo log is in encrypted format. recv_find_max_checkpoint(): Interpret LOG_HEADER_FORMAT_ENCRYPTED. srv_prepare_to_delete_redo_log_files(): Display NOTE messages about adding or removing encryption. Do not issue warnings for redo log resizing any more. innobase_start_or_create_for_mysql(): Rebuild the redo logs also when the encryption changes. innodb_log_checksums_func_update(): Always use the CRC-32C checksum if innodb_encrypt_log. If needed, issue a warning that innodb_encrypt_log implies innodb_log_checksums. log_group_write_buf(): Compute the checksum on the encrypted block contents, so that transmission errors or incomplete blocks can be detected without decrypting. Rewrite most of the redo log encryption code. Only remember one encryption key at a time (but remember up to 5 when upgrading from the MariaDB 10.1 format.)
9 years ago
MDEV-13564: Implement innodb_unsafe_truncate=ON for compatibility While MariaDB Server 10.2 is not really guaranteed to be compatible with Percona XtraBackup 2.4 (for example, the MySQL 5.7 undo log format change that could be present in XtraBackup, but was reverted from MariaDB in MDEV-12289), we do not want to disrupt users who have deployed xtrabackup and MariaDB Server 10.2 in their environments. With this change, MariaDB 10.2 will continue to use the backup-unsafe TRUNCATE TABLE code, so that neither the undo log nor the redo log formats will change in an incompatible way. Undo tablespace truncation will keep using the redo log only. Recovery or backup with old code will fail to shrink the undo tablespace files, but the contents will be recovered just fine. In the MariaDB Server 10.2 series only, we introduce the configuration parameter innodb_unsafe_truncate and make it ON by default. To allow MariaDB Backup (mariabackup) to work properly with TRUNCATE TABLE operations, use loose_innodb_unsafe_truncate=OFF. MariaDB Server 10.3.10 and later releases will always use the backup-safe TRUNCATE TABLE, and this parameter will not be added there. recv_recovery_rollback_active(): Skip row_mysql_drop_garbage_tables() unless innodb_unsafe_truncate=OFF. It is too unsafe to drop orphan tables if RENAME operations are not transactional within InnoDB. LOG_HEADER_FORMAT_10_3: Replaces LOG_HEADER_FORMAT_CURRENT. log_init(), log_group_file_header_flush(), srv_prepare_to_delete_redo_log_files(), innobase_start_or_create_for_mysql(): Choose the redo log format and subformat based on the value of innodb_unsafe_truncate.
7 years ago
MDEV-11782: Redefine the innodb_encrypt_log format Write only one encryption key to the checkpoint page. Use 4 bytes of nonce. Encrypt more of each redo log block, only skipping the 4-byte field LOG_BLOCK_HDR_NO which the initialization vector is derived from. Issue notes, not warning messages for rewriting the redo log files. recv_recovery_from_checkpoint_finish(): Do not generate any redo log, because we must avoid that before rewriting the redo log files, or otherwise a crash during a redo log rewrite (removing or adding encryption) may end up making the database unrecoverable. Instead, do these tasks in innobase_start_or_create_for_mysql(). Issue a firm "Missing MLOG_CHECKPOINT" error message. Remove some unreachable code and duplicated error messages for log corruption. LOG_HEADER_FORMAT_ENCRYPTED: A flag for identifying an encrypted redo log format. log_group_t::is_encrypted(), log_t::is_encrypted(): Determine if the redo log is in encrypted format. recv_find_max_checkpoint(): Interpret LOG_HEADER_FORMAT_ENCRYPTED. srv_prepare_to_delete_redo_log_files(): Display NOTE messages about adding or removing encryption. Do not issue warnings for redo log resizing any more. innobase_start_or_create_for_mysql(): Rebuild the redo logs also when the encryption changes. innodb_log_checksums_func_update(): Always use the CRC-32C checksum if innodb_encrypt_log. If needed, issue a warning that innodb_encrypt_log implies innodb_log_checksums. log_group_write_buf(): Compute the checksum on the encrypted block contents, so that transmission errors or incomplete blocks can be detected without decrypting. Rewrite most of the redo log encryption code. Only remember one encryption key at a time (but remember up to 5 when upgrading from the MariaDB 10.1 format.)
9 years ago
MDEV-11782: Redefine the innodb_encrypt_log format Write only one encryption key to the checkpoint page. Use 4 bytes of nonce. Encrypt more of each redo log block, only skipping the 4-byte field LOG_BLOCK_HDR_NO which the initialization vector is derived from. Issue notes, not warning messages for rewriting the redo log files. recv_recovery_from_checkpoint_finish(): Do not generate any redo log, because we must avoid that before rewriting the redo log files, or otherwise a crash during a redo log rewrite (removing or adding encryption) may end up making the database unrecoverable. Instead, do these tasks in innobase_start_or_create_for_mysql(). Issue a firm "Missing MLOG_CHECKPOINT" error message. Remove some unreachable code and duplicated error messages for log corruption. LOG_HEADER_FORMAT_ENCRYPTED: A flag for identifying an encrypted redo log format. log_group_t::is_encrypted(), log_t::is_encrypted(): Determine if the redo log is in encrypted format. recv_find_max_checkpoint(): Interpret LOG_HEADER_FORMAT_ENCRYPTED. srv_prepare_to_delete_redo_log_files(): Display NOTE messages about adding or removing encryption. Do not issue warnings for redo log resizing any more. innobase_start_or_create_for_mysql(): Rebuild the redo logs also when the encryption changes. innodb_log_checksums_func_update(): Always use the CRC-32C checksum if innodb_encrypt_log. If needed, issue a warning that innodb_encrypt_log implies innodb_log_checksums. log_group_write_buf(): Compute the checksum on the encrypted block contents, so that transmission errors or incomplete blocks can be detected without decrypting. Rewrite most of the redo log encryption code. Only remember one encryption key at a time (but remember up to 5 when upgrading from the MariaDB 10.1 format.)
9 years ago
MDEV-11782: Redefine the innodb_encrypt_log format Write only one encryption key to the checkpoint page. Use 4 bytes of nonce. Encrypt more of each redo log block, only skipping the 4-byte field LOG_BLOCK_HDR_NO which the initialization vector is derived from. Issue notes, not warning messages for rewriting the redo log files. recv_recovery_from_checkpoint_finish(): Do not generate any redo log, because we must avoid that before rewriting the redo log files, or otherwise a crash during a redo log rewrite (removing or adding encryption) may end up making the database unrecoverable. Instead, do these tasks in innobase_start_or_create_for_mysql(). Issue a firm "Missing MLOG_CHECKPOINT" error message. Remove some unreachable code and duplicated error messages for log corruption. LOG_HEADER_FORMAT_ENCRYPTED: A flag for identifying an encrypted redo log format. log_group_t::is_encrypted(), log_t::is_encrypted(): Determine if the redo log is in encrypted format. recv_find_max_checkpoint(): Interpret LOG_HEADER_FORMAT_ENCRYPTED. srv_prepare_to_delete_redo_log_files(): Display NOTE messages about adding or removing encryption. Do not issue warnings for redo log resizing any more. innobase_start_or_create_for_mysql(): Rebuild the redo logs also when the encryption changes. innodb_log_checksums_func_update(): Always use the CRC-32C checksum if innodb_encrypt_log. If needed, issue a warning that innodb_encrypt_log implies innodb_log_checksums. log_group_write_buf(): Compute the checksum on the encrypted block contents, so that transmission errors or incomplete blocks can be detected without decrypting. Rewrite most of the redo log encryption code. Only remember one encryption key at a time (but remember up to 5 when upgrading from the MariaDB 10.1 format.)
9 years ago
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.
9 years ago
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).
9 years ago
Shut down InnoDB after aborted startup. This fixes memory leaks in tests that cause InnoDB startup to fail. buf_pool_free_instance(): Also free buf_pool->flush_rbt, which would normally be freed when crash recovery finishes. fil_node_close_file(), fil_space_free_low(), fil_close_all_files(): Relax some debug assertions to tolerate !srv_was_started. innodb_shutdown(): Renamed from innobase_shutdown_for_mysql(). Changed the return type to void. Do not assume that all subsystems were started. que_init(), que_close(): Remove (empty functions). srv_init(), srv_general_init(): Remove as global functions. srv_free(): Allow srv_sys=NULL. srv_get_active_thread_type(): Only return SRV_PURGE if purge really is running. srv_shutdown_all_bg_threads(): Do not reset srv_start_state. It will be needed by innodb_shutdown(). innobase_start_or_create_for_mysql(): Always call srv_boot() so that innodb_shutdown() can assume that it was called. Make more subsystems dependent on SRV_START_STATE_STAT. srv_shutdown_bg_undo_sources(): Require SRV_START_STATE_STAT. trx_sys_close(): Do not assume purge_sys!=NULL. Do not call buf_dblwr_free(), because the doublewrite buffer can exist while the transaction system does not. logs_empty_and_mark_files_at_shutdown(): Do a faster shutdown if !srv_was_started. recv_sys_close(): Invoke dblwr.pages.clear() which would normally be invoked by buf_dblwr_process(). recv_recovery_from_checkpoint_start(): Always release log_sys->mutex. row_mysql_close(): Allow the subsystem not to exist.
9 years ago
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.
9 years ago
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.
9 years ago
9 years ago
10 years ago
12 years ago
11 years ago
Shut down InnoDB after aborted startup. This fixes memory leaks in tests that cause InnoDB startup to fail. buf_pool_free_instance(): Also free buf_pool->flush_rbt, which would normally be freed when crash recovery finishes. fil_node_close_file(), fil_space_free_low(), fil_close_all_files(): Relax some debug assertions to tolerate !srv_was_started. innodb_shutdown(): Renamed from innobase_shutdown_for_mysql(). Changed the return type to void. Do not assume that all subsystems were started. que_init(), que_close(): Remove (empty functions). srv_init(), srv_general_init(): Remove as global functions. srv_free(): Allow srv_sys=NULL. srv_get_active_thread_type(): Only return SRV_PURGE if purge really is running. srv_shutdown_all_bg_threads(): Do not reset srv_start_state. It will be needed by innodb_shutdown(). innobase_start_or_create_for_mysql(): Always call srv_boot() so that innodb_shutdown() can assume that it was called. Make more subsystems dependent on SRV_START_STATE_STAT. srv_shutdown_bg_undo_sources(): Require SRV_START_STATE_STAT. trx_sys_close(): Do not assume purge_sys!=NULL. Do not call buf_dblwr_free(), because the doublewrite buffer can exist while the transaction system does not. logs_empty_and_mark_files_at_shutdown(): Do a faster shutdown if !srv_was_started. recv_sys_close(): Invoke dblwr.pages.clear() which would normally be invoked by buf_dblwr_process(). recv_recovery_from_checkpoint_start(): Always release log_sys->mutex. row_mysql_close(): Allow the subsystem not to exist.
9 years ago
12 years ago
12 years ago
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.
9 years ago
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.
9 years ago
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.
9 years ago
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.
9 years ago
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.
9 years ago
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.
9 years ago
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.
9 years ago
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.
9 years ago
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.
9 years ago
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.
9 years ago
MDEV-12699 Improve crash recovery of corrupted data pages InnoDB crash recovery used to read every data page for which redo log exists. This is unnecessary for those pages that are initialized by the redo log. If a newly created page is corrupted, recovery could unnecessarily fail. It would suffice to reinitialize the page based on the redo log records. To add insult to injury, InnoDB crash recovery could hang if it encountered a corrupted page. We will fix also that problem. InnoDB would normally refuse to start up if it encounters a corrupted page on recovery, but that can be overridden by setting innodb_force_recovery=1. Data pages are completely initialized by the records MLOG_INIT_FILE_PAGE2 and MLOG_ZIP_PAGE_COMPRESS. MariaDB 10.4 additionally recognizes MLOG_INIT_FREE_PAGE, which notifies that a page has been freed and its contents can be discarded (filled with zeroes). The record MLOG_INDEX_LOAD notifies that redo logging has been re-enabled after being disabled. We can avoid loading the page if all buffered redo log records predate the MLOG_INDEX_LOAD record. For the internal tables of FULLTEXT INDEX, no MLOG_INDEX_LOAD records were written before commit aa3f7a107ce3a9a7f80daf3cadd442a61c5493ab. Hence, we will skip these optimizations for tables whose name starts with FTS_. This is joint work with Thirunarayanan Balathandayuthapani. fil_space_t::enable_lsn, file_name_t::enable_lsn: The LSN of the latest recovered MLOG_INDEX_LOAD record for a tablespace. mlog_init: Page initialization operations discovered during redo log scanning. FIXME: This really belongs in recv_sys->addr_hash, and should be removed in MDEV-19176. recv_addr_state: Add the new state RECV_WILL_NOT_READ to indicate that according to mlog_init, the page will be initialized based on redo log record contents. recv_add_to_hash_table(): Set the RECV_WILL_NOT_READ state if appropriate. For now, we do not treat MLOG_ZIP_PAGE_COMPRESS as page initialization. This works around bugs in the crash recovery of ROW_FORMAT=COMPRESSED tables. recv_mark_log_index_load(): Process a MLOG_INDEX_LOAD record by resetting the state to RECV_NOT_PROCESSED and by updating the fil_name_t::enable_lsn. recv_init_crash_recovery_spaces(): Copy fil_name_t::enable_lsn to fil_space_t::enable_lsn. recv_recover_page(): Add the parameter init_lsn, to ignore any log records that precede the page initialization. Add DBUG output about skipped operations. buf_page_create(): Initialize FIL_PAGE_LSN, so that recv_recover_page() will not wrongly skip applying the page-initialization record due to the field containing some newer LSN as a leftover from a different page. Do not invoke ibuf_merge_or_delete_for_page() during crash recovery. recv_apply_hashed_log_recs(): Remove some unnecessary lookups. Note if a corrupted page was found during recovery. After invoking buf_page_create(), do invoke ibuf_merge_or_delete_for_page() via mlog_init.ibuf_merge() in the last recovery batch. ibuf_merge_or_delete_for_page(): Relax a debug assertion. innobase_start_or_create_for_mysql(): Abort startup if a corrupted page was found during recovery. Corrupted pages will not be flagged if innodb_force_recovery is set. However, the recv_sys->found_corrupt_fs flag can be set regardless of innodb_force_recovery if file names are found to be incorrect (for example, multiple files with the same tablespace ID).
7 years ago
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.
9 years ago
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.
9 years ago
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.
9 years ago
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.
9 years ago
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.
9 years ago
MDEV-11782: Redefine the innodb_encrypt_log format Write only one encryption key to the checkpoint page. Use 4 bytes of nonce. Encrypt more of each redo log block, only skipping the 4-byte field LOG_BLOCK_HDR_NO which the initialization vector is derived from. Issue notes, not warning messages for rewriting the redo log files. recv_recovery_from_checkpoint_finish(): Do not generate any redo log, because we must avoid that before rewriting the redo log files, or otherwise a crash during a redo log rewrite (removing or adding encryption) may end up making the database unrecoverable. Instead, do these tasks in innobase_start_or_create_for_mysql(). Issue a firm "Missing MLOG_CHECKPOINT" error message. Remove some unreachable code and duplicated error messages for log corruption. LOG_HEADER_FORMAT_ENCRYPTED: A flag for identifying an encrypted redo log format. log_group_t::is_encrypted(), log_t::is_encrypted(): Determine if the redo log is in encrypted format. recv_find_max_checkpoint(): Interpret LOG_HEADER_FORMAT_ENCRYPTED. srv_prepare_to_delete_redo_log_files(): Display NOTE messages about adding or removing encryption. Do not issue warnings for redo log resizing any more. innobase_start_or_create_for_mysql(): Rebuild the redo logs also when the encryption changes. innodb_log_checksums_func_update(): Always use the CRC-32C checksum if innodb_encrypt_log. If needed, issue a warning that innodb_encrypt_log implies innodb_log_checksums. log_group_write_buf(): Compute the checksum on the encrypted block contents, so that transmission errors or incomplete blocks can be detected without decrypting. Rewrite most of the redo log encryption code. Only remember one encryption key at a time (but remember up to 5 when upgrading from the MariaDB 10.1 format.)
9 years ago
MDEV-14717: Prevent crash-downgrade to earlier MariaDB 10.2 A crash-downgrade of a RENAME (or TRUNCATE or table-rebuilding ALTER TABLE or OPTIMIZE TABLE) operation to an earlier 10.2 version would trigger a debug assertion failure during rollback, in trx_roll_pop_top_rec_of_trx(). In a non-debug build, the TRX_UNDO_RENAME_TABLE record would be misinterpreted as an update_undo log record, and typically the file name would be interpreted as DB_TRX_ID,DB_ROLL_PTR,PRIMARY KEY. If a matching record would be found, row_undo_mod() would hit ut_error in switch (node->rec_type). Typically, ut_a(table2 == NULL) would fail when opening the table from SQL. Because of this, we prevent a crash-downgrade to earlier MariaDB 10.2 versions by changing the InnoDB redo log format identifier to the 10.3 identifier, and by introducing a subformat identifier so that 10.2 can continue to refuse crash-downgrade from 10.3 or later. After a clean shutdown, a downgrade to MariaDB 10.2.13 or later would still be possible thanks to MDEV-14909. A downgrade to older 10.2 versions is only possible after removing the log files (not recommended). LOG_HEADER_FORMAT_CURRENT: Change to 103 (originally the 10.3 format). log_group_t: Add subformat. For 10.2, we will use subformat 1, and will refuse crash recovery from any other subformat of the 10.3 format, that is, a genuine 10.3 redo log. recv_find_max_checkpoint(): Allow startup after clean shutdown from a future LOG_HEADER_FORMAT_10_4 (unencrypted only). We cannot handle the encrypted 10.4 redo log block format, which was introduced in MDEV-12041. Allow crash recovery from the original 10.2 format as well as the new format. In Mariabackup --backup, do not allow any startup from 10.3 or 10.4 redo logs. recv_recovery_from_checkpoint_start(): Skip redo log apply for clean 10.3 redo log, but not for the new 10.2 redo log (10.3 format, subformat 1). srv_prepare_to_delete_redo_log_files(): On format or subformat mismatch, set srv_log_file_size = 0, so that we will display the correct message. innobase_start_or_create_for_mysql(): Check for format or subformat mismatch. xtrabackup_backup_func(): Remove debug assertions that were made redundant by the code changes in recv_find_max_checkpoint().
7 years ago
MDEV-13564: Implement innodb_unsafe_truncate=ON for compatibility While MariaDB Server 10.2 is not really guaranteed to be compatible with Percona XtraBackup 2.4 (for example, the MySQL 5.7 undo log format change that could be present in XtraBackup, but was reverted from MariaDB in MDEV-12289), we do not want to disrupt users who have deployed xtrabackup and MariaDB Server 10.2 in their environments. With this change, MariaDB 10.2 will continue to use the backup-unsafe TRUNCATE TABLE code, so that neither the undo log nor the redo log formats will change in an incompatible way. Undo tablespace truncation will keep using the redo log only. Recovery or backup with old code will fail to shrink the undo tablespace files, but the contents will be recovered just fine. In the MariaDB Server 10.2 series only, we introduce the configuration parameter innodb_unsafe_truncate and make it ON by default. To allow MariaDB Backup (mariabackup) to work properly with TRUNCATE TABLE operations, use loose_innodb_unsafe_truncate=OFF. MariaDB Server 10.3.10 and later releases will always use the backup-safe TRUNCATE TABLE, and this parameter will not be added there. recv_recovery_rollback_active(): Skip row_mysql_drop_garbage_tables() unless innodb_unsafe_truncate=OFF. It is too unsafe to drop orphan tables if RENAME operations are not transactional within InnoDB. LOG_HEADER_FORMAT_10_3: Replaces LOG_HEADER_FORMAT_CURRENT. log_init(), log_group_file_header_flush(), srv_prepare_to_delete_redo_log_files(), innobase_start_or_create_for_mysql(): Choose the redo log format and subformat based on the value of innodb_unsafe_truncate.
7 years ago
MDEV-13564: Implement innodb_unsafe_truncate=ON for compatibility While MariaDB Server 10.2 is not really guaranteed to be compatible with Percona XtraBackup 2.4 (for example, the MySQL 5.7 undo log format change that could be present in XtraBackup, but was reverted from MariaDB in MDEV-12289), we do not want to disrupt users who have deployed xtrabackup and MariaDB Server 10.2 in their environments. With this change, MariaDB 10.2 will continue to use the backup-unsafe TRUNCATE TABLE code, so that neither the undo log nor the redo log formats will change in an incompatible way. Undo tablespace truncation will keep using the redo log only. Recovery or backup with old code will fail to shrink the undo tablespace files, but the contents will be recovered just fine. In the MariaDB Server 10.2 series only, we introduce the configuration parameter innodb_unsafe_truncate and make it ON by default. To allow MariaDB Backup (mariabackup) to work properly with TRUNCATE TABLE operations, use loose_innodb_unsafe_truncate=OFF. MariaDB Server 10.3.10 and later releases will always use the backup-safe TRUNCATE TABLE, and this parameter will not be added there. recv_recovery_rollback_active(): Skip row_mysql_drop_garbage_tables() unless innodb_unsafe_truncate=OFF. It is too unsafe to drop orphan tables if RENAME operations are not transactional within InnoDB. LOG_HEADER_FORMAT_10_3: Replaces LOG_HEADER_FORMAT_CURRENT. log_init(), log_group_file_header_flush(), srv_prepare_to_delete_redo_log_files(), innobase_start_or_create_for_mysql(): Choose the redo log format and subformat based on the value of innodb_unsafe_truncate.
7 years ago
MDEV-13564: Implement innodb_unsafe_truncate=ON for compatibility While MariaDB Server 10.2 is not really guaranteed to be compatible with Percona XtraBackup 2.4 (for example, the MySQL 5.7 undo log format change that could be present in XtraBackup, but was reverted from MariaDB in MDEV-12289), we do not want to disrupt users who have deployed xtrabackup and MariaDB Server 10.2 in their environments. With this change, MariaDB 10.2 will continue to use the backup-unsafe TRUNCATE TABLE code, so that neither the undo log nor the redo log formats will change in an incompatible way. Undo tablespace truncation will keep using the redo log only. Recovery or backup with old code will fail to shrink the undo tablespace files, but the contents will be recovered just fine. In the MariaDB Server 10.2 series only, we introduce the configuration parameter innodb_unsafe_truncate and make it ON by default. To allow MariaDB Backup (mariabackup) to work properly with TRUNCATE TABLE operations, use loose_innodb_unsafe_truncate=OFF. MariaDB Server 10.3.10 and later releases will always use the backup-safe TRUNCATE TABLE, and this parameter will not be added there. recv_recovery_rollback_active(): Skip row_mysql_drop_garbage_tables() unless innodb_unsafe_truncate=OFF. It is too unsafe to drop orphan tables if RENAME operations are not transactional within InnoDB. LOG_HEADER_FORMAT_10_3: Replaces LOG_HEADER_FORMAT_CURRENT. log_init(), log_group_file_header_flush(), srv_prepare_to_delete_redo_log_files(), innobase_start_or_create_for_mysql(): Choose the redo log format and subformat based on the value of innodb_unsafe_truncate.
7 years ago
MDEV-13564: Implement innodb_unsafe_truncate=ON for compatibility While MariaDB Server 10.2 is not really guaranteed to be compatible with Percona XtraBackup 2.4 (for example, the MySQL 5.7 undo log format change that could be present in XtraBackup, but was reverted from MariaDB in MDEV-12289), we do not want to disrupt users who have deployed xtrabackup and MariaDB Server 10.2 in their environments. With this change, MariaDB 10.2 will continue to use the backup-unsafe TRUNCATE TABLE code, so that neither the undo log nor the redo log formats will change in an incompatible way. Undo tablespace truncation will keep using the redo log only. Recovery or backup with old code will fail to shrink the undo tablespace files, but the contents will be recovered just fine. In the MariaDB Server 10.2 series only, we introduce the configuration parameter innodb_unsafe_truncate and make it ON by default. To allow MariaDB Backup (mariabackup) to work properly with TRUNCATE TABLE operations, use loose_innodb_unsafe_truncate=OFF. MariaDB Server 10.3.10 and later releases will always use the backup-safe TRUNCATE TABLE, and this parameter will not be added there. recv_recovery_rollback_active(): Skip row_mysql_drop_garbage_tables() unless innodb_unsafe_truncate=OFF. It is too unsafe to drop orphan tables if RENAME operations are not transactional within InnoDB. LOG_HEADER_FORMAT_10_3: Replaces LOG_HEADER_FORMAT_CURRENT. log_init(), log_group_file_header_flush(), srv_prepare_to_delete_redo_log_files(), innobase_start_or_create_for_mysql(): Choose the redo log format and subformat based on the value of innodb_unsafe_truncate.
7 years ago
MDEV-14717: Prevent crash-downgrade to earlier MariaDB 10.2 A crash-downgrade of a RENAME (or TRUNCATE or table-rebuilding ALTER TABLE or OPTIMIZE TABLE) operation to an earlier 10.2 version would trigger a debug assertion failure during rollback, in trx_roll_pop_top_rec_of_trx(). In a non-debug build, the TRX_UNDO_RENAME_TABLE record would be misinterpreted as an update_undo log record, and typically the file name would be interpreted as DB_TRX_ID,DB_ROLL_PTR,PRIMARY KEY. If a matching record would be found, row_undo_mod() would hit ut_error in switch (node->rec_type). Typically, ut_a(table2 == NULL) would fail when opening the table from SQL. Because of this, we prevent a crash-downgrade to earlier MariaDB 10.2 versions by changing the InnoDB redo log format identifier to the 10.3 identifier, and by introducing a subformat identifier so that 10.2 can continue to refuse crash-downgrade from 10.3 or later. After a clean shutdown, a downgrade to MariaDB 10.2.13 or later would still be possible thanks to MDEV-14909. A downgrade to older 10.2 versions is only possible after removing the log files (not recommended). LOG_HEADER_FORMAT_CURRENT: Change to 103 (originally the 10.3 format). log_group_t: Add subformat. For 10.2, we will use subformat 1, and will refuse crash recovery from any other subformat of the 10.3 format, that is, a genuine 10.3 redo log. recv_find_max_checkpoint(): Allow startup after clean shutdown from a future LOG_HEADER_FORMAT_10_4 (unencrypted only). We cannot handle the encrypted 10.4 redo log block format, which was introduced in MDEV-12041. Allow crash recovery from the original 10.2 format as well as the new format. In Mariabackup --backup, do not allow any startup from 10.3 or 10.4 redo logs. recv_recovery_from_checkpoint_start(): Skip redo log apply for clean 10.3 redo log, but not for the new 10.2 redo log (10.3 format, subformat 1). srv_prepare_to_delete_redo_log_files(): On format or subformat mismatch, set srv_log_file_size = 0, so that we will display the correct message. innobase_start_or_create_for_mysql(): Check for format or subformat mismatch. xtrabackup_backup_func(): Remove debug assertions that were made redundant by the code changes in recv_find_max_checkpoint().
7 years ago
MDEV-11782: Redefine the innodb_encrypt_log format Write only one encryption key to the checkpoint page. Use 4 bytes of nonce. Encrypt more of each redo log block, only skipping the 4-byte field LOG_BLOCK_HDR_NO which the initialization vector is derived from. Issue notes, not warning messages for rewriting the redo log files. recv_recovery_from_checkpoint_finish(): Do not generate any redo log, because we must avoid that before rewriting the redo log files, or otherwise a crash during a redo log rewrite (removing or adding encryption) may end up making the database unrecoverable. Instead, do these tasks in innobase_start_or_create_for_mysql(). Issue a firm "Missing MLOG_CHECKPOINT" error message. Remove some unreachable code and duplicated error messages for log corruption. LOG_HEADER_FORMAT_ENCRYPTED: A flag for identifying an encrypted redo log format. log_group_t::is_encrypted(), log_t::is_encrypted(): Determine if the redo log is in encrypted format. recv_find_max_checkpoint(): Interpret LOG_HEADER_FORMAT_ENCRYPTED. srv_prepare_to_delete_redo_log_files(): Display NOTE messages about adding or removing encryption. Do not issue warnings for redo log resizing any more. innobase_start_or_create_for_mysql(): Rebuild the redo logs also when the encryption changes. innodb_log_checksums_func_update(): Always use the CRC-32C checksum if innodb_encrypt_log. If needed, issue a warning that innodb_encrypt_log implies innodb_log_checksums. log_group_write_buf(): Compute the checksum on the encrypted block contents, so that transmission errors or incomplete blocks can be detected without decrypting. Rewrite most of the redo log encryption code. Only remember one encryption key at a time (but remember up to 5 when upgrading from the MariaDB 10.1 format.)
9 years ago
MDEV-11782: Redefine the innodb_encrypt_log format Write only one encryption key to the checkpoint page. Use 4 bytes of nonce. Encrypt more of each redo log block, only skipping the 4-byte field LOG_BLOCK_HDR_NO which the initialization vector is derived from. Issue notes, not warning messages for rewriting the redo log files. recv_recovery_from_checkpoint_finish(): Do not generate any redo log, because we must avoid that before rewriting the redo log files, or otherwise a crash during a redo log rewrite (removing or adding encryption) may end up making the database unrecoverable. Instead, do these tasks in innobase_start_or_create_for_mysql(). Issue a firm "Missing MLOG_CHECKPOINT" error message. Remove some unreachable code and duplicated error messages for log corruption. LOG_HEADER_FORMAT_ENCRYPTED: A flag for identifying an encrypted redo log format. log_group_t::is_encrypted(), log_t::is_encrypted(): Determine if the redo log is in encrypted format. recv_find_max_checkpoint(): Interpret LOG_HEADER_FORMAT_ENCRYPTED. srv_prepare_to_delete_redo_log_files(): Display NOTE messages about adding or removing encryption. Do not issue warnings for redo log resizing any more. innobase_start_or_create_for_mysql(): Rebuild the redo logs also when the encryption changes. innodb_log_checksums_func_update(): Always use the CRC-32C checksum if innodb_encrypt_log. If needed, issue a warning that innodb_encrypt_log implies innodb_log_checksums. log_group_write_buf(): Compute the checksum on the encrypted block contents, so that transmission errors or incomplete blocks can be detected without decrypting. Rewrite most of the redo log encryption code. Only remember one encryption key at a time (but remember up to 5 when upgrading from the MariaDB 10.1 format.)
9 years ago
MDEV-11782: Redefine the innodb_encrypt_log format Write only one encryption key to the checkpoint page. Use 4 bytes of nonce. Encrypt more of each redo log block, only skipping the 4-byte field LOG_BLOCK_HDR_NO which the initialization vector is derived from. Issue notes, not warning messages for rewriting the redo log files. recv_recovery_from_checkpoint_finish(): Do not generate any redo log, because we must avoid that before rewriting the redo log files, or otherwise a crash during a redo log rewrite (removing or adding encryption) may end up making the database unrecoverable. Instead, do these tasks in innobase_start_or_create_for_mysql(). Issue a firm "Missing MLOG_CHECKPOINT" error message. Remove some unreachable code and duplicated error messages for log corruption. LOG_HEADER_FORMAT_ENCRYPTED: A flag for identifying an encrypted redo log format. log_group_t::is_encrypted(), log_t::is_encrypted(): Determine if the redo log is in encrypted format. recv_find_max_checkpoint(): Interpret LOG_HEADER_FORMAT_ENCRYPTED. srv_prepare_to_delete_redo_log_files(): Display NOTE messages about adding or removing encryption. Do not issue warnings for redo log resizing any more. innobase_start_or_create_for_mysql(): Rebuild the redo logs also when the encryption changes. innodb_log_checksums_func_update(): Always use the CRC-32C checksum if innodb_encrypt_log. If needed, issue a warning that innodb_encrypt_log implies innodb_log_checksums. log_group_write_buf(): Compute the checksum on the encrypted block contents, so that transmission errors or incomplete blocks can be detected without decrypting. Rewrite most of the redo log encryption code. Only remember one encryption key at a time (but remember up to 5 when upgrading from the MariaDB 10.1 format.)
9 years ago
MDEV-11782: Redefine the innodb_encrypt_log format Write only one encryption key to the checkpoint page. Use 4 bytes of nonce. Encrypt more of each redo log block, only skipping the 4-byte field LOG_BLOCK_HDR_NO which the initialization vector is derived from. Issue notes, not warning messages for rewriting the redo log files. recv_recovery_from_checkpoint_finish(): Do not generate any redo log, because we must avoid that before rewriting the redo log files, or otherwise a crash during a redo log rewrite (removing or adding encryption) may end up making the database unrecoverable. Instead, do these tasks in innobase_start_or_create_for_mysql(). Issue a firm "Missing MLOG_CHECKPOINT" error message. Remove some unreachable code and duplicated error messages for log corruption. LOG_HEADER_FORMAT_ENCRYPTED: A flag for identifying an encrypted redo log format. log_group_t::is_encrypted(), log_t::is_encrypted(): Determine if the redo log is in encrypted format. recv_find_max_checkpoint(): Interpret LOG_HEADER_FORMAT_ENCRYPTED. srv_prepare_to_delete_redo_log_files(): Display NOTE messages about adding or removing encryption. Do not issue warnings for redo log resizing any more. innobase_start_or_create_for_mysql(): Rebuild the redo logs also when the encryption changes. innodb_log_checksums_func_update(): Always use the CRC-32C checksum if innodb_encrypt_log. If needed, issue a warning that innodb_encrypt_log implies innodb_log_checksums. log_group_write_buf(): Compute the checksum on the encrypted block contents, so that transmission errors or incomplete blocks can be detected without decrypting. Rewrite most of the redo log encryption code. Only remember one encryption key at a time (but remember up to 5 when upgrading from the MariaDB 10.1 format.)
9 years ago
MDEV-11782: Redefine the innodb_encrypt_log format Write only one encryption key to the checkpoint page. Use 4 bytes of nonce. Encrypt more of each redo log block, only skipping the 4-byte field LOG_BLOCK_HDR_NO which the initialization vector is derived from. Issue notes, not warning messages for rewriting the redo log files. recv_recovery_from_checkpoint_finish(): Do not generate any redo log, because we must avoid that before rewriting the redo log files, or otherwise a crash during a redo log rewrite (removing or adding encryption) may end up making the database unrecoverable. Instead, do these tasks in innobase_start_or_create_for_mysql(). Issue a firm "Missing MLOG_CHECKPOINT" error message. Remove some unreachable code and duplicated error messages for log corruption. LOG_HEADER_FORMAT_ENCRYPTED: A flag for identifying an encrypted redo log format. log_group_t::is_encrypted(), log_t::is_encrypted(): Determine if the redo log is in encrypted format. recv_find_max_checkpoint(): Interpret LOG_HEADER_FORMAT_ENCRYPTED. srv_prepare_to_delete_redo_log_files(): Display NOTE messages about adding or removing encryption. Do not issue warnings for redo log resizing any more. innobase_start_or_create_for_mysql(): Rebuild the redo logs also when the encryption changes. innodb_log_checksums_func_update(): Always use the CRC-32C checksum if innodb_encrypt_log. If needed, issue a warning that innodb_encrypt_log implies innodb_log_checksums. log_group_write_buf(): Compute the checksum on the encrypted block contents, so that transmission errors or incomplete blocks can be detected without decrypting. Rewrite most of the redo log encryption code. Only remember one encryption key at a time (but remember up to 5 when upgrading from the MariaDB 10.1 format.)
9 years ago
MDEV-11782: Redefine the innodb_encrypt_log format Write only one encryption key to the checkpoint page. Use 4 bytes of nonce. Encrypt more of each redo log block, only skipping the 4-byte field LOG_BLOCK_HDR_NO which the initialization vector is derived from. Issue notes, not warning messages for rewriting the redo log files. recv_recovery_from_checkpoint_finish(): Do not generate any redo log, because we must avoid that before rewriting the redo log files, or otherwise a crash during a redo log rewrite (removing or adding encryption) may end up making the database unrecoverable. Instead, do these tasks in innobase_start_or_create_for_mysql(). Issue a firm "Missing MLOG_CHECKPOINT" error message. Remove some unreachable code and duplicated error messages for log corruption. LOG_HEADER_FORMAT_ENCRYPTED: A flag for identifying an encrypted redo log format. log_group_t::is_encrypted(), log_t::is_encrypted(): Determine if the redo log is in encrypted format. recv_find_max_checkpoint(): Interpret LOG_HEADER_FORMAT_ENCRYPTED. srv_prepare_to_delete_redo_log_files(): Display NOTE messages about adding or removing encryption. Do not issue warnings for redo log resizing any more. innobase_start_or_create_for_mysql(): Rebuild the redo logs also when the encryption changes. innodb_log_checksums_func_update(): Always use the CRC-32C checksum if innodb_encrypt_log. If needed, issue a warning that innodb_encrypt_log implies innodb_log_checksums. log_group_write_buf(): Compute the checksum on the encrypted block contents, so that transmission errors or incomplete blocks can be detected without decrypting. Rewrite most of the redo log encryption code. Only remember one encryption key at a time (but remember up to 5 when upgrading from the MariaDB 10.1 format.)
9 years ago
MDEV-11782: Redefine the innodb_encrypt_log format Write only one encryption key to the checkpoint page. Use 4 bytes of nonce. Encrypt more of each redo log block, only skipping the 4-byte field LOG_BLOCK_HDR_NO which the initialization vector is derived from. Issue notes, not warning messages for rewriting the redo log files. recv_recovery_from_checkpoint_finish(): Do not generate any redo log, because we must avoid that before rewriting the redo log files, or otherwise a crash during a redo log rewrite (removing or adding encryption) may end up making the database unrecoverable. Instead, do these tasks in innobase_start_or_create_for_mysql(). Issue a firm "Missing MLOG_CHECKPOINT" error message. Remove some unreachable code and duplicated error messages for log corruption. LOG_HEADER_FORMAT_ENCRYPTED: A flag for identifying an encrypted redo log format. log_group_t::is_encrypted(), log_t::is_encrypted(): Determine if the redo log is in encrypted format. recv_find_max_checkpoint(): Interpret LOG_HEADER_FORMAT_ENCRYPTED. srv_prepare_to_delete_redo_log_files(): Display NOTE messages about adding or removing encryption. Do not issue warnings for redo log resizing any more. innobase_start_or_create_for_mysql(): Rebuild the redo logs also when the encryption changes. innodb_log_checksums_func_update(): Always use the CRC-32C checksum if innodb_encrypt_log. If needed, issue a warning that innodb_encrypt_log implies innodb_log_checksums. log_group_write_buf(): Compute the checksum on the encrypted block contents, so that transmission errors or incomplete blocks can be detected without decrypting. Rewrite most of the redo log encryption code. Only remember one encryption key at a time (but remember up to 5 when upgrading from the MariaDB 10.1 format.)
9 years ago
MDEV-11782: Redefine the innodb_encrypt_log format Write only one encryption key to the checkpoint page. Use 4 bytes of nonce. Encrypt more of each redo log block, only skipping the 4-byte field LOG_BLOCK_HDR_NO which the initialization vector is derived from. Issue notes, not warning messages for rewriting the redo log files. recv_recovery_from_checkpoint_finish(): Do not generate any redo log, because we must avoid that before rewriting the redo log files, or otherwise a crash during a redo log rewrite (removing or adding encryption) may end up making the database unrecoverable. Instead, do these tasks in innobase_start_or_create_for_mysql(). Issue a firm "Missing MLOG_CHECKPOINT" error message. Remove some unreachable code and duplicated error messages for log corruption. LOG_HEADER_FORMAT_ENCRYPTED: A flag for identifying an encrypted redo log format. log_group_t::is_encrypted(), log_t::is_encrypted(): Determine if the redo log is in encrypted format. recv_find_max_checkpoint(): Interpret LOG_HEADER_FORMAT_ENCRYPTED. srv_prepare_to_delete_redo_log_files(): Display NOTE messages about adding or removing encryption. Do not issue warnings for redo log resizing any more. innobase_start_or_create_for_mysql(): Rebuild the redo logs also when the encryption changes. innodb_log_checksums_func_update(): Always use the CRC-32C checksum if innodb_encrypt_log. If needed, issue a warning that innodb_encrypt_log implies innodb_log_checksums. log_group_write_buf(): Compute the checksum on the encrypted block contents, so that transmission errors or incomplete blocks can be detected without decrypting. Rewrite most of the redo log encryption code. Only remember one encryption key at a time (but remember up to 5 when upgrading from the MariaDB 10.1 format.)
9 years ago
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).
9 years ago
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.
9 years ago
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.
9 years ago
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.
9 years ago
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.
9 years ago
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.
9 years ago
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).
9 years ago
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).
9 years ago
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.
9 years ago
Shut down InnoDB after aborted startup. This fixes memory leaks in tests that cause InnoDB startup to fail. buf_pool_free_instance(): Also free buf_pool->flush_rbt, which would normally be freed when crash recovery finishes. fil_node_close_file(), fil_space_free_low(), fil_close_all_files(): Relax some debug assertions to tolerate !srv_was_started. innodb_shutdown(): Renamed from innobase_shutdown_for_mysql(). Changed the return type to void. Do not assume that all subsystems were started. que_init(), que_close(): Remove (empty functions). srv_init(), srv_general_init(): Remove as global functions. srv_free(): Allow srv_sys=NULL. srv_get_active_thread_type(): Only return SRV_PURGE if purge really is running. srv_shutdown_all_bg_threads(): Do not reset srv_start_state. It will be needed by innodb_shutdown(). innobase_start_or_create_for_mysql(): Always call srv_boot() so that innodb_shutdown() can assume that it was called. Make more subsystems dependent on SRV_START_STATE_STAT. srv_shutdown_bg_undo_sources(): Require SRV_START_STATE_STAT. trx_sys_close(): Do not assume purge_sys!=NULL. Do not call buf_dblwr_free(), because the doublewrite buffer can exist while the transaction system does not. logs_empty_and_mark_files_at_shutdown(): Do a faster shutdown if !srv_was_started. recv_sys_close(): Invoke dblwr.pages.clear() which would normally be invoked by buf_dblwr_process(). recv_recovery_from_checkpoint_start(): Always release log_sys->mutex. row_mysql_close(): Allow the subsystem not to exist.
9 years ago
Shut down InnoDB after aborted startup. This fixes memory leaks in tests that cause InnoDB startup to fail. buf_pool_free_instance(): Also free buf_pool->flush_rbt, which would normally be freed when crash recovery finishes. fil_node_close_file(), fil_space_free_low(), fil_close_all_files(): Relax some debug assertions to tolerate !srv_was_started. innodb_shutdown(): Renamed from innobase_shutdown_for_mysql(). Changed the return type to void. Do not assume that all subsystems were started. que_init(), que_close(): Remove (empty functions). srv_init(), srv_general_init(): Remove as global functions. srv_free(): Allow srv_sys=NULL. srv_get_active_thread_type(): Only return SRV_PURGE if purge really is running. srv_shutdown_all_bg_threads(): Do not reset srv_start_state. It will be needed by innodb_shutdown(). innobase_start_or_create_for_mysql(): Always call srv_boot() so that innodb_shutdown() can assume that it was called. Make more subsystems dependent on SRV_START_STATE_STAT. srv_shutdown_bg_undo_sources(): Require SRV_START_STATE_STAT. trx_sys_close(): Do not assume purge_sys!=NULL. Do not call buf_dblwr_free(), because the doublewrite buffer can exist while the transaction system does not. logs_empty_and_mark_files_at_shutdown(): Do a faster shutdown if !srv_was_started. recv_sys_close(): Invoke dblwr.pages.clear() which would normally be invoked by buf_dblwr_process(). recv_recovery_from_checkpoint_start(): Always release log_sys->mutex. row_mysql_close(): Allow the subsystem not to exist.
9 years ago
Shut down InnoDB after aborted startup. This fixes memory leaks in tests that cause InnoDB startup to fail. buf_pool_free_instance(): Also free buf_pool->flush_rbt, which would normally be freed when crash recovery finishes. fil_node_close_file(), fil_space_free_low(), fil_close_all_files(): Relax some debug assertions to tolerate !srv_was_started. innodb_shutdown(): Renamed from innobase_shutdown_for_mysql(). Changed the return type to void. Do not assume that all subsystems were started. que_init(), que_close(): Remove (empty functions). srv_init(), srv_general_init(): Remove as global functions. srv_free(): Allow srv_sys=NULL. srv_get_active_thread_type(): Only return SRV_PURGE if purge really is running. srv_shutdown_all_bg_threads(): Do not reset srv_start_state. It will be needed by innodb_shutdown(). innobase_start_or_create_for_mysql(): Always call srv_boot() so that innodb_shutdown() can assume that it was called. Make more subsystems dependent on SRV_START_STATE_STAT. srv_shutdown_bg_undo_sources(): Require SRV_START_STATE_STAT. trx_sys_close(): Do not assume purge_sys!=NULL. Do not call buf_dblwr_free(), because the doublewrite buffer can exist while the transaction system does not. logs_empty_and_mark_files_at_shutdown(): Do a faster shutdown if !srv_was_started. recv_sys_close(): Invoke dblwr.pages.clear() which would normally be invoked by buf_dblwr_process(). recv_recovery_from_checkpoint_start(): Always release log_sys->mutex. row_mysql_close(): Allow the subsystem not to exist.
9 years ago
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).
9 years ago
Shut down InnoDB after aborted startup. This fixes memory leaks in tests that cause InnoDB startup to fail. buf_pool_free_instance(): Also free buf_pool->flush_rbt, which would normally be freed when crash recovery finishes. fil_node_close_file(), fil_space_free_low(), fil_close_all_files(): Relax some debug assertions to tolerate !srv_was_started. innodb_shutdown(): Renamed from innobase_shutdown_for_mysql(). Changed the return type to void. Do not assume that all subsystems were started. que_init(), que_close(): Remove (empty functions). srv_init(), srv_general_init(): Remove as global functions. srv_free(): Allow srv_sys=NULL. srv_get_active_thread_type(): Only return SRV_PURGE if purge really is running. srv_shutdown_all_bg_threads(): Do not reset srv_start_state. It will be needed by innodb_shutdown(). innobase_start_or_create_for_mysql(): Always call srv_boot() so that innodb_shutdown() can assume that it was called. Make more subsystems dependent on SRV_START_STATE_STAT. srv_shutdown_bg_undo_sources(): Require SRV_START_STATE_STAT. trx_sys_close(): Do not assume purge_sys!=NULL. Do not call buf_dblwr_free(), because the doublewrite buffer can exist while the transaction system does not. logs_empty_and_mark_files_at_shutdown(): Do a faster shutdown if !srv_was_started. recv_sys_close(): Invoke dblwr.pages.clear() which would normally be invoked by buf_dblwr_process(). recv_recovery_from_checkpoint_start(): Always release log_sys->mutex. row_mysql_close(): Allow the subsystem not to exist.
9 years ago
Shut down InnoDB after aborted startup. This fixes memory leaks in tests that cause InnoDB startup to fail. buf_pool_free_instance(): Also free buf_pool->flush_rbt, which would normally be freed when crash recovery finishes. fil_node_close_file(), fil_space_free_low(), fil_close_all_files(): Relax some debug assertions to tolerate !srv_was_started. innodb_shutdown(): Renamed from innobase_shutdown_for_mysql(). Changed the return type to void. Do not assume that all subsystems were started. que_init(), que_close(): Remove (empty functions). srv_init(), srv_general_init(): Remove as global functions. srv_free(): Allow srv_sys=NULL. srv_get_active_thread_type(): Only return SRV_PURGE if purge really is running. srv_shutdown_all_bg_threads(): Do not reset srv_start_state. It will be needed by innodb_shutdown(). innobase_start_or_create_for_mysql(): Always call srv_boot() so that innodb_shutdown() can assume that it was called. Make more subsystems dependent on SRV_START_STATE_STAT. srv_shutdown_bg_undo_sources(): Require SRV_START_STATE_STAT. trx_sys_close(): Do not assume purge_sys!=NULL. Do not call buf_dblwr_free(), because the doublewrite buffer can exist while the transaction system does not. logs_empty_and_mark_files_at_shutdown(): Do a faster shutdown if !srv_was_started. recv_sys_close(): Invoke dblwr.pages.clear() which would normally be invoked by buf_dblwr_process(). recv_recovery_from_checkpoint_start(): Always release log_sys->mutex. row_mysql_close(): Allow the subsystem not to exist.
9 years ago
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).
9 years ago
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).
9 years ago
Shut down InnoDB after aborted startup. This fixes memory leaks in tests that cause InnoDB startup to fail. buf_pool_free_instance(): Also free buf_pool->flush_rbt, which would normally be freed when crash recovery finishes. fil_node_close_file(), fil_space_free_low(), fil_close_all_files(): Relax some debug assertions to tolerate !srv_was_started. innodb_shutdown(): Renamed from innobase_shutdown_for_mysql(). Changed the return type to void. Do not assume that all subsystems were started. que_init(), que_close(): Remove (empty functions). srv_init(), srv_general_init(): Remove as global functions. srv_free(): Allow srv_sys=NULL. srv_get_active_thread_type(): Only return SRV_PURGE if purge really is running. srv_shutdown_all_bg_threads(): Do not reset srv_start_state. It will be needed by innodb_shutdown(). innobase_start_or_create_for_mysql(): Always call srv_boot() so that innodb_shutdown() can assume that it was called. Make more subsystems dependent on SRV_START_STATE_STAT. srv_shutdown_bg_undo_sources(): Require SRV_START_STATE_STAT. trx_sys_close(): Do not assume purge_sys!=NULL. Do not call buf_dblwr_free(), because the doublewrite buffer can exist while the transaction system does not. logs_empty_and_mark_files_at_shutdown(): Do a faster shutdown if !srv_was_started. recv_sys_close(): Invoke dblwr.pages.clear() which would normally be invoked by buf_dblwr_process(). recv_recovery_from_checkpoint_start(): Always release log_sys->mutex. row_mysql_close(): Allow the subsystem not to exist.
9 years ago
Shut down InnoDB after aborted startup. This fixes memory leaks in tests that cause InnoDB startup to fail. buf_pool_free_instance(): Also free buf_pool->flush_rbt, which would normally be freed when crash recovery finishes. fil_node_close_file(), fil_space_free_low(), fil_close_all_files(): Relax some debug assertions to tolerate !srv_was_started. innodb_shutdown(): Renamed from innobase_shutdown_for_mysql(). Changed the return type to void. Do not assume that all subsystems were started. que_init(), que_close(): Remove (empty functions). srv_init(), srv_general_init(): Remove as global functions. srv_free(): Allow srv_sys=NULL. srv_get_active_thread_type(): Only return SRV_PURGE if purge really is running. srv_shutdown_all_bg_threads(): Do not reset srv_start_state. It will be needed by innodb_shutdown(). innobase_start_or_create_for_mysql(): Always call srv_boot() so that innodb_shutdown() can assume that it was called. Make more subsystems dependent on SRV_START_STATE_STAT. srv_shutdown_bg_undo_sources(): Require SRV_START_STATE_STAT. trx_sys_close(): Do not assume purge_sys!=NULL. Do not call buf_dblwr_free(), because the doublewrite buffer can exist while the transaction system does not. logs_empty_and_mark_files_at_shutdown(): Do a faster shutdown if !srv_was_started. recv_sys_close(): Invoke dblwr.pages.clear() which would normally be invoked by buf_dblwr_process(). recv_recovery_from_checkpoint_start(): Always release log_sys->mutex. row_mysql_close(): Allow the subsystem not to exist.
9 years ago
fix data races srv_last_monitor_time: make all accesses relaxed atomical WARNING: ThreadSanitizer: data race (pid=12041) Write of size 8 at 0x000003949278 by thread T26 (mutexes: write M226445748578513120): #0 thd_destructor_proxy storage/innobase/handler/ha_innodb.cc:314:14 (mysqld+0x19b5505) Previous read of size 8 at 0x000003949278 by main thread: #0 innobase_init(void*) storage/innobase/handler/ha_innodb.cc:4180:11 (mysqld+0x1a03404) #1 ha_initialize_handlerton(st_plugin_int*) sql/handler.cc:522:31 (mysqld+0xc5ec73) #2 plugin_initialize(st_mem_root*, st_plugin_int*, int*, char**, bool) sql/sql_plugin.cc:1447:9 (mysqld+0x134908d) #3 plugin_init(int*, char**, int) sql/sql_plugin.cc:1729:15 (mysqld+0x13484f0) #4 init_server_components() sql/mysqld.cc:5345:7 (mysqld+0xbf720f) #5 mysqld_main(int, char**) sql/mysqld.cc:5940:7 (mysqld+0xbf107d) #6 main sql/main.cc:25:10 (mysqld+0xbe971b) Location is global 'srv_running' of size 8 at 0x000003949278 (mysqld+0x000003949278) WARNING: ThreadSanitizer: data race (pid=27869) Atomic write of size 4 at 0x7b4800000c00 by thread T8: #0 __tsan_atomic32_exchange llvm/projects/compiler-rt/lib/tsan/rtl/tsan_interface_atomic.cc:589 (mysqld+0xbd4eac) #1 TTASEventMutex<GenericPolicy>::exit() storage/innobase/include/ib0mutex.h:467:7 (mysqld+0x1a8d4cb) #2 PolicyMutex<TTASEventMutex<GenericPolicy> >::exit() storage/innobase/include/ib0mutex.h:609:10 (mysqld+0x1a7839e) #3 fil_validate() storage/innobase/fil/fil0fil.cc:5535:2 (mysqld+0x1abd913) #4 fil_validate_skip() storage/innobase/fil/fil0fil.cc:204:9 (mysqld+0x1aba601) #5 fil_aio_wait(unsigned long) storage/innobase/fil/fil0fil.cc:5296:2 (mysqld+0x1abbae6) #6 io_handler_thread storage/innobase/srv/srv0start.cc:340:3 (mysqld+0x21abe1e) Previous read of size 4 at 0x7b4800000c00 by main thread (mutexes: write M1273, write M1271): #0 TTASEventMutex<GenericPolicy>::state() const storage/innobase/include/ib0mutex.h:530:10 (mysqld+0x21c66e2) #1 sync_array_detect_deadlock(sync_array_t*, sync_cell_t*, sync_cell_t*, unsigned long) storage/innobase/sync/sync0arr.cc:746:14 (mysqld+0x21c1c7a) #2 sync_array_wait_event(sync_array_t*, sync_cell_t*&) storage/innobase/sync/sync0arr.cc:465:6 (mysqld+0x21c1708) #3 TTASEventMutex<GenericPolicy>::enter(unsigned int, unsigned int, char const*, unsigned int) storage/innobase/include/ib0mutex.h:516:6 (mysqld+0x1a8c206) #4 PolicyMutex<TTASEventMutex<GenericPolicy> >::enter(unsigned int, unsigned int, char const*, unsigned int) storage/innobase/include/ib0mutex.h:635:10 (mysqld+0x1a782c3) #5 fil_mutex_enter_and_prepare_for_io(unsigned long) storage/innobase/fil/fil0fil.cc:1131:3 (mysqld+0x1a9a92e) #6 fil_io(IORequest const&, bool, page_id_t const&, page_size_t const&, unsigned long, unsigned long, void*, void*, bool) storage/innobase/fil/fil0fil.cc:5082:2 (mysqld+0x1ab8de2) #7 buf_flush_write_block_low(buf_page_t*, buf_flush_t, bool) storage/innobase/buf/buf0flu.cc:1112:3 (mysqld+0x1cb970a) #8 buf_flush_page(buf_pool_t*, buf_page_t*, buf_flush_t, bool) storage/innobase/buf/buf0flu.cc:1270:3 (mysqld+0x1cb7d70) #9 buf_flush_try_neighbors(page_id_t const&, buf_flush_t, unsigned long, unsigned long) storage/innobase/buf/buf0flu.cc:1493:9 (mysqld+0x1cc9674) #10 buf_flush_page_and_try_neighbors(buf_page_t*, buf_flush_t, unsigned long, unsigned long*) storage/innobase/buf/buf0flu.cc:1565:13 (mysqld+0x1cbadf3) #11 buf_do_flush_list_batch(buf_pool_t*, unsigned long, unsigned long) storage/innobase/buf/buf0flu.cc:1825:3 (mysqld+0x1cbbcb8) #12 buf_flush_batch(buf_pool_t*, buf_flush_t, unsigned long, unsigned long, flush_counters_t*) storage/innobase/buf/buf0flu.cc:1895:16 (mysqld+0x1cbb459) #13 buf_flush_do_batch(buf_pool_t*, buf_flush_t, unsigned long, unsigned long, flush_counters_t*) storage/innobase/buf/buf0flu.cc:2065:2 (mysqld+0x1cbcfe1) #14 buf_flush_lists(unsigned long, unsigned long, unsigned long*) storage/innobase/buf/buf0flu.cc:2167:8 (mysqld+0x1cbd5a3) #15 log_preflush_pool_modified_pages(unsigned long) storage/innobase/log/log0log.cc:1400:13 (mysqld+0x1eefc3b) #16 log_make_checkpoint_at(unsigned long, bool) storage/innobase/log/log0log.cc:1751:10 (mysqld+0x1eefb16) #17 buf_dblwr_create() storage/innobase/buf/buf0dblwr.cc:335:2 (mysqld+0x1cd2141) #18 innobase_start_or_create_for_mysql() storage/innobase/srv/srv0start.cc:2539:10 (mysqld+0x21b4d8e) #19 innobase_init(void*) storage/innobase/handler/ha_innodb.cc:4193:8 (mysqld+0x1a5e3d7) #20 ha_initialize_handlerton(st_plugin_int*) sql/handler.cc:522:31 (mysqld+0xc74d33) #21 plugin_initialize(st_mem_root*, st_plugin_int*, int*, char**, bool) sql/sql_plugin.cc:1447:9 (mysqld+0x1376d5d) #22 plugin_init(int*, char**, int) sql/sql_plugin.cc:1729:15 (mysqld+0x13761c0) #23 init_server_components() sql/mysqld.cc:5348:7 (mysqld+0xc0d0ff) #24 mysqld_main(int, char**) sql/mysqld.cc:5943:7 (mysqld+0xc06f9d) #25 main sql/main.cc:25:10 (mysqld+0xbff71b) WARNING: ThreadSanitizer: data race (pid=29031) Write of size 8 at 0x0000039e48e0 by thread T15: #0 srv_monitor_thread storage/innobase/srv/srv0srv.cc:1699:24 (mysqld+0x21a254e) Previous write of size 8 at 0x0000039e48e0 by thread T14: #0 srv_refresh_innodb_monitor_stats() storage/innobase/srv/srv0srv.cc:1165:24 (mysqld+0x21a3124) #1 srv_error_monitor_thread storage/innobase/srv/srv0srv.cc:1836:3 (mysqld+0x21a2d40) Location is global 'srv_last_monitor_time' of size 8 at 0x0000039e48e0 (mysqld+0x0000039e48e0)
8 years ago
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.
9 years ago
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.
9 years ago
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.
9 years ago
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.
9 years ago
Shut down InnoDB after aborted startup. This fixes memory leaks in tests that cause InnoDB startup to fail. buf_pool_free_instance(): Also free buf_pool->flush_rbt, which would normally be freed when crash recovery finishes. fil_node_close_file(), fil_space_free_low(), fil_close_all_files(): Relax some debug assertions to tolerate !srv_was_started. innodb_shutdown(): Renamed from innobase_shutdown_for_mysql(). Changed the return type to void. Do not assume that all subsystems were started. que_init(), que_close(): Remove (empty functions). srv_init(), srv_general_init(): Remove as global functions. srv_free(): Allow srv_sys=NULL. srv_get_active_thread_type(): Only return SRV_PURGE if purge really is running. srv_shutdown_all_bg_threads(): Do not reset srv_start_state. It will be needed by innodb_shutdown(). innobase_start_or_create_for_mysql(): Always call srv_boot() so that innodb_shutdown() can assume that it was called. Make more subsystems dependent on SRV_START_STATE_STAT. srv_shutdown_bg_undo_sources(): Require SRV_START_STATE_STAT. trx_sys_close(): Do not assume purge_sys!=NULL. Do not call buf_dblwr_free(), because the doublewrite buffer can exist while the transaction system does not. logs_empty_and_mark_files_at_shutdown(): Do a faster shutdown if !srv_was_started. recv_sys_close(): Invoke dblwr.pages.clear() which would normally be invoked by buf_dblwr_process(). recv_recovery_from_checkpoint_start(): Always release log_sys->mutex. row_mysql_close(): Allow the subsystem not to exist.
9 years ago
Shut down InnoDB after aborted startup. This fixes memory leaks in tests that cause InnoDB startup to fail. buf_pool_free_instance(): Also free buf_pool->flush_rbt, which would normally be freed when crash recovery finishes. fil_node_close_file(), fil_space_free_low(), fil_close_all_files(): Relax some debug assertions to tolerate !srv_was_started. innodb_shutdown(): Renamed from innobase_shutdown_for_mysql(). Changed the return type to void. Do not assume that all subsystems were started. que_init(), que_close(): Remove (empty functions). srv_init(), srv_general_init(): Remove as global functions. srv_free(): Allow srv_sys=NULL. srv_get_active_thread_type(): Only return SRV_PURGE if purge really is running. srv_shutdown_all_bg_threads(): Do not reset srv_start_state. It will be needed by innodb_shutdown(). innobase_start_or_create_for_mysql(): Always call srv_boot() so that innodb_shutdown() can assume that it was called. Make more subsystems dependent on SRV_START_STATE_STAT. srv_shutdown_bg_undo_sources(): Require SRV_START_STATE_STAT. trx_sys_close(): Do not assume purge_sys!=NULL. Do not call buf_dblwr_free(), because the doublewrite buffer can exist while the transaction system does not. logs_empty_and_mark_files_at_shutdown(): Do a faster shutdown if !srv_was_started. recv_sys_close(): Invoke dblwr.pages.clear() which would normally be invoked by buf_dblwr_process(). recv_recovery_from_checkpoint_start(): Always release log_sys->mutex. row_mysql_close(): Allow the subsystem not to exist.
9 years ago
Shut down InnoDB after aborted startup. This fixes memory leaks in tests that cause InnoDB startup to fail. buf_pool_free_instance(): Also free buf_pool->flush_rbt, which would normally be freed when crash recovery finishes. fil_node_close_file(), fil_space_free_low(), fil_close_all_files(): Relax some debug assertions to tolerate !srv_was_started. innodb_shutdown(): Renamed from innobase_shutdown_for_mysql(). Changed the return type to void. Do not assume that all subsystems were started. que_init(), que_close(): Remove (empty functions). srv_init(), srv_general_init(): Remove as global functions. srv_free(): Allow srv_sys=NULL. srv_get_active_thread_type(): Only return SRV_PURGE if purge really is running. srv_shutdown_all_bg_threads(): Do not reset srv_start_state. It will be needed by innodb_shutdown(). innobase_start_or_create_for_mysql(): Always call srv_boot() so that innodb_shutdown() can assume that it was called. Make more subsystems dependent on SRV_START_STATE_STAT. srv_shutdown_bg_undo_sources(): Require SRV_START_STATE_STAT. trx_sys_close(): Do not assume purge_sys!=NULL. Do not call buf_dblwr_free(), because the doublewrite buffer can exist while the transaction system does not. logs_empty_and_mark_files_at_shutdown(): Do a faster shutdown if !srv_was_started. recv_sys_close(): Invoke dblwr.pages.clear() which would normally be invoked by buf_dblwr_process(). recv_recovery_from_checkpoint_start(): Always release log_sys->mutex. row_mysql_close(): Allow the subsystem not to exist.
9 years ago
Shut down InnoDB after aborted startup. This fixes memory leaks in tests that cause InnoDB startup to fail. buf_pool_free_instance(): Also free buf_pool->flush_rbt, which would normally be freed when crash recovery finishes. fil_node_close_file(), fil_space_free_low(), fil_close_all_files(): Relax some debug assertions to tolerate !srv_was_started. innodb_shutdown(): Renamed from innobase_shutdown_for_mysql(). Changed the return type to void. Do not assume that all subsystems were started. que_init(), que_close(): Remove (empty functions). srv_init(), srv_general_init(): Remove as global functions. srv_free(): Allow srv_sys=NULL. srv_get_active_thread_type(): Only return SRV_PURGE if purge really is running. srv_shutdown_all_bg_threads(): Do not reset srv_start_state. It will be needed by innodb_shutdown(). innobase_start_or_create_for_mysql(): Always call srv_boot() so that innodb_shutdown() can assume that it was called. Make more subsystems dependent on SRV_START_STATE_STAT. srv_shutdown_bg_undo_sources(): Require SRV_START_STATE_STAT. trx_sys_close(): Do not assume purge_sys!=NULL. Do not call buf_dblwr_free(), because the doublewrite buffer can exist while the transaction system does not. logs_empty_and_mark_files_at_shutdown(): Do a faster shutdown if !srv_was_started. recv_sys_close(): Invoke dblwr.pages.clear() which would normally be invoked by buf_dblwr_process(). recv_recovery_from_checkpoint_start(): Always release log_sys->mutex. row_mysql_close(): Allow the subsystem not to exist.
9 years ago
Shut down InnoDB after aborted startup. This fixes memory leaks in tests that cause InnoDB startup to fail. buf_pool_free_instance(): Also free buf_pool->flush_rbt, which would normally be freed when crash recovery finishes. fil_node_close_file(), fil_space_free_low(), fil_close_all_files(): Relax some debug assertions to tolerate !srv_was_started. innodb_shutdown(): Renamed from innobase_shutdown_for_mysql(). Changed the return type to void. Do not assume that all subsystems were started. que_init(), que_close(): Remove (empty functions). srv_init(), srv_general_init(): Remove as global functions. srv_free(): Allow srv_sys=NULL. srv_get_active_thread_type(): Only return SRV_PURGE if purge really is running. srv_shutdown_all_bg_threads(): Do not reset srv_start_state. It will be needed by innodb_shutdown(). innobase_start_or_create_for_mysql(): Always call srv_boot() so that innodb_shutdown() can assume that it was called. Make more subsystems dependent on SRV_START_STATE_STAT. srv_shutdown_bg_undo_sources(): Require SRV_START_STATE_STAT. trx_sys_close(): Do not assume purge_sys!=NULL. Do not call buf_dblwr_free(), because the doublewrite buffer can exist while the transaction system does not. logs_empty_and_mark_files_at_shutdown(): Do a faster shutdown if !srv_was_started. recv_sys_close(): Invoke dblwr.pages.clear() which would normally be invoked by buf_dblwr_process(). recv_recovery_from_checkpoint_start(): Always release log_sys->mutex. row_mysql_close(): Allow the subsystem not to exist.
9 years ago
Shut down InnoDB after aborted startup. This fixes memory leaks in tests that cause InnoDB startup to fail. buf_pool_free_instance(): Also free buf_pool->flush_rbt, which would normally be freed when crash recovery finishes. fil_node_close_file(), fil_space_free_low(), fil_close_all_files(): Relax some debug assertions to tolerate !srv_was_started. innodb_shutdown(): Renamed from innobase_shutdown_for_mysql(). Changed the return type to void. Do not assume that all subsystems were started. que_init(), que_close(): Remove (empty functions). srv_init(), srv_general_init(): Remove as global functions. srv_free(): Allow srv_sys=NULL. srv_get_active_thread_type(): Only return SRV_PURGE if purge really is running. srv_shutdown_all_bg_threads(): Do not reset srv_start_state. It will be needed by innodb_shutdown(). innobase_start_or_create_for_mysql(): Always call srv_boot() so that innodb_shutdown() can assume that it was called. Make more subsystems dependent on SRV_START_STATE_STAT. srv_shutdown_bg_undo_sources(): Require SRV_START_STATE_STAT. trx_sys_close(): Do not assume purge_sys!=NULL. Do not call buf_dblwr_free(), because the doublewrite buffer can exist while the transaction system does not. logs_empty_and_mark_files_at_shutdown(): Do a faster shutdown if !srv_was_started. recv_sys_close(): Invoke dblwr.pages.clear() which would normally be invoked by buf_dblwr_process(). recv_recovery_from_checkpoint_start(): Always release log_sys->mutex. row_mysql_close(): Allow the subsystem not to exist.
9 years ago
Shut down InnoDB after aborted startup. This fixes memory leaks in tests that cause InnoDB startup to fail. buf_pool_free_instance(): Also free buf_pool->flush_rbt, which would normally be freed when crash recovery finishes. fil_node_close_file(), fil_space_free_low(), fil_close_all_files(): Relax some debug assertions to tolerate !srv_was_started. innodb_shutdown(): Renamed from innobase_shutdown_for_mysql(). Changed the return type to void. Do not assume that all subsystems were started. que_init(), que_close(): Remove (empty functions). srv_init(), srv_general_init(): Remove as global functions. srv_free(): Allow srv_sys=NULL. srv_get_active_thread_type(): Only return SRV_PURGE if purge really is running. srv_shutdown_all_bg_threads(): Do not reset srv_start_state. It will be needed by innodb_shutdown(). innobase_start_or_create_for_mysql(): Always call srv_boot() so that innodb_shutdown() can assume that it was called. Make more subsystems dependent on SRV_START_STATE_STAT. srv_shutdown_bg_undo_sources(): Require SRV_START_STATE_STAT. trx_sys_close(): Do not assume purge_sys!=NULL. Do not call buf_dblwr_free(), because the doublewrite buffer can exist while the transaction system does not. logs_empty_and_mark_files_at_shutdown(): Do a faster shutdown if !srv_was_started. recv_sys_close(): Invoke dblwr.pages.clear() which would normally be invoked by buf_dblwr_process(). recv_recovery_from_checkpoint_start(): Always release log_sys->mutex. row_mysql_close(): Allow the subsystem not to exist.
9 years ago
Shut down InnoDB after aborted startup. This fixes memory leaks in tests that cause InnoDB startup to fail. buf_pool_free_instance(): Also free buf_pool->flush_rbt, which would normally be freed when crash recovery finishes. fil_node_close_file(), fil_space_free_low(), fil_close_all_files(): Relax some debug assertions to tolerate !srv_was_started. innodb_shutdown(): Renamed from innobase_shutdown_for_mysql(). Changed the return type to void. Do not assume that all subsystems were started. que_init(), que_close(): Remove (empty functions). srv_init(), srv_general_init(): Remove as global functions. srv_free(): Allow srv_sys=NULL. srv_get_active_thread_type(): Only return SRV_PURGE if purge really is running. srv_shutdown_all_bg_threads(): Do not reset srv_start_state. It will be needed by innodb_shutdown(). innobase_start_or_create_for_mysql(): Always call srv_boot() so that innodb_shutdown() can assume that it was called. Make more subsystems dependent on SRV_START_STATE_STAT. srv_shutdown_bg_undo_sources(): Require SRV_START_STATE_STAT. trx_sys_close(): Do not assume purge_sys!=NULL. Do not call buf_dblwr_free(), because the doublewrite buffer can exist while the transaction system does not. logs_empty_and_mark_files_at_shutdown(): Do a faster shutdown if !srv_was_started. recv_sys_close(): Invoke dblwr.pages.clear() which would normally be invoked by buf_dblwr_process(). recv_recovery_from_checkpoint_start(): Always release log_sys->mutex. row_mysql_close(): Allow the subsystem not to exist.
9 years ago
Shut down InnoDB after aborted startup. This fixes memory leaks in tests that cause InnoDB startup to fail. buf_pool_free_instance(): Also free buf_pool->flush_rbt, which would normally be freed when crash recovery finishes. fil_node_close_file(), fil_space_free_low(), fil_close_all_files(): Relax some debug assertions to tolerate !srv_was_started. innodb_shutdown(): Renamed from innobase_shutdown_for_mysql(). Changed the return type to void. Do not assume that all subsystems were started. que_init(), que_close(): Remove (empty functions). srv_init(), srv_general_init(): Remove as global functions. srv_free(): Allow srv_sys=NULL. srv_get_active_thread_type(): Only return SRV_PURGE if purge really is running. srv_shutdown_all_bg_threads(): Do not reset srv_start_state. It will be needed by innodb_shutdown(). innobase_start_or_create_for_mysql(): Always call srv_boot() so that innodb_shutdown() can assume that it was called. Make more subsystems dependent on SRV_START_STATE_STAT. srv_shutdown_bg_undo_sources(): Require SRV_START_STATE_STAT. trx_sys_close(): Do not assume purge_sys!=NULL. Do not call buf_dblwr_free(), because the doublewrite buffer can exist while the transaction system does not. logs_empty_and_mark_files_at_shutdown(): Do a faster shutdown if !srv_was_started. recv_sys_close(): Invoke dblwr.pages.clear() which would normally be invoked by buf_dblwr_process(). recv_recovery_from_checkpoint_start(): Always release log_sys->mutex. row_mysql_close(): Allow the subsystem not to exist.
9 years ago
Shut down InnoDB after aborted startup. This fixes memory leaks in tests that cause InnoDB startup to fail. buf_pool_free_instance(): Also free buf_pool->flush_rbt, which would normally be freed when crash recovery finishes. fil_node_close_file(), fil_space_free_low(), fil_close_all_files(): Relax some debug assertions to tolerate !srv_was_started. innodb_shutdown(): Renamed from innobase_shutdown_for_mysql(). Changed the return type to void. Do not assume that all subsystems were started. que_init(), que_close(): Remove (empty functions). srv_init(), srv_general_init(): Remove as global functions. srv_free(): Allow srv_sys=NULL. srv_get_active_thread_type(): Only return SRV_PURGE if purge really is running. srv_shutdown_all_bg_threads(): Do not reset srv_start_state. It will be needed by innodb_shutdown(). innobase_start_or_create_for_mysql(): Always call srv_boot() so that innodb_shutdown() can assume that it was called. Make more subsystems dependent on SRV_START_STATE_STAT. srv_shutdown_bg_undo_sources(): Require SRV_START_STATE_STAT. trx_sys_close(): Do not assume purge_sys!=NULL. Do not call buf_dblwr_free(), because the doublewrite buffer can exist while the transaction system does not. logs_empty_and_mark_files_at_shutdown(): Do a faster shutdown if !srv_was_started. recv_sys_close(): Invoke dblwr.pages.clear() which would normally be invoked by buf_dblwr_process(). recv_recovery_from_checkpoint_start(): Always release log_sys->mutex. row_mysql_close(): Allow the subsystem not to exist.
9 years ago
Shut down InnoDB after aborted startup. This fixes memory leaks in tests that cause InnoDB startup to fail. buf_pool_free_instance(): Also free buf_pool->flush_rbt, which would normally be freed when crash recovery finishes. fil_node_close_file(), fil_space_free_low(), fil_close_all_files(): Relax some debug assertions to tolerate !srv_was_started. innodb_shutdown(): Renamed from innobase_shutdown_for_mysql(). Changed the return type to void. Do not assume that all subsystems were started. que_init(), que_close(): Remove (empty functions). srv_init(), srv_general_init(): Remove as global functions. srv_free(): Allow srv_sys=NULL. srv_get_active_thread_type(): Only return SRV_PURGE if purge really is running. srv_shutdown_all_bg_threads(): Do not reset srv_start_state. It will be needed by innodb_shutdown(). innobase_start_or_create_for_mysql(): Always call srv_boot() so that innodb_shutdown() can assume that it was called. Make more subsystems dependent on SRV_START_STATE_STAT. srv_shutdown_bg_undo_sources(): Require SRV_START_STATE_STAT. trx_sys_close(): Do not assume purge_sys!=NULL. Do not call buf_dblwr_free(), because the doublewrite buffer can exist while the transaction system does not. logs_empty_and_mark_files_at_shutdown(): Do a faster shutdown if !srv_was_started. recv_sys_close(): Invoke dblwr.pages.clear() which would normally be invoked by buf_dblwr_process(). recv_recovery_from_checkpoint_start(): Always release log_sys->mutex. row_mysql_close(): Allow the subsystem not to exist.
9 years ago
Shut down InnoDB after aborted startup. This fixes memory leaks in tests that cause InnoDB startup to fail. buf_pool_free_instance(): Also free buf_pool->flush_rbt, which would normally be freed when crash recovery finishes. fil_node_close_file(), fil_space_free_low(), fil_close_all_files(): Relax some debug assertions to tolerate !srv_was_started. innodb_shutdown(): Renamed from innobase_shutdown_for_mysql(). Changed the return type to void. Do not assume that all subsystems were started. que_init(), que_close(): Remove (empty functions). srv_init(), srv_general_init(): Remove as global functions. srv_free(): Allow srv_sys=NULL. srv_get_active_thread_type(): Only return SRV_PURGE if purge really is running. srv_shutdown_all_bg_threads(): Do not reset srv_start_state. It will be needed by innodb_shutdown(). innobase_start_or_create_for_mysql(): Always call srv_boot() so that innodb_shutdown() can assume that it was called. Make more subsystems dependent on SRV_START_STATE_STAT. srv_shutdown_bg_undo_sources(): Require SRV_START_STATE_STAT. trx_sys_close(): Do not assume purge_sys!=NULL. Do not call buf_dblwr_free(), because the doublewrite buffer can exist while the transaction system does not. logs_empty_and_mark_files_at_shutdown(): Do a faster shutdown if !srv_was_started. recv_sys_close(): Invoke dblwr.pages.clear() which would normally be invoked by buf_dblwr_process(). recv_recovery_from_checkpoint_start(): Always release log_sys->mutex. row_mysql_close(): Allow the subsystem not to exist.
9 years ago
Shut down InnoDB after aborted startup. This fixes memory leaks in tests that cause InnoDB startup to fail. buf_pool_free_instance(): Also free buf_pool->flush_rbt, which would normally be freed when crash recovery finishes. fil_node_close_file(), fil_space_free_low(), fil_close_all_files(): Relax some debug assertions to tolerate !srv_was_started. innodb_shutdown(): Renamed from innobase_shutdown_for_mysql(). Changed the return type to void. Do not assume that all subsystems were started. que_init(), que_close(): Remove (empty functions). srv_init(), srv_general_init(): Remove as global functions. srv_free(): Allow srv_sys=NULL. srv_get_active_thread_type(): Only return SRV_PURGE if purge really is running. srv_shutdown_all_bg_threads(): Do not reset srv_start_state. It will be needed by innodb_shutdown(). innobase_start_or_create_for_mysql(): Always call srv_boot() so that innodb_shutdown() can assume that it was called. Make more subsystems dependent on SRV_START_STATE_STAT. srv_shutdown_bg_undo_sources(): Require SRV_START_STATE_STAT. trx_sys_close(): Do not assume purge_sys!=NULL. Do not call buf_dblwr_free(), because the doublewrite buffer can exist while the transaction system does not. logs_empty_and_mark_files_at_shutdown(): Do a faster shutdown if !srv_was_started. recv_sys_close(): Invoke dblwr.pages.clear() which would normally be invoked by buf_dblwr_process(). recv_recovery_from_checkpoint_start(): Always release log_sys->mutex. row_mysql_close(): Allow the subsystem not to exist.
9 years ago
Shut down InnoDB after aborted startup. This fixes memory leaks in tests that cause InnoDB startup to fail. buf_pool_free_instance(): Also free buf_pool->flush_rbt, which would normally be freed when crash recovery finishes. fil_node_close_file(), fil_space_free_low(), fil_close_all_files(): Relax some debug assertions to tolerate !srv_was_started. innodb_shutdown(): Renamed from innobase_shutdown_for_mysql(). Changed the return type to void. Do not assume that all subsystems were started. que_init(), que_close(): Remove (empty functions). srv_init(), srv_general_init(): Remove as global functions. srv_free(): Allow srv_sys=NULL. srv_get_active_thread_type(): Only return SRV_PURGE if purge really is running. srv_shutdown_all_bg_threads(): Do not reset srv_start_state. It will be needed by innodb_shutdown(). innobase_start_or_create_for_mysql(): Always call srv_boot() so that innodb_shutdown() can assume that it was called. Make more subsystems dependent on SRV_START_STATE_STAT. srv_shutdown_bg_undo_sources(): Require SRV_START_STATE_STAT. trx_sys_close(): Do not assume purge_sys!=NULL. Do not call buf_dblwr_free(), because the doublewrite buffer can exist while the transaction system does not. logs_empty_and_mark_files_at_shutdown(): Do a faster shutdown if !srv_was_started. recv_sys_close(): Invoke dblwr.pages.clear() which would normally be invoked by buf_dblwr_process(). recv_recovery_from_checkpoint_start(): Always release log_sys->mutex. row_mysql_close(): Allow the subsystem not to exist.
9 years ago
  1. /*****************************************************************************
  2. Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved.
  3. Copyright (c) 2008, Google Inc.
  4. Copyright (c) 2009, Percona Inc.
  5. Copyright (c) 2013, 2020, MariaDB Corporation.
  6. Portions of this file contain modifications contributed and copyrighted by
  7. Google, Inc. Those modifications are gratefully acknowledged and are described
  8. briefly in the InnoDB documentation. The contributions by Google are
  9. incorporated with their permission, and subject to the conditions contained in
  10. the file COPYING.Google.
  11. Portions of this file contain modifications contributed and copyrighted
  12. by Percona Inc.. Those modifications are
  13. gratefully acknowledged and are described briefly in the InnoDB
  14. documentation. The contributions by Percona Inc. are incorporated with
  15. their permission, and subject to the conditions contained in the file
  16. COPYING.Percona.
  17. This program is free software; you can redistribute it and/or modify it under
  18. the terms of the GNU General Public License as published by the Free Software
  19. Foundation; version 2 of the License.
  20. This program is distributed in the hope that it will be useful, but WITHOUT
  21. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  22. FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  23. You should have received a copy of the GNU General Public License along with
  24. this program; if not, write to the Free Software Foundation, Inc.,
  25. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
  26. *****************************************************************************/
  27. /********************************************************************//**
  28. @file srv/srv0start.cc
  29. Starts the InnoDB database server
  30. Created 2/16/1996 Heikki Tuuri
  31. *************************************************************************/
  32. #include "my_global.h"
  33. #include "mysqld.h"
  34. #include "mysql/psi/mysql_stage.h"
  35. #include "mysql/psi/psi.h"
  36. #include "row0ftsort.h"
  37. #include "ut0mem.h"
  38. #include "mem0mem.h"
  39. #include "data0data.h"
  40. #include "data0type.h"
  41. #include "dict0dict.h"
  42. #include "buf0buf.h"
  43. #include "buf0dump.h"
  44. #include "os0file.h"
  45. #include "os0thread.h"
  46. #include "fil0fil.h"
  47. #include "fil0crypt.h"
  48. #include "fsp0fsp.h"
  49. #include "rem0rec.h"
  50. #include "mtr0mtr.h"
  51. #include "log0crypt.h"
  52. #include "log0recv.h"
  53. #include "page0page.h"
  54. #include "page0cur.h"
  55. #include "trx0trx.h"
  56. #include "trx0sys.h"
  57. #include "btr0btr.h"
  58. #include "btr0cur.h"
  59. #include "rem0rec.h"
  60. #include "ibuf0ibuf.h"
  61. #include "srv0start.h"
  62. #include "srv0srv.h"
  63. #include "btr0defragment.h"
  64. #include "row0trunc.h"
  65. #include "mysql/service_wsrep.h" /* wsrep_recovery */
  66. #include "trx0rseg.h"
  67. #include "os0proc.h"
  68. #include "buf0flu.h"
  69. #include "buf0rea.h"
  70. #include "buf0mtflu.h"
  71. #include "dict0boot.h"
  72. #include "dict0load.h"
  73. #include "dict0stats_bg.h"
  74. #include "que0que.h"
  75. #include "lock0lock.h"
  76. #include "trx0roll.h"
  77. #include "trx0purge.h"
  78. #include "lock0lock.h"
  79. #include "pars0pars.h"
  80. #include "btr0sea.h"
  81. #include "rem0cmp.h"
  82. #include "dict0crea.h"
  83. #include "row0ins.h"
  84. #include "row0sel.h"
  85. #include "row0upd.h"
  86. #include "row0row.h"
  87. #include "row0mysql.h"
  88. #include "row0trunc.h"
  89. #include "btr0pcur.h"
  90. #include "os0event.h"
  91. #include "zlib.h"
  92. #include "ut0crc32.h"
  93. #include "btr0scrub.h"
  94. /** Log sequence number immediately after startup */
  95. lsn_t srv_start_lsn;
  96. /** Log sequence number at shutdown */
  97. lsn_t srv_shutdown_lsn;
  98. /** TRUE if a raw partition is in use */
  99. ibool srv_start_raw_disk_in_use;
  100. /** Number of IO threads to use */
  101. ulint srv_n_file_io_threads;
  102. /** UNDO tablespaces starts with space id. */
  103. ulint srv_undo_space_id_start;
  104. /** TRUE if the server is being started, before rolling back any
  105. incomplete transactions */
  106. bool srv_startup_is_before_trx_rollback_phase;
  107. /** TRUE if the server is being started */
  108. bool srv_is_being_started;
  109. /** TRUE if SYS_TABLESPACES is available for lookups */
  110. bool srv_sys_tablespaces_open;
  111. /** TRUE if the server was successfully started */
  112. bool srv_was_started;
  113. /** The original value of srv_log_file_size (innodb_log_file_size) */
  114. static ulonglong srv_log_file_size_requested;
  115. /** TRUE if innobase_start_or_create_for_mysql() has been called */
  116. static bool srv_start_has_been_called;
  117. /** Whether any undo log records can be generated */
  118. UNIV_INTERN bool srv_undo_sources;
  119. #ifdef UNIV_DEBUG
  120. /** InnoDB system tablespace to set during recovery */
  121. UNIV_INTERN uint srv_sys_space_size_debug;
  122. /** whether redo log files have been created at startup */
  123. UNIV_INTERN bool srv_log_files_created;
  124. #endif /* UNIV_DEBUG */
  125. /** Bit flags for tracking background thread creation. They are used to
  126. determine which threads need to be stopped if we need to abort during
  127. the initialisation step. */
  128. enum srv_start_state_t {
  129. /** No thread started */
  130. SRV_START_STATE_NONE = 0, /*!< No thread started */
  131. /** lock_wait_timeout_thread started */
  132. SRV_START_STATE_LOCK_SYS = 1, /*!< Started lock-timeout
  133. thread. */
  134. /** buf_flush_page_cleaner_coordinator,
  135. buf_flush_page_cleaner_worker started */
  136. SRV_START_STATE_IO = 2,
  137. /** srv_error_monitor_thread, srv_monitor_thread started */
  138. SRV_START_STATE_MONITOR = 4,
  139. /** srv_master_thread started */
  140. SRV_START_STATE_MASTER = 8,
  141. /** srv_purge_coordinator_thread, srv_worker_thread started */
  142. SRV_START_STATE_PURGE = 16,
  143. /** fil_crypt_thread, btr_defragment_thread started
  144. (all background threads that can generate redo log but not undo log */
  145. SRV_START_STATE_REDO = 32
  146. };
  147. /** Track server thrd starting phases */
  148. static ulint srv_start_state;
  149. /** At a shutdown this value climbs from SRV_SHUTDOWN_NONE to
  150. SRV_SHUTDOWN_CLEANUP and then to SRV_SHUTDOWN_LAST_PHASE, and so on */
  151. enum srv_shutdown_t srv_shutdown_state = SRV_SHUTDOWN_NONE;
  152. /** Files comprising the system tablespace */
  153. pfs_os_file_t files[1000];
  154. /** io_handler_thread parameters for thread identification */
  155. static ulint n[SRV_MAX_N_IO_THREADS + 6];
  156. /** io_handler_thread identifiers, 32 is the maximum number of purge threads */
  157. /** 6 is the ? */
  158. #define START_OLD_THREAD_CNT (SRV_MAX_N_IO_THREADS + 6 + 32)
  159. static os_thread_id_t thread_ids[SRV_MAX_N_IO_THREADS + 6 + 32 + MTFLUSH_MAX_WORKER];
  160. /* Thread contex data for multi-threaded flush */
  161. void *mtflush_ctx=NULL;
  162. /** Thead handles */
  163. static os_thread_t thread_handles[SRV_MAX_N_IO_THREADS + 6 + 32];
  164. static os_thread_t buf_dump_thread_handle;
  165. static os_thread_t dict_stats_thread_handle;
  166. /** Status variables, is thread started ?*/
  167. static bool thread_started[SRV_MAX_N_IO_THREADS + 6 + 32] = {false};
  168. /** Name of srv_monitor_file */
  169. static char* srv_monitor_file_name;
  170. /** Minimum expected tablespace size. (10M) */
  171. static const ulint MIN_EXPECTED_TABLESPACE_SIZE = 5 * 1024 * 1024;
  172. /** */
  173. #define SRV_MAX_N_PENDING_SYNC_IOS 100
  174. #ifdef UNIV_PFS_THREAD
  175. /* Keys to register InnoDB threads with performance schema */
  176. mysql_pfs_key_t buf_dump_thread_key;
  177. mysql_pfs_key_t dict_stats_thread_key;
  178. mysql_pfs_key_t io_handler_thread_key;
  179. mysql_pfs_key_t io_ibuf_thread_key;
  180. mysql_pfs_key_t io_log_thread_key;
  181. mysql_pfs_key_t io_read_thread_key;
  182. mysql_pfs_key_t io_write_thread_key;
  183. mysql_pfs_key_t srv_error_monitor_thread_key;
  184. mysql_pfs_key_t srv_lock_timeout_thread_key;
  185. mysql_pfs_key_t srv_master_thread_key;
  186. mysql_pfs_key_t srv_monitor_thread_key;
  187. mysql_pfs_key_t srv_purge_thread_key;
  188. mysql_pfs_key_t srv_worker_thread_key;
  189. #endif /* UNIV_PFS_THREAD */
  190. #ifdef HAVE_PSI_STAGE_INTERFACE
  191. /** Array of all InnoDB stage events for monitoring activities via
  192. performance schema. */
  193. static PSI_stage_info* srv_stages[] =
  194. {
  195. &srv_stage_alter_table_end,
  196. &srv_stage_alter_table_flush,
  197. &srv_stage_alter_table_insert,
  198. &srv_stage_alter_table_log_index,
  199. &srv_stage_alter_table_log_table,
  200. &srv_stage_alter_table_merge_sort,
  201. &srv_stage_alter_table_read_pk_internal_sort,
  202. &srv_stage_buffer_pool_load,
  203. };
  204. #endif /* HAVE_PSI_STAGE_INTERFACE */
  205. /*********************************************************************//**
  206. Check if a file can be opened in read-write mode.
  207. @return true if it doesn't exist or can be opened in rw mode. */
  208. static
  209. bool
  210. srv_file_check_mode(
  211. /*================*/
  212. const char* name) /*!< in: filename to check */
  213. {
  214. os_file_stat_t stat;
  215. memset(&stat, 0x0, sizeof(stat));
  216. dberr_t err = os_file_get_status(
  217. name, &stat, true, srv_read_only_mode);
  218. if (err == DB_FAIL) {
  219. ib::error() << "os_file_get_status() failed on '" << name
  220. << "'. Can't determine file permissions.";
  221. return(false);
  222. } else if (err == DB_SUCCESS) {
  223. /* Note: stat.rw_perm is only valid of files */
  224. if (stat.type == OS_FILE_TYPE_FILE) {
  225. if (!stat.rw_perm) {
  226. const char* mode = srv_read_only_mode
  227. ? "read" : "read-write";
  228. ib::error() << name << " can't be opened in "
  229. << mode << " mode.";
  230. return(false);
  231. }
  232. } else {
  233. /* Not a regular file, bail out. */
  234. ib::error() << "'" << name << "' not a regular file.";
  235. return(false);
  236. }
  237. } else {
  238. /* This is OK. If the file create fails on RO media, there
  239. is nothing we can do. */
  240. ut_a(err == DB_NOT_FOUND);
  241. }
  242. return(true);
  243. }
  244. /********************************************************************//**
  245. I/o-handler thread function.
  246. @return OS_THREAD_DUMMY_RETURN */
  247. extern "C"
  248. os_thread_ret_t
  249. DECLARE_THREAD(io_handler_thread)(
  250. /*==============================*/
  251. void* arg) /*!< in: pointer to the number of the segment in
  252. the aio array */
  253. {
  254. ulint segment;
  255. segment = *((ulint*) arg);
  256. #ifdef UNIV_DEBUG_THREAD_CREATION
  257. ib::info() << "Io handler thread " << segment << " starts, id "
  258. << os_thread_pf(os_thread_get_curr_id());
  259. #endif
  260. /* For read only mode, we don't need ibuf and log I/O thread.
  261. Please see innobase_start_or_create_for_mysql() */
  262. ulint start = (srv_read_only_mode) ? 0 : 2;
  263. if (segment < start) {
  264. if (segment == 0) {
  265. pfs_register_thread(io_ibuf_thread_key);
  266. } else {
  267. ut_ad(segment == 1);
  268. pfs_register_thread(io_log_thread_key);
  269. }
  270. } else if (segment >= start
  271. && segment < (start + srv_n_read_io_threads)) {
  272. pfs_register_thread(io_read_thread_key);
  273. } else if (segment >= (start + srv_n_read_io_threads)
  274. && segment < (start + srv_n_read_io_threads
  275. + srv_n_write_io_threads)) {
  276. pfs_register_thread(io_write_thread_key);
  277. } else {
  278. pfs_register_thread(io_handler_thread_key);
  279. }
  280. while (srv_shutdown_state != SRV_SHUTDOWN_EXIT_THREADS
  281. || buf_page_cleaner_is_active
  282. || !os_aio_all_slots_free()) {
  283. fil_aio_wait(segment);
  284. }
  285. /* We count the number of threads in os_thread_exit(). A created
  286. thread should always use that to exit and not use return() to exit.
  287. The thread actually never comes here because it is exited in an
  288. os_event_wait(). */
  289. os_thread_exit();
  290. OS_THREAD_DUMMY_RETURN;
  291. }
  292. /*********************************************************************//**
  293. Creates a log file.
  294. @return DB_SUCCESS or error code */
  295. static MY_ATTRIBUTE((nonnull, warn_unused_result))
  296. dberr_t
  297. create_log_file(
  298. /*============*/
  299. pfs_os_file_t* file, /*!< out: file handle */
  300. const char* name) /*!< in: log file name */
  301. {
  302. bool ret;
  303. *file = os_file_create(
  304. innodb_log_file_key, name,
  305. OS_FILE_CREATE|OS_FILE_ON_ERROR_NO_EXIT, OS_FILE_NORMAL,
  306. OS_LOG_FILE, srv_read_only_mode, &ret);
  307. if (!ret) {
  308. ib::error() << "Cannot create " << name;
  309. return(DB_ERROR);
  310. }
  311. ib::info() << "Setting log file " << name << " size to "
  312. << srv_log_file_size << " bytes";
  313. ret = os_file_set_size(name, *file, srv_log_file_size);
  314. if (!ret) {
  315. ib::error() << "Cannot set log file " << name << " size to "
  316. << srv_log_file_size << " bytes";
  317. return(DB_ERROR);
  318. }
  319. ret = os_file_close(*file);
  320. ut_a(ret);
  321. return(DB_SUCCESS);
  322. }
  323. /** Initial number of the first redo log file */
  324. #define INIT_LOG_FILE0 (SRV_N_LOG_FILES_MAX + 1)
  325. /** Delete all log files.
  326. @param[in,out] logfilename buffer for log file name
  327. @param[in] dirnamelen length of the directory path
  328. @param[in] n_files number of files to delete
  329. @param[in] i first file to delete */
  330. static
  331. void
  332. delete_log_files(char* logfilename, size_t dirnamelen, uint n_files, uint i=0)
  333. {
  334. /* Remove any old log files. */
  335. for (; i < n_files; i++) {
  336. sprintf(logfilename + dirnamelen, "ib_logfile%u", i);
  337. /* Ignore errors about non-existent files or files
  338. that cannot be removed. The create_log_file() will
  339. return an error when the file exists. */
  340. #ifdef _WIN32
  341. DeleteFile((LPCTSTR) logfilename);
  342. #else
  343. unlink(logfilename);
  344. #endif
  345. }
  346. }
  347. /*********************************************************************//**
  348. Creates all log files.
  349. @return DB_SUCCESS or error code */
  350. static
  351. dberr_t
  352. create_log_files(
  353. /*=============*/
  354. char* logfilename, /*!< in/out: buffer for log file name */
  355. size_t dirnamelen, /*!< in: length of the directory path */
  356. lsn_t lsn, /*!< in: FIL_PAGE_FILE_FLUSH_LSN value */
  357. char*& logfile0) /*!< out: name of the first log file */
  358. {
  359. dberr_t err;
  360. if (srv_read_only_mode) {
  361. ib::error() << "Cannot create log files in read-only mode";
  362. return(DB_READ_ONLY);
  363. }
  364. /* Crashing after deleting the first file should be
  365. recoverable. The buffer pool was clean, and we can simply
  366. create all log files from the scratch. */
  367. DBUG_EXECUTE_IF("innodb_log_abort_6",
  368. delete_log_files(logfilename, dirnamelen, 1);
  369. return(DB_ERROR););
  370. delete_log_files(logfilename, dirnamelen, INIT_LOG_FILE0 + 1);
  371. DBUG_PRINT("ib_log", ("After innodb_log_abort_6"));
  372. ut_ad(!buf_pool_check_no_pending_io());
  373. DBUG_EXECUTE_IF("innodb_log_abort_7", return(DB_ERROR););
  374. DBUG_PRINT("ib_log", ("After innodb_log_abort_7"));
  375. for (unsigned i = 0; i < srv_n_log_files; i++) {
  376. sprintf(logfilename + dirnamelen,
  377. "ib_logfile%u", i ? i : INIT_LOG_FILE0);
  378. err = create_log_file(&files[i], logfilename);
  379. if (err != DB_SUCCESS) {
  380. return(err);
  381. }
  382. }
  383. DBUG_EXECUTE_IF("innodb_log_abort_8", return(DB_ERROR););
  384. DBUG_PRINT("ib_log", ("After innodb_log_abort_8"));
  385. /* We did not create the first log file initially as
  386. ib_logfile0, so that crash recovery cannot find it until it
  387. has been completed and renamed. */
  388. sprintf(logfilename + dirnamelen, "ib_logfile%u", INIT_LOG_FILE0);
  389. fil_space_t* log_space = fil_space_create(
  390. "innodb_redo_log", SRV_LOG_SPACE_FIRST_ID, 0, FIL_TYPE_LOG,
  391. NULL/* innodb_encrypt_log works at a different level */);
  392. ut_a(fil_validate());
  393. ut_a(log_space != NULL);
  394. const ulint size = ulint(srv_log_file_size >> srv_page_size_shift);
  395. logfile0 = log_space->add(logfilename, OS_FILE_CLOSED, size,
  396. false, false)->name;
  397. ut_a(logfile0);
  398. for (unsigned i = 1; i < srv_n_log_files; i++) {
  399. sprintf(logfilename + dirnamelen, "ib_logfile%u", i);
  400. log_space->add(logfilename, OS_FILE_CLOSED, size,
  401. false, false);
  402. }
  403. log_init(srv_n_log_files);
  404. if (!log_set_capacity(srv_log_file_size_requested)) {
  405. return(DB_ERROR);
  406. }
  407. fil_open_log_and_system_tablespace_files();
  408. /* Create a log checkpoint. */
  409. log_mutex_enter();
  410. if (log_sys->is_encrypted() && !log_crypt_init()) {
  411. return DB_ERROR;
  412. }
  413. ut_d(recv_no_log_write = false);
  414. log_sys->lsn = ut_uint64_align_up(lsn, OS_FILE_LOG_BLOCK_SIZE);
  415. log_sys->log.lsn = log_sys->lsn;
  416. log_sys->log.lsn_offset = LOG_FILE_HDR_SIZE;
  417. log_sys->buf_next_to_write = 0;
  418. log_sys->write_lsn = log_sys->lsn;
  419. log_sys->next_checkpoint_no = 0;
  420. log_sys->last_checkpoint_lsn = 0;
  421. memset(log_sys->buf, 0, log_sys->buf_size);
  422. log_block_init(log_sys->buf, log_sys->lsn);
  423. log_block_set_first_rec_group(log_sys->buf, LOG_BLOCK_HDR_SIZE);
  424. log_sys->buf_free = LOG_BLOCK_HDR_SIZE;
  425. log_sys->lsn += LOG_BLOCK_HDR_SIZE;
  426. MONITOR_SET(MONITOR_LSN_CHECKPOINT_AGE,
  427. (log_sys->lsn - log_sys->last_checkpoint_lsn));
  428. log_mutex_exit();
  429. log_make_checkpoint();
  430. return(DB_SUCCESS);
  431. }
  432. /** Rename the first redo log file.
  433. @param[in,out] logfilename buffer for the log file name
  434. @param[in] dirnamelen length of the directory path
  435. @param[in] lsn FIL_PAGE_FILE_FLUSH_LSN value
  436. @param[in,out] logfile0 name of the first log file
  437. @return error code
  438. @retval DB_SUCCESS on successful operation */
  439. MY_ATTRIBUTE((warn_unused_result, nonnull))
  440. static
  441. dberr_t
  442. create_log_files_rename(
  443. /*====================*/
  444. char* logfilename, /*!< in/out: buffer for log file name */
  445. size_t dirnamelen, /*!< in: length of the directory path */
  446. lsn_t lsn, /*!< in: FIL_PAGE_FILE_FLUSH_LSN value */
  447. char* logfile0) /*!< in/out: name of the first log file */
  448. {
  449. /* If innodb_flush_method=O_DSYNC,
  450. we need to explicitly flush the log buffers. */
  451. fil_flush(SRV_LOG_SPACE_FIRST_ID);
  452. ut_ad(!srv_log_files_created);
  453. ut_d(srv_log_files_created = true);
  454. DBUG_EXECUTE_IF("innodb_log_abort_9", return(DB_ERROR););
  455. DBUG_PRINT("ib_log", ("After innodb_log_abort_9"));
  456. /* Close the log files, so that we can rename
  457. the first one. */
  458. fil_close_log_files(false);
  459. /* Rename the first log file, now that a log
  460. checkpoint has been created. */
  461. sprintf(logfilename + dirnamelen, "ib_logfile%u", 0);
  462. ib::info() << "Renaming log file " << logfile0 << " to "
  463. << logfilename;
  464. log_mutex_enter();
  465. ut_ad(strlen(logfile0) == 2 + strlen(logfilename));
  466. dberr_t err = os_file_rename(
  467. innodb_log_file_key, logfile0, logfilename)
  468. ? DB_SUCCESS : DB_ERROR;
  469. /* Replace the first file with ib_logfile0. */
  470. strcpy(logfile0, logfilename);
  471. log_mutex_exit();
  472. DBUG_EXECUTE_IF("innodb_log_abort_10", err = DB_ERROR;);
  473. if (err == DB_SUCCESS) {
  474. fil_open_log_and_system_tablespace_files();
  475. ib::info() << "New log files created, LSN=" << lsn;
  476. }
  477. return(err);
  478. }
  479. /*********************************************************************//**
  480. Create undo tablespace.
  481. @return DB_SUCCESS or error code */
  482. static
  483. dberr_t
  484. srv_undo_tablespace_create(
  485. /*=======================*/
  486. const char* name, /*!< in: tablespace name */
  487. ulint size) /*!< in: tablespace size in pages */
  488. {
  489. pfs_os_file_t fh;
  490. bool ret;
  491. dberr_t err = DB_SUCCESS;
  492. os_file_create_subdirs_if_needed(name);
  493. fh = os_file_create(
  494. innodb_data_file_key,
  495. name,
  496. srv_read_only_mode ? OS_FILE_OPEN : OS_FILE_CREATE,
  497. OS_FILE_NORMAL, OS_DATA_FILE, srv_read_only_mode, &ret);
  498. if (srv_read_only_mode && ret) {
  499. ib::info() << name << " opened in read-only mode";
  500. } else if (ret == FALSE) {
  501. if (os_file_get_last_error(false) != OS_FILE_ALREADY_EXISTS
  502. #ifdef UNIV_AIX
  503. /* AIX 5.1 after security patch ML7 may have
  504. errno set to 0 here, which causes our function
  505. to return 100; work around that AIX problem */
  506. && os_file_get_last_error(false) != 100
  507. #endif /* UNIV_AIX */
  508. ) {
  509. ib::error() << "Can't create UNDO tablespace "
  510. << name;
  511. }
  512. err = DB_ERROR;
  513. } else {
  514. ut_a(!srv_read_only_mode);
  515. /* We created the data file and now write it full of zeros */
  516. ib::info() << "Data file " << name << " did not exist: new to"
  517. " be created";
  518. ib::info() << "Setting file " << name << " size to "
  519. << (size >> (20 - UNIV_PAGE_SIZE_SHIFT)) << " MB";
  520. ib::info() << "Database physically writes the file full: "
  521. << "wait...";
  522. ret = os_file_set_size(
  523. name, fh, os_offset_t(size) << UNIV_PAGE_SIZE_SHIFT);
  524. if (!ret) {
  525. ib::info() << "Error in creating " << name
  526. << ": probably out of disk space";
  527. err = DB_ERROR;
  528. }
  529. os_file_close(fh);
  530. }
  531. return(err);
  532. }
  533. /** Open an undo tablespace.
  534. @param[in] name tablespace file name
  535. @param[in] space_id tablespace ID
  536. @param[in] create_new_db whether undo tablespaces are being created
  537. @return whether the tablespace was opened */
  538. static bool srv_undo_tablespace_open(const char* name, ulint space_id,
  539. bool create_new_db)
  540. {
  541. pfs_os_file_t fh;
  542. bool success;
  543. char undo_name[sizeof "innodb_undo000"];
  544. snprintf(undo_name, sizeof(undo_name),
  545. "innodb_undo%03u", static_cast<unsigned>(space_id));
  546. fh = os_file_create(
  547. innodb_data_file_key, name, OS_FILE_OPEN
  548. | OS_FILE_ON_ERROR_NO_EXIT | OS_FILE_ON_ERROR_SILENT,
  549. OS_FILE_AIO, OS_DATA_FILE, srv_read_only_mode, &success);
  550. if (!success) {
  551. return false;
  552. }
  553. os_offset_t size = os_file_get_size(fh);
  554. ut_a(size != os_offset_t(-1));
  555. /* Load the tablespace into InnoDB's internal data structures. */
  556. /* We set the biggest space id to the undo tablespace
  557. because InnoDB hasn't opened any other tablespace apart
  558. from the system tablespace. */
  559. fil_set_max_space_id_if_bigger(space_id);
  560. fil_space_t* space = fil_space_create(
  561. undo_name, space_id, FSP_FLAGS_PAGE_SSIZE(),
  562. FIL_TYPE_TABLESPACE, NULL);
  563. ut_a(fil_validate());
  564. ut_a(space);
  565. fil_node_t* file = space->add(name, fh, 0, false, true);
  566. mutex_enter(&fil_system->mutex);
  567. if (create_new_db) {
  568. space->size = file->size = ulint(size >> srv_page_size_shift);
  569. space->size_in_header = SRV_UNDO_TABLESPACE_SIZE_IN_PAGES;
  570. space->committed_size = SRV_UNDO_TABLESPACE_SIZE_IN_PAGES;
  571. } else {
  572. success = file->read_page0(true);
  573. if (!success) {
  574. os_file_close(file->handle);
  575. file->handle = OS_FILE_CLOSED;
  576. ut_a(fil_system->n_open > 0);
  577. fil_system->n_open--;
  578. }
  579. }
  580. mutex_exit(&fil_system->mutex);
  581. return success;
  582. }
  583. /** Check if undo tablespaces and redo log files exist before creating a
  584. new system tablespace
  585. @retval DB_SUCCESS if all undo and redo logs are not found
  586. @retval DB_ERROR if any undo and redo logs are found */
  587. static
  588. dberr_t
  589. srv_check_undo_redo_logs_exists()
  590. {
  591. bool ret;
  592. os_file_t fh;
  593. char name[OS_FILE_MAX_PATH];
  594. /* Check if any undo tablespaces exist */
  595. for (ulint i = 1; i <= srv_undo_tablespaces; ++i) {
  596. snprintf(
  597. name, sizeof(name),
  598. "%s%cundo%03zu",
  599. srv_undo_dir, OS_PATH_SEPARATOR,
  600. i);
  601. fh = os_file_create(
  602. innodb_data_file_key, name,
  603. OS_FILE_OPEN_RETRY
  604. | OS_FILE_ON_ERROR_NO_EXIT
  605. | OS_FILE_ON_ERROR_SILENT,
  606. OS_FILE_NORMAL,
  607. OS_DATA_FILE,
  608. srv_read_only_mode,
  609. &ret);
  610. if (ret) {
  611. os_file_close(fh);
  612. ib::error()
  613. << "undo tablespace '" << name << "' exists."
  614. " Creating system tablespace with existing undo"
  615. " tablespaces is not supported. Please delete"
  616. " all undo tablespaces before creating new"
  617. " system tablespace.";
  618. return(DB_ERROR);
  619. }
  620. }
  621. /* Check if any redo log files exist */
  622. char logfilename[OS_FILE_MAX_PATH];
  623. size_t dirnamelen = strlen(srv_log_group_home_dir);
  624. memcpy(logfilename, srv_log_group_home_dir, dirnamelen);
  625. for (unsigned i = 0; i < srv_n_log_files; i++) {
  626. sprintf(logfilename + dirnamelen,
  627. "ib_logfile%u", i);
  628. fh = os_file_create(
  629. innodb_log_file_key, logfilename,
  630. OS_FILE_OPEN_RETRY
  631. | OS_FILE_ON_ERROR_NO_EXIT
  632. | OS_FILE_ON_ERROR_SILENT,
  633. OS_FILE_NORMAL,
  634. OS_LOG_FILE,
  635. srv_read_only_mode,
  636. &ret);
  637. if (ret) {
  638. os_file_close(fh);
  639. ib::error() << "redo log file '" << logfilename
  640. << "' exists. Creating system tablespace with"
  641. " existing redo log files is not recommended."
  642. " Please delete all redo log files before"
  643. " creating new system tablespace.";
  644. return(DB_ERROR);
  645. }
  646. }
  647. return(DB_SUCCESS);
  648. }
  649. undo::undo_spaces_t undo::Truncate::s_fix_up_spaces;
  650. /** Open the configured number of dedicated undo tablespaces.
  651. @param[in] create_new_db whether the database is being initialized
  652. @return DB_SUCCESS or error code */
  653. dberr_t
  654. srv_undo_tablespaces_init(bool create_new_db)
  655. {
  656. ulint i;
  657. dberr_t err = DB_SUCCESS;
  658. ulint prev_space_id = 0;
  659. ulint n_undo_tablespaces;
  660. ulint undo_tablespace_ids[TRX_SYS_N_RSEGS + 1];
  661. srv_undo_tablespaces_open = 0;
  662. ut_a(srv_undo_tablespaces <= TRX_SYS_N_RSEGS);
  663. ut_a(!create_new_db || srv_operation == SRV_OPERATION_NORMAL);
  664. if (srv_undo_tablespaces == 1) { /* 1 is not allowed, make it 0 */
  665. srv_undo_tablespaces = 0;
  666. }
  667. memset(undo_tablespace_ids, 0x0, sizeof(undo_tablespace_ids));
  668. /* Create the undo spaces only if we are creating a new
  669. instance. We don't allow creating of new undo tablespaces
  670. in an existing instance (yet). This restriction exists because
  671. we check in several places for SYSTEM tablespaces to be less than
  672. the min of user defined tablespace ids. Once we implement saving
  673. the location of the undo tablespaces and their space ids this
  674. restriction will/should be lifted. */
  675. for (i = 0; create_new_db && i < srv_undo_tablespaces; ++i) {
  676. char name[OS_FILE_MAX_PATH];
  677. ulint space_id = i + 1;
  678. DBUG_EXECUTE_IF("innodb_undo_upgrade",
  679. space_id = i + 3;);
  680. snprintf(
  681. name, sizeof(name),
  682. "%s%cundo%03zu",
  683. srv_undo_dir, OS_PATH_SEPARATOR, space_id);
  684. if (i == 0) {
  685. srv_undo_space_id_start = space_id;
  686. prev_space_id = srv_undo_space_id_start - 1;
  687. }
  688. undo_tablespace_ids[i] = space_id;
  689. err = srv_undo_tablespace_create(
  690. name, SRV_UNDO_TABLESPACE_SIZE_IN_PAGES);
  691. if (err != DB_SUCCESS) {
  692. ib::error() << "Could not create undo tablespace '"
  693. << name << "'.";
  694. return(err);
  695. }
  696. }
  697. /* Get the tablespace ids of all the undo segments excluding
  698. the system tablespace (0). If we are creating a new instance then
  699. we build the undo_tablespace_ids ourselves since they don't
  700. already exist. */
  701. n_undo_tablespaces = create_new_db
  702. || srv_operation == SRV_OPERATION_BACKUP
  703. || srv_operation == SRV_OPERATION_RESTORE_DELTA
  704. ? srv_undo_tablespaces
  705. : trx_rseg_get_n_undo_tablespaces(undo_tablespace_ids);
  706. srv_undo_tablespaces_active = srv_undo_tablespaces;
  707. switch (srv_operation) {
  708. case SRV_OPERATION_RESTORE_DELTA:
  709. case SRV_OPERATION_BACKUP:
  710. for (i = 0; i < n_undo_tablespaces; i++) {
  711. undo_tablespace_ids[i] = i + srv_undo_space_id_start;
  712. }
  713. prev_space_id = srv_undo_space_id_start - 1;
  714. break;
  715. case SRV_OPERATION_NORMAL:
  716. if (create_new_db) {
  717. break;
  718. }
  719. /* fall through */
  720. case SRV_OPERATION_RESTORE_ROLLBACK_XA:
  721. case SRV_OPERATION_RESTORE:
  722. case SRV_OPERATION_RESTORE_EXPORT:
  723. ut_ad(!create_new_db);
  724. /* Check if any of the UNDO tablespace needs fix-up because
  725. server crashed while truncate was active on UNDO tablespace.*/
  726. for (i = 0; i < n_undo_tablespaces; ++i) {
  727. undo::Truncate undo_trunc;
  728. if (undo_trunc.needs_fix_up(undo_tablespace_ids[i])) {
  729. char name[OS_FILE_MAX_PATH];
  730. snprintf(name, sizeof(name),
  731. "%s%cundo%03zu",
  732. srv_undo_dir, OS_PATH_SEPARATOR,
  733. undo_tablespace_ids[i]);
  734. os_file_delete(innodb_data_file_key, name);
  735. err = srv_undo_tablespace_create(
  736. name,
  737. SRV_UNDO_TABLESPACE_SIZE_IN_PAGES);
  738. if (err != DB_SUCCESS) {
  739. ib::error() << "Could not fix-up undo "
  740. " tablespace truncate '"
  741. << name << "'.";
  742. return(err);
  743. }
  744. undo::Truncate::s_fix_up_spaces.push_back(
  745. undo_tablespace_ids[i]);
  746. }
  747. }
  748. break;
  749. }
  750. /* Open all the undo tablespaces that are currently in use. If we
  751. fail to open any of these it is a fatal error. The tablespace ids
  752. should be contiguous. It is a fatal error because they are required
  753. for recovery and are referenced by the UNDO logs (a.k.a RBS). */
  754. for (i = 0; i < n_undo_tablespaces; ++i) {
  755. char name[OS_FILE_MAX_PATH];
  756. snprintf(
  757. name, sizeof(name),
  758. "%s%cundo%03zu",
  759. srv_undo_dir, OS_PATH_SEPARATOR,
  760. undo_tablespace_ids[i]);
  761. /* Should be no gaps in undo tablespace ids. */
  762. ut_a(!i || prev_space_id + 1 == undo_tablespace_ids[i]);
  763. /* The system space id should not be in this array. */
  764. ut_a(undo_tablespace_ids[i] != 0);
  765. ut_a(undo_tablespace_ids[i] != ULINT_UNDEFINED);
  766. if (!srv_undo_tablespace_open(name, undo_tablespace_ids[i],
  767. create_new_db)) {
  768. ib::error() << "Unable to open undo tablespace '"
  769. << name << "'.";
  770. return DB_ERROR;
  771. }
  772. prev_space_id = undo_tablespace_ids[i];
  773. /* Note the first undo tablespace id in case of
  774. no active undo tablespace. */
  775. if (0 == srv_undo_tablespaces_open++) {
  776. srv_undo_space_id_start = undo_tablespace_ids[i];
  777. }
  778. }
  779. /* Open any extra unused undo tablespaces. These must be contiguous.
  780. We stop at the first failure. These are undo tablespaces that are
  781. not in use and therefore not required by recovery. We only check
  782. that there are no gaps. */
  783. for (i = prev_space_id + 1;
  784. i < srv_undo_space_id_start + TRX_SYS_N_RSEGS; ++i) {
  785. char name[OS_FILE_MAX_PATH];
  786. snprintf(
  787. name, sizeof(name),
  788. "%s%cundo%03zu", srv_undo_dir, OS_PATH_SEPARATOR, i);
  789. if (!srv_undo_tablespace_open(name, i, create_new_db)) {
  790. err = DB_ERROR;
  791. break;
  792. }
  793. ++n_undo_tablespaces;
  794. ++srv_undo_tablespaces_open;
  795. }
  796. /* Initialize srv_undo_space_id_start=0 when there are no
  797. dedicated undo tablespaces. */
  798. if (n_undo_tablespaces == 0) {
  799. srv_undo_space_id_start = 0;
  800. }
  801. /* If the user says that there are fewer than what we find we
  802. tolerate that discrepancy but not the inverse. Because there could
  803. be unused undo tablespaces for future use. */
  804. if (srv_undo_tablespaces > n_undo_tablespaces) {
  805. ib::error() << "Expected to open innodb_undo_tablespaces="
  806. << srv_undo_tablespaces
  807. << " but was able to find only "
  808. << n_undo_tablespaces;
  809. return(err != DB_SUCCESS ? err : DB_ERROR);
  810. } else if (n_undo_tablespaces > 0) {
  811. ib::info() << "Opened " << n_undo_tablespaces
  812. << " undo tablespaces";
  813. if (srv_undo_tablespaces == 0) {
  814. ib::warn() << "innodb_undo_tablespaces=0 disables"
  815. " dedicated undo log tablespaces";
  816. }
  817. }
  818. if (create_new_db) {
  819. mtr_t mtr;
  820. mtr_start(&mtr);
  821. /* The undo log tablespace */
  822. for (i = 0; i < n_undo_tablespaces; ++i) {
  823. fsp_header_init(
  824. undo_tablespace_ids[i],
  825. SRV_UNDO_TABLESPACE_SIZE_IN_PAGES, &mtr);
  826. }
  827. mtr_commit(&mtr);
  828. }
  829. if (!undo::Truncate::s_fix_up_spaces.empty()) {
  830. /* Step-1: Initialize the tablespace header and rsegs header. */
  831. mtr_t mtr;
  832. trx_sysf_t* sys_header;
  833. mtr_start(&mtr);
  834. /* Turn off REDO logging. We are in server start mode and fixing
  835. UNDO tablespace even before REDO log is read. Let's say we
  836. do REDO logging here then this REDO log record will be applied
  837. as part of the current recovery process. We surely don't need
  838. that as this is fix-up action parallel to REDO logging. */
  839. mtr_set_log_mode(&mtr, MTR_LOG_NO_REDO);
  840. sys_header = trx_sysf_get(&mtr);
  841. for (undo::undo_spaces_t::const_iterator it
  842. = undo::Truncate::s_fix_up_spaces.begin();
  843. it != undo::Truncate::s_fix_up_spaces.end();
  844. ++it) {
  845. undo::Truncate::add_space_to_trunc_list(*it);
  846. fsp_header_init(
  847. *it, SRV_UNDO_TABLESPACE_SIZE_IN_PAGES, &mtr);
  848. mtr_x_lock_space(*it, &mtr);
  849. for (ulint i = 0; i < TRX_SYS_N_RSEGS; i++) {
  850. ulint space_id = trx_sysf_rseg_get_space(
  851. sys_header, i, &mtr);
  852. if (space_id == *it) {
  853. trx_rseg_header_create(
  854. *it, ULINT_MAX, i, &mtr);
  855. }
  856. }
  857. undo::Truncate::clear_trunc_list();
  858. }
  859. mtr_commit(&mtr);
  860. /* Step-2: Flush the dirty pages from the buffer pool. */
  861. for (undo::undo_spaces_t::const_iterator it
  862. = undo::Truncate::s_fix_up_spaces.begin();
  863. it != undo::Truncate::s_fix_up_spaces.end();
  864. ++it) {
  865. FlushObserver dummy(TRX_SYS_SPACE, NULL, NULL);
  866. buf_LRU_flush_or_remove_pages(TRX_SYS_SPACE, &dummy);
  867. FlushObserver dummy2(*it, NULL, NULL);
  868. buf_LRU_flush_or_remove_pages(*it, &dummy2);
  869. /* Remove the truncate redo log file. */
  870. undo::done(*it);
  871. }
  872. }
  873. return(DB_SUCCESS);
  874. }
  875. /********************************************************************
  876. Wait for the purge thread(s) to start up. */
  877. static
  878. void
  879. srv_start_wait_for_purge_to_start()
  880. /*===============================*/
  881. {
  882. /* Wait for the purge coordinator and master thread to startup. */
  883. purge_state_t state = trx_purge_state();
  884. ut_a(state != PURGE_STATE_DISABLED);
  885. while (srv_shutdown_state <= SRV_SHUTDOWN_INITIATED
  886. && srv_force_recovery < SRV_FORCE_NO_BACKGROUND
  887. && state == PURGE_STATE_INIT) {
  888. switch (state = trx_purge_state()) {
  889. case PURGE_STATE_RUN:
  890. case PURGE_STATE_STOP:
  891. break;
  892. case PURGE_STATE_INIT:
  893. ib::info() << "Waiting for purge to start";
  894. os_thread_sleep(50000);
  895. break;
  896. case PURGE_STATE_EXIT:
  897. case PURGE_STATE_DISABLED:
  898. ut_error;
  899. }
  900. }
  901. }
  902. /** Create the temporary file tablespace.
  903. @param[in] create_new_db whether we are creating a new database
  904. @return DB_SUCCESS or error code. */
  905. static
  906. dberr_t
  907. srv_open_tmp_tablespace(bool create_new_db)
  908. {
  909. ulint sum_of_new_sizes;
  910. /* Will try to remove if there is existing file left-over by last
  911. unclean shutdown */
  912. srv_tmp_space.set_sanity_check_status(true);
  913. srv_tmp_space.delete_files();
  914. srv_tmp_space.set_ignore_read_only(true);
  915. ib::info() << "Creating shared tablespace for temporary tables";
  916. bool create_new_temp_space;
  917. srv_tmp_space.set_space_id(SRV_TMP_SPACE_ID);
  918. dberr_t err = srv_tmp_space.check_file_spec(
  919. &create_new_temp_space, 12 * 1024 * 1024);
  920. if (err == DB_FAIL) {
  921. ib::error() << "The " << srv_tmp_space.name()
  922. << " data file must be writable!";
  923. err = DB_ERROR;
  924. } else if (err != DB_SUCCESS) {
  925. ib::error() << "Could not create the shared "
  926. << srv_tmp_space.name() << ".";
  927. } else if ((err = srv_tmp_space.open_or_create(
  928. true, create_new_db, &sum_of_new_sizes, NULL))
  929. != DB_SUCCESS) {
  930. ib::error() << "Unable to create the shared "
  931. << srv_tmp_space.name();
  932. } else {
  933. mtr_t mtr;
  934. ulint size = srv_tmp_space.get_sum_of_sizes();
  935. /* Open this shared temp tablespace in the fil_system so that
  936. it stays open until shutdown. */
  937. if (fil_space_open(srv_tmp_space.name())) {
  938. /* Initialize the header page */
  939. mtr_start(&mtr);
  940. mtr_set_log_mode(&mtr, MTR_LOG_NO_REDO);
  941. fsp_header_init(SRV_TMP_SPACE_ID, size, &mtr);
  942. mtr_commit(&mtr);
  943. } else {
  944. /* This file was just opened in the code above! */
  945. ib::error() << "The " << srv_tmp_space.name()
  946. << " data file cannot be re-opened"
  947. " after check_file_spec() succeeded!";
  948. err = DB_ERROR;
  949. }
  950. }
  951. return(err);
  952. }
  953. /****************************************************************//**
  954. Set state to indicate start of particular group of threads in InnoDB. */
  955. UNIV_INLINE
  956. void
  957. srv_start_state_set(
  958. /*================*/
  959. srv_start_state_t state) /*!< in: indicate current state of
  960. thread startup */
  961. {
  962. srv_start_state |= state;
  963. }
  964. /****************************************************************//**
  965. Check if following group of threads is started.
  966. @return true if started */
  967. UNIV_INLINE
  968. bool
  969. srv_start_state_is_set(
  970. /*===================*/
  971. srv_start_state_t state) /*!< in: state to check for */
  972. {
  973. return(srv_start_state & state);
  974. }
  975. /**
  976. Shutdown all background threads created by InnoDB. */
  977. static
  978. void
  979. srv_shutdown_all_bg_threads()
  980. {
  981. ut_ad(!srv_undo_sources);
  982. srv_shutdown_state = SRV_SHUTDOWN_EXIT_THREADS;
  983. /* All threads end up waiting for certain events. Put those events
  984. to the signaled state. Then the threads will exit themselves after
  985. os_event_wait(). */
  986. for (uint i = 0; i < 1000; ++i) {
  987. /* NOTE: IF YOU CREATE THREADS IN INNODB, YOU MUST EXIT THEM
  988. HERE OR EARLIER */
  989. if (srv_start_state_is_set(SRV_START_STATE_LOCK_SYS)) {
  990. /* a. Let the lock timeout thread exit */
  991. os_event_set(lock_sys->timeout_event);
  992. }
  993. if (!srv_read_only_mode) {
  994. /* b. srv error monitor thread exits automatically,
  995. no need to do anything here */
  996. if (srv_start_state_is_set(SRV_START_STATE_MASTER)) {
  997. /* c. We wake the master thread so that
  998. it exits */
  999. srv_inc_activity_count();
  1000. }
  1001. if (srv_start_state_is_set(SRV_START_STATE_PURGE)) {
  1002. /* d. Wakeup purge threads. */
  1003. srv_purge_wakeup();
  1004. }
  1005. if (srv_n_fil_crypt_threads_started) {
  1006. os_event_set(fil_crypt_threads_event);
  1007. }
  1008. if (log_scrub_thread_active) {
  1009. os_event_set(log_scrub_event);
  1010. }
  1011. }
  1012. if (srv_start_state_is_set(SRV_START_STATE_IO)) {
  1013. ut_ad(!srv_read_only_mode);
  1014. /* e. Exit the i/o threads */
  1015. if (recv_sys->flush_start != NULL) {
  1016. os_event_set(recv_sys->flush_start);
  1017. }
  1018. if (recv_sys->flush_end != NULL) {
  1019. os_event_set(recv_sys->flush_end);
  1020. }
  1021. os_event_set(buf_flush_event);
  1022. if (srv_use_mtflush) {
  1023. buf_mtflu_io_thread_exit();
  1024. }
  1025. }
  1026. if (!os_thread_count) {
  1027. return;
  1028. }
  1029. switch (srv_operation) {
  1030. case SRV_OPERATION_BACKUP:
  1031. case SRV_OPERATION_RESTORE_DELTA:
  1032. break;
  1033. case SRV_OPERATION_NORMAL:
  1034. case SRV_OPERATION_RESTORE_ROLLBACK_XA:
  1035. case SRV_OPERATION_RESTORE:
  1036. case SRV_OPERATION_RESTORE_EXPORT:
  1037. if (!buf_page_cleaner_is_active
  1038. && os_aio_all_slots_free()) {
  1039. os_aio_wake_all_threads_at_shutdown();
  1040. }
  1041. }
  1042. os_thread_sleep(100000);
  1043. }
  1044. ib::warn() << os_thread_count << " threads created by InnoDB"
  1045. " had not exited at shutdown!";
  1046. ut_d(os_aio_print_pending_io(stderr));
  1047. ut_ad(0);
  1048. }
  1049. #ifdef UNIV_DEBUG
  1050. # define srv_init_abort(_db_err) \
  1051. srv_init_abort_low(create_new_db, __FILE__, __LINE__, _db_err)
  1052. #else
  1053. # define srv_init_abort(_db_err) \
  1054. srv_init_abort_low(create_new_db, _db_err)
  1055. #endif /* UNIV_DEBUG */
  1056. /** Innobase start-up aborted. Perform cleanup actions.
  1057. @param[in] create_new_db TRUE if new db is being created
  1058. @param[in] file File name
  1059. @param[in] line Line number
  1060. @param[in] err Reason for aborting InnoDB startup
  1061. @return DB_SUCCESS or error code. */
  1062. MY_ATTRIBUTE((warn_unused_result, nonnull))
  1063. static
  1064. dberr_t
  1065. srv_init_abort_low(
  1066. bool create_new_db,
  1067. #ifdef UNIV_DEBUG
  1068. const char* file,
  1069. unsigned line,
  1070. #endif /* UNIV_DEBUG */
  1071. dberr_t err)
  1072. {
  1073. if (create_new_db) {
  1074. ib::error() << "Database creation was aborted"
  1075. #ifdef UNIV_DEBUG
  1076. " at " << innobase_basename(file) << "[" << line << "]"
  1077. #endif /* UNIV_DEBUG */
  1078. " with error " << err << ". You may need"
  1079. " to delete the ibdata1 file before trying to start"
  1080. " up again.";
  1081. } else {
  1082. ib::error() << "Plugin initialization aborted"
  1083. #ifdef UNIV_DEBUG
  1084. " at " << innobase_basename(file) << "[" << line << "]"
  1085. #endif /* UNIV_DEBUG */
  1086. " with error " << err;
  1087. }
  1088. srv_shutdown_all_bg_threads();
  1089. return(err);
  1090. }
  1091. /** Prepare to delete the redo log files. Flush the dirty pages from all the
  1092. buffer pools. Flush the redo log buffer to the redo log file.
  1093. @param[in] n_files number of old redo log files
  1094. @return lsn upto which data pages have been flushed. */
  1095. static
  1096. lsn_t
  1097. srv_prepare_to_delete_redo_log_files(
  1098. ulint n_files)
  1099. {
  1100. DBUG_ENTER("srv_prepare_to_delete_redo_log_files");
  1101. lsn_t flushed_lsn;
  1102. ulint pending_io = 0;
  1103. ulint count = 0;
  1104. if (srv_safe_truncate) {
  1105. if ((log_sys->log.format & ~LOG_HEADER_FORMAT_ENCRYPTED)
  1106. != LOG_HEADER_FORMAT_10_3
  1107. || log_sys->log.subformat != 1) {
  1108. srv_log_file_size = 0;
  1109. }
  1110. } else {
  1111. if ((log_sys->log.format & ~LOG_HEADER_FORMAT_ENCRYPTED)
  1112. != LOG_HEADER_FORMAT_10_2) {
  1113. srv_log_file_size = 0;
  1114. }
  1115. }
  1116. do {
  1117. /* Clean the buffer pool. */
  1118. buf_flush_sync_all_buf_pools();
  1119. DBUG_EXECUTE_IF("innodb_log_abort_1", DBUG_RETURN(0););
  1120. DBUG_PRINT("ib_log", ("After innodb_log_abort_1"));
  1121. log_mutex_enter();
  1122. fil_names_clear(log_sys->lsn, false);
  1123. flushed_lsn = log_sys->lsn;
  1124. {
  1125. ib::info info;
  1126. if (srv_log_file_size == 0) {
  1127. info << ((log_sys->log.format
  1128. & ~LOG_HEADER_FORMAT_ENCRYPTED)
  1129. < LOG_HEADER_FORMAT_10_3
  1130. ? "Upgrading redo log: "
  1131. : "Downgrading redo log: ");
  1132. } else if (n_files != srv_n_log_files
  1133. || srv_log_file_size
  1134. != srv_log_file_size_requested) {
  1135. if (srv_encrypt_log
  1136. == log_sys->is_encrypted()) {
  1137. info << (srv_encrypt_log
  1138. ? "Resizing encrypted"
  1139. : "Resizing");
  1140. } else if (srv_encrypt_log) {
  1141. info << "Encrypting and resizing";
  1142. } else {
  1143. info << "Removing encryption"
  1144. " and resizing";
  1145. }
  1146. info << " redo log from " << n_files
  1147. << "*" << srv_log_file_size << " to ";
  1148. } else if (srv_encrypt_log) {
  1149. info << "Encrypting redo log: ";
  1150. } else {
  1151. info << "Removing redo log encryption: ";
  1152. }
  1153. info << srv_n_log_files << "*"
  1154. << srv_log_file_size_requested
  1155. << " bytes; LSN=" << flushed_lsn;
  1156. }
  1157. srv_start_lsn = flushed_lsn;
  1158. /* Flush the old log files. */
  1159. log_mutex_exit();
  1160. log_write_up_to(flushed_lsn, true);
  1161. /* If innodb_flush_method=O_DSYNC,
  1162. we need to explicitly flush the log buffers. */
  1163. fil_flush(SRV_LOG_SPACE_FIRST_ID);
  1164. ut_ad(flushed_lsn == log_get_lsn());
  1165. /* Check if the buffer pools are clean. If not
  1166. retry till it is clean. */
  1167. pending_io = buf_pool_check_no_pending_io();
  1168. if (pending_io > 0) {
  1169. count++;
  1170. /* Print a message every 60 seconds if we
  1171. are waiting to clean the buffer pools */
  1172. if (srv_print_verbose_log && count > 600) {
  1173. ib::info() << "Waiting for "
  1174. << pending_io << " buffer "
  1175. << "page I/Os to complete";
  1176. count = 0;
  1177. }
  1178. }
  1179. os_thread_sleep(100000);
  1180. } while (buf_pool_check_no_pending_io());
  1181. DBUG_RETURN(flushed_lsn);
  1182. }
  1183. /********************************************************************
  1184. Starts InnoDB and creates a new database if database files
  1185. are not found and the user wants.
  1186. @return DB_SUCCESS or error code */
  1187. dberr_t
  1188. innobase_start_or_create_for_mysql()
  1189. {
  1190. bool create_new_db = false;
  1191. lsn_t flushed_lsn;
  1192. dberr_t err = DB_SUCCESS;
  1193. ulint srv_n_log_files_found = srv_n_log_files;
  1194. mtr_t mtr;
  1195. char logfilename[10000];
  1196. char* logfile0 = NULL;
  1197. size_t dirnamelen;
  1198. unsigned i = 0;
  1199. ut_ad(srv_operation == SRV_OPERATION_NORMAL
  1200. || is_mariabackup_restore_or_export());
  1201. if (srv_force_recovery == SRV_FORCE_NO_LOG_REDO) {
  1202. srv_read_only_mode = true;
  1203. }
  1204. high_level_read_only = srv_read_only_mode
  1205. || srv_force_recovery > SRV_FORCE_NO_TRX_UNDO
  1206. || srv_sys_space.created_new_raw();
  1207. /* Reset the start state. */
  1208. srv_start_state = SRV_START_STATE_NONE;
  1209. if (srv_read_only_mode) {
  1210. ib::info() << "Started in read only mode";
  1211. /* There is no write to InnoDB tablespaces (not even
  1212. temporary ones, because also CREATE TEMPORARY TABLE is
  1213. refused in read-only mode). */
  1214. srv_use_doublewrite_buf = FALSE;
  1215. }
  1216. compile_time_assert(sizeof(ulint) == sizeof(void*));
  1217. #ifdef UNIV_DEBUG
  1218. ib::info() << "!!!!!!!! UNIV_DEBUG switched on !!!!!!!!!";
  1219. #endif
  1220. #ifdef UNIV_IBUF_DEBUG
  1221. ib::info() << "!!!!!!!! UNIV_IBUF_DEBUG switched on !!!!!!!!!";
  1222. #endif
  1223. #ifdef UNIV_LOG_LSN_DEBUG
  1224. ib::info() << "!!!!!!!! UNIV_LOG_LSN_DEBUG switched on !!!!!!!!!";
  1225. #endif /* UNIV_LOG_LSN_DEBUG */
  1226. #if defined(COMPILER_HINTS_ENABLED)
  1227. ib::info() << "Compiler hints enabled.";
  1228. #endif /* defined(COMPILER_HINTS_ENABLED) */
  1229. #ifdef _WIN32
  1230. ib::info() << "Mutexes and rw_locks use Windows interlocked functions";
  1231. #else
  1232. ib::info() << "Mutexes and rw_locks use GCC atomic builtins";
  1233. #endif
  1234. ib::info() << MUTEX_TYPE;
  1235. ib::info() << "Compressed tables use zlib " ZLIB_VERSION
  1236. #ifdef UNIV_ZIP_DEBUG
  1237. " with validation"
  1238. #endif /* UNIV_ZIP_DEBUG */
  1239. ;
  1240. #ifdef UNIV_ZIP_COPY
  1241. ib::info() << "and extra copying";
  1242. #endif /* UNIV_ZIP_COPY */
  1243. /* Since InnoDB does not currently clean up all its internal data
  1244. structures in MySQL Embedded Server Library server_end(), we
  1245. print an error message if someone tries to start up InnoDB a
  1246. second time during the process lifetime. */
  1247. if (srv_start_has_been_called) {
  1248. ib::error() << "Startup called second time"
  1249. " during the process lifetime."
  1250. " In the MySQL Embedded Server Library"
  1251. " you cannot call server_init() more than"
  1252. " once during the process lifetime.";
  1253. }
  1254. srv_start_has_been_called = true;
  1255. srv_is_being_started = true;
  1256. #ifdef _WIN32
  1257. srv_use_native_aio = TRUE;
  1258. #elif defined(LINUX_NATIVE_AIO)
  1259. if (srv_use_native_aio) {
  1260. ib::info() << "Using Linux native AIO";
  1261. }
  1262. #else
  1263. /* Currently native AIO is supported only on windows and linux
  1264. and that also when the support is compiled in. In all other
  1265. cases, we ignore the setting of innodb_use_native_aio. */
  1266. srv_use_native_aio = FALSE;
  1267. #endif /* _WIN32 */
  1268. /* Register performance schema stages before any real work has been
  1269. started which may need to be instrumented. */
  1270. mysql_stage_register("innodb", srv_stages, UT_ARR_SIZE(srv_stages));
  1271. if (srv_file_flush_method_str == NULL) {
  1272. /* These are the default options */
  1273. srv_file_flush_method = IF_WIN(SRV_ALL_O_DIRECT_FSYNC,SRV_FSYNC);
  1274. } else if (0 == ut_strcmp(srv_file_flush_method_str, "fsync")) {
  1275. srv_file_flush_method = SRV_FSYNC;
  1276. } else if (0 == ut_strcmp(srv_file_flush_method_str, "O_DSYNC")) {
  1277. srv_file_flush_method = SRV_O_DSYNC;
  1278. } else if (0 == ut_strcmp(srv_file_flush_method_str, "O_DIRECT")) {
  1279. srv_file_flush_method = SRV_O_DIRECT;
  1280. } else if (0 == ut_strcmp(srv_file_flush_method_str, "O_DIRECT_NO_FSYNC")) {
  1281. srv_file_flush_method = SRV_O_DIRECT_NO_FSYNC;
  1282. } else if (0 == ut_strcmp(srv_file_flush_method_str, "littlesync")) {
  1283. srv_file_flush_method = SRV_LITTLESYNC;
  1284. } else if (0 == ut_strcmp(srv_file_flush_method_str, "nosync")) {
  1285. srv_file_flush_method = SRV_NOSYNC;
  1286. #ifdef _WIN32
  1287. } else if (0 == ut_strcmp(srv_file_flush_method_str, "normal")) {
  1288. srv_file_flush_method = SRV_FSYNC;
  1289. } else if (0 == ut_strcmp(srv_file_flush_method_str, "unbuffered")) {
  1290. } else if (0 == ut_strcmp(srv_file_flush_method_str,
  1291. "async_unbuffered")) {
  1292. #endif /* _WIN32 */
  1293. } else {
  1294. ib::error() << "Unrecognized value "
  1295. << srv_file_flush_method_str
  1296. << " for innodb_flush_method";
  1297. err = DB_ERROR;
  1298. }
  1299. /* Note that the call srv_boot() also changes the values of
  1300. some variables to the units used by InnoDB internally */
  1301. /* Set the maximum number of threads which can wait for a semaphore
  1302. inside InnoDB: this is the 'sync wait array' size, as well as the
  1303. maximum number of threads that can wait in the 'srv_conc array' for
  1304. their time to enter InnoDB. */
  1305. srv_max_n_threads = 1 /* io_ibuf_thread */
  1306. + 1 /* io_log_thread */
  1307. + 1 /* lock_wait_timeout_thread */
  1308. + 1 /* srv_error_monitor_thread */
  1309. + 1 /* srv_monitor_thread */
  1310. + 1 /* srv_master_thread */
  1311. + 1 /* srv_purge_coordinator_thread */
  1312. + 1 /* buf_dump_thread */
  1313. + 1 /* dict_stats_thread */
  1314. + 1 /* fts_optimize_thread */
  1315. + 1 /* recv_writer_thread */
  1316. + 1 /* trx_rollback_or_clean_all_recovered */
  1317. + 128 /* added as margin, for use of
  1318. InnoDB Memcached etc. */
  1319. + max_connections
  1320. + srv_n_read_io_threads
  1321. + srv_n_write_io_threads
  1322. + srv_n_purge_threads
  1323. + srv_n_page_cleaners
  1324. /* FTS Parallel Sort */
  1325. + fts_sort_pll_degree * FTS_NUM_AUX_INDEX
  1326. * max_connections;
  1327. if (srv_buf_pool_size >= BUF_POOL_SIZE_THRESHOLD) {
  1328. if (srv_buf_pool_instances == srv_buf_pool_instances_default) {
  1329. #if defined(_WIN32) && !defined(_WIN64)
  1330. /* Do not allocate too large of a buffer pool on
  1331. Windows 32-bit systems, which can have trouble
  1332. allocating larger single contiguous memory blocks. */
  1333. srv_buf_pool_size = static_cast<ulint>(ut_uint64_align_up(srv_buf_pool_size, srv_buf_pool_chunk_unit));
  1334. srv_buf_pool_instances = ut_min(
  1335. static_cast<ulong>(MAX_BUFFER_POOLS),
  1336. static_cast<ulong>(srv_buf_pool_size / srv_buf_pool_chunk_unit));
  1337. #else /* defined(_WIN32) && !defined(_WIN64) */
  1338. /* Default to 8 instances when size > 1GB. */
  1339. srv_buf_pool_instances = 8;
  1340. #endif /* defined(_WIN32) && !defined(_WIN64) */
  1341. }
  1342. } else {
  1343. /* If buffer pool is less than 1 GiB, assume fewer
  1344. threads. Also use only one buffer pool instance. */
  1345. if (srv_buf_pool_instances != srv_buf_pool_instances_default
  1346. && srv_buf_pool_instances != 1) {
  1347. /* We can't distinguish whether the user has explicitly
  1348. started mysqld with --innodb-buffer-pool-instances=0,
  1349. (srv_buf_pool_instances_default is 0) or has not
  1350. specified that option at all. Thus we have the
  1351. limitation that if the user started with =0, we
  1352. will not emit a warning here, but we should actually
  1353. do so. */
  1354. ib::info()
  1355. << "Adjusting innodb_buffer_pool_instances"
  1356. " from " << srv_buf_pool_instances << " to 1"
  1357. " since innodb_buffer_pool_size is less than "
  1358. << BUF_POOL_SIZE_THRESHOLD / (1024 * 1024)
  1359. << " MiB";
  1360. }
  1361. srv_buf_pool_instances = 1;
  1362. }
  1363. if (srv_buf_pool_chunk_unit * srv_buf_pool_instances
  1364. > srv_buf_pool_size) {
  1365. /* Size unit of buffer pool is larger than srv_buf_pool_size.
  1366. adjust srv_buf_pool_chunk_unit for srv_buf_pool_size. */
  1367. srv_buf_pool_chunk_unit
  1368. = static_cast<ulong>(srv_buf_pool_size)
  1369. / srv_buf_pool_instances;
  1370. if (srv_buf_pool_size % srv_buf_pool_instances != 0) {
  1371. ++srv_buf_pool_chunk_unit;
  1372. }
  1373. }
  1374. srv_buf_pool_size = buf_pool_size_align(srv_buf_pool_size);
  1375. if (srv_n_page_cleaners > srv_buf_pool_instances) {
  1376. /* limit of page_cleaner parallelizability
  1377. is number of buffer pool instances. */
  1378. srv_n_page_cleaners = srv_buf_pool_instances;
  1379. }
  1380. srv_boot();
  1381. ib::info() << ut_crc32_implementation;
  1382. if (!srv_read_only_mode) {
  1383. mutex_create(LATCH_ID_SRV_MONITOR_FILE,
  1384. &srv_monitor_file_mutex);
  1385. if (srv_innodb_status) {
  1386. srv_monitor_file_name = static_cast<char*>(
  1387. ut_malloc_nokey(
  1388. strlen(fil_path_to_mysql_datadir)
  1389. + 20 + sizeof "/innodb_status."));
  1390. sprintf(srv_monitor_file_name,
  1391. "%s/innodb_status." ULINTPF,
  1392. fil_path_to_mysql_datadir,
  1393. os_proc_get_number());
  1394. srv_monitor_file = fopen(srv_monitor_file_name, "w+");
  1395. if (!srv_monitor_file) {
  1396. ib::error() << "Unable to create "
  1397. << srv_monitor_file_name << ": "
  1398. << strerror(errno);
  1399. if (err == DB_SUCCESS) {
  1400. err = DB_ERROR;
  1401. }
  1402. }
  1403. } else {
  1404. srv_monitor_file_name = NULL;
  1405. srv_monitor_file = os_file_create_tmpfile(NULL);
  1406. if (!srv_monitor_file && err == DB_SUCCESS) {
  1407. err = DB_ERROR;
  1408. }
  1409. }
  1410. mutex_create(LATCH_ID_SRV_MISC_TMPFILE,
  1411. &srv_misc_tmpfile_mutex);
  1412. srv_misc_tmpfile = os_file_create_tmpfile(NULL);
  1413. if (!srv_misc_tmpfile && err == DB_SUCCESS) {
  1414. err = DB_ERROR;
  1415. }
  1416. }
  1417. if (err != DB_SUCCESS) {
  1418. return(srv_init_abort(err));
  1419. }
  1420. srv_n_file_io_threads = srv_n_read_io_threads;
  1421. srv_n_file_io_threads += srv_n_write_io_threads;
  1422. if (!srv_read_only_mode) {
  1423. /* Add the log and ibuf IO threads. */
  1424. srv_n_file_io_threads += 2;
  1425. } else {
  1426. ib::info() << "Disabling background log and ibuf IO write"
  1427. << " threads.";
  1428. }
  1429. ut_a(srv_n_file_io_threads <= SRV_MAX_N_IO_THREADS);
  1430. if (!os_aio_init(srv_n_read_io_threads,
  1431. srv_n_write_io_threads,
  1432. SRV_MAX_N_PENDING_SYNC_IOS)) {
  1433. ib::error() << "Cannot initialize AIO sub-system";
  1434. return(srv_init_abort(DB_ERROR));
  1435. }
  1436. fil_init(srv_file_per_table ? 50000 : 5000, srv_max_n_open_files);
  1437. double size;
  1438. char unit;
  1439. if (srv_buf_pool_size >= 1024 * 1024 * 1024) {
  1440. size = ((double) srv_buf_pool_size) / (1024 * 1024 * 1024);
  1441. unit = 'G';
  1442. } else {
  1443. size = ((double) srv_buf_pool_size) / (1024 * 1024);
  1444. unit = 'M';
  1445. }
  1446. double chunk_size;
  1447. char chunk_unit;
  1448. if (srv_buf_pool_chunk_unit >= 1024 * 1024 * 1024) {
  1449. chunk_size = srv_buf_pool_chunk_unit / 1024.0 / 1024 / 1024;
  1450. chunk_unit = 'G';
  1451. } else {
  1452. chunk_size = srv_buf_pool_chunk_unit / 1024.0 / 1024;
  1453. chunk_unit = 'M';
  1454. }
  1455. ib::info() << "Initializing buffer pool, total size = "
  1456. << size << unit << ", instances = " << srv_buf_pool_instances
  1457. << ", chunk size = " << chunk_size << chunk_unit;
  1458. err = buf_pool_init(srv_buf_pool_size, srv_buf_pool_instances);
  1459. if (err != DB_SUCCESS) {
  1460. ib::error() << "Cannot allocate memory for the buffer pool";
  1461. return(srv_init_abort(DB_ERROR));
  1462. }
  1463. ib::info() << "Completed initialization of buffer pool";
  1464. #ifdef UNIV_DEBUG
  1465. /* We have observed deadlocks with a 5MB buffer pool but
  1466. the actual lower limit could very well be a little higher. */
  1467. if (srv_buf_pool_size <= 5 * 1024 * 1024) {
  1468. ib::info() << "Small buffer pool size ("
  1469. << srv_buf_pool_size / 1024 / 1024
  1470. << "M), the flst_validate() debug function can cause a"
  1471. << " deadlock if the buffer pool fills up.";
  1472. }
  1473. #endif /* UNIV_DEBUG */
  1474. fsp_init();
  1475. log_sys_init();
  1476. recv_sys_init();
  1477. lock_sys_create(srv_lock_table_size);
  1478. /* Create i/o-handler threads: */
  1479. for (ulint t = 0; t < srv_n_file_io_threads; ++t) {
  1480. n[t] = t;
  1481. thread_handles[t] = os_thread_create(io_handler_thread, n + t, thread_ids + t);
  1482. thread_started[t] = true;
  1483. }
  1484. if (!srv_read_only_mode) {
  1485. buf_flush_page_cleaner_init();
  1486. buf_page_cleaner_is_active = true;
  1487. os_thread_create(buf_flush_page_cleaner_coordinator,
  1488. NULL, NULL);
  1489. for (i = 1; i < srv_n_page_cleaners; ++i) {
  1490. os_thread_create(buf_flush_page_cleaner_worker,
  1491. NULL, NULL);
  1492. }
  1493. #ifdef UNIV_LINUX
  1494. /* Wait for the setpriority() call to finish. */
  1495. os_event_wait(recv_sys->flush_end);
  1496. #endif /* UNIV_LINUX */
  1497. srv_start_state_set(SRV_START_STATE_IO);
  1498. }
  1499. if (srv_n_log_files * srv_log_file_size >= log_group_max_size) {
  1500. /* Log group size is limited by the size of page number. Remove this
  1501. limitation when fil_io() is not used for recovery log io. */
  1502. ib::error() << "Combined size of log files must be < "
  1503. << log_group_max_size;
  1504. return(srv_init_abort(DB_ERROR));
  1505. }
  1506. os_normalize_path(srv_data_home);
  1507. /* Check if the data files exist or not. */
  1508. err = srv_sys_space.check_file_spec(
  1509. &create_new_db, MIN_EXPECTED_TABLESPACE_SIZE);
  1510. if (err != DB_SUCCESS) {
  1511. return(srv_init_abort(DB_ERROR));
  1512. }
  1513. srv_startup_is_before_trx_rollback_phase = !create_new_db;
  1514. /* Check if undo tablespaces and redo log files exist before creating
  1515. a new system tablespace */
  1516. if (create_new_db) {
  1517. err = srv_check_undo_redo_logs_exists();
  1518. if (err != DB_SUCCESS) {
  1519. return(srv_init_abort(DB_ERROR));
  1520. }
  1521. recv_sys_debug_free();
  1522. }
  1523. /* Open or create the data files. */
  1524. ulint sum_of_new_sizes;
  1525. err = srv_sys_space.open_or_create(
  1526. false, create_new_db, &sum_of_new_sizes, &flushed_lsn);
  1527. switch (err) {
  1528. case DB_SUCCESS:
  1529. break;
  1530. case DB_CANNOT_OPEN_FILE:
  1531. ib::error()
  1532. << "Could not open or create the system tablespace. If"
  1533. " you tried to add new data files to the system"
  1534. " tablespace, and it failed here, you should now"
  1535. " edit innodb_data_file_path in my.cnf back to what"
  1536. " it was, and remove the new ibdata files InnoDB"
  1537. " created in this failed attempt. InnoDB only wrote"
  1538. " those files full of zeros, but did not yet use"
  1539. " them in any way. But be careful: do not remove"
  1540. " old data files which contain your precious data!";
  1541. /* fall through */
  1542. default:
  1543. /* Other errors might come from Datafile::validate_first_page() */
  1544. return(srv_init_abort(err));
  1545. }
  1546. dirnamelen = strlen(srv_log_group_home_dir);
  1547. ut_a(dirnamelen < (sizeof logfilename) - 10 - sizeof "ib_logfile");
  1548. memcpy(logfilename, srv_log_group_home_dir, dirnamelen);
  1549. /* Add a path separator if needed. */
  1550. if (dirnamelen && logfilename[dirnamelen - 1] != OS_PATH_SEPARATOR) {
  1551. logfilename[dirnamelen++] = OS_PATH_SEPARATOR;
  1552. }
  1553. srv_log_file_size_requested = srv_log_file_size;
  1554. if (innodb_encrypt_temporary_tables && !log_crypt_init()) {
  1555. return srv_init_abort(DB_ERROR);
  1556. }
  1557. if (create_new_db) {
  1558. buf_flush_sync_all_buf_pools();
  1559. flushed_lsn = log_get_lsn();
  1560. err = create_log_files(
  1561. logfilename, dirnamelen, flushed_lsn, logfile0);
  1562. if (err != DB_SUCCESS) {
  1563. return(srv_init_abort(err));
  1564. }
  1565. } else {
  1566. srv_log_file_size = 0;
  1567. for (i = 0; i < SRV_N_LOG_FILES_MAX; i++) {
  1568. os_file_stat_t stat_info;
  1569. sprintf(logfilename + dirnamelen,
  1570. "ib_logfile%u", i);
  1571. err = os_file_get_status(
  1572. logfilename, &stat_info, false,
  1573. srv_read_only_mode);
  1574. if (err == DB_NOT_FOUND) {
  1575. if (i == 0
  1576. && is_mariabackup_restore_or_export())
  1577. return (DB_SUCCESS);
  1578. /* opened all files */
  1579. break;
  1580. }
  1581. if (stat_info.type != OS_FILE_TYPE_FILE) {
  1582. break;
  1583. }
  1584. if (!srv_file_check_mode(logfilename)) {
  1585. return(srv_init_abort(DB_ERROR));
  1586. }
  1587. const os_offset_t size = stat_info.size;
  1588. ut_a(size != (os_offset_t) -1);
  1589. if (size & (OS_FILE_LOG_BLOCK_SIZE - 1)) {
  1590. ib::error() << "Log file " << logfilename
  1591. << " size " << size << " is not a"
  1592. " multiple of 512 bytes";
  1593. return(srv_init_abort(DB_ERROR));
  1594. }
  1595. if (i == 0) {
  1596. if (size == 0
  1597. && is_mariabackup_restore_or_export()) {
  1598. /* Tolerate an empty ib_logfile0
  1599. from a previous run of
  1600. mariabackup --prepare. */
  1601. return(DB_SUCCESS);
  1602. }
  1603. /* The first log file must consist of
  1604. at least the following 512-byte pages:
  1605. header, checkpoint page 1, empty,
  1606. checkpoint page 2, redo log page(s).
  1607. Mariabackup --prepare would create an
  1608. empty ib_logfile0. Tolerate it if there
  1609. are no other ib_logfile* files. */
  1610. if ((size != 0 || i != 0)
  1611. && size <= OS_FILE_LOG_BLOCK_SIZE * 4) {
  1612. ib::error() << "Log file "
  1613. << logfilename << " size "
  1614. << size << " is too small";
  1615. return(srv_init_abort(DB_ERROR));
  1616. }
  1617. srv_log_file_size = size;
  1618. } else if (size != srv_log_file_size) {
  1619. ib::error() << "Log file " << logfilename
  1620. << " is of different size " << size
  1621. << " bytes than other log files "
  1622. << srv_log_file_size << " bytes!";
  1623. return(srv_init_abort(DB_ERROR));
  1624. }
  1625. }
  1626. if (srv_log_file_size == 0) {
  1627. if (flushed_lsn < lsn_t(1000)) {
  1628. ib::error()
  1629. << "Cannot create log files because"
  1630. " data files are corrupt or the"
  1631. " database was not shut down cleanly"
  1632. " after creating the data files.";
  1633. return srv_init_abort(DB_ERROR);
  1634. }
  1635. strcpy(logfilename + dirnamelen, "ib_logfile0");
  1636. srv_log_file_size = srv_log_file_size_requested;
  1637. err = create_log_files(
  1638. logfilename, dirnamelen,
  1639. flushed_lsn, logfile0);
  1640. if (err == DB_SUCCESS) {
  1641. err = create_log_files_rename(
  1642. logfilename, dirnamelen,
  1643. flushed_lsn, logfile0);
  1644. }
  1645. if (err != DB_SUCCESS) {
  1646. return(srv_init_abort(err));
  1647. }
  1648. /* Suppress the message about
  1649. crash recovery. */
  1650. flushed_lsn = log_get_lsn();
  1651. goto files_checked;
  1652. }
  1653. srv_n_log_files_found = i;
  1654. /* Create the in-memory file space objects. */
  1655. sprintf(logfilename + dirnamelen, "ib_logfile%u", 0);
  1656. /* Disable the doublewrite buffer for log files. */
  1657. fil_space_t* log_space = fil_space_create(
  1658. "innodb_redo_log",
  1659. SRV_LOG_SPACE_FIRST_ID, 0,
  1660. FIL_TYPE_LOG,
  1661. NULL /* no encryption yet */);
  1662. ut_a(fil_validate());
  1663. ut_a(log_space);
  1664. ut_a(srv_log_file_size <= log_group_max_size);
  1665. const ulint size = 1 + ulint((srv_log_file_size - 1)
  1666. >> srv_page_size_shift);
  1667. for (unsigned j = 0; j < srv_n_log_files_found; j++) {
  1668. sprintf(logfilename + dirnamelen, "ib_logfile%u", j);
  1669. log_space->add(logfilename, OS_FILE_CLOSED, size,
  1670. false, false);
  1671. }
  1672. log_init(srv_n_log_files_found);
  1673. if (!log_set_capacity(srv_log_file_size_requested)) {
  1674. return(srv_init_abort(DB_ERROR));
  1675. }
  1676. }
  1677. files_checked:
  1678. /* Open all log files and data files in the system
  1679. tablespace: we keep them open until database
  1680. shutdown */
  1681. fil_open_log_and_system_tablespace_files();
  1682. ut_d(fil_space_get(0)->recv_size = srv_sys_space_size_debug);
  1683. err = srv_undo_tablespaces_init(create_new_db);
  1684. /* If the force recovery is set very high then we carry on regardless
  1685. of all errors. Basically this is fingers crossed mode. */
  1686. if (err != DB_SUCCESS
  1687. && srv_force_recovery < SRV_FORCE_NO_UNDO_LOG_SCAN) {
  1688. return(srv_init_abort(err));
  1689. }
  1690. /* Initialize objects used by dict stats gathering thread, which
  1691. can also be used by recovery if it tries to drop some table */
  1692. if (!srv_read_only_mode) {
  1693. dict_stats_thread_init();
  1694. }
  1695. trx_sys_file_format_init();
  1696. trx_sys_create();
  1697. if (create_new_db) {
  1698. ut_a(!srv_read_only_mode);
  1699. mtr_start(&mtr);
  1700. fsp_header_init(0, sum_of_new_sizes, &mtr);
  1701. compile_time_assert(TRX_SYS_SPACE == 0);
  1702. compile_time_assert(IBUF_SPACE_ID == 0);
  1703. ulint ibuf_root = btr_create(
  1704. DICT_CLUSTERED | DICT_IBUF,
  1705. 0, univ_page_size, DICT_IBUF_ID_MIN,
  1706. dict_ind_redundant, NULL, &mtr);
  1707. mtr_commit(&mtr);
  1708. if (ibuf_root == FIL_NULL) {
  1709. return(srv_init_abort(DB_ERROR));
  1710. }
  1711. ut_ad(ibuf_root == IBUF_TREE_ROOT_PAGE_NO);
  1712. /* To maintain backward compatibility we create only
  1713. the first rollback segment before the double write buffer.
  1714. All the remaining rollback segments will be created later,
  1715. after the double write buffer has been created. */
  1716. trx_sys_create_sys_pages();
  1717. trx_sys_init_at_db_start();
  1718. err = dict_create();
  1719. if (err != DB_SUCCESS) {
  1720. return(srv_init_abort(err));
  1721. }
  1722. buf_flush_sync_all_buf_pools();
  1723. flushed_lsn = log_get_lsn();
  1724. err = fil_write_flushed_lsn(flushed_lsn);
  1725. if (err == DB_SUCCESS) {
  1726. err = create_log_files_rename(
  1727. logfilename, dirnamelen,
  1728. flushed_lsn, logfile0);
  1729. }
  1730. if (err != DB_SUCCESS) {
  1731. return(srv_init_abort(err));
  1732. }
  1733. } else {
  1734. /* Check if we support the max format that is stamped
  1735. on the system tablespace.
  1736. Note: We are NOT allowed to make any modifications to
  1737. the TRX_SYS_PAGE_NO page before recovery because this
  1738. page also contains the max_trx_id etc. important system
  1739. variables that are required for recovery. We need to
  1740. ensure that we return the system to a state where normal
  1741. recovery is guaranteed to work. We do this by
  1742. invalidating the buffer cache, this will force the
  1743. reread of the page and restoration to its last known
  1744. consistent state, this is REQUIRED for the recovery
  1745. process to work. */
  1746. err = trx_sys_file_format_max_check(
  1747. srv_max_file_format_at_startup);
  1748. if (err != DB_SUCCESS) {
  1749. return(srv_init_abort(err));
  1750. }
  1751. /* Invalidate the buffer pool to ensure that we reread
  1752. the page that we read above, during recovery.
  1753. Note that this is not as heavy weight as it seems. At
  1754. this point there will be only ONE page in the buf_LRU
  1755. and there must be no page in the buf_flush list. */
  1756. buf_pool_invalidate();
  1757. /* Scan and locate truncate log files. Parsed located files
  1758. and add table to truncate information to central vector for
  1759. truncate fix-up action post recovery. */
  1760. err = TruncateLogParser::scan_and_parse(srv_log_group_home_dir);
  1761. if (err != DB_SUCCESS) {
  1762. return(srv_init_abort(DB_ERROR));
  1763. }
  1764. /* We always try to do a recovery, even if the database had
  1765. been shut down normally: this is the normal startup path */
  1766. err = recv_recovery_from_checkpoint_start(flushed_lsn);
  1767. recv_sys->dblwr.pages.clear();
  1768. if (err != DB_SUCCESS) {
  1769. return(srv_init_abort(err));
  1770. }
  1771. switch (srv_operation) {
  1772. case SRV_OPERATION_NORMAL:
  1773. case SRV_OPERATION_RESTORE_ROLLBACK_XA:
  1774. case SRV_OPERATION_RESTORE_EXPORT:
  1775. /* Initialize the change buffer. */
  1776. err = dict_boot();
  1777. if (err != DB_SUCCESS) {
  1778. return(srv_init_abort(err));
  1779. }
  1780. /* This must precede
  1781. recv_apply_hashed_log_recs(true). */
  1782. trx_sys_init_at_db_start();
  1783. break;
  1784. case SRV_OPERATION_RESTORE_DELTA:
  1785. case SRV_OPERATION_BACKUP:
  1786. ut_ad(!"wrong mariabackup mode");
  1787. /* fall through */
  1788. case SRV_OPERATION_RESTORE:
  1789. /* mariabackup --prepare only deals with
  1790. the redo log and the data files, not with
  1791. transactions or the data dictionary. */
  1792. break;
  1793. }
  1794. if (srv_force_recovery < SRV_FORCE_NO_LOG_REDO) {
  1795. /* Apply the hashed log records to the
  1796. respective file pages, for the last batch of
  1797. recv_group_scan_log_recs(). */
  1798. recv_apply_hashed_log_recs(true);
  1799. if (recv_sys->found_corrupt_log
  1800. || recv_sys->found_corrupt_fs) {
  1801. return(srv_init_abort(DB_CORRUPTION));
  1802. }
  1803. DBUG_PRINT("ib_log", ("apply completed"));
  1804. if (recv_needed_recovery) {
  1805. trx_sys_print_mysql_binlog_offset();
  1806. }
  1807. }
  1808. if (!srv_read_only_mode) {
  1809. const ulint flags = FSP_FLAGS_PAGE_SSIZE();
  1810. for (ulint id = 0; id <= srv_undo_tablespaces; id++) {
  1811. if (fil_space_get(id)) {
  1812. fsp_flags_try_adjust(id, flags);
  1813. }
  1814. }
  1815. if (sum_of_new_sizes > 0) {
  1816. /* New data file(s) were added */
  1817. mtr.start();
  1818. fsp_header_inc_size(0, sum_of_new_sizes, &mtr);
  1819. mtr.commit();
  1820. /* Immediately write the log record about
  1821. increased tablespace size to disk, so that it
  1822. is durable even if mysqld would crash
  1823. quickly */
  1824. log_buffer_flush_to_disk();
  1825. }
  1826. }
  1827. const ulint tablespace_size_in_header
  1828. = fsp_header_get_tablespace_size();
  1829. const ulint sum_of_data_file_sizes
  1830. = srv_sys_space.get_sum_of_sizes();
  1831. /* Compare the system tablespace file size to what is
  1832. stored in FSP_SIZE. In srv_sys_space.open_or_create()
  1833. we already checked that the file sizes match the
  1834. innodb_data_file_path specification. */
  1835. if (srv_read_only_mode
  1836. || sum_of_data_file_sizes == tablespace_size_in_header) {
  1837. /* Do not complain about the size. */
  1838. } else if (!srv_sys_space.can_auto_extend_last_file()
  1839. || sum_of_data_file_sizes
  1840. < tablespace_size_in_header) {
  1841. ib::error() << "Tablespace size stored in header is "
  1842. << tablespace_size_in_header
  1843. << " pages, but the sum of data file sizes is "
  1844. << sum_of_data_file_sizes << " pages";
  1845. if (srv_force_recovery == 0
  1846. && sum_of_data_file_sizes
  1847. < tablespace_size_in_header) {
  1848. ib::error() <<
  1849. "Cannot start InnoDB. The tail of"
  1850. " the system tablespace is"
  1851. " missing. Have you edited"
  1852. " innodb_data_file_path in my.cnf"
  1853. " in an inappropriate way, removing"
  1854. " data files from there?"
  1855. " You can set innodb_force_recovery=1"
  1856. " in my.cnf to force"
  1857. " a startup if you are trying to"
  1858. " recover a badly corrupt database.";
  1859. return(srv_init_abort(DB_ERROR));
  1860. }
  1861. }
  1862. /* recv_recovery_from_checkpoint_finish needs trx lists which
  1863. are initialized in trx_sys_init_at_db_start(). */
  1864. recv_recovery_from_checkpoint_finish();
  1865. if (is_mariabackup_restore_or_export()) {
  1866. /* After applying the redo log from
  1867. SRV_OPERATION_BACKUP, flush the changes
  1868. to the data files and truncate or delete the log.
  1869. Unless --export is specified, no further change to
  1870. InnoDB files is needed. */
  1871. ut_ad(!srv_force_recovery);
  1872. ut_ad(srv_n_log_files_found <= 1);
  1873. ut_ad(recv_no_log_write);
  1874. buf_flush_sync_all_buf_pools();
  1875. err = fil_write_flushed_lsn(log_get_lsn());
  1876. ut_ad(!buf_pool_check_no_pending_io());
  1877. fil_close_log_files(true);
  1878. log_group_close_all();
  1879. if (err == DB_SUCCESS) {
  1880. bool trunc = is_mariabackup_restore();
  1881. /* Delete subsequent log files. */
  1882. delete_log_files(logfilename, dirnamelen,
  1883. srv_n_log_files_found, trunc);
  1884. if (trunc) {
  1885. /* Truncate the first log file. */
  1886. strcpy(logfilename + dirnamelen,
  1887. "ib_logfile0");
  1888. FILE* f = fopen(logfilename, "w");
  1889. fclose(f);
  1890. }
  1891. }
  1892. return(err);
  1893. }
  1894. /* Upgrade or resize or rebuild the redo logs before
  1895. generating any dirty pages, so that the old redo log
  1896. files will not be written to. */
  1897. if (srv_force_recovery == SRV_FORCE_NO_LOG_REDO) {
  1898. /* Completely ignore the redo log. */
  1899. } else if (srv_read_only_mode) {
  1900. /* Leave the redo log alone. */
  1901. } else if (srv_log_file_size_requested == srv_log_file_size
  1902. && srv_n_log_files_found == srv_n_log_files
  1903. && log_sys->log.format
  1904. == (srv_safe_truncate
  1905. ? (srv_encrypt_log
  1906. ? LOG_HEADER_FORMAT_10_3
  1907. | LOG_HEADER_FORMAT_ENCRYPTED
  1908. : LOG_HEADER_FORMAT_10_3)
  1909. : (srv_encrypt_log
  1910. ? LOG_HEADER_FORMAT_10_2
  1911. | LOG_HEADER_FORMAT_ENCRYPTED
  1912. : LOG_HEADER_FORMAT_10_2))
  1913. && log_sys->log.subformat == !!srv_safe_truncate) {
  1914. /* No need to add or remove encryption,
  1915. upgrade, downgrade, or resize. */
  1916. } else {
  1917. /* Prepare to delete the old redo log files */
  1918. flushed_lsn = srv_prepare_to_delete_redo_log_files(i);
  1919. DBUG_EXECUTE_IF("innodb_log_abort_1",
  1920. return(srv_init_abort(DB_ERROR)););
  1921. /* Prohibit redo log writes from any other
  1922. threads until creating a log checkpoint at the
  1923. end of create_log_files(). */
  1924. ut_d(recv_no_log_write = true);
  1925. ut_ad(!buf_pool_check_no_pending_io());
  1926. DBUG_EXECUTE_IF("innodb_log_abort_3",
  1927. return(srv_init_abort(DB_ERROR)););
  1928. DBUG_PRINT("ib_log", ("After innodb_log_abort_3"));
  1929. /* Stamp the LSN to the data files. */
  1930. err = fil_write_flushed_lsn(flushed_lsn);
  1931. DBUG_EXECUTE_IF("innodb_log_abort_4", err = DB_ERROR;);
  1932. DBUG_PRINT("ib_log", ("After innodb_log_abort_4"));
  1933. if (err != DB_SUCCESS) {
  1934. return(srv_init_abort(err));
  1935. }
  1936. /* Close and free the redo log files, so that
  1937. we can replace them. */
  1938. fil_close_log_files(true);
  1939. DBUG_EXECUTE_IF("innodb_log_abort_5",
  1940. return(srv_init_abort(DB_ERROR)););
  1941. DBUG_PRINT("ib_log", ("After innodb_log_abort_5"));
  1942. /* Free the old log file space. */
  1943. log_group_close_all();
  1944. ib::info() << "Starting to delete and rewrite log"
  1945. " files.";
  1946. srv_log_file_size = srv_log_file_size_requested;
  1947. err = create_log_files(
  1948. logfilename, dirnamelen, flushed_lsn,
  1949. logfile0);
  1950. if (err == DB_SUCCESS) {
  1951. err = create_log_files_rename(
  1952. logfilename, dirnamelen, flushed_lsn,
  1953. logfile0);
  1954. }
  1955. if (err != DB_SUCCESS) {
  1956. return(srv_init_abort(err));
  1957. }
  1958. }
  1959. /* Validate a few system page types that were left
  1960. uninitialized by older versions of MySQL. */
  1961. if (!high_level_read_only) {
  1962. mtr_t mtr;
  1963. buf_block_t* block;
  1964. mtr.start();
  1965. mtr.set_sys_modified();
  1966. /* Bitmap page types will be reset in
  1967. buf_dblwr_check_block() without redo logging. */
  1968. block = buf_page_get(
  1969. page_id_t(IBUF_SPACE_ID,
  1970. FSP_IBUF_HEADER_PAGE_NO),
  1971. univ_page_size, RW_X_LATCH, &mtr);
  1972. fil_block_check_type(*block, FIL_PAGE_TYPE_SYS, &mtr);
  1973. /* Already MySQL 3.23.53 initialized
  1974. FSP_IBUF_TREE_ROOT_PAGE_NO to
  1975. FIL_PAGE_INDEX. No need to reset that one. */
  1976. block = buf_page_get(
  1977. page_id_t(TRX_SYS_SPACE, TRX_SYS_PAGE_NO),
  1978. univ_page_size, RW_X_LATCH, &mtr);
  1979. fil_block_check_type(*block, FIL_PAGE_TYPE_TRX_SYS,
  1980. &mtr);
  1981. block = buf_page_get(
  1982. page_id_t(TRX_SYS_SPACE,
  1983. FSP_FIRST_RSEG_PAGE_NO),
  1984. univ_page_size, RW_X_LATCH, &mtr);
  1985. fil_block_check_type(*block, FIL_PAGE_TYPE_SYS, &mtr);
  1986. block = buf_page_get(
  1987. page_id_t(TRX_SYS_SPACE, FSP_DICT_HDR_PAGE_NO),
  1988. univ_page_size, RW_X_LATCH, &mtr);
  1989. fil_block_check_type(*block, FIL_PAGE_TYPE_SYS, &mtr);
  1990. mtr.commit();
  1991. }
  1992. /* Roll back any recovered data dictionary transactions, so
  1993. that the data dictionary tables will be free of any locks.
  1994. The data dictionary latch should guarantee that there is at
  1995. most one data dictionary transaction active at a time. */
  1996. if (srv_force_recovery < SRV_FORCE_NO_TRX_UNDO) {
  1997. trx_rollback_or_clean_recovered(FALSE);
  1998. }
  1999. /* Fix-up truncate of tables in the system tablespace
  2000. if server crashed while truncate was active. The non-
  2001. system tables are done after tablespace discovery. Do
  2002. this now because this procedure assumes that no pages
  2003. have changed since redo recovery. Tablespace discovery
  2004. can do updates to pages in the system tablespace.*/
  2005. err = truncate_t::fixup_tables_in_system_tablespace();
  2006. if (srv_force_recovery < SRV_FORCE_NO_IBUF_MERGE) {
  2007. /* Open or Create SYS_TABLESPACES and SYS_DATAFILES
  2008. so that tablespace names and other metadata can be
  2009. found. */
  2010. err = dict_create_or_check_sys_tablespace();
  2011. if (err != DB_SUCCESS) {
  2012. return(srv_init_abort(err));
  2013. }
  2014. /* The following call is necessary for the insert
  2015. buffer to work with multiple tablespaces. We must
  2016. know the mapping between space id's and .ibd file
  2017. names.
  2018. In a crash recovery, we check that the info in data
  2019. dictionary is consistent with what we already know
  2020. about space id's from the calls to fil_ibd_load().
  2021. In a normal startup, we create the space objects for
  2022. every table in the InnoDB data dictionary that has
  2023. an .ibd file.
  2024. We also determine the maximum tablespace id used. */
  2025. dict_check_tablespaces_and_store_max_id();
  2026. }
  2027. /* Fix-up truncate of table if server crashed while truncate
  2028. was active. */
  2029. err = truncate_t::fixup_tables_in_non_system_tablespace();
  2030. if (err != DB_SUCCESS) {
  2031. return(srv_init_abort(err));
  2032. }
  2033. recv_recovery_rollback_active();
  2034. srv_startup_is_before_trx_rollback_phase = FALSE;
  2035. /* It is possible that file_format tag has never
  2036. been set. In this case we initialize it to minimum
  2037. value. Important to note that we can do it ONLY after
  2038. we have finished the recovery process so that the
  2039. image of TRX_SYS_PAGE_NO is not stale. */
  2040. trx_sys_file_format_tag_init();
  2041. }
  2042. ut_ad(err == DB_SUCCESS);
  2043. ut_a(sum_of_new_sizes != ULINT_UNDEFINED);
  2044. /* Create the doublewrite buffer to a new tablespace */
  2045. if (!srv_read_only_mode && srv_force_recovery < SRV_FORCE_NO_TRX_UNDO
  2046. && !buf_dblwr_create()) {
  2047. return(srv_init_abort(DB_ERROR));
  2048. }
  2049. /* Here the double write buffer has already been created and so
  2050. any new rollback segments will be allocated after the double
  2051. write buffer. The default segment should already exist.
  2052. We create the new segments only if it's a new database or
  2053. the database was shutdown cleanly. */
  2054. /* Note: When creating the extra rollback segments during an upgrade
  2055. we violate the latching order, even if the change buffer is empty.
  2056. We make an exception in sync0sync.cc and check srv_is_being_started
  2057. for that violation. It cannot create a deadlock because we are still
  2058. running in single threaded mode essentially. Only the IO threads
  2059. should be running at this stage. */
  2060. ut_a(srv_undo_logs > 0);
  2061. ut_a(srv_undo_logs <= TRX_SYS_N_RSEGS);
  2062. if (!trx_sys_create_rsegs()) {
  2063. return(srv_init_abort(DB_ERROR));
  2064. }
  2065. srv_startup_is_before_trx_rollback_phase = false;
  2066. if (!srv_read_only_mode) {
  2067. /* Create the thread which watches the timeouts
  2068. for lock waits */
  2069. thread_handles[2 + SRV_MAX_N_IO_THREADS] = os_thread_create(
  2070. lock_wait_timeout_thread,
  2071. NULL, thread_ids + 2 + SRV_MAX_N_IO_THREADS);
  2072. thread_started[2 + SRV_MAX_N_IO_THREADS] = true;
  2073. lock_sys->timeout_thread_active = true;
  2074. /* Create the thread which warns of long semaphore waits */
  2075. srv_error_monitor_active = true;
  2076. thread_handles[3 + SRV_MAX_N_IO_THREADS] = os_thread_create(
  2077. srv_error_monitor_thread,
  2078. NULL, thread_ids + 3 + SRV_MAX_N_IO_THREADS);
  2079. thread_started[3 + SRV_MAX_N_IO_THREADS] = true;
  2080. /* Create the thread which prints InnoDB monitor info */
  2081. srv_monitor_active = true;
  2082. thread_handles[4 + SRV_MAX_N_IO_THREADS] = os_thread_create(
  2083. srv_monitor_thread,
  2084. NULL, thread_ids + 4 + SRV_MAX_N_IO_THREADS);
  2085. thread_started[4 + SRV_MAX_N_IO_THREADS] = true;
  2086. srv_start_state |= SRV_START_STATE_LOCK_SYS
  2087. | SRV_START_STATE_MONITOR;
  2088. }
  2089. /* Create the SYS_FOREIGN and SYS_FOREIGN_COLS system tables */
  2090. err = dict_create_or_check_foreign_constraint_tables();
  2091. if (err == DB_SUCCESS) {
  2092. err = dict_create_or_check_sys_tablespace();
  2093. if (err == DB_SUCCESS) {
  2094. err = dict_create_or_check_sys_virtual();
  2095. }
  2096. }
  2097. switch (err) {
  2098. case DB_SUCCESS:
  2099. break;
  2100. case DB_READ_ONLY:
  2101. if (srv_force_recovery >= SRV_FORCE_NO_TRX_UNDO) {
  2102. break;
  2103. }
  2104. ib::error() << "Cannot create system tables in read-only mode";
  2105. /* fall through */
  2106. default:
  2107. return(srv_init_abort(err));
  2108. }
  2109. if (!srv_read_only_mode && srv_operation == SRV_OPERATION_NORMAL) {
  2110. /* Initialize the innodb_temporary tablespace and keep
  2111. it open until shutdown. */
  2112. err = srv_open_tmp_tablespace(create_new_db);
  2113. if (err != DB_SUCCESS) {
  2114. return(srv_init_abort(err));
  2115. }
  2116. trx_temp_rseg_create();
  2117. }
  2118. ut_a(trx_purge_state() == PURGE_STATE_INIT);
  2119. /* Create the master thread which does purge and other utility
  2120. operations */
  2121. if (!srv_read_only_mode
  2122. && srv_force_recovery < SRV_FORCE_NO_BACKGROUND) {
  2123. thread_handles[1 + SRV_MAX_N_IO_THREADS] = os_thread_create(
  2124. srv_master_thread,
  2125. NULL, thread_ids + (1 + SRV_MAX_N_IO_THREADS));
  2126. thread_started[1 + SRV_MAX_N_IO_THREADS] = true;
  2127. srv_start_state_set(SRV_START_STATE_MASTER);
  2128. }
  2129. if (!srv_read_only_mode
  2130. && (srv_operation == SRV_OPERATION_NORMAL
  2131. || srv_operation == SRV_OPERATION_RESTORE_ROLLBACK_XA)
  2132. && srv_force_recovery < SRV_FORCE_NO_BACKGROUND) {
  2133. srv_undo_sources = true;
  2134. /* Create the dict stats gathering thread */
  2135. srv_dict_stats_thread_active = true;
  2136. dict_stats_thread_handle = os_thread_create(
  2137. dict_stats_thread, NULL, NULL);
  2138. /* Create the thread that will optimize the FTS sub-system. */
  2139. fts_optimize_init();
  2140. thread_handles[5 + SRV_MAX_N_IO_THREADS] = os_thread_create(
  2141. srv_purge_coordinator_thread,
  2142. NULL, thread_ids + 5 + SRV_MAX_N_IO_THREADS);
  2143. thread_started[5 + SRV_MAX_N_IO_THREADS] = true;
  2144. ut_a(UT_ARR_SIZE(thread_ids)
  2145. > 5 + srv_n_purge_threads + SRV_MAX_N_IO_THREADS);
  2146. /* We've already created the purge coordinator thread above. */
  2147. for (i = 1; i < srv_n_purge_threads; ++i) {
  2148. thread_handles[5 + i + SRV_MAX_N_IO_THREADS] = os_thread_create(
  2149. srv_worker_thread, NULL,
  2150. thread_ids + 5 + i + SRV_MAX_N_IO_THREADS);
  2151. thread_started[5 + i + SRV_MAX_N_IO_THREADS] = true;
  2152. }
  2153. srv_start_wait_for_purge_to_start();
  2154. srv_start_state_set(SRV_START_STATE_PURGE);
  2155. } else {
  2156. purge_sys->state = PURGE_STATE_DISABLED;
  2157. }
  2158. srv_is_being_started = false;
  2159. if (!srv_read_only_mode) {
  2160. /* wake main loop of page cleaner up */
  2161. os_event_set(buf_flush_event);
  2162. if (srv_use_mtflush) {
  2163. /* Start multi-threaded flush threads */
  2164. mtflush_ctx = buf_mtflu_handler_init(
  2165. srv_mtflush_threads,
  2166. srv_buf_pool_instances);
  2167. /* Set up the thread ids */
  2168. buf_mtflu_set_thread_ids(
  2169. srv_mtflush_threads,
  2170. mtflush_ctx,
  2171. (thread_ids + 6 + 32));
  2172. }
  2173. }
  2174. if (srv_print_verbose_log) {
  2175. ib::info() << INNODB_VERSION_STR
  2176. << " started; log sequence number "
  2177. << srv_start_lsn;
  2178. }
  2179. if (srv_force_recovery > 0) {
  2180. ib::info() << "!!! innodb_force_recovery is set to "
  2181. << srv_force_recovery << " !!!";
  2182. }
  2183. if (srv_force_recovery == 0) {
  2184. /* In the insert buffer we may have even bigger tablespace
  2185. id's, because we may have dropped those tablespaces, but
  2186. insert buffer merge has not had time to clean the records from
  2187. the ibuf tree. */
  2188. ibuf_update_max_tablespace_id();
  2189. }
  2190. if (!srv_read_only_mode) {
  2191. if (create_new_db) {
  2192. srv_buffer_pool_load_at_startup = FALSE;
  2193. }
  2194. #ifdef WITH_WSREP
  2195. /*
  2196. Create the dump/load thread only when not running with
  2197. --wsrep-recover.
  2198. */
  2199. if (!wsrep_recovery) {
  2200. #endif /* WITH_WSREP */
  2201. /* Create the buffer pool dump/load thread */
  2202. srv_buf_dump_thread_active = true;
  2203. buf_dump_thread_handle=
  2204. os_thread_create(buf_dump_thread, NULL, NULL);
  2205. #ifdef WITH_WSREP
  2206. } else {
  2207. ib::warn() <<
  2208. "Skipping buffer pool dump/restore during "
  2209. "wsrep recovery.";
  2210. }
  2211. #endif /* WITH_WSREP */
  2212. /* Create thread(s) that handles key rotation. This is
  2213. needed already here as log_preflush_pool_modified_pages
  2214. will flush dirty pages and that might need e.g.
  2215. fil_crypt_threads_event. */
  2216. fil_system_enter();
  2217. btr_scrub_init();
  2218. fil_crypt_threads_init();
  2219. fil_system_exit();
  2220. /* Initialize online defragmentation. */
  2221. btr_defragment_init();
  2222. btr_defragment_thread_active = true;
  2223. os_thread_create(btr_defragment_thread, NULL, NULL);
  2224. srv_start_state |= SRV_START_STATE_REDO;
  2225. }
  2226. /* Create the buffer pool resize thread */
  2227. srv_buf_resize_thread_active = true;
  2228. os_thread_create(buf_resize_thread, NULL, NULL);
  2229. return(DB_SUCCESS);
  2230. }
  2231. /** Shut down background threads that can generate undo log. */
  2232. void
  2233. srv_shutdown_bg_undo_sources()
  2234. {
  2235. if (srv_undo_sources) {
  2236. ut_ad(!srv_read_only_mode);
  2237. srv_shutdown_state = SRV_SHUTDOWN_INITIATED;
  2238. fts_optimize_shutdown();
  2239. dict_stats_shutdown();
  2240. while (row_get_background_drop_list_len_low()) {
  2241. srv_inc_activity_count();
  2242. os_thread_yield();
  2243. }
  2244. srv_undo_sources = false;
  2245. }
  2246. }
  2247. /** Shut down InnoDB. */
  2248. void
  2249. innodb_shutdown()
  2250. {
  2251. ut_ad(!my_atomic_loadptr_explicit(reinterpret_cast<void**>
  2252. (&srv_running),
  2253. MY_MEMORY_ORDER_RELAXED));
  2254. ut_ad(!srv_undo_sources);
  2255. switch (srv_operation) {
  2256. case SRV_OPERATION_RESTORE_ROLLBACK_XA:
  2257. if (dberr_t err = fil_write_flushed_lsn(log_sys->lsn))
  2258. ib::error() << "Writing flushed lsn " << log_sys->lsn
  2259. << " failed; error=" << err;
  2260. /* fall through */
  2261. case SRV_OPERATION_BACKUP:
  2262. case SRV_OPERATION_RESTORE:
  2263. case SRV_OPERATION_RESTORE_DELTA:
  2264. case SRV_OPERATION_RESTORE_EXPORT:
  2265. fil_close_all_files();
  2266. break;
  2267. case SRV_OPERATION_NORMAL:
  2268. /* Shut down the persistent files. */
  2269. logs_empty_and_mark_files_at_shutdown();
  2270. if (ulint n_threads = srv_conc_get_active_threads()) {
  2271. ib::warn() << "Query counter shows "
  2272. << n_threads << " queries still"
  2273. " inside InnoDB at shutdown";
  2274. }
  2275. }
  2276. /* Exit any remaining threads. */
  2277. srv_shutdown_all_bg_threads();
  2278. if (srv_monitor_file) {
  2279. fclose(srv_monitor_file);
  2280. srv_monitor_file = 0;
  2281. if (srv_monitor_file_name) {
  2282. unlink(srv_monitor_file_name);
  2283. ut_free(srv_monitor_file_name);
  2284. }
  2285. }
  2286. if (srv_misc_tmpfile) {
  2287. fclose(srv_misc_tmpfile);
  2288. srv_misc_tmpfile = 0;
  2289. }
  2290. ut_ad(dict_stats_event || !srv_was_started || srv_read_only_mode);
  2291. ut_ad(dict_sys || !srv_was_started);
  2292. ut_ad(trx_sys || !srv_was_started);
  2293. ut_ad(buf_dblwr || !srv_was_started || srv_read_only_mode
  2294. || srv_force_recovery >= SRV_FORCE_NO_TRX_UNDO);
  2295. ut_ad(lock_sys || !srv_was_started);
  2296. #ifdef BTR_CUR_HASH_ADAPT
  2297. ut_ad(btr_search_sys || !srv_was_started);
  2298. #endif /* BTR_CUR_HASH_ADAPT */
  2299. ut_ad(ibuf || !srv_was_started);
  2300. ut_ad(log_sys || !srv_was_started);
  2301. if (dict_stats_event) {
  2302. dict_stats_thread_deinit();
  2303. }
  2304. if (srv_start_state_is_set(SRV_START_STATE_REDO)) {
  2305. ut_ad(!srv_read_only_mode);
  2306. /* srv_shutdown_bg_undo_sources() already invoked
  2307. fts_optimize_shutdown(); dict_stats_shutdown(); */
  2308. fil_crypt_threads_cleanup();
  2309. btr_scrub_cleanup();
  2310. btr_defragment_shutdown();
  2311. }
  2312. /* This must be disabled before closing the buffer pool
  2313. and closing the data dictionary. */
  2314. #ifdef BTR_CUR_HASH_ADAPT
  2315. if (dict_sys) {
  2316. btr_search_disable();
  2317. }
  2318. #endif /* BTR_CUR_HASH_ADAPT */
  2319. if (ibuf) {
  2320. ibuf_close();
  2321. }
  2322. if (log_sys) {
  2323. log_shutdown();
  2324. }
  2325. if (trx_sys) {
  2326. trx_sys_file_format_close();
  2327. trx_sys_close();
  2328. }
  2329. UT_DELETE(purge_sys);
  2330. purge_sys = NULL;
  2331. if (buf_dblwr) {
  2332. buf_dblwr_free();
  2333. }
  2334. if (lock_sys) {
  2335. lock_sys_close();
  2336. }
  2337. trx_pool_close();
  2338. /* We don't create these mutexes in RO mode because we don't create
  2339. the temp files that the cover. */
  2340. if (!srv_read_only_mode) {
  2341. mutex_free(&srv_monitor_file_mutex);
  2342. mutex_free(&srv_misc_tmpfile_mutex);
  2343. }
  2344. if (dict_sys) {
  2345. dict_close();
  2346. }
  2347. #ifdef BTR_CUR_HASH_ADAPT
  2348. if (btr_search_sys) {
  2349. btr_search_sys_free();
  2350. }
  2351. #endif /* BTR_CUR_HASH_ADAPT */
  2352. /* 3. Free all InnoDB's own mutexes and the os_fast_mutexes inside
  2353. them */
  2354. os_aio_free();
  2355. row_mysql_close();
  2356. srv_free();
  2357. fil_close();
  2358. /* 4. Free all allocated memory */
  2359. pars_lexer_close();
  2360. recv_sys_close();
  2361. ut_ad(buf_pool_ptr || !srv_was_started);
  2362. if (buf_pool_ptr) {
  2363. buf_pool_free(srv_buf_pool_instances);
  2364. }
  2365. sync_check_close();
  2366. if (dict_foreign_err_file) {
  2367. fclose(dict_foreign_err_file);
  2368. }
  2369. if (srv_was_started && srv_print_verbose_log) {
  2370. ib::info() << "Shutdown completed; log sequence number "
  2371. << srv_shutdown_lsn;
  2372. }
  2373. srv_start_state = SRV_START_STATE_NONE;
  2374. srv_was_started = false;
  2375. srv_start_has_been_called = false;
  2376. }
  2377. /** Get the meta-data filename from the table name for a
  2378. single-table tablespace.
  2379. @param[in] table table object
  2380. @param[out] filename filename
  2381. @param[in] max_len filename max length */
  2382. void
  2383. srv_get_meta_data_filename(
  2384. dict_table_t* table,
  2385. char* filename,
  2386. ulint max_len)
  2387. {
  2388. ulint len;
  2389. char* path;
  2390. /* Make sure the data_dir_path is set. */
  2391. dict_get_and_save_data_dir_path(table, false);
  2392. if (DICT_TF_HAS_DATA_DIR(table->flags)) {
  2393. ut_a(table->data_dir_path);
  2394. path = fil_make_filepath(
  2395. table->data_dir_path, table->name.m_name, CFG, true);
  2396. } else {
  2397. path = fil_make_filepath(NULL, table->name.m_name, CFG, false);
  2398. }
  2399. ut_a(path);
  2400. len = ut_strlen(path);
  2401. ut_a(max_len >= len);
  2402. strcpy(filename, path);
  2403. ut_free(path);
  2404. }