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.

2967 lines
80 KiB

9 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.
8 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).
8 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.
8 years ago
10 years ago
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.
8 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.
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.
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.
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.
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.
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.
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.
8 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.
8 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.
8 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.
8 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.
8 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
9 years ago
9 years ago
9 years ago
10 years ago
10 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.
8 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-15132 Avoid accessing the TRX_SYS page InnoDB maintains an internal persistent sequence of transaction identifiers. This sequence is used for assigning both transaction start identifiers (DB_TRX_ID=trx->id) and end identifiers (trx->no) as well as end identifiers for the mysql.transaction_registry table that was introduced in MDEV-12894. TRX_SYS_TRX_ID_WRITE_MARGIN: Remove. After this many updates of the sequence we used to update the TRX_SYS page. We can avoid accessing the TRX_SYS page if we modify the InnoDB startup so that resurrecting the sequence from other pages of the transaction system. TRX_SYS_TRX_ID_STORE: Deprecate. The field only exists for the purpose of upgrading from an earlier version of MySQL or MariaDB. Starting with this fix, MariaDB will rely on the fields TRX_UNDO_TRX_ID, TRX_UNDO_TRX_NO in the undo log header page of each non-committed transaction, and on the new field TRX_RSEG_MAX_TRX_ID in rollback segment header pages. Because of this change, setting innodb_force_recovery=5 or 6 may cause the system to recover with trx_sys.get_max_trx_id()==0. We must adjust checks for invalid DB_TRX_ID and PAGE_MAX_TRX_ID accordingly. We will change the startup and shutdown messages to display the trx_sys.get_max_trx_id() in addition to the log sequence number. trx_sys_t::flush_max_trx_id(): Remove. trx_undo_mem_create_at_db_start(), trx_undo_lists_init(): Add an output parameter max_trx_id, to be updated from TRX_UNDO_TRX_ID, TRX_UNDO_TRX_NO. TRX_RSEG_MAX_TRX_ID: New field, for persisting trx_sys.get_max_trx_id() at the time of the latest transaction commit. Startup is not reading the undo log pages of committed transactions. We want to avoid additional page accesses on startup, as well as trouble when all undo logs have been emptied. On startup, we will simply determine the maximum value from all pages that are being read anyway. TRX_RSEG_FORMAT: Redefined from TRX_RSEG_MAX_SIZE. Old versions of InnoDB wrote uninitialized garbage to unused data fields. Because of this, we cannot simply introduce a new field in the rollback segment pages and expect it to be always zero, like it would if the database was created by a recent enough InnoDB version. Luckily, it looks like the field TRX_RSEG_MAX_SIZE was always written as 0xfffffffe. We will indicate a new subformat of the page by writing 0 to this field. This has the nice side effect that after a downgrade to older versions of InnoDB, transactions should fail to allocate any undo log, that is, writes will be blocked. So, there is no problem of getting corrupted transaction identifiers after downgrading. trx_rseg_t::max_size: Remove. trx_rseg_header_create(): Remove the parameter max_size=ULINT_MAX. trx_purge_add_undo_to_history(): Update TRX_RSEG_MAX_SIZE (and TRX_RSEG_FORMAT if needed). This is invoked on transaction commit. trx_rseg_mem_restore(): If TRX_RSEG_FORMAT contains 0, read TRX_RSEG_MAX_SIZE. trx_rseg_array_init(): Invoke trx_sys.init_max_trx_id(max_trx_id + 1) where max_trx_id was the maximum that was encountered in the rollback segment pages and the undo log pages of recovered active, XA PREPARE, or some committed transactions. (See trx_purge_add_undo_to_history() which invokes trx_rsegf_set_nth_undo(..., FIL_NULL, ...); not all committed transactions will be immediately detached from the rollback segment header.)
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.
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.
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.
8 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
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.
8 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).
8 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.
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.
8 years ago
10 years ago
12 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
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.
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.
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.
8 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.
8 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.
8 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.
8 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.
8 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.
8 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.
8 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.
8 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.
8 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.
8 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-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.
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.
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.
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.
8 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).
8 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-12288 Reset DB_TRX_ID when the history is removed, to speed up MVCC Let InnoDB purge reset DB_TRX_ID,DB_ROLL_PTR when the history is removed. [TODO: It appears that the resetting is not taking place as often as it could be. We should test that a simple INSERT should eventually cause row_purge_reset_trx_id() to be invoked unless DROP TABLE is invoked soon enough.] The InnoDB clustered index record system columns DB_TRX_ID,DB_ROLL_PTR are used by multi-versioning. After the history is no longer needed, these columns can safely be reset to 0 and 1<<55 (to indicate a fresh insert). When a reader sees 0 in the DB_TRX_ID column, it can instantly determine that the record is present the read view. There is no need to acquire the transaction system mutex to check if the transaction exists, because writes can never be conducted by a transaction whose ID is 0. The persistent InnoDB undo log used to be split into two parts: insert_undo and update_undo. The insert_undo log was discarded at transaction commit or rollback, and the update_undo log was processed by the purge subsystem. As part of this change, we will only generate a single undo log for new transactions, and the purge subsystem will reset the DB_TRX_ID whenever a clustered index record is touched. That is, all persistent undo log will be preserved at transaction commit or rollback, to be removed by purge. The InnoDB redo log format is changed in two ways: We remove the redo log record type MLOG_UNDO_HDR_REUSE, and we introduce the MLOG_ZIP_WRITE_TRX_ID record for updating the DB_TRX_ID,DB_ROLL_PTR in a ROW_FORMAT=COMPRESSED table. This is also changing the format of persistent InnoDB data files: undo log and clustered index leaf page records. It will still be possible via import and export to exchange data files with earlier versions of MariaDB. The change to clustered index leaf page records is simple: we allow DB_TRX_ID to be 0. When it comes to the undo log, we must be able to upgrade from earlier MariaDB versions after a clean shutdown (no redo log to apply). While it would be nice to perform a slow shutdown (innodb_fast_shutdown=0) before an upgrade, to empty the undo logs, we cannot assume that this has been done. So, separate insert_undo log may exist for recovered uncommitted transactions. These transactions may be automatically rolled back, or they may be in XA PREPARE state, in which case InnoDB will preserve the transaction until an explicit XA COMMIT or XA ROLLBACK. Upgrade has been tested by starting up MariaDB 10.2 with ./mysql-test-run --manual-gdb innodb.read_only_recovery and then starting up this patched server with and without --innodb-read-only. trx_undo_ptr_t::undo: Renamed from update_undo. trx_undo_ptr_t::old_insert: Renamed from insert_undo. trx_rseg_t::undo_list: Renamed from update_undo_list. trx_rseg_t::undo_cached: Merged from update_undo_cached and insert_undo_cached. trx_rseg_t::old_insert_list: Renamed from insert_undo_list. row_purge_reset_trx_id(): New function to reset the columns. This will be called for all undo processing in purge that does not remove the clustered index record. trx_undo_update_rec_get_update(): Allow trx_id=0 when copying the old DB_TRX_ID of the record to the undo log. ReadView::changes_visible(): Allow id==0. (Return true for it. This is what speeds up the MVCC.) row_vers_impl_x_locked_low(), row_vers_build_for_semi_consistent_read(): Implement a fast path for DB_TRX_ID=0. Always initialize the TRX_UNDO_PAGE_TYPE to 0. Remove undo->type. MLOG_UNDO_HDR_REUSE: Remove. This changes the redo log format! innobase_start_or_create_for_mysql(): Set srv_undo_sources before starting any transactions. The parsing of the MLOG_ZIP_WRITE_TRX_ID record was successfully tested by running the following: ./mtr --parallel=auto --mysqld=--debug=d,ib_log innodb_zip.bug56680 grep MLOG_ZIP_WRITE_TRX_ID var/*/log/mysqld.1.err
8 years ago
MDEV-12288 Reset DB_TRX_ID when the history is removed, to speed up MVCC Let InnoDB purge reset DB_TRX_ID,DB_ROLL_PTR when the history is removed. [TODO: It appears that the resetting is not taking place as often as it could be. We should test that a simple INSERT should eventually cause row_purge_reset_trx_id() to be invoked unless DROP TABLE is invoked soon enough.] The InnoDB clustered index record system columns DB_TRX_ID,DB_ROLL_PTR are used by multi-versioning. After the history is no longer needed, these columns can safely be reset to 0 and 1<<55 (to indicate a fresh insert). When a reader sees 0 in the DB_TRX_ID column, it can instantly determine that the record is present the read view. There is no need to acquire the transaction system mutex to check if the transaction exists, because writes can never be conducted by a transaction whose ID is 0. The persistent InnoDB undo log used to be split into two parts: insert_undo and update_undo. The insert_undo log was discarded at transaction commit or rollback, and the update_undo log was processed by the purge subsystem. As part of this change, we will only generate a single undo log for new transactions, and the purge subsystem will reset the DB_TRX_ID whenever a clustered index record is touched. That is, all persistent undo log will be preserved at transaction commit or rollback, to be removed by purge. The InnoDB redo log format is changed in two ways: We remove the redo log record type MLOG_UNDO_HDR_REUSE, and we introduce the MLOG_ZIP_WRITE_TRX_ID record for updating the DB_TRX_ID,DB_ROLL_PTR in a ROW_FORMAT=COMPRESSED table. This is also changing the format of persistent InnoDB data files: undo log and clustered index leaf page records. It will still be possible via import and export to exchange data files with earlier versions of MariaDB. The change to clustered index leaf page records is simple: we allow DB_TRX_ID to be 0. When it comes to the undo log, we must be able to upgrade from earlier MariaDB versions after a clean shutdown (no redo log to apply). While it would be nice to perform a slow shutdown (innodb_fast_shutdown=0) before an upgrade, to empty the undo logs, we cannot assume that this has been done. So, separate insert_undo log may exist for recovered uncommitted transactions. These transactions may be automatically rolled back, or they may be in XA PREPARE state, in which case InnoDB will preserve the transaction until an explicit XA COMMIT or XA ROLLBACK. Upgrade has been tested by starting up MariaDB 10.2 with ./mysql-test-run --manual-gdb innodb.read_only_recovery and then starting up this patched server with and without --innodb-read-only. trx_undo_ptr_t::undo: Renamed from update_undo. trx_undo_ptr_t::old_insert: Renamed from insert_undo. trx_rseg_t::undo_list: Renamed from update_undo_list. trx_rseg_t::undo_cached: Merged from update_undo_cached and insert_undo_cached. trx_rseg_t::old_insert_list: Renamed from insert_undo_list. row_purge_reset_trx_id(): New function to reset the columns. This will be called for all undo processing in purge that does not remove the clustered index record. trx_undo_update_rec_get_update(): Allow trx_id=0 when copying the old DB_TRX_ID of the record to the undo log. ReadView::changes_visible(): Allow id==0. (Return true for it. This is what speeds up the MVCC.) row_vers_impl_x_locked_low(), row_vers_build_for_semi_consistent_read(): Implement a fast path for DB_TRX_ID=0. Always initialize the TRX_UNDO_PAGE_TYPE to 0. Remove undo->type. MLOG_UNDO_HDR_REUSE: Remove. This changes the redo log format! innobase_start_or_create_for_mysql(): Set srv_undo_sources before starting any transactions. The parsing of the MLOG_ZIP_WRITE_TRX_ID record was successfully tested by running the following: ./mtr --parallel=auto --mysqld=--debug=d,ib_log innodb_zip.bug56680 grep MLOG_ZIP_WRITE_TRX_ID var/*/log/mysqld.1.err
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.
8 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).
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.
8 years ago
MDEV-15132 Avoid accessing the TRX_SYS page InnoDB maintains an internal persistent sequence of transaction identifiers. This sequence is used for assigning both transaction start identifiers (DB_TRX_ID=trx->id) and end identifiers (trx->no) as well as end identifiers for the mysql.transaction_registry table that was introduced in MDEV-12894. TRX_SYS_TRX_ID_WRITE_MARGIN: Remove. After this many updates of the sequence we used to update the TRX_SYS page. We can avoid accessing the TRX_SYS page if we modify the InnoDB startup so that resurrecting the sequence from other pages of the transaction system. TRX_SYS_TRX_ID_STORE: Deprecate. The field only exists for the purpose of upgrading from an earlier version of MySQL or MariaDB. Starting with this fix, MariaDB will rely on the fields TRX_UNDO_TRX_ID, TRX_UNDO_TRX_NO in the undo log header page of each non-committed transaction, and on the new field TRX_RSEG_MAX_TRX_ID in rollback segment header pages. Because of this change, setting innodb_force_recovery=5 or 6 may cause the system to recover with trx_sys.get_max_trx_id()==0. We must adjust checks for invalid DB_TRX_ID and PAGE_MAX_TRX_ID accordingly. We will change the startup and shutdown messages to display the trx_sys.get_max_trx_id() in addition to the log sequence number. trx_sys_t::flush_max_trx_id(): Remove. trx_undo_mem_create_at_db_start(), trx_undo_lists_init(): Add an output parameter max_trx_id, to be updated from TRX_UNDO_TRX_ID, TRX_UNDO_TRX_NO. TRX_RSEG_MAX_TRX_ID: New field, for persisting trx_sys.get_max_trx_id() at the time of the latest transaction commit. Startup is not reading the undo log pages of committed transactions. We want to avoid additional page accesses on startup, as well as trouble when all undo logs have been emptied. On startup, we will simply determine the maximum value from all pages that are being read anyway. TRX_RSEG_FORMAT: Redefined from TRX_RSEG_MAX_SIZE. Old versions of InnoDB wrote uninitialized garbage to unused data fields. Because of this, we cannot simply introduce a new field in the rollback segment pages and expect it to be always zero, like it would if the database was created by a recent enough InnoDB version. Luckily, it looks like the field TRX_RSEG_MAX_SIZE was always written as 0xfffffffe. We will indicate a new subformat of the page by writing 0 to this field. This has the nice side effect that after a downgrade to older versions of InnoDB, transactions should fail to allocate any undo log, that is, writes will be blocked. So, there is no problem of getting corrupted transaction identifiers after downgrading. trx_rseg_t::max_size: Remove. trx_rseg_header_create(): Remove the parameter max_size=ULINT_MAX. trx_purge_add_undo_to_history(): Update TRX_RSEG_MAX_SIZE (and TRX_RSEG_FORMAT if needed). This is invoked on transaction commit. trx_rseg_mem_restore(): If TRX_RSEG_FORMAT contains 0, read TRX_RSEG_MAX_SIZE. trx_rseg_array_init(): Invoke trx_sys.init_max_trx_id(max_trx_id + 1) where max_trx_id was the maximum that was encountered in the rollback segment pages and the undo log pages of recovered active, XA PREPARE, or some committed transactions. (See trx_purge_add_undo_to_history() which invokes trx_rsegf_set_nth_undo(..., FIL_NULL, ...); not all committed transactions will be immediately detached from the rollback segment header.)
8 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).
8 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).
8 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.
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.
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.
8 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
MDEV-15132 Avoid accessing the TRX_SYS page InnoDB maintains an internal persistent sequence of transaction identifiers. This sequence is used for assigning both transaction start identifiers (DB_TRX_ID=trx->id) and end identifiers (trx->no) as well as end identifiers for the mysql.transaction_registry table that was introduced in MDEV-12894. TRX_SYS_TRX_ID_WRITE_MARGIN: Remove. After this many updates of the sequence we used to update the TRX_SYS page. We can avoid accessing the TRX_SYS page if we modify the InnoDB startup so that resurrecting the sequence from other pages of the transaction system. TRX_SYS_TRX_ID_STORE: Deprecate. The field only exists for the purpose of upgrading from an earlier version of MySQL or MariaDB. Starting with this fix, MariaDB will rely on the fields TRX_UNDO_TRX_ID, TRX_UNDO_TRX_NO in the undo log header page of each non-committed transaction, and on the new field TRX_RSEG_MAX_TRX_ID in rollback segment header pages. Because of this change, setting innodb_force_recovery=5 or 6 may cause the system to recover with trx_sys.get_max_trx_id()==0. We must adjust checks for invalid DB_TRX_ID and PAGE_MAX_TRX_ID accordingly. We will change the startup and shutdown messages to display the trx_sys.get_max_trx_id() in addition to the log sequence number. trx_sys_t::flush_max_trx_id(): Remove. trx_undo_mem_create_at_db_start(), trx_undo_lists_init(): Add an output parameter max_trx_id, to be updated from TRX_UNDO_TRX_ID, TRX_UNDO_TRX_NO. TRX_RSEG_MAX_TRX_ID: New field, for persisting trx_sys.get_max_trx_id() at the time of the latest transaction commit. Startup is not reading the undo log pages of committed transactions. We want to avoid additional page accesses on startup, as well as trouble when all undo logs have been emptied. On startup, we will simply determine the maximum value from all pages that are being read anyway. TRX_RSEG_FORMAT: Redefined from TRX_RSEG_MAX_SIZE. Old versions of InnoDB wrote uninitialized garbage to unused data fields. Because of this, we cannot simply introduce a new field in the rollback segment pages and expect it to be always zero, like it would if the database was created by a recent enough InnoDB version. Luckily, it looks like the field TRX_RSEG_MAX_SIZE was always written as 0xfffffffe. We will indicate a new subformat of the page by writing 0 to this field. This has the nice side effect that after a downgrade to older versions of InnoDB, transactions should fail to allocate any undo log, that is, writes will be blocked. So, there is no problem of getting corrupted transaction identifiers after downgrading. trx_rseg_t::max_size: Remove. trx_rseg_header_create(): Remove the parameter max_size=ULINT_MAX. trx_purge_add_undo_to_history(): Update TRX_RSEG_MAX_SIZE (and TRX_RSEG_FORMAT if needed). This is invoked on transaction commit. trx_rseg_mem_restore(): If TRX_RSEG_FORMAT contains 0, read TRX_RSEG_MAX_SIZE. trx_rseg_array_init(): Invoke trx_sys.init_max_trx_id(max_trx_id + 1) where max_trx_id was the maximum that was encountered in the rollback segment pages and the undo log pages of recovered active, XA PREPARE, or some committed transactions. (See trx_purge_add_undo_to_history() which invokes trx_rsegf_set_nth_undo(..., FIL_NULL, ...); not all committed transactions will be immediately detached from the rollback segment header.)
8 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, 2018, 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, Suite 500, 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 "ha_prototypes.h"
  34. #include "mysqld.h"
  35. #include "mysql/psi/mysql_stage.h"
  36. #include "mysql/psi/psi.h"
  37. #include "row0ftsort.h"
  38. #include "ut0mem.h"
  39. #include "ut0timer.h"
  40. #include "mem0mem.h"
  41. #include "data0data.h"
  42. #include "data0type.h"
  43. #include "dict0dict.h"
  44. #include "buf0buf.h"
  45. #include "buf0dump.h"
  46. #include "os0file.h"
  47. #include "os0thread.h"
  48. #include "fil0fil.h"
  49. #include "fil0crypt.h"
  50. #include "fsp0fsp.h"
  51. #include "rem0rec.h"
  52. #include "mtr0mtr.h"
  53. #include "log0crypt.h"
  54. #include "log0recv.h"
  55. #include "page0page.h"
  56. #include "page0cur.h"
  57. #include "trx0trx.h"
  58. #include "trx0sys.h"
  59. #include "btr0btr.h"
  60. #include "btr0cur.h"
  61. #include "rem0rec.h"
  62. #include "ibuf0ibuf.h"
  63. #include "srv0start.h"
  64. #include "srv0srv.h"
  65. #include "btr0defragment.h"
  66. #include "fsp0sysspace.h"
  67. #include "row0trunc.h"
  68. #include "mysql/service_wsrep.h" /* wsrep_recovery */
  69. #include "trx0rseg.h"
  70. #include "os0proc.h"
  71. #include "buf0flu.h"
  72. #include "buf0rea.h"
  73. #include "dict0boot.h"
  74. #include "dict0load.h"
  75. #include "dict0stats_bg.h"
  76. #include "que0que.h"
  77. #include "lock0lock.h"
  78. #include "trx0roll.h"
  79. #include "trx0purge.h"
  80. #include "lock0lock.h"
  81. #include "pars0pars.h"
  82. #include "btr0sea.h"
  83. #include "rem0cmp.h"
  84. #include "dict0crea.h"
  85. #include "row0ins.h"
  86. #include "row0sel.h"
  87. #include "row0upd.h"
  88. #include "row0row.h"
  89. #include "row0mysql.h"
  90. #include "row0trunc.h"
  91. #include "btr0pcur.h"
  92. #include "os0event.h"
  93. #include "zlib.h"
  94. #include "ut0crc32.h"
  95. #include "btr0scrub.h"
  96. #include "ut0new.h"
  97. #ifdef HAVE_LZO1X
  98. #include <lzo/lzo1x.h>
  99. extern bool srv_lzo_disabled;
  100. #endif /* HAVE_LZO1X */
  101. /** Log sequence number immediately after startup */
  102. lsn_t srv_start_lsn;
  103. /** Log sequence number at shutdown */
  104. lsn_t srv_shutdown_lsn;
  105. /** TRUE if a raw partition is in use */
  106. ibool srv_start_raw_disk_in_use;
  107. /** Number of IO threads to use */
  108. ulint srv_n_file_io_threads;
  109. /** UNDO tablespaces starts with space id. */
  110. ulint srv_undo_space_id_start;
  111. /** TRUE if the server is being started, before rolling back any
  112. incomplete transactions */
  113. bool srv_startup_is_before_trx_rollback_phase;
  114. /** TRUE if the server is being started */
  115. bool srv_is_being_started;
  116. /** TRUE if SYS_TABLESPACES is available for lookups */
  117. bool srv_sys_tablespaces_open;
  118. /** TRUE if the server was successfully started */
  119. bool srv_was_started;
  120. /** The original value of srv_log_file_size (innodb_log_file_size) */
  121. static ulonglong srv_log_file_size_requested;
  122. /** TRUE if innobase_start_or_create_for_mysql() has been called */
  123. static bool srv_start_has_been_called;
  124. /** Whether any undo log records can be generated */
  125. UNIV_INTERN bool srv_undo_sources;
  126. #ifdef UNIV_DEBUG
  127. /** InnoDB system tablespace to set during recovery */
  128. UNIV_INTERN uint srv_sys_space_size_debug;
  129. /** whether redo log files have been created at startup */
  130. UNIV_INTERN bool srv_log_files_created;
  131. #endif /* UNIV_DEBUG */
  132. /** Bit flags for tracking background thread creation. They are used to
  133. determine which threads need to be stopped if we need to abort during
  134. the initialisation step. */
  135. enum srv_start_state_t {
  136. /** No thread started */
  137. SRV_START_STATE_NONE = 0, /*!< No thread started */
  138. /** lock_wait_timeout_thread started */
  139. SRV_START_STATE_LOCK_SYS = 1, /*!< Started lock-timeout
  140. thread. */
  141. /** buf_flush_page_cleaner_coordinator,
  142. buf_flush_page_cleaner_worker started */
  143. SRV_START_STATE_IO = 2,
  144. /** srv_error_monitor_thread, srv_monitor_thread started */
  145. SRV_START_STATE_MONITOR = 4,
  146. /** srv_master_thread started */
  147. SRV_START_STATE_MASTER = 8,
  148. /** srv_purge_coordinator_thread, srv_worker_thread started */
  149. SRV_START_STATE_PURGE = 16,
  150. /** fil_crypt_thread, btr_defragment_thread started
  151. (all background threads that can generate redo log but not undo log */
  152. SRV_START_STATE_REDO = 32
  153. };
  154. /** Track server thrd starting phases */
  155. static ulint srv_start_state;
  156. /** At a shutdown this value climbs from SRV_SHUTDOWN_NONE to
  157. SRV_SHUTDOWN_CLEANUP and then to SRV_SHUTDOWN_LAST_PHASE, and so on */
  158. enum srv_shutdown_t srv_shutdown_state = SRV_SHUTDOWN_NONE;
  159. /** Files comprising the system tablespace */
  160. pfs_os_file_t files[1000];
  161. /** io_handler_thread parameters for thread identification */
  162. static ulint n[SRV_MAX_N_IO_THREADS + 6];
  163. /** io_handler_thread identifiers, 32 is the maximum number of purge threads */
  164. /** 6 is the ? */
  165. #define START_OLD_THREAD_CNT (SRV_MAX_N_IO_THREADS + 6 + 32)
  166. static os_thread_id_t thread_ids[SRV_MAX_N_IO_THREADS + 6 + 32];
  167. /** Thead handles */
  168. static os_thread_t thread_handles[SRV_MAX_N_IO_THREADS + 6 + 32];
  169. static os_thread_t buf_dump_thread_handle;
  170. static os_thread_t dict_stats_thread_handle;
  171. /** Status variables, is thread started ?*/
  172. static bool thread_started[SRV_MAX_N_IO_THREADS + 6 + 32] = {false};
  173. /** Name of srv_monitor_file */
  174. static char* srv_monitor_file_name;
  175. /** Minimum expected tablespace size. (10M) */
  176. static const ulint MIN_EXPECTED_TABLESPACE_SIZE = 5 * 1024 * 1024;
  177. /** */
  178. #define SRV_MAX_N_PENDING_SYNC_IOS 100
  179. #ifdef UNIV_PFS_THREAD
  180. /* Keys to register InnoDB threads with performance schema */
  181. mysql_pfs_key_t buf_dump_thread_key;
  182. mysql_pfs_key_t dict_stats_thread_key;
  183. mysql_pfs_key_t io_handler_thread_key;
  184. mysql_pfs_key_t io_ibuf_thread_key;
  185. mysql_pfs_key_t io_log_thread_key;
  186. mysql_pfs_key_t io_read_thread_key;
  187. mysql_pfs_key_t io_write_thread_key;
  188. mysql_pfs_key_t srv_error_monitor_thread_key;
  189. mysql_pfs_key_t srv_lock_timeout_thread_key;
  190. mysql_pfs_key_t srv_master_thread_key;
  191. mysql_pfs_key_t srv_monitor_thread_key;
  192. mysql_pfs_key_t srv_purge_thread_key;
  193. mysql_pfs_key_t srv_worker_thread_key;
  194. #endif /* UNIV_PFS_THREAD */
  195. #ifdef HAVE_PSI_STAGE_INTERFACE
  196. /** Array of all InnoDB stage events for monitoring activities via
  197. performance schema. */
  198. static PSI_stage_info* srv_stages[] =
  199. {
  200. &srv_stage_alter_table_end,
  201. &srv_stage_alter_table_flush,
  202. &srv_stage_alter_table_insert,
  203. &srv_stage_alter_table_log_index,
  204. &srv_stage_alter_table_log_table,
  205. &srv_stage_alter_table_merge_sort,
  206. &srv_stage_alter_table_read_pk_internal_sort,
  207. &srv_stage_buffer_pool_load,
  208. };
  209. #endif /* HAVE_PSI_STAGE_INTERFACE */
  210. /*********************************************************************//**
  211. Check if a file can be opened in read-write mode.
  212. @return true if it doesn't exist or can be opened in rw mode. */
  213. static
  214. bool
  215. srv_file_check_mode(
  216. /*================*/
  217. const char* name) /*!< in: filename to check */
  218. {
  219. os_file_stat_t stat;
  220. memset(&stat, 0x0, sizeof(stat));
  221. dberr_t err = os_file_get_status(
  222. name, &stat, true, srv_read_only_mode);
  223. if (err == DB_FAIL) {
  224. ib::error() << "os_file_get_status() failed on '" << name
  225. << "'. Can't determine file permissions.";
  226. return(false);
  227. } else if (err == DB_SUCCESS) {
  228. /* Note: stat.rw_perm is only valid of files */
  229. if (stat.type == OS_FILE_TYPE_FILE) {
  230. if (!stat.rw_perm) {
  231. const char* mode = srv_read_only_mode
  232. ? "read" : "read-write";
  233. ib::error() << name << " can't be opened in "
  234. << mode << " mode.";
  235. return(false);
  236. }
  237. } else {
  238. /* Not a regular file, bail out. */
  239. ib::error() << "'" << name << "' not a regular file.";
  240. return(false);
  241. }
  242. } else {
  243. /* This is OK. If the file create fails on RO media, there
  244. is nothing we can do. */
  245. ut_a(err == DB_NOT_FOUND);
  246. }
  247. return(true);
  248. }
  249. /********************************************************************//**
  250. I/o-handler thread function.
  251. @return OS_THREAD_DUMMY_RETURN */
  252. extern "C"
  253. os_thread_ret_t
  254. DECLARE_THREAD(io_handler_thread)(
  255. /*==============================*/
  256. void* arg) /*!< in: pointer to the number of the segment in
  257. the aio array */
  258. {
  259. ulint segment;
  260. segment = *((ulint*) arg);
  261. #ifdef UNIV_DEBUG_THREAD_CREATION
  262. ib::info() << "Io handler thread " << segment << " starts, id "
  263. << os_thread_pf(os_thread_get_curr_id());
  264. #endif
  265. /* For read only mode, we don't need ibuf and log I/O thread.
  266. Please see innobase_start_or_create_for_mysql() */
  267. ulint start = (srv_read_only_mode) ? 0 : 2;
  268. if (segment < start) {
  269. if (segment == 0) {
  270. pfs_register_thread(io_ibuf_thread_key);
  271. } else {
  272. ut_ad(segment == 1);
  273. pfs_register_thread(io_log_thread_key);
  274. }
  275. } else if (segment >= start
  276. && segment < (start + srv_n_read_io_threads)) {
  277. pfs_register_thread(io_read_thread_key);
  278. } else if (segment >= (start + srv_n_read_io_threads)
  279. && segment < (start + srv_n_read_io_threads
  280. + srv_n_write_io_threads)) {
  281. pfs_register_thread(io_write_thread_key);
  282. } else {
  283. pfs_register_thread(io_handler_thread_key);
  284. }
  285. while (srv_shutdown_state != SRV_SHUTDOWN_EXIT_THREADS
  286. || buf_page_cleaner_is_active
  287. || !os_aio_all_slots_free()) {
  288. fil_aio_wait(segment);
  289. }
  290. /* We count the number of threads in os_thread_exit(). A created
  291. thread should always use that to exit and not use return() to exit.
  292. The thread actually never comes here because it is exited in an
  293. os_event_wait(). */
  294. os_thread_exit();
  295. OS_THREAD_DUMMY_RETURN;
  296. }
  297. /*********************************************************************//**
  298. Creates a log file.
  299. @return DB_SUCCESS or error code */
  300. static MY_ATTRIBUTE((nonnull, warn_unused_result))
  301. dberr_t
  302. create_log_file(
  303. /*============*/
  304. pfs_os_file_t* file, /*!< out: file handle */
  305. const char* name) /*!< in: log file name */
  306. {
  307. bool ret;
  308. *file = os_file_create(
  309. innodb_log_file_key, name,
  310. OS_FILE_CREATE|OS_FILE_ON_ERROR_NO_EXIT, OS_FILE_NORMAL,
  311. OS_LOG_FILE, srv_read_only_mode, &ret);
  312. if (!ret) {
  313. ib::error() << "Cannot create " << name;
  314. return(DB_ERROR);
  315. }
  316. ib::info() << "Setting log file " << name << " size to "
  317. << srv_log_file_size << " bytes";
  318. ret = os_file_set_size(name, *file, srv_log_file_size);
  319. if (!ret) {
  320. ib::error() << "Cannot set log file " << name << " size to "
  321. << srv_log_file_size << " bytes";
  322. return(DB_ERROR);
  323. }
  324. ret = os_file_close(*file);
  325. ut_a(ret);
  326. return(DB_SUCCESS);
  327. }
  328. /** Initial number of the first redo log file */
  329. #define INIT_LOG_FILE0 (SRV_N_LOG_FILES_MAX + 1)
  330. /** Delete all log files.
  331. @param[in,out] logfilename buffer for log file name
  332. @param[in] dirnamelen length of the directory path
  333. @param[in] n_files number of files to delete
  334. @param[in] i first file to delete */
  335. static
  336. void
  337. delete_log_files(char* logfilename, size_t dirnamelen, uint n_files, uint i=0)
  338. {
  339. /* Remove any old log files. */
  340. for (; i < n_files; i++) {
  341. sprintf(logfilename + dirnamelen, "ib_logfile%u", i);
  342. /* Ignore errors about non-existent files or files
  343. that cannot be removed. The create_log_file() will
  344. return an error when the file exists. */
  345. #ifdef _WIN32
  346. DeleteFile((LPCTSTR) logfilename);
  347. #else
  348. unlink(logfilename);
  349. #endif
  350. }
  351. }
  352. /*********************************************************************//**
  353. Creates all log files.
  354. @return DB_SUCCESS or error code */
  355. static
  356. dberr_t
  357. create_log_files(
  358. /*=============*/
  359. char* logfilename, /*!< in/out: buffer for log file name */
  360. size_t dirnamelen, /*!< in: length of the directory path */
  361. lsn_t lsn, /*!< in: FIL_PAGE_FILE_FLUSH_LSN value */
  362. char*& logfile0) /*!< out: name of the first log file */
  363. {
  364. dberr_t err;
  365. if (srv_read_only_mode) {
  366. ib::error() << "Cannot create log files in read-only mode";
  367. return(DB_READ_ONLY);
  368. }
  369. /* Crashing after deleting the first file should be
  370. recoverable. The buffer pool was clean, and we can simply
  371. create all log files from the scratch. */
  372. DBUG_EXECUTE_IF("innodb_log_abort_6",
  373. delete_log_files(logfilename, dirnamelen, 1);
  374. return(DB_ERROR););
  375. delete_log_files(logfilename, dirnamelen, INIT_LOG_FILE0 + 1);
  376. DBUG_PRINT("ib_log", ("After innodb_log_abort_6"));
  377. ut_ad(!buf_pool_check_no_pending_io());
  378. DBUG_EXECUTE_IF("innodb_log_abort_7", return(DB_ERROR););
  379. DBUG_PRINT("ib_log", ("After innodb_log_abort_7"));
  380. for (unsigned i = 0; i < srv_n_log_files; i++) {
  381. sprintf(logfilename + dirnamelen,
  382. "ib_logfile%u", i ? i : INIT_LOG_FILE0);
  383. err = create_log_file(&files[i], logfilename);
  384. if (err != DB_SUCCESS) {
  385. return(err);
  386. }
  387. }
  388. DBUG_EXECUTE_IF("innodb_log_abort_8", return(DB_ERROR););
  389. DBUG_PRINT("ib_log", ("After innodb_log_abort_8"));
  390. /* We did not create the first log file initially as
  391. ib_logfile0, so that crash recovery cannot find it until it
  392. has been completed and renamed. */
  393. sprintf(logfilename + dirnamelen, "ib_logfile%u", INIT_LOG_FILE0);
  394. fil_space_t* log_space = fil_space_create(
  395. "innodb_redo_log", SRV_LOG_SPACE_FIRST_ID, 0, FIL_TYPE_LOG,
  396. NULL/* innodb_encrypt_log works at a different level */);
  397. ut_a(fil_validate());
  398. ut_a(log_space != NULL);
  399. const ulint size = ulint(srv_log_file_size >> srv_page_size_shift);
  400. logfile0 = fil_node_create(
  401. logfilename, size, log_space, false, false);
  402. ut_a(logfile0);
  403. for (unsigned i = 1; i < srv_n_log_files; i++) {
  404. sprintf(logfilename + dirnamelen, "ib_logfile%u", i);
  405. if (!fil_node_create(logfilename, size,
  406. log_space, false, false)) {
  407. ib::error()
  408. << "Cannot create file node for log file "
  409. << logfilename;
  410. return(DB_ERROR);
  411. }
  412. }
  413. log_init(srv_n_log_files);
  414. if (!log_set_capacity(srv_log_file_size_requested)) {
  415. return(DB_ERROR);
  416. }
  417. fil_open_log_and_system_tablespace_files();
  418. /* Create a log checkpoint. */
  419. log_mutex_enter();
  420. if (log_sys->is_encrypted() && !log_crypt_init()) {
  421. return(DB_ERROR);
  422. }
  423. ut_d(recv_no_log_write = false);
  424. recv_reset_logs(lsn);
  425. log_mutex_exit();
  426. return(DB_SUCCESS);
  427. }
  428. /** Rename the first redo log file.
  429. @param[in,out] logfilename buffer for the log file name
  430. @param[in] dirnamelen length of the directory path
  431. @param[in] lsn FIL_PAGE_FILE_FLUSH_LSN value
  432. @param[in,out] logfile0 name of the first log file
  433. @return error code
  434. @retval DB_SUCCESS on successful operation */
  435. MY_ATTRIBUTE((warn_unused_result, nonnull))
  436. static
  437. dberr_t
  438. create_log_files_rename(
  439. /*====================*/
  440. char* logfilename, /*!< in/out: buffer for log file name */
  441. size_t dirnamelen, /*!< in: length of the directory path */
  442. lsn_t lsn, /*!< in: FIL_PAGE_FILE_FLUSH_LSN value */
  443. char* logfile0) /*!< in/out: name of the first log file */
  444. {
  445. /* If innodb_flush_method=O_DSYNC,
  446. we need to explicitly flush the log buffers. */
  447. fil_flush(SRV_LOG_SPACE_FIRST_ID);
  448. ut_ad(!srv_log_files_created);
  449. ut_d(srv_log_files_created = true);
  450. DBUG_EXECUTE_IF("innodb_log_abort_9", return(DB_ERROR););
  451. DBUG_PRINT("ib_log", ("After innodb_log_abort_9"));
  452. /* Close the log files, so that we can rename
  453. the first one. */
  454. fil_close_log_files(false);
  455. /* Rename the first log file, now that a log
  456. checkpoint has been created. */
  457. sprintf(logfilename + dirnamelen, "ib_logfile%u", 0);
  458. ib::info() << "Renaming log file " << logfile0 << " to "
  459. << logfilename;
  460. log_mutex_enter();
  461. ut_ad(strlen(logfile0) == 2 + strlen(logfilename));
  462. dberr_t err = os_file_rename(
  463. innodb_log_file_key, logfile0, logfilename)
  464. ? DB_SUCCESS : DB_ERROR;
  465. /* Replace the first file with ib_logfile0. */
  466. strcpy(logfile0, logfilename);
  467. log_mutex_exit();
  468. DBUG_EXECUTE_IF("innodb_log_abort_10", err = DB_ERROR;);
  469. if (err == DB_SUCCESS) {
  470. fil_open_log_and_system_tablespace_files();
  471. ib::info() << "New log files created, LSN=" << lsn;
  472. }
  473. return(err);
  474. }
  475. /*********************************************************************//**
  476. Opens a log file.
  477. @return DB_SUCCESS or error code */
  478. static MY_ATTRIBUTE((nonnull, warn_unused_result))
  479. dberr_t
  480. open_log_file(
  481. /*==========*/
  482. pfs_os_file_t* file, /*!< out: file handle */
  483. const char* name, /*!< in: log file name */
  484. os_offset_t* size) /*!< out: file size */
  485. {
  486. bool ret;
  487. *file = os_file_create(innodb_log_file_key, name,
  488. OS_FILE_OPEN, OS_FILE_AIO,
  489. OS_LOG_FILE, srv_read_only_mode, &ret);
  490. if (!ret) {
  491. ib::error() << "Unable to open '" << name << "'";
  492. return(DB_ERROR);
  493. }
  494. *size = os_file_get_size(*file);
  495. ret = os_file_close(*file);
  496. ut_a(ret);
  497. return(DB_SUCCESS);
  498. }
  499. /*********************************************************************//**
  500. Create undo tablespace.
  501. @return DB_SUCCESS or error code */
  502. static
  503. dberr_t
  504. srv_undo_tablespace_create(
  505. /*=======================*/
  506. const char* name, /*!< in: tablespace name */
  507. ulint size) /*!< in: tablespace size in pages */
  508. {
  509. pfs_os_file_t fh;
  510. bool ret;
  511. dberr_t err = DB_SUCCESS;
  512. os_file_create_subdirs_if_needed(name);
  513. fh = os_file_create(
  514. innodb_data_file_key,
  515. name,
  516. srv_read_only_mode ? OS_FILE_OPEN : OS_FILE_CREATE,
  517. OS_FILE_NORMAL, OS_DATA_FILE, srv_read_only_mode, &ret);
  518. if (srv_read_only_mode && ret) {
  519. ib::info() << name << " opened in read-only mode";
  520. } else if (ret == FALSE) {
  521. if (os_file_get_last_error(false) != OS_FILE_ALREADY_EXISTS
  522. #ifdef UNIV_AIX
  523. /* AIX 5.1 after security patch ML7 may have
  524. errno set to 0 here, which causes our function
  525. to return 100; work around that AIX problem */
  526. && os_file_get_last_error(false) != 100
  527. #endif /* UNIV_AIX */
  528. ) {
  529. ib::error() << "Can't create UNDO tablespace "
  530. << name;
  531. }
  532. err = DB_ERROR;
  533. } else {
  534. ut_a(!srv_read_only_mode);
  535. /* We created the data file and now write it full of zeros */
  536. ib::info() << "Data file " << name << " did not exist: new to"
  537. " be created";
  538. ib::info() << "Setting file " << name << " size to "
  539. << (size >> (20 - UNIV_PAGE_SIZE_SHIFT)) << " MB";
  540. ib::info() << "Database physically writes the file full: "
  541. << "wait...";
  542. ret = os_file_set_size(
  543. name, fh, os_offset_t(size) << UNIV_PAGE_SIZE_SHIFT);
  544. if (!ret) {
  545. ib::info() << "Error in creating " << name
  546. << ": probably out of disk space";
  547. err = DB_ERROR;
  548. }
  549. os_file_close(fh);
  550. }
  551. return(err);
  552. }
  553. /*********************************************************************//**
  554. Open an undo tablespace.
  555. @return DB_SUCCESS or error code */
  556. static
  557. dberr_t
  558. srv_undo_tablespace_open(
  559. /*=====================*/
  560. const char* name, /*!< in: tablespace file name */
  561. ulint space_id) /*!< in: tablespace id */
  562. {
  563. pfs_os_file_t fh;
  564. bool ret;
  565. dberr_t err = DB_ERROR;
  566. char undo_name[sizeof "innodb_undo000"];
  567. snprintf(undo_name, sizeof(undo_name),
  568. "innodb_undo%03u", static_cast<unsigned>(space_id));
  569. if (!srv_file_check_mode(name)) {
  570. ib::error() << "UNDO tablespaces must be " <<
  571. (srv_read_only_mode ? "writable" : "readable") << "!";
  572. return(DB_ERROR);
  573. }
  574. fh = os_file_create(
  575. innodb_data_file_key, name,
  576. OS_FILE_OPEN_RETRY
  577. | OS_FILE_ON_ERROR_NO_EXIT
  578. | OS_FILE_ON_ERROR_SILENT,
  579. OS_FILE_NORMAL,
  580. OS_DATA_FILE,
  581. srv_read_only_mode,
  582. &ret);
  583. /* If the file open was successful then load the tablespace. */
  584. if (ret) {
  585. os_offset_t size;
  586. fil_space_t* space;
  587. size = os_file_get_size(fh);
  588. ut_a(size != (os_offset_t) -1);
  589. ret = os_file_close(fh);
  590. ut_a(ret);
  591. /* Load the tablespace into InnoDB's internal
  592. data structures. */
  593. /* We set the biggest space id to the undo tablespace
  594. because InnoDB hasn't opened any other tablespace apart
  595. from the system tablespace. */
  596. fil_set_max_space_id_if_bigger(space_id);
  597. space = fil_space_create(
  598. undo_name, space_id, FSP_FLAGS_PAGE_SSIZE(),
  599. FIL_TYPE_TABLESPACE, NULL);
  600. ut_a(fil_validate());
  601. ut_a(space);
  602. os_offset_t n_pages = size / UNIV_PAGE_SIZE;
  603. /* On 32-bit platforms, ulint is 32 bits and os_offset_t
  604. is 64 bits. It is OK to cast the n_pages to ulint because
  605. the unit has been scaled to pages and page number is always
  606. 32 bits. */
  607. if (fil_node_create(
  608. name, (ulint) n_pages, space, false, TRUE)) {
  609. err = DB_SUCCESS;
  610. }
  611. }
  612. return(err);
  613. }
  614. /** Check if undo tablespaces and redo log files exist before creating a
  615. new system tablespace
  616. @retval DB_SUCCESS if all undo and redo logs are not found
  617. @retval DB_ERROR if any undo and redo logs are found */
  618. static
  619. dberr_t
  620. srv_check_undo_redo_logs_exists()
  621. {
  622. bool ret;
  623. os_file_t fh;
  624. char name[OS_FILE_MAX_PATH];
  625. /* Check if any undo tablespaces exist */
  626. for (ulint i = 1; i <= srv_undo_tablespaces; ++i) {
  627. snprintf(
  628. name, sizeof(name),
  629. "%s%cundo%03zu",
  630. srv_undo_dir, OS_PATH_SEPARATOR,
  631. i);
  632. fh = os_file_create(
  633. innodb_data_file_key, name,
  634. OS_FILE_OPEN_RETRY
  635. | OS_FILE_ON_ERROR_NO_EXIT
  636. | OS_FILE_ON_ERROR_SILENT,
  637. OS_FILE_NORMAL,
  638. OS_DATA_FILE,
  639. srv_read_only_mode,
  640. &ret);
  641. if (ret) {
  642. os_file_close(fh);
  643. ib::error()
  644. << "undo tablespace '" << name << "' exists."
  645. " Creating system tablespace with existing undo"
  646. " tablespaces is not supported. Please delete"
  647. " all undo tablespaces before creating new"
  648. " system tablespace.";
  649. return(DB_ERROR);
  650. }
  651. }
  652. /* Check if any redo log files exist */
  653. char logfilename[OS_FILE_MAX_PATH];
  654. size_t dirnamelen = strlen(srv_log_group_home_dir);
  655. memcpy(logfilename, srv_log_group_home_dir, dirnamelen);
  656. for (unsigned i = 0; i < srv_n_log_files; i++) {
  657. sprintf(logfilename + dirnamelen,
  658. "ib_logfile%u", i);
  659. fh = os_file_create(
  660. innodb_log_file_key, logfilename,
  661. OS_FILE_OPEN_RETRY
  662. | OS_FILE_ON_ERROR_NO_EXIT
  663. | OS_FILE_ON_ERROR_SILENT,
  664. OS_FILE_NORMAL,
  665. OS_LOG_FILE,
  666. srv_read_only_mode,
  667. &ret);
  668. if (ret) {
  669. os_file_close(fh);
  670. ib::error() << "redo log file '" << logfilename
  671. << "' exists. Creating system tablespace with"
  672. " existing redo log files is not recommended."
  673. " Please delete all redo log files before"
  674. " creating new system tablespace.";
  675. return(DB_ERROR);
  676. }
  677. }
  678. return(DB_SUCCESS);
  679. }
  680. undo::undo_spaces_t undo::Truncate::s_fix_up_spaces;
  681. /** Open the configured number of dedicated undo tablespaces.
  682. @param[in] create_new_db whether the database is being initialized
  683. @return DB_SUCCESS or error code */
  684. dberr_t
  685. srv_undo_tablespaces_init(bool create_new_db)
  686. {
  687. ulint i;
  688. dberr_t err = DB_SUCCESS;
  689. ulint prev_space_id = 0;
  690. ulint n_undo_tablespaces;
  691. ulint undo_tablespace_ids[TRX_SYS_N_RSEGS + 1];
  692. srv_undo_tablespaces_open = 0;
  693. ut_a(srv_undo_tablespaces <= TRX_SYS_N_RSEGS);
  694. ut_a(!create_new_db || srv_operation == SRV_OPERATION_NORMAL);
  695. memset(undo_tablespace_ids, 0x0, sizeof(undo_tablespace_ids));
  696. /* Create the undo spaces only if we are creating a new
  697. instance. We don't allow creating of new undo tablespaces
  698. in an existing instance (yet). This restriction exists because
  699. we check in several places for SYSTEM tablespaces to be less than
  700. the min of user defined tablespace ids. Once we implement saving
  701. the location of the undo tablespaces and their space ids this
  702. restriction will/should be lifted. */
  703. for (i = 0; create_new_db && i < srv_undo_tablespaces; ++i) {
  704. char name[OS_FILE_MAX_PATH];
  705. ulint space_id = i + 1;
  706. DBUG_EXECUTE_IF("innodb_undo_upgrade",
  707. space_id = i + 3;);
  708. snprintf(
  709. name, sizeof(name),
  710. "%s%cundo%03zu",
  711. srv_undo_dir, OS_PATH_SEPARATOR, space_id);
  712. if (i == 0) {
  713. srv_undo_space_id_start = space_id;
  714. prev_space_id = srv_undo_space_id_start - 1;
  715. }
  716. undo_tablespace_ids[i] = space_id;
  717. err = srv_undo_tablespace_create(
  718. name, SRV_UNDO_TABLESPACE_SIZE_IN_PAGES);
  719. if (err != DB_SUCCESS) {
  720. ib::error() << "Could not create undo tablespace '"
  721. << name << "'.";
  722. return(err);
  723. }
  724. }
  725. /* Get the tablespace ids of all the undo segments excluding
  726. the system tablespace (0). If we are creating a new instance then
  727. we build the undo_tablespace_ids ourselves since they don't
  728. already exist. */
  729. n_undo_tablespaces = create_new_db
  730. || srv_operation == SRV_OPERATION_BACKUP
  731. || srv_operation == SRV_OPERATION_RESTORE_DELTA
  732. ? srv_undo_tablespaces
  733. : trx_rseg_get_n_undo_tablespaces(undo_tablespace_ids);
  734. srv_undo_tablespaces_active = srv_undo_tablespaces;
  735. switch (srv_operation) {
  736. case SRV_OPERATION_RESTORE_DELTA:
  737. case SRV_OPERATION_BACKUP:
  738. for (i = 0; i < n_undo_tablespaces; i++) {
  739. undo_tablespace_ids[i] = i + srv_undo_space_id_start;
  740. }
  741. prev_space_id = srv_undo_space_id_start - 1;
  742. break;
  743. case SRV_OPERATION_NORMAL:
  744. if (create_new_db) {
  745. break;
  746. }
  747. /* fall through */
  748. case SRV_OPERATION_RESTORE:
  749. case SRV_OPERATION_RESTORE_EXPORT:
  750. ut_ad(!create_new_db);
  751. /* Check if any of the UNDO tablespace needs fix-up because
  752. server crashed while truncate was active on UNDO tablespace.*/
  753. for (i = 0; i < n_undo_tablespaces; ++i) {
  754. undo::Truncate undo_trunc;
  755. if (undo_trunc.needs_fix_up(undo_tablespace_ids[i])) {
  756. char name[OS_FILE_MAX_PATH];
  757. snprintf(name, sizeof(name),
  758. "%s%cundo%03zu",
  759. srv_undo_dir, OS_PATH_SEPARATOR,
  760. undo_tablespace_ids[i]);
  761. os_file_delete(innodb_data_file_key, name);
  762. err = srv_undo_tablespace_create(
  763. name,
  764. SRV_UNDO_TABLESPACE_SIZE_IN_PAGES);
  765. if (err != DB_SUCCESS) {
  766. ib::error() << "Could not fix-up undo "
  767. " tablespace truncate '"
  768. << name << "'.";
  769. return(err);
  770. }
  771. undo::Truncate::s_fix_up_spaces.push_back(
  772. undo_tablespace_ids[i]);
  773. }
  774. }
  775. break;
  776. }
  777. /* Open all the undo tablespaces that are currently in use. If we
  778. fail to open any of these it is a fatal error. The tablespace ids
  779. should be contiguous. It is a fatal error because they are required
  780. for recovery and are referenced by the UNDO logs (a.k.a RBS). */
  781. for (i = 0; i < n_undo_tablespaces; ++i) {
  782. char name[OS_FILE_MAX_PATH];
  783. snprintf(
  784. name, sizeof(name),
  785. "%s%cundo%03zu",
  786. srv_undo_dir, OS_PATH_SEPARATOR,
  787. undo_tablespace_ids[i]);
  788. /* Should be no gaps in undo tablespace ids. */
  789. ut_a(!i || prev_space_id + 1 == undo_tablespace_ids[i]);
  790. /* The system space id should not be in this array. */
  791. ut_a(undo_tablespace_ids[i] != 0);
  792. ut_a(undo_tablespace_ids[i] != ULINT_UNDEFINED);
  793. err = srv_undo_tablespace_open(name, undo_tablespace_ids[i]);
  794. if (err != DB_SUCCESS) {
  795. ib::error() << "Unable to open undo tablespace '"
  796. << name << "'.";
  797. return(err);
  798. }
  799. prev_space_id = undo_tablespace_ids[i];
  800. /* Note the first undo tablespace id in case of
  801. no active undo tablespace. */
  802. if (0 == srv_undo_tablespaces_open++) {
  803. srv_undo_space_id_start = undo_tablespace_ids[i];
  804. }
  805. }
  806. /* Open any extra unused undo tablespaces. These must be contiguous.
  807. We stop at the first failure. These are undo tablespaces that are
  808. not in use and therefore not required by recovery. We only check
  809. that there are no gaps. */
  810. for (i = prev_space_id + 1;
  811. i < srv_undo_space_id_start + TRX_SYS_N_RSEGS; ++i) {
  812. char name[OS_FILE_MAX_PATH];
  813. snprintf(
  814. name, sizeof(name),
  815. "%s%cundo%03zu", srv_undo_dir, OS_PATH_SEPARATOR, i);
  816. err = srv_undo_tablespace_open(name, i);
  817. if (err != DB_SUCCESS) {
  818. break;
  819. }
  820. ++n_undo_tablespaces;
  821. ++srv_undo_tablespaces_open;
  822. }
  823. /* Initialize srv_undo_space_id_start=0 when there are no
  824. dedicated undo tablespaces. */
  825. if (n_undo_tablespaces == 0) {
  826. srv_undo_space_id_start = 0;
  827. }
  828. /* If the user says that there are fewer than what we find we
  829. tolerate that discrepancy but not the inverse. Because there could
  830. be unused undo tablespaces for future use. */
  831. if (srv_undo_tablespaces > n_undo_tablespaces) {
  832. ib::error() << "Expected to open innodb_undo_tablespaces="
  833. << srv_undo_tablespaces
  834. << " but was able to find only "
  835. << n_undo_tablespaces;
  836. return(err != DB_SUCCESS ? err : DB_ERROR);
  837. } else if (n_undo_tablespaces > 0) {
  838. ib::info() << "Opened " << n_undo_tablespaces
  839. << " undo tablespaces";
  840. if (srv_undo_tablespaces == 0) {
  841. ib::warn() << "innodb_undo_tablespaces=0 disables"
  842. " dedicated undo log tablespaces";
  843. }
  844. }
  845. if (create_new_db) {
  846. mtr_t mtr;
  847. mtr_start(&mtr);
  848. /* The undo log tablespace */
  849. for (i = 0; i < n_undo_tablespaces; ++i) {
  850. fsp_header_init(
  851. undo_tablespace_ids[i],
  852. SRV_UNDO_TABLESPACE_SIZE_IN_PAGES, &mtr);
  853. }
  854. mtr_commit(&mtr);
  855. }
  856. if (!undo::Truncate::s_fix_up_spaces.empty()) {
  857. /* Step-1: Initialize the tablespace header and rsegs header. */
  858. mtr_t mtr;
  859. mtr_start(&mtr);
  860. /* Turn off REDO logging. We are in server start mode and fixing
  861. UNDO tablespace even before REDO log is read. Let's say we
  862. do REDO logging here then this REDO log record will be applied
  863. as part of the current recovery process. We surely don't need
  864. that as this is fix-up action parallel to REDO logging. */
  865. mtr_set_log_mode(&mtr, MTR_LOG_NO_REDO);
  866. buf_block_t* sys_header = trx_sysf_get(&mtr);
  867. if (!sys_header) {
  868. mtr.commit();
  869. return DB_CORRUPTION;
  870. }
  871. for (undo::undo_spaces_t::const_iterator it
  872. = undo::Truncate::s_fix_up_spaces.begin();
  873. it != undo::Truncate::s_fix_up_spaces.end();
  874. ++it) {
  875. undo::Truncate::add_space_to_trunc_list(*it);
  876. fsp_header_init(
  877. *it, SRV_UNDO_TABLESPACE_SIZE_IN_PAGES, &mtr);
  878. mtr_x_lock(fil_space_get_latch(*it, NULL), &mtr);
  879. for (ulint i = 0; i < TRX_SYS_N_RSEGS; i++) {
  880. if (trx_sysf_rseg_get_space(sys_header, i)
  881. == *it) {
  882. trx_rseg_header_create(
  883. *it, i, sys_header, &mtr);
  884. }
  885. }
  886. undo::Truncate::clear_trunc_list();
  887. }
  888. mtr_commit(&mtr);
  889. /* Step-2: Flush the dirty pages from the buffer pool. */
  890. for (undo::undo_spaces_t::const_iterator it
  891. = undo::Truncate::s_fix_up_spaces.begin();
  892. it != undo::Truncate::s_fix_up_spaces.end();
  893. ++it) {
  894. FlushObserver dummy(TRX_SYS_SPACE, NULL, NULL);
  895. buf_LRU_flush_or_remove_pages(TRX_SYS_SPACE, &dummy);
  896. FlushObserver dummy2(*it, NULL, NULL);
  897. buf_LRU_flush_or_remove_pages(*it, &dummy2);
  898. /* Remove the truncate redo log file. */
  899. undo::Truncate undo_trunc;
  900. undo_trunc.done_logging(*it);
  901. }
  902. }
  903. return(DB_SUCCESS);
  904. }
  905. /********************************************************************
  906. Wait for the purge thread(s) to start up. */
  907. static
  908. void
  909. srv_start_wait_for_purge_to_start()
  910. /*===============================*/
  911. {
  912. /* Wait for the purge coordinator and master thread to startup. */
  913. purge_state_t state = trx_purge_state();
  914. ut_a(state != PURGE_STATE_DISABLED);
  915. while (srv_shutdown_state == SRV_SHUTDOWN_NONE
  916. && srv_force_recovery < SRV_FORCE_NO_BACKGROUND
  917. && state == PURGE_STATE_INIT) {
  918. switch (state = trx_purge_state()) {
  919. case PURGE_STATE_RUN:
  920. case PURGE_STATE_STOP:
  921. break;
  922. case PURGE_STATE_INIT:
  923. ib::info() << "Waiting for purge to start";
  924. os_thread_sleep(50000);
  925. break;
  926. case PURGE_STATE_EXIT:
  927. case PURGE_STATE_DISABLED:
  928. ut_error;
  929. }
  930. }
  931. }
  932. /** Create the temporary file tablespace.
  933. @param[in] create_new_db whether we are creating a new database
  934. @return DB_SUCCESS or error code. */
  935. static
  936. dberr_t
  937. srv_open_tmp_tablespace(bool create_new_db)
  938. {
  939. ulint sum_of_new_sizes;
  940. /* Will try to remove if there is existing file left-over by last
  941. unclean shutdown */
  942. srv_tmp_space.set_sanity_check_status(true);
  943. srv_tmp_space.delete_files();
  944. srv_tmp_space.set_ignore_read_only(true);
  945. ib::info() << "Creating shared tablespace for temporary tables";
  946. bool create_new_temp_space;
  947. srv_tmp_space.set_space_id(SRV_TMP_SPACE_ID);
  948. dberr_t err = srv_tmp_space.check_file_spec(
  949. &create_new_temp_space, 12 * 1024 * 1024);
  950. if (err == DB_FAIL) {
  951. ib::error() << "The " << srv_tmp_space.name()
  952. << " data file must be writable!";
  953. err = DB_ERROR;
  954. } else if (err != DB_SUCCESS) {
  955. ib::error() << "Could not create the shared "
  956. << srv_tmp_space.name() << ".";
  957. } else if ((err = srv_tmp_space.open_or_create(
  958. true, create_new_db, &sum_of_new_sizes, NULL))
  959. != DB_SUCCESS) {
  960. ib::error() << "Unable to create the shared "
  961. << srv_tmp_space.name();
  962. } else {
  963. mtr_t mtr;
  964. ulint size = srv_tmp_space.get_sum_of_sizes();
  965. /* Open this shared temp tablespace in the fil_system so that
  966. it stays open until shutdown. */
  967. if (fil_space_open(srv_tmp_space.name())) {
  968. /* Initialize the header page */
  969. mtr_start(&mtr);
  970. mtr_set_log_mode(&mtr, MTR_LOG_NO_REDO);
  971. fsp_header_init(SRV_TMP_SPACE_ID, size, &mtr);
  972. mtr_commit(&mtr);
  973. } else {
  974. /* This file was just opened in the code above! */
  975. ib::error() << "The " << srv_tmp_space.name()
  976. << " data file cannot be re-opened"
  977. " after check_file_spec() succeeded!";
  978. err = DB_ERROR;
  979. }
  980. }
  981. return(err);
  982. }
  983. /****************************************************************//**
  984. Set state to indicate start of particular group of threads in InnoDB. */
  985. UNIV_INLINE
  986. void
  987. srv_start_state_set(
  988. /*================*/
  989. srv_start_state_t state) /*!< in: indicate current state of
  990. thread startup */
  991. {
  992. srv_start_state |= state;
  993. }
  994. /****************************************************************//**
  995. Check if following group of threads is started.
  996. @return true if started */
  997. UNIV_INLINE
  998. bool
  999. srv_start_state_is_set(
  1000. /*===================*/
  1001. srv_start_state_t state) /*!< in: state to check for */
  1002. {
  1003. return(srv_start_state & state);
  1004. }
  1005. /**
  1006. Shutdown all background threads created by InnoDB. */
  1007. static
  1008. void
  1009. srv_shutdown_all_bg_threads()
  1010. {
  1011. ut_ad(!srv_undo_sources);
  1012. srv_shutdown_state = SRV_SHUTDOWN_EXIT_THREADS;
  1013. /* All threads end up waiting for certain events. Put those events
  1014. to the signaled state. Then the threads will exit themselves after
  1015. os_event_wait(). */
  1016. for (uint i = 0; i < 1000; ++i) {
  1017. /* NOTE: IF YOU CREATE THREADS IN INNODB, YOU MUST EXIT THEM
  1018. HERE OR EARLIER */
  1019. if (srv_start_state_is_set(SRV_START_STATE_LOCK_SYS)) {
  1020. /* a. Let the lock timeout thread exit */
  1021. os_event_set(lock_sys.timeout_event);
  1022. }
  1023. if (!srv_read_only_mode) {
  1024. /* b. srv error monitor thread exits automatically,
  1025. no need to do anything here */
  1026. if (srv_start_state_is_set(SRV_START_STATE_MASTER)) {
  1027. /* c. We wake the master thread so that
  1028. it exits */
  1029. srv_wake_master_thread();
  1030. }
  1031. if (srv_start_state_is_set(SRV_START_STATE_PURGE)) {
  1032. /* d. Wakeup purge threads. */
  1033. srv_purge_wakeup();
  1034. }
  1035. if (srv_n_fil_crypt_threads_started) {
  1036. os_event_set(fil_crypt_threads_event);
  1037. }
  1038. if (log_scrub_thread_active) {
  1039. os_event_set(log_scrub_event);
  1040. }
  1041. }
  1042. if (srv_start_state_is_set(SRV_START_STATE_IO)) {
  1043. ut_ad(!srv_read_only_mode);
  1044. /* e. Exit the i/o threads */
  1045. if (recv_sys->flush_start != NULL) {
  1046. os_event_set(recv_sys->flush_start);
  1047. }
  1048. if (recv_sys->flush_end != NULL) {
  1049. os_event_set(recv_sys->flush_end);
  1050. }
  1051. os_event_set(buf_flush_event);
  1052. }
  1053. if (!os_thread_count) {
  1054. return;
  1055. }
  1056. switch (srv_operation) {
  1057. case SRV_OPERATION_BACKUP:
  1058. case SRV_OPERATION_RESTORE_DELTA:
  1059. break;
  1060. case SRV_OPERATION_NORMAL:
  1061. case SRV_OPERATION_RESTORE:
  1062. case SRV_OPERATION_RESTORE_EXPORT:
  1063. if (!buf_page_cleaner_is_active
  1064. && os_aio_all_slots_free()) {
  1065. os_aio_wake_all_threads_at_shutdown();
  1066. }
  1067. }
  1068. os_thread_sleep(100000);
  1069. }
  1070. ib::warn() << os_thread_count << " threads created by InnoDB"
  1071. " had not exited at shutdown!";
  1072. ut_d(os_aio_print_pending_io(stderr));
  1073. ut_ad(0);
  1074. }
  1075. #ifdef UNIV_DEBUG
  1076. # define srv_init_abort(_db_err) \
  1077. srv_init_abort_low(create_new_db, __FILE__, __LINE__, _db_err)
  1078. #else
  1079. # define srv_init_abort(_db_err) \
  1080. srv_init_abort_low(create_new_db, _db_err)
  1081. #endif /* UNIV_DEBUG */
  1082. /** Innobase start-up aborted. Perform cleanup actions.
  1083. @param[in] create_new_db TRUE if new db is being created
  1084. @param[in] file File name
  1085. @param[in] line Line number
  1086. @param[in] err Reason for aborting InnoDB startup
  1087. @return DB_SUCCESS or error code. */
  1088. MY_ATTRIBUTE((warn_unused_result, nonnull))
  1089. static
  1090. dberr_t
  1091. srv_init_abort_low(
  1092. bool create_new_db,
  1093. #ifdef UNIV_DEBUG
  1094. const char* file,
  1095. unsigned line,
  1096. #endif /* UNIV_DEBUG */
  1097. dberr_t err)
  1098. {
  1099. if (create_new_db) {
  1100. ib::error() << "Database creation was aborted"
  1101. #ifdef UNIV_DEBUG
  1102. " at " << innobase_basename(file) << "[" << line << "]"
  1103. #endif /* UNIV_DEBUG */
  1104. " with error " << ut_strerr(err) << ". You may need"
  1105. " to delete the ibdata1 file before trying to start"
  1106. " up again.";
  1107. } else {
  1108. ib::error() << "Plugin initialization aborted"
  1109. #ifdef UNIV_DEBUG
  1110. " at " << innobase_basename(file) << "[" << line << "]"
  1111. #endif /* UNIV_DEBUG */
  1112. " with error " << ut_strerr(err);
  1113. }
  1114. srv_shutdown_bg_undo_sources();
  1115. srv_shutdown_all_bg_threads();
  1116. return(err);
  1117. }
  1118. /** Prepare to delete the redo log files. Flush the dirty pages from all the
  1119. buffer pools. Flush the redo log buffer to the redo log file.
  1120. @param[in] n_files number of old redo log files
  1121. @return lsn upto which data pages have been flushed. */
  1122. static
  1123. lsn_t
  1124. srv_prepare_to_delete_redo_log_files(
  1125. ulint n_files)
  1126. {
  1127. DBUG_ENTER("srv_prepare_to_delete_redo_log_files");
  1128. lsn_t flushed_lsn;
  1129. ulint pending_io = 0;
  1130. ulint count = 0;
  1131. do {
  1132. /* Clean the buffer pool. */
  1133. buf_flush_sync_all_buf_pools();
  1134. DBUG_EXECUTE_IF("innodb_log_abort_1", DBUG_RETURN(0););
  1135. DBUG_PRINT("ib_log", ("After innodb_log_abort_1"));
  1136. log_mutex_enter();
  1137. fil_names_clear(log_sys->lsn, false);
  1138. flushed_lsn = log_sys->lsn;
  1139. {
  1140. ib::info info;
  1141. if (srv_log_file_size == 0
  1142. || (log_sys->log.format
  1143. & ~LOG_HEADER_FORMAT_ENCRYPTED)
  1144. != LOG_HEADER_FORMAT_CURRENT) {
  1145. info << "Upgrading redo log: ";
  1146. } else if (n_files != srv_n_log_files
  1147. || srv_log_file_size
  1148. != srv_log_file_size_requested) {
  1149. if (srv_encrypt_log
  1150. == (my_bool)log_sys->is_encrypted()) {
  1151. info << (srv_encrypt_log
  1152. ? "Resizing encrypted"
  1153. : "Resizing");
  1154. } else if (srv_encrypt_log) {
  1155. info << "Encrypting and resizing";
  1156. } else {
  1157. info << "Removing encryption"
  1158. " and resizing";
  1159. }
  1160. info << " redo log from " << n_files
  1161. << "*" << srv_log_file_size << " to ";
  1162. } else if (srv_encrypt_log) {
  1163. info << "Encrypting redo log: ";
  1164. } else {
  1165. info << "Removing redo log encryption: ";
  1166. }
  1167. info << srv_n_log_files << "*"
  1168. << srv_log_file_size_requested
  1169. << " bytes; LSN=" << flushed_lsn;
  1170. }
  1171. srv_start_lsn = flushed_lsn;
  1172. /* Flush the old log files. */
  1173. log_mutex_exit();
  1174. log_write_up_to(flushed_lsn, true);
  1175. /* If innodb_flush_method=O_DSYNC,
  1176. we need to explicitly flush the log buffers. */
  1177. fil_flush(SRV_LOG_SPACE_FIRST_ID);
  1178. ut_ad(flushed_lsn == log_get_lsn());
  1179. /* Check if the buffer pools are clean. If not
  1180. retry till it is clean. */
  1181. pending_io = buf_pool_check_no_pending_io();
  1182. if (pending_io > 0) {
  1183. count++;
  1184. /* Print a message every 60 seconds if we
  1185. are waiting to clean the buffer pools */
  1186. if (srv_print_verbose_log && count > 600) {
  1187. ib::info() << "Waiting for "
  1188. << pending_io << " buffer "
  1189. << "page I/Os to complete";
  1190. count = 0;
  1191. }
  1192. }
  1193. os_thread_sleep(100000);
  1194. } while (buf_pool_check_no_pending_io());
  1195. DBUG_RETURN(flushed_lsn);
  1196. }
  1197. /********************************************************************
  1198. Starts InnoDB and creates a new database if database files
  1199. are not found and the user wants.
  1200. @return DB_SUCCESS or error code */
  1201. dberr_t
  1202. innobase_start_or_create_for_mysql()
  1203. {
  1204. bool create_new_db = false;
  1205. lsn_t flushed_lsn;
  1206. dberr_t err = DB_SUCCESS;
  1207. ulint srv_n_log_files_found = srv_n_log_files;
  1208. mtr_t mtr;
  1209. char logfilename[10000];
  1210. char* logfile0 = NULL;
  1211. size_t dirnamelen;
  1212. unsigned i = 0;
  1213. ut_ad(srv_operation == SRV_OPERATION_NORMAL
  1214. || srv_operation == SRV_OPERATION_RESTORE
  1215. || srv_operation == SRV_OPERATION_RESTORE_EXPORT);
  1216. if (srv_force_recovery == SRV_FORCE_NO_LOG_REDO) {
  1217. srv_read_only_mode = true;
  1218. }
  1219. high_level_read_only = srv_read_only_mode
  1220. || srv_force_recovery > SRV_FORCE_NO_TRX_UNDO
  1221. || srv_sys_space.created_new_raw();
  1222. /* Reset the start state. */
  1223. srv_start_state = SRV_START_STATE_NONE;
  1224. if (srv_read_only_mode) {
  1225. ib::info() << "Started in read only mode";
  1226. /* There is no write to InnoDB tablespaces (not even
  1227. temporary ones, because also CREATE TEMPORARY TABLE is
  1228. refused in read-only mode). */
  1229. srv_use_doublewrite_buf = FALSE;
  1230. }
  1231. #ifdef HAVE_LZO1X
  1232. if (lzo_init() != LZO_E_OK) {
  1233. ib::warn() << "lzo_init() failed, support disabled";
  1234. srv_lzo_disabled = true;
  1235. } else {
  1236. ib::info() << "LZO1X support available";
  1237. srv_lzo_disabled = false;
  1238. }
  1239. #endif /* HAVE_LZO1X */
  1240. compile_time_assert(sizeof(ulint) == sizeof(void*));
  1241. #ifdef UNIV_DEBUG
  1242. ib::info() << "!!!!!!!! UNIV_DEBUG switched on !!!!!!!!!";
  1243. #endif
  1244. #ifdef UNIV_IBUF_DEBUG
  1245. ib::info() << "!!!!!!!! UNIV_IBUF_DEBUG switched on !!!!!!!!!";
  1246. # ifdef UNIV_IBUF_COUNT_DEBUG
  1247. ib::info() << "!!!!!!!! UNIV_IBUF_COUNT_DEBUG switched on !!!!!!!!!";
  1248. ib::error() << "Crash recovery will fail with UNIV_IBUF_COUNT_DEBUG";
  1249. # endif
  1250. #endif
  1251. #ifdef UNIV_LOG_LSN_DEBUG
  1252. ib::info() << "!!!!!!!! UNIV_LOG_LSN_DEBUG switched on !!!!!!!!!";
  1253. #endif /* UNIV_LOG_LSN_DEBUG */
  1254. #if defined(COMPILER_HINTS_ENABLED)
  1255. ib::info() << "Compiler hints enabled.";
  1256. #endif /* defined(COMPILER_HINTS_ENABLED) */
  1257. #ifdef _WIN32
  1258. ib::info() << "Mutexes and rw_locks use Windows interlocked functions";
  1259. #else
  1260. ib::info() << "Mutexes and rw_locks use GCC atomic builtins";
  1261. #endif
  1262. ib::info() << MUTEX_TYPE;
  1263. ib::info() << "Compressed tables use zlib " ZLIB_VERSION
  1264. #ifdef UNIV_ZIP_DEBUG
  1265. " with validation"
  1266. #endif /* UNIV_ZIP_DEBUG */
  1267. ;
  1268. #ifdef UNIV_ZIP_COPY
  1269. ib::info() << "and extra copying";
  1270. #endif /* UNIV_ZIP_COPY */
  1271. /* Since InnoDB does not currently clean up all its internal data
  1272. structures in MySQL Embedded Server Library server_end(), we
  1273. print an error message if someone tries to start up InnoDB a
  1274. second time during the process lifetime. */
  1275. if (srv_start_has_been_called) {
  1276. ib::error() << "Startup called second time"
  1277. " during the process lifetime."
  1278. " In the MySQL Embedded Server Library"
  1279. " you cannot call server_init() more than"
  1280. " once during the process lifetime.";
  1281. }
  1282. srv_start_has_been_called = true;
  1283. srv_is_being_started = true;
  1284. #ifdef _WIN32
  1285. srv_use_native_aio = TRUE;
  1286. #elif defined(LINUX_NATIVE_AIO)
  1287. if (srv_use_native_aio) {
  1288. ib::info() << "Using Linux native AIO";
  1289. }
  1290. #else
  1291. /* Currently native AIO is supported only on windows and linux
  1292. and that also when the support is compiled in. In all other
  1293. cases, we ignore the setting of innodb_use_native_aio. */
  1294. srv_use_native_aio = FALSE;
  1295. #endif /* _WIN32 */
  1296. /* Register performance schema stages before any real work has been
  1297. started which may need to be instrumented. */
  1298. mysql_stage_register("innodb", srv_stages, UT_ARR_SIZE(srv_stages));
  1299. if (srv_file_flush_method_str == NULL) {
  1300. /* These are the default options */
  1301. srv_file_flush_method = IF_WIN(SRV_ALL_O_DIRECT_FSYNC,SRV_FSYNC);
  1302. } else if (0 == ut_strcmp(srv_file_flush_method_str, "fsync")) {
  1303. srv_file_flush_method = SRV_FSYNC;
  1304. } else if (0 == ut_strcmp(srv_file_flush_method_str, "O_DSYNC")) {
  1305. srv_file_flush_method = SRV_O_DSYNC;
  1306. } else if (0 == ut_strcmp(srv_file_flush_method_str, "O_DIRECT")) {
  1307. srv_file_flush_method = SRV_O_DIRECT;
  1308. } else if (0 == ut_strcmp(srv_file_flush_method_str, "O_DIRECT_NO_FSYNC")) {
  1309. srv_file_flush_method = SRV_O_DIRECT_NO_FSYNC;
  1310. } else if (0 == ut_strcmp(srv_file_flush_method_str, "littlesync")) {
  1311. srv_file_flush_method = SRV_LITTLESYNC;
  1312. } else if (0 == ut_strcmp(srv_file_flush_method_str, "nosync")) {
  1313. srv_file_flush_method = SRV_NOSYNC;
  1314. #ifdef _WIN32
  1315. } else if (0 == ut_strcmp(srv_file_flush_method_str, "normal")) {
  1316. srv_file_flush_method = SRV_FSYNC;
  1317. } else if (0 == ut_strcmp(srv_file_flush_method_str, "unbuffered")) {
  1318. } else if (0 == ut_strcmp(srv_file_flush_method_str,
  1319. "async_unbuffered")) {
  1320. #endif /* _WIN32 */
  1321. } else {
  1322. ib::error() << "Unrecognized value "
  1323. << srv_file_flush_method_str
  1324. << " for innodb_flush_method";
  1325. err = DB_ERROR;
  1326. }
  1327. /* Note that the call srv_boot() also changes the values of
  1328. some variables to the units used by InnoDB internally */
  1329. /* Set the maximum number of threads which can wait for a semaphore
  1330. inside InnoDB: this is the 'sync wait array' size, as well as the
  1331. maximum number of threads that can wait in the 'srv_conc array' for
  1332. their time to enter InnoDB. */
  1333. srv_max_n_threads = 1 /* io_ibuf_thread */
  1334. + 1 /* io_log_thread */
  1335. + 1 /* lock_wait_timeout_thread */
  1336. + 1 /* srv_error_monitor_thread */
  1337. + 1 /* srv_monitor_thread */
  1338. + 1 /* srv_master_thread */
  1339. + 1 /* srv_purge_coordinator_thread */
  1340. + 1 /* buf_dump_thread */
  1341. + 1 /* dict_stats_thread */
  1342. + 1 /* fts_optimize_thread */
  1343. + 1 /* recv_writer_thread */
  1344. + 1 /* trx_rollback_all_recovered */
  1345. + 128 /* added as margin, for use of
  1346. InnoDB Memcached etc. */
  1347. + max_connections
  1348. + srv_n_read_io_threads
  1349. + srv_n_write_io_threads
  1350. + srv_n_purge_threads
  1351. + srv_n_page_cleaners
  1352. /* FTS Parallel Sort */
  1353. + fts_sort_pll_degree * FTS_NUM_AUX_INDEX
  1354. * max_connections;
  1355. if (srv_buf_pool_size >= BUF_POOL_SIZE_THRESHOLD) {
  1356. if (srv_buf_pool_instances == srv_buf_pool_instances_default) {
  1357. #if defined(_WIN32) && !defined(_WIN64)
  1358. /* Do not allocate too large of a buffer pool on
  1359. Windows 32-bit systems, which can have trouble
  1360. allocating larger single contiguous memory blocks. */
  1361. srv_buf_pool_size = static_cast<ulint>(ut_uint64_align_up(srv_buf_pool_size, srv_buf_pool_chunk_unit));
  1362. srv_buf_pool_instances = ut_min(
  1363. static_cast<ulong>(MAX_BUFFER_POOLS),
  1364. static_cast<ulong>(srv_buf_pool_size / srv_buf_pool_chunk_unit));
  1365. #else /* defined(_WIN32) && !defined(_WIN64) */
  1366. /* Default to 8 instances when size > 1GB. */
  1367. srv_buf_pool_instances = 8;
  1368. #endif /* defined(_WIN32) && !defined(_WIN64) */
  1369. }
  1370. } else {
  1371. /* If buffer pool is less than 1 GiB, assume fewer
  1372. threads. Also use only one buffer pool instance. */
  1373. if (srv_buf_pool_instances != srv_buf_pool_instances_default
  1374. && srv_buf_pool_instances != 1) {
  1375. /* We can't distinguish whether the user has explicitly
  1376. started mysqld with --innodb-buffer-pool-instances=0,
  1377. (srv_buf_pool_instances_default is 0) or has not
  1378. specified that option at all. Thus we have the
  1379. limitation that if the user started with =0, we
  1380. will not emit a warning here, but we should actually
  1381. do so. */
  1382. ib::info()
  1383. << "Adjusting innodb_buffer_pool_instances"
  1384. " from " << srv_buf_pool_instances << " to 1"
  1385. " since innodb_buffer_pool_size is less than "
  1386. << BUF_POOL_SIZE_THRESHOLD / (1024 * 1024)
  1387. << " MiB";
  1388. }
  1389. srv_buf_pool_instances = 1;
  1390. }
  1391. if (srv_buf_pool_chunk_unit * srv_buf_pool_instances
  1392. > srv_buf_pool_size) {
  1393. /* Size unit of buffer pool is larger than srv_buf_pool_size.
  1394. adjust srv_buf_pool_chunk_unit for srv_buf_pool_size. */
  1395. srv_buf_pool_chunk_unit
  1396. = static_cast<ulong>(srv_buf_pool_size)
  1397. / srv_buf_pool_instances;
  1398. if (srv_buf_pool_size % srv_buf_pool_instances != 0) {
  1399. ++srv_buf_pool_chunk_unit;
  1400. }
  1401. }
  1402. srv_buf_pool_size = buf_pool_size_align(srv_buf_pool_size);
  1403. if (srv_n_page_cleaners > srv_buf_pool_instances) {
  1404. /* limit of page_cleaner parallelizability
  1405. is number of buffer pool instances. */
  1406. srv_n_page_cleaners = srv_buf_pool_instances;
  1407. }
  1408. srv_boot();
  1409. ib::info() << ut_crc32_implementation;
  1410. if (!srv_read_only_mode) {
  1411. mutex_create(LATCH_ID_SRV_MONITOR_FILE,
  1412. &srv_monitor_file_mutex);
  1413. if (srv_innodb_status) {
  1414. srv_monitor_file_name = static_cast<char*>(
  1415. ut_malloc_nokey(
  1416. strlen(fil_path_to_mysql_datadir)
  1417. + 20 + sizeof "/innodb_status."));
  1418. sprintf(srv_monitor_file_name,
  1419. "%s/innodb_status." ULINTPF,
  1420. fil_path_to_mysql_datadir,
  1421. os_proc_get_number());
  1422. srv_monitor_file = fopen(srv_monitor_file_name, "w+");
  1423. if (!srv_monitor_file) {
  1424. ib::error() << "Unable to create "
  1425. << srv_monitor_file_name << ": "
  1426. << strerror(errno);
  1427. if (err == DB_SUCCESS) {
  1428. err = DB_ERROR;
  1429. }
  1430. }
  1431. } else {
  1432. srv_monitor_file_name = NULL;
  1433. srv_monitor_file = os_file_create_tmpfile();
  1434. if (!srv_monitor_file && err == DB_SUCCESS) {
  1435. err = DB_ERROR;
  1436. }
  1437. }
  1438. mutex_create(LATCH_ID_SRV_MISC_TMPFILE,
  1439. &srv_misc_tmpfile_mutex);
  1440. srv_misc_tmpfile = os_file_create_tmpfile();
  1441. if (!srv_misc_tmpfile && err == DB_SUCCESS) {
  1442. err = DB_ERROR;
  1443. }
  1444. }
  1445. if (err != DB_SUCCESS) {
  1446. return(srv_init_abort(err));
  1447. }
  1448. srv_n_file_io_threads = srv_n_read_io_threads;
  1449. srv_n_file_io_threads += srv_n_write_io_threads;
  1450. if (!srv_read_only_mode) {
  1451. /* Add the log and ibuf IO threads. */
  1452. srv_n_file_io_threads += 2;
  1453. } else {
  1454. ib::info() << "Disabling background log and ibuf IO write"
  1455. << " threads.";
  1456. }
  1457. ut_a(srv_n_file_io_threads <= SRV_MAX_N_IO_THREADS);
  1458. if (!os_aio_init(srv_n_read_io_threads,
  1459. srv_n_write_io_threads,
  1460. SRV_MAX_N_PENDING_SYNC_IOS)) {
  1461. ib::error() << "Cannot initialize AIO sub-system";
  1462. return(srv_init_abort(DB_ERROR));
  1463. }
  1464. fil_system.create(srv_file_per_table ? 50000 : 5000);
  1465. double size;
  1466. char unit;
  1467. if (srv_buf_pool_size >= 1024 * 1024 * 1024) {
  1468. size = ((double) srv_buf_pool_size) / (1024 * 1024 * 1024);
  1469. unit = 'G';
  1470. } else {
  1471. size = ((double) srv_buf_pool_size) / (1024 * 1024);
  1472. unit = 'M';
  1473. }
  1474. double chunk_size;
  1475. char chunk_unit;
  1476. if (srv_buf_pool_chunk_unit >= 1024 * 1024 * 1024) {
  1477. chunk_size = srv_buf_pool_chunk_unit / 1024.0 / 1024 / 1024;
  1478. chunk_unit = 'G';
  1479. } else {
  1480. chunk_size = srv_buf_pool_chunk_unit / 1024.0 / 1024;
  1481. chunk_unit = 'M';
  1482. }
  1483. ib::info() << "Initializing buffer pool, total size = "
  1484. << size << unit << ", instances = " << srv_buf_pool_instances
  1485. << ", chunk size = " << chunk_size << chunk_unit;
  1486. err = buf_pool_init(srv_buf_pool_size, srv_buf_pool_instances);
  1487. if (err != DB_SUCCESS) {
  1488. ib::error() << "Cannot allocate memory for the buffer pool";
  1489. return(srv_init_abort(DB_ERROR));
  1490. }
  1491. ib::info() << "Completed initialization of buffer pool";
  1492. #ifdef UNIV_DEBUG
  1493. /* We have observed deadlocks with a 5MB buffer pool but
  1494. the actual lower limit could very well be a little higher. */
  1495. if (srv_buf_pool_size <= 5 * 1024 * 1024) {
  1496. ib::info() << "Small buffer pool size ("
  1497. << srv_buf_pool_size / 1024 / 1024
  1498. << "M), the flst_validate() debug function can cause a"
  1499. << " deadlock if the buffer pool fills up.";
  1500. }
  1501. #endif /* UNIV_DEBUG */
  1502. log_sys_init();
  1503. recv_sys_init();
  1504. lock_sys.create(srv_lock_table_size);
  1505. /* Create i/o-handler threads: */
  1506. for (ulint t = 0; t < srv_n_file_io_threads; ++t) {
  1507. n[t] = t;
  1508. thread_handles[t] = os_thread_create(io_handler_thread, n + t, thread_ids + t);
  1509. thread_started[t] = true;
  1510. }
  1511. if (!srv_read_only_mode) {
  1512. buf_flush_page_cleaner_init();
  1513. buf_page_cleaner_is_active = true;
  1514. os_thread_create(buf_flush_page_cleaner_coordinator,
  1515. NULL, NULL);
  1516. /* Create page cleaner workers if needed. For example
  1517. mariabackup could set srv_n_page_cleaners = 0. */
  1518. if (srv_n_page_cleaners > 1) {
  1519. buf_flush_set_page_cleaner_thread_cnt(srv_n_page_cleaners);
  1520. }
  1521. #ifdef UNIV_LINUX
  1522. /* Wait for the setpriority() call to finish. */
  1523. os_event_wait(recv_sys->flush_end);
  1524. #endif /* UNIV_LINUX */
  1525. srv_start_state_set(SRV_START_STATE_IO);
  1526. }
  1527. if (srv_n_log_files * srv_log_file_size >= 512ULL << 30) {
  1528. /* log_block_convert_lsn_to_no() limits the returned block
  1529. number to 1G and given that OS_FILE_LOG_BLOCK_SIZE is 512
  1530. bytes, then we have a limit of 512 GB. If that limit is to
  1531. be raised, then log_block_convert_lsn_to_no() must be
  1532. modified. */
  1533. ib::error() << "Combined size of log files must be < 512 GB";
  1534. return(srv_init_abort(DB_ERROR));
  1535. }
  1536. os_normalize_path(srv_data_home);
  1537. /* Check if the data files exist or not. */
  1538. err = srv_sys_space.check_file_spec(
  1539. &create_new_db, MIN_EXPECTED_TABLESPACE_SIZE);
  1540. if (err != DB_SUCCESS) {
  1541. return(srv_init_abort(DB_ERROR));
  1542. }
  1543. srv_startup_is_before_trx_rollback_phase = !create_new_db;
  1544. /* Check if undo tablespaces and redo log files exist before creating
  1545. a new system tablespace */
  1546. if (create_new_db) {
  1547. err = srv_check_undo_redo_logs_exists();
  1548. if (err != DB_SUCCESS) {
  1549. return(srv_init_abort(DB_ERROR));
  1550. }
  1551. recv_sys_debug_free();
  1552. }
  1553. /* Open or create the data files. */
  1554. ulint sum_of_new_sizes;
  1555. err = srv_sys_space.open_or_create(
  1556. false, create_new_db, &sum_of_new_sizes, &flushed_lsn);
  1557. switch (err) {
  1558. case DB_SUCCESS:
  1559. break;
  1560. case DB_CANNOT_OPEN_FILE:
  1561. ib::error()
  1562. << "Could not open or create the system tablespace. If"
  1563. " you tried to add new data files to the system"
  1564. " tablespace, and it failed here, you should now"
  1565. " edit innodb_data_file_path in my.cnf back to what"
  1566. " it was, and remove the new ibdata files InnoDB"
  1567. " created in this failed attempt. InnoDB only wrote"
  1568. " those files full of zeros, but did not yet use"
  1569. " them in any way. But be careful: do not remove"
  1570. " old data files which contain your precious data!";
  1571. /* fall through */
  1572. default:
  1573. /* Other errors might come from Datafile::validate_first_page() */
  1574. return(srv_init_abort(err));
  1575. }
  1576. dirnamelen = strlen(srv_log_group_home_dir);
  1577. ut_a(dirnamelen < (sizeof logfilename) - 10 - sizeof "ib_logfile");
  1578. memcpy(logfilename, srv_log_group_home_dir, dirnamelen);
  1579. /* Add a path separator if needed. */
  1580. if (dirnamelen && logfilename[dirnamelen - 1] != OS_PATH_SEPARATOR) {
  1581. logfilename[dirnamelen++] = OS_PATH_SEPARATOR;
  1582. }
  1583. srv_log_file_size_requested = srv_log_file_size;
  1584. if (create_new_db) {
  1585. buf_flush_sync_all_buf_pools();
  1586. flushed_lsn = log_get_lsn();
  1587. err = create_log_files(
  1588. logfilename, dirnamelen, flushed_lsn, logfile0);
  1589. if (err != DB_SUCCESS) {
  1590. return(srv_init_abort(err));
  1591. }
  1592. } else {
  1593. for (i = 0; i < SRV_N_LOG_FILES_MAX; i++) {
  1594. os_offset_t size;
  1595. os_file_stat_t stat_info;
  1596. sprintf(logfilename + dirnamelen,
  1597. "ib_logfile%u", i);
  1598. err = os_file_get_status(
  1599. logfilename, &stat_info, false,
  1600. srv_read_only_mode);
  1601. if (err == DB_NOT_FOUND) {
  1602. if (i == 0) {
  1603. if (srv_operation
  1604. == SRV_OPERATION_RESTORE
  1605. || srv_operation
  1606. == SRV_OPERATION_RESTORE_EXPORT) {
  1607. return(DB_SUCCESS);
  1608. }
  1609. if (flushed_lsn
  1610. < static_cast<lsn_t>(1000)) {
  1611. ib::error()
  1612. << "Cannot create"
  1613. " log files because"
  1614. " data files are"
  1615. " corrupt or the"
  1616. " database was not"
  1617. " shut down cleanly"
  1618. " after creating"
  1619. " the data files.";
  1620. return(srv_init_abort(
  1621. DB_ERROR));
  1622. }
  1623. err = create_log_files(
  1624. logfilename, dirnamelen,
  1625. flushed_lsn, logfile0);
  1626. if (err == DB_SUCCESS) {
  1627. err = create_log_files_rename(
  1628. logfilename,
  1629. dirnamelen,
  1630. flushed_lsn, logfile0);
  1631. }
  1632. if (err != DB_SUCCESS) {
  1633. return(srv_init_abort(err));
  1634. }
  1635. /* Suppress the message about
  1636. crash recovery. */
  1637. flushed_lsn = log_get_lsn();
  1638. goto files_checked;
  1639. }
  1640. /* opened all files */
  1641. break;
  1642. }
  1643. if (!srv_file_check_mode(logfilename)) {
  1644. return(srv_init_abort(DB_ERROR));
  1645. }
  1646. err = open_log_file(&files[i], logfilename, &size);
  1647. if (err != DB_SUCCESS) {
  1648. return(srv_init_abort(err));
  1649. }
  1650. ut_a(size != (os_offset_t) -1);
  1651. if (size & (OS_FILE_LOG_BLOCK_SIZE - 1)) {
  1652. ib::error() << "Log file " << logfilename
  1653. << " size " << size << " is not a"
  1654. " multiple of 512 bytes";
  1655. return(srv_init_abort(DB_ERROR));
  1656. }
  1657. if (i == 0) {
  1658. if (size == 0
  1659. && (srv_operation
  1660. == SRV_OPERATION_RESTORE
  1661. || srv_operation
  1662. == SRV_OPERATION_RESTORE_EXPORT)) {
  1663. /* Tolerate an empty ib_logfile0
  1664. from a previous run of
  1665. mariabackup --prepare. */
  1666. return(DB_SUCCESS);
  1667. }
  1668. /* The first log file must consist of
  1669. at least the following 512-byte pages:
  1670. header, checkpoint page 1, empty,
  1671. checkpoint page 2, redo log page(s) */
  1672. if (size <= OS_FILE_LOG_BLOCK_SIZE * 4) {
  1673. ib::error() << "Log file "
  1674. << logfilename << " size "
  1675. << size << " is too small";
  1676. return(srv_init_abort(DB_ERROR));
  1677. }
  1678. srv_log_file_size = size;
  1679. } else if (size != srv_log_file_size) {
  1680. ib::error() << "Log file " << logfilename
  1681. << " is of different size " << size
  1682. << " bytes than other log files "
  1683. << srv_log_file_size << " bytes!";
  1684. return(srv_init_abort(DB_ERROR));
  1685. }
  1686. }
  1687. srv_n_log_files_found = i;
  1688. /* Create the in-memory file space objects. */
  1689. sprintf(logfilename + dirnamelen, "ib_logfile%u", 0);
  1690. /* Disable the doublewrite buffer for log files. */
  1691. fil_space_t* log_space = fil_space_create(
  1692. "innodb_redo_log",
  1693. SRV_LOG_SPACE_FIRST_ID, 0,
  1694. FIL_TYPE_LOG,
  1695. NULL /* no encryption yet */);
  1696. ut_a(fil_validate());
  1697. ut_a(log_space);
  1698. ut_a(srv_log_file_size <= 512ULL << 30);
  1699. const ulint size = 1 + ulint((srv_log_file_size - 1)
  1700. >> srv_page_size_shift);
  1701. for (unsigned j = 0; j < srv_n_log_files_found; j++) {
  1702. sprintf(logfilename + dirnamelen, "ib_logfile%u", j);
  1703. if (!fil_node_create(logfilename, size,
  1704. log_space, false, false)) {
  1705. return(srv_init_abort(DB_ERROR));
  1706. }
  1707. }
  1708. log_init(srv_n_log_files_found);
  1709. if (!log_set_capacity(srv_log_file_size_requested)) {
  1710. return(srv_init_abort(DB_ERROR));
  1711. }
  1712. }
  1713. files_checked:
  1714. /* Open all log files and data files in the system
  1715. tablespace: we keep them open until database
  1716. shutdown */
  1717. fil_open_log_and_system_tablespace_files();
  1718. ut_d(fil_space_get(0)->recv_size = srv_sys_space_size_debug);
  1719. err = srv_undo_tablespaces_init(create_new_db);
  1720. /* If the force recovery is set very high then we carry on regardless
  1721. of all errors. Basically this is fingers crossed mode. */
  1722. if (err != DB_SUCCESS
  1723. && srv_force_recovery < SRV_FORCE_NO_UNDO_LOG_SCAN) {
  1724. return(srv_init_abort(err));
  1725. }
  1726. /* Initialize objects used by dict stats gathering thread, which
  1727. can also be used by recovery if it tries to drop some table */
  1728. if (!srv_read_only_mode) {
  1729. dict_stats_thread_init();
  1730. }
  1731. trx_sys.create();
  1732. if (create_new_db) {
  1733. ut_a(!srv_read_only_mode);
  1734. mtr_start(&mtr);
  1735. fsp_header_init(0, sum_of_new_sizes, &mtr);
  1736. compile_time_assert(TRX_SYS_SPACE == 0);
  1737. compile_time_assert(IBUF_SPACE_ID == 0);
  1738. ulint ibuf_root = btr_create(
  1739. DICT_CLUSTERED | DICT_IBUF,
  1740. 0, univ_page_size, DICT_IBUF_ID_MIN,
  1741. dict_ind_redundant, NULL, &mtr);
  1742. mtr_commit(&mtr);
  1743. if (ibuf_root == FIL_NULL) {
  1744. return(srv_init_abort(DB_ERROR));
  1745. }
  1746. ut_ad(ibuf_root == IBUF_TREE_ROOT_PAGE_NO);
  1747. /* To maintain backward compatibility we create only
  1748. the first rollback segment before the double write buffer.
  1749. All the remaining rollback segments will be created later,
  1750. after the double write buffer has been created. */
  1751. trx_sys_create_sys_pages();
  1752. trx_lists_init_at_db_start();
  1753. err = dict_create();
  1754. if (err != DB_SUCCESS) {
  1755. return(srv_init_abort(err));
  1756. }
  1757. buf_flush_sync_all_buf_pools();
  1758. flushed_lsn = log_get_lsn();
  1759. err = fil_write_flushed_lsn(flushed_lsn);
  1760. if (err == DB_SUCCESS) {
  1761. err = create_log_files_rename(
  1762. logfilename, dirnamelen,
  1763. flushed_lsn, logfile0);
  1764. }
  1765. if (err != DB_SUCCESS) {
  1766. return(srv_init_abort(err));
  1767. }
  1768. } else {
  1769. /* Invalidate the buffer pool to ensure that we reread
  1770. the page that we read above, during recovery.
  1771. Note that this is not as heavy weight as it seems. At
  1772. this point there will be only ONE page in the buf_LRU
  1773. and there must be no page in the buf_flush list. */
  1774. buf_pool_invalidate();
  1775. /* Scan and locate truncate log files. Parsed located files
  1776. and add table to truncate information to central vector for
  1777. truncate fix-up action post recovery. */
  1778. err = TruncateLogParser::scan_and_parse(srv_log_group_home_dir);
  1779. if (err != DB_SUCCESS) {
  1780. return(srv_init_abort(DB_ERROR));
  1781. }
  1782. /* We always try to do a recovery, even if the database had
  1783. been shut down normally: this is the normal startup path */
  1784. err = recv_recovery_from_checkpoint_start(flushed_lsn);
  1785. recv_sys->dblwr.pages.clear();
  1786. if (err != DB_SUCCESS) {
  1787. return(srv_init_abort(err));
  1788. }
  1789. switch (srv_operation) {
  1790. case SRV_OPERATION_NORMAL:
  1791. case SRV_OPERATION_RESTORE_EXPORT:
  1792. /* Initialize the change buffer. */
  1793. err = dict_boot();
  1794. if (err != DB_SUCCESS) {
  1795. return(srv_init_abort(err));
  1796. }
  1797. /* fall through */
  1798. case SRV_OPERATION_RESTORE:
  1799. /* This must precede
  1800. recv_apply_hashed_log_recs(true). */
  1801. trx_lists_init_at_db_start();
  1802. break;
  1803. case SRV_OPERATION_RESTORE_DELTA:
  1804. case SRV_OPERATION_BACKUP:
  1805. ut_ad(!"wrong mariabackup mode");
  1806. }
  1807. if (srv_force_recovery < SRV_FORCE_NO_LOG_REDO) {
  1808. /* Apply the hashed log records to the
  1809. respective file pages, for the last batch of
  1810. recv_group_scan_log_recs(). */
  1811. recv_apply_hashed_log_recs(true);
  1812. if (recv_sys->found_corrupt_log) {
  1813. return(srv_init_abort(DB_CORRUPTION));
  1814. }
  1815. DBUG_PRINT("ib_log", ("apply completed"));
  1816. if (recv_needed_recovery) {
  1817. trx_sys_print_mysql_binlog_offset();
  1818. }
  1819. }
  1820. if (!srv_read_only_mode) {
  1821. const ulint flags = FSP_FLAGS_PAGE_SSIZE();
  1822. for (ulint id = 0; id <= srv_undo_tablespaces; id++) {
  1823. if (fil_space_get(id)) {
  1824. fsp_flags_try_adjust(id, flags);
  1825. }
  1826. }
  1827. if (sum_of_new_sizes > 0) {
  1828. /* New data file(s) were added */
  1829. mtr.start();
  1830. fsp_header_inc_size(0, sum_of_new_sizes, &mtr);
  1831. mtr.commit();
  1832. /* Immediately write the log record about
  1833. increased tablespace size to disk, so that it
  1834. is durable even if mysqld would crash
  1835. quickly */
  1836. log_buffer_flush_to_disk();
  1837. }
  1838. }
  1839. const ulint tablespace_size_in_header
  1840. = fsp_header_get_tablespace_size();
  1841. const ulint sum_of_data_file_sizes
  1842. = srv_sys_space.get_sum_of_sizes();
  1843. /* Compare the system tablespace file size to what is
  1844. stored in FSP_SIZE. In srv_sys_space.open_or_create()
  1845. we already checked that the file sizes match the
  1846. innodb_data_file_path specification. */
  1847. if (srv_read_only_mode
  1848. || sum_of_data_file_sizes == tablespace_size_in_header) {
  1849. /* Do not complain about the size. */
  1850. } else if (!srv_sys_space.can_auto_extend_last_file()
  1851. || sum_of_data_file_sizes
  1852. < tablespace_size_in_header) {
  1853. ib::error() << "Tablespace size stored in header is "
  1854. << tablespace_size_in_header
  1855. << " pages, but the sum of data file sizes is "
  1856. << sum_of_data_file_sizes << " pages";
  1857. if (srv_force_recovery == 0
  1858. && sum_of_data_file_sizes
  1859. < tablespace_size_in_header) {
  1860. ib::error() <<
  1861. "Cannot start InnoDB. The tail of"
  1862. " the system tablespace is"
  1863. " missing. Have you edited"
  1864. " innodb_data_file_path in my.cnf"
  1865. " in an inappropriate way, removing"
  1866. " data files from there?"
  1867. " You can set innodb_force_recovery=1"
  1868. " in my.cnf to force"
  1869. " a startup if you are trying to"
  1870. " recover a badly corrupt database.";
  1871. return(srv_init_abort(DB_ERROR));
  1872. }
  1873. }
  1874. /* recv_recovery_from_checkpoint_finish needs trx lists which
  1875. are initialized in trx_lists_init_at_db_start(). */
  1876. recv_recovery_from_checkpoint_finish();
  1877. if (srv_operation == SRV_OPERATION_RESTORE
  1878. || srv_operation == SRV_OPERATION_RESTORE_EXPORT) {
  1879. /* After applying the redo log from
  1880. SRV_OPERATION_BACKUP, flush the changes
  1881. to the data files and truncate or delete the log.
  1882. Unless --export is specified, no further change to
  1883. InnoDB files is needed. */
  1884. ut_ad(!srv_force_recovery);
  1885. ut_ad(srv_n_log_files_found <= 1);
  1886. ut_ad(recv_no_log_write);
  1887. buf_flush_sync_all_buf_pools();
  1888. err = fil_write_flushed_lsn(log_get_lsn());
  1889. ut_ad(!buf_pool_check_no_pending_io());
  1890. fil_close_log_files(true);
  1891. log_group_close_all();
  1892. if (err == DB_SUCCESS) {
  1893. bool trunc = srv_operation
  1894. == SRV_OPERATION_RESTORE;
  1895. /* Delete subsequent log files. */
  1896. delete_log_files(logfilename, dirnamelen,
  1897. (uint)srv_n_log_files_found, trunc);
  1898. if (trunc) {
  1899. /* Truncate the first log file. */
  1900. strcpy(logfilename + dirnamelen,
  1901. "ib_logfile0");
  1902. FILE* f = fopen(logfilename, "w");
  1903. fclose(f);
  1904. }
  1905. }
  1906. return(err);
  1907. }
  1908. /* Upgrade or resize or rebuild the redo logs before
  1909. generating any dirty pages, so that the old redo log
  1910. files will not be written to. */
  1911. if (srv_force_recovery == SRV_FORCE_NO_LOG_REDO) {
  1912. /* Completely ignore the redo log. */
  1913. } else if (srv_read_only_mode) {
  1914. /* Leave the redo log alone. */
  1915. } else if (srv_log_file_size_requested == srv_log_file_size
  1916. && srv_n_log_files_found == srv_n_log_files
  1917. && log_sys->log.format
  1918. == (srv_encrypt_log
  1919. ? LOG_HEADER_FORMAT_CURRENT
  1920. | LOG_HEADER_FORMAT_ENCRYPTED
  1921. : LOG_HEADER_FORMAT_CURRENT)) {
  1922. /* No need to upgrade or resize the redo log. */
  1923. } else {
  1924. /* Prepare to delete the old redo log files */
  1925. flushed_lsn = srv_prepare_to_delete_redo_log_files(i);
  1926. DBUG_EXECUTE_IF("innodb_log_abort_1",
  1927. return(srv_init_abort(DB_ERROR)););
  1928. /* Prohibit redo log writes from any other
  1929. threads until creating a log checkpoint at the
  1930. end of create_log_files(). */
  1931. ut_d(recv_no_log_write = true);
  1932. ut_ad(!buf_pool_check_no_pending_io());
  1933. DBUG_EXECUTE_IF("innodb_log_abort_3",
  1934. return(srv_init_abort(DB_ERROR)););
  1935. DBUG_PRINT("ib_log", ("After innodb_log_abort_3"));
  1936. /* Stamp the LSN to the data files. */
  1937. err = fil_write_flushed_lsn(flushed_lsn);
  1938. DBUG_EXECUTE_IF("innodb_log_abort_4", err = DB_ERROR;);
  1939. DBUG_PRINT("ib_log", ("After innodb_log_abort_4"));
  1940. if (err != DB_SUCCESS) {
  1941. return(srv_init_abort(err));
  1942. }
  1943. /* Close and free the redo log files, so that
  1944. we can replace them. */
  1945. fil_close_log_files(true);
  1946. DBUG_EXECUTE_IF("innodb_log_abort_5",
  1947. return(srv_init_abort(DB_ERROR)););
  1948. DBUG_PRINT("ib_log", ("After innodb_log_abort_5"));
  1949. /* Free the old log file space. */
  1950. log_group_close_all();
  1951. ib::info() << "Starting to delete and rewrite log"
  1952. " files.";
  1953. srv_log_file_size = srv_log_file_size_requested;
  1954. err = create_log_files(
  1955. logfilename, dirnamelen, flushed_lsn,
  1956. logfile0);
  1957. if (err == DB_SUCCESS) {
  1958. err = create_log_files_rename(
  1959. logfilename, dirnamelen, flushed_lsn,
  1960. logfile0);
  1961. }
  1962. if (err != DB_SUCCESS) {
  1963. return(srv_init_abort(err));
  1964. }
  1965. }
  1966. /* Validate a few system page types that were left
  1967. uninitialized by older versions of MySQL. */
  1968. if (!high_level_read_only) {
  1969. mtr_t mtr;
  1970. buf_block_t* block;
  1971. mtr.start();
  1972. mtr.set_sys_modified();
  1973. /* Bitmap page types will be reset in
  1974. buf_dblwr_check_block() without redo logging. */
  1975. block = buf_page_get(
  1976. page_id_t(IBUF_SPACE_ID,
  1977. FSP_IBUF_HEADER_PAGE_NO),
  1978. univ_page_size, RW_X_LATCH, &mtr);
  1979. fil_block_check_type(block, FIL_PAGE_TYPE_SYS, &mtr);
  1980. /* Already MySQL 3.23.53 initialized
  1981. FSP_IBUF_TREE_ROOT_PAGE_NO to
  1982. FIL_PAGE_INDEX. No need to reset that one. */
  1983. block = buf_page_get(
  1984. page_id_t(TRX_SYS_SPACE, TRX_SYS_PAGE_NO),
  1985. univ_page_size, RW_X_LATCH, &mtr);
  1986. fil_block_check_type(block, FIL_PAGE_TYPE_TRX_SYS,
  1987. &mtr);
  1988. block = buf_page_get(
  1989. page_id_t(TRX_SYS_SPACE,
  1990. FSP_FIRST_RSEG_PAGE_NO),
  1991. univ_page_size, RW_X_LATCH, &mtr);
  1992. fil_block_check_type(block, FIL_PAGE_TYPE_SYS, &mtr);
  1993. block = buf_page_get(
  1994. page_id_t(TRX_SYS_SPACE, FSP_DICT_HDR_PAGE_NO),
  1995. univ_page_size, RW_X_LATCH, &mtr);
  1996. fil_block_check_type(block, FIL_PAGE_TYPE_SYS, &mtr);
  1997. mtr.commit();
  1998. }
  1999. /* Roll back any recovered data dictionary transactions, so
  2000. that the data dictionary tables will be free of any locks.
  2001. The data dictionary latch should guarantee that there is at
  2002. most one data dictionary transaction active at a time. */
  2003. if (srv_force_recovery < SRV_FORCE_NO_TRX_UNDO) {
  2004. trx_rollback_recovered(false);
  2005. }
  2006. /* Fix-up truncate of tables in the system tablespace
  2007. if server crashed while truncate was active. The non-
  2008. system tables are done after tablespace discovery. Do
  2009. this now because this procedure assumes that no pages
  2010. have changed since redo recovery. Tablespace discovery
  2011. can do updates to pages in the system tablespace.*/
  2012. err = truncate_t::fixup_tables_in_system_tablespace();
  2013. if (srv_force_recovery < SRV_FORCE_NO_IBUF_MERGE) {
  2014. /* Open or Create SYS_TABLESPACES and SYS_DATAFILES
  2015. so that tablespace names and other metadata can be
  2016. found. */
  2017. err = dict_create_or_check_sys_tablespace();
  2018. if (err != DB_SUCCESS) {
  2019. return(srv_init_abort(err));
  2020. }
  2021. /* The following call is necessary for the insert
  2022. buffer to work with multiple tablespaces. We must
  2023. know the mapping between space id's and .ibd file
  2024. names.
  2025. In a crash recovery, we check that the info in data
  2026. dictionary is consistent with what we already know
  2027. about space id's from the calls to fil_ibd_load().
  2028. In a normal startup, we create the space objects for
  2029. every table in the InnoDB data dictionary that has
  2030. an .ibd file.
  2031. We also determine the maximum tablespace id used.
  2032. The 'validate' flag indicates that when a tablespace
  2033. is opened, we also read the header page and validate
  2034. the contents to the data dictionary. This is time
  2035. consuming, especially for databases with lots of ibd
  2036. files. So only do it after a crash and not forcing
  2037. recovery. Open rw transactions at this point is not
  2038. a good reason to validate. */
  2039. bool validate = recv_needed_recovery
  2040. && srv_force_recovery == 0;
  2041. dict_check_tablespaces_and_store_max_id(validate);
  2042. }
  2043. /* Fix-up truncate of table if server crashed while truncate
  2044. was active. */
  2045. err = truncate_t::fixup_tables_in_non_system_tablespace();
  2046. if (err != DB_SUCCESS) {
  2047. return(srv_init_abort(err));
  2048. }
  2049. recv_recovery_rollback_active();
  2050. srv_startup_is_before_trx_rollback_phase = FALSE;
  2051. }
  2052. ut_ad(err == DB_SUCCESS);
  2053. ut_a(sum_of_new_sizes != ULINT_UNDEFINED);
  2054. /* Create the doublewrite buffer to a new tablespace */
  2055. if (!srv_read_only_mode && srv_force_recovery < SRV_FORCE_NO_TRX_UNDO
  2056. && !buf_dblwr_create()) {
  2057. return(srv_init_abort(DB_ERROR));
  2058. }
  2059. /* Here the double write buffer has already been created and so
  2060. any new rollback segments will be allocated after the double
  2061. write buffer. The default segment should already exist.
  2062. We create the new segments only if it's a new database or
  2063. the database was shutdown cleanly. */
  2064. /* Note: When creating the extra rollback segments during an upgrade
  2065. we violate the latching order, even if the change buffer is empty.
  2066. We make an exception in sync0sync.cc and check srv_is_being_started
  2067. for that violation. It cannot create a deadlock because we are still
  2068. running in single threaded mode essentially. Only the IO threads
  2069. should be running at this stage. */
  2070. ut_a(srv_undo_logs > 0);
  2071. ut_a(srv_undo_logs <= TRX_SYS_N_RSEGS);
  2072. if (!trx_sys_create_rsegs()) {
  2073. return(srv_init_abort(DB_ERROR));
  2074. }
  2075. srv_startup_is_before_trx_rollback_phase = false;
  2076. if (!srv_read_only_mode) {
  2077. /* Create the thread which watches the timeouts
  2078. for lock waits */
  2079. thread_handles[2 + SRV_MAX_N_IO_THREADS] = os_thread_create(
  2080. lock_wait_timeout_thread,
  2081. NULL, thread_ids + 2 + SRV_MAX_N_IO_THREADS);
  2082. thread_started[2 + SRV_MAX_N_IO_THREADS] = true;
  2083. lock_sys.timeout_thread_active = true;
  2084. /* Create the thread which warns of long semaphore waits */
  2085. srv_error_monitor_active = true;
  2086. thread_handles[3 + SRV_MAX_N_IO_THREADS] = os_thread_create(
  2087. srv_error_monitor_thread,
  2088. NULL, thread_ids + 3 + SRV_MAX_N_IO_THREADS);
  2089. thread_started[3 + SRV_MAX_N_IO_THREADS] = true;
  2090. /* Create the thread which prints InnoDB monitor info */
  2091. srv_monitor_active = true;
  2092. thread_handles[4 + SRV_MAX_N_IO_THREADS] = os_thread_create(
  2093. srv_monitor_thread,
  2094. NULL, thread_ids + 4 + SRV_MAX_N_IO_THREADS);
  2095. thread_started[4 + SRV_MAX_N_IO_THREADS] = true;
  2096. srv_start_state |= SRV_START_STATE_LOCK_SYS
  2097. | SRV_START_STATE_MONITOR;
  2098. ut_ad(srv_force_recovery >= SRV_FORCE_NO_UNDO_LOG_SCAN
  2099. || trx_purge_state() == PURGE_STATE_INIT);
  2100. if (srv_force_recovery < SRV_FORCE_NO_BACKGROUND) {
  2101. srv_undo_sources = true;
  2102. /* Create the dict stats gathering thread */
  2103. srv_dict_stats_thread_active = true;
  2104. dict_stats_thread_handle = os_thread_create(
  2105. dict_stats_thread, NULL, NULL);
  2106. /* Create the thread that will optimize the
  2107. FULLTEXT search index subsystem. */
  2108. fts_optimize_init();
  2109. }
  2110. }
  2111. /* Create the SYS_FOREIGN and SYS_FOREIGN_COLS system tables */
  2112. err = dict_create_or_check_foreign_constraint_tables();
  2113. if (err == DB_SUCCESS) {
  2114. err = dict_create_or_check_sys_tablespace();
  2115. if (err == DB_SUCCESS) {
  2116. err = dict_create_or_check_sys_virtual();
  2117. }
  2118. }
  2119. switch (err) {
  2120. case DB_SUCCESS:
  2121. break;
  2122. case DB_READ_ONLY:
  2123. if (srv_force_recovery >= SRV_FORCE_NO_TRX_UNDO) {
  2124. break;
  2125. }
  2126. ib::error() << "Cannot create system tables in read-only mode";
  2127. /* fall through */
  2128. default:
  2129. return(srv_init_abort(err));
  2130. }
  2131. if (!srv_read_only_mode && srv_operation == SRV_OPERATION_NORMAL) {
  2132. /* Initialize the innodb_temporary tablespace and keep
  2133. it open until shutdown. */
  2134. err = srv_open_tmp_tablespace(create_new_db);
  2135. if (err != DB_SUCCESS) {
  2136. return(srv_init_abort(err));
  2137. }
  2138. trx_temp_rseg_create();
  2139. thread_handles[1 + SRV_MAX_N_IO_THREADS] = os_thread_create(
  2140. srv_master_thread,
  2141. NULL, thread_ids + (1 + SRV_MAX_N_IO_THREADS));
  2142. thread_started[1 + SRV_MAX_N_IO_THREADS] = true;
  2143. srv_start_state_set(SRV_START_STATE_MASTER);
  2144. }
  2145. if (!srv_read_only_mode && srv_operation == SRV_OPERATION_NORMAL
  2146. && srv_force_recovery < SRV_FORCE_NO_BACKGROUND) {
  2147. thread_handles[5 + SRV_MAX_N_IO_THREADS] = os_thread_create(
  2148. srv_purge_coordinator_thread,
  2149. NULL, thread_ids + 5 + SRV_MAX_N_IO_THREADS);
  2150. thread_started[5 + SRV_MAX_N_IO_THREADS] = true;
  2151. ut_a(UT_ARR_SIZE(thread_ids)
  2152. > 5 + srv_n_purge_threads + SRV_MAX_N_IO_THREADS);
  2153. /* We've already created the purge coordinator thread above. */
  2154. for (i = 1; i < srv_n_purge_threads; ++i) {
  2155. thread_handles[5 + i + SRV_MAX_N_IO_THREADS] = os_thread_create(
  2156. srv_worker_thread, NULL,
  2157. thread_ids + 5 + i + SRV_MAX_N_IO_THREADS);
  2158. thread_started[5 + i + SRV_MAX_N_IO_THREADS] = true;
  2159. }
  2160. srv_start_wait_for_purge_to_start();
  2161. srv_start_state_set(SRV_START_STATE_PURGE);
  2162. } else {
  2163. purge_sys.state = PURGE_STATE_DISABLED;
  2164. }
  2165. srv_is_being_started = false;
  2166. if (!srv_read_only_mode) {
  2167. /* wake main loop of page cleaner up */
  2168. os_event_set(buf_flush_event);
  2169. }
  2170. if (srv_print_verbose_log) {
  2171. ib::info() << INNODB_VERSION_STR
  2172. << " started; log sequence number "
  2173. << srv_start_lsn
  2174. << "; transaction id " << trx_sys.get_max_trx_id();
  2175. }
  2176. if (srv_force_recovery > 0) {
  2177. ib::info() << "!!! innodb_force_recovery is set to "
  2178. << srv_force_recovery << " !!!";
  2179. }
  2180. if (srv_force_recovery == 0) {
  2181. /* In the insert buffer we may have even bigger tablespace
  2182. id's, because we may have dropped those tablespaces, but
  2183. insert buffer merge has not had time to clean the records from
  2184. the ibuf tree. */
  2185. ibuf_update_max_tablespace_id();
  2186. }
  2187. if (!srv_read_only_mode) {
  2188. if (create_new_db) {
  2189. srv_buffer_pool_load_at_startup = FALSE;
  2190. }
  2191. #ifdef WITH_WSREP
  2192. /*
  2193. Create the dump/load thread only when not running with
  2194. --wsrep-recover.
  2195. */
  2196. if (!wsrep_recovery) {
  2197. #endif /* WITH_WSREP */
  2198. /* Create the buffer pool dump/load thread */
  2199. srv_buf_dump_thread_active = true;
  2200. buf_dump_thread_handle=
  2201. os_thread_create(buf_dump_thread, NULL, NULL);
  2202. #ifdef WITH_WSREP
  2203. } else {
  2204. ib::warn() <<
  2205. "Skipping buffer pool dump/restore during "
  2206. "wsrep recovery.";
  2207. }
  2208. #endif /* WITH_WSREP */
  2209. /* Create thread(s) that handles key rotation. This is
  2210. needed already here as log_preflush_pool_modified_pages
  2211. will flush dirty pages and that might need e.g.
  2212. fil_crypt_threads_event. */
  2213. fil_system_enter();
  2214. btr_scrub_init();
  2215. fil_crypt_threads_init();
  2216. fil_system_exit();
  2217. /* Initialize online defragmentation. */
  2218. btr_defragment_init();
  2219. btr_defragment_thread_active = true;
  2220. os_thread_create(btr_defragment_thread, NULL, NULL);
  2221. srv_start_state |= SRV_START_STATE_REDO;
  2222. }
  2223. /* Create the buffer pool resize thread */
  2224. srv_buf_resize_thread_active = true;
  2225. os_thread_create(buf_resize_thread, NULL, NULL);
  2226. return(DB_SUCCESS);
  2227. }
  2228. #if 0
  2229. /********************************************************************
  2230. Sync all FTS cache before shutdown */
  2231. static
  2232. void
  2233. srv_fts_close(void)
  2234. /*===============*/
  2235. {
  2236. dict_table_t* table;
  2237. for (table = UT_LIST_GET_FIRST(dict_sys->table_LRU);
  2238. table; table = UT_LIST_GET_NEXT(table_LRU, table)) {
  2239. fts_t* fts = table->fts;
  2240. if (fts != NULL) {
  2241. fts_sync_table(table);
  2242. }
  2243. }
  2244. for (table = UT_LIST_GET_FIRST(dict_sys->table_non_LRU);
  2245. table; table = UT_LIST_GET_NEXT(table_LRU, table)) {
  2246. fts_t* fts = table->fts;
  2247. if (fts != NULL) {
  2248. fts_sync_table(table);
  2249. }
  2250. }
  2251. }
  2252. #endif
  2253. /** Shut down background threads that can generate undo log. */
  2254. void
  2255. srv_shutdown_bg_undo_sources()
  2256. {
  2257. if (srv_undo_sources) {
  2258. ut_ad(!srv_read_only_mode);
  2259. fts_optimize_shutdown();
  2260. dict_stats_shutdown();
  2261. while (row_get_background_drop_list_len_low()) {
  2262. srv_wake_master_thread();
  2263. os_thread_yield();
  2264. }
  2265. srv_undo_sources = false;
  2266. }
  2267. }
  2268. /** Shut down InnoDB. */
  2269. void
  2270. innodb_shutdown()
  2271. {
  2272. ut_ad(!my_atomic_loadptr_explicit(reinterpret_cast<void**>
  2273. (&srv_running),
  2274. MY_MEMORY_ORDER_RELAXED));
  2275. ut_ad(!srv_undo_sources);
  2276. switch (srv_operation) {
  2277. case SRV_OPERATION_BACKUP:
  2278. case SRV_OPERATION_RESTORE:
  2279. case SRV_OPERATION_RESTORE_DELTA:
  2280. case SRV_OPERATION_RESTORE_EXPORT:
  2281. fil_close_all_files();
  2282. break;
  2283. case SRV_OPERATION_NORMAL:
  2284. /* Shut down the persistent files. */
  2285. logs_empty_and_mark_files_at_shutdown();
  2286. if (ulint n_threads = srv_conc_get_active_threads()) {
  2287. ib::warn() << "Query counter shows "
  2288. << n_threads << " queries still"
  2289. " inside InnoDB at shutdown";
  2290. }
  2291. }
  2292. /* Exit any remaining threads. */
  2293. srv_shutdown_all_bg_threads();
  2294. if (srv_monitor_file) {
  2295. fclose(srv_monitor_file);
  2296. srv_monitor_file = 0;
  2297. if (srv_monitor_file_name) {
  2298. unlink(srv_monitor_file_name);
  2299. ut_free(srv_monitor_file_name);
  2300. }
  2301. }
  2302. if (srv_misc_tmpfile) {
  2303. fclose(srv_misc_tmpfile);
  2304. srv_misc_tmpfile = 0;
  2305. }
  2306. ut_ad(dict_stats_event || !srv_was_started || srv_read_only_mode);
  2307. ut_ad(dict_sys || !srv_was_started);
  2308. ut_ad(trx_sys.is_initialised() || !srv_was_started);
  2309. ut_ad(buf_dblwr || !srv_was_started || srv_read_only_mode
  2310. || srv_force_recovery >= SRV_FORCE_NO_TRX_UNDO);
  2311. ut_ad(lock_sys.is_initialised() || !srv_was_started);
  2312. #ifdef BTR_CUR_HASH_ADAPT
  2313. ut_ad(btr_search_sys || !srv_was_started);
  2314. #endif /* BTR_CUR_HASH_ADAPT */
  2315. ut_ad(ibuf || !srv_was_started);
  2316. ut_ad(log_sys || !srv_was_started);
  2317. if (dict_stats_event) {
  2318. dict_stats_thread_deinit();
  2319. }
  2320. if (srv_start_state_is_set(SRV_START_STATE_REDO)) {
  2321. ut_ad(!srv_read_only_mode);
  2322. /* srv_shutdown_bg_undo_sources() already invoked
  2323. fts_optimize_shutdown(); dict_stats_shutdown(); */
  2324. fil_crypt_threads_cleanup();
  2325. btr_scrub_cleanup();
  2326. btr_defragment_shutdown();
  2327. }
  2328. /* This must be disabled before closing the buffer pool
  2329. and closing the data dictionary. */
  2330. #ifdef BTR_CUR_HASH_ADAPT
  2331. if (dict_sys) {
  2332. btr_search_disable(true);
  2333. }
  2334. #endif /* BTR_CUR_HASH_ADAPT */
  2335. if (ibuf) {
  2336. ibuf_close();
  2337. }
  2338. if (log_sys) {
  2339. log_shutdown();
  2340. }
  2341. trx_sys.close();
  2342. purge_sys.close();
  2343. if (buf_dblwr) {
  2344. buf_dblwr_free();
  2345. }
  2346. lock_sys.close();
  2347. trx_pool_close();
  2348. /* We don't create these mutexes in RO mode because we don't create
  2349. the temp files that the cover. */
  2350. if (!srv_read_only_mode) {
  2351. mutex_free(&srv_monitor_file_mutex);
  2352. mutex_free(&srv_misc_tmpfile_mutex);
  2353. }
  2354. if (dict_sys) {
  2355. dict_close();
  2356. }
  2357. #ifdef BTR_CUR_HASH_ADAPT
  2358. if (btr_search_sys) {
  2359. btr_search_sys_free();
  2360. }
  2361. #endif /* BTR_CUR_HASH_ADAPT */
  2362. /* 3. Free all InnoDB's own mutexes and the os_fast_mutexes inside
  2363. them */
  2364. os_aio_free();
  2365. row_mysql_close();
  2366. srv_free();
  2367. fil_system.close();
  2368. /* 4. Free all allocated memory */
  2369. pars_lexer_close();
  2370. recv_sys_close();
  2371. ut_ad(buf_pool_ptr || !srv_was_started);
  2372. if (buf_pool_ptr) {
  2373. buf_pool_free(srv_buf_pool_instances);
  2374. }
  2375. sync_check_close();
  2376. if (dict_foreign_err_file) {
  2377. fclose(dict_foreign_err_file);
  2378. }
  2379. if (srv_was_started && srv_print_verbose_log) {
  2380. ib::info() << "Shutdown completed; log sequence number "
  2381. << srv_shutdown_lsn
  2382. << "; transaction id " << trx_sys.get_max_trx_id();
  2383. }
  2384. srv_start_state = SRV_START_STATE_NONE;
  2385. srv_was_started = false;
  2386. srv_start_has_been_called = false;
  2387. }
  2388. /** Get the meta-data filename from the table name for a
  2389. single-table tablespace.
  2390. @param[in] table table object
  2391. @param[out] filename filename
  2392. @param[in] max_len filename max length */
  2393. void
  2394. srv_get_meta_data_filename(
  2395. dict_table_t* table,
  2396. char* filename,
  2397. ulint max_len)
  2398. {
  2399. ulint len;
  2400. char* path;
  2401. /* Make sure the data_dir_path is set. */
  2402. dict_get_and_save_data_dir_path(table, false);
  2403. if (DICT_TF_HAS_DATA_DIR(table->flags)) {
  2404. ut_a(table->data_dir_path);
  2405. path = fil_make_filepath(
  2406. table->data_dir_path, table->name.m_name, CFG, true);
  2407. } else {
  2408. path = fil_make_filepath(NULL, table->name.m_name, CFG, false);
  2409. }
  2410. ut_a(path);
  2411. len = ut_strlen(path);
  2412. ut_a(max_len >= len);
  2413. strcpy(filename, path);
  2414. ut_free(path);
  2415. }