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.

2465 lines
66 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.
9 years ago
MDEV-13039 innodb_fast_shutdown=0 may fail to purge all undo log When a slow shutdown is performed soon after spawning some work for background threads that can create or commit transactions, it is possible that new transactions are started or committed after the purge has finished. This is violating the specification of innodb_fast_shutdown=0, namely that the purge must be completed. (None of the history of the recent transactions would be purged.) Also, it is possible that the purge threads would exit in slow shutdown while there exist active transactions, such as recovered incomplete transactions that are being rolled back. Thus, the slow shutdown could fail to purge some undo log that becomes purgeable after the transaction commit or rollback. srv_undo_sources: A flag that indicates if undo log can be generated or the persistent, whether by background threads or by user SQL. Even when this flag is clear, active transactions that already exist in the system may be committed or rolled back. innodb_shutdown(): Renamed from innobase_shutdown_for_mysql(). Do not return an error code; the operation never fails. Clear the srv_undo_sources flag, and also ensure that the background DROP TABLE queue is empty. srv_purge_should_exit(): Do not allow the purge to exit if srv_undo_sources are active or the background DROP TABLE queue is not empty, or in slow shutdown, if any active transactions exist (and are being rolled back). srv_purge_coordinator_thread(): Remove some previous workarounds for this bug. innobase_start_or_create_for_mysql(): Set buf_page_cleaner_is_active and srv_dict_stats_thread_active directly. Set srv_undo_sources before starting the purge subsystem, to prevent immediate shutdown of the purge. Create dict_stats_thread and fts_optimize_thread immediately after setting srv_undo_sources, so that shutdown can use this flag to determine if these subsystems were started. dict_stats_shutdown(): Shut down dict_stats_thread. Backported from 10.2. srv_shutdown_table_bg_threads(): Remove (unused).
9 years ago
MDEV-11556 InnoDB redo log apply fails to adjust data file sizes fil_space_t::recv_size: New member: recovered tablespace size in pages; 0 if no size change was read from the redo log, or if the size change was implemented. fil_space_set_recv_size(): New function for setting space->recv_size. innodb_data_file_size_debug: A debug parameter for setting the system tablespace size in recovery even when the redo log does not contain any size changes. It is hard to write a small test case that would cause the system tablespace to be extended at the critical moment. recv_parse_log_rec(): Note those tablespaces whose size is being changed by the redo log, by invoking fil_space_set_recv_size(). innobase_init(): Correct an error message, and do not require a larger innodb_buffer_pool_size when starting up with a smaller innodb_page_size. innobase_start_or_create_for_mysql(): Allow startup with any initial size of the ibdata1 file if the autoextend attribute is set. Require the minimum size of fixed-size system tablespaces to be 640 pages, not 10 megabytes. Implement innodb_data_file_size_debug. open_or_create_data_files(): Round the system tablespace size down to pages, not to full megabytes, (Our test truncates the system tablespace to more than 800 pages with innodb_page_size=4k. InnoDB should not imagine that it was truncated to 768 pages and then overwrite good pages in the tablespace.) fil_flush_low(): Refactored from fil_flush(). fil_space_extend_must_retry(): Refactored from fil_extend_space_to_desired_size(). fil_mutex_enter_and_prepare_for_io(): Extend the tablespace if fil_space_set_recv_size() was called. The test case has been successfully run with all the innodb_page_size values 4k, 8k, 16k, 32k, 64k.
9 years ago
MDEV-11556 InnoDB redo log apply fails to adjust data file sizes fil_space_t::recv_size: New member: recovered tablespace size in pages; 0 if no size change was read from the redo log, or if the size change was implemented. fil_space_set_recv_size(): New function for setting space->recv_size. innodb_data_file_size_debug: A debug parameter for setting the system tablespace size in recovery even when the redo log does not contain any size changes. It is hard to write a small test case that would cause the system tablespace to be extended at the critical moment. recv_parse_log_rec(): Note those tablespaces whose size is being changed by the redo log, by invoking fil_space_set_recv_size(). innobase_init(): Correct an error message, and do not require a larger innodb_buffer_pool_size when starting up with a smaller innodb_page_size. innobase_start_or_create_for_mysql(): Allow startup with any initial size of the ibdata1 file if the autoextend attribute is set. Require the minimum size of fixed-size system tablespaces to be 640 pages, not 10 megabytes. Implement innodb_data_file_size_debug. open_or_create_data_files(): Round the system tablespace size down to pages, not to full megabytes, (Our test truncates the system tablespace to more than 800 pages with innodb_page_size=4k. InnoDB should not imagine that it was truncated to 768 pages and then overwrite good pages in the tablespace.) fil_flush_low(): Refactored from fil_flush(). fil_space_extend_must_retry(): Refactored from fil_extend_space_to_desired_size(). fil_mutex_enter_and_prepare_for_io(): Extend the tablespace if fil_space_set_recv_size() was called. The test case has been successfully run with all the innodb_page_size values 4k, 8k, 16k, 32k, 64k.
9 years ago
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2 InnoDB I/O and buffer pool interfaces and the redo log format have been changed between MariaDB 10.1 and 10.2, and the backup code has to be adjusted accordingly. The code has been simplified, and many memory leaks have been fixed. Instead of the file name xtrabackup_logfile, the file name ib_logfile0 is being used for the copy of the redo log. Unnecessary InnoDB startup and shutdown and some unnecessary threads have been removed. Some help was provided by Vladislav Vaintroub. Parameters have been cleaned up and aligned with those of MariaDB 10.2. The --dbug option has been added, so that in debug builds, --dbug=d,ib_log can be specified to enable diagnostic messages for processing redo log entries. By default, innodb_doublewrite=OFF, so that --prepare works faster. If more crash-safety for --prepare is needed, double buffering can be enabled. The parameter innodb_log_checksums=OFF can be used to ignore redo log checksums in --backup. Some messages have been cleaned up. Unless --export is specified, Mariabackup will not deal with undo log. The InnoDB mini-transaction redo log is not only about user-level transactions; it is actually about mini-transactions. To avoid confusion, call it the redo log, not transaction log. We disable any undo log processing in --prepare. Because MariaDB 10.2 supports indexed virtual columns, the undo log processing would need to be able to evaluate virtual column expressions. To reduce the amount of code dependencies, we will not process any undo log in prepare. This means that the --export option must be disabled for now. This also means that the following options are redundant and have been removed: xtrabackup --apply-log-only innobackupex --redo-only In addition to disabling any undo log processing, we will disable any further changes to data pages during --prepare, including the change buffer merge. This means that restoring incremental backups should reliably work even when change buffering is being used on the server. Because of this, preparing a backup will not generate any further redo log, and the redo log file can be safely deleted. (If the --export option is enabled in the future, it must generate redo log when processing undo logs and buffered changes.) In --prepare, we cannot easily know if a partial backup was used, especially when restoring a series of incremental backups. So, we simply warn about any missing files, and ignore the redo log for them. FIXME: Enable the --export option. FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write a test that initiates a backup while an ALGORITHM=INPLACE operation is creating indexes or rebuilding a table. An error should be detected when preparing the backup. FIXME: In --incremental --prepare, xtrabackup_apply_delta() should ensure that if FSP_SIZE is modified, the file size will be adjusted accordingly.
9 years ago
11 years ago
10 years ago
9 years ago
Reduce the granularity of innodb_log_file_size In Mariabackup, we would want the backed-up redo log file size to be a multiple of 512 bytes, or OS_FILE_LOG_BLOCK_SIZE. However, at startup, InnoDB would be picky, requiring the file size to be a multiple of innodb_page_size. Furthermore, InnoDB would require the parameter to be a multiple of one megabyte, while the minimum granularity is 512 bytes. Because the data-file-oriented fil_io() API is being used for writing the InnoDB redo log, writes will for now require innodb_log_file_size to be a multiple of the maximum innodb_page_size (65536 bytes). To complicate matters, InnoDB startup divided srv_log_file_size by UNIV_PAGE_SIZE, so that initially, the unit was bytes, and later it was innodb_page_size. We will simplify this and keep srv_log_file_size in bytes at all times. innobase_log_file_size: Remove. Remove some obsolete checks against overflow on 32-bit systems. srv_log_file_size is always 64 bits, and the maximum size 512GiB in multiples of innodb_page_size always fits in ulint (which is 32 or 64 bits). 512GiB would be 8,388,608*64KiB or 134,217,728*4KiB. log_init(): Remove the parameter file_size that was always passed as srv_log_file_size. log_set_capacity(): Add a parameter for passing the requested file size. srv_log_file_size_requested: Declare static in srv0start.cc. create_log_file(), create_log_files(), innobase_start_or_create_for_mysql(): Invoke fil_node_create() with srv_log_file_size expressed in multiples of innodb_page_size. innobase_start_or_create_for_mysql(): Require the redo log file sizes to be multiples of 512 bytes.
9 years ago
Reduce the granularity of innodb_log_file_size In Mariabackup, we would want the backed-up redo log file size to be a multiple of 512 bytes, or OS_FILE_LOG_BLOCK_SIZE. However, at startup, InnoDB would be picky, requiring the file size to be a multiple of innodb_page_size. Furthermore, InnoDB would require the parameter to be a multiple of one megabyte, while the minimum granularity is 512 bytes. Because the data-file-oriented fil_io() API is being used for writing the InnoDB redo log, writes will for now require innodb_log_file_size to be a multiple of the maximum innodb_page_size (65536 bytes). To complicate matters, InnoDB startup divided srv_log_file_size by UNIV_PAGE_SIZE, so that initially, the unit was bytes, and later it was innodb_page_size. We will simplify this and keep srv_log_file_size in bytes at all times. innobase_log_file_size: Remove. Remove some obsolete checks against overflow on 32-bit systems. srv_log_file_size is always 64 bits, and the maximum size 512GiB in multiples of innodb_page_size always fits in ulint (which is 32 or 64 bits). 512GiB would be 8,388,608*64KiB or 134,217,728*4KiB. log_init(): Remove the parameter file_size that was always passed as srv_log_file_size. log_set_capacity(): Add a parameter for passing the requested file size. srv_log_file_size_requested: Declare static in srv0start.cc. create_log_file(), create_log_files(), innobase_start_or_create_for_mysql(): Invoke fil_node_create() with srv_log_file_size expressed in multiples of innodb_page_size. innobase_start_or_create_for_mysql(): Require the redo log file sizes to be multiples of 512 bytes.
9 years ago
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2 InnoDB I/O and buffer pool interfaces and the redo log format have been changed between MariaDB 10.1 and 10.2, and the backup code has to be adjusted accordingly. The code has been simplified, and many memory leaks have been fixed. Instead of the file name xtrabackup_logfile, the file name ib_logfile0 is being used for the copy of the redo log. Unnecessary InnoDB startup and shutdown and some unnecessary threads have been removed. Some help was provided by Vladislav Vaintroub. Parameters have been cleaned up and aligned with those of MariaDB 10.2. The --dbug option has been added, so that in debug builds, --dbug=d,ib_log can be specified to enable diagnostic messages for processing redo log entries. By default, innodb_doublewrite=OFF, so that --prepare works faster. If more crash-safety for --prepare is needed, double buffering can be enabled. The parameter innodb_log_checksums=OFF can be used to ignore redo log checksums in --backup. Some messages have been cleaned up. Unless --export is specified, Mariabackup will not deal with undo log. The InnoDB mini-transaction redo log is not only about user-level transactions; it is actually about mini-transactions. To avoid confusion, call it the redo log, not transaction log. We disable any undo log processing in --prepare. Because MariaDB 10.2 supports indexed virtual columns, the undo log processing would need to be able to evaluate virtual column expressions. To reduce the amount of code dependencies, we will not process any undo log in prepare. This means that the --export option must be disabled for now. This also means that the following options are redundant and have been removed: xtrabackup --apply-log-only innobackupex --redo-only In addition to disabling any undo log processing, we will disable any further changes to data pages during --prepare, including the change buffer merge. This means that restoring incremental backups should reliably work even when change buffering is being used on the server. Because of this, preparing a backup will not generate any further redo log, and the redo log file can be safely deleted. (If the --export option is enabled in the future, it must generate redo log when processing undo logs and buffered changes.) In --prepare, we cannot easily know if a partial backup was used, especially when restoring a series of incremental backups. So, we simply warn about any missing files, and ignore the redo log for them. FIXME: Enable the --export option. FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write a test that initiates a backup while an ALGORITHM=INPLACE operation is creating indexes or rebuilding a table. An error should be detected when preparing the backup. FIXME: In --incremental --prepare, xtrabackup_apply_delta() should ensure that if FSP_SIZE is modified, the file size will be adjusted accordingly.
9 years ago
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2 InnoDB I/O and buffer pool interfaces and the redo log format have been changed between MariaDB 10.1 and 10.2, and the backup code has to be adjusted accordingly. The code has been simplified, and many memory leaks have been fixed. Instead of the file name xtrabackup_logfile, the file name ib_logfile0 is being used for the copy of the redo log. Unnecessary InnoDB startup and shutdown and some unnecessary threads have been removed. Some help was provided by Vladislav Vaintroub. Parameters have been cleaned up and aligned with those of MariaDB 10.2. The --dbug option has been added, so that in debug builds, --dbug=d,ib_log can be specified to enable diagnostic messages for processing redo log entries. By default, innodb_doublewrite=OFF, so that --prepare works faster. If more crash-safety for --prepare is needed, double buffering can be enabled. The parameter innodb_log_checksums=OFF can be used to ignore redo log checksums in --backup. Some messages have been cleaned up. Unless --export is specified, Mariabackup will not deal with undo log. The InnoDB mini-transaction redo log is not only about user-level transactions; it is actually about mini-transactions. To avoid confusion, call it the redo log, not transaction log. We disable any undo log processing in --prepare. Because MariaDB 10.2 supports indexed virtual columns, the undo log processing would need to be able to evaluate virtual column expressions. To reduce the amount of code dependencies, we will not process any undo log in prepare. This means that the --export option must be disabled for now. This also means that the following options are redundant and have been removed: xtrabackup --apply-log-only innobackupex --redo-only In addition to disabling any undo log processing, we will disable any further changes to data pages during --prepare, including the change buffer merge. This means that restoring incremental backups should reliably work even when change buffering is being used on the server. Because of this, preparing a backup will not generate any further redo log, and the redo log file can be safely deleted. (If the --export option is enabled in the future, it must generate redo log when processing undo logs and buffered changes.) In --prepare, we cannot easily know if a partial backup was used, especially when restoring a series of incremental backups. So, we simply warn about any missing files, and ignore the redo log for them. FIXME: Enable the --export option. FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write a test that initiates a backup while an ALGORITHM=INPLACE operation is creating indexes or rebuilding a table. An error should be detected when preparing the backup. FIXME: In --incremental --prepare, xtrabackup_apply_delta() should ensure that if FSP_SIZE is modified, the file size will be adjusted accordingly.
9 years ago
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2 InnoDB I/O and buffer pool interfaces and the redo log format have been changed between MariaDB 10.1 and 10.2, and the backup code has to be adjusted accordingly. The code has been simplified, and many memory leaks have been fixed. Instead of the file name xtrabackup_logfile, the file name ib_logfile0 is being used for the copy of the redo log. Unnecessary InnoDB startup and shutdown and some unnecessary threads have been removed. Some help was provided by Vladislav Vaintroub. Parameters have been cleaned up and aligned with those of MariaDB 10.2. The --dbug option has been added, so that in debug builds, --dbug=d,ib_log can be specified to enable diagnostic messages for processing redo log entries. By default, innodb_doublewrite=OFF, so that --prepare works faster. If more crash-safety for --prepare is needed, double buffering can be enabled. The parameter innodb_log_checksums=OFF can be used to ignore redo log checksums in --backup. Some messages have been cleaned up. Unless --export is specified, Mariabackup will not deal with undo log. The InnoDB mini-transaction redo log is not only about user-level transactions; it is actually about mini-transactions. To avoid confusion, call it the redo log, not transaction log. We disable any undo log processing in --prepare. Because MariaDB 10.2 supports indexed virtual columns, the undo log processing would need to be able to evaluate virtual column expressions. To reduce the amount of code dependencies, we will not process any undo log in prepare. This means that the --export option must be disabled for now. This also means that the following options are redundant and have been removed: xtrabackup --apply-log-only innobackupex --redo-only In addition to disabling any undo log processing, we will disable any further changes to data pages during --prepare, including the change buffer merge. This means that restoring incremental backups should reliably work even when change buffering is being used on the server. Because of this, preparing a backup will not generate any further redo log, and the redo log file can be safely deleted. (If the --export option is enabled in the future, it must generate redo log when processing undo logs and buffered changes.) In --prepare, we cannot easily know if a partial backup was used, especially when restoring a series of incremental backups. So, we simply warn about any missing files, and ignore the redo log for them. FIXME: Enable the --export option. FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write a test that initiates a backup while an ALGORITHM=INPLACE operation is creating indexes or rebuilding a table. An error should be detected when preparing the backup. FIXME: In --incremental --prepare, xtrabackup_apply_delta() should ensure that if FSP_SIZE is modified, the file size will be adjusted accordingly.
9 years ago
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2 InnoDB I/O and buffer pool interfaces and the redo log format have been changed between MariaDB 10.1 and 10.2, and the backup code has to be adjusted accordingly. The code has been simplified, and many memory leaks have been fixed. Instead of the file name xtrabackup_logfile, the file name ib_logfile0 is being used for the copy of the redo log. Unnecessary InnoDB startup and shutdown and some unnecessary threads have been removed. Some help was provided by Vladislav Vaintroub. Parameters have been cleaned up and aligned with those of MariaDB 10.2. The --dbug option has been added, so that in debug builds, --dbug=d,ib_log can be specified to enable diagnostic messages for processing redo log entries. By default, innodb_doublewrite=OFF, so that --prepare works faster. If more crash-safety for --prepare is needed, double buffering can be enabled. The parameter innodb_log_checksums=OFF can be used to ignore redo log checksums in --backup. Some messages have been cleaned up. Unless --export is specified, Mariabackup will not deal with undo log. The InnoDB mini-transaction redo log is not only about user-level transactions; it is actually about mini-transactions. To avoid confusion, call it the redo log, not transaction log. We disable any undo log processing in --prepare. Because MariaDB 10.2 supports indexed virtual columns, the undo log processing would need to be able to evaluate virtual column expressions. To reduce the amount of code dependencies, we will not process any undo log in prepare. This means that the --export option must be disabled for now. This also means that the following options are redundant and have been removed: xtrabackup --apply-log-only innobackupex --redo-only In addition to disabling any undo log processing, we will disable any further changes to data pages during --prepare, including the change buffer merge. This means that restoring incremental backups should reliably work even when change buffering is being used on the server. Because of this, preparing a backup will not generate any further redo log, and the redo log file can be safely deleted. (If the --export option is enabled in the future, it must generate redo log when processing undo logs and buffered changes.) In --prepare, we cannot easily know if a partial backup was used, especially when restoring a series of incremental backups. So, we simply warn about any missing files, and ignore the redo log for them. FIXME: Enable the --export option. FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write a test that initiates a backup while an ALGORITHM=INPLACE operation is creating indexes or rebuilding a table. An error should be detected when preparing the backup. FIXME: In --incremental --prepare, xtrabackup_apply_delta() should ensure that if FSP_SIZE is modified, the file size will be adjusted accordingly.
9 years ago
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2 InnoDB I/O and buffer pool interfaces and the redo log format have been changed between MariaDB 10.1 and 10.2, and the backup code has to be adjusted accordingly. The code has been simplified, and many memory leaks have been fixed. Instead of the file name xtrabackup_logfile, the file name ib_logfile0 is being used for the copy of the redo log. Unnecessary InnoDB startup and shutdown and some unnecessary threads have been removed. Some help was provided by Vladislav Vaintroub. Parameters have been cleaned up and aligned with those of MariaDB 10.2. The --dbug option has been added, so that in debug builds, --dbug=d,ib_log can be specified to enable diagnostic messages for processing redo log entries. By default, innodb_doublewrite=OFF, so that --prepare works faster. If more crash-safety for --prepare is needed, double buffering can be enabled. The parameter innodb_log_checksums=OFF can be used to ignore redo log checksums in --backup. Some messages have been cleaned up. Unless --export is specified, Mariabackup will not deal with undo log. The InnoDB mini-transaction redo log is not only about user-level transactions; it is actually about mini-transactions. To avoid confusion, call it the redo log, not transaction log. We disable any undo log processing in --prepare. Because MariaDB 10.2 supports indexed virtual columns, the undo log processing would need to be able to evaluate virtual column expressions. To reduce the amount of code dependencies, we will not process any undo log in prepare. This means that the --export option must be disabled for now. This also means that the following options are redundant and have been removed: xtrabackup --apply-log-only innobackupex --redo-only In addition to disabling any undo log processing, we will disable any further changes to data pages during --prepare, including the change buffer merge. This means that restoring incremental backups should reliably work even when change buffering is being used on the server. Because of this, preparing a backup will not generate any further redo log, and the redo log file can be safely deleted. (If the --export option is enabled in the future, it must generate redo log when processing undo logs and buffered changes.) In --prepare, we cannot easily know if a partial backup was used, especially when restoring a series of incremental backups. So, we simply warn about any missing files, and ignore the redo log for them. FIXME: Enable the --export option. FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write a test that initiates a backup while an ALGORITHM=INPLACE operation is creating indexes or rebuilding a table. An error should be detected when preparing the backup. FIXME: In --incremental --prepare, xtrabackup_apply_delta() should ensure that if FSP_SIZE is modified, the file size will be adjusted accordingly.
9 years ago
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2 InnoDB I/O and buffer pool interfaces and the redo log format have been changed between MariaDB 10.1 and 10.2, and the backup code has to be adjusted accordingly. The code has been simplified, and many memory leaks have been fixed. Instead of the file name xtrabackup_logfile, the file name ib_logfile0 is being used for the copy of the redo log. Unnecessary InnoDB startup and shutdown and some unnecessary threads have been removed. Some help was provided by Vladislav Vaintroub. Parameters have been cleaned up and aligned with those of MariaDB 10.2. The --dbug option has been added, so that in debug builds, --dbug=d,ib_log can be specified to enable diagnostic messages for processing redo log entries. By default, innodb_doublewrite=OFF, so that --prepare works faster. If more crash-safety for --prepare is needed, double buffering can be enabled. The parameter innodb_log_checksums=OFF can be used to ignore redo log checksums in --backup. Some messages have been cleaned up. Unless --export is specified, Mariabackup will not deal with undo log. The InnoDB mini-transaction redo log is not only about user-level transactions; it is actually about mini-transactions. To avoid confusion, call it the redo log, not transaction log. We disable any undo log processing in --prepare. Because MariaDB 10.2 supports indexed virtual columns, the undo log processing would need to be able to evaluate virtual column expressions. To reduce the amount of code dependencies, we will not process any undo log in prepare. This means that the --export option must be disabled for now. This also means that the following options are redundant and have been removed: xtrabackup --apply-log-only innobackupex --redo-only In addition to disabling any undo log processing, we will disable any further changes to data pages during --prepare, including the change buffer merge. This means that restoring incremental backups should reliably work even when change buffering is being used on the server. Because of this, preparing a backup will not generate any further redo log, and the redo log file can be safely deleted. (If the --export option is enabled in the future, it must generate redo log when processing undo logs and buffered changes.) In --prepare, we cannot easily know if a partial backup was used, especially when restoring a series of incremental backups. So, we simply warn about any missing files, and ignore the redo log for them. FIXME: Enable the --export option. FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write a test that initiates a backup while an ALGORITHM=INPLACE operation is creating indexes or rebuilding a table. An error should be detected when preparing the backup. FIXME: In --incremental --prepare, xtrabackup_apply_delta() should ensure that if FSP_SIZE is modified, the file size will be adjusted accordingly.
9 years ago
MDEV-11738: Mariadb uses 100% of several of my 8 cpus doing nothing MDEV-11581: Mariadb starts InnoDB encryption threads when key has not changed or data scrubbing turned off Background: Key rotation is based on background threads (innodb-encryption-threads) periodically going through all tablespaces on fil_system. For each tablespace current used key version is compared to max key age (innodb-encryption-rotate-key-age). This process naturally takes CPU. Similarly, in same time need for scrubbing is investigated. Currently, key rotation is fully supported on Amazon AWS key management plugin only but InnoDB does not have knowledge what key management plugin is used. This patch re-purposes innodb-encryption-rotate-key-age=0 to disable key rotation and background data scrubbing. All new tables are added to special list for key rotation and key rotation is based on sending a event to background encryption threads instead of using periodic checking (i.e. timeout). fil0fil.cc: Added functions fil_space_acquire_low() to acquire a tablespace when it could be dropped concurrently. This function is used from fil_space_acquire() or fil_space_acquire_silent() that will not print any messages if we try to acquire space that does not exist. fil_space_release() to release a acquired tablespace. fil_space_next() to iterate tablespaces in fil_system using fil_space_acquire() and fil_space_release(). Similarly, fil_space_keyrotation_next() to iterate new list fil_system->rotation_list where new tables. are added if key rotation is disabled. Removed unnecessary functions fil_get_first_space_safe() fil_get_next_space_safe() fil_node_open_file(): After page 0 is read read also crypt_info if it is not yet read. btr_scrub_lock_dict_func() buf_page_check_corrupt() buf_page_encrypt_before_write() buf_merge_or_delete_for_page() lock_print_info_all_transactions() row_fts_psort_info_init() row_truncate_table_for_mysql() row_drop_table_for_mysql() Use fil_space_acquire()/release() to access fil_space_t. buf_page_decrypt_after_read(): Use fil_space_get_crypt_data() because at this point we might not yet have read page 0. fil0crypt.cc/fil0fil.h: Lot of changes. Pass fil_space_t* directly to functions needing it and store fil_space_t* to rotation state. Use fil_space_acquire()/release() when iterating tablespaces and removed unnecessary is_closing from fil_crypt_t. Use fil_space_t::is_stopping() to detect when access to tablespace should be stopped. Removed unnecessary fil_space_get_crypt_data(). fil_space_create(): Inform key rotation that there could be something to do if key rotation is disabled and new table with encryption enabled is created. Remove unnecessary functions fil_get_first_space_safe() and fil_get_next_space_safe(). fil_space_acquire() and fil_space_release() are used instead. Moved fil_space_get_crypt_data() and fil_space_set_crypt_data() to fil0crypt.cc. fsp_header_init(): Acquire fil_space_t*, write crypt_data and release space. check_table_options() Renamed FIL_SPACE_ENCRYPTION_* TO FIL_ENCRYPTION_* i_s.cc: Added ROTATING_OR_FLUSHING field to information_schema.innodb_tablespace_encryption to show current status of key rotation.
9 years ago
Reduce the granularity of innodb_log_file_size In Mariabackup, we would want the backed-up redo log file size to be a multiple of 512 bytes, or OS_FILE_LOG_BLOCK_SIZE. However, at startup, InnoDB would be picky, requiring the file size to be a multiple of innodb_page_size. Furthermore, InnoDB would require the parameter to be a multiple of one megabyte, while the minimum granularity is 512 bytes. Because the data-file-oriented fil_io() API is being used for writing the InnoDB redo log, writes will for now require innodb_log_file_size to be a multiple of the maximum innodb_page_size (65536 bytes). To complicate matters, InnoDB startup divided srv_log_file_size by UNIV_PAGE_SIZE, so that initially, the unit was bytes, and later it was innodb_page_size. We will simplify this and keep srv_log_file_size in bytes at all times. innobase_log_file_size: Remove. Remove some obsolete checks against overflow on 32-bit systems. srv_log_file_size is always 64 bits, and the maximum size 512GiB in multiples of innodb_page_size always fits in ulint (which is 32 or 64 bits). 512GiB would be 8,388,608*64KiB or 134,217,728*4KiB. log_init(): Remove the parameter file_size that was always passed as srv_log_file_size. log_set_capacity(): Add a parameter for passing the requested file size. srv_log_file_size_requested: Declare static in srv0start.cc. create_log_file(), create_log_files(), innobase_start_or_create_for_mysql(): Invoke fil_node_create() with srv_log_file_size expressed in multiples of innodb_page_size. innobase_start_or_create_for_mysql(): Require the redo log file sizes to be multiples of 512 bytes.
9 years ago
Reduce the granularity of innodb_log_file_size In Mariabackup, we would want the backed-up redo log file size to be a multiple of 512 bytes, or OS_FILE_LOG_BLOCK_SIZE. However, at startup, InnoDB would be picky, requiring the file size to be a multiple of innodb_page_size. Furthermore, InnoDB would require the parameter to be a multiple of one megabyte, while the minimum granularity is 512 bytes. Because the data-file-oriented fil_io() API is being used for writing the InnoDB redo log, writes will for now require innodb_log_file_size to be a multiple of the maximum innodb_page_size (65536 bytes). To complicate matters, InnoDB startup divided srv_log_file_size by UNIV_PAGE_SIZE, so that initially, the unit was bytes, and later it was innodb_page_size. We will simplify this and keep srv_log_file_size in bytes at all times. innobase_log_file_size: Remove. Remove some obsolete checks against overflow on 32-bit systems. srv_log_file_size is always 64 bits, and the maximum size 512GiB in multiples of innodb_page_size always fits in ulint (which is 32 or 64 bits). 512GiB would be 8,388,608*64KiB or 134,217,728*4KiB. log_init(): Remove the parameter file_size that was always passed as srv_log_file_size. log_set_capacity(): Add a parameter for passing the requested file size. srv_log_file_size_requested: Declare static in srv0start.cc. create_log_file(), create_log_files(), innobase_start_or_create_for_mysql(): Invoke fil_node_create() with srv_log_file_size expressed in multiples of innodb_page_size. innobase_start_or_create_for_mysql(): Require the redo log file sizes to be multiples of 512 bytes.
9 years ago
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
MDEV-12026: Implement innodb_checksum_algorithm=full_crc32 MariaDB data-at-rest encryption (innodb_encrypt_tables) had repurposed the same unused data field that was repurposed in MySQL 5.7 (and MariaDB 10.2) for the Split Sequence Number (SSN) field of SPATIAL INDEX. Because of this, MariaDB was unable to support encryption on SPATIAL INDEX pages. Furthermore, InnoDB page checksums skipped some bytes, and there are multiple variations and checksum algorithms. By default, InnoDB accepts all variations of all algorithms that ever existed. This unnecessarily weakens the page checksums. We hereby introduce two more innodb_checksum_algorithm variants (full_crc32, strict_full_crc32) that are special in a way: When either setting is active, newly created data files will carry a flag (fil_space_t::full_crc32()) that indicates that all pages of the file will use a full CRC-32C checksum over the entire page contents (excluding the bytes where the checksum is stored, at the very end of the page). Such files will always use that checksum, no matter what the parameter innodb_checksum_algorithm is assigned to. For old files, the old checksum algorithms will continue to be used. The value strict_full_crc32 will be equivalent to strict_crc32 and the value full_crc32 will be equivalent to crc32. ROW_FORMAT=COMPRESSED tables will only use the old format. These tables do not support new features, such as larger innodb_page_size or instant ADD/DROP COLUMN. They may be deprecated in the future. We do not want an unnecessary file format change for them. The new full_crc32() format also cleans up the MariaDB tablespace flags. We will reserve flags to store the page_compressed compression algorithm, and to store the compressed payload length, so that checksum can be computed over the compressed (and possibly encrypted) stream and can be validated without decrypting or decompressing the page. In the full_crc32 format, there no longer are separate before-encryption and after-encryption checksums for pages. The single checksum is computed on the page contents that is written to the file. We do not make the new algorithm the default for two reasons. First, MariaDB 10.4.2 was a beta release, and the default values of parameters should not change after beta. Second, we did not yet implement the full_crc32 format for page_compressed pages. This will be fixed in MDEV-18644. This is joint work with Marko Mäkelä.
7 years ago
11 years ago
11 years ago
MDEV-12289 Keep 128 persistent rollback segments for compatibility and performance InnoDB divides the allocation of undo logs into rollback segments. The DB_ROLL_PTR system column of clustered indexes can address up to 128 rollback segments (TRX_SYS_N_RSEGS). Originally, InnoDB only created one rollback segment. In MySQL 5.5 or in the InnoDB Plugin for MySQL 5.1, all 128 rollback segments were created. MySQL 5.7 hard-codes the rollback segment IDs 1..32 for temporary undo logs. On upgrade, unless a slow shutdown (innodb_fast_shutdown=0) was performed on the old server instance, these rollback segments could be in use by transactions that are in XA PREPARE state or transactions that were left behind by a server kill followed by a normal shutdown immediately after restart. Persistent tables cannot refer to temporary undo logs or vice versa. Therefore, we should keep two distinct sets of rollback segments: one for persistent tables and another for temporary tables. In this way, all 128 rollback segments will be available for both types of tables, which could improve performance. Also, MariaDB 10.2 will remain more compatible than MySQL 5.7 with data files from earlier versions of MySQL or MariaDB. trx_sys_t::temp_rsegs[TRX_SYS_N_RSEGS]: A new array of temporary rollback segments. The trx_sys_t::rseg_array[TRX_SYS_N_RSEGS] will be solely for persistent undo logs. srv_tmp_undo_logs. Remove. Use the constant TRX_SYS_N_RSEGS. srv_available_undo_logs: Change the type to ulong. trx_rseg_get_on_id(): Remove. Instead, let the callers refer to trx_sys directly. trx_rseg_create(), trx_sysf_rseg_find_free(): Remove unneeded parameters. These functions only deal with persistent undo logs. trx_temp_rseg_create(): New function, to create all temporary rollback segments at server startup. trx_rseg_t::is_persistent(): Determine if the rollback segment is for persistent tables. trx_sys_is_noredo_rseg_slot(): Remove. The callers must know based on context (such as table handle) whether the DB_ROLL_PTR is referring to a persistent undo log. trx_sys_create_rsegs(): Remove all parameters, which were always passed as global variables. Instead, modify the global variables directly. enum trx_rseg_type_t: Remove. trx_t::get_temp_rseg(): A method to ensure that a temporary rollback segment has been assigned for the transaction. trx_t::assign_temp_rseg(): Replaces trx_assign_rseg(). trx_purge_free_segment(), trx_purge_truncate_rseg_history(): Remove the redundant variable noredo=false. Temporary undo logs are discarded immediately at transaction commit or rollback, not lazily by purge. trx_purge_mark_undo_for_truncate(): Remove references to the temporary rollback segments. trx_purge_mark_undo_for_truncate(): Remove a check for temporary rollback segments. Only the dedicated persistent undo log tablespaces can be truncated. trx_undo_get_undo_rec_low(), trx_undo_get_undo_rec(): Add the parameter is_temp. trx_rseg_mem_restore(): Split from trx_rseg_mem_create(). Initialize the undo log and the rollback segment from the file data structures. trx_sysf_get_n_rseg_slots(): Renamed from trx_sysf_used_slots_for_redo_rseg(). Count the persistent rollback segment headers that have been initialized. trx_sys_close(): Also free trx_sys->temp_rsegs[]. get_next_redo_rseg(): Merged to trx_assign_rseg_low(). trx_assign_rseg_low(): Remove the parameters and access the global variables directly. Revert to simple round-robin, now that the whole trx_sys->rseg_array[] is for persistent undo log again. get_next_noredo_rseg(): Moved to trx_t::assign_temp_rseg(). srv_undo_tablespaces_init(): Remove some parameters and use the global variables directly. Clarify some error messages. Adjust the test innodb.log_file. Apparently, before these changes, InnoDB somehow ignored missing dedicated undo tablespace files that are pointed by the TRX_SYS header page, possibly losing part of essential transaction system state.
9 years ago
MDEV-12289 Keep 128 persistent rollback segments for compatibility and performance InnoDB divides the allocation of undo logs into rollback segments. The DB_ROLL_PTR system column of clustered indexes can address up to 128 rollback segments (TRX_SYS_N_RSEGS). Originally, InnoDB only created one rollback segment. In MySQL 5.5 or in the InnoDB Plugin for MySQL 5.1, all 128 rollback segments were created. MySQL 5.7 hard-codes the rollback segment IDs 1..32 for temporary undo logs. On upgrade, unless a slow shutdown (innodb_fast_shutdown=0) was performed on the old server instance, these rollback segments could be in use by transactions that are in XA PREPARE state or transactions that were left behind by a server kill followed by a normal shutdown immediately after restart. Persistent tables cannot refer to temporary undo logs or vice versa. Therefore, we should keep two distinct sets of rollback segments: one for persistent tables and another for temporary tables. In this way, all 128 rollback segments will be available for both types of tables, which could improve performance. Also, MariaDB 10.2 will remain more compatible than MySQL 5.7 with data files from earlier versions of MySQL or MariaDB. trx_sys_t::temp_rsegs[TRX_SYS_N_RSEGS]: A new array of temporary rollback segments. The trx_sys_t::rseg_array[TRX_SYS_N_RSEGS] will be solely for persistent undo logs. srv_tmp_undo_logs. Remove. Use the constant TRX_SYS_N_RSEGS. srv_available_undo_logs: Change the type to ulong. trx_rseg_get_on_id(): Remove. Instead, let the callers refer to trx_sys directly. trx_rseg_create(), trx_sysf_rseg_find_free(): Remove unneeded parameters. These functions only deal with persistent undo logs. trx_temp_rseg_create(): New function, to create all temporary rollback segments at server startup. trx_rseg_t::is_persistent(): Determine if the rollback segment is for persistent tables. trx_sys_is_noredo_rseg_slot(): Remove. The callers must know based on context (such as table handle) whether the DB_ROLL_PTR is referring to a persistent undo log. trx_sys_create_rsegs(): Remove all parameters, which were always passed as global variables. Instead, modify the global variables directly. enum trx_rseg_type_t: Remove. trx_t::get_temp_rseg(): A method to ensure that a temporary rollback segment has been assigned for the transaction. trx_t::assign_temp_rseg(): Replaces trx_assign_rseg(). trx_purge_free_segment(), trx_purge_truncate_rseg_history(): Remove the redundant variable noredo=false. Temporary undo logs are discarded immediately at transaction commit or rollback, not lazily by purge. trx_purge_mark_undo_for_truncate(): Remove references to the temporary rollback segments. trx_purge_mark_undo_for_truncate(): Remove a check for temporary rollback segments. Only the dedicated persistent undo log tablespaces can be truncated. trx_undo_get_undo_rec_low(), trx_undo_get_undo_rec(): Add the parameter is_temp. trx_rseg_mem_restore(): Split from trx_rseg_mem_create(). Initialize the undo log and the rollback segment from the file data structures. trx_sysf_get_n_rseg_slots(): Renamed from trx_sysf_used_slots_for_redo_rseg(). Count the persistent rollback segment headers that have been initialized. trx_sys_close(): Also free trx_sys->temp_rsegs[]. get_next_redo_rseg(): Merged to trx_assign_rseg_low(). trx_assign_rseg_low(): Remove the parameters and access the global variables directly. Revert to simple round-robin, now that the whole trx_sys->rseg_array[] is for persistent undo log again. get_next_noredo_rseg(): Moved to trx_t::assign_temp_rseg(). srv_undo_tablespaces_init(): Remove some parameters and use the global variables directly. Clarify some error messages. Adjust the test innodb.log_file. Apparently, before these changes, InnoDB somehow ignored missing dedicated undo tablespace files that are pointed by the TRX_SYS header page, possibly losing part of essential transaction system state.
9 years ago
MDEV-12289 Keep 128 persistent rollback segments for compatibility and performance InnoDB divides the allocation of undo logs into rollback segments. The DB_ROLL_PTR system column of clustered indexes can address up to 128 rollback segments (TRX_SYS_N_RSEGS). Originally, InnoDB only created one rollback segment. In MySQL 5.5 or in the InnoDB Plugin for MySQL 5.1, all 128 rollback segments were created. MySQL 5.7 hard-codes the rollback segment IDs 1..32 for temporary undo logs. On upgrade, unless a slow shutdown (innodb_fast_shutdown=0) was performed on the old server instance, these rollback segments could be in use by transactions that are in XA PREPARE state or transactions that were left behind by a server kill followed by a normal shutdown immediately after restart. Persistent tables cannot refer to temporary undo logs or vice versa. Therefore, we should keep two distinct sets of rollback segments: one for persistent tables and another for temporary tables. In this way, all 128 rollback segments will be available for both types of tables, which could improve performance. Also, MariaDB 10.2 will remain more compatible than MySQL 5.7 with data files from earlier versions of MySQL or MariaDB. trx_sys_t::temp_rsegs[TRX_SYS_N_RSEGS]: A new array of temporary rollback segments. The trx_sys_t::rseg_array[TRX_SYS_N_RSEGS] will be solely for persistent undo logs. srv_tmp_undo_logs. Remove. Use the constant TRX_SYS_N_RSEGS. srv_available_undo_logs: Change the type to ulong. trx_rseg_get_on_id(): Remove. Instead, let the callers refer to trx_sys directly. trx_rseg_create(), trx_sysf_rseg_find_free(): Remove unneeded parameters. These functions only deal with persistent undo logs. trx_temp_rseg_create(): New function, to create all temporary rollback segments at server startup. trx_rseg_t::is_persistent(): Determine if the rollback segment is for persistent tables. trx_sys_is_noredo_rseg_slot(): Remove. The callers must know based on context (such as table handle) whether the DB_ROLL_PTR is referring to a persistent undo log. trx_sys_create_rsegs(): Remove all parameters, which were always passed as global variables. Instead, modify the global variables directly. enum trx_rseg_type_t: Remove. trx_t::get_temp_rseg(): A method to ensure that a temporary rollback segment has been assigned for the transaction. trx_t::assign_temp_rseg(): Replaces trx_assign_rseg(). trx_purge_free_segment(), trx_purge_truncate_rseg_history(): Remove the redundant variable noredo=false. Temporary undo logs are discarded immediately at transaction commit or rollback, not lazily by purge. trx_purge_mark_undo_for_truncate(): Remove references to the temporary rollback segments. trx_purge_mark_undo_for_truncate(): Remove a check for temporary rollback segments. Only the dedicated persistent undo log tablespaces can be truncated. trx_undo_get_undo_rec_low(), trx_undo_get_undo_rec(): Add the parameter is_temp. trx_rseg_mem_restore(): Split from trx_rseg_mem_create(). Initialize the undo log and the rollback segment from the file data structures. trx_sysf_get_n_rseg_slots(): Renamed from trx_sysf_used_slots_for_redo_rseg(). Count the persistent rollback segment headers that have been initialized. trx_sys_close(): Also free trx_sys->temp_rsegs[]. get_next_redo_rseg(): Merged to trx_assign_rseg_low(). trx_assign_rseg_low(): Remove the parameters and access the global variables directly. Revert to simple round-robin, now that the whole trx_sys->rseg_array[] is for persistent undo log again. get_next_noredo_rseg(): Moved to trx_t::assign_temp_rseg(). srv_undo_tablespaces_init(): Remove some parameters and use the global variables directly. Clarify some error messages. Adjust the test innodb.log_file. Apparently, before these changes, InnoDB somehow ignored missing dedicated undo tablespace files that are pointed by the TRX_SYS header page, possibly losing part of essential transaction system state.
9 years ago
MDEV-12289 Keep 128 persistent rollback segments for compatibility and performance InnoDB divides the allocation of undo logs into rollback segments. The DB_ROLL_PTR system column of clustered indexes can address up to 128 rollback segments (TRX_SYS_N_RSEGS). Originally, InnoDB only created one rollback segment. In MySQL 5.5 or in the InnoDB Plugin for MySQL 5.1, all 128 rollback segments were created. MySQL 5.7 hard-codes the rollback segment IDs 1..32 for temporary undo logs. On upgrade, unless a slow shutdown (innodb_fast_shutdown=0) was performed on the old server instance, these rollback segments could be in use by transactions that are in XA PREPARE state or transactions that were left behind by a server kill followed by a normal shutdown immediately after restart. Persistent tables cannot refer to temporary undo logs or vice versa. Therefore, we should keep two distinct sets of rollback segments: one for persistent tables and another for temporary tables. In this way, all 128 rollback segments will be available for both types of tables, which could improve performance. Also, MariaDB 10.2 will remain more compatible than MySQL 5.7 with data files from earlier versions of MySQL or MariaDB. trx_sys_t::temp_rsegs[TRX_SYS_N_RSEGS]: A new array of temporary rollback segments. The trx_sys_t::rseg_array[TRX_SYS_N_RSEGS] will be solely for persistent undo logs. srv_tmp_undo_logs. Remove. Use the constant TRX_SYS_N_RSEGS. srv_available_undo_logs: Change the type to ulong. trx_rseg_get_on_id(): Remove. Instead, let the callers refer to trx_sys directly. trx_rseg_create(), trx_sysf_rseg_find_free(): Remove unneeded parameters. These functions only deal with persistent undo logs. trx_temp_rseg_create(): New function, to create all temporary rollback segments at server startup. trx_rseg_t::is_persistent(): Determine if the rollback segment is for persistent tables. trx_sys_is_noredo_rseg_slot(): Remove. The callers must know based on context (such as table handle) whether the DB_ROLL_PTR is referring to a persistent undo log. trx_sys_create_rsegs(): Remove all parameters, which were always passed as global variables. Instead, modify the global variables directly. enum trx_rseg_type_t: Remove. trx_t::get_temp_rseg(): A method to ensure that a temporary rollback segment has been assigned for the transaction. trx_t::assign_temp_rseg(): Replaces trx_assign_rseg(). trx_purge_free_segment(), trx_purge_truncate_rseg_history(): Remove the redundant variable noredo=false. Temporary undo logs are discarded immediately at transaction commit or rollback, not lazily by purge. trx_purge_mark_undo_for_truncate(): Remove references to the temporary rollback segments. trx_purge_mark_undo_for_truncate(): Remove a check for temporary rollback segments. Only the dedicated persistent undo log tablespaces can be truncated. trx_undo_get_undo_rec_low(), trx_undo_get_undo_rec(): Add the parameter is_temp. trx_rseg_mem_restore(): Split from trx_rseg_mem_create(). Initialize the undo log and the rollback segment from the file data structures. trx_sysf_get_n_rseg_slots(): Renamed from trx_sysf_used_slots_for_redo_rseg(). Count the persistent rollback segment headers that have been initialized. trx_sys_close(): Also free trx_sys->temp_rsegs[]. get_next_redo_rseg(): Merged to trx_assign_rseg_low(). trx_assign_rseg_low(): Remove the parameters and access the global variables directly. Revert to simple round-robin, now that the whole trx_sys->rseg_array[] is for persistent undo log again. get_next_noredo_rseg(): Moved to trx_t::assign_temp_rseg(). srv_undo_tablespaces_init(): Remove some parameters and use the global variables directly. Clarify some error messages. Adjust the test innodb.log_file. Apparently, before these changes, InnoDB somehow ignored missing dedicated undo tablespace files that are pointed by the TRX_SYS header page, possibly losing part of essential transaction system state.
9 years ago
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2 InnoDB I/O and buffer pool interfaces and the redo log format have been changed between MariaDB 10.1 and 10.2, and the backup code has to be adjusted accordingly. The code has been simplified, and many memory leaks have been fixed. Instead of the file name xtrabackup_logfile, the file name ib_logfile0 is being used for the copy of the redo log. Unnecessary InnoDB startup and shutdown and some unnecessary threads have been removed. Some help was provided by Vladislav Vaintroub. Parameters have been cleaned up and aligned with those of MariaDB 10.2. The --dbug option has been added, so that in debug builds, --dbug=d,ib_log can be specified to enable diagnostic messages for processing redo log entries. By default, innodb_doublewrite=OFF, so that --prepare works faster. If more crash-safety for --prepare is needed, double buffering can be enabled. The parameter innodb_log_checksums=OFF can be used to ignore redo log checksums in --backup. Some messages have been cleaned up. Unless --export is specified, Mariabackup will not deal with undo log. The InnoDB mini-transaction redo log is not only about user-level transactions; it is actually about mini-transactions. To avoid confusion, call it the redo log, not transaction log. We disable any undo log processing in --prepare. Because MariaDB 10.2 supports indexed virtual columns, the undo log processing would need to be able to evaluate virtual column expressions. To reduce the amount of code dependencies, we will not process any undo log in prepare. This means that the --export option must be disabled for now. This also means that the following options are redundant and have been removed: xtrabackup --apply-log-only innobackupex --redo-only In addition to disabling any undo log processing, we will disable any further changes to data pages during --prepare, including the change buffer merge. This means that restoring incremental backups should reliably work even when change buffering is being used on the server. Because of this, preparing a backup will not generate any further redo log, and the redo log file can be safely deleted. (If the --export option is enabled in the future, it must generate redo log when processing undo logs and buffered changes.) In --prepare, we cannot easily know if a partial backup was used, especially when restoring a series of incremental backups. So, we simply warn about any missing files, and ignore the redo log for them. FIXME: Enable the --export option. FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write a test that initiates a backup while an ALGORITHM=INPLACE operation is creating indexes or rebuilding a table. An error should be detected when preparing the backup. FIXME: In --incremental --prepare, xtrabackup_apply_delta() should ensure that if FSP_SIZE is modified, the file size will be adjusted accordingly.
9 years ago
MDEV-12289 Keep 128 persistent rollback segments for compatibility and performance InnoDB divides the allocation of undo logs into rollback segments. The DB_ROLL_PTR system column of clustered indexes can address up to 128 rollback segments (TRX_SYS_N_RSEGS). Originally, InnoDB only created one rollback segment. In MySQL 5.5 or in the InnoDB Plugin for MySQL 5.1, all 128 rollback segments were created. MySQL 5.7 hard-codes the rollback segment IDs 1..32 for temporary undo logs. On upgrade, unless a slow shutdown (innodb_fast_shutdown=0) was performed on the old server instance, these rollback segments could be in use by transactions that are in XA PREPARE state or transactions that were left behind by a server kill followed by a normal shutdown immediately after restart. Persistent tables cannot refer to temporary undo logs or vice versa. Therefore, we should keep two distinct sets of rollback segments: one for persistent tables and another for temporary tables. In this way, all 128 rollback segments will be available for both types of tables, which could improve performance. Also, MariaDB 10.2 will remain more compatible than MySQL 5.7 with data files from earlier versions of MySQL or MariaDB. trx_sys_t::temp_rsegs[TRX_SYS_N_RSEGS]: A new array of temporary rollback segments. The trx_sys_t::rseg_array[TRX_SYS_N_RSEGS] will be solely for persistent undo logs. srv_tmp_undo_logs. Remove. Use the constant TRX_SYS_N_RSEGS. srv_available_undo_logs: Change the type to ulong. trx_rseg_get_on_id(): Remove. Instead, let the callers refer to trx_sys directly. trx_rseg_create(), trx_sysf_rseg_find_free(): Remove unneeded parameters. These functions only deal with persistent undo logs. trx_temp_rseg_create(): New function, to create all temporary rollback segments at server startup. trx_rseg_t::is_persistent(): Determine if the rollback segment is for persistent tables. trx_sys_is_noredo_rseg_slot(): Remove. The callers must know based on context (such as table handle) whether the DB_ROLL_PTR is referring to a persistent undo log. trx_sys_create_rsegs(): Remove all parameters, which were always passed as global variables. Instead, modify the global variables directly. enum trx_rseg_type_t: Remove. trx_t::get_temp_rseg(): A method to ensure that a temporary rollback segment has been assigned for the transaction. trx_t::assign_temp_rseg(): Replaces trx_assign_rseg(). trx_purge_free_segment(), trx_purge_truncate_rseg_history(): Remove the redundant variable noredo=false. Temporary undo logs are discarded immediately at transaction commit or rollback, not lazily by purge. trx_purge_mark_undo_for_truncate(): Remove references to the temporary rollback segments. trx_purge_mark_undo_for_truncate(): Remove a check for temporary rollback segments. Only the dedicated persistent undo log tablespaces can be truncated. trx_undo_get_undo_rec_low(), trx_undo_get_undo_rec(): Add the parameter is_temp. trx_rseg_mem_restore(): Split from trx_rseg_mem_create(). Initialize the undo log and the rollback segment from the file data structures. trx_sysf_get_n_rseg_slots(): Renamed from trx_sysf_used_slots_for_redo_rseg(). Count the persistent rollback segment headers that have been initialized. trx_sys_close(): Also free trx_sys->temp_rsegs[]. get_next_redo_rseg(): Merged to trx_assign_rseg_low(). trx_assign_rseg_low(): Remove the parameters and access the global variables directly. Revert to simple round-robin, now that the whole trx_sys->rseg_array[] is for persistent undo log again. get_next_noredo_rseg(): Moved to trx_t::assign_temp_rseg(). srv_undo_tablespaces_init(): Remove some parameters and use the global variables directly. Clarify some error messages. Adjust the test innodb.log_file. Apparently, before these changes, InnoDB somehow ignored missing dedicated undo tablespace files that are pointed by the TRX_SYS header page, possibly losing part of essential transaction system state.
9 years ago
9 years ago
9 years ago
MDEV-12289 Keep 128 persistent rollback segments for compatibility and performance InnoDB divides the allocation of undo logs into rollback segments. The DB_ROLL_PTR system column of clustered indexes can address up to 128 rollback segments (TRX_SYS_N_RSEGS). Originally, InnoDB only created one rollback segment. In MySQL 5.5 or in the InnoDB Plugin for MySQL 5.1, all 128 rollback segments were created. MySQL 5.7 hard-codes the rollback segment IDs 1..32 for temporary undo logs. On upgrade, unless a slow shutdown (innodb_fast_shutdown=0) was performed on the old server instance, these rollback segments could be in use by transactions that are in XA PREPARE state or transactions that were left behind by a server kill followed by a normal shutdown immediately after restart. Persistent tables cannot refer to temporary undo logs or vice versa. Therefore, we should keep two distinct sets of rollback segments: one for persistent tables and another for temporary tables. In this way, all 128 rollback segments will be available for both types of tables, which could improve performance. Also, MariaDB 10.2 will remain more compatible than MySQL 5.7 with data files from earlier versions of MySQL or MariaDB. trx_sys_t::temp_rsegs[TRX_SYS_N_RSEGS]: A new array of temporary rollback segments. The trx_sys_t::rseg_array[TRX_SYS_N_RSEGS] will be solely for persistent undo logs. srv_tmp_undo_logs. Remove. Use the constant TRX_SYS_N_RSEGS. srv_available_undo_logs: Change the type to ulong. trx_rseg_get_on_id(): Remove. Instead, let the callers refer to trx_sys directly. trx_rseg_create(), trx_sysf_rseg_find_free(): Remove unneeded parameters. These functions only deal with persistent undo logs. trx_temp_rseg_create(): New function, to create all temporary rollback segments at server startup. trx_rseg_t::is_persistent(): Determine if the rollback segment is for persistent tables. trx_sys_is_noredo_rseg_slot(): Remove. The callers must know based on context (such as table handle) whether the DB_ROLL_PTR is referring to a persistent undo log. trx_sys_create_rsegs(): Remove all parameters, which were always passed as global variables. Instead, modify the global variables directly. enum trx_rseg_type_t: Remove. trx_t::get_temp_rseg(): A method to ensure that a temporary rollback segment has been assigned for the transaction. trx_t::assign_temp_rseg(): Replaces trx_assign_rseg(). trx_purge_free_segment(), trx_purge_truncate_rseg_history(): Remove the redundant variable noredo=false. Temporary undo logs are discarded immediately at transaction commit or rollback, not lazily by purge. trx_purge_mark_undo_for_truncate(): Remove references to the temporary rollback segments. trx_purge_mark_undo_for_truncate(): Remove a check for temporary rollback segments. Only the dedicated persistent undo log tablespaces can be truncated. trx_undo_get_undo_rec_low(), trx_undo_get_undo_rec(): Add the parameter is_temp. trx_rseg_mem_restore(): Split from trx_rseg_mem_create(). Initialize the undo log and the rollback segment from the file data structures. trx_sysf_get_n_rseg_slots(): Renamed from trx_sysf_used_slots_for_redo_rseg(). Count the persistent rollback segment headers that have been initialized. trx_sys_close(): Also free trx_sys->temp_rsegs[]. get_next_redo_rseg(): Merged to trx_assign_rseg_low(). trx_assign_rseg_low(): Remove the parameters and access the global variables directly. Revert to simple round-robin, now that the whole trx_sys->rseg_array[] is for persistent undo log again. get_next_noredo_rseg(): Moved to trx_t::assign_temp_rseg(). srv_undo_tablespaces_init(): Remove some parameters and use the global variables directly. Clarify some error messages. Adjust the test innodb.log_file. Apparently, before these changes, InnoDB somehow ignored missing dedicated undo tablespace files that are pointed by the TRX_SYS header page, possibly losing part of essential transaction system state.
9 years ago
MDEV-12289 Keep 128 persistent rollback segments for compatibility and performance InnoDB divides the allocation of undo logs into rollback segments. The DB_ROLL_PTR system column of clustered indexes can address up to 128 rollback segments (TRX_SYS_N_RSEGS). Originally, InnoDB only created one rollback segment. In MySQL 5.5 or in the InnoDB Plugin for MySQL 5.1, all 128 rollback segments were created. MySQL 5.7 hard-codes the rollback segment IDs 1..32 for temporary undo logs. On upgrade, unless a slow shutdown (innodb_fast_shutdown=0) was performed on the old server instance, these rollback segments could be in use by transactions that are in XA PREPARE state or transactions that were left behind by a server kill followed by a normal shutdown immediately after restart. Persistent tables cannot refer to temporary undo logs or vice versa. Therefore, we should keep two distinct sets of rollback segments: one for persistent tables and another for temporary tables. In this way, all 128 rollback segments will be available for both types of tables, which could improve performance. Also, MariaDB 10.2 will remain more compatible than MySQL 5.7 with data files from earlier versions of MySQL or MariaDB. trx_sys_t::temp_rsegs[TRX_SYS_N_RSEGS]: A new array of temporary rollback segments. The trx_sys_t::rseg_array[TRX_SYS_N_RSEGS] will be solely for persistent undo logs. srv_tmp_undo_logs. Remove. Use the constant TRX_SYS_N_RSEGS. srv_available_undo_logs: Change the type to ulong. trx_rseg_get_on_id(): Remove. Instead, let the callers refer to trx_sys directly. trx_rseg_create(), trx_sysf_rseg_find_free(): Remove unneeded parameters. These functions only deal with persistent undo logs. trx_temp_rseg_create(): New function, to create all temporary rollback segments at server startup. trx_rseg_t::is_persistent(): Determine if the rollback segment is for persistent tables. trx_sys_is_noredo_rseg_slot(): Remove. The callers must know based on context (such as table handle) whether the DB_ROLL_PTR is referring to a persistent undo log. trx_sys_create_rsegs(): Remove all parameters, which were always passed as global variables. Instead, modify the global variables directly. enum trx_rseg_type_t: Remove. trx_t::get_temp_rseg(): A method to ensure that a temporary rollback segment has been assigned for the transaction. trx_t::assign_temp_rseg(): Replaces trx_assign_rseg(). trx_purge_free_segment(), trx_purge_truncate_rseg_history(): Remove the redundant variable noredo=false. Temporary undo logs are discarded immediately at transaction commit or rollback, not lazily by purge. trx_purge_mark_undo_for_truncate(): Remove references to the temporary rollback segments. trx_purge_mark_undo_for_truncate(): Remove a check for temporary rollback segments. Only the dedicated persistent undo log tablespaces can be truncated. trx_undo_get_undo_rec_low(), trx_undo_get_undo_rec(): Add the parameter is_temp. trx_rseg_mem_restore(): Split from trx_rseg_mem_create(). Initialize the undo log and the rollback segment from the file data structures. trx_sysf_get_n_rseg_slots(): Renamed from trx_sysf_used_slots_for_redo_rseg(). Count the persistent rollback segment headers that have been initialized. trx_sys_close(): Also free trx_sys->temp_rsegs[]. get_next_redo_rseg(): Merged to trx_assign_rseg_low(). trx_assign_rseg_low(): Remove the parameters and access the global variables directly. Revert to simple round-robin, now that the whole trx_sys->rseg_array[] is for persistent undo log again. get_next_noredo_rseg(): Moved to trx_t::assign_temp_rseg(). srv_undo_tablespaces_init(): Remove some parameters and use the global variables directly. Clarify some error messages. Adjust the test innodb.log_file. Apparently, before these changes, InnoDB somehow ignored missing dedicated undo tablespace files that are pointed by the TRX_SYS header page, possibly losing part of essential transaction system state.
9 years ago
MDEV-12289 Keep 128 persistent rollback segments for compatibility and performance InnoDB divides the allocation of undo logs into rollback segments. The DB_ROLL_PTR system column of clustered indexes can address up to 128 rollback segments (TRX_SYS_N_RSEGS). Originally, InnoDB only created one rollback segment. In MySQL 5.5 or in the InnoDB Plugin for MySQL 5.1, all 128 rollback segments were created. MySQL 5.7 hard-codes the rollback segment IDs 1..32 for temporary undo logs. On upgrade, unless a slow shutdown (innodb_fast_shutdown=0) was performed on the old server instance, these rollback segments could be in use by transactions that are in XA PREPARE state or transactions that were left behind by a server kill followed by a normal shutdown immediately after restart. Persistent tables cannot refer to temporary undo logs or vice versa. Therefore, we should keep two distinct sets of rollback segments: one for persistent tables and another for temporary tables. In this way, all 128 rollback segments will be available for both types of tables, which could improve performance. Also, MariaDB 10.2 will remain more compatible than MySQL 5.7 with data files from earlier versions of MySQL or MariaDB. trx_sys_t::temp_rsegs[TRX_SYS_N_RSEGS]: A new array of temporary rollback segments. The trx_sys_t::rseg_array[TRX_SYS_N_RSEGS] will be solely for persistent undo logs. srv_tmp_undo_logs. Remove. Use the constant TRX_SYS_N_RSEGS. srv_available_undo_logs: Change the type to ulong. trx_rseg_get_on_id(): Remove. Instead, let the callers refer to trx_sys directly. trx_rseg_create(), trx_sysf_rseg_find_free(): Remove unneeded parameters. These functions only deal with persistent undo logs. trx_temp_rseg_create(): New function, to create all temporary rollback segments at server startup. trx_rseg_t::is_persistent(): Determine if the rollback segment is for persistent tables. trx_sys_is_noredo_rseg_slot(): Remove. The callers must know based on context (such as table handle) whether the DB_ROLL_PTR is referring to a persistent undo log. trx_sys_create_rsegs(): Remove all parameters, which were always passed as global variables. Instead, modify the global variables directly. enum trx_rseg_type_t: Remove. trx_t::get_temp_rseg(): A method to ensure that a temporary rollback segment has been assigned for the transaction. trx_t::assign_temp_rseg(): Replaces trx_assign_rseg(). trx_purge_free_segment(), trx_purge_truncate_rseg_history(): Remove the redundant variable noredo=false. Temporary undo logs are discarded immediately at transaction commit or rollback, not lazily by purge. trx_purge_mark_undo_for_truncate(): Remove references to the temporary rollback segments. trx_purge_mark_undo_for_truncate(): Remove a check for temporary rollback segments. Only the dedicated persistent undo log tablespaces can be truncated. trx_undo_get_undo_rec_low(), trx_undo_get_undo_rec(): Add the parameter is_temp. trx_rseg_mem_restore(): Split from trx_rseg_mem_create(). Initialize the undo log and the rollback segment from the file data structures. trx_sysf_get_n_rseg_slots(): Renamed from trx_sysf_used_slots_for_redo_rseg(). Count the persistent rollback segment headers that have been initialized. trx_sys_close(): Also free trx_sys->temp_rsegs[]. get_next_redo_rseg(): Merged to trx_assign_rseg_low(). trx_assign_rseg_low(): Remove the parameters and access the global variables directly. Revert to simple round-robin, now that the whole trx_sys->rseg_array[] is for persistent undo log again. get_next_noredo_rseg(): Moved to trx_t::assign_temp_rseg(). srv_undo_tablespaces_init(): Remove some parameters and use the global variables directly. Clarify some error messages. Adjust the test innodb.log_file. Apparently, before these changes, InnoDB somehow ignored missing dedicated undo tablespace files that are pointed by the TRX_SYS header page, possibly losing part of essential transaction system state.
9 years ago
MDEV-14717: Prevent crash-downgrade to earlier MariaDB 10.2 A crash-downgrade of a RENAME (or TRUNCATE or table-rebuilding ALTER TABLE or OPTIMIZE TABLE) operation to an earlier 10.2 version would trigger a debug assertion failure during rollback, in trx_roll_pop_top_rec_of_trx(). In a non-debug build, the TRX_UNDO_RENAME_TABLE record would be misinterpreted as an update_undo log record, and typically the file name would be interpreted as DB_TRX_ID,DB_ROLL_PTR,PRIMARY KEY. If a matching record would be found, row_undo_mod() would hit ut_error in switch (node->rec_type). Typically, ut_a(table2 == NULL) would fail when opening the table from SQL. Because of this, we prevent a crash-downgrade to earlier MariaDB 10.2 versions by changing the InnoDB redo log format identifier to the 10.3 identifier, and by introducing a subformat identifier so that 10.2 can continue to refuse crash-downgrade from 10.3 or later. After a clean shutdown, a downgrade to MariaDB 10.2.13 or later would still be possible thanks to MDEV-14909. A downgrade to older 10.2 versions is only possible after removing the log files (not recommended). LOG_HEADER_FORMAT_CURRENT: Change to 103 (originally the 10.3 format). log_group_t: Add subformat. For 10.2, we will use subformat 1, and will refuse crash recovery from any other subformat of the 10.3 format, that is, a genuine 10.3 redo log. recv_find_max_checkpoint(): Allow startup after clean shutdown from a future LOG_HEADER_FORMAT_10_4 (unencrypted only). We cannot handle the encrypted 10.4 redo log block format, which was introduced in MDEV-12041. Allow crash recovery from the original 10.2 format as well as the new format. In Mariabackup --backup, do not allow any startup from 10.3 or 10.4 redo logs. recv_recovery_from_checkpoint_start(): Skip redo log apply for clean 10.3 redo log, but not for the new 10.2 redo log (10.3 format, subformat 1). srv_prepare_to_delete_redo_log_files(): On format or subformat mismatch, set srv_log_file_size = 0, so that we will display the correct message. innobase_start_or_create_for_mysql(): Check for format or subformat mismatch. xtrabackup_backup_func(): Remove debug assertions that were made redundant by the code changes in recv_find_max_checkpoint().
7 years ago
MDEV-11782: Redefine the innodb_encrypt_log format Write only one encryption key to the checkpoint page. Use 4 bytes of nonce. Encrypt more of each redo log block, only skipping the 4-byte field LOG_BLOCK_HDR_NO which the initialization vector is derived from. Issue notes, not warning messages for rewriting the redo log files. recv_recovery_from_checkpoint_finish(): Do not generate any redo log, because we must avoid that before rewriting the redo log files, or otherwise a crash during a redo log rewrite (removing or adding encryption) may end up making the database unrecoverable. Instead, do these tasks in innobase_start_or_create_for_mysql(). Issue a firm "Missing MLOG_CHECKPOINT" error message. Remove some unreachable code and duplicated error messages for log corruption. LOG_HEADER_FORMAT_ENCRYPTED: A flag for identifying an encrypted redo log format. log_group_t::is_encrypted(), log_t::is_encrypted(): Determine if the redo log is in encrypted format. recv_find_max_checkpoint(): Interpret LOG_HEADER_FORMAT_ENCRYPTED. srv_prepare_to_delete_redo_log_files(): Display NOTE messages about adding or removing encryption. Do not issue warnings for redo log resizing any more. innobase_start_or_create_for_mysql(): Rebuild the redo logs also when the encryption changes. innodb_log_checksums_func_update(): Always use the CRC-32C checksum if innodb_encrypt_log. If needed, issue a warning that innodb_encrypt_log implies innodb_log_checksums. log_group_write_buf(): Compute the checksum on the encrypted block contents, so that transmission errors or incomplete blocks can be detected without decrypting. Rewrite most of the redo log encryption code. Only remember one encryption key at a time (but remember up to 5 when upgrading from the MariaDB 10.1 format.)
9 years ago
MDEV-11782: Redefine the innodb_encrypt_log format Write only one encryption key to the checkpoint page. Use 4 bytes of nonce. Encrypt more of each redo log block, only skipping the 4-byte field LOG_BLOCK_HDR_NO which the initialization vector is derived from. Issue notes, not warning messages for rewriting the redo log files. recv_recovery_from_checkpoint_finish(): Do not generate any redo log, because we must avoid that before rewriting the redo log files, or otherwise a crash during a redo log rewrite (removing or adding encryption) may end up making the database unrecoverable. Instead, do these tasks in innobase_start_or_create_for_mysql(). Issue a firm "Missing MLOG_CHECKPOINT" error message. Remove some unreachable code and duplicated error messages for log corruption. LOG_HEADER_FORMAT_ENCRYPTED: A flag for identifying an encrypted redo log format. log_group_t::is_encrypted(), log_t::is_encrypted(): Determine if the redo log is in encrypted format. recv_find_max_checkpoint(): Interpret LOG_HEADER_FORMAT_ENCRYPTED. srv_prepare_to_delete_redo_log_files(): Display NOTE messages about adding or removing encryption. Do not issue warnings for redo log resizing any more. innobase_start_or_create_for_mysql(): Rebuild the redo logs also when the encryption changes. innodb_log_checksums_func_update(): Always use the CRC-32C checksum if innodb_encrypt_log. If needed, issue a warning that innodb_encrypt_log implies innodb_log_checksums. log_group_write_buf(): Compute the checksum on the encrypted block contents, so that transmission errors or incomplete blocks can be detected without decrypting. Rewrite most of the redo log encryption code. Only remember one encryption key at a time (but remember up to 5 when upgrading from the MariaDB 10.1 format.)
9 years ago
MDEV-11782: Redefine the innodb_encrypt_log format Write only one encryption key to the checkpoint page. Use 4 bytes of nonce. Encrypt more of each redo log block, only skipping the 4-byte field LOG_BLOCK_HDR_NO which the initialization vector is derived from. Issue notes, not warning messages for rewriting the redo log files. recv_recovery_from_checkpoint_finish(): Do not generate any redo log, because we must avoid that before rewriting the redo log files, or otherwise a crash during a redo log rewrite (removing or adding encryption) may end up making the database unrecoverable. Instead, do these tasks in innobase_start_or_create_for_mysql(). Issue a firm "Missing MLOG_CHECKPOINT" error message. Remove some unreachable code and duplicated error messages for log corruption. LOG_HEADER_FORMAT_ENCRYPTED: A flag for identifying an encrypted redo log format. log_group_t::is_encrypted(), log_t::is_encrypted(): Determine if the redo log is in encrypted format. recv_find_max_checkpoint(): Interpret LOG_HEADER_FORMAT_ENCRYPTED. srv_prepare_to_delete_redo_log_files(): Display NOTE messages about adding or removing encryption. Do not issue warnings for redo log resizing any more. innobase_start_or_create_for_mysql(): Rebuild the redo logs also when the encryption changes. innodb_log_checksums_func_update(): Always use the CRC-32C checksum if innodb_encrypt_log. If needed, issue a warning that innodb_encrypt_log implies innodb_log_checksums. log_group_write_buf(): Compute the checksum on the encrypted block contents, so that transmission errors or incomplete blocks can be detected without decrypting. Rewrite most of the redo log encryption code. Only remember one encryption key at a time (but remember up to 5 when upgrading from the MariaDB 10.1 format.)
9 years ago
MDEV-11782: Redefine the innodb_encrypt_log format Write only one encryption key to the checkpoint page. Use 4 bytes of nonce. Encrypt more of each redo log block, only skipping the 4-byte field LOG_BLOCK_HDR_NO which the initialization vector is derived from. Issue notes, not warning messages for rewriting the redo log files. recv_recovery_from_checkpoint_finish(): Do not generate any redo log, because we must avoid that before rewriting the redo log files, or otherwise a crash during a redo log rewrite (removing or adding encryption) may end up making the database unrecoverable. Instead, do these tasks in innobase_start_or_create_for_mysql(). Issue a firm "Missing MLOG_CHECKPOINT" error message. Remove some unreachable code and duplicated error messages for log corruption. LOG_HEADER_FORMAT_ENCRYPTED: A flag for identifying an encrypted redo log format. log_group_t::is_encrypted(), log_t::is_encrypted(): Determine if the redo log is in encrypted format. recv_find_max_checkpoint(): Interpret LOG_HEADER_FORMAT_ENCRYPTED. srv_prepare_to_delete_redo_log_files(): Display NOTE messages about adding or removing encryption. Do not issue warnings for redo log resizing any more. innobase_start_or_create_for_mysql(): Rebuild the redo logs also when the encryption changes. innodb_log_checksums_func_update(): Always use the CRC-32C checksum if innodb_encrypt_log. If needed, issue a warning that innodb_encrypt_log implies innodb_log_checksums. log_group_write_buf(): Compute the checksum on the encrypted block contents, so that transmission errors or incomplete blocks can be detected without decrypting. Rewrite most of the redo log encryption code. Only remember one encryption key at a time (but remember up to 5 when upgrading from the MariaDB 10.1 format.)
9 years ago
MDEV-11782: Redefine the innodb_encrypt_log format Write only one encryption key to the checkpoint page. Use 4 bytes of nonce. Encrypt more of each redo log block, only skipping the 4-byte field LOG_BLOCK_HDR_NO which the initialization vector is derived from. Issue notes, not warning messages for rewriting the redo log files. recv_recovery_from_checkpoint_finish(): Do not generate any redo log, because we must avoid that before rewriting the redo log files, or otherwise a crash during a redo log rewrite (removing or adding encryption) may end up making the database unrecoverable. Instead, do these tasks in innobase_start_or_create_for_mysql(). Issue a firm "Missing MLOG_CHECKPOINT" error message. Remove some unreachable code and duplicated error messages for log corruption. LOG_HEADER_FORMAT_ENCRYPTED: A flag for identifying an encrypted redo log format. log_group_t::is_encrypted(), log_t::is_encrypted(): Determine if the redo log is in encrypted format. recv_find_max_checkpoint(): Interpret LOG_HEADER_FORMAT_ENCRYPTED. srv_prepare_to_delete_redo_log_files(): Display NOTE messages about adding or removing encryption. Do not issue warnings for redo log resizing any more. innobase_start_or_create_for_mysql(): Rebuild the redo logs also when the encryption changes. innodb_log_checksums_func_update(): Always use the CRC-32C checksum if innodb_encrypt_log. If needed, issue a warning that innodb_encrypt_log implies innodb_log_checksums. log_group_write_buf(): Compute the checksum on the encrypted block contents, so that transmission errors or incomplete blocks can be detected without decrypting. Rewrite most of the redo log encryption code. Only remember one encryption key at a time (but remember up to 5 when upgrading from the MariaDB 10.1 format.)
9 years ago
Reduce the granularity of innodb_log_file_size In Mariabackup, we would want the backed-up redo log file size to be a multiple of 512 bytes, or OS_FILE_LOG_BLOCK_SIZE. However, at startup, InnoDB would be picky, requiring the file size to be a multiple of innodb_page_size. Furthermore, InnoDB would require the parameter to be a multiple of one megabyte, while the minimum granularity is 512 bytes. Because the data-file-oriented fil_io() API is being used for writing the InnoDB redo log, writes will for now require innodb_log_file_size to be a multiple of the maximum innodb_page_size (65536 bytes). To complicate matters, InnoDB startup divided srv_log_file_size by UNIV_PAGE_SIZE, so that initially, the unit was bytes, and later it was innodb_page_size. We will simplify this and keep srv_log_file_size in bytes at all times. innobase_log_file_size: Remove. Remove some obsolete checks against overflow on 32-bit systems. srv_log_file_size is always 64 bits, and the maximum size 512GiB in multiples of innodb_page_size always fits in ulint (which is 32 or 64 bits). 512GiB would be 8,388,608*64KiB or 134,217,728*4KiB. log_init(): Remove the parameter file_size that was always passed as srv_log_file_size. log_set_capacity(): Add a parameter for passing the requested file size. srv_log_file_size_requested: Declare static in srv0start.cc. create_log_file(), create_log_files(), innobase_start_or_create_for_mysql(): Invoke fil_node_create() with srv_log_file_size expressed in multiples of innodb_page_size. innobase_start_or_create_for_mysql(): Require the redo log file sizes to be multiples of 512 bytes.
9 years ago
Shut down InnoDB after aborted startup. This fixes memory leaks in tests that cause InnoDB startup to fail. buf_pool_free_instance(): Also free buf_pool->flush_rbt, which would normally be freed when crash recovery finishes. fil_node_close_file(), fil_space_free_low(), fil_close_all_files(): Relax some debug assertions to tolerate !srv_was_started. innodb_shutdown(): Renamed from innobase_shutdown_for_mysql(). Changed the return type to void. Do not assume that all subsystems were started. que_init(), que_close(): Remove (empty functions). srv_init(), srv_general_init(): Remove as global functions. srv_free(): Allow srv_sys=NULL. srv_get_active_thread_type(): Only return SRV_PURGE if purge really is running. srv_shutdown_all_bg_threads(): Do not reset srv_start_state. It will be needed by innodb_shutdown(). innobase_start_or_create_for_mysql(): Always call srv_boot() so that innodb_shutdown() can assume that it was called. Make more subsystems dependent on SRV_START_STATE_STAT. srv_shutdown_bg_undo_sources(): Require SRV_START_STATE_STAT. trx_sys_close(): Do not assume purge_sys!=NULL. Do not call buf_dblwr_free(), because the doublewrite buffer can exist while the transaction system does not. logs_empty_and_mark_files_at_shutdown(): Do a faster shutdown if !srv_was_started. recv_sys_close(): Invoke dblwr.pages.clear() which would normally be invoked by buf_dblwr_process(). recv_recovery_from_checkpoint_start(): Always release log_sys->mutex. row_mysql_close(): Allow the subsystem not to exist.
9 years ago
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2 InnoDB I/O and buffer pool interfaces and the redo log format have been changed between MariaDB 10.1 and 10.2, and the backup code has to be adjusted accordingly. The code has been simplified, and many memory leaks have been fixed. Instead of the file name xtrabackup_logfile, the file name ib_logfile0 is being used for the copy of the redo log. Unnecessary InnoDB startup and shutdown and some unnecessary threads have been removed. Some help was provided by Vladislav Vaintroub. Parameters have been cleaned up and aligned with those of MariaDB 10.2. The --dbug option has been added, so that in debug builds, --dbug=d,ib_log can be specified to enable diagnostic messages for processing redo log entries. By default, innodb_doublewrite=OFF, so that --prepare works faster. If more crash-safety for --prepare is needed, double buffering can be enabled. The parameter innodb_log_checksums=OFF can be used to ignore redo log checksums in --backup. Some messages have been cleaned up. Unless --export is specified, Mariabackup will not deal with undo log. The InnoDB mini-transaction redo log is not only about user-level transactions; it is actually about mini-transactions. To avoid confusion, call it the redo log, not transaction log. We disable any undo log processing in --prepare. Because MariaDB 10.2 supports indexed virtual columns, the undo log processing would need to be able to evaluate virtual column expressions. To reduce the amount of code dependencies, we will not process any undo log in prepare. This means that the --export option must be disabled for now. This also means that the following options are redundant and have been removed: xtrabackup --apply-log-only innobackupex --redo-only In addition to disabling any undo log processing, we will disable any further changes to data pages during --prepare, including the change buffer merge. This means that restoring incremental backups should reliably work even when change buffering is being used on the server. Because of this, preparing a backup will not generate any further redo log, and the redo log file can be safely deleted. (If the --export option is enabled in the future, it must generate redo log when processing undo logs and buffered changes.) In --prepare, we cannot easily know if a partial backup was used, especially when restoring a series of incremental backups. So, we simply warn about any missing files, and ignore the redo log for them. FIXME: Enable the --export option. FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write a test that initiates a backup while an ALGORITHM=INPLACE operation is creating indexes or rebuilding a table. An error should be detected when preparing the backup. FIXME: In --incremental --prepare, xtrabackup_apply_delta() should ensure that if FSP_SIZE is modified, the file size will be adjusted accordingly.
9 years ago
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2 InnoDB I/O and buffer pool interfaces and the redo log format have been changed between MariaDB 10.1 and 10.2, and the backup code has to be adjusted accordingly. The code has been simplified, and many memory leaks have been fixed. Instead of the file name xtrabackup_logfile, the file name ib_logfile0 is being used for the copy of the redo log. Unnecessary InnoDB startup and shutdown and some unnecessary threads have been removed. Some help was provided by Vladislav Vaintroub. Parameters have been cleaned up and aligned with those of MariaDB 10.2. The --dbug option has been added, so that in debug builds, --dbug=d,ib_log can be specified to enable diagnostic messages for processing redo log entries. By default, innodb_doublewrite=OFF, so that --prepare works faster. If more crash-safety for --prepare is needed, double buffering can be enabled. The parameter innodb_log_checksums=OFF can be used to ignore redo log checksums in --backup. Some messages have been cleaned up. Unless --export is specified, Mariabackup will not deal with undo log. The InnoDB mini-transaction redo log is not only about user-level transactions; it is actually about mini-transactions. To avoid confusion, call it the redo log, not transaction log. We disable any undo log processing in --prepare. Because MariaDB 10.2 supports indexed virtual columns, the undo log processing would need to be able to evaluate virtual column expressions. To reduce the amount of code dependencies, we will not process any undo log in prepare. This means that the --export option must be disabled for now. This also means that the following options are redundant and have been removed: xtrabackup --apply-log-only innobackupex --redo-only In addition to disabling any undo log processing, we will disable any further changes to data pages during --prepare, including the change buffer merge. This means that restoring incremental backups should reliably work even when change buffering is being used on the server. Because of this, preparing a backup will not generate any further redo log, and the redo log file can be safely deleted. (If the --export option is enabled in the future, it must generate redo log when processing undo logs and buffered changes.) In --prepare, we cannot easily know if a partial backup was used, especially when restoring a series of incremental backups. So, we simply warn about any missing files, and ignore the redo log for them. FIXME: Enable the --export option. FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write a test that initiates a backup while an ALGORITHM=INPLACE operation is creating indexes or rebuilding a table. An error should be detected when preparing the backup. FIXME: In --incremental --prepare, xtrabackup_apply_delta() should ensure that if FSP_SIZE is modified, the file size will be adjusted accordingly.
9 years ago
10 years ago
MDEV-19514 Defer change buffer merge until pages are requested We will remove the InnoDB background operation of merging buffered changes to secondary index leaf pages. Changes will only be merged as a result of an operation that accesses a secondary index leaf page, such as a SQL statement that performs a lookup via that index, or is modifying the index. Also ROLLBACK and some background operations, such as purging the history of committed transactions, or computing index cardinality statistics, can cause change buffer merge. Encryption key rotation will not perform change buffer merge. The motivation of this change is to simplify the I/O logic and to allow crash recovery to happen in the background (MDEV-14481). We also hope that this will reduce the number of "mystery" crashes due to corrupted data. Because change buffer merge will typically take place as a result of executing SQL statements, there should be a clearer connection between the crash and the SQL statements that were executed when the server crashed. In many cases, a slight performance improvement was observed. This is joint work with Thirunarayanan Balathandayuthapani and was tested by Axel Schwenke and Matthias Leich. The InnoDB monitor counter innodb_ibuf_merge_usec will be removed. On slow shutdown (innodb_fast_shutdown=0), we will continue to merge all buffered changes (and purge all undo log history). Two InnoDB configuration parameters will be changed as follows: innodb_disable_background_merge: Removed. This parameter existed only in debug builds. All change buffer merges will use synchronous reads. innodb_force_recovery will be changed as follows: * innodb_force_recovery=4 will be the same as innodb_force_recovery=3 (the change buffer merge cannot be disabled; it can only happen as a result of an operation that accesses a secondary index leaf page). The option used to be capable of corrupting secondary index leaf pages. Now that capability is removed, and innodb_force_recovery=4 becomes 'safe'. * innodb_force_recovery=5 (which essentially hard-wires SET GLOBAL TRANSACTION ISOLATION LEVEL READ UNCOMMITTED) becomes safe to use. Bogus data can be returned to SQL, but persistent InnoDB data files will not be corrupted further. * innodb_force_recovery=6 (ignore the redo log files) will be the only option that can potentially cause persistent corruption of InnoDB data files. Code changes: buf_page_t::ibuf_exist: New flag, to indicate whether buffered changes exist for a buffer pool page. Pages with pending changes can be returned by buf_page_get_gen(). Previously, the changes were always merged inside buf_page_get_gen() if needed. ibuf_page_exists(const buf_page_t&): Check if a buffered changes exist for an X-latched or read-fixed page. buf_page_get_gen(): Add the parameter allow_ibuf_merge=false. All callers that know that they may be accessing a secondary index leaf page must pass this parameter as allow_ibuf_merge=true, unless it does not matter for that caller whether all buffered changes have been applied. Assert that whenever allow_ibuf_merge holds, the page actually is a leaf page. Attempt change buffer merge only to secondary B-tree index leaf pages. btr_block_get(): Add parameter 'bool merge'. All callers of btr_block_get() should know whether the page could be a secondary index leaf page. If it is not, we should avoid consulting the change buffer bitmap to even consider a merge. This is the main interface to requesting index pages from the buffer pool. ibuf_merge_or_delete_for_page(), recv_recover_page(): Replace buf_page_get_known_nowait() with much simpler logic, because it is now guaranteed that that the block is x-latched or read-fixed. mlog_init_t::mark_ibuf_exist(): Renamed from mlog_init_t::ibuf_merge(). On crash recovery, we will no longer merge any buffered changes for the pages that we read into the buffer pool during the last batch of applying log records. buf_page_get_gen_known_nowait(), BUF_MAKE_YOUNG, BUF_KEEP_OLD: Remove. btr_search_guess_on_hash(): Merge buf_page_get_gen_known_nowait() to its only remaining caller. buf_page_make_young_if_needed(): Define as an inline function. Add the parameter buf_pool. buf_page_peek_if_young(), buf_page_peek_if_too_old(): Add the parameter buf_pool. fil_space_validate_for_mtr_commit(): Remove a bogus comment about background merge of the change buffer. btr_cur_open_at_rnd_pos_func(), btr_cur_search_to_nth_level_func(), btr_cur_open_at_index_side_func(): Use narrower data types and scopes. ibuf_read_merge_pages(): Replaces buf_read_ibuf_merge_pages(). Merge the change buffer by invoking buf_page_get_gen().
6 years ago
12 years ago
11 years ago
12 years ago
12 years ago
12 years ago
12 years ago
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2 InnoDB I/O and buffer pool interfaces and the redo log format have been changed between MariaDB 10.1 and 10.2, and the backup code has to be adjusted accordingly. The code has been simplified, and many memory leaks have been fixed. Instead of the file name xtrabackup_logfile, the file name ib_logfile0 is being used for the copy of the redo log. Unnecessary InnoDB startup and shutdown and some unnecessary threads have been removed. Some help was provided by Vladislav Vaintroub. Parameters have been cleaned up and aligned with those of MariaDB 10.2. The --dbug option has been added, so that in debug builds, --dbug=d,ib_log can be specified to enable diagnostic messages for processing redo log entries. By default, innodb_doublewrite=OFF, so that --prepare works faster. If more crash-safety for --prepare is needed, double buffering can be enabled. The parameter innodb_log_checksums=OFF can be used to ignore redo log checksums in --backup. Some messages have been cleaned up. Unless --export is specified, Mariabackup will not deal with undo log. The InnoDB mini-transaction redo log is not only about user-level transactions; it is actually about mini-transactions. To avoid confusion, call it the redo log, not transaction log. We disable any undo log processing in --prepare. Because MariaDB 10.2 supports indexed virtual columns, the undo log processing would need to be able to evaluate virtual column expressions. To reduce the amount of code dependencies, we will not process any undo log in prepare. This means that the --export option must be disabled for now. This also means that the following options are redundant and have been removed: xtrabackup --apply-log-only innobackupex --redo-only In addition to disabling any undo log processing, we will disable any further changes to data pages during --prepare, including the change buffer merge. This means that restoring incremental backups should reliably work even when change buffering is being used on the server. Because of this, preparing a backup will not generate any further redo log, and the redo log file can be safely deleted. (If the --export option is enabled in the future, it must generate redo log when processing undo logs and buffered changes.) In --prepare, we cannot easily know if a partial backup was used, especially when restoring a series of incremental backups. So, we simply warn about any missing files, and ignore the redo log for them. FIXME: Enable the --export option. FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write a test that initiates a backup while an ALGORITHM=INPLACE operation is creating indexes or rebuilding a table. An error should be detected when preparing the backup. FIXME: In --incremental --prepare, xtrabackup_apply_delta() should ensure that if FSP_SIZE is modified, the file size will be adjusted accordingly.
9 years ago
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2 InnoDB I/O and buffer pool interfaces and the redo log format have been changed between MariaDB 10.1 and 10.2, and the backup code has to be adjusted accordingly. The code has been simplified, and many memory leaks have been fixed. Instead of the file name xtrabackup_logfile, the file name ib_logfile0 is being used for the copy of the redo log. Unnecessary InnoDB startup and shutdown and some unnecessary threads have been removed. Some help was provided by Vladislav Vaintroub. Parameters have been cleaned up and aligned with those of MariaDB 10.2. The --dbug option has been added, so that in debug builds, --dbug=d,ib_log can be specified to enable diagnostic messages for processing redo log entries. By default, innodb_doublewrite=OFF, so that --prepare works faster. If more crash-safety for --prepare is needed, double buffering can be enabled. The parameter innodb_log_checksums=OFF can be used to ignore redo log checksums in --backup. Some messages have been cleaned up. Unless --export is specified, Mariabackup will not deal with undo log. The InnoDB mini-transaction redo log is not only about user-level transactions; it is actually about mini-transactions. To avoid confusion, call it the redo log, not transaction log. We disable any undo log processing in --prepare. Because MariaDB 10.2 supports indexed virtual columns, the undo log processing would need to be able to evaluate virtual column expressions. To reduce the amount of code dependencies, we will not process any undo log in prepare. This means that the --export option must be disabled for now. This also means that the following options are redundant and have been removed: xtrabackup --apply-log-only innobackupex --redo-only In addition to disabling any undo log processing, we will disable any further changes to data pages during --prepare, including the change buffer merge. This means that restoring incremental backups should reliably work even when change buffering is being used on the server. Because of this, preparing a backup will not generate any further redo log, and the redo log file can be safely deleted. (If the --export option is enabled in the future, it must generate redo log when processing undo logs and buffered changes.) In --prepare, we cannot easily know if a partial backup was used, especially when restoring a series of incremental backups. So, we simply warn about any missing files, and ignore the redo log for them. FIXME: Enable the --export option. FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write a test that initiates a backup while an ALGORITHM=INPLACE operation is creating indexes or rebuilding a table. An error should be detected when preparing the backup. FIXME: In --incremental --prepare, xtrabackup_apply_delta() should ensure that if FSP_SIZE is modified, the file size will be adjusted accordingly.
9 years ago
Reduce the granularity of innodb_log_file_size In Mariabackup, we would want the backed-up redo log file size to be a multiple of 512 bytes, or OS_FILE_LOG_BLOCK_SIZE. However, at startup, InnoDB would be picky, requiring the file size to be a multiple of innodb_page_size. Furthermore, InnoDB would require the parameter to be a multiple of one megabyte, while the minimum granularity is 512 bytes. Because the data-file-oriented fil_io() API is being used for writing the InnoDB redo log, writes will for now require innodb_log_file_size to be a multiple of the maximum innodb_page_size (65536 bytes). To complicate matters, InnoDB startup divided srv_log_file_size by UNIV_PAGE_SIZE, so that initially, the unit was bytes, and later it was innodb_page_size. We will simplify this and keep srv_log_file_size in bytes at all times. innobase_log_file_size: Remove. Remove some obsolete checks against overflow on 32-bit systems. srv_log_file_size is always 64 bits, and the maximum size 512GiB in multiples of innodb_page_size always fits in ulint (which is 32 or 64 bits). 512GiB would be 8,388,608*64KiB or 134,217,728*4KiB. log_init(): Remove the parameter file_size that was always passed as srv_log_file_size. log_set_capacity(): Add a parameter for passing the requested file size. srv_log_file_size_requested: Declare static in srv0start.cc. create_log_file(), create_log_files(), innobase_start_or_create_for_mysql(): Invoke fil_node_create() with srv_log_file_size expressed in multiples of innodb_page_size. innobase_start_or_create_for_mysql(): Require the redo log file sizes to be multiples of 512 bytes.
9 years ago
Reduce the granularity of innodb_log_file_size In Mariabackup, we would want the backed-up redo log file size to be a multiple of 512 bytes, or OS_FILE_LOG_BLOCK_SIZE. However, at startup, InnoDB would be picky, requiring the file size to be a multiple of innodb_page_size. Furthermore, InnoDB would require the parameter to be a multiple of one megabyte, while the minimum granularity is 512 bytes. Because the data-file-oriented fil_io() API is being used for writing the InnoDB redo log, writes will for now require innodb_log_file_size to be a multiple of the maximum innodb_page_size (65536 bytes). To complicate matters, InnoDB startup divided srv_log_file_size by UNIV_PAGE_SIZE, so that initially, the unit was bytes, and later it was innodb_page_size. We will simplify this and keep srv_log_file_size in bytes at all times. innobase_log_file_size: Remove. Remove some obsolete checks against overflow on 32-bit systems. srv_log_file_size is always 64 bits, and the maximum size 512GiB in multiples of innodb_page_size always fits in ulint (which is 32 or 64 bits). 512GiB would be 8,388,608*64KiB or 134,217,728*4KiB. log_init(): Remove the parameter file_size that was always passed as srv_log_file_size. log_set_capacity(): Add a parameter for passing the requested file size. srv_log_file_size_requested: Declare static in srv0start.cc. create_log_file(), create_log_files(), innobase_start_or_create_for_mysql(): Invoke fil_node_create() with srv_log_file_size expressed in multiples of innodb_page_size. innobase_start_or_create_for_mysql(): Require the redo log file sizes to be multiples of 512 bytes.
9 years ago
Reduce the granularity of innodb_log_file_size In Mariabackup, we would want the backed-up redo log file size to be a multiple of 512 bytes, or OS_FILE_LOG_BLOCK_SIZE. However, at startup, InnoDB would be picky, requiring the file size to be a multiple of innodb_page_size. Furthermore, InnoDB would require the parameter to be a multiple of one megabyte, while the minimum granularity is 512 bytes. Because the data-file-oriented fil_io() API is being used for writing the InnoDB redo log, writes will for now require innodb_log_file_size to be a multiple of the maximum innodb_page_size (65536 bytes). To complicate matters, InnoDB startup divided srv_log_file_size by UNIV_PAGE_SIZE, so that initially, the unit was bytes, and later it was innodb_page_size. We will simplify this and keep srv_log_file_size in bytes at all times. innobase_log_file_size: Remove. Remove some obsolete checks against overflow on 32-bit systems. srv_log_file_size is always 64 bits, and the maximum size 512GiB in multiples of innodb_page_size always fits in ulint (which is 32 or 64 bits). 512GiB would be 8,388,608*64KiB or 134,217,728*4KiB. log_init(): Remove the parameter file_size that was always passed as srv_log_file_size. log_set_capacity(): Add a parameter for passing the requested file size. srv_log_file_size_requested: Declare static in srv0start.cc. create_log_file(), create_log_files(), innobase_start_or_create_for_mysql(): Invoke fil_node_create() with srv_log_file_size expressed in multiples of innodb_page_size. innobase_start_or_create_for_mysql(): Require the redo log file sizes to be multiples of 512 bytes.
9 years ago
Reduce the granularity of innodb_log_file_size In Mariabackup, we would want the backed-up redo log file size to be a multiple of 512 bytes, or OS_FILE_LOG_BLOCK_SIZE. However, at startup, InnoDB would be picky, requiring the file size to be a multiple of innodb_page_size. Furthermore, InnoDB would require the parameter to be a multiple of one megabyte, while the minimum granularity is 512 bytes. Because the data-file-oriented fil_io() API is being used for writing the InnoDB redo log, writes will for now require innodb_log_file_size to be a multiple of the maximum innodb_page_size (65536 bytes). To complicate matters, InnoDB startup divided srv_log_file_size by UNIV_PAGE_SIZE, so that initially, the unit was bytes, and later it was innodb_page_size. We will simplify this and keep srv_log_file_size in bytes at all times. innobase_log_file_size: Remove. Remove some obsolete checks against overflow on 32-bit systems. srv_log_file_size is always 64 bits, and the maximum size 512GiB in multiples of innodb_page_size always fits in ulint (which is 32 or 64 bits). 512GiB would be 8,388,608*64KiB or 134,217,728*4KiB. log_init(): Remove the parameter file_size that was always passed as srv_log_file_size. log_set_capacity(): Add a parameter for passing the requested file size. srv_log_file_size_requested: Declare static in srv0start.cc. create_log_file(), create_log_files(), innobase_start_or_create_for_mysql(): Invoke fil_node_create() with srv_log_file_size expressed in multiples of innodb_page_size. innobase_start_or_create_for_mysql(): Require the redo log file sizes to be multiples of 512 bytes.
9 years ago
Reduce the granularity of innodb_log_file_size In Mariabackup, we would want the backed-up redo log file size to be a multiple of 512 bytes, or OS_FILE_LOG_BLOCK_SIZE. However, at startup, InnoDB would be picky, requiring the file size to be a multiple of innodb_page_size. Furthermore, InnoDB would require the parameter to be a multiple of one megabyte, while the minimum granularity is 512 bytes. Because the data-file-oriented fil_io() API is being used for writing the InnoDB redo log, writes will for now require innodb_log_file_size to be a multiple of the maximum innodb_page_size (65536 bytes). To complicate matters, InnoDB startup divided srv_log_file_size by UNIV_PAGE_SIZE, so that initially, the unit was bytes, and later it was innodb_page_size. We will simplify this and keep srv_log_file_size in bytes at all times. innobase_log_file_size: Remove. Remove some obsolete checks against overflow on 32-bit systems. srv_log_file_size is always 64 bits, and the maximum size 512GiB in multiples of innodb_page_size always fits in ulint (which is 32 or 64 bits). 512GiB would be 8,388,608*64KiB or 134,217,728*4KiB. log_init(): Remove the parameter file_size that was always passed as srv_log_file_size. log_set_capacity(): Add a parameter for passing the requested file size. srv_log_file_size_requested: Declare static in srv0start.cc. create_log_file(), create_log_files(), innobase_start_or_create_for_mysql(): Invoke fil_node_create() with srv_log_file_size expressed in multiples of innodb_page_size. innobase_start_or_create_for_mysql(): Require the redo log file sizes to be multiples of 512 bytes.
9 years ago
Reduce the granularity of innodb_log_file_size In Mariabackup, we would want the backed-up redo log file size to be a multiple of 512 bytes, or OS_FILE_LOG_BLOCK_SIZE. However, at startup, InnoDB would be picky, requiring the file size to be a multiple of innodb_page_size. Furthermore, InnoDB would require the parameter to be a multiple of one megabyte, while the minimum granularity is 512 bytes. Because the data-file-oriented fil_io() API is being used for writing the InnoDB redo log, writes will for now require innodb_log_file_size to be a multiple of the maximum innodb_page_size (65536 bytes). To complicate matters, InnoDB startup divided srv_log_file_size by UNIV_PAGE_SIZE, so that initially, the unit was bytes, and later it was innodb_page_size. We will simplify this and keep srv_log_file_size in bytes at all times. innobase_log_file_size: Remove. Remove some obsolete checks against overflow on 32-bit systems. srv_log_file_size is always 64 bits, and the maximum size 512GiB in multiples of innodb_page_size always fits in ulint (which is 32 or 64 bits). 512GiB would be 8,388,608*64KiB or 134,217,728*4KiB. log_init(): Remove the parameter file_size that was always passed as srv_log_file_size. log_set_capacity(): Add a parameter for passing the requested file size. srv_log_file_size_requested: Declare static in srv0start.cc. create_log_file(), create_log_files(), innobase_start_or_create_for_mysql(): Invoke fil_node_create() with srv_log_file_size expressed in multiples of innodb_page_size. innobase_start_or_create_for_mysql(): Require the redo log file sizes to be multiples of 512 bytes.
9 years ago
Reduce the granularity of innodb_log_file_size In Mariabackup, we would want the backed-up redo log file size to be a multiple of 512 bytes, or OS_FILE_LOG_BLOCK_SIZE. However, at startup, InnoDB would be picky, requiring the file size to be a multiple of innodb_page_size. Furthermore, InnoDB would require the parameter to be a multiple of one megabyte, while the minimum granularity is 512 bytes. Because the data-file-oriented fil_io() API is being used for writing the InnoDB redo log, writes will for now require innodb_log_file_size to be a multiple of the maximum innodb_page_size (65536 bytes). To complicate matters, InnoDB startup divided srv_log_file_size by UNIV_PAGE_SIZE, so that initially, the unit was bytes, and later it was innodb_page_size. We will simplify this and keep srv_log_file_size in bytes at all times. innobase_log_file_size: Remove. Remove some obsolete checks against overflow on 32-bit systems. srv_log_file_size is always 64 bits, and the maximum size 512GiB in multiples of innodb_page_size always fits in ulint (which is 32 or 64 bits). 512GiB would be 8,388,608*64KiB or 134,217,728*4KiB. log_init(): Remove the parameter file_size that was always passed as srv_log_file_size. log_set_capacity(): Add a parameter for passing the requested file size. srv_log_file_size_requested: Declare static in srv0start.cc. create_log_file(), create_log_files(), innobase_start_or_create_for_mysql(): Invoke fil_node_create() with srv_log_file_size expressed in multiples of innodb_page_size. innobase_start_or_create_for_mysql(): Require the redo log file sizes to be multiples of 512 bytes.
9 years ago
MDEV-12289 Keep 128 persistent rollback segments for compatibility and performance InnoDB divides the allocation of undo logs into rollback segments. The DB_ROLL_PTR system column of clustered indexes can address up to 128 rollback segments (TRX_SYS_N_RSEGS). Originally, InnoDB only created one rollback segment. In MySQL 5.5 or in the InnoDB Plugin for MySQL 5.1, all 128 rollback segments were created. MySQL 5.7 hard-codes the rollback segment IDs 1..32 for temporary undo logs. On upgrade, unless a slow shutdown (innodb_fast_shutdown=0) was performed on the old server instance, these rollback segments could be in use by transactions that are in XA PREPARE state or transactions that were left behind by a server kill followed by a normal shutdown immediately after restart. Persistent tables cannot refer to temporary undo logs or vice versa. Therefore, we should keep two distinct sets of rollback segments: one for persistent tables and another for temporary tables. In this way, all 128 rollback segments will be available for both types of tables, which could improve performance. Also, MariaDB 10.2 will remain more compatible than MySQL 5.7 with data files from earlier versions of MySQL or MariaDB. trx_sys_t::temp_rsegs[TRX_SYS_N_RSEGS]: A new array of temporary rollback segments. The trx_sys_t::rseg_array[TRX_SYS_N_RSEGS] will be solely for persistent undo logs. srv_tmp_undo_logs. Remove. Use the constant TRX_SYS_N_RSEGS. srv_available_undo_logs: Change the type to ulong. trx_rseg_get_on_id(): Remove. Instead, let the callers refer to trx_sys directly. trx_rseg_create(), trx_sysf_rseg_find_free(): Remove unneeded parameters. These functions only deal with persistent undo logs. trx_temp_rseg_create(): New function, to create all temporary rollback segments at server startup. trx_rseg_t::is_persistent(): Determine if the rollback segment is for persistent tables. trx_sys_is_noredo_rseg_slot(): Remove. The callers must know based on context (such as table handle) whether the DB_ROLL_PTR is referring to a persistent undo log. trx_sys_create_rsegs(): Remove all parameters, which were always passed as global variables. Instead, modify the global variables directly. enum trx_rseg_type_t: Remove. trx_t::get_temp_rseg(): A method to ensure that a temporary rollback segment has been assigned for the transaction. trx_t::assign_temp_rseg(): Replaces trx_assign_rseg(). trx_purge_free_segment(), trx_purge_truncate_rseg_history(): Remove the redundant variable noredo=false. Temporary undo logs are discarded immediately at transaction commit or rollback, not lazily by purge. trx_purge_mark_undo_for_truncate(): Remove references to the temporary rollback segments. trx_purge_mark_undo_for_truncate(): Remove a check for temporary rollback segments. Only the dedicated persistent undo log tablespaces can be truncated. trx_undo_get_undo_rec_low(), trx_undo_get_undo_rec(): Add the parameter is_temp. trx_rseg_mem_restore(): Split from trx_rseg_mem_create(). Initialize the undo log and the rollback segment from the file data structures. trx_sysf_get_n_rseg_slots(): Renamed from trx_sysf_used_slots_for_redo_rseg(). Count the persistent rollback segment headers that have been initialized. trx_sys_close(): Also free trx_sys->temp_rsegs[]. get_next_redo_rseg(): Merged to trx_assign_rseg_low(). trx_assign_rseg_low(): Remove the parameters and access the global variables directly. Revert to simple round-robin, now that the whole trx_sys->rseg_array[] is for persistent undo log again. get_next_noredo_rseg(): Moved to trx_t::assign_temp_rseg(). srv_undo_tablespaces_init(): Remove some parameters and use the global variables directly. Clarify some error messages. Adjust the test innodb.log_file. Apparently, before these changes, InnoDB somehow ignored missing dedicated undo tablespace files that are pointed by the TRX_SYS header page, possibly losing part of essential transaction system state.
9 years ago
MDEV-12266: Change dict_table_t::space to fil_space_t* InnoDB always keeps all tablespaces in the fil_system cache. The fil_system.LRU is only for closing file handles; the fil_space_t and fil_node_t for all data files will remain in main memory. Between startup to shutdown, they can only be created and removed by DDL statements. Therefore, we can let dict_table_t::space point directly to the fil_space_t. dict_table_t::space_id: A numeric tablespace ID for the corner cases where we do not have a tablespace. The most prominent examples are ALTER TABLE...DISCARD TABLESPACE or a missing or corrupted file. There are a few functional differences; most notably: (1) DROP TABLE will delete matching .ibd and .cfg files, even if they were not attached to the data dictionary. (2) Some error messages will report file names instead of numeric IDs. There still are many functions that use numeric tablespace IDs instead of fil_space_t*, and many functions could be converted to fil_space_t member functions. Also, Tablespace and Datafile should be merged with fil_space_t and fil_node_t. page_id_t and buf_page_get_gen() could use fil_space_t& instead of a numeric ID, and after moving to a single buffer pool (MDEV-15058), buf_pool_t::page_hash could be moved to fil_space_t::page_hash. FilSpace: Remove. Only few calls to fil_space_acquire() will remain, and gradually they should be removed. mtr_t::set_named_space_id(ulint): Renamed from set_named_space(), to prevent accidental calls to this slower function. Very few callers remain. fseg_create(), fsp_reserve_free_extents(): Take fil_space_t* as a parameter instead of a space_id. fil_space_t::rename(): Wrapper for fil_rename_tablespace_check(), fil_name_write_rename(), fil_rename_tablespace(). Mariabackup passes the parameter log=false; InnoDB passes log=true. dict_mem_table_create(): Take fil_space_t* instead of space_id as parameter. dict_process_sys_tables_rec_and_mtr_commit(): Replace the parameter 'status' with 'bool cached'. dict_get_and_save_data_dir_path(): Avoid copying the fil_node_t::name. fil_ibd_open(): Return the tablespace. fil_space_t::set_imported(): Replaces fil_space_set_imported(). truncate_t: Change many member function parameters to fil_space_t*, and remove page_size parameters. row_truncate_prepare(): Merge to its only caller. row_drop_table_from_cache(): Assert that the table is persistent. dict_create_sys_indexes_tuple(): Write SYS_INDEXES.SPACE=FIL_NULL if the tablespace has been discarded. row_import_update_discarded_flag(): Remove a constant parameter.
8 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.
9 years ago
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2 InnoDB I/O and buffer pool interfaces and the redo log format have been changed between MariaDB 10.1 and 10.2, and the backup code has to be adjusted accordingly. The code has been simplified, and many memory leaks have been fixed. Instead of the file name xtrabackup_logfile, the file name ib_logfile0 is being used for the copy of the redo log. Unnecessary InnoDB startup and shutdown and some unnecessary threads have been removed. Some help was provided by Vladislav Vaintroub. Parameters have been cleaned up and aligned with those of MariaDB 10.2. The --dbug option has been added, so that in debug builds, --dbug=d,ib_log can be specified to enable diagnostic messages for processing redo log entries. By default, innodb_doublewrite=OFF, so that --prepare works faster. If more crash-safety for --prepare is needed, double buffering can be enabled. The parameter innodb_log_checksums=OFF can be used to ignore redo log checksums in --backup. Some messages have been cleaned up. Unless --export is specified, Mariabackup will not deal with undo log. The InnoDB mini-transaction redo log is not only about user-level transactions; it is actually about mini-transactions. To avoid confusion, call it the redo log, not transaction log. We disable any undo log processing in --prepare. Because MariaDB 10.2 supports indexed virtual columns, the undo log processing would need to be able to evaluate virtual column expressions. To reduce the amount of code dependencies, we will not process any undo log in prepare. This means that the --export option must be disabled for now. This also means that the following options are redundant and have been removed: xtrabackup --apply-log-only innobackupex --redo-only In addition to disabling any undo log processing, we will disable any further changes to data pages during --prepare, including the change buffer merge. This means that restoring incremental backups should reliably work even when change buffering is being used on the server. Because of this, preparing a backup will not generate any further redo log, and the redo log file can be safely deleted. (If the --export option is enabled in the future, it must generate redo log when processing undo logs and buffered changes.) In --prepare, we cannot easily know if a partial backup was used, especially when restoring a series of incremental backups. So, we simply warn about any missing files, and ignore the redo log for them. FIXME: Enable the --export option. FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write a test that initiates a backup while an ALGORITHM=INPLACE operation is creating indexes or rebuilding a table. An error should be detected when preparing the backup. FIXME: In --incremental --prepare, xtrabackup_apply_delta() should ensure that if FSP_SIZE is modified, the file size will be adjusted accordingly.
9 years ago
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2 InnoDB I/O and buffer pool interfaces and the redo log format have been changed between MariaDB 10.1 and 10.2, and the backup code has to be adjusted accordingly. The code has been simplified, and many memory leaks have been fixed. Instead of the file name xtrabackup_logfile, the file name ib_logfile0 is being used for the copy of the redo log. Unnecessary InnoDB startup and shutdown and some unnecessary threads have been removed. Some help was provided by Vladislav Vaintroub. Parameters have been cleaned up and aligned with those of MariaDB 10.2. The --dbug option has been added, so that in debug builds, --dbug=d,ib_log can be specified to enable diagnostic messages for processing redo log entries. By default, innodb_doublewrite=OFF, so that --prepare works faster. If more crash-safety for --prepare is needed, double buffering can be enabled. The parameter innodb_log_checksums=OFF can be used to ignore redo log checksums in --backup. Some messages have been cleaned up. Unless --export is specified, Mariabackup will not deal with undo log. The InnoDB mini-transaction redo log is not only about user-level transactions; it is actually about mini-transactions. To avoid confusion, call it the redo log, not transaction log. We disable any undo log processing in --prepare. Because MariaDB 10.2 supports indexed virtual columns, the undo log processing would need to be able to evaluate virtual column expressions. To reduce the amount of code dependencies, we will not process any undo log in prepare. This means that the --export option must be disabled for now. This also means that the following options are redundant and have been removed: xtrabackup --apply-log-only innobackupex --redo-only In addition to disabling any undo log processing, we will disable any further changes to data pages during --prepare, including the change buffer merge. This means that restoring incremental backups should reliably work even when change buffering is being used on the server. Because of this, preparing a backup will not generate any further redo log, and the redo log file can be safely deleted. (If the --export option is enabled in the future, it must generate redo log when processing undo logs and buffered changes.) In --prepare, we cannot easily know if a partial backup was used, especially when restoring a series of incremental backups. So, we simply warn about any missing files, and ignore the redo log for them. FIXME: Enable the --export option. FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write a test that initiates a backup while an ALGORITHM=INPLACE operation is creating indexes or rebuilding a table. An error should be detected when preparing the backup. FIXME: In --incremental --prepare, xtrabackup_apply_delta() should ensure that if FSP_SIZE is modified, the file size will be adjusted accordingly.
9 years ago
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2 InnoDB I/O and buffer pool interfaces and the redo log format have been changed between MariaDB 10.1 and 10.2, and the backup code has to be adjusted accordingly. The code has been simplified, and many memory leaks have been fixed. Instead of the file name xtrabackup_logfile, the file name ib_logfile0 is being used for the copy of the redo log. Unnecessary InnoDB startup and shutdown and some unnecessary threads have been removed. Some help was provided by Vladislav Vaintroub. Parameters have been cleaned up and aligned with those of MariaDB 10.2. The --dbug option has been added, so that in debug builds, --dbug=d,ib_log can be specified to enable diagnostic messages for processing redo log entries. By default, innodb_doublewrite=OFF, so that --prepare works faster. If more crash-safety for --prepare is needed, double buffering can be enabled. The parameter innodb_log_checksums=OFF can be used to ignore redo log checksums in --backup. Some messages have been cleaned up. Unless --export is specified, Mariabackup will not deal with undo log. The InnoDB mini-transaction redo log is not only about user-level transactions; it is actually about mini-transactions. To avoid confusion, call it the redo log, not transaction log. We disable any undo log processing in --prepare. Because MariaDB 10.2 supports indexed virtual columns, the undo log processing would need to be able to evaluate virtual column expressions. To reduce the amount of code dependencies, we will not process any undo log in prepare. This means that the --export option must be disabled for now. This also means that the following options are redundant and have been removed: xtrabackup --apply-log-only innobackupex --redo-only In addition to disabling any undo log processing, we will disable any further changes to data pages during --prepare, including the change buffer merge. This means that restoring incremental backups should reliably work even when change buffering is being used on the server. Because of this, preparing a backup will not generate any further redo log, and the redo log file can be safely deleted. (If the --export option is enabled in the future, it must generate redo log when processing undo logs and buffered changes.) In --prepare, we cannot easily know if a partial backup was used, especially when restoring a series of incremental backups. So, we simply warn about any missing files, and ignore the redo log for them. FIXME: Enable the --export option. FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write a test that initiates a backup while an ALGORITHM=INPLACE operation is creating indexes or rebuilding a table. An error should be detected when preparing the backup. FIXME: In --incremental --prepare, xtrabackup_apply_delta() should ensure that if FSP_SIZE is modified, the file size will be adjusted accordingly.
9 years ago
MDEV-11782: Redefine the innodb_encrypt_log format Write only one encryption key to the checkpoint page. Use 4 bytes of nonce. Encrypt more of each redo log block, only skipping the 4-byte field LOG_BLOCK_HDR_NO which the initialization vector is derived from. Issue notes, not warning messages for rewriting the redo log files. recv_recovery_from_checkpoint_finish(): Do not generate any redo log, because we must avoid that before rewriting the redo log files, or otherwise a crash during a redo log rewrite (removing or adding encryption) may end up making the database unrecoverable. Instead, do these tasks in innobase_start_or_create_for_mysql(). Issue a firm "Missing MLOG_CHECKPOINT" error message. Remove some unreachable code and duplicated error messages for log corruption. LOG_HEADER_FORMAT_ENCRYPTED: A flag for identifying an encrypted redo log format. log_group_t::is_encrypted(), log_t::is_encrypted(): Determine if the redo log is in encrypted format. recv_find_max_checkpoint(): Interpret LOG_HEADER_FORMAT_ENCRYPTED. srv_prepare_to_delete_redo_log_files(): Display NOTE messages about adding or removing encryption. Do not issue warnings for redo log resizing any more. innobase_start_or_create_for_mysql(): Rebuild the redo logs also when the encryption changes. innodb_log_checksums_func_update(): Always use the CRC-32C checksum if innodb_encrypt_log. If needed, issue a warning that innodb_encrypt_log implies innodb_log_checksums. log_group_write_buf(): Compute the checksum on the encrypted block contents, so that transmission errors or incomplete blocks can be detected without decrypting. Rewrite most of the redo log encryption code. Only remember one encryption key at a time (but remember up to 5 when upgrading from the MariaDB 10.1 format.)
9 years ago
MDEV-14717: Prevent crash-downgrade to earlier MariaDB 10.2 A crash-downgrade of a RENAME (or TRUNCATE or table-rebuilding ALTER TABLE or OPTIMIZE TABLE) operation to an earlier 10.2 version would trigger a debug assertion failure during rollback, in trx_roll_pop_top_rec_of_trx(). In a non-debug build, the TRX_UNDO_RENAME_TABLE record would be misinterpreted as an update_undo log record, and typically the file name would be interpreted as DB_TRX_ID,DB_ROLL_PTR,PRIMARY KEY. If a matching record would be found, row_undo_mod() would hit ut_error in switch (node->rec_type). Typically, ut_a(table2 == NULL) would fail when opening the table from SQL. Because of this, we prevent a crash-downgrade to earlier MariaDB 10.2 versions by changing the InnoDB redo log format identifier to the 10.3 identifier, and by introducing a subformat identifier so that 10.2 can continue to refuse crash-downgrade from 10.3 or later. After a clean shutdown, a downgrade to MariaDB 10.2.13 or later would still be possible thanks to MDEV-14909. A downgrade to older 10.2 versions is only possible after removing the log files (not recommended). LOG_HEADER_FORMAT_CURRENT: Change to 103 (originally the 10.3 format). log_group_t: Add subformat. For 10.2, we will use subformat 1, and will refuse crash recovery from any other subformat of the 10.3 format, that is, a genuine 10.3 redo log. recv_find_max_checkpoint(): Allow startup after clean shutdown from a future LOG_HEADER_FORMAT_10_4 (unencrypted only). We cannot handle the encrypted 10.4 redo log block format, which was introduced in MDEV-12041. Allow crash recovery from the original 10.2 format as well as the new format. In Mariabackup --backup, do not allow any startup from 10.3 or 10.4 redo logs. recv_recovery_from_checkpoint_start(): Skip redo log apply for clean 10.3 redo log, but not for the new 10.2 redo log (10.3 format, subformat 1). srv_prepare_to_delete_redo_log_files(): On format or subformat mismatch, set srv_log_file_size = 0, so that we will display the correct message. innobase_start_or_create_for_mysql(): Check for format or subformat mismatch. xtrabackup_backup_func(): Remove debug assertions that were made redundant by the code changes in recv_find_max_checkpoint().
7 years ago
MDEV-11782: Redefine the innodb_encrypt_log format Write only one encryption key to the checkpoint page. Use 4 bytes of nonce. Encrypt more of each redo log block, only skipping the 4-byte field LOG_BLOCK_HDR_NO which the initialization vector is derived from. Issue notes, not warning messages for rewriting the redo log files. recv_recovery_from_checkpoint_finish(): Do not generate any redo log, because we must avoid that before rewriting the redo log files, or otherwise a crash during a redo log rewrite (removing or adding encryption) may end up making the database unrecoverable. Instead, do these tasks in innobase_start_or_create_for_mysql(). Issue a firm "Missing MLOG_CHECKPOINT" error message. Remove some unreachable code and duplicated error messages for log corruption. LOG_HEADER_FORMAT_ENCRYPTED: A flag for identifying an encrypted redo log format. log_group_t::is_encrypted(), log_t::is_encrypted(): Determine if the redo log is in encrypted format. recv_find_max_checkpoint(): Interpret LOG_HEADER_FORMAT_ENCRYPTED. srv_prepare_to_delete_redo_log_files(): Display NOTE messages about adding or removing encryption. Do not issue warnings for redo log resizing any more. innobase_start_or_create_for_mysql(): Rebuild the redo logs also when the encryption changes. innodb_log_checksums_func_update(): Always use the CRC-32C checksum if innodb_encrypt_log. If needed, issue a warning that innodb_encrypt_log implies innodb_log_checksums. log_group_write_buf(): Compute the checksum on the encrypted block contents, so that transmission errors or incomplete blocks can be detected without decrypting. Rewrite most of the redo log encryption code. Only remember one encryption key at a time (but remember up to 5 when upgrading from the MariaDB 10.1 format.)
9 years ago
MDEV-11782: Redefine the innodb_encrypt_log format Write only one encryption key to the checkpoint page. Use 4 bytes of nonce. Encrypt more of each redo log block, only skipping the 4-byte field LOG_BLOCK_HDR_NO which the initialization vector is derived from. Issue notes, not warning messages for rewriting the redo log files. recv_recovery_from_checkpoint_finish(): Do not generate any redo log, because we must avoid that before rewriting the redo log files, or otherwise a crash during a redo log rewrite (removing or adding encryption) may end up making the database unrecoverable. Instead, do these tasks in innobase_start_or_create_for_mysql(). Issue a firm "Missing MLOG_CHECKPOINT" error message. Remove some unreachable code and duplicated error messages for log corruption. LOG_HEADER_FORMAT_ENCRYPTED: A flag for identifying an encrypted redo log format. log_group_t::is_encrypted(), log_t::is_encrypted(): Determine if the redo log is in encrypted format. recv_find_max_checkpoint(): Interpret LOG_HEADER_FORMAT_ENCRYPTED. srv_prepare_to_delete_redo_log_files(): Display NOTE messages about adding or removing encryption. Do not issue warnings for redo log resizing any more. innobase_start_or_create_for_mysql(): Rebuild the redo logs also when the encryption changes. innodb_log_checksums_func_update(): Always use the CRC-32C checksum if innodb_encrypt_log. If needed, issue a warning that innodb_encrypt_log implies innodb_log_checksums. log_group_write_buf(): Compute the checksum on the encrypted block contents, so that transmission errors or incomplete blocks can be detected without decrypting. Rewrite most of the redo log encryption code. Only remember one encryption key at a time (but remember up to 5 when upgrading from the MariaDB 10.1 format.)
9 years ago
MDEV-11782: Redefine the innodb_encrypt_log format Write only one encryption key to the checkpoint page. Use 4 bytes of nonce. Encrypt more of each redo log block, only skipping the 4-byte field LOG_BLOCK_HDR_NO which the initialization vector is derived from. Issue notes, not warning messages for rewriting the redo log files. recv_recovery_from_checkpoint_finish(): Do not generate any redo log, because we must avoid that before rewriting the redo log files, or otherwise a crash during a redo log rewrite (removing or adding encryption) may end up making the database unrecoverable. Instead, do these tasks in innobase_start_or_create_for_mysql(). Issue a firm "Missing MLOG_CHECKPOINT" error message. Remove some unreachable code and duplicated error messages for log corruption. LOG_HEADER_FORMAT_ENCRYPTED: A flag for identifying an encrypted redo log format. log_group_t::is_encrypted(), log_t::is_encrypted(): Determine if the redo log is in encrypted format. recv_find_max_checkpoint(): Interpret LOG_HEADER_FORMAT_ENCRYPTED. srv_prepare_to_delete_redo_log_files(): Display NOTE messages about adding or removing encryption. Do not issue warnings for redo log resizing any more. innobase_start_or_create_for_mysql(): Rebuild the redo logs also when the encryption changes. innodb_log_checksums_func_update(): Always use the CRC-32C checksum if innodb_encrypt_log. If needed, issue a warning that innodb_encrypt_log implies innodb_log_checksums. log_group_write_buf(): Compute the checksum on the encrypted block contents, so that transmission errors or incomplete blocks can be detected without decrypting. Rewrite most of the redo log encryption code. Only remember one encryption key at a time (but remember up to 5 when upgrading from the MariaDB 10.1 format.)
9 years ago
MDEV-11782: Redefine the innodb_encrypt_log format Write only one encryption key to the checkpoint page. Use 4 bytes of nonce. Encrypt more of each redo log block, only skipping the 4-byte field LOG_BLOCK_HDR_NO which the initialization vector is derived from. Issue notes, not warning messages for rewriting the redo log files. recv_recovery_from_checkpoint_finish(): Do not generate any redo log, because we must avoid that before rewriting the redo log files, or otherwise a crash during a redo log rewrite (removing or adding encryption) may end up making the database unrecoverable. Instead, do these tasks in innobase_start_or_create_for_mysql(). Issue a firm "Missing MLOG_CHECKPOINT" error message. Remove some unreachable code and duplicated error messages for log corruption. LOG_HEADER_FORMAT_ENCRYPTED: A flag for identifying an encrypted redo log format. log_group_t::is_encrypted(), log_t::is_encrypted(): Determine if the redo log is in encrypted format. recv_find_max_checkpoint(): Interpret LOG_HEADER_FORMAT_ENCRYPTED. srv_prepare_to_delete_redo_log_files(): Display NOTE messages about adding or removing encryption. Do not issue warnings for redo log resizing any more. innobase_start_or_create_for_mysql(): Rebuild the redo logs also when the encryption changes. innodb_log_checksums_func_update(): Always use the CRC-32C checksum if innodb_encrypt_log. If needed, issue a warning that innodb_encrypt_log implies innodb_log_checksums. log_group_write_buf(): Compute the checksum on the encrypted block contents, so that transmission errors or incomplete blocks can be detected without decrypting. Rewrite most of the redo log encryption code. Only remember one encryption key at a time (but remember up to 5 when upgrading from the MariaDB 10.1 format.)
9 years ago
MDEV-11782: Redefine the innodb_encrypt_log format Write only one encryption key to the checkpoint page. Use 4 bytes of nonce. Encrypt more of each redo log block, only skipping the 4-byte field LOG_BLOCK_HDR_NO which the initialization vector is derived from. Issue notes, not warning messages for rewriting the redo log files. recv_recovery_from_checkpoint_finish(): Do not generate any redo log, because we must avoid that before rewriting the redo log files, or otherwise a crash during a redo log rewrite (removing or adding encryption) may end up making the database unrecoverable. Instead, do these tasks in innobase_start_or_create_for_mysql(). Issue a firm "Missing MLOG_CHECKPOINT" error message. Remove some unreachable code and duplicated error messages for log corruption. LOG_HEADER_FORMAT_ENCRYPTED: A flag for identifying an encrypted redo log format. log_group_t::is_encrypted(), log_t::is_encrypted(): Determine if the redo log is in encrypted format. recv_find_max_checkpoint(): Interpret LOG_HEADER_FORMAT_ENCRYPTED. srv_prepare_to_delete_redo_log_files(): Display NOTE messages about adding or removing encryption. Do not issue warnings for redo log resizing any more. innobase_start_or_create_for_mysql(): Rebuild the redo logs also when the encryption changes. innodb_log_checksums_func_update(): Always use the CRC-32C checksum if innodb_encrypt_log. If needed, issue a warning that innodb_encrypt_log implies innodb_log_checksums. log_group_write_buf(): Compute the checksum on the encrypted block contents, so that transmission errors or incomplete blocks can be detected without decrypting. Rewrite most of the redo log encryption code. Only remember one encryption key at a time (but remember up to 5 when upgrading from the MariaDB 10.1 format.)
9 years ago
MDEV-11782: Redefine the innodb_encrypt_log format Write only one encryption key to the checkpoint page. Use 4 bytes of nonce. Encrypt more of each redo log block, only skipping the 4-byte field LOG_BLOCK_HDR_NO which the initialization vector is derived from. Issue notes, not warning messages for rewriting the redo log files. recv_recovery_from_checkpoint_finish(): Do not generate any redo log, because we must avoid that before rewriting the redo log files, or otherwise a crash during a redo log rewrite (removing or adding encryption) may end up making the database unrecoverable. Instead, do these tasks in innobase_start_or_create_for_mysql(). Issue a firm "Missing MLOG_CHECKPOINT" error message. Remove some unreachable code and duplicated error messages for log corruption. LOG_HEADER_FORMAT_ENCRYPTED: A flag for identifying an encrypted redo log format. log_group_t::is_encrypted(), log_t::is_encrypted(): Determine if the redo log is in encrypted format. recv_find_max_checkpoint(): Interpret LOG_HEADER_FORMAT_ENCRYPTED. srv_prepare_to_delete_redo_log_files(): Display NOTE messages about adding or removing encryption. Do not issue warnings for redo log resizing any more. innobase_start_or_create_for_mysql(): Rebuild the redo logs also when the encryption changes. innodb_log_checksums_func_update(): Always use the CRC-32C checksum if innodb_encrypt_log. If needed, issue a warning that innodb_encrypt_log implies innodb_log_checksums. log_group_write_buf(): Compute the checksum on the encrypted block contents, so that transmission errors or incomplete blocks can be detected without decrypting. Rewrite most of the redo log encryption code. Only remember one encryption key at a time (but remember up to 5 when upgrading from the MariaDB 10.1 format.)
9 years ago
MDEV-11782: Redefine the innodb_encrypt_log format Write only one encryption key to the checkpoint page. Use 4 bytes of nonce. Encrypt more of each redo log block, only skipping the 4-byte field LOG_BLOCK_HDR_NO which the initialization vector is derived from. Issue notes, not warning messages for rewriting the redo log files. recv_recovery_from_checkpoint_finish(): Do not generate any redo log, because we must avoid that before rewriting the redo log files, or otherwise a crash during a redo log rewrite (removing or adding encryption) may end up making the database unrecoverable. Instead, do these tasks in innobase_start_or_create_for_mysql(). Issue a firm "Missing MLOG_CHECKPOINT" error message. Remove some unreachable code and duplicated error messages for log corruption. LOG_HEADER_FORMAT_ENCRYPTED: A flag for identifying an encrypted redo log format. log_group_t::is_encrypted(), log_t::is_encrypted(): Determine if the redo log is in encrypted format. recv_find_max_checkpoint(): Interpret LOG_HEADER_FORMAT_ENCRYPTED. srv_prepare_to_delete_redo_log_files(): Display NOTE messages about adding or removing encryption. Do not issue warnings for redo log resizing any more. innobase_start_or_create_for_mysql(): Rebuild the redo logs also when the encryption changes. innodb_log_checksums_func_update(): Always use the CRC-32C checksum if innodb_encrypt_log. If needed, issue a warning that innodb_encrypt_log implies innodb_log_checksums. log_group_write_buf(): Compute the checksum on the encrypted block contents, so that transmission errors or incomplete blocks can be detected without decrypting. Rewrite most of the redo log encryption code. Only remember one encryption key at a time (but remember up to 5 when upgrading from the MariaDB 10.1 format.)
9 years ago
MDEV-19514 Defer change buffer merge until pages are requested We will remove the InnoDB background operation of merging buffered changes to secondary index leaf pages. Changes will only be merged as a result of an operation that accesses a secondary index leaf page, such as a SQL statement that performs a lookup via that index, or is modifying the index. Also ROLLBACK and some background operations, such as purging the history of committed transactions, or computing index cardinality statistics, can cause change buffer merge. Encryption key rotation will not perform change buffer merge. The motivation of this change is to simplify the I/O logic and to allow crash recovery to happen in the background (MDEV-14481). We also hope that this will reduce the number of "mystery" crashes due to corrupted data. Because change buffer merge will typically take place as a result of executing SQL statements, there should be a clearer connection between the crash and the SQL statements that were executed when the server crashed. In many cases, a slight performance improvement was observed. This is joint work with Thirunarayanan Balathandayuthapani and was tested by Axel Schwenke and Matthias Leich. The InnoDB monitor counter innodb_ibuf_merge_usec will be removed. On slow shutdown (innodb_fast_shutdown=0), we will continue to merge all buffered changes (and purge all undo log history). Two InnoDB configuration parameters will be changed as follows: innodb_disable_background_merge: Removed. This parameter existed only in debug builds. All change buffer merges will use synchronous reads. innodb_force_recovery will be changed as follows: * innodb_force_recovery=4 will be the same as innodb_force_recovery=3 (the change buffer merge cannot be disabled; it can only happen as a result of an operation that accesses a secondary index leaf page). The option used to be capable of corrupting secondary index leaf pages. Now that capability is removed, and innodb_force_recovery=4 becomes 'safe'. * innodb_force_recovery=5 (which essentially hard-wires SET GLOBAL TRANSACTION ISOLATION LEVEL READ UNCOMMITTED) becomes safe to use. Bogus data can be returned to SQL, but persistent InnoDB data files will not be corrupted further. * innodb_force_recovery=6 (ignore the redo log files) will be the only option that can potentially cause persistent corruption of InnoDB data files. Code changes: buf_page_t::ibuf_exist: New flag, to indicate whether buffered changes exist for a buffer pool page. Pages with pending changes can be returned by buf_page_get_gen(). Previously, the changes were always merged inside buf_page_get_gen() if needed. ibuf_page_exists(const buf_page_t&): Check if a buffered changes exist for an X-latched or read-fixed page. buf_page_get_gen(): Add the parameter allow_ibuf_merge=false. All callers that know that they may be accessing a secondary index leaf page must pass this parameter as allow_ibuf_merge=true, unless it does not matter for that caller whether all buffered changes have been applied. Assert that whenever allow_ibuf_merge holds, the page actually is a leaf page. Attempt change buffer merge only to secondary B-tree index leaf pages. btr_block_get(): Add parameter 'bool merge'. All callers of btr_block_get() should know whether the page could be a secondary index leaf page. If it is not, we should avoid consulting the change buffer bitmap to even consider a merge. This is the main interface to requesting index pages from the buffer pool. ibuf_merge_or_delete_for_page(), recv_recover_page(): Replace buf_page_get_known_nowait() with much simpler logic, because it is now guaranteed that that the block is x-latched or read-fixed. mlog_init_t::mark_ibuf_exist(): Renamed from mlog_init_t::ibuf_merge(). On crash recovery, we will no longer merge any buffered changes for the pages that we read into the buffer pool during the last batch of applying log records. buf_page_get_gen_known_nowait(), BUF_MAKE_YOUNG, BUF_KEEP_OLD: Remove. btr_search_guess_on_hash(): Merge buf_page_get_gen_known_nowait() to its only remaining caller. buf_page_make_young_if_needed(): Define as an inline function. Add the parameter buf_pool. buf_page_peek_if_young(), buf_page_peek_if_too_old(): Add the parameter buf_pool. fil_space_validate_for_mtr_commit(): Remove a bogus comment about background merge of the change buffer. btr_cur_open_at_rnd_pos_func(), btr_cur_search_to_nth_level_func(), btr_cur_open_at_index_side_func(): Use narrower data types and scopes. ibuf_read_merge_pages(): Replaces buf_read_ibuf_merge_pages(). Merge the change buffer by invoking buf_page_get_gen().
6 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-19514 Defer change buffer merge until pages are requested We will remove the InnoDB background operation of merging buffered changes to secondary index leaf pages. Changes will only be merged as a result of an operation that accesses a secondary index leaf page, such as a SQL statement that performs a lookup via that index, or is modifying the index. Also ROLLBACK and some background operations, such as purging the history of committed transactions, or computing index cardinality statistics, can cause change buffer merge. Encryption key rotation will not perform change buffer merge. The motivation of this change is to simplify the I/O logic and to allow crash recovery to happen in the background (MDEV-14481). We also hope that this will reduce the number of "mystery" crashes due to corrupted data. Because change buffer merge will typically take place as a result of executing SQL statements, there should be a clearer connection between the crash and the SQL statements that were executed when the server crashed. In many cases, a slight performance improvement was observed. This is joint work with Thirunarayanan Balathandayuthapani and was tested by Axel Schwenke and Matthias Leich. The InnoDB monitor counter innodb_ibuf_merge_usec will be removed. On slow shutdown (innodb_fast_shutdown=0), we will continue to merge all buffered changes (and purge all undo log history). Two InnoDB configuration parameters will be changed as follows: innodb_disable_background_merge: Removed. This parameter existed only in debug builds. All change buffer merges will use synchronous reads. innodb_force_recovery will be changed as follows: * innodb_force_recovery=4 will be the same as innodb_force_recovery=3 (the change buffer merge cannot be disabled; it can only happen as a result of an operation that accesses a secondary index leaf page). The option used to be capable of corrupting secondary index leaf pages. Now that capability is removed, and innodb_force_recovery=4 becomes 'safe'. * innodb_force_recovery=5 (which essentially hard-wires SET GLOBAL TRANSACTION ISOLATION LEVEL READ UNCOMMITTED) becomes safe to use. Bogus data can be returned to SQL, but persistent InnoDB data files will not be corrupted further. * innodb_force_recovery=6 (ignore the redo log files) will be the only option that can potentially cause persistent corruption of InnoDB data files. Code changes: buf_page_t::ibuf_exist: New flag, to indicate whether buffered changes exist for a buffer pool page. Pages with pending changes can be returned by buf_page_get_gen(). Previously, the changes were always merged inside buf_page_get_gen() if needed. ibuf_page_exists(const buf_page_t&): Check if a buffered changes exist for an X-latched or read-fixed page. buf_page_get_gen(): Add the parameter allow_ibuf_merge=false. All callers that know that they may be accessing a secondary index leaf page must pass this parameter as allow_ibuf_merge=true, unless it does not matter for that caller whether all buffered changes have been applied. Assert that whenever allow_ibuf_merge holds, the page actually is a leaf page. Attempt change buffer merge only to secondary B-tree index leaf pages. btr_block_get(): Add parameter 'bool merge'. All callers of btr_block_get() should know whether the page could be a secondary index leaf page. If it is not, we should avoid consulting the change buffer bitmap to even consider a merge. This is the main interface to requesting index pages from the buffer pool. ibuf_merge_or_delete_for_page(), recv_recover_page(): Replace buf_page_get_known_nowait() with much simpler logic, because it is now guaranteed that that the block is x-latched or read-fixed. mlog_init_t::mark_ibuf_exist(): Renamed from mlog_init_t::ibuf_merge(). On crash recovery, we will no longer merge any buffered changes for the pages that we read into the buffer pool during the last batch of applying log records. buf_page_get_gen_known_nowait(), BUF_MAKE_YOUNG, BUF_KEEP_OLD: Remove. btr_search_guess_on_hash(): Merge buf_page_get_gen_known_nowait() to its only remaining caller. buf_page_make_young_if_needed(): Define as an inline function. Add the parameter buf_pool. buf_page_peek_if_young(), buf_page_peek_if_too_old(): Add the parameter buf_pool. fil_space_validate_for_mtr_commit(): Remove a bogus comment about background merge of the change buffer. btr_cur_open_at_rnd_pos_func(), btr_cur_search_to_nth_level_func(), btr_cur_open_at_index_side_func(): Use narrower data types and scopes. ibuf_read_merge_pages(): Replaces buf_read_ibuf_merge_pages(). Merge the change buffer by invoking buf_page_get_gen().
6 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
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
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
9 years ago
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2 InnoDB I/O and buffer pool interfaces and the redo log format have been changed between MariaDB 10.1 and 10.2, and the backup code has to be adjusted accordingly. The code has been simplified, and many memory leaks have been fixed. Instead of the file name xtrabackup_logfile, the file name ib_logfile0 is being used for the copy of the redo log. Unnecessary InnoDB startup and shutdown and some unnecessary threads have been removed. Some help was provided by Vladislav Vaintroub. Parameters have been cleaned up and aligned with those of MariaDB 10.2. The --dbug option has been added, so that in debug builds, --dbug=d,ib_log can be specified to enable diagnostic messages for processing redo log entries. By default, innodb_doublewrite=OFF, so that --prepare works faster. If more crash-safety for --prepare is needed, double buffering can be enabled. The parameter innodb_log_checksums=OFF can be used to ignore redo log checksums in --backup. Some messages have been cleaned up. Unless --export is specified, Mariabackup will not deal with undo log. The InnoDB mini-transaction redo log is not only about user-level transactions; it is actually about mini-transactions. To avoid confusion, call it the redo log, not transaction log. We disable any undo log processing in --prepare. Because MariaDB 10.2 supports indexed virtual columns, the undo log processing would need to be able to evaluate virtual column expressions. To reduce the amount of code dependencies, we will not process any undo log in prepare. This means that the --export option must be disabled for now. This also means that the following options are redundant and have been removed: xtrabackup --apply-log-only innobackupex --redo-only In addition to disabling any undo log processing, we will disable any further changes to data pages during --prepare, including the change buffer merge. This means that restoring incremental backups should reliably work even when change buffering is being used on the server. Because of this, preparing a backup will not generate any further redo log, and the redo log file can be safely deleted. (If the --export option is enabled in the future, it must generate redo log when processing undo logs and buffered changes.) In --prepare, we cannot easily know if a partial backup was used, especially when restoring a series of incremental backups. So, we simply warn about any missing files, and ignore the redo log for them. FIXME: Enable the --export option. FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write a test that initiates a backup while an ALGORITHM=INPLACE operation is creating indexes or rebuilding a table. An error should be detected when preparing the backup. FIXME: In --incremental --prepare, xtrabackup_apply_delta() should ensure that if FSP_SIZE is modified, the file size will be adjusted accordingly.
9 years ago
MDEV-13039 innodb_fast_shutdown=0 may fail to purge all undo log When a slow shutdown is performed soon after spawning some work for background threads that can create or commit transactions, it is possible that new transactions are started or committed after the purge has finished. This is violating the specification of innodb_fast_shutdown=0, namely that the purge must be completed. (None of the history of the recent transactions would be purged.) Also, it is possible that the purge threads would exit in slow shutdown while there exist active transactions, such as recovered incomplete transactions that are being rolled back. Thus, the slow shutdown could fail to purge some undo log that becomes purgeable after the transaction commit or rollback. srv_undo_sources: A flag that indicates if undo log can be generated or the persistent, whether by background threads or by user SQL. Even when this flag is clear, active transactions that already exist in the system may be committed or rolled back. innodb_shutdown(): Renamed from innobase_shutdown_for_mysql(). Do not return an error code; the operation never fails. Clear the srv_undo_sources flag, and also ensure that the background DROP TABLE queue is empty. srv_purge_should_exit(): Do not allow the purge to exit if srv_undo_sources are active or the background DROP TABLE queue is not empty, or in slow shutdown, if any active transactions exist (and are being rolled back). srv_purge_coordinator_thread(): Remove some previous workarounds for this bug. innobase_start_or_create_for_mysql(): Set buf_page_cleaner_is_active and srv_dict_stats_thread_active directly. Set srv_undo_sources before starting the purge subsystem, to prevent immediate shutdown of the purge. Create dict_stats_thread and fts_optimize_thread immediately after setting srv_undo_sources, so that shutdown can use this flag to determine if these subsystems were started. dict_stats_shutdown(): Shut down dict_stats_thread. Backported from 10.2. srv_shutdown_table_bg_threads(): Remove (unused).
9 years ago
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2 InnoDB I/O and buffer pool interfaces and the redo log format have been changed between MariaDB 10.1 and 10.2, and the backup code has to be adjusted accordingly. The code has been simplified, and many memory leaks have been fixed. Instead of the file name xtrabackup_logfile, the file name ib_logfile0 is being used for the copy of the redo log. Unnecessary InnoDB startup and shutdown and some unnecessary threads have been removed. Some help was provided by Vladislav Vaintroub. Parameters have been cleaned up and aligned with those of MariaDB 10.2. The --dbug option has been added, so that in debug builds, --dbug=d,ib_log can be specified to enable diagnostic messages for processing redo log entries. By default, innodb_doublewrite=OFF, so that --prepare works faster. If more crash-safety for --prepare is needed, double buffering can be enabled. The parameter innodb_log_checksums=OFF can be used to ignore redo log checksums in --backup. Some messages have been cleaned up. Unless --export is specified, Mariabackup will not deal with undo log. The InnoDB mini-transaction redo log is not only about user-level transactions; it is actually about mini-transactions. To avoid confusion, call it the redo log, not transaction log. We disable any undo log processing in --prepare. Because MariaDB 10.2 supports indexed virtual columns, the undo log processing would need to be able to evaluate virtual column expressions. To reduce the amount of code dependencies, we will not process any undo log in prepare. This means that the --export option must be disabled for now. This also means that the following options are redundant and have been removed: xtrabackup --apply-log-only innobackupex --redo-only In addition to disabling any undo log processing, we will disable any further changes to data pages during --prepare, including the change buffer merge. This means that restoring incremental backups should reliably work even when change buffering is being used on the server. Because of this, preparing a backup will not generate any further redo log, and the redo log file can be safely deleted. (If the --export option is enabled in the future, it must generate redo log when processing undo logs and buffered changes.) In --prepare, we cannot easily know if a partial backup was used, especially when restoring a series of incremental backups. So, we simply warn about any missing files, and ignore the redo log for them. FIXME: Enable the --export option. FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write a test that initiates a backup while an ALGORITHM=INPLACE operation is creating indexes or rebuilding a table. An error should be detected when preparing the backup. FIXME: In --incremental --prepare, xtrabackup_apply_delta() should ensure that if FSP_SIZE is modified, the file size will be adjusted accordingly.
9 years ago
MDEV-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
7 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
MDEV-13039 innodb_fast_shutdown=0 may fail to purge all undo log When a slow shutdown is performed soon after spawning some work for background threads that can create or commit transactions, it is possible that new transactions are started or committed after the purge has finished. This is violating the specification of innodb_fast_shutdown=0, namely that the purge must be completed. (None of the history of the recent transactions would be purged.) Also, it is possible that the purge threads would exit in slow shutdown while there exist active transactions, such as recovered incomplete transactions that are being rolled back. Thus, the slow shutdown could fail to purge some undo log that becomes purgeable after the transaction commit or rollback. srv_undo_sources: A flag that indicates if undo log can be generated or the persistent, whether by background threads or by user SQL. Even when this flag is clear, active transactions that already exist in the system may be committed or rolled back. innodb_shutdown(): Renamed from innobase_shutdown_for_mysql(). Do not return an error code; the operation never fails. Clear the srv_undo_sources flag, and also ensure that the background DROP TABLE queue is empty. srv_purge_should_exit(): Do not allow the purge to exit if srv_undo_sources are active or the background DROP TABLE queue is not empty, or in slow shutdown, if any active transactions exist (and are being rolled back). srv_purge_coordinator_thread(): Remove some previous workarounds for this bug. innobase_start_or_create_for_mysql(): Set buf_page_cleaner_is_active and srv_dict_stats_thread_active directly. Set srv_undo_sources before starting the purge subsystem, to prevent immediate shutdown of the purge. Create dict_stats_thread and fts_optimize_thread immediately after setting srv_undo_sources, so that shutdown can use this flag to determine if these subsystems were started. dict_stats_shutdown(): Shut down dict_stats_thread. Backported from 10.2. srv_shutdown_table_bg_threads(): Remove (unused).
9 years ago
Shut down InnoDB after aborted startup. This fixes memory leaks in tests that cause InnoDB startup to fail. buf_pool_free_instance(): Also free buf_pool->flush_rbt, which would normally be freed when crash recovery finishes. fil_node_close_file(), fil_space_free_low(), fil_close_all_files(): Relax some debug assertions to tolerate !srv_was_started. innodb_shutdown(): Renamed from innobase_shutdown_for_mysql(). Changed the return type to void. Do not assume that all subsystems were started. que_init(), que_close(): Remove (empty functions). srv_init(), srv_general_init(): Remove as global functions. srv_free(): Allow srv_sys=NULL. srv_get_active_thread_type(): Only return SRV_PURGE if purge really is running. srv_shutdown_all_bg_threads(): Do not reset srv_start_state. It will be needed by innodb_shutdown(). innobase_start_or_create_for_mysql(): Always call srv_boot() so that innodb_shutdown() can assume that it was called. Make more subsystems dependent on SRV_START_STATE_STAT. srv_shutdown_bg_undo_sources(): Require SRV_START_STATE_STAT. trx_sys_close(): Do not assume purge_sys!=NULL. Do not call buf_dblwr_free(), because the doublewrite buffer can exist while the transaction system does not. logs_empty_and_mark_files_at_shutdown(): Do a faster shutdown if !srv_was_started. recv_sys_close(): Invoke dblwr.pages.clear() which would normally be invoked by buf_dblwr_process(). recv_recovery_from_checkpoint_start(): Always release log_sys->mutex. row_mysql_close(): Allow the subsystem not to exist.
9 years ago
MDEV-13039 innodb_fast_shutdown=0 may fail to purge all undo log When a slow shutdown is performed soon after spawning some work for background threads that can create or commit transactions, it is possible that new transactions are started or committed after the purge has finished. This is violating the specification of innodb_fast_shutdown=0, namely that the purge must be completed. (None of the history of the recent transactions would be purged.) Also, it is possible that the purge threads would exit in slow shutdown while there exist active transactions, such as recovered incomplete transactions that are being rolled back. Thus, the slow shutdown could fail to purge some undo log that becomes purgeable after the transaction commit or rollback. srv_undo_sources: A flag that indicates if undo log can be generated or the persistent, whether by background threads or by user SQL. Even when this flag is clear, active transactions that already exist in the system may be committed or rolled back. innodb_shutdown(): Renamed from innobase_shutdown_for_mysql(). Do not return an error code; the operation never fails. Clear the srv_undo_sources flag, and also ensure that the background DROP TABLE queue is empty. srv_purge_should_exit(): Do not allow the purge to exit if srv_undo_sources are active or the background DROP TABLE queue is not empty, or in slow shutdown, if any active transactions exist (and are being rolled back). srv_purge_coordinator_thread(): Remove some previous workarounds for this bug. innobase_start_or_create_for_mysql(): Set buf_page_cleaner_is_active and srv_dict_stats_thread_active directly. Set srv_undo_sources before starting the purge subsystem, to prevent immediate shutdown of the purge. Create dict_stats_thread and fts_optimize_thread immediately after setting srv_undo_sources, so that shutdown can use this flag to determine if these subsystems were started. dict_stats_shutdown(): Shut down dict_stats_thread. Backported from 10.2. srv_shutdown_table_bg_threads(): Remove (unused).
9 years ago
Shut down InnoDB after aborted startup. This fixes memory leaks in tests that cause InnoDB startup to fail. buf_pool_free_instance(): Also free buf_pool->flush_rbt, which would normally be freed when crash recovery finishes. fil_node_close_file(), fil_space_free_low(), fil_close_all_files(): Relax some debug assertions to tolerate !srv_was_started. innodb_shutdown(): Renamed from innobase_shutdown_for_mysql(). Changed the return type to void. Do not assume that all subsystems were started. que_init(), que_close(): Remove (empty functions). srv_init(), srv_general_init(): Remove as global functions. srv_free(): Allow srv_sys=NULL. srv_get_active_thread_type(): Only return SRV_PURGE if purge really is running. srv_shutdown_all_bg_threads(): Do not reset srv_start_state. It will be needed by innodb_shutdown(). innobase_start_or_create_for_mysql(): Always call srv_boot() so that innodb_shutdown() can assume that it was called. Make more subsystems dependent on SRV_START_STATE_STAT. srv_shutdown_bg_undo_sources(): Require SRV_START_STATE_STAT. trx_sys_close(): Do not assume purge_sys!=NULL. Do not call buf_dblwr_free(), because the doublewrite buffer can exist while the transaction system does not. logs_empty_and_mark_files_at_shutdown(): Do a faster shutdown if !srv_was_started. recv_sys_close(): Invoke dblwr.pages.clear() which would normally be invoked by buf_dblwr_process(). recv_recovery_from_checkpoint_start(): Always release log_sys->mutex. row_mysql_close(): Allow the subsystem not to exist.
9 years ago
Shut down InnoDB after aborted startup. This fixes memory leaks in tests that cause InnoDB startup to fail. buf_pool_free_instance(): Also free buf_pool->flush_rbt, which would normally be freed when crash recovery finishes. fil_node_close_file(), fil_space_free_low(), fil_close_all_files(): Relax some debug assertions to tolerate !srv_was_started. innodb_shutdown(): Renamed from innobase_shutdown_for_mysql(). Changed the return type to void. Do not assume that all subsystems were started. que_init(), que_close(): Remove (empty functions). srv_init(), srv_general_init(): Remove as global functions. srv_free(): Allow srv_sys=NULL. srv_get_active_thread_type(): Only return SRV_PURGE if purge really is running. srv_shutdown_all_bg_threads(): Do not reset srv_start_state. It will be needed by innodb_shutdown(). innobase_start_or_create_for_mysql(): Always call srv_boot() so that innodb_shutdown() can assume that it was called. Make more subsystems dependent on SRV_START_STATE_STAT. srv_shutdown_bg_undo_sources(): Require SRV_START_STATE_STAT. trx_sys_close(): Do not assume purge_sys!=NULL. Do not call buf_dblwr_free(), because the doublewrite buffer can exist while the transaction system does not. logs_empty_and_mark_files_at_shutdown(): Do a faster shutdown if !srv_was_started. recv_sys_close(): Invoke dblwr.pages.clear() which would normally be invoked by buf_dblwr_process(). recv_recovery_from_checkpoint_start(): Always release log_sys->mutex. row_mysql_close(): Allow the subsystem not to exist.
9 years ago
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2 InnoDB I/O and buffer pool interfaces and the redo log format have been changed between MariaDB 10.1 and 10.2, and the backup code has to be adjusted accordingly. The code has been simplified, and many memory leaks have been fixed. Instead of the file name xtrabackup_logfile, the file name ib_logfile0 is being used for the copy of the redo log. Unnecessary InnoDB startup and shutdown and some unnecessary threads have been removed. Some help was provided by Vladislav Vaintroub. Parameters have been cleaned up and aligned with those of MariaDB 10.2. The --dbug option has been added, so that in debug builds, --dbug=d,ib_log can be specified to enable diagnostic messages for processing redo log entries. By default, innodb_doublewrite=OFF, so that --prepare works faster. If more crash-safety for --prepare is needed, double buffering can be enabled. The parameter innodb_log_checksums=OFF can be used to ignore redo log checksums in --backup. Some messages have been cleaned up. Unless --export is specified, Mariabackup will not deal with undo log. The InnoDB mini-transaction redo log is not only about user-level transactions; it is actually about mini-transactions. To avoid confusion, call it the redo log, not transaction log. We disable any undo log processing in --prepare. Because MariaDB 10.2 supports indexed virtual columns, the undo log processing would need to be able to evaluate virtual column expressions. To reduce the amount of code dependencies, we will not process any undo log in prepare. This means that the --export option must be disabled for now. This also means that the following options are redundant and have been removed: xtrabackup --apply-log-only innobackupex --redo-only In addition to disabling any undo log processing, we will disable any further changes to data pages during --prepare, including the change buffer merge. This means that restoring incremental backups should reliably work even when change buffering is being used on the server. Because of this, preparing a backup will not generate any further redo log, and the redo log file can be safely deleted. (If the --export option is enabled in the future, it must generate redo log when processing undo logs and buffered changes.) In --prepare, we cannot easily know if a partial backup was used, especially when restoring a series of incremental backups. So, we simply warn about any missing files, and ignore the redo log for them. FIXME: Enable the --export option. FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write a test that initiates a backup while an ALGORITHM=INPLACE operation is creating indexes or rebuilding a table. An error should be detected when preparing the backup. FIXME: In --incremental --prepare, xtrabackup_apply_delta() should ensure that if FSP_SIZE is modified, the file size will be adjusted accordingly.
9 years ago
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2 InnoDB I/O and buffer pool interfaces and the redo log format have been changed between MariaDB 10.1 and 10.2, and the backup code has to be adjusted accordingly. The code has been simplified, and many memory leaks have been fixed. Instead of the file name xtrabackup_logfile, the file name ib_logfile0 is being used for the copy of the redo log. Unnecessary InnoDB startup and shutdown and some unnecessary threads have been removed. Some help was provided by Vladislav Vaintroub. Parameters have been cleaned up and aligned with those of MariaDB 10.2. The --dbug option has been added, so that in debug builds, --dbug=d,ib_log can be specified to enable diagnostic messages for processing redo log entries. By default, innodb_doublewrite=OFF, so that --prepare works faster. If more crash-safety for --prepare is needed, double buffering can be enabled. The parameter innodb_log_checksums=OFF can be used to ignore redo log checksums in --backup. Some messages have been cleaned up. Unless --export is specified, Mariabackup will not deal with undo log. The InnoDB mini-transaction redo log is not only about user-level transactions; it is actually about mini-transactions. To avoid confusion, call it the redo log, not transaction log. We disable any undo log processing in --prepare. Because MariaDB 10.2 supports indexed virtual columns, the undo log processing would need to be able to evaluate virtual column expressions. To reduce the amount of code dependencies, we will not process any undo log in prepare. This means that the --export option must be disabled for now. This also means that the following options are redundant and have been removed: xtrabackup --apply-log-only innobackupex --redo-only In addition to disabling any undo log processing, we will disable any further changes to data pages during --prepare, including the change buffer merge. This means that restoring incremental backups should reliably work even when change buffering is being used on the server. Because of this, preparing a backup will not generate any further redo log, and the redo log file can be safely deleted. (If the --export option is enabled in the future, it must generate redo log when processing undo logs and buffered changes.) In --prepare, we cannot easily know if a partial backup was used, especially when restoring a series of incremental backups. So, we simply warn about any missing files, and ignore the redo log for them. FIXME: Enable the --export option. FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write a test that initiates a backup while an ALGORITHM=INPLACE operation is creating indexes or rebuilding a table. An error should be detected when preparing the backup. FIXME: In --incremental --prepare, xtrabackup_apply_delta() should ensure that if FSP_SIZE is modified, the file size will be adjusted accordingly.
9 years ago
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2 InnoDB I/O and buffer pool interfaces and the redo log format have been changed between MariaDB 10.1 and 10.2, and the backup code has to be adjusted accordingly. The code has been simplified, and many memory leaks have been fixed. Instead of the file name xtrabackup_logfile, the file name ib_logfile0 is being used for the copy of the redo log. Unnecessary InnoDB startup and shutdown and some unnecessary threads have been removed. Some help was provided by Vladislav Vaintroub. Parameters have been cleaned up and aligned with those of MariaDB 10.2. The --dbug option has been added, so that in debug builds, --dbug=d,ib_log can be specified to enable diagnostic messages for processing redo log entries. By default, innodb_doublewrite=OFF, so that --prepare works faster. If more crash-safety for --prepare is needed, double buffering can be enabled. The parameter innodb_log_checksums=OFF can be used to ignore redo log checksums in --backup. Some messages have been cleaned up. Unless --export is specified, Mariabackup will not deal with undo log. The InnoDB mini-transaction redo log is not only about user-level transactions; it is actually about mini-transactions. To avoid confusion, call it the redo log, not transaction log. We disable any undo log processing in --prepare. Because MariaDB 10.2 supports indexed virtual columns, the undo log processing would need to be able to evaluate virtual column expressions. To reduce the amount of code dependencies, we will not process any undo log in prepare. This means that the --export option must be disabled for now. This also means that the following options are redundant and have been removed: xtrabackup --apply-log-only innobackupex --redo-only In addition to disabling any undo log processing, we will disable any further changes to data pages during --prepare, including the change buffer merge. This means that restoring incremental backups should reliably work even when change buffering is being used on the server. Because of this, preparing a backup will not generate any further redo log, and the redo log file can be safely deleted. (If the --export option is enabled in the future, it must generate redo log when processing undo logs and buffered changes.) In --prepare, we cannot easily know if a partial backup was used, especially when restoring a series of incremental backups. So, we simply warn about any missing files, and ignore the redo log for them. FIXME: Enable the --export option. FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write a test that initiates a backup while an ALGORITHM=INPLACE operation is creating indexes or rebuilding a table. An error should be detected when preparing the backup. FIXME: In --incremental --prepare, xtrabackup_apply_delta() should ensure that if FSP_SIZE is modified, the file size will be adjusted accordingly.
9 years ago
Shut down InnoDB after aborted startup. This fixes memory leaks in tests that cause InnoDB startup to fail. buf_pool_free_instance(): Also free buf_pool->flush_rbt, which would normally be freed when crash recovery finishes. fil_node_close_file(), fil_space_free_low(), fil_close_all_files(): Relax some debug assertions to tolerate !srv_was_started. innodb_shutdown(): Renamed from innobase_shutdown_for_mysql(). Changed the return type to void. Do not assume that all subsystems were started. que_init(), que_close(): Remove (empty functions). srv_init(), srv_general_init(): Remove as global functions. srv_free(): Allow srv_sys=NULL. srv_get_active_thread_type(): Only return SRV_PURGE if purge really is running. srv_shutdown_all_bg_threads(): Do not reset srv_start_state. It will be needed by innodb_shutdown(). innobase_start_or_create_for_mysql(): Always call srv_boot() so that innodb_shutdown() can assume that it was called. Make more subsystems dependent on SRV_START_STATE_STAT. srv_shutdown_bg_undo_sources(): Require SRV_START_STATE_STAT. trx_sys_close(): Do not assume purge_sys!=NULL. Do not call buf_dblwr_free(), because the doublewrite buffer can exist while the transaction system does not. logs_empty_and_mark_files_at_shutdown(): Do a faster shutdown if !srv_was_started. recv_sys_close(): Invoke dblwr.pages.clear() which would normally be invoked by buf_dblwr_process(). recv_recovery_from_checkpoint_start(): Always release log_sys->mutex. row_mysql_close(): Allow the subsystem not to exist.
9 years ago
Shut down InnoDB after aborted startup. This fixes memory leaks in tests that cause InnoDB startup to fail. buf_pool_free_instance(): Also free buf_pool->flush_rbt, which would normally be freed when crash recovery finishes. fil_node_close_file(), fil_space_free_low(), fil_close_all_files(): Relax some debug assertions to tolerate !srv_was_started. innodb_shutdown(): Renamed from innobase_shutdown_for_mysql(). Changed the return type to void. Do not assume that all subsystems were started. que_init(), que_close(): Remove (empty functions). srv_init(), srv_general_init(): Remove as global functions. srv_free(): Allow srv_sys=NULL. srv_get_active_thread_type(): Only return SRV_PURGE if purge really is running. srv_shutdown_all_bg_threads(): Do not reset srv_start_state. It will be needed by innodb_shutdown(). innobase_start_or_create_for_mysql(): Always call srv_boot() so that innodb_shutdown() can assume that it was called. Make more subsystems dependent on SRV_START_STATE_STAT. srv_shutdown_bg_undo_sources(): Require SRV_START_STATE_STAT. trx_sys_close(): Do not assume purge_sys!=NULL. Do not call buf_dblwr_free(), because the doublewrite buffer can exist while the transaction system does not. logs_empty_and_mark_files_at_shutdown(): Do a faster shutdown if !srv_was_started. recv_sys_close(): Invoke dblwr.pages.clear() which would normally be invoked by buf_dblwr_process(). recv_recovery_from_checkpoint_start(): Always release log_sys->mutex. row_mysql_close(): Allow the subsystem not to exist.
9 years ago
Shut down InnoDB after aborted startup. This fixes memory leaks in tests that cause InnoDB startup to fail. buf_pool_free_instance(): Also free buf_pool->flush_rbt, which would normally be freed when crash recovery finishes. fil_node_close_file(), fil_space_free_low(), fil_close_all_files(): Relax some debug assertions to tolerate !srv_was_started. innodb_shutdown(): Renamed from innobase_shutdown_for_mysql(). Changed the return type to void. Do not assume that all subsystems were started. que_init(), que_close(): Remove (empty functions). srv_init(), srv_general_init(): Remove as global functions. srv_free(): Allow srv_sys=NULL. srv_get_active_thread_type(): Only return SRV_PURGE if purge really is running. srv_shutdown_all_bg_threads(): Do not reset srv_start_state. It will be needed by innodb_shutdown(). innobase_start_or_create_for_mysql(): Always call srv_boot() so that innodb_shutdown() can assume that it was called. Make more subsystems dependent on SRV_START_STATE_STAT. srv_shutdown_bg_undo_sources(): Require SRV_START_STATE_STAT. trx_sys_close(): Do not assume purge_sys!=NULL. Do not call buf_dblwr_free(), because the doublewrite buffer can exist while the transaction system does not. logs_empty_and_mark_files_at_shutdown(): Do a faster shutdown if !srv_was_started. recv_sys_close(): Invoke dblwr.pages.clear() which would normally be invoked by buf_dblwr_process(). recv_recovery_from_checkpoint_start(): Always release log_sys->mutex. row_mysql_close(): Allow the subsystem not to exist.
9 years ago
Shut down InnoDB after aborted startup. This fixes memory leaks in tests that cause InnoDB startup to fail. buf_pool_free_instance(): Also free buf_pool->flush_rbt, which would normally be freed when crash recovery finishes. fil_node_close_file(), fil_space_free_low(), fil_close_all_files(): Relax some debug assertions to tolerate !srv_was_started. innodb_shutdown(): Renamed from innobase_shutdown_for_mysql(). Changed the return type to void. Do not assume that all subsystems were started. que_init(), que_close(): Remove (empty functions). srv_init(), srv_general_init(): Remove as global functions. srv_free(): Allow srv_sys=NULL. srv_get_active_thread_type(): Only return SRV_PURGE if purge really is running. srv_shutdown_all_bg_threads(): Do not reset srv_start_state. It will be needed by innodb_shutdown(). innobase_start_or_create_for_mysql(): Always call srv_boot() so that innodb_shutdown() can assume that it was called. Make more subsystems dependent on SRV_START_STATE_STAT. srv_shutdown_bg_undo_sources(): Require SRV_START_STATE_STAT. trx_sys_close(): Do not assume purge_sys!=NULL. Do not call buf_dblwr_free(), because the doublewrite buffer can exist while the transaction system does not. logs_empty_and_mark_files_at_shutdown(): Do a faster shutdown if !srv_was_started. recv_sys_close(): Invoke dblwr.pages.clear() which would normally be invoked by buf_dblwr_process(). recv_recovery_from_checkpoint_start(): Always release log_sys->mutex. row_mysql_close(): Allow the subsystem not to exist.
9 years ago
Shut down InnoDB after aborted startup. This fixes memory leaks in tests that cause InnoDB startup to fail. buf_pool_free_instance(): Also free buf_pool->flush_rbt, which would normally be freed when crash recovery finishes. fil_node_close_file(), fil_space_free_low(), fil_close_all_files(): Relax some debug assertions to tolerate !srv_was_started. innodb_shutdown(): Renamed from innobase_shutdown_for_mysql(). Changed the return type to void. Do not assume that all subsystems were started. que_init(), que_close(): Remove (empty functions). srv_init(), srv_general_init(): Remove as global functions. srv_free(): Allow srv_sys=NULL. srv_get_active_thread_type(): Only return SRV_PURGE if purge really is running. srv_shutdown_all_bg_threads(): Do not reset srv_start_state. It will be needed by innodb_shutdown(). innobase_start_or_create_for_mysql(): Always call srv_boot() so that innodb_shutdown() can assume that it was called. Make more subsystems dependent on SRV_START_STATE_STAT. srv_shutdown_bg_undo_sources(): Require SRV_START_STATE_STAT. trx_sys_close(): Do not assume purge_sys!=NULL. Do not call buf_dblwr_free(), because the doublewrite buffer can exist while the transaction system does not. logs_empty_and_mark_files_at_shutdown(): Do a faster shutdown if !srv_was_started. recv_sys_close(): Invoke dblwr.pages.clear() which would normally be invoked by buf_dblwr_process(). recv_recovery_from_checkpoint_start(): Always release log_sys->mutex. row_mysql_close(): Allow the subsystem not to exist.
9 years ago
Shut down InnoDB after aborted startup. This fixes memory leaks in tests that cause InnoDB startup to fail. buf_pool_free_instance(): Also free buf_pool->flush_rbt, which would normally be freed when crash recovery finishes. fil_node_close_file(), fil_space_free_low(), fil_close_all_files(): Relax some debug assertions to tolerate !srv_was_started. innodb_shutdown(): Renamed from innobase_shutdown_for_mysql(). Changed the return type to void. Do not assume that all subsystems were started. que_init(), que_close(): Remove (empty functions). srv_init(), srv_general_init(): Remove as global functions. srv_free(): Allow srv_sys=NULL. srv_get_active_thread_type(): Only return SRV_PURGE if purge really is running. srv_shutdown_all_bg_threads(): Do not reset srv_start_state. It will be needed by innodb_shutdown(). innobase_start_or_create_for_mysql(): Always call srv_boot() so that innodb_shutdown() can assume that it was called. Make more subsystems dependent on SRV_START_STATE_STAT. srv_shutdown_bg_undo_sources(): Require SRV_START_STATE_STAT. trx_sys_close(): Do not assume purge_sys!=NULL. Do not call buf_dblwr_free(), because the doublewrite buffer can exist while the transaction system does not. logs_empty_and_mark_files_at_shutdown(): Do a faster shutdown if !srv_was_started. recv_sys_close(): Invoke dblwr.pages.clear() which would normally be invoked by buf_dblwr_process(). recv_recovery_from_checkpoint_start(): Always release log_sys->mutex. row_mysql_close(): Allow the subsystem not to exist.
9 years ago
Shut down InnoDB after aborted startup. This fixes memory leaks in tests that cause InnoDB startup to fail. buf_pool_free_instance(): Also free buf_pool->flush_rbt, which would normally be freed when crash recovery finishes. fil_node_close_file(), fil_space_free_low(), fil_close_all_files(): Relax some debug assertions to tolerate !srv_was_started. innodb_shutdown(): Renamed from innobase_shutdown_for_mysql(). Changed the return type to void. Do not assume that all subsystems were started. que_init(), que_close(): Remove (empty functions). srv_init(), srv_general_init(): Remove as global functions. srv_free(): Allow srv_sys=NULL. srv_get_active_thread_type(): Only return SRV_PURGE if purge really is running. srv_shutdown_all_bg_threads(): Do not reset srv_start_state. It will be needed by innodb_shutdown(). innobase_start_or_create_for_mysql(): Always call srv_boot() so that innodb_shutdown() can assume that it was called. Make more subsystems dependent on SRV_START_STATE_STAT. srv_shutdown_bg_undo_sources(): Require SRV_START_STATE_STAT. trx_sys_close(): Do not assume purge_sys!=NULL. Do not call buf_dblwr_free(), because the doublewrite buffer can exist while the transaction system does not. logs_empty_and_mark_files_at_shutdown(): Do a faster shutdown if !srv_was_started. recv_sys_close(): Invoke dblwr.pages.clear() which would normally be invoked by buf_dblwr_process(). recv_recovery_from_checkpoint_start(): Always release log_sys->mutex. row_mysql_close(): Allow the subsystem not to exist.
9 years ago
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, 2019, MariaDB Corporation.
  6. Portions of this file contain modifications contributed and copyrighted by
  7. Google, Inc. Those modifications are gratefully acknowledged and are described
  8. briefly in the InnoDB documentation. The contributions by Google are
  9. incorporated with their permission, and subject to the conditions contained in
  10. the file COPYING.Google.
  11. Portions of this file contain modifications contributed and copyrighted
  12. by Percona Inc.. Those modifications are
  13. gratefully acknowledged and are described briefly in the InnoDB
  14. documentation. The contributions by Percona Inc. are incorporated with
  15. their permission, and subject to the conditions contained in the file
  16. COPYING.Percona.
  17. This program is free software; you can redistribute it and/or modify it under
  18. the terms of the GNU General Public License as published by the Free Software
  19. Foundation; version 2 of the License.
  20. This program is distributed in the hope that it will be useful, but WITHOUT
  21. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  22. FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  23. You should have received a copy of the GNU General Public License along with
  24. this program; if not, write to the Free Software Foundation, Inc.,
  25. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
  26. *****************************************************************************/
  27. /********************************************************************//**
  28. @file srv/srv0start.cc
  29. Starts the InnoDB database server
  30. Created 2/16/1996 Heikki Tuuri
  31. *************************************************************************/
  32. #include "my_global.h"
  33. #include "mysqld.h"
  34. #include "mysql/psi/mysql_stage.h"
  35. #include "mysql/psi/psi.h"
  36. #include "row0ftsort.h"
  37. #include "ut0mem.h"
  38. #include "mem0mem.h"
  39. #include "data0data.h"
  40. #include "data0type.h"
  41. #include "dict0dict.h"
  42. #include "buf0buf.h"
  43. #include "buf0dump.h"
  44. #include "os0file.h"
  45. #include "os0thread.h"
  46. #include "fil0fil.h"
  47. #include "fil0crypt.h"
  48. #include "fsp0fsp.h"
  49. #include "rem0rec.h"
  50. #include "mtr0mtr.h"
  51. #include "log0crypt.h"
  52. #include "log0recv.h"
  53. #include "page0page.h"
  54. #include "page0cur.h"
  55. #include "trx0trx.h"
  56. #include "trx0sys.h"
  57. #include "btr0btr.h"
  58. #include "btr0cur.h"
  59. #include "rem0rec.h"
  60. #include "ibuf0ibuf.h"
  61. #include "srv0start.h"
  62. #include "srv0srv.h"
  63. #include "btr0defragment.h"
  64. #include "mysql/service_wsrep.h" /* wsrep_recovery */
  65. #include "trx0rseg.h"
  66. #include "os0proc.h"
  67. #include "buf0flu.h"
  68. #include "buf0rea.h"
  69. #include "dict0boot.h"
  70. #include "dict0load.h"
  71. #include "dict0stats_bg.h"
  72. #include "que0que.h"
  73. #include "lock0lock.h"
  74. #include "trx0roll.h"
  75. #include "trx0purge.h"
  76. #include "lock0lock.h"
  77. #include "pars0pars.h"
  78. #include "btr0sea.h"
  79. #include "rem0cmp.h"
  80. #include "dict0crea.h"
  81. #include "row0ins.h"
  82. #include "row0sel.h"
  83. #include "row0upd.h"
  84. #include "row0row.h"
  85. #include "row0mysql.h"
  86. #include "btr0pcur.h"
  87. #include "os0event.h"
  88. #include "zlib.h"
  89. #include "ut0crc32.h"
  90. #include "btr0scrub.h"
  91. /** Log sequence number immediately after startup */
  92. lsn_t srv_start_lsn;
  93. /** Log sequence number at shutdown */
  94. lsn_t srv_shutdown_lsn;
  95. /** TRUE if a raw partition is in use */
  96. ibool srv_start_raw_disk_in_use;
  97. /** Number of IO threads to use */
  98. ulint srv_n_file_io_threads;
  99. /** UNDO tablespaces starts with space id. */
  100. ulint srv_undo_space_id_start;
  101. /** TRUE if the server is being started, before rolling back any
  102. incomplete transactions */
  103. bool srv_startup_is_before_trx_rollback_phase;
  104. /** TRUE if the server is being started */
  105. bool srv_is_being_started;
  106. /** TRUE if SYS_TABLESPACES is available for lookups */
  107. bool srv_sys_tablespaces_open;
  108. /** TRUE if the server was successfully started */
  109. bool srv_was_started;
  110. /** The original value of srv_log_file_size (innodb_log_file_size) */
  111. static ulonglong srv_log_file_size_requested;
  112. /** whether srv_start() has been called */
  113. static bool srv_start_has_been_called;
  114. /** Whether any undo log records can be generated */
  115. UNIV_INTERN bool srv_undo_sources;
  116. #ifdef UNIV_DEBUG
  117. /** InnoDB system tablespace to set during recovery */
  118. UNIV_INTERN uint srv_sys_space_size_debug;
  119. /** whether redo log files have been created at startup */
  120. UNIV_INTERN bool srv_log_files_created;
  121. #endif /* UNIV_DEBUG */
  122. /** Bit flags for tracking background thread creation. They are used to
  123. determine which threads need to be stopped if we need to abort during
  124. the initialisation step. */
  125. enum srv_start_state_t {
  126. /** No thread started */
  127. SRV_START_STATE_NONE = 0, /*!< No thread started */
  128. /** lock_wait_timeout timer task started */
  129. SRV_START_STATE_LOCK_SYS = 1,
  130. /** buf_flush_page_cleaner_coordinator,
  131. buf_flush_page_cleaner_worker started */
  132. SRV_START_STATE_IO = 2,
  133. /** srv_error_monitor_thread, srv_print_monitor_task started */
  134. SRV_START_STATE_MONITOR = 4,
  135. /** srv_master_thread started */
  136. SRV_START_STATE_MASTER = 8,
  137. /** srv_purge_coordinator_thread, srv_worker_thread started */
  138. SRV_START_STATE_PURGE = 16,
  139. /** fil_crypt_thread,
  140. (all background threads that can generate redo log but not undo log */
  141. SRV_START_STATE_REDO = 32
  142. };
  143. /** Track server thrd starting phases */
  144. static ulint srv_start_state;
  145. /** At a shutdown this value climbs from SRV_SHUTDOWN_NONE to
  146. SRV_SHUTDOWN_CLEANUP and then to SRV_SHUTDOWN_LAST_PHASE, and so on */
  147. enum srv_shutdown_t srv_shutdown_state = SRV_SHUTDOWN_NONE;
  148. /** Files comprising the system tablespace */
  149. pfs_os_file_t files[1000];
  150. /** Name of srv_monitor_file */
  151. static char* srv_monitor_file_name;
  152. std::unique_ptr<tpool::timer> srv_master_timer;
  153. /** */
  154. #define SRV_MAX_N_PENDING_SYNC_IOS 100
  155. #ifdef UNIV_PFS_THREAD
  156. /* Keys to register InnoDB threads with performance schema */
  157. mysql_pfs_key_t thread_pool_thread_key;
  158. #endif /* UNIV_PFS_THREAD */
  159. #ifdef HAVE_PSI_STAGE_INTERFACE
  160. /** Array of all InnoDB stage events for monitoring activities via
  161. performance schema. */
  162. static PSI_stage_info* srv_stages[] =
  163. {
  164. &srv_stage_alter_table_end,
  165. &srv_stage_alter_table_flush,
  166. &srv_stage_alter_table_insert,
  167. &srv_stage_alter_table_log_index,
  168. &srv_stage_alter_table_log_table,
  169. &srv_stage_alter_table_merge_sort,
  170. &srv_stage_alter_table_read_pk_internal_sort,
  171. &srv_stage_buffer_pool_load,
  172. };
  173. #endif /* HAVE_PSI_STAGE_INTERFACE */
  174. /*********************************************************************//**
  175. Check if a file can be opened in read-write mode.
  176. @return true if it doesn't exist or can be opened in rw mode. */
  177. static
  178. bool
  179. srv_file_check_mode(
  180. /*================*/
  181. const char* name) /*!< in: filename to check */
  182. {
  183. os_file_stat_t stat;
  184. memset(&stat, 0x0, sizeof(stat));
  185. dberr_t err = os_file_get_status(
  186. name, &stat, true, srv_read_only_mode);
  187. if (err == DB_FAIL) {
  188. ib::error() << "os_file_get_status() failed on '" << name
  189. << "'. Can't determine file permissions.";
  190. return(false);
  191. } else if (err == DB_SUCCESS) {
  192. /* Note: stat.rw_perm is only valid of files */
  193. if (stat.type == OS_FILE_TYPE_FILE) {
  194. if (!stat.rw_perm) {
  195. const char* mode = srv_read_only_mode
  196. ? "read" : "read-write";
  197. ib::error() << name << " can't be opened in "
  198. << mode << " mode.";
  199. return(false);
  200. }
  201. } else {
  202. /* Not a regular file, bail out. */
  203. ib::error() << "'" << name << "' not a regular file.";
  204. return(false);
  205. }
  206. } else {
  207. /* This is OK. If the file create fails on RO media, there
  208. is nothing we can do. */
  209. ut_a(err == DB_NOT_FOUND);
  210. }
  211. return(true);
  212. }
  213. /*********************************************************************//**
  214. Creates a log file.
  215. @return DB_SUCCESS or error code */
  216. static MY_ATTRIBUTE((nonnull, warn_unused_result))
  217. dberr_t
  218. create_log_file(
  219. /*============*/
  220. pfs_os_file_t* file, /*!< out: file handle */
  221. const char* name) /*!< in: log file name */
  222. {
  223. bool ret;
  224. *file = os_file_create(
  225. innodb_log_file_key, name,
  226. OS_FILE_CREATE|OS_FILE_ON_ERROR_NO_EXIT, OS_FILE_NORMAL,
  227. OS_LOG_FILE, srv_read_only_mode, &ret);
  228. if (!ret) {
  229. ib::error() << "Cannot create " << name;
  230. return(DB_ERROR);
  231. }
  232. ib::info() << "Setting log file " << name << " size to "
  233. << srv_log_file_size << " bytes";
  234. ret = os_file_set_size(name, *file, srv_log_file_size);
  235. if (!ret) {
  236. ib::error() << "Cannot set log file " << name << " size to "
  237. << srv_log_file_size << " bytes";
  238. return(DB_ERROR);
  239. }
  240. ret = os_file_close(*file);
  241. ut_a(ret);
  242. return(DB_SUCCESS);
  243. }
  244. /** Initial number of the first redo log file */
  245. #define INIT_LOG_FILE0 (SRV_N_LOG_FILES_MAX + 1)
  246. /** Delete all log files.
  247. @param[in,out] logfilename buffer for log file name
  248. @param[in] dirnamelen length of the directory path
  249. @param[in] n_files number of files to delete
  250. @param[in] i first file to delete */
  251. static
  252. void
  253. delete_log_files(char* logfilename, size_t dirnamelen, uint n_files, uint i=0)
  254. {
  255. /* Remove any old log files. */
  256. for (; i < n_files; i++) {
  257. sprintf(logfilename + dirnamelen, "ib_logfile%u", i);
  258. /* Ignore errors about non-existent files or files
  259. that cannot be removed. The create_log_file() will
  260. return an error when the file exists. */
  261. #ifdef _WIN32
  262. DeleteFile((LPCTSTR) logfilename);
  263. #else
  264. unlink(logfilename);
  265. #endif
  266. }
  267. }
  268. /*********************************************************************//**
  269. Creates all log files.
  270. @return DB_SUCCESS or error code */
  271. static
  272. dberr_t
  273. create_log_files(
  274. /*=============*/
  275. char* logfilename, /*!< in/out: buffer for log file name */
  276. size_t dirnamelen, /*!< in: length of the directory path */
  277. lsn_t lsn, /*!< in: FIL_PAGE_FILE_FLUSH_LSN value */
  278. char*& logfile0) /*!< out: name of the first log file */
  279. {
  280. dberr_t err;
  281. if (srv_read_only_mode) {
  282. ib::error() << "Cannot create log files in read-only mode";
  283. return(DB_READ_ONLY);
  284. }
  285. /* Crashing after deleting the first file should be
  286. recoverable. The buffer pool was clean, and we can simply
  287. create all log files from the scratch. */
  288. DBUG_EXECUTE_IF("innodb_log_abort_6",
  289. delete_log_files(logfilename, dirnamelen, 1);
  290. return(DB_ERROR););
  291. delete_log_files(logfilename, dirnamelen, INIT_LOG_FILE0 + 1);
  292. DBUG_PRINT("ib_log", ("After innodb_log_abort_6"));
  293. ut_ad(!buf_pool_check_no_pending_io());
  294. DBUG_EXECUTE_IF("innodb_log_abort_7", return(DB_ERROR););
  295. DBUG_PRINT("ib_log", ("After innodb_log_abort_7"));
  296. for (unsigned i = 0; i < srv_n_log_files; i++) {
  297. sprintf(logfilename + dirnamelen,
  298. "ib_logfile%u", i ? i : INIT_LOG_FILE0);
  299. err = create_log_file(&files[i], logfilename);
  300. if (err != DB_SUCCESS) {
  301. return(err);
  302. }
  303. }
  304. DBUG_EXECUTE_IF("innodb_log_abort_8", return(DB_ERROR););
  305. DBUG_PRINT("ib_log", ("After innodb_log_abort_8"));
  306. /* We did not create the first log file initially as
  307. ib_logfile0, so that crash recovery cannot find it until it
  308. has been completed and renamed. */
  309. sprintf(logfilename + dirnamelen, "ib_logfile%u", INIT_LOG_FILE0);
  310. fil_space_t* log_space = fil_space_create(
  311. "innodb_redo_log", SRV_LOG_SPACE_FIRST_ID, 0, FIL_TYPE_LOG,
  312. NULL/* innodb_encrypt_log works at a different level */);
  313. ut_a(fil_validate());
  314. ut_a(log_space != NULL);
  315. const ulint size = ulint(srv_log_file_size >> srv_page_size_shift);
  316. logfile0 = log_space->add(logfilename, OS_FILE_CLOSED, size,
  317. false, false)->name;
  318. ut_a(logfile0);
  319. for (unsigned i = 1; i < srv_n_log_files; i++) {
  320. sprintf(logfilename + dirnamelen, "ib_logfile%u", i);
  321. log_space->add(logfilename, OS_FILE_CLOSED, size,
  322. false, false);
  323. }
  324. log_sys.log.create(srv_n_log_files);
  325. if (!log_set_capacity(srv_log_file_size_requested)) {
  326. return(DB_ERROR);
  327. }
  328. fil_open_log_and_system_tablespace_files();
  329. /* Create a log checkpoint. */
  330. log_mutex_enter();
  331. if (log_sys.is_encrypted() && !log_crypt_init()) {
  332. return DB_ERROR;
  333. }
  334. ut_d(recv_no_log_write = false);
  335. log_sys.lsn = ut_uint64_align_up(lsn, OS_FILE_LOG_BLOCK_SIZE);
  336. log_sys.log.set_lsn(log_sys.lsn);
  337. log_sys.log.set_lsn_offset(LOG_FILE_HDR_SIZE);
  338. log_sys.buf_next_to_write = 0;
  339. log_sys.write_lsn = log_sys.lsn;
  340. log_sys.next_checkpoint_no = 0;
  341. log_sys.last_checkpoint_lsn = 0;
  342. memset(log_sys.buf, 0, srv_log_buffer_size);
  343. log_block_init(log_sys.buf, log_sys.lsn);
  344. log_block_set_first_rec_group(log_sys.buf, LOG_BLOCK_HDR_SIZE);
  345. log_sys.buf_free = LOG_BLOCK_HDR_SIZE;
  346. log_sys.lsn += LOG_BLOCK_HDR_SIZE;
  347. MONITOR_SET(MONITOR_LSN_CHECKPOINT_AGE,
  348. (log_sys.lsn - log_sys.last_checkpoint_lsn));
  349. log_mutex_exit();
  350. log_make_checkpoint();
  351. return(DB_SUCCESS);
  352. }
  353. /** Rename the first redo log file.
  354. @param[in,out] logfilename buffer for the log file name
  355. @param[in] dirnamelen length of the directory path
  356. @param[in] lsn FIL_PAGE_FILE_FLUSH_LSN value
  357. @param[in,out] logfile0 name of the first log file
  358. @return error code
  359. @retval DB_SUCCESS on successful operation */
  360. MY_ATTRIBUTE((warn_unused_result, nonnull))
  361. static
  362. dberr_t
  363. create_log_files_rename(
  364. /*====================*/
  365. char* logfilename, /*!< in/out: buffer for log file name */
  366. size_t dirnamelen, /*!< in: length of the directory path */
  367. lsn_t lsn, /*!< in: FIL_PAGE_FILE_FLUSH_LSN value */
  368. char* logfile0) /*!< in/out: name of the first log file */
  369. {
  370. /* If innodb_flush_method=O_DSYNC,
  371. we need to explicitly flush the log buffers. */
  372. fil_flush(SRV_LOG_SPACE_FIRST_ID);
  373. ut_ad(!srv_log_files_created);
  374. ut_d(srv_log_files_created = true);
  375. DBUG_EXECUTE_IF("innodb_log_abort_9", return(DB_ERROR););
  376. DBUG_PRINT("ib_log", ("After innodb_log_abort_9"));
  377. /* Close the log files, so that we can rename
  378. the first one. */
  379. fil_close_log_files(false);
  380. /* Rename the first log file, now that a log
  381. checkpoint has been created. */
  382. sprintf(logfilename + dirnamelen, "ib_logfile%u", 0);
  383. ib::info() << "Renaming log file " << logfile0 << " to "
  384. << logfilename;
  385. log_mutex_enter();
  386. ut_ad(strlen(logfile0) == 2 + strlen(logfilename));
  387. dberr_t err = os_file_rename(
  388. innodb_log_file_key, logfile0, logfilename)
  389. ? DB_SUCCESS : DB_ERROR;
  390. /* Replace the first file with ib_logfile0. */
  391. strcpy(logfile0, logfilename);
  392. log_mutex_exit();
  393. DBUG_EXECUTE_IF("innodb_log_abort_10", err = DB_ERROR;);
  394. if (err == DB_SUCCESS) {
  395. fil_open_log_and_system_tablespace_files();
  396. ib::info() << "New log files created, LSN=" << lsn;
  397. }
  398. return(err);
  399. }
  400. /*********************************************************************//**
  401. Create undo tablespace.
  402. @return DB_SUCCESS or error code */
  403. static
  404. dberr_t
  405. srv_undo_tablespace_create(
  406. /*=======================*/
  407. const char* name, /*!< in: tablespace name */
  408. ulint size) /*!< in: tablespace size in pages */
  409. {
  410. pfs_os_file_t fh;
  411. bool ret;
  412. dberr_t err = DB_SUCCESS;
  413. os_file_create_subdirs_if_needed(name);
  414. fh = os_file_create(
  415. innodb_data_file_key,
  416. name,
  417. srv_read_only_mode ? OS_FILE_OPEN : OS_FILE_CREATE,
  418. OS_FILE_NORMAL, OS_DATA_FILE, srv_read_only_mode, &ret);
  419. if (srv_read_only_mode && ret) {
  420. ib::info() << name << " opened in read-only mode";
  421. } else if (ret == FALSE) {
  422. if (os_file_get_last_error(false) != OS_FILE_ALREADY_EXISTS
  423. #ifdef UNIV_AIX
  424. /* AIX 5.1 after security patch ML7 may have
  425. errno set to 0 here, which causes our function
  426. to return 100; work around that AIX problem */
  427. && os_file_get_last_error(false) != 100
  428. #endif /* UNIV_AIX */
  429. ) {
  430. ib::error() << "Can't create UNDO tablespace "
  431. << name;
  432. }
  433. err = DB_ERROR;
  434. } else {
  435. ut_a(!srv_read_only_mode);
  436. /* We created the data file and now write it full of zeros */
  437. ib::info() << "Data file " << name << " did not exist: new to"
  438. " be created";
  439. ib::info() << "Setting file " << name << " size to "
  440. << (size >> (20 - srv_page_size_shift)) << " MB";
  441. ib::info() << "Database physically writes the file full: "
  442. << "wait...";
  443. ret = os_file_set_size(
  444. name, fh, os_offset_t(size) << srv_page_size_shift);
  445. if (!ret) {
  446. ib::info() << "Error in creating " << name
  447. << ": probably out of disk space";
  448. err = DB_ERROR;
  449. }
  450. os_file_close(fh);
  451. }
  452. return(err);
  453. }
  454. /** Open an undo tablespace.
  455. @param[in] name tablespace file name
  456. @param[in] space_id tablespace ID
  457. @param[in] create_new_db whether undo tablespaces are being created
  458. @return whether the tablespace was opened */
  459. static bool srv_undo_tablespace_open(const char* name, ulint space_id,
  460. bool create_new_db)
  461. {
  462. pfs_os_file_t fh;
  463. bool success;
  464. char undo_name[sizeof "innodb_undo000"];
  465. snprintf(undo_name, sizeof(undo_name),
  466. "innodb_undo%03u", static_cast<unsigned>(space_id));
  467. fh = os_file_create(
  468. innodb_data_file_key, name, OS_FILE_OPEN
  469. | OS_FILE_ON_ERROR_NO_EXIT | OS_FILE_ON_ERROR_SILENT,
  470. OS_FILE_AIO, OS_DATA_FILE, srv_read_only_mode, &success);
  471. if (!success) {
  472. return false;
  473. }
  474. os_offset_t size = os_file_get_size(fh);
  475. ut_a(size != os_offset_t(-1));
  476. /* Load the tablespace into InnoDB's internal data structures. */
  477. /* We set the biggest space id to the undo tablespace
  478. because InnoDB hasn't opened any other tablespace apart
  479. from the system tablespace. */
  480. fil_set_max_space_id_if_bigger(space_id);
  481. ulint fsp_flags;
  482. switch (srv_checksum_algorithm) {
  483. case SRV_CHECKSUM_ALGORITHM_FULL_CRC32:
  484. case SRV_CHECKSUM_ALGORITHM_STRICT_FULL_CRC32:
  485. fsp_flags = (FSP_FLAGS_FCRC32_MASK_MARKER
  486. | FSP_FLAGS_FCRC32_PAGE_SSIZE());
  487. break;
  488. default:
  489. fsp_flags = FSP_FLAGS_PAGE_SSIZE();
  490. }
  491. fil_space_t* space = fil_space_create(undo_name, space_id, fsp_flags,
  492. FIL_TYPE_TABLESPACE, NULL);
  493. ut_a(fil_validate());
  494. ut_a(space);
  495. fil_node_t* file = space->add(name, fh, 0, false, true);
  496. mutex_enter(&fil_system.mutex);
  497. if (create_new_db) {
  498. space->size = file->size = ulint(size >> srv_page_size_shift);
  499. space->size_in_header = SRV_UNDO_TABLESPACE_SIZE_IN_PAGES;
  500. } else {
  501. success = file->read_page0(true);
  502. if (!success) {
  503. os_file_close(file->handle);
  504. file->handle = OS_FILE_CLOSED;
  505. ut_a(fil_system.n_open > 0);
  506. fil_system.n_open--;
  507. }
  508. }
  509. mutex_exit(&fil_system.mutex);
  510. return success;
  511. }
  512. /** Check if undo tablespaces and redo log files exist before creating a
  513. new system tablespace
  514. @retval DB_SUCCESS if all undo and redo logs are not found
  515. @retval DB_ERROR if any undo and redo logs are found */
  516. static
  517. dberr_t
  518. srv_check_undo_redo_logs_exists()
  519. {
  520. bool ret;
  521. pfs_os_file_t fh;
  522. char name[OS_FILE_MAX_PATH];
  523. /* Check if any undo tablespaces exist */
  524. for (ulint i = 1; i <= srv_undo_tablespaces; ++i) {
  525. snprintf(
  526. name, sizeof(name),
  527. "%s%cundo%03zu",
  528. srv_undo_dir, OS_PATH_SEPARATOR,
  529. i);
  530. fh = os_file_create(
  531. innodb_data_file_key, name,
  532. OS_FILE_OPEN_RETRY
  533. | OS_FILE_ON_ERROR_NO_EXIT
  534. | OS_FILE_ON_ERROR_SILENT,
  535. OS_FILE_NORMAL,
  536. OS_DATA_FILE,
  537. srv_read_only_mode,
  538. &ret);
  539. if (ret) {
  540. os_file_close(fh);
  541. ib::error()
  542. << "undo tablespace '" << name << "' exists."
  543. " Creating system tablespace with existing undo"
  544. " tablespaces is not supported. Please delete"
  545. " all undo tablespaces before creating new"
  546. " system tablespace.";
  547. return(DB_ERROR);
  548. }
  549. }
  550. /* Check if any redo log files exist */
  551. char logfilename[OS_FILE_MAX_PATH];
  552. size_t dirnamelen = strlen(srv_log_group_home_dir);
  553. memcpy(logfilename, srv_log_group_home_dir, dirnamelen);
  554. for (unsigned i = 0; i < srv_n_log_files; i++) {
  555. sprintf(logfilename + dirnamelen,
  556. "ib_logfile%u", i);
  557. fh = os_file_create(
  558. innodb_log_file_key, logfilename,
  559. OS_FILE_OPEN_RETRY
  560. | OS_FILE_ON_ERROR_NO_EXIT
  561. | OS_FILE_ON_ERROR_SILENT,
  562. OS_FILE_NORMAL,
  563. OS_LOG_FILE,
  564. srv_read_only_mode,
  565. &ret);
  566. if (ret) {
  567. os_file_close(fh);
  568. ib::error() << "redo log file '" << logfilename
  569. << "' exists. Creating system tablespace with"
  570. " existing redo log files is not recommended."
  571. " Please delete all redo log files before"
  572. " creating new system tablespace.";
  573. return(DB_ERROR);
  574. }
  575. }
  576. return(DB_SUCCESS);
  577. }
  578. /** Open the configured number of dedicated undo tablespaces.
  579. @param[in] create_new_db whether the database is being initialized
  580. @return DB_SUCCESS or error code */
  581. dberr_t
  582. srv_undo_tablespaces_init(bool create_new_db)
  583. {
  584. ulint i;
  585. dberr_t err = DB_SUCCESS;
  586. ulint prev_space_id = 0;
  587. ulint n_undo_tablespaces;
  588. ulint undo_tablespace_ids[TRX_SYS_N_RSEGS + 1];
  589. srv_undo_tablespaces_open = 0;
  590. ut_a(srv_undo_tablespaces <= TRX_SYS_N_RSEGS);
  591. ut_a(!create_new_db || srv_operation == SRV_OPERATION_NORMAL);
  592. if (srv_undo_tablespaces == 1) { /* 1 is not allowed, make it 0 */
  593. srv_undo_tablespaces = 0;
  594. }
  595. memset(undo_tablespace_ids, 0x0, sizeof(undo_tablespace_ids));
  596. /* Create the undo spaces only if we are creating a new
  597. instance. We don't allow creating of new undo tablespaces
  598. in an existing instance (yet). This restriction exists because
  599. we check in several places for SYSTEM tablespaces to be less than
  600. the min of user defined tablespace ids. Once we implement saving
  601. the location of the undo tablespaces and their space ids this
  602. restriction will/should be lifted. */
  603. for (i = 0; create_new_db && i < srv_undo_tablespaces; ++i) {
  604. char name[OS_FILE_MAX_PATH];
  605. ulint space_id = i + 1;
  606. DBUG_EXECUTE_IF("innodb_undo_upgrade",
  607. space_id = i + 3;);
  608. snprintf(
  609. name, sizeof(name),
  610. "%s%cundo%03zu",
  611. srv_undo_dir, OS_PATH_SEPARATOR, space_id);
  612. if (i == 0) {
  613. srv_undo_space_id_start = space_id;
  614. prev_space_id = srv_undo_space_id_start - 1;
  615. }
  616. undo_tablespace_ids[i] = space_id;
  617. err = srv_undo_tablespace_create(
  618. name, SRV_UNDO_TABLESPACE_SIZE_IN_PAGES);
  619. if (err != DB_SUCCESS) {
  620. ib::error() << "Could not create undo tablespace '"
  621. << name << "'.";
  622. return(err);
  623. }
  624. }
  625. /* Get the tablespace ids of all the undo segments excluding
  626. the system tablespace (0). If we are creating a new instance then
  627. we build the undo_tablespace_ids ourselves since they don't
  628. already exist. */
  629. n_undo_tablespaces = create_new_db
  630. || srv_operation == SRV_OPERATION_BACKUP
  631. || srv_operation == SRV_OPERATION_RESTORE_DELTA
  632. ? srv_undo_tablespaces
  633. : trx_rseg_get_n_undo_tablespaces(undo_tablespace_ids);
  634. srv_undo_tablespaces_active = srv_undo_tablespaces;
  635. switch (srv_operation) {
  636. case SRV_OPERATION_RESTORE_DELTA:
  637. case SRV_OPERATION_BACKUP:
  638. for (i = 0; i < n_undo_tablespaces; i++) {
  639. undo_tablespace_ids[i] = i + srv_undo_space_id_start;
  640. }
  641. prev_space_id = srv_undo_space_id_start - 1;
  642. break;
  643. case SRV_OPERATION_NORMAL:
  644. case SRV_OPERATION_RESTORE:
  645. case SRV_OPERATION_RESTORE_EXPORT:
  646. break;
  647. }
  648. /* Open all the undo tablespaces that are currently in use. If we
  649. fail to open any of these it is a fatal error. The tablespace ids
  650. should be contiguous. It is a fatal error because they are required
  651. for recovery and are referenced by the UNDO logs (a.k.a RBS). */
  652. for (i = 0; i < n_undo_tablespaces; ++i) {
  653. char name[OS_FILE_MAX_PATH];
  654. snprintf(
  655. name, sizeof(name),
  656. "%s%cundo%03zu",
  657. srv_undo_dir, OS_PATH_SEPARATOR,
  658. undo_tablespace_ids[i]);
  659. /* Should be no gaps in undo tablespace ids. */
  660. ut_a(!i || prev_space_id + 1 == undo_tablespace_ids[i]);
  661. /* The system space id should not be in this array. */
  662. ut_a(undo_tablespace_ids[i] != 0);
  663. ut_a(undo_tablespace_ids[i] != ULINT_UNDEFINED);
  664. if (!srv_undo_tablespace_open(name, undo_tablespace_ids[i],
  665. create_new_db)) {
  666. ib::error() << "Unable to open undo tablespace '"
  667. << name << "'.";
  668. return DB_ERROR;
  669. }
  670. prev_space_id = undo_tablespace_ids[i];
  671. /* Note the first undo tablespace id in case of
  672. no active undo tablespace. */
  673. if (0 == srv_undo_tablespaces_open++) {
  674. srv_undo_space_id_start = undo_tablespace_ids[i];
  675. }
  676. }
  677. /* Open any extra unused undo tablespaces. These must be contiguous.
  678. We stop at the first failure. These are undo tablespaces that are
  679. not in use and therefore not required by recovery. We only check
  680. that there are no gaps. */
  681. for (i = prev_space_id + 1;
  682. i < srv_undo_space_id_start + TRX_SYS_N_RSEGS; ++i) {
  683. char name[OS_FILE_MAX_PATH];
  684. snprintf(
  685. name, sizeof(name),
  686. "%s%cundo%03zu", srv_undo_dir, OS_PATH_SEPARATOR, i);
  687. if (!srv_undo_tablespace_open(name, i, create_new_db)) {
  688. err = DB_ERROR;
  689. break;
  690. }
  691. ++n_undo_tablespaces;
  692. ++srv_undo_tablespaces_open;
  693. }
  694. /* Initialize srv_undo_space_id_start=0 when there are no
  695. dedicated undo tablespaces. */
  696. if (n_undo_tablespaces == 0) {
  697. srv_undo_space_id_start = 0;
  698. }
  699. /* If the user says that there are fewer than what we find we
  700. tolerate that discrepancy but not the inverse. Because there could
  701. be unused undo tablespaces for future use. */
  702. if (srv_undo_tablespaces > n_undo_tablespaces) {
  703. ib::error() << "Expected to open innodb_undo_tablespaces="
  704. << srv_undo_tablespaces
  705. << " but was able to find only "
  706. << n_undo_tablespaces;
  707. return(err != DB_SUCCESS ? err : DB_ERROR);
  708. } else if (n_undo_tablespaces > 0) {
  709. ib::info() << "Opened " << n_undo_tablespaces
  710. << " undo tablespaces";
  711. if (srv_undo_tablespaces == 0) {
  712. ib::warn() << "innodb_undo_tablespaces=0 disables"
  713. " dedicated undo log tablespaces";
  714. }
  715. }
  716. if (create_new_db) {
  717. mtr_t mtr;
  718. for (i = 0; i < n_undo_tablespaces; ++i) {
  719. mtr.start();
  720. fsp_header_init(fil_space_get(undo_tablespace_ids[i]),
  721. SRV_UNDO_TABLESPACE_SIZE_IN_PAGES,
  722. &mtr);
  723. mtr.commit();
  724. }
  725. }
  726. return(DB_SUCCESS);
  727. }
  728. /** Create the temporary file tablespace.
  729. @param[in] create_new_db whether we are creating a new database
  730. @return DB_SUCCESS or error code. */
  731. static
  732. dberr_t
  733. srv_open_tmp_tablespace(bool create_new_db)
  734. {
  735. ulint sum_of_new_sizes;
  736. /* Will try to remove if there is existing file left-over by last
  737. unclean shutdown */
  738. srv_tmp_space.set_sanity_check_status(true);
  739. srv_tmp_space.delete_files();
  740. srv_tmp_space.set_ignore_read_only(true);
  741. ib::info() << "Creating shared tablespace for temporary tables";
  742. bool create_new_temp_space;
  743. srv_tmp_space.set_space_id(SRV_TMP_SPACE_ID);
  744. dberr_t err = srv_tmp_space.check_file_spec(
  745. &create_new_temp_space, 12 * 1024 * 1024);
  746. if (err == DB_FAIL) {
  747. ib::error() << "The innodb_temporary"
  748. " data file must be writable!";
  749. err = DB_ERROR;
  750. } else if (err != DB_SUCCESS) {
  751. ib::error() << "Could not create the shared innodb_temporary.";
  752. } else if ((err = srv_tmp_space.open_or_create(
  753. true, create_new_db, &sum_of_new_sizes, NULL))
  754. != DB_SUCCESS) {
  755. ib::error() << "Unable to create the shared innodb_temporary";
  756. } else if (fil_system.temp_space->open()) {
  757. /* Initialize the header page */
  758. mtr_t mtr;
  759. mtr.start();
  760. mtr.set_log_mode(MTR_LOG_NO_REDO);
  761. fsp_header_init(fil_system.temp_space,
  762. srv_tmp_space.get_sum_of_sizes(),
  763. &mtr);
  764. mtr.commit();
  765. } else {
  766. /* This file was just opened in the code above! */
  767. ib::error() << "The innodb_temporary"
  768. " data file cannot be re-opened"
  769. " after check_file_spec() succeeded!";
  770. err = DB_ERROR;
  771. }
  772. return(err);
  773. }
  774. /****************************************************************//**
  775. Set state to indicate start of particular group of threads in InnoDB. */
  776. UNIV_INLINE
  777. void
  778. srv_start_state_set(
  779. /*================*/
  780. srv_start_state_t state) /*!< in: indicate current state of
  781. thread startup */
  782. {
  783. srv_start_state |= ulint(state);
  784. }
  785. /****************************************************************//**
  786. Check if following group of threads is started.
  787. @return true if started */
  788. UNIV_INLINE
  789. bool
  790. srv_start_state_is_set(
  791. /*===================*/
  792. srv_start_state_t state) /*!< in: state to check for */
  793. {
  794. return(srv_start_state & ulint(state));
  795. }
  796. /**
  797. Shutdown all background threads created by InnoDB. */
  798. static
  799. void
  800. srv_shutdown_all_bg_threads()
  801. {
  802. ut_ad(!srv_undo_sources);
  803. srv_shutdown_state = SRV_SHUTDOWN_EXIT_THREADS;
  804. lock_sys.timeout_timer.reset();
  805. srv_master_timer.reset();
  806. if (purge_sys.enabled()) {
  807. srv_purge_shutdown();
  808. }
  809. /* All threads end up waiting for certain events. Put those events
  810. to the signaled state. Then the threads will exit themselves after
  811. os_event_wait(). */
  812. for (uint i = 0; i < 1000; ++i) {
  813. /* NOTE: IF YOU CREATE THREADS IN INNODB, YOU MUST EXIT THEM
  814. HERE OR EARLIER */
  815. if (!srv_read_only_mode) {
  816. /* b. srv error monitor thread exits automatically,
  817. no need to do anything here */
  818. if (srv_n_fil_crypt_threads_started) {
  819. os_event_set(fil_crypt_threads_event);
  820. }
  821. if (log_scrub_thread_active) {
  822. os_event_set(log_scrub_event);
  823. }
  824. }
  825. if (srv_start_state_is_set(SRV_START_STATE_IO)) {
  826. ut_ad(!srv_read_only_mode);
  827. /* e. Exit the i/o threads */
  828. if (recv_sys.flush_start != NULL) {
  829. os_event_set(recv_sys.flush_start);
  830. }
  831. if (recv_sys.flush_end != NULL) {
  832. os_event_set(recv_sys.flush_end);
  833. }
  834. os_event_set(buf_flush_event);
  835. }
  836. if (!os_thread_count) {
  837. return;
  838. }
  839. os_thread_sleep(100000);
  840. }
  841. ib::warn() << os_thread_count << " threads created by InnoDB"
  842. " had not exited at shutdown!";
  843. ut_ad(0);
  844. }
  845. #ifdef UNIV_DEBUG
  846. # define srv_init_abort(_db_err) \
  847. srv_init_abort_low(create_new_db, __FILE__, __LINE__, _db_err)
  848. #else
  849. # define srv_init_abort(_db_err) \
  850. srv_init_abort_low(create_new_db, _db_err)
  851. #endif /* UNIV_DEBUG */
  852. /** Innobase start-up aborted. Perform cleanup actions.
  853. @param[in] create_new_db TRUE if new db is being created
  854. @param[in] file File name
  855. @param[in] line Line number
  856. @param[in] err Reason for aborting InnoDB startup
  857. @return DB_SUCCESS or error code. */
  858. MY_ATTRIBUTE((warn_unused_result, nonnull))
  859. static
  860. dberr_t
  861. srv_init_abort_low(
  862. bool create_new_db,
  863. #ifdef UNIV_DEBUG
  864. const char* file,
  865. unsigned line,
  866. #endif /* UNIV_DEBUG */
  867. dberr_t err)
  868. {
  869. if (create_new_db) {
  870. ib::error() << "Database creation was aborted"
  871. #ifdef UNIV_DEBUG
  872. " at " << innobase_basename(file) << "[" << line << "]"
  873. #endif /* UNIV_DEBUG */
  874. " with error " << ut_strerr(err) << ". You may need"
  875. " to delete the ibdata1 file before trying to start"
  876. " up again.";
  877. } else {
  878. ib::error() << "Plugin initialization aborted"
  879. #ifdef UNIV_DEBUG
  880. " at " << innobase_basename(file) << "[" << line << "]"
  881. #endif /* UNIV_DEBUG */
  882. " with error " << ut_strerr(err);
  883. }
  884. srv_shutdown_bg_undo_sources();
  885. srv_shutdown_all_bg_threads();
  886. return(err);
  887. }
  888. /** Prepare to delete the redo log files. Flush the dirty pages from all the
  889. buffer pools. Flush the redo log buffer to the redo log file.
  890. @param[in] n_files number of old redo log files
  891. @return lsn upto which data pages have been flushed. */
  892. static
  893. lsn_t
  894. srv_prepare_to_delete_redo_log_files(
  895. ulint n_files)
  896. {
  897. DBUG_ENTER("srv_prepare_to_delete_redo_log_files");
  898. lsn_t flushed_lsn;
  899. ulint pending_io = 0;
  900. ulint count = 0;
  901. if (log_sys.log.subformat != 2) {
  902. srv_log_file_size = 0;
  903. }
  904. do {
  905. /* Clean the buffer pool. */
  906. buf_flush_sync_all_buf_pools();
  907. DBUG_EXECUTE_IF("innodb_log_abort_1", DBUG_RETURN(0););
  908. DBUG_PRINT("ib_log", ("After innodb_log_abort_1"));
  909. log_mutex_enter();
  910. fil_names_clear(log_sys.lsn, false);
  911. flushed_lsn = log_sys.lsn;
  912. {
  913. ib::info info;
  914. if (srv_log_file_size == 0
  915. || (log_sys.log.format & ~log_t::FORMAT_ENCRYPTED)
  916. != log_t::FORMAT_10_4) {
  917. info << "Upgrading redo log: ";
  918. } else if (n_files != srv_n_log_files
  919. || srv_log_file_size
  920. != srv_log_file_size_requested) {
  921. if (srv_encrypt_log
  922. == (my_bool)log_sys.is_encrypted()) {
  923. info << (srv_encrypt_log
  924. ? "Resizing encrypted"
  925. : "Resizing");
  926. } else if (srv_encrypt_log) {
  927. info << "Encrypting and resizing";
  928. } else {
  929. info << "Removing encryption"
  930. " and resizing";
  931. }
  932. info << " redo log from " << n_files
  933. << "*" << srv_log_file_size << " to ";
  934. } else if (srv_encrypt_log) {
  935. info << "Encrypting redo log: ";
  936. } else {
  937. info << "Removing redo log encryption: ";
  938. }
  939. info << srv_n_log_files << "*"
  940. << srv_log_file_size_requested
  941. << " bytes; LSN=" << flushed_lsn;
  942. }
  943. srv_start_lsn = flushed_lsn;
  944. /* Flush the old log files. */
  945. log_mutex_exit();
  946. log_write_up_to(flushed_lsn, true);
  947. /* If innodb_flush_method=O_DSYNC,
  948. we need to explicitly flush the log buffers. */
  949. fil_flush(SRV_LOG_SPACE_FIRST_ID);
  950. ut_ad(flushed_lsn == log_get_lsn());
  951. /* Check if the buffer pools are clean. If not
  952. retry till it is clean. */
  953. pending_io = buf_pool_check_no_pending_io();
  954. if (pending_io > 0) {
  955. count++;
  956. /* Print a message every 60 seconds if we
  957. are waiting to clean the buffer pools */
  958. if (srv_print_verbose_log && count > 600) {
  959. ib::info() << "Waiting for "
  960. << pending_io << " buffer "
  961. << "page I/Os to complete";
  962. count = 0;
  963. }
  964. }
  965. os_thread_sleep(100000);
  966. } while (buf_pool_check_no_pending_io());
  967. DBUG_RETURN(flushed_lsn);
  968. }
  969. /** Start InnoDB.
  970. @param[in] create_new_db whether to create a new database
  971. @return DB_SUCCESS or error code */
  972. dberr_t srv_start(bool create_new_db)
  973. {
  974. lsn_t flushed_lsn;
  975. dberr_t err = DB_SUCCESS;
  976. ulint srv_n_log_files_found = srv_n_log_files;
  977. mtr_t mtr;
  978. char logfilename[10000];
  979. char* logfile0 = NULL;
  980. size_t dirnamelen;
  981. unsigned i = 0;
  982. ut_ad(srv_operation == SRV_OPERATION_NORMAL
  983. || srv_operation == SRV_OPERATION_RESTORE
  984. || srv_operation == SRV_OPERATION_RESTORE_EXPORT);
  985. if (srv_force_recovery == SRV_FORCE_NO_LOG_REDO) {
  986. srv_read_only_mode = true;
  987. }
  988. high_level_read_only = srv_read_only_mode
  989. || srv_force_recovery > SRV_FORCE_NO_IBUF_MERGE
  990. || srv_sys_space.created_new_raw();
  991. /* Reset the start state. */
  992. srv_start_state = SRV_START_STATE_NONE;
  993. compile_time_assert(sizeof(ulint) == sizeof(void*));
  994. #ifdef UNIV_DEBUG
  995. ib::info() << "!!!!!!!! UNIV_DEBUG switched on !!!!!!!!!";
  996. #endif
  997. #ifdef UNIV_IBUF_DEBUG
  998. ib::info() << "!!!!!!!! UNIV_IBUF_DEBUG switched on !!!!!!!!!";
  999. #endif
  1000. #ifdef UNIV_LOG_LSN_DEBUG
  1001. ib::info() << "!!!!!!!! UNIV_LOG_LSN_DEBUG switched on !!!!!!!!!";
  1002. #endif /* UNIV_LOG_LSN_DEBUG */
  1003. #if defined(COMPILER_HINTS_ENABLED)
  1004. ib::info() << "Compiler hints enabled.";
  1005. #endif /* defined(COMPILER_HINTS_ENABLED) */
  1006. #ifdef _WIN32
  1007. ib::info() << "Mutexes and rw_locks use Windows interlocked functions";
  1008. #else
  1009. ib::info() << "Mutexes and rw_locks use GCC atomic builtins";
  1010. #endif
  1011. ib::info() << MUTEX_TYPE;
  1012. ib::info() << "Compressed tables use zlib " ZLIB_VERSION
  1013. #ifdef UNIV_ZIP_DEBUG
  1014. " with validation"
  1015. #endif /* UNIV_ZIP_DEBUG */
  1016. ;
  1017. #ifdef UNIV_ZIP_COPY
  1018. ib::info() << "and extra copying";
  1019. #endif /* UNIV_ZIP_COPY */
  1020. /* Since InnoDB does not currently clean up all its internal data
  1021. structures in MySQL Embedded Server Library server_end(), we
  1022. print an error message if someone tries to start up InnoDB a
  1023. second time during the process lifetime. */
  1024. if (srv_start_has_been_called) {
  1025. ib::error() << "Startup called second time"
  1026. " during the process lifetime."
  1027. " In the MySQL Embedded Server Library"
  1028. " you cannot call server_init() more than"
  1029. " once during the process lifetime.";
  1030. }
  1031. srv_start_has_been_called = true;
  1032. srv_is_being_started = true;
  1033. /* Register performance schema stages before any real work has been
  1034. started which may need to be instrumented. */
  1035. mysql_stage_register("innodb", srv_stages, UT_ARR_SIZE(srv_stages));
  1036. /* Set the maximum number of threads which can wait for a semaphore
  1037. inside InnoDB: this is the 'sync wait array' size, as well as the
  1038. maximum number of threads that can wait in the 'srv_conc array' for
  1039. their time to enter InnoDB. */
  1040. srv_max_n_threads = 1 /* io_ibuf_thread */
  1041. + 1 /* io_log_thread */
  1042. + 1 /* srv_print_monitor_task */
  1043. + 1 /* srv_purge_coordinator_thread */
  1044. + 1 /* buf_dump_thread */
  1045. + 1 /* dict_stats_thread */
  1046. + 1 /* fts_optimize_thread */
  1047. + 1 /* recv_writer_thread */
  1048. + 1 /* trx_rollback_all_recovered */
  1049. + 128 /* added as margin, for use of
  1050. InnoDB Memcached etc. */
  1051. + max_connections
  1052. + srv_n_read_io_threads
  1053. + srv_n_write_io_threads
  1054. + srv_n_purge_threads
  1055. + srv_n_page_cleaners
  1056. /* FTS Parallel Sort */
  1057. + fts_sort_pll_degree * FTS_NUM_AUX_INDEX
  1058. * max_connections;
  1059. srv_boot();
  1060. ib::info() << ut_crc32_implementation;
  1061. if (!srv_read_only_mode) {
  1062. mutex_create(LATCH_ID_SRV_MONITOR_FILE,
  1063. &srv_monitor_file_mutex);
  1064. if (srv_innodb_status) {
  1065. srv_monitor_file_name = static_cast<char*>(
  1066. ut_malloc_nokey(
  1067. strlen(fil_path_to_mysql_datadir)
  1068. + 20 + sizeof "/innodb_status."));
  1069. sprintf(srv_monitor_file_name,
  1070. "%s/innodb_status." ULINTPF,
  1071. fil_path_to_mysql_datadir,
  1072. os_proc_get_number());
  1073. srv_monitor_file = my_fopen(srv_monitor_file_name,
  1074. O_RDWR|O_TRUNC|O_CREAT,
  1075. MYF(MY_WME));
  1076. if (!srv_monitor_file) {
  1077. ib::error() << "Unable to create "
  1078. << srv_monitor_file_name << ": "
  1079. << strerror(errno);
  1080. if (err == DB_SUCCESS) {
  1081. err = DB_ERROR;
  1082. }
  1083. }
  1084. } else {
  1085. srv_monitor_file_name = NULL;
  1086. srv_monitor_file = os_file_create_tmpfile();
  1087. if (!srv_monitor_file && err == DB_SUCCESS) {
  1088. err = DB_ERROR;
  1089. }
  1090. }
  1091. mutex_create(LATCH_ID_SRV_MISC_TMPFILE,
  1092. &srv_misc_tmpfile_mutex);
  1093. srv_misc_tmpfile = os_file_create_tmpfile();
  1094. if (!srv_misc_tmpfile && err == DB_SUCCESS) {
  1095. err = DB_ERROR;
  1096. }
  1097. }
  1098. if (err != DB_SUCCESS) {
  1099. return(srv_init_abort(err));
  1100. }
  1101. srv_n_file_io_threads = srv_n_read_io_threads;
  1102. srv_n_file_io_threads += srv_n_write_io_threads;
  1103. if (!srv_read_only_mode) {
  1104. /* Add the log and ibuf IO threads. */
  1105. srv_n_file_io_threads += 2;
  1106. } else {
  1107. ib::info() << "Disabling background log and ibuf IO write"
  1108. << " threads.";
  1109. }
  1110. ut_a(srv_n_file_io_threads <= SRV_MAX_N_IO_THREADS);
  1111. if (!os_aio_init(srv_n_read_io_threads,
  1112. srv_n_write_io_threads,
  1113. SRV_MAX_N_PENDING_SYNC_IOS)) {
  1114. ib::error() << "Cannot initialize AIO sub-system";
  1115. return(srv_init_abort(DB_ERROR));
  1116. }
  1117. fil_system.create(srv_file_per_table ? 50000 : 5000);
  1118. double size;
  1119. char unit;
  1120. if (srv_buf_pool_size >= 1024 * 1024 * 1024) {
  1121. size = ((double) srv_buf_pool_size) / (1024 * 1024 * 1024);
  1122. unit = 'G';
  1123. } else {
  1124. size = ((double) srv_buf_pool_size) / (1024 * 1024);
  1125. unit = 'M';
  1126. }
  1127. double chunk_size;
  1128. char chunk_unit;
  1129. if (srv_buf_pool_chunk_unit >= 1024 * 1024 * 1024) {
  1130. chunk_size = srv_buf_pool_chunk_unit / 1024.0 / 1024 / 1024;
  1131. chunk_unit = 'G';
  1132. } else {
  1133. chunk_size = srv_buf_pool_chunk_unit / 1024.0 / 1024;
  1134. chunk_unit = 'M';
  1135. }
  1136. ib::info() << "Initializing buffer pool, total size = "
  1137. << size << unit << ", instances = " << srv_buf_pool_instances
  1138. << ", chunk size = " << chunk_size << chunk_unit;
  1139. err = buf_pool_init(srv_buf_pool_size, srv_buf_pool_instances);
  1140. if (err != DB_SUCCESS) {
  1141. ib::error() << "Cannot allocate memory for the buffer pool";
  1142. return(srv_init_abort(DB_ERROR));
  1143. }
  1144. ib::info() << "Completed initialization of buffer pool";
  1145. #ifdef UNIV_DEBUG
  1146. /* We have observed deadlocks with a 5MB buffer pool but
  1147. the actual lower limit could very well be a little higher. */
  1148. if (srv_buf_pool_size <= 5 * 1024 * 1024) {
  1149. ib::info() << "Small buffer pool size ("
  1150. << srv_buf_pool_size / 1024 / 1024
  1151. << "M), the flst_validate() debug function can cause a"
  1152. << " deadlock if the buffer pool fills up.";
  1153. }
  1154. #endif /* UNIV_DEBUG */
  1155. log_sys.create();
  1156. recv_sys.create();
  1157. lock_sys.create(srv_lock_table_size);
  1158. if (!srv_read_only_mode) {
  1159. buf_flush_page_cleaner_init();
  1160. buf_page_cleaner_is_active = true;
  1161. os_thread_create(buf_flush_page_cleaner_coordinator,
  1162. NULL, NULL);
  1163. /* Create page cleaner workers if needed. For example
  1164. mariabackup could set srv_n_page_cleaners = 0. */
  1165. if (srv_n_page_cleaners > 1) {
  1166. buf_flush_set_page_cleaner_thread_cnt(srv_n_page_cleaners);
  1167. }
  1168. #ifdef UNIV_LINUX
  1169. /* Wait for the setpriority() call to finish. */
  1170. os_event_wait(recv_sys.flush_end);
  1171. #endif /* UNIV_LINUX */
  1172. srv_start_state_set(SRV_START_STATE_IO);
  1173. }
  1174. srv_startup_is_before_trx_rollback_phase = !create_new_db;
  1175. /* Check if undo tablespaces and redo log files exist before creating
  1176. a new system tablespace */
  1177. if (create_new_db) {
  1178. err = srv_check_undo_redo_logs_exists();
  1179. if (err != DB_SUCCESS) {
  1180. return(srv_init_abort(DB_ERROR));
  1181. }
  1182. recv_sys.debug_free();
  1183. }
  1184. /* Open or create the data files. */
  1185. ulint sum_of_new_sizes;
  1186. err = srv_sys_space.open_or_create(
  1187. false, create_new_db, &sum_of_new_sizes, &flushed_lsn);
  1188. switch (err) {
  1189. case DB_SUCCESS:
  1190. break;
  1191. case DB_CANNOT_OPEN_FILE:
  1192. ib::error()
  1193. << "Could not open or create the system tablespace. If"
  1194. " you tried to add new data files to the system"
  1195. " tablespace, and it failed here, you should now"
  1196. " edit innodb_data_file_path in my.cnf back to what"
  1197. " it was, and remove the new ibdata files InnoDB"
  1198. " created in this failed attempt. InnoDB only wrote"
  1199. " those files full of zeros, but did not yet use"
  1200. " them in any way. But be careful: do not remove"
  1201. " old data files which contain your precious data!";
  1202. /* fall through */
  1203. default:
  1204. /* Other errors might come from Datafile::validate_first_page() */
  1205. return(srv_init_abort(err));
  1206. }
  1207. dirnamelen = strlen(srv_log_group_home_dir);
  1208. ut_a(dirnamelen < (sizeof logfilename) - 10 - sizeof "ib_logfile");
  1209. memcpy(logfilename, srv_log_group_home_dir, dirnamelen);
  1210. /* Add a path separator if needed. */
  1211. if (dirnamelen && logfilename[dirnamelen - 1] != OS_PATH_SEPARATOR) {
  1212. logfilename[dirnamelen++] = OS_PATH_SEPARATOR;
  1213. }
  1214. srv_log_file_size_requested = srv_log_file_size;
  1215. if (innodb_encrypt_temporary_tables && !log_crypt_init()) {
  1216. return srv_init_abort(DB_ERROR);
  1217. }
  1218. if (create_new_db) {
  1219. buf_flush_sync_all_buf_pools();
  1220. flushed_lsn = log_get_lsn();
  1221. err = create_log_files(
  1222. logfilename, dirnamelen, flushed_lsn, logfile0);
  1223. if (err != DB_SUCCESS) {
  1224. return(srv_init_abort(err));
  1225. }
  1226. } else {
  1227. srv_log_file_size = 0;
  1228. for (i = 0; i < SRV_N_LOG_FILES_MAX; i++) {
  1229. os_file_stat_t stat_info;
  1230. sprintf(logfilename + dirnamelen,
  1231. "ib_logfile%u", i);
  1232. err = os_file_get_status(
  1233. logfilename, &stat_info, false,
  1234. srv_read_only_mode);
  1235. if (err == DB_NOT_FOUND) {
  1236. if (i == 0) {
  1237. if (srv_operation
  1238. == SRV_OPERATION_RESTORE
  1239. || srv_operation
  1240. == SRV_OPERATION_RESTORE_EXPORT) {
  1241. return(DB_SUCCESS);
  1242. }
  1243. }
  1244. /* opened all files */
  1245. break;
  1246. }
  1247. if (stat_info.type != OS_FILE_TYPE_FILE) {
  1248. break;
  1249. }
  1250. if (!srv_file_check_mode(logfilename)) {
  1251. return(srv_init_abort(DB_ERROR));
  1252. }
  1253. const os_offset_t size = stat_info.size;
  1254. ut_a(size != (os_offset_t) -1);
  1255. if (size & (OS_FILE_LOG_BLOCK_SIZE - 1)) {
  1256. ib::error() << "Log file " << logfilename
  1257. << " size " << size << " is not a"
  1258. " multiple of 512 bytes";
  1259. return(srv_init_abort(DB_ERROR));
  1260. }
  1261. if (i == 0) {
  1262. if (size == 0
  1263. && (srv_operation
  1264. == SRV_OPERATION_RESTORE
  1265. || srv_operation
  1266. == SRV_OPERATION_RESTORE_EXPORT)) {
  1267. /* Tolerate an empty ib_logfile0
  1268. from a previous run of
  1269. mariabackup --prepare. */
  1270. return(DB_SUCCESS);
  1271. }
  1272. /* The first log file must consist of
  1273. at least the following 512-byte pages:
  1274. header, checkpoint page 1, empty,
  1275. checkpoint page 2, redo log page(s).
  1276. Mariabackup --prepare would create an
  1277. empty ib_logfile0. Tolerate it if there
  1278. are no other ib_logfile* files. */
  1279. if ((size != 0 || i != 0)
  1280. && size <= OS_FILE_LOG_BLOCK_SIZE * 4) {
  1281. ib::error() << "Log file "
  1282. << logfilename << " size "
  1283. << size << " is too small";
  1284. return(srv_init_abort(DB_ERROR));
  1285. }
  1286. srv_log_file_size = size;
  1287. } else if (size != srv_log_file_size) {
  1288. ib::error() << "Log file " << logfilename
  1289. << " is of different size " << size
  1290. << " bytes than other log files "
  1291. << srv_log_file_size << " bytes!";
  1292. return(srv_init_abort(DB_ERROR));
  1293. }
  1294. }
  1295. if (srv_log_file_size == 0) {
  1296. if (flushed_lsn < lsn_t(1000)) {
  1297. ib::error()
  1298. << "Cannot create log files because"
  1299. " data files are corrupt or the"
  1300. " database was not shut down cleanly"
  1301. " after creating the data files.";
  1302. return srv_init_abort(DB_ERROR);
  1303. }
  1304. strcpy(logfilename + dirnamelen, "ib_logfile0");
  1305. srv_log_file_size = srv_log_file_size_requested;
  1306. err = create_log_files(
  1307. logfilename, dirnamelen,
  1308. flushed_lsn, logfile0);
  1309. if (err == DB_SUCCESS) {
  1310. err = create_log_files_rename(
  1311. logfilename, dirnamelen,
  1312. flushed_lsn, logfile0);
  1313. }
  1314. if (err != DB_SUCCESS) {
  1315. return(srv_init_abort(err));
  1316. }
  1317. /* Suppress the message about
  1318. crash recovery. */
  1319. flushed_lsn = log_get_lsn();
  1320. goto files_checked;
  1321. }
  1322. srv_n_log_files_found = i;
  1323. /* Create the in-memory file space objects. */
  1324. sprintf(logfilename + dirnamelen, "ib_logfile%u", 0);
  1325. /* Disable the doublewrite buffer for log files. */
  1326. fil_space_t* log_space = fil_space_create(
  1327. "innodb_redo_log",
  1328. SRV_LOG_SPACE_FIRST_ID, 0,
  1329. FIL_TYPE_LOG,
  1330. NULL /* no encryption yet */);
  1331. ut_a(fil_validate());
  1332. ut_a(log_space);
  1333. ut_a(srv_log_file_size <= log_group_max_size);
  1334. const ulint size = 1 + ulint((srv_log_file_size - 1)
  1335. >> srv_page_size_shift);
  1336. for (unsigned j = 0; j < srv_n_log_files_found; j++) {
  1337. sprintf(logfilename + dirnamelen, "ib_logfile%u", j);
  1338. log_space->add(logfilename, OS_FILE_CLOSED, size,
  1339. false, false);
  1340. }
  1341. log_sys.log.create(srv_n_log_files_found);
  1342. if (!log_set_capacity(srv_log_file_size_requested)) {
  1343. return(srv_init_abort(DB_ERROR));
  1344. }
  1345. }
  1346. files_checked:
  1347. /* Open all log files and data files in the system
  1348. tablespace: we keep them open until database
  1349. shutdown */
  1350. fil_open_log_and_system_tablespace_files();
  1351. ut_d(fil_system.sys_space->recv_size = srv_sys_space_size_debug);
  1352. err = srv_undo_tablespaces_init(create_new_db);
  1353. /* If the force recovery is set very high then we carry on regardless
  1354. of all errors. Basically this is fingers crossed mode. */
  1355. if (err != DB_SUCCESS
  1356. && srv_force_recovery < SRV_FORCE_NO_UNDO_LOG_SCAN) {
  1357. return(srv_init_abort(err));
  1358. }
  1359. /* Initialize objects used by dict stats gathering thread, which
  1360. can also be used by recovery if it tries to drop some table */
  1361. if (!srv_read_only_mode) {
  1362. dict_stats_init();
  1363. }
  1364. trx_sys.create();
  1365. if (create_new_db) {
  1366. ut_a(!srv_read_only_mode);
  1367. mtr_start(&mtr);
  1368. ut_ad(fil_system.sys_space->id == 0);
  1369. compile_time_assert(TRX_SYS_SPACE == 0);
  1370. compile_time_assert(IBUF_SPACE_ID == 0);
  1371. fsp_header_init(fil_system.sys_space, sum_of_new_sizes, &mtr);
  1372. ulint ibuf_root = btr_create(
  1373. DICT_CLUSTERED | DICT_IBUF, fil_system.sys_space,
  1374. DICT_IBUF_ID_MIN, dict_ind_redundant, &mtr);
  1375. mtr_commit(&mtr);
  1376. if (ibuf_root == FIL_NULL) {
  1377. return(srv_init_abort(DB_ERROR));
  1378. }
  1379. ut_ad(ibuf_root == IBUF_TREE_ROOT_PAGE_NO);
  1380. /* To maintain backward compatibility we create only
  1381. the first rollback segment before the double write buffer.
  1382. All the remaining rollback segments will be created later,
  1383. after the double write buffer has been created. */
  1384. trx_sys_create_sys_pages();
  1385. trx_lists_init_at_db_start();
  1386. err = dict_create();
  1387. if (err != DB_SUCCESS) {
  1388. return(srv_init_abort(err));
  1389. }
  1390. buf_flush_sync_all_buf_pools();
  1391. flushed_lsn = log_get_lsn();
  1392. err = fil_write_flushed_lsn(flushed_lsn);
  1393. if (err == DB_SUCCESS) {
  1394. err = create_log_files_rename(
  1395. logfilename, dirnamelen,
  1396. flushed_lsn, logfile0);
  1397. }
  1398. if (err != DB_SUCCESS) {
  1399. return(srv_init_abort(err));
  1400. }
  1401. } else {
  1402. /* Work around the bug that we were performing a dirty read of
  1403. at least the TRX_SYS page into the buffer pool above, without
  1404. reading or applying any redo logs.
  1405. MDEV-19229 FIXME: Remove the dirty reads and this call.
  1406. Add an assertion that the buffer pool is empty. */
  1407. buf_pool_invalidate();
  1408. /* We always try to do a recovery, even if the database had
  1409. been shut down normally: this is the normal startup path */
  1410. err = recv_recovery_from_checkpoint_start(flushed_lsn);
  1411. recv_sys.dblwr.pages.clear();
  1412. if (err != DB_SUCCESS) {
  1413. return(srv_init_abort(err));
  1414. }
  1415. switch (srv_operation) {
  1416. case SRV_OPERATION_NORMAL:
  1417. case SRV_OPERATION_RESTORE_EXPORT:
  1418. /* Initialize the change buffer. */
  1419. err = dict_boot();
  1420. if (err != DB_SUCCESS) {
  1421. return(srv_init_abort(err));
  1422. }
  1423. /* fall through */
  1424. case SRV_OPERATION_RESTORE:
  1425. /* This must precede
  1426. recv_apply_hashed_log_recs(true). */
  1427. trx_lists_init_at_db_start();
  1428. break;
  1429. case SRV_OPERATION_RESTORE_DELTA:
  1430. case SRV_OPERATION_BACKUP:
  1431. ut_ad(!"wrong mariabackup mode");
  1432. }
  1433. if (srv_force_recovery < SRV_FORCE_NO_LOG_REDO) {
  1434. /* Apply the hashed log records to the
  1435. respective file pages, for the last batch of
  1436. recv_group_scan_log_recs(). */
  1437. recv_apply_hashed_log_recs(true);
  1438. if (recv_sys.found_corrupt_log
  1439. || recv_sys.found_corrupt_fs) {
  1440. return(srv_init_abort(DB_CORRUPTION));
  1441. }
  1442. DBUG_PRINT("ib_log", ("apply completed"));
  1443. if (recv_needed_recovery) {
  1444. trx_sys_print_mysql_binlog_offset();
  1445. }
  1446. }
  1447. if (!srv_read_only_mode) {
  1448. const ulint flags = FSP_FLAGS_PAGE_SSIZE();
  1449. for (ulint id = 0; id <= srv_undo_tablespaces; id++) {
  1450. if (fil_space_t* space = fil_space_get(id)) {
  1451. fsp_flags_try_adjust(space, flags);
  1452. }
  1453. }
  1454. if (sum_of_new_sizes > 0) {
  1455. /* New data file(s) were added */
  1456. mtr.start();
  1457. buf_block_t* block = buf_page_get(
  1458. page_id_t(0, 0), 0,
  1459. RW_SX_LATCH, &mtr);
  1460. ulint size = mach_read_from_4(
  1461. FSP_HEADER_OFFSET + FSP_SIZE
  1462. + block->frame);
  1463. ut_ad(size == fil_system.sys_space
  1464. ->size_in_header);
  1465. size += sum_of_new_sizes;
  1466. mlog_write_ulint(FSP_HEADER_OFFSET + FSP_SIZE
  1467. + block->frame, size,
  1468. MLOG_4BYTES, &mtr);
  1469. fil_system.sys_space->size_in_header = size;
  1470. mtr.commit();
  1471. /* Immediately write the log record about
  1472. increased tablespace size to disk, so that it
  1473. is durable even if mysqld would crash
  1474. quickly */
  1475. log_buffer_flush_to_disk();
  1476. }
  1477. }
  1478. #ifdef UNIV_DEBUG
  1479. {
  1480. mtr.start();
  1481. buf_block_t* block = buf_page_get(page_id_t(0, 0), 0,
  1482. RW_S_LATCH, &mtr);
  1483. ut_ad(mach_read_from_4(FSP_SIZE + FSP_HEADER_OFFSET
  1484. + block->frame)
  1485. == fil_system.sys_space->size_in_header);
  1486. mtr.commit();
  1487. }
  1488. #endif
  1489. const ulint tablespace_size_in_header
  1490. = fil_system.sys_space->size_in_header;
  1491. const ulint sum_of_data_file_sizes
  1492. = srv_sys_space.get_sum_of_sizes();
  1493. /* Compare the system tablespace file size to what is
  1494. stored in FSP_SIZE. In srv_sys_space.open_or_create()
  1495. we already checked that the file sizes match the
  1496. innodb_data_file_path specification. */
  1497. if (srv_read_only_mode
  1498. || sum_of_data_file_sizes == tablespace_size_in_header) {
  1499. /* Do not complain about the size. */
  1500. } else if (!srv_sys_space.can_auto_extend_last_file()
  1501. || sum_of_data_file_sizes
  1502. < tablespace_size_in_header) {
  1503. ib::error() << "Tablespace size stored in header is "
  1504. << tablespace_size_in_header
  1505. << " pages, but the sum of data file sizes is "
  1506. << sum_of_data_file_sizes << " pages";
  1507. if (srv_force_recovery == 0
  1508. && sum_of_data_file_sizes
  1509. < tablespace_size_in_header) {
  1510. ib::error() <<
  1511. "Cannot start InnoDB. The tail of"
  1512. " the system tablespace is"
  1513. " missing. Have you edited"
  1514. " innodb_data_file_path in my.cnf"
  1515. " in an inappropriate way, removing"
  1516. " data files from there?"
  1517. " You can set innodb_force_recovery=1"
  1518. " in my.cnf to force"
  1519. " a startup if you are trying to"
  1520. " recover a badly corrupt database.";
  1521. return(srv_init_abort(DB_ERROR));
  1522. }
  1523. }
  1524. /* recv_recovery_from_checkpoint_finish needs trx lists which
  1525. are initialized in trx_lists_init_at_db_start(). */
  1526. recv_recovery_from_checkpoint_finish();
  1527. if (srv_operation == SRV_OPERATION_RESTORE
  1528. || srv_operation == SRV_OPERATION_RESTORE_EXPORT) {
  1529. /* After applying the redo log from
  1530. SRV_OPERATION_BACKUP, flush the changes
  1531. to the data files and truncate or delete the log.
  1532. Unless --export is specified, no further change to
  1533. InnoDB files is needed. */
  1534. ut_ad(!srv_force_recovery);
  1535. ut_ad(srv_n_log_files_found <= 1);
  1536. ut_ad(recv_no_log_write);
  1537. buf_flush_sync_all_buf_pools();
  1538. err = fil_write_flushed_lsn(log_get_lsn());
  1539. ut_ad(!buf_pool_check_no_pending_io());
  1540. fil_close_log_files(true);
  1541. if (err == DB_SUCCESS) {
  1542. bool trunc = srv_operation
  1543. == SRV_OPERATION_RESTORE;
  1544. /* Delete subsequent log files. */
  1545. delete_log_files(logfilename, dirnamelen,
  1546. (uint)srv_n_log_files_found, trunc);
  1547. if (trunc) {
  1548. /* Truncate the first log file. */
  1549. strcpy(logfilename + dirnamelen,
  1550. "ib_logfile0");
  1551. FILE* f = fopen(logfilename, "w");
  1552. fclose(f);
  1553. }
  1554. }
  1555. return(err);
  1556. }
  1557. /* Upgrade or resize or rebuild the redo logs before
  1558. generating any dirty pages, so that the old redo log
  1559. files will not be written to. */
  1560. if (srv_force_recovery == SRV_FORCE_NO_LOG_REDO) {
  1561. /* Completely ignore the redo log. */
  1562. } else if (srv_read_only_mode) {
  1563. /* Leave the redo log alone. */
  1564. } else if (srv_log_file_size_requested == srv_log_file_size
  1565. && srv_n_log_files_found == srv_n_log_files
  1566. && log_sys.log.format
  1567. == (srv_encrypt_log
  1568. ? log_t::FORMAT_ENC_10_4
  1569. : log_t::FORMAT_10_4)
  1570. && log_sys.log.subformat == 2) {
  1571. /* No need to add or remove encryption,
  1572. upgrade, downgrade, or resize. */
  1573. } else {
  1574. /* Prepare to delete the old redo log files */
  1575. flushed_lsn = srv_prepare_to_delete_redo_log_files(i);
  1576. DBUG_EXECUTE_IF("innodb_log_abort_1",
  1577. return(srv_init_abort(DB_ERROR)););
  1578. /* Prohibit redo log writes from any other
  1579. threads until creating a log checkpoint at the
  1580. end of create_log_files(). */
  1581. ut_d(recv_no_log_write = true);
  1582. ut_ad(!buf_pool_check_no_pending_io());
  1583. DBUG_EXECUTE_IF("innodb_log_abort_3",
  1584. return(srv_init_abort(DB_ERROR)););
  1585. DBUG_PRINT("ib_log", ("After innodb_log_abort_3"));
  1586. /* Stamp the LSN to the data files. */
  1587. err = fil_write_flushed_lsn(flushed_lsn);
  1588. DBUG_EXECUTE_IF("innodb_log_abort_4", err = DB_ERROR;);
  1589. DBUG_PRINT("ib_log", ("After innodb_log_abort_4"));
  1590. if (err != DB_SUCCESS) {
  1591. return(srv_init_abort(err));
  1592. }
  1593. /* Close and free the redo log files, so that
  1594. we can replace them. */
  1595. fil_close_log_files(true);
  1596. DBUG_EXECUTE_IF("innodb_log_abort_5",
  1597. return(srv_init_abort(DB_ERROR)););
  1598. DBUG_PRINT("ib_log", ("After innodb_log_abort_5"));
  1599. ib::info() << "Starting to delete and rewrite log"
  1600. " files.";
  1601. srv_log_file_size = srv_log_file_size_requested;
  1602. err = create_log_files(
  1603. logfilename, dirnamelen, flushed_lsn,
  1604. logfile0);
  1605. if (err == DB_SUCCESS) {
  1606. err = create_log_files_rename(
  1607. logfilename, dirnamelen, flushed_lsn,
  1608. logfile0);
  1609. }
  1610. if (err != DB_SUCCESS) {
  1611. return(srv_init_abort(err));
  1612. }
  1613. }
  1614. }
  1615. ut_ad(err == DB_SUCCESS);
  1616. ut_a(sum_of_new_sizes != ULINT_UNDEFINED);
  1617. /* Create the doublewrite buffer to a new tablespace */
  1618. if (!srv_read_only_mode && srv_force_recovery < SRV_FORCE_NO_TRX_UNDO
  1619. && !buf_dblwr_create()) {
  1620. return(srv_init_abort(DB_ERROR));
  1621. }
  1622. /* Here the double write buffer has already been created and so
  1623. any new rollback segments will be allocated after the double
  1624. write buffer. The default segment should already exist.
  1625. We create the new segments only if it's a new database or
  1626. the database was shutdown cleanly. */
  1627. /* Note: When creating the extra rollback segments during an upgrade
  1628. we violate the latching order, even if the change buffer is empty.
  1629. We make an exception in sync0sync.cc and check srv_is_being_started
  1630. for that violation. It cannot create a deadlock because we are still
  1631. running in single threaded mode essentially. Only the IO threads
  1632. should be running at this stage. */
  1633. if (!trx_sys_create_rsegs()) {
  1634. return(srv_init_abort(DB_ERROR));
  1635. }
  1636. if (!create_new_db) {
  1637. /* Validate a few system page types that were left
  1638. uninitialized before MySQL or MariaDB 5.5. */
  1639. if (!high_level_read_only) {
  1640. ut_ad(srv_force_recovery <= SRV_FORCE_NO_IBUF_MERGE);
  1641. buf_block_t* block;
  1642. mtr.start();
  1643. /* Bitmap page types will be reset in
  1644. buf_dblwr_check_block() without redo logging. */
  1645. block = buf_page_get(
  1646. page_id_t(IBUF_SPACE_ID,
  1647. FSP_IBUF_HEADER_PAGE_NO),
  1648. 0, RW_X_LATCH, &mtr);
  1649. fil_block_check_type(*block, FIL_PAGE_TYPE_SYS, &mtr);
  1650. /* Already MySQL 3.23.53 initialized
  1651. FSP_IBUF_TREE_ROOT_PAGE_NO to
  1652. FIL_PAGE_INDEX. No need to reset that one. */
  1653. block = buf_page_get(
  1654. page_id_t(TRX_SYS_SPACE, TRX_SYS_PAGE_NO),
  1655. 0, RW_X_LATCH, &mtr);
  1656. fil_block_check_type(*block, FIL_PAGE_TYPE_TRX_SYS,
  1657. &mtr);
  1658. block = buf_page_get(
  1659. page_id_t(TRX_SYS_SPACE,
  1660. FSP_FIRST_RSEG_PAGE_NO),
  1661. 0, RW_X_LATCH, &mtr);
  1662. fil_block_check_type(*block, FIL_PAGE_TYPE_SYS, &mtr);
  1663. block = buf_page_get(
  1664. page_id_t(TRX_SYS_SPACE, FSP_DICT_HDR_PAGE_NO),
  1665. 0, RW_X_LATCH, &mtr);
  1666. fil_block_check_type(*block, FIL_PAGE_TYPE_SYS, &mtr);
  1667. mtr.commit();
  1668. /* Roll back any recovered data dictionary
  1669. transactions, so that the data dictionary
  1670. tables will be free of any locks. The data
  1671. dictionary latch should guarantee that there
  1672. is at most one data dictionary transaction
  1673. active at a time. */
  1674. if (srv_force_recovery < SRV_FORCE_NO_TRX_UNDO) {
  1675. /* If the following call is ever
  1676. removed, the first-time
  1677. ha_innobase::open() must hold (or
  1678. acquire and release) a table lock that
  1679. conflicts with
  1680. trx_resurrect_table_locks(), to ensure
  1681. that any recovered incomplete ALTER
  1682. TABLE will have been rolled
  1683. back. Otherwise, dict_table_t::instant
  1684. could be cleared by rollback invoking
  1685. dict_index_t::clear_instant_alter()
  1686. while open table handles exist in
  1687. client connections. */
  1688. trx_rollback_recovered(false);
  1689. }
  1690. }
  1691. /* FIXME: Skip the following if srv_read_only_mode,
  1692. while avoiding "Allocated tablespace ID" warnings. */
  1693. if (srv_force_recovery <= SRV_FORCE_NO_IBUF_MERGE) {
  1694. /* Open or Create SYS_TABLESPACES and SYS_DATAFILES
  1695. so that tablespace names and other metadata can be
  1696. found. */
  1697. err = dict_create_or_check_sys_tablespace();
  1698. if (err != DB_SUCCESS) {
  1699. return(srv_init_abort(err));
  1700. }
  1701. /* The following call is necessary for the insert
  1702. buffer to work with multiple tablespaces. We must
  1703. know the mapping between space id's and .ibd file
  1704. names.
  1705. In a crash recovery, we check that the info in data
  1706. dictionary is consistent with what we already know
  1707. about space id's from the calls to fil_ibd_load().
  1708. In a normal startup, we create the space objects for
  1709. every table in the InnoDB data dictionary that has
  1710. an .ibd file.
  1711. We also determine the maximum tablespace id used. */
  1712. dict_check_tablespaces_and_store_max_id();
  1713. }
  1714. if (srv_force_recovery < SRV_FORCE_NO_TRX_UNDO
  1715. && !srv_read_only_mode) {
  1716. /* Drop partially created indexes. */
  1717. row_merge_drop_temp_indexes();
  1718. /* Drop garbage tables. */
  1719. row_mysql_drop_garbage_tables();
  1720. /* Drop any auxiliary tables that were not
  1721. dropped when the parent table was
  1722. dropped. This can happen if the parent table
  1723. was dropped but the server crashed before the
  1724. auxiliary tables were dropped. */
  1725. fts_drop_orphaned_tables();
  1726. /* Rollback incomplete non-DDL transactions */
  1727. trx_rollback_is_active = true;
  1728. os_thread_create(trx_rollback_all_recovered, 0, 0);
  1729. }
  1730. }
  1731. srv_startup_is_before_trx_rollback_phase = false;
  1732. if (!srv_read_only_mode) {
  1733. /* timer task which watches the timeouts
  1734. for lock waits */
  1735. lock_sys.timeout_timer.reset(srv_thread_pool->create_timer(
  1736. lock_wait_timeout_task));
  1737. DBUG_EXECUTE_IF("innodb_skip_monitors", goto skip_monitors;);
  1738. /* Create the task which warns of long semaphore waits */
  1739. srv_start_periodic_timer(srv_error_monitor_timer, srv_error_monitor_task, 1000);
  1740. srv_start_periodic_timer(srv_monitor_timer, srv_monitor_task, 5000);
  1741. srv_start_state |= SRV_START_STATE_LOCK_SYS
  1742. | SRV_START_STATE_MONITOR;
  1743. #ifndef DBUG_OFF
  1744. skip_monitors:
  1745. #endif
  1746. ut_ad(srv_force_recovery >= SRV_FORCE_NO_UNDO_LOG_SCAN
  1747. || !purge_sys.enabled());
  1748. if (srv_force_recovery < SRV_FORCE_NO_BACKGROUND) {
  1749. srv_undo_sources = true;
  1750. /* Create the dict stats gathering task */
  1751. dict_stats_start();
  1752. /* Create the thread that will optimize the
  1753. FULLTEXT search index subsystem. */
  1754. fts_optimize_init();
  1755. }
  1756. }
  1757. /* Create the SYS_FOREIGN and SYS_FOREIGN_COLS system tables */
  1758. err = dict_create_or_check_foreign_constraint_tables();
  1759. if (err == DB_SUCCESS) {
  1760. err = dict_create_or_check_sys_tablespace();
  1761. if (err == DB_SUCCESS) {
  1762. err = dict_create_or_check_sys_virtual();
  1763. }
  1764. }
  1765. switch (err) {
  1766. case DB_SUCCESS:
  1767. break;
  1768. case DB_READ_ONLY:
  1769. if (srv_force_recovery >= SRV_FORCE_NO_TRX_UNDO) {
  1770. break;
  1771. }
  1772. ib::error() << "Cannot create system tables in read-only mode";
  1773. /* fall through */
  1774. default:
  1775. return(srv_init_abort(err));
  1776. }
  1777. if (!srv_read_only_mode && srv_operation == SRV_OPERATION_NORMAL) {
  1778. /* Initialize the innodb_temporary tablespace and keep
  1779. it open until shutdown. */
  1780. err = srv_open_tmp_tablespace(create_new_db);
  1781. if (err != DB_SUCCESS) {
  1782. return(srv_init_abort(err));
  1783. }
  1784. trx_temp_rseg_create();
  1785. if (srv_force_recovery < SRV_FORCE_NO_BACKGROUND) {
  1786. srv_start_periodic_timer(srv_master_timer, srv_master_callback, 1000);
  1787. }
  1788. }
  1789. if (!srv_read_only_mode && srv_operation == SRV_OPERATION_NORMAL
  1790. && srv_force_recovery < SRV_FORCE_NO_BACKGROUND) {
  1791. srv_init_purge_tasks(srv_n_purge_threads);
  1792. purge_sys.coordinator_startup();
  1793. srv_wake_purge_thread_if_not_active();
  1794. srv_start_state_set(SRV_START_STATE_PURGE);
  1795. }
  1796. srv_is_being_started = false;
  1797. if (!srv_read_only_mode) {
  1798. /* wake main loop of page cleaner up */
  1799. os_event_set(buf_flush_event);
  1800. }
  1801. if (srv_print_verbose_log) {
  1802. ib::info() << INNODB_VERSION_STR
  1803. << " started; log sequence number "
  1804. << srv_start_lsn
  1805. << "; transaction id " << trx_sys.get_max_trx_id();
  1806. }
  1807. if (srv_force_recovery > 0) {
  1808. ib::info() << "!!! innodb_force_recovery is set to "
  1809. << srv_force_recovery << " !!!";
  1810. }
  1811. if (srv_force_recovery == 0) {
  1812. /* In the insert buffer we may have even bigger tablespace
  1813. id's, because we may have dropped those tablespaces, but
  1814. insert buffer merge has not had time to clean the records from
  1815. the ibuf tree. */
  1816. ibuf_update_max_tablespace_id();
  1817. }
  1818. if (!srv_read_only_mode) {
  1819. if (create_new_db) {
  1820. srv_buffer_pool_load_at_startup = FALSE;
  1821. }
  1822. #ifdef WITH_WSREP
  1823. /*
  1824. Create the dump/load thread only when not running with
  1825. --wsrep-recover.
  1826. */
  1827. if (!get_wsrep_recovery()) {
  1828. #endif /* WITH_WSREP */
  1829. /* Start buffer pool dump/load task */
  1830. buf_load_at_startup();
  1831. #ifdef WITH_WSREP
  1832. } else {
  1833. ib::warn() <<
  1834. "Skipping buffer pool dump/restore during "
  1835. "wsrep recovery.";
  1836. }
  1837. #endif /* WITH_WSREP */
  1838. /* Create thread(s) that handles key rotation. This is
  1839. needed already here as log_preflush_pool_modified_pages
  1840. will flush dirty pages and that might need e.g.
  1841. fil_crypt_threads_event. */
  1842. fil_system_enter();
  1843. btr_scrub_init();
  1844. fil_crypt_threads_init();
  1845. fil_system_exit();
  1846. /* Initialize online defragmentation. */
  1847. btr_defragment_init();
  1848. srv_start_state |= SRV_START_STATE_REDO;
  1849. }
  1850. return(DB_SUCCESS);
  1851. }
  1852. /** Shut down background threads that can generate undo log. */
  1853. void srv_shutdown_bg_undo_sources()
  1854. {
  1855. if (srv_undo_sources) {
  1856. ut_ad(!srv_read_only_mode);
  1857. fts_optimize_shutdown();
  1858. dict_stats_shutdown();
  1859. while (row_get_background_drop_list_len_low()) {
  1860. srv_wake_master_thread();
  1861. os_thread_yield();
  1862. }
  1863. srv_undo_sources = false;
  1864. }
  1865. }
  1866. /**
  1867. Perform pre-shutdown task.
  1868. Since purge tasks vall into server (some MDL acqusition,
  1869. and compute virtual functions), let them shut down right
  1870. after use connections go down while the rest of the server
  1871. infrasture is still intact.
  1872. */
  1873. void innodb_preshutdown()
  1874. {
  1875. static bool first_time = true;
  1876. if (!first_time)
  1877. return;
  1878. first_time = false;
  1879. if (!srv_read_only_mode) {
  1880. if (!srv_fast_shutdown && srv_operation == SRV_OPERATION_NORMAL) {
  1881. while (trx_sys.any_active_transactions()) {
  1882. os_thread_sleep(1000);
  1883. }
  1884. }
  1885. srv_shutdown_bg_undo_sources();
  1886. srv_purge_shutdown();
  1887. }
  1888. }
  1889. /** Shut down InnoDB. */
  1890. void innodb_shutdown()
  1891. {
  1892. innodb_preshutdown();
  1893. ut_ad(!srv_undo_sources);
  1894. switch (srv_operation) {
  1895. case SRV_OPERATION_BACKUP:
  1896. case SRV_OPERATION_RESTORE:
  1897. case SRV_OPERATION_RESTORE_DELTA:
  1898. case SRV_OPERATION_RESTORE_EXPORT:
  1899. fil_close_all_files();
  1900. break;
  1901. case SRV_OPERATION_NORMAL:
  1902. /* Shut down the persistent files. */
  1903. logs_empty_and_mark_files_at_shutdown();
  1904. if (ulint n_threads = srv_conc_get_active_threads()) {
  1905. ib::warn() << "Query counter shows "
  1906. << n_threads << " queries still"
  1907. " inside InnoDB at shutdown";
  1908. }
  1909. }
  1910. /* Exit any remaining threads. */
  1911. srv_shutdown_all_bg_threads();
  1912. if (srv_monitor_file) {
  1913. my_fclose(srv_monitor_file, MYF(MY_WME));
  1914. srv_monitor_file = 0;
  1915. if (srv_monitor_file_name) {
  1916. unlink(srv_monitor_file_name);
  1917. ut_free(srv_monitor_file_name);
  1918. }
  1919. }
  1920. if (srv_misc_tmpfile) {
  1921. my_fclose(srv_misc_tmpfile, MYF(MY_WME));
  1922. srv_misc_tmpfile = 0;
  1923. }
  1924. ut_ad(dict_sys.is_initialised() || !srv_was_started);
  1925. ut_ad(trx_sys.is_initialised() || !srv_was_started);
  1926. ut_ad(buf_dblwr || !srv_was_started || srv_read_only_mode
  1927. || srv_force_recovery >= SRV_FORCE_NO_TRX_UNDO);
  1928. ut_ad(lock_sys.is_initialised() || !srv_was_started);
  1929. ut_ad(log_sys.is_initialised() || !srv_was_started);
  1930. #ifdef BTR_CUR_HASH_ADAPT
  1931. ut_ad(btr_search_sys || !srv_was_started);
  1932. #endif /* BTR_CUR_HASH_ADAPT */
  1933. ut_ad(ibuf.index || !srv_was_started);
  1934. dict_stats_deinit();
  1935. if (srv_start_state_is_set(SRV_START_STATE_REDO)) {
  1936. ut_ad(!srv_read_only_mode);
  1937. /* srv_shutdown_bg_undo_sources() already invoked
  1938. fts_optimize_shutdown(); dict_stats_shutdown(); */
  1939. fil_crypt_threads_cleanup();
  1940. btr_scrub_cleanup();
  1941. btr_defragment_shutdown();
  1942. }
  1943. /* This must be disabled before closing the buffer pool
  1944. and closing the data dictionary. */
  1945. #ifdef BTR_CUR_HASH_ADAPT
  1946. if (dict_sys.is_initialised()) {
  1947. btr_search_disable(true);
  1948. }
  1949. #endif /* BTR_CUR_HASH_ADAPT */
  1950. ibuf_close();
  1951. log_sys.close();
  1952. purge_sys.close();
  1953. trx_sys.close();
  1954. if (buf_dblwr) {
  1955. buf_dblwr_free();
  1956. }
  1957. lock_sys.close();
  1958. trx_pool_close();
  1959. if (!srv_read_only_mode) {
  1960. mutex_free(&srv_monitor_file_mutex);
  1961. mutex_free(&srv_misc_tmpfile_mutex);
  1962. }
  1963. dict_sys.close();
  1964. btr_search_sys_free();
  1965. /* 3. Free all InnoDB's own mutexes and the os_fast_mutexes inside
  1966. them */
  1967. os_aio_free();
  1968. row_mysql_close();
  1969. srv_free();
  1970. fil_system.close();
  1971. /* 4. Free all allocated memory */
  1972. pars_lexer_close();
  1973. recv_sys.close();
  1974. ut_ad(buf_pool_ptr || !srv_was_started);
  1975. if (buf_pool_ptr) {
  1976. buf_pool_free(srv_buf_pool_instances);
  1977. }
  1978. sync_check_close();
  1979. if (srv_was_started && srv_print_verbose_log) {
  1980. ib::info() << "Shutdown completed; log sequence number "
  1981. << srv_shutdown_lsn
  1982. << "; transaction id " << trx_sys.get_max_trx_id();
  1983. }
  1984. srv_thread_pool_end();
  1985. srv_start_state = SRV_START_STATE_NONE;
  1986. srv_was_started = false;
  1987. srv_start_has_been_called = false;
  1988. }
  1989. /** Get the meta-data filename from the table name for a
  1990. single-table tablespace.
  1991. @param[in] table table object
  1992. @param[out] filename filename
  1993. @param[in] max_len filename max length */
  1994. void
  1995. srv_get_meta_data_filename(
  1996. dict_table_t* table,
  1997. char* filename,
  1998. ulint max_len)
  1999. {
  2000. ulint len;
  2001. char* path;
  2002. /* Make sure the data_dir_path is set. */
  2003. dict_get_and_save_data_dir_path(table, false);
  2004. if (DICT_TF_HAS_DATA_DIR(table->flags)) {
  2005. ut_a(table->data_dir_path);
  2006. path = fil_make_filepath(
  2007. table->data_dir_path, table->name.m_name, CFG, true);
  2008. } else {
  2009. path = fil_make_filepath(NULL, table->name.m_name, CFG, false);
  2010. }
  2011. ut_a(path);
  2012. len = strlen(path);
  2013. ut_a(max_len >= len);
  2014. strcpy(filename, path);
  2015. ut_free(path);
  2016. }