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.

3487 lines
90 KiB

17 years ago
9 years ago
17 years ago
17 years ago
17 years ago
17 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
9 years ago
16 years ago
16 years ago
16 years ago
16 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
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
15 years ago
15 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
16 years ago
17 years ago
16 years ago
16 years ago
15 years ago
16 years ago
9 years ago
16 years ago
9 years ago
9 years ago
MDEV-11623 MariaDB 10.1 fails to start datadir created with MariaDB 10.0/MySQL 5.6 using innodb-page-size!=16K The storage format of FSP_SPACE_FLAGS was accidentally broken already in MariaDB 10.1.0. This fix is bringing the format in line with other MySQL and MariaDB release series. Please refer to the comments that were added to fsp0fsp.h for details. This is an INCOMPATIBLE CHANGE that affects users of page_compression and non-default innodb_page_size. Upgrading to this release will correct the flags in the data files. If you want to downgrade to earlier MariaDB 10.1.x, please refer to the test innodb.101_compatibility how to reset the FSP_SPACE_FLAGS in the files. NOTE: MariaDB 10.1.0 to 10.1.20 can misinterpret uncompressed data files with innodb_page_size=4k or 64k as compressed innodb_page_size=16k files, and then probably fail when trying to access the pages. See the comments in the function fsp_flags_convert_from_101() for detailed analysis. Move PAGE_COMPRESSION to FSP_SPACE_FLAGS bit position 16. In this way, compressed innodb_page_size=16k tablespaces will not be mistaken for uncompressed ones by MariaDB 10.1.0 to 10.1.20. Derive PAGE_COMPRESSION_LEVEL, ATOMIC_WRITES and DATA_DIR from the dict_table_t::flags when the table is available, in fil_space_for_table_exists_in_mem() or fil_open_single_table_tablespace(). During crash recovery, fil_load_single_table_tablespace() will use innodb_compression_level for the PAGE_COMPRESSION_LEVEL. FSP_FLAGS_MEM_MASK: A bitmap of the memory-only fil_space_t::flags that are not to be written to FSP_SPACE_FLAGS. Currently, these will include PAGE_COMPRESSION_LEVEL, ATOMIC_WRITES and DATA_DIR. Introduce the macro FSP_FLAGS_PAGE_SSIZE(). We only support one innodb_page_size for the whole instance. When creating a dummy tablespace for the redo log, use fil_space_t::flags=0. The flags are never written to the redo log files. Remove many FSP_FLAGS_SET_ macros. dict_tf_verify_flags(): Remove. This is basically only duplicating the logic of dict_tf_to_fsp_flags(), used in a debug assertion. fil_space_t::mark: Remove. This flag was not used for anything. fil_space_for_table_exists_in_mem(): Remove the unnecessary parameter mark_space, and add a parameter for table flags. Check that fil_space_t::flags match the table flags, and adjust the (memory-only) flags based on the table flags. fil_node_open_file(): Remove some redundant or unreachable conditions, do not use stderr for output, and avoid unnecessary server aborts. fil_user_tablespace_restore_page(): Convert the flags, so that the correct page_size will be used when restoring a page from the doublewrite buffer. fil_space_get_page_compressed(), fsp_flags_is_page_compressed(): Remove. It suffices to have fil_space_is_page_compressed(). FSP_FLAGS_WIDTH_DATA_DIR, FSP_FLAGS_WIDTH_PAGE_COMPRESSION_LEVEL, FSP_FLAGS_WIDTH_ATOMIC_WRITES: Remove, because these flags do not exist in the FSP_SPACE_FLAGS but only in memory. fsp_flags_try_adjust(): New function, to adjust the FSP_SPACE_FLAGS in page 0. Called by fil_open_single_table_tablespace(), fil_space_for_table_exists_in_mem(), innobase_start_or_create_for_mysql() except if --innodb-read-only is active. fsp_flags_is_valid(ulint): Reimplement from the scratch, with accurate comments. Do not display any details of detected inconsistencies, because the output could be confusing when dealing with MariaDB 10.1.x data files. fsp_flags_convert_from_101(ulint): Convert flags from buggy MariaDB 10.1.x format, or return ULINT_UNDEFINED if the flags cannot be in MariaDB 10.1.x format. fsp_flags_match(): Check the flags when probing files. Implemented based on fsp_flags_is_valid() and fsp_flags_convert_from_101(). dict_check_tablespaces_and_store_max_id(): Do not access the page after committing the mini-transaction. IMPORT TABLESPACE fixes: AbstractCallback::init(): Convert the flags. FetchIndexRootPages::operator(): Check that the tablespace flags match the table flags. Do not attempt to convert tablespace flags to table flags, because the conversion would necessarily be lossy. PageConverter::update_header(): Write back the correct flags. This takes care of the flags in IMPORT TABLESPACE.
9 years ago
Merge Google encryption commit 195158e9889365dc3298f8c1f3bcaa745992f27f Author: Minli Zhu <minliz@google.com> Date: Mon Nov 25 11:05:55 2013 -0800 Innodb redo log encryption/decryption. Use start lsn of a log block as part of AES CTR counter. Record key version with each checkpoint. Internally key version 0 means no encryption. Tests done (see test_innodb_log_encryption.sh for detail): - Verify flag innodb_encrypt_log on or off, combined with various key versions passed through CLI, and dynamically set after startup, will not corrupt database. This includes tests from being unencrypted to encrypted, and encrypted to unencrypted. - Verify start-up with no redo logs succeeds. - Verify fresh start-up succeeds. Change-Id: I4ce4c2afdf3076be2fce90ebbc2a7ce01184b612 commit c1b97273659f07866758c25f4a56f680a1fbad24 Author: Jonas Oreland <jonaso@google.com> Date: Tue Dec 3 18:47:27 2013 +0100 encryption of aria data&index files this patch implements encryption of aria data & index files. this is implemented as 1) add read/write hooks (renamed from callbacks) that does encrypt/decrypt (also add pre_read and post_write hooks) 2) modify page headers for data/index to contain key version (making the data-page header size different for with/without encryption) 3) modify index page 0 to contain IV (and crypt header) 4) AES CRT crypt functions 5) counter block is implemented using combination of page no, lsn and table specific id NOTE: 1) log files are not encrypted, this is not needed for if aria is only used for internal temporary tables and they are not transactional (i.e not logged) 2) all encrypted tables are using PAGE_CHECKSUM (crc) normal internal temporary tables are (currently) not CHECKSUM:ed 3) This patch adds insert-order semantics to aria block_format. The default behaviour of aria block-format is best-fit, meaning that rows gets allocated to page trying to fill the pages as much as possible. However, certain sql constructs materialize temporary result in tmp-tables, and expect that a table scan will later return the rows in the same order they were inserted. This implementation of insert-order is only enabled when explicitly requested by sql-layer. CHANGES: 1) found bug in ma_write that made code try to abort a record that was never written unsure why this is not exposed Change-Id: Ia82bbaa92e2c0629c08693c5add2f56b815c0509 commit 89dc1ab651fe0205d55b4eb588f62df550aa65fc Author: Jonas Oreland <jonaso@google.com> Date: Mon Feb 17 08:04:50 2014 -0800 Implement encryption of innodb datafiles. Pages are encrypted before written to disk and decrypted when read from disk. Each page except first page (page 0) in tablespace is encrypted. Page 0 is unencrypted and contains IV for the tablespace. FIL_PAGE_FILE_FLUSH_LSN on each page (except page 0) is used to store a 32-bit key-version, so that multiple keys can be active in a tablespace simultaneous. The other 32-bit of the FIL_PAGE_FILE_FLUSH_LSN field contains a checksum that is computed after encryption. This checksum is used by innochecksum and when restoring from double-write-buffer. The encryption is performed using AES CRT. Monitoring of encryption is enabled using new IS-table INNODB_TABLESPACES_ENCRYPTION. In addition to that new status variables innodb_encryption_rotation_{ pages_read_from_cache, pages_read_from_disk, pages_modified,pages_flushed } has been added. The following tunables are introduces - innodb_encrypt_tables - innodb_encryption_threads - innodb_encryption_rotate_key_age - innodb_encryption_rotation_iops Change-Id: I8f651795a30b52e71b16d6bc9cb7559be349d0b2 commit a17eef2f6948e58219c9e26fc35633d6fd4de1de Author: Andrew Ford <andrewford@google.com> Date: Thu Jan 2 15:43:09 2014 -0800 Key management skeleton with debug hooks. Change-Id: Ifd6aa3743d7ea291c70083f433a059c439aed866 commit 68a399838ad72264fd61b3dc67fecd29bbdb0af1 Author: Andrew Ford <andrewford@google.com> Date: Mon Oct 28 16:27:44 2013 -0700 Add AES-128 CTR and GCM encryption classes. Change-Id: I116305eced2a233db15306bc2ef5b9d398d1a3a2
11 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
9 years ago
9 years ago
MDEV-12113: install_db shows corruption for rest encryption with innodb_data_file_path=ibdata1:3M; Problem was that FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION field that for encrypted pages even in system datafiles should contain key_version except very first page (0:0) is after encryption overwritten with flush lsn. Ported WL#7990 Repurpose FIL_PAGE_FLUSH_LSN to 10.1 The field FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION is consulted during InnoDB startup. At startup, InnoDB reads the FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION from the first page of each file in the InnoDB system tablespace. If there are multiple files, the minimum and maximum LSN can differ. These numbers are passed to InnoDB startup. Having the number in other files than the first file of the InnoDB system tablespace is not providing much additional value. It is conflicting with other use of the field, such as on InnoDB R-tree index pages and encryption key_version. This worklog will stop writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to other files than the first file of the InnoDB system tablespace (page number 0:0) when system tablespace is encrypted. If tablespace is not encrypted we continue writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to all first pages of system tablespace to avoid unnecessary warnings on downgrade. open_or_create_data_files(): pass only one flushed_lsn parameter xb_load_tablespaces(): pass only one flushed_lsn parameter. buf_page_create(): Improve comment about where FIL_PAGE_FIL_FLUSH_LSN_OR_KEY_VERSION is set. fil_write_flushed_lsn(): A new function, merged from fil_write_lsn_and_arch_no_to_file() and fil_write_flushed_lsn_to_data_files(). Only write to the first page of the system tablespace (page 0:0) if tablespace is encrypted, or write all first pages of system tablespace and invoke fil_flush_file_spaces(FIL_TYPE_TABLESPACE) afterwards. fil_read_first_page(): read flush_lsn and crypt_data only from first datafile. fil_open_single_table_tablespace(): Remove output of LSN, because it was only valid for the system tablespace and the undo tablespaces, not user tablespaces. fil_validate_single_table_tablespace(): Remove output of LSN. checkpoint_now_set(): Use fil_write_flushed_lsn and output a error if operation fails. Remove lsn variable from fsp_open_info. recv_recovery_from_checkpoint_start(): Remove unnecessary second flush_lsn parameter. log_empty_and_mark_files_at_shutdown(): Use fil_writte_flushed_lsn and output error if it fails. open_or_create_data_files(): Pass only one flushed_lsn variable.
9 years ago
16 years ago
MDEV-12113: install_db shows corruption for rest encryption with innodb_data_file_path=ibdata1:3M; Problem was that FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION field that for encrypted pages even in system datafiles should contain key_version except very first page (0:0) is after encryption overwritten with flush lsn. Ported WL#7990 Repurpose FIL_PAGE_FLUSH_LSN to 10.1 The field FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION is consulted during InnoDB startup. At startup, InnoDB reads the FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION from the first page of each file in the InnoDB system tablespace. If there are multiple files, the minimum and maximum LSN can differ. These numbers are passed to InnoDB startup. Having the number in other files than the first file of the InnoDB system tablespace is not providing much additional value. It is conflicting with other use of the field, such as on InnoDB R-tree index pages and encryption key_version. This worklog will stop writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to other files than the first file of the InnoDB system tablespace (page number 0:0) when system tablespace is encrypted. If tablespace is not encrypted we continue writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to all first pages of system tablespace to avoid unnecessary warnings on downgrade. open_or_create_data_files(): pass only one flushed_lsn parameter xb_load_tablespaces(): pass only one flushed_lsn parameter. buf_page_create(): Improve comment about where FIL_PAGE_FIL_FLUSH_LSN_OR_KEY_VERSION is set. fil_write_flushed_lsn(): A new function, merged from fil_write_lsn_and_arch_no_to_file() and fil_write_flushed_lsn_to_data_files(). Only write to the first page of the system tablespace (page 0:0) if tablespace is encrypted, or write all first pages of system tablespace and invoke fil_flush_file_spaces(FIL_TYPE_TABLESPACE) afterwards. fil_read_first_page(): read flush_lsn and crypt_data only from first datafile. fil_open_single_table_tablespace(): Remove output of LSN, because it was only valid for the system tablespace and the undo tablespaces, not user tablespaces. fil_validate_single_table_tablespace(): Remove output of LSN. checkpoint_now_set(): Use fil_write_flushed_lsn and output a error if operation fails. Remove lsn variable from fsp_open_info. recv_recovery_from_checkpoint_start(): Remove unnecessary second flush_lsn parameter. log_empty_and_mark_files_at_shutdown(): Use fil_writte_flushed_lsn and output error if it fails. open_or_create_data_files(): Pass only one flushed_lsn variable.
9 years ago
MDEV-12113: install_db shows corruption for rest encryption with innodb_data_file_path=ibdata1:3M; Problem was that FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION field that for encrypted pages even in system datafiles should contain key_version except very first page (0:0) is after encryption overwritten with flush lsn. Ported WL#7990 Repurpose FIL_PAGE_FLUSH_LSN to 10.1 The field FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION is consulted during InnoDB startup. At startup, InnoDB reads the FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION from the first page of each file in the InnoDB system tablespace. If there are multiple files, the minimum and maximum LSN can differ. These numbers are passed to InnoDB startup. Having the number in other files than the first file of the InnoDB system tablespace is not providing much additional value. It is conflicting with other use of the field, such as on InnoDB R-tree index pages and encryption key_version. This worklog will stop writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to other files than the first file of the InnoDB system tablespace (page number 0:0) when system tablespace is encrypted. If tablespace is not encrypted we continue writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to all first pages of system tablespace to avoid unnecessary warnings on downgrade. open_or_create_data_files(): pass only one flushed_lsn parameter xb_load_tablespaces(): pass only one flushed_lsn parameter. buf_page_create(): Improve comment about where FIL_PAGE_FIL_FLUSH_LSN_OR_KEY_VERSION is set. fil_write_flushed_lsn(): A new function, merged from fil_write_lsn_and_arch_no_to_file() and fil_write_flushed_lsn_to_data_files(). Only write to the first page of the system tablespace (page 0:0) if tablespace is encrypted, or write all first pages of system tablespace and invoke fil_flush_file_spaces(FIL_TYPE_TABLESPACE) afterwards. fil_read_first_page(): read flush_lsn and crypt_data only from first datafile. fil_open_single_table_tablespace(): Remove output of LSN, because it was only valid for the system tablespace and the undo tablespaces, not user tablespaces. fil_validate_single_table_tablespace(): Remove output of LSN. checkpoint_now_set(): Use fil_write_flushed_lsn and output a error if operation fails. Remove lsn variable from fsp_open_info. recv_recovery_from_checkpoint_start(): Remove unnecessary second flush_lsn parameter. log_empty_and_mark_files_at_shutdown(): Use fil_writte_flushed_lsn and output error if it fails. open_or_create_data_files(): Pass only one flushed_lsn variable.
9 years ago
MDEV-12113: install_db shows corruption for rest encryption with innodb_data_file_path=ibdata1:3M; Problem was that FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION field that for encrypted pages even in system datafiles should contain key_version except very first page (0:0) is after encryption overwritten with flush lsn. Ported WL#7990 Repurpose FIL_PAGE_FLUSH_LSN to 10.1 The field FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION is consulted during InnoDB startup. At startup, InnoDB reads the FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION from the first page of each file in the InnoDB system tablespace. If there are multiple files, the minimum and maximum LSN can differ. These numbers are passed to InnoDB startup. Having the number in other files than the first file of the InnoDB system tablespace is not providing much additional value. It is conflicting with other use of the field, such as on InnoDB R-tree index pages and encryption key_version. This worklog will stop writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to other files than the first file of the InnoDB system tablespace (page number 0:0) when system tablespace is encrypted. If tablespace is not encrypted we continue writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to all first pages of system tablespace to avoid unnecessary warnings on downgrade. open_or_create_data_files(): pass only one flushed_lsn parameter xb_load_tablespaces(): pass only one flushed_lsn parameter. buf_page_create(): Improve comment about where FIL_PAGE_FIL_FLUSH_LSN_OR_KEY_VERSION is set. fil_write_flushed_lsn(): A new function, merged from fil_write_lsn_and_arch_no_to_file() and fil_write_flushed_lsn_to_data_files(). Only write to the first page of the system tablespace (page 0:0) if tablespace is encrypted, or write all first pages of system tablespace and invoke fil_flush_file_spaces(FIL_TYPE_TABLESPACE) afterwards. fil_read_first_page(): read flush_lsn and crypt_data only from first datafile. fil_open_single_table_tablespace(): Remove output of LSN, because it was only valid for the system tablespace and the undo tablespaces, not user tablespaces. fil_validate_single_table_tablespace(): Remove output of LSN. checkpoint_now_set(): Use fil_write_flushed_lsn and output a error if operation fails. Remove lsn variable from fsp_open_info. recv_recovery_from_checkpoint_start(): Remove unnecessary second flush_lsn parameter. log_empty_and_mark_files_at_shutdown(): Use fil_writte_flushed_lsn and output error if it fails. open_or_create_data_files(): Pass only one flushed_lsn variable.
9 years ago
MDEV-12113: install_db shows corruption for rest encryption with innodb_data_file_path=ibdata1:3M; Problem was that FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION field that for encrypted pages even in system datafiles should contain key_version except very first page (0:0) is after encryption overwritten with flush lsn. Ported WL#7990 Repurpose FIL_PAGE_FLUSH_LSN to 10.1 The field FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION is consulted during InnoDB startup. At startup, InnoDB reads the FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION from the first page of each file in the InnoDB system tablespace. If there are multiple files, the minimum and maximum LSN can differ. These numbers are passed to InnoDB startup. Having the number in other files than the first file of the InnoDB system tablespace is not providing much additional value. It is conflicting with other use of the field, such as on InnoDB R-tree index pages and encryption key_version. This worklog will stop writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to other files than the first file of the InnoDB system tablespace (page number 0:0) when system tablespace is encrypted. If tablespace is not encrypted we continue writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to all first pages of system tablespace to avoid unnecessary warnings on downgrade. open_or_create_data_files(): pass only one flushed_lsn parameter xb_load_tablespaces(): pass only one flushed_lsn parameter. buf_page_create(): Improve comment about where FIL_PAGE_FIL_FLUSH_LSN_OR_KEY_VERSION is set. fil_write_flushed_lsn(): A new function, merged from fil_write_lsn_and_arch_no_to_file() and fil_write_flushed_lsn_to_data_files(). Only write to the first page of the system tablespace (page 0:0) if tablespace is encrypted, or write all first pages of system tablespace and invoke fil_flush_file_spaces(FIL_TYPE_TABLESPACE) afterwards. fil_read_first_page(): read flush_lsn and crypt_data only from first datafile. fil_open_single_table_tablespace(): Remove output of LSN, because it was only valid for the system tablespace and the undo tablespaces, not user tablespaces. fil_validate_single_table_tablespace(): Remove output of LSN. checkpoint_now_set(): Use fil_write_flushed_lsn and output a error if operation fails. Remove lsn variable from fsp_open_info. recv_recovery_from_checkpoint_start(): Remove unnecessary second flush_lsn parameter. log_empty_and_mark_files_at_shutdown(): Use fil_writte_flushed_lsn and output error if it fails. open_or_create_data_files(): Pass only one flushed_lsn variable.
9 years ago
MDEV-12113: install_db shows corruption for rest encryption with innodb_data_file_path=ibdata1:3M; Problem was that FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION field that for encrypted pages even in system datafiles should contain key_version except very first page (0:0) is after encryption overwritten with flush lsn. Ported WL#7990 Repurpose FIL_PAGE_FLUSH_LSN to 10.1 The field FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION is consulted during InnoDB startup. At startup, InnoDB reads the FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION from the first page of each file in the InnoDB system tablespace. If there are multiple files, the minimum and maximum LSN can differ. These numbers are passed to InnoDB startup. Having the number in other files than the first file of the InnoDB system tablespace is not providing much additional value. It is conflicting with other use of the field, such as on InnoDB R-tree index pages and encryption key_version. This worklog will stop writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to other files than the first file of the InnoDB system tablespace (page number 0:0) when system tablespace is encrypted. If tablespace is not encrypted we continue writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to all first pages of system tablespace to avoid unnecessary warnings on downgrade. open_or_create_data_files(): pass only one flushed_lsn parameter xb_load_tablespaces(): pass only one flushed_lsn parameter. buf_page_create(): Improve comment about where FIL_PAGE_FIL_FLUSH_LSN_OR_KEY_VERSION is set. fil_write_flushed_lsn(): A new function, merged from fil_write_lsn_and_arch_no_to_file() and fil_write_flushed_lsn_to_data_files(). Only write to the first page of the system tablespace (page 0:0) if tablespace is encrypted, or write all first pages of system tablespace and invoke fil_flush_file_spaces(FIL_TYPE_TABLESPACE) afterwards. fil_read_first_page(): read flush_lsn and crypt_data only from first datafile. fil_open_single_table_tablespace(): Remove output of LSN, because it was only valid for the system tablespace and the undo tablespaces, not user tablespaces. fil_validate_single_table_tablespace(): Remove output of LSN. checkpoint_now_set(): Use fil_write_flushed_lsn and output a error if operation fails. Remove lsn variable from fsp_open_info. recv_recovery_from_checkpoint_start(): Remove unnecessary second flush_lsn parameter. log_empty_and_mark_files_at_shutdown(): Use fil_writte_flushed_lsn and output error if it fails. open_or_create_data_files(): Pass only one flushed_lsn variable.
9 years ago
9 years ago
MDEV-12113: install_db shows corruption for rest encryption with innodb_data_file_path=ibdata1:3M; Problem was that FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION field that for encrypted pages even in system datafiles should contain key_version except very first page (0:0) is after encryption overwritten with flush lsn. Ported WL#7990 Repurpose FIL_PAGE_FLUSH_LSN to 10.1 The field FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION is consulted during InnoDB startup. At startup, InnoDB reads the FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION from the first page of each file in the InnoDB system tablespace. If there are multiple files, the minimum and maximum LSN can differ. These numbers are passed to InnoDB startup. Having the number in other files than the first file of the InnoDB system tablespace is not providing much additional value. It is conflicting with other use of the field, such as on InnoDB R-tree index pages and encryption key_version. This worklog will stop writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to other files than the first file of the InnoDB system tablespace (page number 0:0) when system tablespace is encrypted. If tablespace is not encrypted we continue writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to all first pages of system tablespace to avoid unnecessary warnings on downgrade. open_or_create_data_files(): pass only one flushed_lsn parameter xb_load_tablespaces(): pass only one flushed_lsn parameter. buf_page_create(): Improve comment about where FIL_PAGE_FIL_FLUSH_LSN_OR_KEY_VERSION is set. fil_write_flushed_lsn(): A new function, merged from fil_write_lsn_and_arch_no_to_file() and fil_write_flushed_lsn_to_data_files(). Only write to the first page of the system tablespace (page 0:0) if tablespace is encrypted, or write all first pages of system tablespace and invoke fil_flush_file_spaces(FIL_TYPE_TABLESPACE) afterwards. fil_read_first_page(): read flush_lsn and crypt_data only from first datafile. fil_open_single_table_tablespace(): Remove output of LSN, because it was only valid for the system tablespace and the undo tablespaces, not user tablespaces. fil_validate_single_table_tablespace(): Remove output of LSN. checkpoint_now_set(): Use fil_write_flushed_lsn and output a error if operation fails. Remove lsn variable from fsp_open_info. recv_recovery_from_checkpoint_start(): Remove unnecessary second flush_lsn parameter. log_empty_and_mark_files_at_shutdown(): Use fil_writte_flushed_lsn and output error if it fails. open_or_create_data_files(): Pass only one flushed_lsn variable.
9 years ago
MDEV-12113: install_db shows corruption for rest encryption with innodb_data_file_path=ibdata1:3M; Problem was that FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION field that for encrypted pages even in system datafiles should contain key_version except very first page (0:0) is after encryption overwritten with flush lsn. Ported WL#7990 Repurpose FIL_PAGE_FLUSH_LSN to 10.1 The field FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION is consulted during InnoDB startup. At startup, InnoDB reads the FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION from the first page of each file in the InnoDB system tablespace. If there are multiple files, the minimum and maximum LSN can differ. These numbers are passed to InnoDB startup. Having the number in other files than the first file of the InnoDB system tablespace is not providing much additional value. It is conflicting with other use of the field, such as on InnoDB R-tree index pages and encryption key_version. This worklog will stop writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to other files than the first file of the InnoDB system tablespace (page number 0:0) when system tablespace is encrypted. If tablespace is not encrypted we continue writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to all first pages of system tablespace to avoid unnecessary warnings on downgrade. open_or_create_data_files(): pass only one flushed_lsn parameter xb_load_tablespaces(): pass only one flushed_lsn parameter. buf_page_create(): Improve comment about where FIL_PAGE_FIL_FLUSH_LSN_OR_KEY_VERSION is set. fil_write_flushed_lsn(): A new function, merged from fil_write_lsn_and_arch_no_to_file() and fil_write_flushed_lsn_to_data_files(). Only write to the first page of the system tablespace (page 0:0) if tablespace is encrypted, or write all first pages of system tablespace and invoke fil_flush_file_spaces(FIL_TYPE_TABLESPACE) afterwards. fil_read_first_page(): read flush_lsn and crypt_data only from first datafile. fil_open_single_table_tablespace(): Remove output of LSN, because it was only valid for the system tablespace and the undo tablespaces, not user tablespaces. fil_validate_single_table_tablespace(): Remove output of LSN. checkpoint_now_set(): Use fil_write_flushed_lsn and output a error if operation fails. Remove lsn variable from fsp_open_info. recv_recovery_from_checkpoint_start(): Remove unnecessary second flush_lsn parameter. log_empty_and_mark_files_at_shutdown(): Use fil_writte_flushed_lsn and output error if it fails. open_or_create_data_files(): Pass only one flushed_lsn variable.
9 years ago
MDEV-12113: install_db shows corruption for rest encryption with innodb_data_file_path=ibdata1:3M; Problem was that FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION field that for encrypted pages even in system datafiles should contain key_version except very first page (0:0) is after encryption overwritten with flush lsn. Ported WL#7990 Repurpose FIL_PAGE_FLUSH_LSN to 10.1 The field FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION is consulted during InnoDB startup. At startup, InnoDB reads the FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION from the first page of each file in the InnoDB system tablespace. If there are multiple files, the minimum and maximum LSN can differ. These numbers are passed to InnoDB startup. Having the number in other files than the first file of the InnoDB system tablespace is not providing much additional value. It is conflicting with other use of the field, such as on InnoDB R-tree index pages and encryption key_version. This worklog will stop writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to other files than the first file of the InnoDB system tablespace (page number 0:0) when system tablespace is encrypted. If tablespace is not encrypted we continue writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to all first pages of system tablespace to avoid unnecessary warnings on downgrade. open_or_create_data_files(): pass only one flushed_lsn parameter xb_load_tablespaces(): pass only one flushed_lsn parameter. buf_page_create(): Improve comment about where FIL_PAGE_FIL_FLUSH_LSN_OR_KEY_VERSION is set. fil_write_flushed_lsn(): A new function, merged from fil_write_lsn_and_arch_no_to_file() and fil_write_flushed_lsn_to_data_files(). Only write to the first page of the system tablespace (page 0:0) if tablespace is encrypted, or write all first pages of system tablespace and invoke fil_flush_file_spaces(FIL_TYPE_TABLESPACE) afterwards. fil_read_first_page(): read flush_lsn and crypt_data only from first datafile. fil_open_single_table_tablespace(): Remove output of LSN, because it was only valid for the system tablespace and the undo tablespaces, not user tablespaces. fil_validate_single_table_tablespace(): Remove output of LSN. checkpoint_now_set(): Use fil_write_flushed_lsn and output a error if operation fails. Remove lsn variable from fsp_open_info. recv_recovery_from_checkpoint_start(): Remove unnecessary second flush_lsn parameter. log_empty_and_mark_files_at_shutdown(): Use fil_writte_flushed_lsn and output error if it fails. open_or_create_data_files(): Pass only one flushed_lsn variable.
9 years ago
15 years ago
15 years ago
15 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
10 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-12113: install_db shows corruption for rest encryption with innodb_data_file_path=ibdata1:3M; Problem was that FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION field that for encrypted pages even in system datafiles should contain key_version except very first page (0:0) is after encryption overwritten with flush lsn. Ported WL#7990 Repurpose FIL_PAGE_FLUSH_LSN to 10.1 The field FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION is consulted during InnoDB startup. At startup, InnoDB reads the FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION from the first page of each file in the InnoDB system tablespace. If there are multiple files, the minimum and maximum LSN can differ. These numbers are passed to InnoDB startup. Having the number in other files than the first file of the InnoDB system tablespace is not providing much additional value. It is conflicting with other use of the field, such as on InnoDB R-tree index pages and encryption key_version. This worklog will stop writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to other files than the first file of the InnoDB system tablespace (page number 0:0) when system tablespace is encrypted. If tablespace is not encrypted we continue writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to all first pages of system tablespace to avoid unnecessary warnings on downgrade. open_or_create_data_files(): pass only one flushed_lsn parameter xb_load_tablespaces(): pass only one flushed_lsn parameter. buf_page_create(): Improve comment about where FIL_PAGE_FIL_FLUSH_LSN_OR_KEY_VERSION is set. fil_write_flushed_lsn(): A new function, merged from fil_write_lsn_and_arch_no_to_file() and fil_write_flushed_lsn_to_data_files(). Only write to the first page of the system tablespace (page 0:0) if tablespace is encrypted, or write all first pages of system tablespace and invoke fil_flush_file_spaces(FIL_TYPE_TABLESPACE) afterwards. fil_read_first_page(): read flush_lsn and crypt_data only from first datafile. fil_open_single_table_tablespace(): Remove output of LSN, because it was only valid for the system tablespace and the undo tablespaces, not user tablespaces. fil_validate_single_table_tablespace(): Remove output of LSN. checkpoint_now_set(): Use fil_write_flushed_lsn and output a error if operation fails. Remove lsn variable from fsp_open_info. recv_recovery_from_checkpoint_start(): Remove unnecessary second flush_lsn parameter. log_empty_and_mark_files_at_shutdown(): Use fil_writte_flushed_lsn and output error if it fails. open_or_create_data_files(): Pass only one flushed_lsn variable.
9 years ago
MDEV-12113: install_db shows corruption for rest encryption with innodb_data_file_path=ibdata1:3M; Problem was that FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION field that for encrypted pages even in system datafiles should contain key_version except very first page (0:0) is after encryption overwritten with flush lsn. Ported WL#7990 Repurpose FIL_PAGE_FLUSH_LSN to 10.1 The field FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION is consulted during InnoDB startup. At startup, InnoDB reads the FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION from the first page of each file in the InnoDB system tablespace. If there are multiple files, the minimum and maximum LSN can differ. These numbers are passed to InnoDB startup. Having the number in other files than the first file of the InnoDB system tablespace is not providing much additional value. It is conflicting with other use of the field, such as on InnoDB R-tree index pages and encryption key_version. This worklog will stop writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to other files than the first file of the InnoDB system tablespace (page number 0:0) when system tablespace is encrypted. If tablespace is not encrypted we continue writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to all first pages of system tablespace to avoid unnecessary warnings on downgrade. open_or_create_data_files(): pass only one flushed_lsn parameter xb_load_tablespaces(): pass only one flushed_lsn parameter. buf_page_create(): Improve comment about where FIL_PAGE_FIL_FLUSH_LSN_OR_KEY_VERSION is set. fil_write_flushed_lsn(): A new function, merged from fil_write_lsn_and_arch_no_to_file() and fil_write_flushed_lsn_to_data_files(). Only write to the first page of the system tablespace (page 0:0) if tablespace is encrypted, or write all first pages of system tablespace and invoke fil_flush_file_spaces(FIL_TYPE_TABLESPACE) afterwards. fil_read_first_page(): read flush_lsn and crypt_data only from first datafile. fil_open_single_table_tablespace(): Remove output of LSN, because it was only valid for the system tablespace and the undo tablespaces, not user tablespaces. fil_validate_single_table_tablespace(): Remove output of LSN. checkpoint_now_set(): Use fil_write_flushed_lsn and output a error if operation fails. Remove lsn variable from fsp_open_info. recv_recovery_from_checkpoint_start(): Remove unnecessary second flush_lsn parameter. log_empty_and_mark_files_at_shutdown(): Use fil_writte_flushed_lsn and output error if it fails. open_or_create_data_files(): Pass only one flushed_lsn variable.
9 years ago
MDEV-12113: install_db shows corruption for rest encryption with innodb_data_file_path=ibdata1:3M; Problem was that FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION field that for encrypted pages even in system datafiles should contain key_version except very first page (0:0) is after encryption overwritten with flush lsn. Ported WL#7990 Repurpose FIL_PAGE_FLUSH_LSN to 10.1 The field FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION is consulted during InnoDB startup. At startup, InnoDB reads the FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION from the first page of each file in the InnoDB system tablespace. If there are multiple files, the minimum and maximum LSN can differ. These numbers are passed to InnoDB startup. Having the number in other files than the first file of the InnoDB system tablespace is not providing much additional value. It is conflicting with other use of the field, such as on InnoDB R-tree index pages and encryption key_version. This worklog will stop writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to other files than the first file of the InnoDB system tablespace (page number 0:0) when system tablespace is encrypted. If tablespace is not encrypted we continue writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to all first pages of system tablespace to avoid unnecessary warnings on downgrade. open_or_create_data_files(): pass only one flushed_lsn parameter xb_load_tablespaces(): pass only one flushed_lsn parameter. buf_page_create(): Improve comment about where FIL_PAGE_FIL_FLUSH_LSN_OR_KEY_VERSION is set. fil_write_flushed_lsn(): A new function, merged from fil_write_lsn_and_arch_no_to_file() and fil_write_flushed_lsn_to_data_files(). Only write to the first page of the system tablespace (page 0:0) if tablespace is encrypted, or write all first pages of system tablespace and invoke fil_flush_file_spaces(FIL_TYPE_TABLESPACE) afterwards. fil_read_first_page(): read flush_lsn and crypt_data only from first datafile. fil_open_single_table_tablespace(): Remove output of LSN, because it was only valid for the system tablespace and the undo tablespaces, not user tablespaces. fil_validate_single_table_tablespace(): Remove output of LSN. checkpoint_now_set(): Use fil_write_flushed_lsn and output a error if operation fails. Remove lsn variable from fsp_open_info. recv_recovery_from_checkpoint_start(): Remove unnecessary second flush_lsn parameter. log_empty_and_mark_files_at_shutdown(): Use fil_writte_flushed_lsn and output error if it fails. open_or_create_data_files(): Pass only one flushed_lsn variable.
9 years ago
MDEV-12113: install_db shows corruption for rest encryption with innodb_data_file_path=ibdata1:3M; Problem was that FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION field that for encrypted pages even in system datafiles should contain key_version except very first page (0:0) is after encryption overwritten with flush lsn. Ported WL#7990 Repurpose FIL_PAGE_FLUSH_LSN to 10.1 The field FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION is consulted during InnoDB startup. At startup, InnoDB reads the FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION from the first page of each file in the InnoDB system tablespace. If there are multiple files, the minimum and maximum LSN can differ. These numbers are passed to InnoDB startup. Having the number in other files than the first file of the InnoDB system tablespace is not providing much additional value. It is conflicting with other use of the field, such as on InnoDB R-tree index pages and encryption key_version. This worklog will stop writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to other files than the first file of the InnoDB system tablespace (page number 0:0) when system tablespace is encrypted. If tablespace is not encrypted we continue writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to all first pages of system tablespace to avoid unnecessary warnings on downgrade. open_or_create_data_files(): pass only one flushed_lsn parameter xb_load_tablespaces(): pass only one flushed_lsn parameter. buf_page_create(): Improve comment about where FIL_PAGE_FIL_FLUSH_LSN_OR_KEY_VERSION is set. fil_write_flushed_lsn(): A new function, merged from fil_write_lsn_and_arch_no_to_file() and fil_write_flushed_lsn_to_data_files(). Only write to the first page of the system tablespace (page 0:0) if tablespace is encrypted, or write all first pages of system tablespace and invoke fil_flush_file_spaces(FIL_TYPE_TABLESPACE) afterwards. fil_read_first_page(): read flush_lsn and crypt_data only from first datafile. fil_open_single_table_tablespace(): Remove output of LSN, because it was only valid for the system tablespace and the undo tablespaces, not user tablespaces. fil_validate_single_table_tablespace(): Remove output of LSN. checkpoint_now_set(): Use fil_write_flushed_lsn and output a error if operation fails. Remove lsn variable from fsp_open_info. recv_recovery_from_checkpoint_start(): Remove unnecessary second flush_lsn parameter. log_empty_and_mark_files_at_shutdown(): Use fil_writte_flushed_lsn and output error if it fails. open_or_create_data_files(): Pass only one flushed_lsn variable.
9 years ago
MDEV-12113: install_db shows corruption for rest encryption with innodb_data_file_path=ibdata1:3M; Problem was that FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION field that for encrypted pages even in system datafiles should contain key_version except very first page (0:0) is after encryption overwritten with flush lsn. Ported WL#7990 Repurpose FIL_PAGE_FLUSH_LSN to 10.1 The field FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION is consulted during InnoDB startup. At startup, InnoDB reads the FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION from the first page of each file in the InnoDB system tablespace. If there are multiple files, the minimum and maximum LSN can differ. These numbers are passed to InnoDB startup. Having the number in other files than the first file of the InnoDB system tablespace is not providing much additional value. It is conflicting with other use of the field, such as on InnoDB R-tree index pages and encryption key_version. This worklog will stop writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to other files than the first file of the InnoDB system tablespace (page number 0:0) when system tablespace is encrypted. If tablespace is not encrypted we continue writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to all first pages of system tablespace to avoid unnecessary warnings on downgrade. open_or_create_data_files(): pass only one flushed_lsn parameter xb_load_tablespaces(): pass only one flushed_lsn parameter. buf_page_create(): Improve comment about where FIL_PAGE_FIL_FLUSH_LSN_OR_KEY_VERSION is set. fil_write_flushed_lsn(): A new function, merged from fil_write_lsn_and_arch_no_to_file() and fil_write_flushed_lsn_to_data_files(). Only write to the first page of the system tablespace (page 0:0) if tablespace is encrypted, or write all first pages of system tablespace and invoke fil_flush_file_spaces(FIL_TYPE_TABLESPACE) afterwards. fil_read_first_page(): read flush_lsn and crypt_data only from first datafile. fil_open_single_table_tablespace(): Remove output of LSN, because it was only valid for the system tablespace and the undo tablespaces, not user tablespaces. fil_validate_single_table_tablespace(): Remove output of LSN. checkpoint_now_set(): Use fil_write_flushed_lsn and output a error if operation fails. Remove lsn variable from fsp_open_info. recv_recovery_from_checkpoint_start(): Remove unnecessary second flush_lsn parameter. log_empty_and_mark_files_at_shutdown(): Use fil_writte_flushed_lsn and output error if it fails. open_or_create_data_files(): Pass only one flushed_lsn variable.
9 years ago
MDEV-12113: install_db shows corruption for rest encryption with innodb_data_file_path=ibdata1:3M; Problem was that FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION field that for encrypted pages even in system datafiles should contain key_version except very first page (0:0) is after encryption overwritten with flush lsn. Ported WL#7990 Repurpose FIL_PAGE_FLUSH_LSN to 10.1 The field FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION is consulted during InnoDB startup. At startup, InnoDB reads the FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION from the first page of each file in the InnoDB system tablespace. If there are multiple files, the minimum and maximum LSN can differ. These numbers are passed to InnoDB startup. Having the number in other files than the first file of the InnoDB system tablespace is not providing much additional value. It is conflicting with other use of the field, such as on InnoDB R-tree index pages and encryption key_version. This worklog will stop writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to other files than the first file of the InnoDB system tablespace (page number 0:0) when system tablespace is encrypted. If tablespace is not encrypted we continue writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to all first pages of system tablespace to avoid unnecessary warnings on downgrade. open_or_create_data_files(): pass only one flushed_lsn parameter xb_load_tablespaces(): pass only one flushed_lsn parameter. buf_page_create(): Improve comment about where FIL_PAGE_FIL_FLUSH_LSN_OR_KEY_VERSION is set. fil_write_flushed_lsn(): A new function, merged from fil_write_lsn_and_arch_no_to_file() and fil_write_flushed_lsn_to_data_files(). Only write to the first page of the system tablespace (page 0:0) if tablespace is encrypted, or write all first pages of system tablespace and invoke fil_flush_file_spaces(FIL_TYPE_TABLESPACE) afterwards. fil_read_first_page(): read flush_lsn and crypt_data only from first datafile. fil_open_single_table_tablespace(): Remove output of LSN, because it was only valid for the system tablespace and the undo tablespaces, not user tablespaces. fil_validate_single_table_tablespace(): Remove output of LSN. checkpoint_now_set(): Use fil_write_flushed_lsn and output a error if operation fails. Remove lsn variable from fsp_open_info. recv_recovery_from_checkpoint_start(): Remove unnecessary second flush_lsn parameter. log_empty_and_mark_files_at_shutdown(): Use fil_writte_flushed_lsn and output error if it fails. open_or_create_data_files(): Pass only one flushed_lsn variable.
9 years ago
MDEV-12113: install_db shows corruption for rest encryption with innodb_data_file_path=ibdata1:3M; Problem was that FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION field that for encrypted pages even in system datafiles should contain key_version except very first page (0:0) is after encryption overwritten with flush lsn. Ported WL#7990 Repurpose FIL_PAGE_FLUSH_LSN to 10.1 The field FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION is consulted during InnoDB startup. At startup, InnoDB reads the FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION from the first page of each file in the InnoDB system tablespace. If there are multiple files, the minimum and maximum LSN can differ. These numbers are passed to InnoDB startup. Having the number in other files than the first file of the InnoDB system tablespace is not providing much additional value. It is conflicting with other use of the field, such as on InnoDB R-tree index pages and encryption key_version. This worklog will stop writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to other files than the first file of the InnoDB system tablespace (page number 0:0) when system tablespace is encrypted. If tablespace is not encrypted we continue writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to all first pages of system tablespace to avoid unnecessary warnings on downgrade. open_or_create_data_files(): pass only one flushed_lsn parameter xb_load_tablespaces(): pass only one flushed_lsn parameter. buf_page_create(): Improve comment about where FIL_PAGE_FIL_FLUSH_LSN_OR_KEY_VERSION is set. fil_write_flushed_lsn(): A new function, merged from fil_write_lsn_and_arch_no_to_file() and fil_write_flushed_lsn_to_data_files(). Only write to the first page of the system tablespace (page 0:0) if tablespace is encrypted, or write all first pages of system tablespace and invoke fil_flush_file_spaces(FIL_TYPE_TABLESPACE) afterwards. fil_read_first_page(): read flush_lsn and crypt_data only from first datafile. fil_open_single_table_tablespace(): Remove output of LSN, because it was only valid for the system tablespace and the undo tablespaces, not user tablespaces. fil_validate_single_table_tablespace(): Remove output of LSN. checkpoint_now_set(): Use fil_write_flushed_lsn and output a error if operation fails. Remove lsn variable from fsp_open_info. recv_recovery_from_checkpoint_start(): Remove unnecessary second flush_lsn parameter. log_empty_and_mark_files_at_shutdown(): Use fil_writte_flushed_lsn and output error if it fails. open_or_create_data_files(): Pass only one flushed_lsn variable.
9 years ago
MDEV-12113: install_db shows corruption for rest encryption with innodb_data_file_path=ibdata1:3M; Problem was that FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION field that for encrypted pages even in system datafiles should contain key_version except very first page (0:0) is after encryption overwritten with flush lsn. Ported WL#7990 Repurpose FIL_PAGE_FLUSH_LSN to 10.1 The field FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION is consulted during InnoDB startup. At startup, InnoDB reads the FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION from the first page of each file in the InnoDB system tablespace. If there are multiple files, the minimum and maximum LSN can differ. These numbers are passed to InnoDB startup. Having the number in other files than the first file of the InnoDB system tablespace is not providing much additional value. It is conflicting with other use of the field, such as on InnoDB R-tree index pages and encryption key_version. This worklog will stop writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to other files than the first file of the InnoDB system tablespace (page number 0:0) when system tablespace is encrypted. If tablespace is not encrypted we continue writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to all first pages of system tablespace to avoid unnecessary warnings on downgrade. open_or_create_data_files(): pass only one flushed_lsn parameter xb_load_tablespaces(): pass only one flushed_lsn parameter. buf_page_create(): Improve comment about where FIL_PAGE_FIL_FLUSH_LSN_OR_KEY_VERSION is set. fil_write_flushed_lsn(): A new function, merged from fil_write_lsn_and_arch_no_to_file() and fil_write_flushed_lsn_to_data_files(). Only write to the first page of the system tablespace (page 0:0) if tablespace is encrypted, or write all first pages of system tablespace and invoke fil_flush_file_spaces(FIL_TYPE_TABLESPACE) afterwards. fil_read_first_page(): read flush_lsn and crypt_data only from first datafile. fil_open_single_table_tablespace(): Remove output of LSN, because it was only valid for the system tablespace and the undo tablespaces, not user tablespaces. fil_validate_single_table_tablespace(): Remove output of LSN. checkpoint_now_set(): Use fil_write_flushed_lsn and output a error if operation fails. Remove lsn variable from fsp_open_info. recv_recovery_from_checkpoint_start(): Remove unnecessary second flush_lsn parameter. log_empty_and_mark_files_at_shutdown(): Use fil_writte_flushed_lsn and output error if it fails. open_or_create_data_files(): Pass only one flushed_lsn variable.
9 years ago
MDEV-12113: install_db shows corruption for rest encryption with innodb_data_file_path=ibdata1:3M; Problem was that FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION field that for encrypted pages even in system datafiles should contain key_version except very first page (0:0) is after encryption overwritten with flush lsn. Ported WL#7990 Repurpose FIL_PAGE_FLUSH_LSN to 10.1 The field FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION is consulted during InnoDB startup. At startup, InnoDB reads the FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION from the first page of each file in the InnoDB system tablespace. If there are multiple files, the minimum and maximum LSN can differ. These numbers are passed to InnoDB startup. Having the number in other files than the first file of the InnoDB system tablespace is not providing much additional value. It is conflicting with other use of the field, such as on InnoDB R-tree index pages and encryption key_version. This worklog will stop writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to other files than the first file of the InnoDB system tablespace (page number 0:0) when system tablespace is encrypted. If tablespace is not encrypted we continue writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to all first pages of system tablespace to avoid unnecessary warnings on downgrade. open_or_create_data_files(): pass only one flushed_lsn parameter xb_load_tablespaces(): pass only one flushed_lsn parameter. buf_page_create(): Improve comment about where FIL_PAGE_FIL_FLUSH_LSN_OR_KEY_VERSION is set. fil_write_flushed_lsn(): A new function, merged from fil_write_lsn_and_arch_no_to_file() and fil_write_flushed_lsn_to_data_files(). Only write to the first page of the system tablespace (page 0:0) if tablespace is encrypted, or write all first pages of system tablespace and invoke fil_flush_file_spaces(FIL_TYPE_TABLESPACE) afterwards. fil_read_first_page(): read flush_lsn and crypt_data only from first datafile. fil_open_single_table_tablespace(): Remove output of LSN, because it was only valid for the system tablespace and the undo tablespaces, not user tablespaces. fil_validate_single_table_tablespace(): Remove output of LSN. checkpoint_now_set(): Use fil_write_flushed_lsn and output a error if operation fails. Remove lsn variable from fsp_open_info. recv_recovery_from_checkpoint_start(): Remove unnecessary second flush_lsn parameter. log_empty_and_mark_files_at_shutdown(): Use fil_writte_flushed_lsn and output error if it fails. open_or_create_data_files(): Pass only one flushed_lsn variable.
9 years ago
MDEV-12113: install_db shows corruption for rest encryption with innodb_data_file_path=ibdata1:3M; Problem was that FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION field that for encrypted pages even in system datafiles should contain key_version except very first page (0:0) is after encryption overwritten with flush lsn. Ported WL#7990 Repurpose FIL_PAGE_FLUSH_LSN to 10.1 The field FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION is consulted during InnoDB startup. At startup, InnoDB reads the FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION from the first page of each file in the InnoDB system tablespace. If there are multiple files, the minimum and maximum LSN can differ. These numbers are passed to InnoDB startup. Having the number in other files than the first file of the InnoDB system tablespace is not providing much additional value. It is conflicting with other use of the field, such as on InnoDB R-tree index pages and encryption key_version. This worklog will stop writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to other files than the first file of the InnoDB system tablespace (page number 0:0) when system tablespace is encrypted. If tablespace is not encrypted we continue writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to all first pages of system tablespace to avoid unnecessary warnings on downgrade. open_or_create_data_files(): pass only one flushed_lsn parameter xb_load_tablespaces(): pass only one flushed_lsn parameter. buf_page_create(): Improve comment about where FIL_PAGE_FIL_FLUSH_LSN_OR_KEY_VERSION is set. fil_write_flushed_lsn(): A new function, merged from fil_write_lsn_and_arch_no_to_file() and fil_write_flushed_lsn_to_data_files(). Only write to the first page of the system tablespace (page 0:0) if tablespace is encrypted, or write all first pages of system tablespace and invoke fil_flush_file_spaces(FIL_TYPE_TABLESPACE) afterwards. fil_read_first_page(): read flush_lsn and crypt_data only from first datafile. fil_open_single_table_tablespace(): Remove output of LSN, because it was only valid for the system tablespace and the undo tablespaces, not user tablespaces. fil_validate_single_table_tablespace(): Remove output of LSN. checkpoint_now_set(): Use fil_write_flushed_lsn and output a error if operation fails. Remove lsn variable from fsp_open_info. recv_recovery_from_checkpoint_start(): Remove unnecessary second flush_lsn parameter. log_empty_and_mark_files_at_shutdown(): Use fil_writte_flushed_lsn and output error if it fails. open_or_create_data_files(): Pass only one flushed_lsn variable.
9 years ago
MDEV-12113: install_db shows corruption for rest encryption with innodb_data_file_path=ibdata1:3M; Problem was that FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION field that for encrypted pages even in system datafiles should contain key_version except very first page (0:0) is after encryption overwritten with flush lsn. Ported WL#7990 Repurpose FIL_PAGE_FLUSH_LSN to 10.1 The field FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION is consulted during InnoDB startup. At startup, InnoDB reads the FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION from the first page of each file in the InnoDB system tablespace. If there are multiple files, the minimum and maximum LSN can differ. These numbers are passed to InnoDB startup. Having the number in other files than the first file of the InnoDB system tablespace is not providing much additional value. It is conflicting with other use of the field, such as on InnoDB R-tree index pages and encryption key_version. This worklog will stop writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to other files than the first file of the InnoDB system tablespace (page number 0:0) when system tablespace is encrypted. If tablespace is not encrypted we continue writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to all first pages of system tablespace to avoid unnecessary warnings on downgrade. open_or_create_data_files(): pass only one flushed_lsn parameter xb_load_tablespaces(): pass only one flushed_lsn parameter. buf_page_create(): Improve comment about where FIL_PAGE_FIL_FLUSH_LSN_OR_KEY_VERSION is set. fil_write_flushed_lsn(): A new function, merged from fil_write_lsn_and_arch_no_to_file() and fil_write_flushed_lsn_to_data_files(). Only write to the first page of the system tablespace (page 0:0) if tablespace is encrypted, or write all first pages of system tablespace and invoke fil_flush_file_spaces(FIL_TYPE_TABLESPACE) afterwards. fil_read_first_page(): read flush_lsn and crypt_data only from first datafile. fil_open_single_table_tablespace(): Remove output of LSN, because it was only valid for the system tablespace and the undo tablespaces, not user tablespaces. fil_validate_single_table_tablespace(): Remove output of LSN. checkpoint_now_set(): Use fil_write_flushed_lsn and output a error if operation fails. Remove lsn variable from fsp_open_info. recv_recovery_from_checkpoint_start(): Remove unnecessary second flush_lsn parameter. log_empty_and_mark_files_at_shutdown(): Use fil_writte_flushed_lsn and output error if it fails. open_or_create_data_files(): Pass only one flushed_lsn variable.
9 years ago
MDEV-11623 MariaDB 10.1 fails to start datadir created with MariaDB 10.0/MySQL 5.6 using innodb-page-size!=16K The storage format of FSP_SPACE_FLAGS was accidentally broken already in MariaDB 10.1.0. This fix is bringing the format in line with other MySQL and MariaDB release series. Please refer to the comments that were added to fsp0fsp.h for details. This is an INCOMPATIBLE CHANGE that affects users of page_compression and non-default innodb_page_size. Upgrading to this release will correct the flags in the data files. If you want to downgrade to earlier MariaDB 10.1.x, please refer to the test innodb.101_compatibility how to reset the FSP_SPACE_FLAGS in the files. NOTE: MariaDB 10.1.0 to 10.1.20 can misinterpret uncompressed data files with innodb_page_size=4k or 64k as compressed innodb_page_size=16k files, and then probably fail when trying to access the pages. See the comments in the function fsp_flags_convert_from_101() for detailed analysis. Move PAGE_COMPRESSION to FSP_SPACE_FLAGS bit position 16. In this way, compressed innodb_page_size=16k tablespaces will not be mistaken for uncompressed ones by MariaDB 10.1.0 to 10.1.20. Derive PAGE_COMPRESSION_LEVEL, ATOMIC_WRITES and DATA_DIR from the dict_table_t::flags when the table is available, in fil_space_for_table_exists_in_mem() or fil_open_single_table_tablespace(). During crash recovery, fil_load_single_table_tablespace() will use innodb_compression_level for the PAGE_COMPRESSION_LEVEL. FSP_FLAGS_MEM_MASK: A bitmap of the memory-only fil_space_t::flags that are not to be written to FSP_SPACE_FLAGS. Currently, these will include PAGE_COMPRESSION_LEVEL, ATOMIC_WRITES and DATA_DIR. Introduce the macro FSP_FLAGS_PAGE_SSIZE(). We only support one innodb_page_size for the whole instance. When creating a dummy tablespace for the redo log, use fil_space_t::flags=0. The flags are never written to the redo log files. Remove many FSP_FLAGS_SET_ macros. dict_tf_verify_flags(): Remove. This is basically only duplicating the logic of dict_tf_to_fsp_flags(), used in a debug assertion. fil_space_t::mark: Remove. This flag was not used for anything. fil_space_for_table_exists_in_mem(): Remove the unnecessary parameter mark_space, and add a parameter for table flags. Check that fil_space_t::flags match the table flags, and adjust the (memory-only) flags based on the table flags. fil_node_open_file(): Remove some redundant or unreachable conditions, do not use stderr for output, and avoid unnecessary server aborts. fil_user_tablespace_restore_page(): Convert the flags, so that the correct page_size will be used when restoring a page from the doublewrite buffer. fil_space_get_page_compressed(), fsp_flags_is_page_compressed(): Remove. It suffices to have fil_space_is_page_compressed(). FSP_FLAGS_WIDTH_DATA_DIR, FSP_FLAGS_WIDTH_PAGE_COMPRESSION_LEVEL, FSP_FLAGS_WIDTH_ATOMIC_WRITES: Remove, because these flags do not exist in the FSP_SPACE_FLAGS but only in memory. fsp_flags_try_adjust(): New function, to adjust the FSP_SPACE_FLAGS in page 0. Called by fil_open_single_table_tablespace(), fil_space_for_table_exists_in_mem(), innobase_start_or_create_for_mysql() except if --innodb-read-only is active. fsp_flags_is_valid(ulint): Reimplement from the scratch, with accurate comments. Do not display any details of detected inconsistencies, because the output could be confusing when dealing with MariaDB 10.1.x data files. fsp_flags_convert_from_101(ulint): Convert flags from buggy MariaDB 10.1.x format, or return ULINT_UNDEFINED if the flags cannot be in MariaDB 10.1.x format. fsp_flags_match(): Check the flags when probing files. Implemented based on fsp_flags_is_valid() and fsp_flags_convert_from_101(). dict_check_tablespaces_and_store_max_id(): Do not access the page after committing the mini-transaction. IMPORT TABLESPACE fixes: AbstractCallback::init(): Convert the flags. FetchIndexRootPages::operator(): Check that the tablespace flags match the table flags. Do not attempt to convert tablespace flags to table flags, because the conversion would necessarily be lossy. PageConverter::update_header(): Write back the correct flags. This takes care of the flags in IMPORT TABLESPACE.
9 years ago
Merge Google encryption commit 195158e9889365dc3298f8c1f3bcaa745992f27f Author: Minli Zhu <minliz@google.com> Date: Mon Nov 25 11:05:55 2013 -0800 Innodb redo log encryption/decryption. Use start lsn of a log block as part of AES CTR counter. Record key version with each checkpoint. Internally key version 0 means no encryption. Tests done (see test_innodb_log_encryption.sh for detail): - Verify flag innodb_encrypt_log on or off, combined with various key versions passed through CLI, and dynamically set after startup, will not corrupt database. This includes tests from being unencrypted to encrypted, and encrypted to unencrypted. - Verify start-up with no redo logs succeeds. - Verify fresh start-up succeeds. Change-Id: I4ce4c2afdf3076be2fce90ebbc2a7ce01184b612 commit c1b97273659f07866758c25f4a56f680a1fbad24 Author: Jonas Oreland <jonaso@google.com> Date: Tue Dec 3 18:47:27 2013 +0100 encryption of aria data&index files this patch implements encryption of aria data & index files. this is implemented as 1) add read/write hooks (renamed from callbacks) that does encrypt/decrypt (also add pre_read and post_write hooks) 2) modify page headers for data/index to contain key version (making the data-page header size different for with/without encryption) 3) modify index page 0 to contain IV (and crypt header) 4) AES CRT crypt functions 5) counter block is implemented using combination of page no, lsn and table specific id NOTE: 1) log files are not encrypted, this is not needed for if aria is only used for internal temporary tables and they are not transactional (i.e not logged) 2) all encrypted tables are using PAGE_CHECKSUM (crc) normal internal temporary tables are (currently) not CHECKSUM:ed 3) This patch adds insert-order semantics to aria block_format. The default behaviour of aria block-format is best-fit, meaning that rows gets allocated to page trying to fill the pages as much as possible. However, certain sql constructs materialize temporary result in tmp-tables, and expect that a table scan will later return the rows in the same order they were inserted. This implementation of insert-order is only enabled when explicitly requested by sql-layer. CHANGES: 1) found bug in ma_write that made code try to abort a record that was never written unsure why this is not exposed Change-Id: Ia82bbaa92e2c0629c08693c5add2f56b815c0509 commit 89dc1ab651fe0205d55b4eb588f62df550aa65fc Author: Jonas Oreland <jonaso@google.com> Date: Mon Feb 17 08:04:50 2014 -0800 Implement encryption of innodb datafiles. Pages are encrypted before written to disk and decrypted when read from disk. Each page except first page (page 0) in tablespace is encrypted. Page 0 is unencrypted and contains IV for the tablespace. FIL_PAGE_FILE_FLUSH_LSN on each page (except page 0) is used to store a 32-bit key-version, so that multiple keys can be active in a tablespace simultaneous. The other 32-bit of the FIL_PAGE_FILE_FLUSH_LSN field contains a checksum that is computed after encryption. This checksum is used by innochecksum and when restoring from double-write-buffer. The encryption is performed using AES CRT. Monitoring of encryption is enabled using new IS-table INNODB_TABLESPACES_ENCRYPTION. In addition to that new status variables innodb_encryption_rotation_{ pages_read_from_cache, pages_read_from_disk, pages_modified,pages_flushed } has been added. The following tunables are introduces - innodb_encrypt_tables - innodb_encryption_threads - innodb_encryption_rotate_key_age - innodb_encryption_rotation_iops Change-Id: I8f651795a30b52e71b16d6bc9cb7559be349d0b2 commit a17eef2f6948e58219c9e26fc35633d6fd4de1de Author: Andrew Ford <andrewford@google.com> Date: Thu Jan 2 15:43:09 2014 -0800 Key management skeleton with debug hooks. Change-Id: Ifd6aa3743d7ea291c70083f433a059c439aed866 commit 68a399838ad72264fd61b3dc67fecd29bbdb0af1 Author: Andrew Ford <andrewford@google.com> Date: Mon Oct 28 16:27:44 2013 -0700 Add AES-128 CTR and GCM encryption classes. Change-Id: I116305eced2a233db15306bc2ef5b9d398d1a3a2
11 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
9 years ago
9 years ago
Merge Google encryption commit 195158e9889365dc3298f8c1f3bcaa745992f27f Author: Minli Zhu <minliz@google.com> Date: Mon Nov 25 11:05:55 2013 -0800 Innodb redo log encryption/decryption. Use start lsn of a log block as part of AES CTR counter. Record key version with each checkpoint. Internally key version 0 means no encryption. Tests done (see test_innodb_log_encryption.sh for detail): - Verify flag innodb_encrypt_log on or off, combined with various key versions passed through CLI, and dynamically set after startup, will not corrupt database. This includes tests from being unencrypted to encrypted, and encrypted to unencrypted. - Verify start-up with no redo logs succeeds. - Verify fresh start-up succeeds. Change-Id: I4ce4c2afdf3076be2fce90ebbc2a7ce01184b612 commit c1b97273659f07866758c25f4a56f680a1fbad24 Author: Jonas Oreland <jonaso@google.com> Date: Tue Dec 3 18:47:27 2013 +0100 encryption of aria data&index files this patch implements encryption of aria data & index files. this is implemented as 1) add read/write hooks (renamed from callbacks) that does encrypt/decrypt (also add pre_read and post_write hooks) 2) modify page headers for data/index to contain key version (making the data-page header size different for with/without encryption) 3) modify index page 0 to contain IV (and crypt header) 4) AES CRT crypt functions 5) counter block is implemented using combination of page no, lsn and table specific id NOTE: 1) log files are not encrypted, this is not needed for if aria is only used for internal temporary tables and they are not transactional (i.e not logged) 2) all encrypted tables are using PAGE_CHECKSUM (crc) normal internal temporary tables are (currently) not CHECKSUM:ed 3) This patch adds insert-order semantics to aria block_format. The default behaviour of aria block-format is best-fit, meaning that rows gets allocated to page trying to fill the pages as much as possible. However, certain sql constructs materialize temporary result in tmp-tables, and expect that a table scan will later return the rows in the same order they were inserted. This implementation of insert-order is only enabled when explicitly requested by sql-layer. CHANGES: 1) found bug in ma_write that made code try to abort a record that was never written unsure why this is not exposed Change-Id: Ia82bbaa92e2c0629c08693c5add2f56b815c0509 commit 89dc1ab651fe0205d55b4eb588f62df550aa65fc Author: Jonas Oreland <jonaso@google.com> Date: Mon Feb 17 08:04:50 2014 -0800 Implement encryption of innodb datafiles. Pages are encrypted before written to disk and decrypted when read from disk. Each page except first page (page 0) in tablespace is encrypted. Page 0 is unencrypted and contains IV for the tablespace. FIL_PAGE_FILE_FLUSH_LSN on each page (except page 0) is used to store a 32-bit key-version, so that multiple keys can be active in a tablespace simultaneous. The other 32-bit of the FIL_PAGE_FILE_FLUSH_LSN field contains a checksum that is computed after encryption. This checksum is used by innochecksum and when restoring from double-write-buffer. The encryption is performed using AES CRT. Monitoring of encryption is enabled using new IS-table INNODB_TABLESPACES_ENCRYPTION. In addition to that new status variables innodb_encryption_rotation_{ pages_read_from_cache, pages_read_from_disk, pages_modified,pages_flushed } has been added. The following tunables are introduces - innodb_encrypt_tables - innodb_encryption_threads - innodb_encryption_rotate_key_age - innodb_encryption_rotation_iops Change-Id: I8f651795a30b52e71b16d6bc9cb7559be349d0b2 commit a17eef2f6948e58219c9e26fc35633d6fd4de1de Author: Andrew Ford <andrewford@google.com> Date: Thu Jan 2 15:43:09 2014 -0800 Key management skeleton with debug hooks. Change-Id: Ifd6aa3743d7ea291c70083f433a059c439aed866 commit 68a399838ad72264fd61b3dc67fecd29bbdb0af1 Author: Andrew Ford <andrewford@google.com> Date: Mon Oct 28 16:27:44 2013 -0700 Add AES-128 CTR and GCM encryption classes. Change-Id: I116305eced2a233db15306bc2ef5b9d398d1a3a2
11 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
16 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-12113: install_db shows corruption for rest encryption with innodb_data_file_path=ibdata1:3M; Problem was that FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION field that for encrypted pages even in system datafiles should contain key_version except very first page (0:0) is after encryption overwritten with flush lsn. Ported WL#7990 Repurpose FIL_PAGE_FLUSH_LSN to 10.1 The field FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION is consulted during InnoDB startup. At startup, InnoDB reads the FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION from the first page of each file in the InnoDB system tablespace. If there are multiple files, the minimum and maximum LSN can differ. These numbers are passed to InnoDB startup. Having the number in other files than the first file of the InnoDB system tablespace is not providing much additional value. It is conflicting with other use of the field, such as on InnoDB R-tree index pages and encryption key_version. This worklog will stop writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to other files than the first file of the InnoDB system tablespace (page number 0:0) when system tablespace is encrypted. If tablespace is not encrypted we continue writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to all first pages of system tablespace to avoid unnecessary warnings on downgrade. open_or_create_data_files(): pass only one flushed_lsn parameter xb_load_tablespaces(): pass only one flushed_lsn parameter. buf_page_create(): Improve comment about where FIL_PAGE_FIL_FLUSH_LSN_OR_KEY_VERSION is set. fil_write_flushed_lsn(): A new function, merged from fil_write_lsn_and_arch_no_to_file() and fil_write_flushed_lsn_to_data_files(). Only write to the first page of the system tablespace (page 0:0) if tablespace is encrypted, or write all first pages of system tablespace and invoke fil_flush_file_spaces(FIL_TYPE_TABLESPACE) afterwards. fil_read_first_page(): read flush_lsn and crypt_data only from first datafile. fil_open_single_table_tablespace(): Remove output of LSN, because it was only valid for the system tablespace and the undo tablespaces, not user tablespaces. fil_validate_single_table_tablespace(): Remove output of LSN. checkpoint_now_set(): Use fil_write_flushed_lsn and output a error if operation fails. Remove lsn variable from fsp_open_info. recv_recovery_from_checkpoint_start(): Remove unnecessary second flush_lsn parameter. log_empty_and_mark_files_at_shutdown(): Use fil_writte_flushed_lsn and output error if it fails. open_or_create_data_files(): Pass only one flushed_lsn variable.
9 years ago
11 years ago
16 years ago
9 years ago
10 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
17 years ago
15 years ago
17 years ago
15 years ago
16 years ago
15 years ago
16 years ago
15 years ago
15 years ago
15 years ago
16 years ago
15 years ago
16 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
10 years ago
10 years ago
10 years ago
16 years ago
16 years ago
16 years ago
16 years ago
15 years ago
16 years ago
15 years ago
16 years ago
10 years ago
15 years ago
9 years ago
15 years ago
15 years ago
15 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-12113: install_db shows corruption for rest encryption with innodb_data_file_path=ibdata1:3M; Problem was that FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION field that for encrypted pages even in system datafiles should contain key_version except very first page (0:0) is after encryption overwritten with flush lsn. Ported WL#7990 Repurpose FIL_PAGE_FLUSH_LSN to 10.1 The field FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION is consulted during InnoDB startup. At startup, InnoDB reads the FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION from the first page of each file in the InnoDB system tablespace. If there are multiple files, the minimum and maximum LSN can differ. These numbers are passed to InnoDB startup. Having the number in other files than the first file of the InnoDB system tablespace is not providing much additional value. It is conflicting with other use of the field, such as on InnoDB R-tree index pages and encryption key_version. This worklog will stop writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to other files than the first file of the InnoDB system tablespace (page number 0:0) when system tablespace is encrypted. If tablespace is not encrypted we continue writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to all first pages of system tablespace to avoid unnecessary warnings on downgrade. open_or_create_data_files(): pass only one flushed_lsn parameter xb_load_tablespaces(): pass only one flushed_lsn parameter. buf_page_create(): Improve comment about where FIL_PAGE_FIL_FLUSH_LSN_OR_KEY_VERSION is set. fil_write_flushed_lsn(): A new function, merged from fil_write_lsn_and_arch_no_to_file() and fil_write_flushed_lsn_to_data_files(). Only write to the first page of the system tablespace (page 0:0) if tablespace is encrypted, or write all first pages of system tablespace and invoke fil_flush_file_spaces(FIL_TYPE_TABLESPACE) afterwards. fil_read_first_page(): read flush_lsn and crypt_data only from first datafile. fil_open_single_table_tablespace(): Remove output of LSN, because it was only valid for the system tablespace and the undo tablespaces, not user tablespaces. fil_validate_single_table_tablespace(): Remove output of LSN. checkpoint_now_set(): Use fil_write_flushed_lsn and output a error if operation fails. Remove lsn variable from fsp_open_info. recv_recovery_from_checkpoint_start(): Remove unnecessary second flush_lsn parameter. log_empty_and_mark_files_at_shutdown(): Use fil_writte_flushed_lsn and output error if it fails. open_or_create_data_files(): Pass only one flushed_lsn variable.
9 years ago
MDEV-12113: install_db shows corruption for rest encryption with innodb_data_file_path=ibdata1:3M; Problem was that FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION field that for encrypted pages even in system datafiles should contain key_version except very first page (0:0) is after encryption overwritten with flush lsn. Ported WL#7990 Repurpose FIL_PAGE_FLUSH_LSN to 10.1 The field FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION is consulted during InnoDB startup. At startup, InnoDB reads the FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION from the first page of each file in the InnoDB system tablespace. If there are multiple files, the minimum and maximum LSN can differ. These numbers are passed to InnoDB startup. Having the number in other files than the first file of the InnoDB system tablespace is not providing much additional value. It is conflicting with other use of the field, such as on InnoDB R-tree index pages and encryption key_version. This worklog will stop writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to other files than the first file of the InnoDB system tablespace (page number 0:0) when system tablespace is encrypted. If tablespace is not encrypted we continue writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to all first pages of system tablespace to avoid unnecessary warnings on downgrade. open_or_create_data_files(): pass only one flushed_lsn parameter xb_load_tablespaces(): pass only one flushed_lsn parameter. buf_page_create(): Improve comment about where FIL_PAGE_FIL_FLUSH_LSN_OR_KEY_VERSION is set. fil_write_flushed_lsn(): A new function, merged from fil_write_lsn_and_arch_no_to_file() and fil_write_flushed_lsn_to_data_files(). Only write to the first page of the system tablespace (page 0:0) if tablespace is encrypted, or write all first pages of system tablespace and invoke fil_flush_file_spaces(FIL_TYPE_TABLESPACE) afterwards. fil_read_first_page(): read flush_lsn and crypt_data only from first datafile. fil_open_single_table_tablespace(): Remove output of LSN, because it was only valid for the system tablespace and the undo tablespaces, not user tablespaces. fil_validate_single_table_tablespace(): Remove output of LSN. checkpoint_now_set(): Use fil_write_flushed_lsn and output a error if operation fails. Remove lsn variable from fsp_open_info. recv_recovery_from_checkpoint_start(): Remove unnecessary second flush_lsn parameter. log_empty_and_mark_files_at_shutdown(): Use fil_writte_flushed_lsn and output error if it fails. open_or_create_data_files(): Pass only one flushed_lsn variable.
9 years ago
MDEV-12113: install_db shows corruption for rest encryption with innodb_data_file_path=ibdata1:3M; Problem was that FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION field that for encrypted pages even in system datafiles should contain key_version except very first page (0:0) is after encryption overwritten with flush lsn. Ported WL#7990 Repurpose FIL_PAGE_FLUSH_LSN to 10.1 The field FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION is consulted during InnoDB startup. At startup, InnoDB reads the FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION from the first page of each file in the InnoDB system tablespace. If there are multiple files, the minimum and maximum LSN can differ. These numbers are passed to InnoDB startup. Having the number in other files than the first file of the InnoDB system tablespace is not providing much additional value. It is conflicting with other use of the field, such as on InnoDB R-tree index pages and encryption key_version. This worklog will stop writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to other files than the first file of the InnoDB system tablespace (page number 0:0) when system tablespace is encrypted. If tablespace is not encrypted we continue writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to all first pages of system tablespace to avoid unnecessary warnings on downgrade. open_or_create_data_files(): pass only one flushed_lsn parameter xb_load_tablespaces(): pass only one flushed_lsn parameter. buf_page_create(): Improve comment about where FIL_PAGE_FIL_FLUSH_LSN_OR_KEY_VERSION is set. fil_write_flushed_lsn(): A new function, merged from fil_write_lsn_and_arch_no_to_file() and fil_write_flushed_lsn_to_data_files(). Only write to the first page of the system tablespace (page 0:0) if tablespace is encrypted, or write all first pages of system tablespace and invoke fil_flush_file_spaces(FIL_TYPE_TABLESPACE) afterwards. fil_read_first_page(): read flush_lsn and crypt_data only from first datafile. fil_open_single_table_tablespace(): Remove output of LSN, because it was only valid for the system tablespace and the undo tablespaces, not user tablespaces. fil_validate_single_table_tablespace(): Remove output of LSN. checkpoint_now_set(): Use fil_write_flushed_lsn and output a error if operation fails. Remove lsn variable from fsp_open_info. recv_recovery_from_checkpoint_start(): Remove unnecessary second flush_lsn parameter. log_empty_and_mark_files_at_shutdown(): Use fil_writte_flushed_lsn and output error if it fails. open_or_create_data_files(): Pass only one flushed_lsn variable.
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-12113: install_db shows corruption for rest encryption with innodb_data_file_path=ibdata1:3M; Problem was that FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION field that for encrypted pages even in system datafiles should contain key_version except very first page (0:0) is after encryption overwritten with flush lsn. Ported WL#7990 Repurpose FIL_PAGE_FLUSH_LSN to 10.1 The field FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION is consulted during InnoDB startup. At startup, InnoDB reads the FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION from the first page of each file in the InnoDB system tablespace. If there are multiple files, the minimum and maximum LSN can differ. These numbers are passed to InnoDB startup. Having the number in other files than the first file of the InnoDB system tablespace is not providing much additional value. It is conflicting with other use of the field, such as on InnoDB R-tree index pages and encryption key_version. This worklog will stop writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to other files than the first file of the InnoDB system tablespace (page number 0:0) when system tablespace is encrypted. If tablespace is not encrypted we continue writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to all first pages of system tablespace to avoid unnecessary warnings on downgrade. open_or_create_data_files(): pass only one flushed_lsn parameter xb_load_tablespaces(): pass only one flushed_lsn parameter. buf_page_create(): Improve comment about where FIL_PAGE_FIL_FLUSH_LSN_OR_KEY_VERSION is set. fil_write_flushed_lsn(): A new function, merged from fil_write_lsn_and_arch_no_to_file() and fil_write_flushed_lsn_to_data_files(). Only write to the first page of the system tablespace (page 0:0) if tablespace is encrypted, or write all first pages of system tablespace and invoke fil_flush_file_spaces(FIL_TYPE_TABLESPACE) afterwards. fil_read_first_page(): read flush_lsn and crypt_data only from first datafile. fil_open_single_table_tablespace(): Remove output of LSN, because it was only valid for the system tablespace and the undo tablespaces, not user tablespaces. fil_validate_single_table_tablespace(): Remove output of LSN. checkpoint_now_set(): Use fil_write_flushed_lsn and output a error if operation fails. Remove lsn variable from fsp_open_info. recv_recovery_from_checkpoint_start(): Remove unnecessary second flush_lsn parameter. log_empty_and_mark_files_at_shutdown(): Use fil_writte_flushed_lsn and output error if it fails. open_or_create_data_files(): Pass only one flushed_lsn variable.
9 years ago
MDEV-12113: install_db shows corruption for rest encryption with innodb_data_file_path=ibdata1:3M; Problem was that FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION field that for encrypted pages even in system datafiles should contain key_version except very first page (0:0) is after encryption overwritten with flush lsn. Ported WL#7990 Repurpose FIL_PAGE_FLUSH_LSN to 10.1 The field FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION is consulted during InnoDB startup. At startup, InnoDB reads the FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION from the first page of each file in the InnoDB system tablespace. If there are multiple files, the minimum and maximum LSN can differ. These numbers are passed to InnoDB startup. Having the number in other files than the first file of the InnoDB system tablespace is not providing much additional value. It is conflicting with other use of the field, such as on InnoDB R-tree index pages and encryption key_version. This worklog will stop writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to other files than the first file of the InnoDB system tablespace (page number 0:0) when system tablespace is encrypted. If tablespace is not encrypted we continue writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to all first pages of system tablespace to avoid unnecessary warnings on downgrade. open_or_create_data_files(): pass only one flushed_lsn parameter xb_load_tablespaces(): pass only one flushed_lsn parameter. buf_page_create(): Improve comment about where FIL_PAGE_FIL_FLUSH_LSN_OR_KEY_VERSION is set. fil_write_flushed_lsn(): A new function, merged from fil_write_lsn_and_arch_no_to_file() and fil_write_flushed_lsn_to_data_files(). Only write to the first page of the system tablespace (page 0:0) if tablespace is encrypted, or write all first pages of system tablespace and invoke fil_flush_file_spaces(FIL_TYPE_TABLESPACE) afterwards. fil_read_first_page(): read flush_lsn and crypt_data only from first datafile. fil_open_single_table_tablespace(): Remove output of LSN, because it was only valid for the system tablespace and the undo tablespaces, not user tablespaces. fil_validate_single_table_tablespace(): Remove output of LSN. checkpoint_now_set(): Use fil_write_flushed_lsn and output a error if operation fails. Remove lsn variable from fsp_open_info. recv_recovery_from_checkpoint_start(): Remove unnecessary second flush_lsn parameter. log_empty_and_mark_files_at_shutdown(): Use fil_writte_flushed_lsn and output error if it fails. open_or_create_data_files(): Pass only one flushed_lsn variable.
9 years ago
MDEV-12113: install_db shows corruption for rest encryption with innodb_data_file_path=ibdata1:3M; Problem was that FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION field that for encrypted pages even in system datafiles should contain key_version except very first page (0:0) is after encryption overwritten with flush lsn. Ported WL#7990 Repurpose FIL_PAGE_FLUSH_LSN to 10.1 The field FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION is consulted during InnoDB startup. At startup, InnoDB reads the FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION from the first page of each file in the InnoDB system tablespace. If there are multiple files, the minimum and maximum LSN can differ. These numbers are passed to InnoDB startup. Having the number in other files than the first file of the InnoDB system tablespace is not providing much additional value. It is conflicting with other use of the field, such as on InnoDB R-tree index pages and encryption key_version. This worklog will stop writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to other files than the first file of the InnoDB system tablespace (page number 0:0) when system tablespace is encrypted. If tablespace is not encrypted we continue writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to all first pages of system tablespace to avoid unnecessary warnings on downgrade. open_or_create_data_files(): pass only one flushed_lsn parameter xb_load_tablespaces(): pass only one flushed_lsn parameter. buf_page_create(): Improve comment about where FIL_PAGE_FIL_FLUSH_LSN_OR_KEY_VERSION is set. fil_write_flushed_lsn(): A new function, merged from fil_write_lsn_and_arch_no_to_file() and fil_write_flushed_lsn_to_data_files(). Only write to the first page of the system tablespace (page 0:0) if tablespace is encrypted, or write all first pages of system tablespace and invoke fil_flush_file_spaces(FIL_TYPE_TABLESPACE) afterwards. fil_read_first_page(): read flush_lsn and crypt_data only from first datafile. fil_open_single_table_tablespace(): Remove output of LSN, because it was only valid for the system tablespace and the undo tablespaces, not user tablespaces. fil_validate_single_table_tablespace(): Remove output of LSN. checkpoint_now_set(): Use fil_write_flushed_lsn and output a error if operation fails. Remove lsn variable from fsp_open_info. recv_recovery_from_checkpoint_start(): Remove unnecessary second flush_lsn parameter. log_empty_and_mark_files_at_shutdown(): Use fil_writte_flushed_lsn and output error if it fails. open_or_create_data_files(): Pass only one flushed_lsn variable.
9 years ago
MDEV-12113: install_db shows corruption for rest encryption with innodb_data_file_path=ibdata1:3M; Problem was that FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION field that for encrypted pages even in system datafiles should contain key_version except very first page (0:0) is after encryption overwritten with flush lsn. Ported WL#7990 Repurpose FIL_PAGE_FLUSH_LSN to 10.1 The field FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION is consulted during InnoDB startup. At startup, InnoDB reads the FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION from the first page of each file in the InnoDB system tablespace. If there are multiple files, the minimum and maximum LSN can differ. These numbers are passed to InnoDB startup. Having the number in other files than the first file of the InnoDB system tablespace is not providing much additional value. It is conflicting with other use of the field, such as on InnoDB R-tree index pages and encryption key_version. This worklog will stop writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to other files than the first file of the InnoDB system tablespace (page number 0:0) when system tablespace is encrypted. If tablespace is not encrypted we continue writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to all first pages of system tablespace to avoid unnecessary warnings on downgrade. open_or_create_data_files(): pass only one flushed_lsn parameter xb_load_tablespaces(): pass only one flushed_lsn parameter. buf_page_create(): Improve comment about where FIL_PAGE_FIL_FLUSH_LSN_OR_KEY_VERSION is set. fil_write_flushed_lsn(): A new function, merged from fil_write_lsn_and_arch_no_to_file() and fil_write_flushed_lsn_to_data_files(). Only write to the first page of the system tablespace (page 0:0) if tablespace is encrypted, or write all first pages of system tablespace and invoke fil_flush_file_spaces(FIL_TYPE_TABLESPACE) afterwards. fil_read_first_page(): read flush_lsn and crypt_data only from first datafile. fil_open_single_table_tablespace(): Remove output of LSN, because it was only valid for the system tablespace and the undo tablespaces, not user tablespaces. fil_validate_single_table_tablespace(): Remove output of LSN. checkpoint_now_set(): Use fil_write_flushed_lsn and output a error if operation fails. Remove lsn variable from fsp_open_info. recv_recovery_from_checkpoint_start(): Remove unnecessary second flush_lsn parameter. log_empty_and_mark_files_at_shutdown(): Use fil_writte_flushed_lsn and output error if it fails. open_or_create_data_files(): Pass only one flushed_lsn variable.
9 years ago
MDEV-11623 MariaDB 10.1 fails to start datadir created with MariaDB 10.0/MySQL 5.6 using innodb-page-size!=16K The storage format of FSP_SPACE_FLAGS was accidentally broken already in MariaDB 10.1.0. This fix is bringing the format in line with other MySQL and MariaDB release series. Please refer to the comments that were added to fsp0fsp.h for details. This is an INCOMPATIBLE CHANGE that affects users of page_compression and non-default innodb_page_size. Upgrading to this release will correct the flags in the data files. If you want to downgrade to earlier MariaDB 10.1.x, please refer to the test innodb.101_compatibility how to reset the FSP_SPACE_FLAGS in the files. NOTE: MariaDB 10.1.0 to 10.1.20 can misinterpret uncompressed data files with innodb_page_size=4k or 64k as compressed innodb_page_size=16k files, and then probably fail when trying to access the pages. See the comments in the function fsp_flags_convert_from_101() for detailed analysis. Move PAGE_COMPRESSION to FSP_SPACE_FLAGS bit position 16. In this way, compressed innodb_page_size=16k tablespaces will not be mistaken for uncompressed ones by MariaDB 10.1.0 to 10.1.20. Derive PAGE_COMPRESSION_LEVEL, ATOMIC_WRITES and DATA_DIR from the dict_table_t::flags when the table is available, in fil_space_for_table_exists_in_mem() or fil_open_single_table_tablespace(). During crash recovery, fil_load_single_table_tablespace() will use innodb_compression_level for the PAGE_COMPRESSION_LEVEL. FSP_FLAGS_MEM_MASK: A bitmap of the memory-only fil_space_t::flags that are not to be written to FSP_SPACE_FLAGS. Currently, these will include PAGE_COMPRESSION_LEVEL, ATOMIC_WRITES and DATA_DIR. Introduce the macro FSP_FLAGS_PAGE_SSIZE(). We only support one innodb_page_size for the whole instance. When creating a dummy tablespace for the redo log, use fil_space_t::flags=0. The flags are never written to the redo log files. Remove many FSP_FLAGS_SET_ macros. dict_tf_verify_flags(): Remove. This is basically only duplicating the logic of dict_tf_to_fsp_flags(), used in a debug assertion. fil_space_t::mark: Remove. This flag was not used for anything. fil_space_for_table_exists_in_mem(): Remove the unnecessary parameter mark_space, and add a parameter for table flags. Check that fil_space_t::flags match the table flags, and adjust the (memory-only) flags based on the table flags. fil_node_open_file(): Remove some redundant or unreachable conditions, do not use stderr for output, and avoid unnecessary server aborts. fil_user_tablespace_restore_page(): Convert the flags, so that the correct page_size will be used when restoring a page from the doublewrite buffer. fil_space_get_page_compressed(), fsp_flags_is_page_compressed(): Remove. It suffices to have fil_space_is_page_compressed(). FSP_FLAGS_WIDTH_DATA_DIR, FSP_FLAGS_WIDTH_PAGE_COMPRESSION_LEVEL, FSP_FLAGS_WIDTH_ATOMIC_WRITES: Remove, because these flags do not exist in the FSP_SPACE_FLAGS but only in memory. fsp_flags_try_adjust(): New function, to adjust the FSP_SPACE_FLAGS in page 0. Called by fil_open_single_table_tablespace(), fil_space_for_table_exists_in_mem(), innobase_start_or_create_for_mysql() except if --innodb-read-only is active. fsp_flags_is_valid(ulint): Reimplement from the scratch, with accurate comments. Do not display any details of detected inconsistencies, because the output could be confusing when dealing with MariaDB 10.1.x data files. fsp_flags_convert_from_101(ulint): Convert flags from buggy MariaDB 10.1.x format, or return ULINT_UNDEFINED if the flags cannot be in MariaDB 10.1.x format. fsp_flags_match(): Check the flags when probing files. Implemented based on fsp_flags_is_valid() and fsp_flags_convert_from_101(). dict_check_tablespaces_and_store_max_id(): Do not access the page after committing the mini-transaction. IMPORT TABLESPACE fixes: AbstractCallback::init(): Convert the flags. FetchIndexRootPages::operator(): Check that the tablespace flags match the table flags. Do not attempt to convert tablespace flags to table flags, because the conversion would necessarily be lossy. PageConverter::update_header(): Write back the correct flags. This takes care of the flags in IMPORT TABLESPACE.
9 years ago
15 years ago
15 years ago
15 years ago
MDEV-12113: install_db shows corruption for rest encryption with innodb_data_file_path=ibdata1:3M; Problem was that FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION field that for encrypted pages even in system datafiles should contain key_version except very first page (0:0) is after encryption overwritten with flush lsn. Ported WL#7990 Repurpose FIL_PAGE_FLUSH_LSN to 10.1 The field FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION is consulted during InnoDB startup. At startup, InnoDB reads the FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION from the first page of each file in the InnoDB system tablespace. If there are multiple files, the minimum and maximum LSN can differ. These numbers are passed to InnoDB startup. Having the number in other files than the first file of the InnoDB system tablespace is not providing much additional value. It is conflicting with other use of the field, such as on InnoDB R-tree index pages and encryption key_version. This worklog will stop writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to other files than the first file of the InnoDB system tablespace (page number 0:0) when system tablespace is encrypted. If tablespace is not encrypted we continue writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to all first pages of system tablespace to avoid unnecessary warnings on downgrade. open_or_create_data_files(): pass only one flushed_lsn parameter xb_load_tablespaces(): pass only one flushed_lsn parameter. buf_page_create(): Improve comment about where FIL_PAGE_FIL_FLUSH_LSN_OR_KEY_VERSION is set. fil_write_flushed_lsn(): A new function, merged from fil_write_lsn_and_arch_no_to_file() and fil_write_flushed_lsn_to_data_files(). Only write to the first page of the system tablespace (page 0:0) if tablespace is encrypted, or write all first pages of system tablespace and invoke fil_flush_file_spaces(FIL_TYPE_TABLESPACE) afterwards. fil_read_first_page(): read flush_lsn and crypt_data only from first datafile. fil_open_single_table_tablespace(): Remove output of LSN, because it was only valid for the system tablespace and the undo tablespaces, not user tablespaces. fil_validate_single_table_tablespace(): Remove output of LSN. checkpoint_now_set(): Use fil_write_flushed_lsn and output a error if operation fails. Remove lsn variable from fsp_open_info. recv_recovery_from_checkpoint_start(): Remove unnecessary second flush_lsn parameter. log_empty_and_mark_files_at_shutdown(): Use fil_writte_flushed_lsn and output error if it fails. open_or_create_data_files(): Pass only one flushed_lsn variable.
9 years ago
MDEV-12113: install_db shows corruption for rest encryption with innodb_data_file_path=ibdata1:3M; Problem was that FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION field that for encrypted pages even in system datafiles should contain key_version except very first page (0:0) is after encryption overwritten with flush lsn. Ported WL#7990 Repurpose FIL_PAGE_FLUSH_LSN to 10.1 The field FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION is consulted during InnoDB startup. At startup, InnoDB reads the FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION from the first page of each file in the InnoDB system tablespace. If there are multiple files, the minimum and maximum LSN can differ. These numbers are passed to InnoDB startup. Having the number in other files than the first file of the InnoDB system tablespace is not providing much additional value. It is conflicting with other use of the field, such as on InnoDB R-tree index pages and encryption key_version. This worklog will stop writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to other files than the first file of the InnoDB system tablespace (page number 0:0) when system tablespace is encrypted. If tablespace is not encrypted we continue writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to all first pages of system tablespace to avoid unnecessary warnings on downgrade. open_or_create_data_files(): pass only one flushed_lsn parameter xb_load_tablespaces(): pass only one flushed_lsn parameter. buf_page_create(): Improve comment about where FIL_PAGE_FIL_FLUSH_LSN_OR_KEY_VERSION is set. fil_write_flushed_lsn(): A new function, merged from fil_write_lsn_and_arch_no_to_file() and fil_write_flushed_lsn_to_data_files(). Only write to the first page of the system tablespace (page 0:0) if tablespace is encrypted, or write all first pages of system tablespace and invoke fil_flush_file_spaces(FIL_TYPE_TABLESPACE) afterwards. fil_read_first_page(): read flush_lsn and crypt_data only from first datafile. fil_open_single_table_tablespace(): Remove output of LSN, because it was only valid for the system tablespace and the undo tablespaces, not user tablespaces. fil_validate_single_table_tablespace(): Remove output of LSN. checkpoint_now_set(): Use fil_write_flushed_lsn and output a error if operation fails. Remove lsn variable from fsp_open_info. recv_recovery_from_checkpoint_start(): Remove unnecessary second flush_lsn parameter. log_empty_and_mark_files_at_shutdown(): Use fil_writte_flushed_lsn and output error if it fails. open_or_create_data_files(): Pass only one flushed_lsn variable.
9 years ago
MDEV-12113: install_db shows corruption for rest encryption with innodb_data_file_path=ibdata1:3M; Problem was that FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION field that for encrypted pages even in system datafiles should contain key_version except very first page (0:0) is after encryption overwritten with flush lsn. Ported WL#7990 Repurpose FIL_PAGE_FLUSH_LSN to 10.1 The field FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION is consulted during InnoDB startup. At startup, InnoDB reads the FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION from the first page of each file in the InnoDB system tablespace. If there are multiple files, the minimum and maximum LSN can differ. These numbers are passed to InnoDB startup. Having the number in other files than the first file of the InnoDB system tablespace is not providing much additional value. It is conflicting with other use of the field, such as on InnoDB R-tree index pages and encryption key_version. This worklog will stop writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to other files than the first file of the InnoDB system tablespace (page number 0:0) when system tablespace is encrypted. If tablespace is not encrypted we continue writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to all first pages of system tablespace to avoid unnecessary warnings on downgrade. open_or_create_data_files(): pass only one flushed_lsn parameter xb_load_tablespaces(): pass only one flushed_lsn parameter. buf_page_create(): Improve comment about where FIL_PAGE_FIL_FLUSH_LSN_OR_KEY_VERSION is set. fil_write_flushed_lsn(): A new function, merged from fil_write_lsn_and_arch_no_to_file() and fil_write_flushed_lsn_to_data_files(). Only write to the first page of the system tablespace (page 0:0) if tablespace is encrypted, or write all first pages of system tablespace and invoke fil_flush_file_spaces(FIL_TYPE_TABLESPACE) afterwards. fil_read_first_page(): read flush_lsn and crypt_data only from first datafile. fil_open_single_table_tablespace(): Remove output of LSN, because it was only valid for the system tablespace and the undo tablespaces, not user tablespaces. fil_validate_single_table_tablespace(): Remove output of LSN. checkpoint_now_set(): Use fil_write_flushed_lsn and output a error if operation fails. Remove lsn variable from fsp_open_info. recv_recovery_from_checkpoint_start(): Remove unnecessary second flush_lsn parameter. log_empty_and_mark_files_at_shutdown(): Use fil_writte_flushed_lsn and output error if it fails. open_or_create_data_files(): Pass only one flushed_lsn variable.
9 years ago
MDEV-12113: install_db shows corruption for rest encryption with innodb_data_file_path=ibdata1:3M; Problem was that FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION field that for encrypted pages even in system datafiles should contain key_version except very first page (0:0) is after encryption overwritten with flush lsn. Ported WL#7990 Repurpose FIL_PAGE_FLUSH_LSN to 10.1 The field FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION is consulted during InnoDB startup. At startup, InnoDB reads the FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION from the first page of each file in the InnoDB system tablespace. If there are multiple files, the minimum and maximum LSN can differ. These numbers are passed to InnoDB startup. Having the number in other files than the first file of the InnoDB system tablespace is not providing much additional value. It is conflicting with other use of the field, such as on InnoDB R-tree index pages and encryption key_version. This worklog will stop writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to other files than the first file of the InnoDB system tablespace (page number 0:0) when system tablespace is encrypted. If tablespace is not encrypted we continue writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to all first pages of system tablespace to avoid unnecessary warnings on downgrade. open_or_create_data_files(): pass only one flushed_lsn parameter xb_load_tablespaces(): pass only one flushed_lsn parameter. buf_page_create(): Improve comment about where FIL_PAGE_FIL_FLUSH_LSN_OR_KEY_VERSION is set. fil_write_flushed_lsn(): A new function, merged from fil_write_lsn_and_arch_no_to_file() and fil_write_flushed_lsn_to_data_files(). Only write to the first page of the system tablespace (page 0:0) if tablespace is encrypted, or write all first pages of system tablespace and invoke fil_flush_file_spaces(FIL_TYPE_TABLESPACE) afterwards. fil_read_first_page(): read flush_lsn and crypt_data only from first datafile. fil_open_single_table_tablespace(): Remove output of LSN, because it was only valid for the system tablespace and the undo tablespaces, not user tablespaces. fil_validate_single_table_tablespace(): Remove output of LSN. checkpoint_now_set(): Use fil_write_flushed_lsn and output a error if operation fails. Remove lsn variable from fsp_open_info. recv_recovery_from_checkpoint_start(): Remove unnecessary second flush_lsn parameter. log_empty_and_mark_files_at_shutdown(): Use fil_writte_flushed_lsn and output error if it fails. open_or_create_data_files(): Pass only one flushed_lsn variable.
9 years ago
15 years ago
9 years ago
9 years ago
9 years ago
MDEV-12113: install_db shows corruption for rest encryption with innodb_data_file_path=ibdata1:3M; Problem was that FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION field that for encrypted pages even in system datafiles should contain key_version except very first page (0:0) is after encryption overwritten with flush lsn. Ported WL#7990 Repurpose FIL_PAGE_FLUSH_LSN to 10.1 The field FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION is consulted during InnoDB startup. At startup, InnoDB reads the FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION from the first page of each file in the InnoDB system tablespace. If there are multiple files, the minimum and maximum LSN can differ. These numbers are passed to InnoDB startup. Having the number in other files than the first file of the InnoDB system tablespace is not providing much additional value. It is conflicting with other use of the field, such as on InnoDB R-tree index pages and encryption key_version. This worklog will stop writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to other files than the first file of the InnoDB system tablespace (page number 0:0) when system tablespace is encrypted. If tablespace is not encrypted we continue writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to all first pages of system tablespace to avoid unnecessary warnings on downgrade. open_or_create_data_files(): pass only one flushed_lsn parameter xb_load_tablespaces(): pass only one flushed_lsn parameter. buf_page_create(): Improve comment about where FIL_PAGE_FIL_FLUSH_LSN_OR_KEY_VERSION is set. fil_write_flushed_lsn(): A new function, merged from fil_write_lsn_and_arch_no_to_file() and fil_write_flushed_lsn_to_data_files(). Only write to the first page of the system tablespace (page 0:0) if tablespace is encrypted, or write all first pages of system tablespace and invoke fil_flush_file_spaces(FIL_TYPE_TABLESPACE) afterwards. fil_read_first_page(): read flush_lsn and crypt_data only from first datafile. fil_open_single_table_tablespace(): Remove output of LSN, because it was only valid for the system tablespace and the undo tablespaces, not user tablespaces. fil_validate_single_table_tablespace(): Remove output of LSN. checkpoint_now_set(): Use fil_write_flushed_lsn and output a error if operation fails. Remove lsn variable from fsp_open_info. recv_recovery_from_checkpoint_start(): Remove unnecessary second flush_lsn parameter. log_empty_and_mark_files_at_shutdown(): Use fil_writte_flushed_lsn and output error if it fails. open_or_create_data_files(): Pass only one flushed_lsn variable.
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-12113: install_db shows corruption for rest encryption with innodb_data_file_path=ibdata1:3M; Problem was that FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION field that for encrypted pages even in system datafiles should contain key_version except very first page (0:0) is after encryption overwritten with flush lsn. Ported WL#7990 Repurpose FIL_PAGE_FLUSH_LSN to 10.1 The field FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION is consulted during InnoDB startup. At startup, InnoDB reads the FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION from the first page of each file in the InnoDB system tablespace. If there are multiple files, the minimum and maximum LSN can differ. These numbers are passed to InnoDB startup. Having the number in other files than the first file of the InnoDB system tablespace is not providing much additional value. It is conflicting with other use of the field, such as on InnoDB R-tree index pages and encryption key_version. This worklog will stop writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to other files than the first file of the InnoDB system tablespace (page number 0:0) when system tablespace is encrypted. If tablespace is not encrypted we continue writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to all first pages of system tablespace to avoid unnecessary warnings on downgrade. open_or_create_data_files(): pass only one flushed_lsn parameter xb_load_tablespaces(): pass only one flushed_lsn parameter. buf_page_create(): Improve comment about where FIL_PAGE_FIL_FLUSH_LSN_OR_KEY_VERSION is set. fil_write_flushed_lsn(): A new function, merged from fil_write_lsn_and_arch_no_to_file() and fil_write_flushed_lsn_to_data_files(). Only write to the first page of the system tablespace (page 0:0) if tablespace is encrypted, or write all first pages of system tablespace and invoke fil_flush_file_spaces(FIL_TYPE_TABLESPACE) afterwards. fil_read_first_page(): read flush_lsn and crypt_data only from first datafile. fil_open_single_table_tablespace(): Remove output of LSN, because it was only valid for the system tablespace and the undo tablespaces, not user tablespaces. fil_validate_single_table_tablespace(): Remove output of LSN. checkpoint_now_set(): Use fil_write_flushed_lsn and output a error if operation fails. Remove lsn variable from fsp_open_info. recv_recovery_from_checkpoint_start(): Remove unnecessary second flush_lsn parameter. log_empty_and_mark_files_at_shutdown(): Use fil_writte_flushed_lsn and output error if it fails. open_or_create_data_files(): Pass only one flushed_lsn variable.
9 years ago
MDEV-12113: install_db shows corruption for rest encryption with innodb_data_file_path=ibdata1:3M; Problem was that FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION field that for encrypted pages even in system datafiles should contain key_version except very first page (0:0) is after encryption overwritten with flush lsn. Ported WL#7990 Repurpose FIL_PAGE_FLUSH_LSN to 10.1 The field FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION is consulted during InnoDB startup. At startup, InnoDB reads the FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION from the first page of each file in the InnoDB system tablespace. If there are multiple files, the minimum and maximum LSN can differ. These numbers are passed to InnoDB startup. Having the number in other files than the first file of the InnoDB system tablespace is not providing much additional value. It is conflicting with other use of the field, such as on InnoDB R-tree index pages and encryption key_version. This worklog will stop writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to other files than the first file of the InnoDB system tablespace (page number 0:0) when system tablespace is encrypted. If tablespace is not encrypted we continue writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to all first pages of system tablespace to avoid unnecessary warnings on downgrade. open_or_create_data_files(): pass only one flushed_lsn parameter xb_load_tablespaces(): pass only one flushed_lsn parameter. buf_page_create(): Improve comment about where FIL_PAGE_FIL_FLUSH_LSN_OR_KEY_VERSION is set. fil_write_flushed_lsn(): A new function, merged from fil_write_lsn_and_arch_no_to_file() and fil_write_flushed_lsn_to_data_files(). Only write to the first page of the system tablespace (page 0:0) if tablespace is encrypted, or write all first pages of system tablespace and invoke fil_flush_file_spaces(FIL_TYPE_TABLESPACE) afterwards. fil_read_first_page(): read flush_lsn and crypt_data only from first datafile. fil_open_single_table_tablespace(): Remove output of LSN, because it was only valid for the system tablespace and the undo tablespaces, not user tablespaces. fil_validate_single_table_tablespace(): Remove output of LSN. checkpoint_now_set(): Use fil_write_flushed_lsn and output a error if operation fails. Remove lsn variable from fsp_open_info. recv_recovery_from_checkpoint_start(): Remove unnecessary second flush_lsn parameter. log_empty_and_mark_files_at_shutdown(): Use fil_writte_flushed_lsn and output error if it fails. open_or_create_data_files(): Pass only one flushed_lsn variable.
9 years ago
MDEV-12113: install_db shows corruption for rest encryption with innodb_data_file_path=ibdata1:3M; Problem was that FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION field that for encrypted pages even in system datafiles should contain key_version except very first page (0:0) is after encryption overwritten with flush lsn. Ported WL#7990 Repurpose FIL_PAGE_FLUSH_LSN to 10.1 The field FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION is consulted during InnoDB startup. At startup, InnoDB reads the FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION from the first page of each file in the InnoDB system tablespace. If there are multiple files, the minimum and maximum LSN can differ. These numbers are passed to InnoDB startup. Having the number in other files than the first file of the InnoDB system tablespace is not providing much additional value. It is conflicting with other use of the field, such as on InnoDB R-tree index pages and encryption key_version. This worklog will stop writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to other files than the first file of the InnoDB system tablespace (page number 0:0) when system tablespace is encrypted. If tablespace is not encrypted we continue writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to all first pages of system tablespace to avoid unnecessary warnings on downgrade. open_or_create_data_files(): pass only one flushed_lsn parameter xb_load_tablespaces(): pass only one flushed_lsn parameter. buf_page_create(): Improve comment about where FIL_PAGE_FIL_FLUSH_LSN_OR_KEY_VERSION is set. fil_write_flushed_lsn(): A new function, merged from fil_write_lsn_and_arch_no_to_file() and fil_write_flushed_lsn_to_data_files(). Only write to the first page of the system tablespace (page 0:0) if tablespace is encrypted, or write all first pages of system tablespace and invoke fil_flush_file_spaces(FIL_TYPE_TABLESPACE) afterwards. fil_read_first_page(): read flush_lsn and crypt_data only from first datafile. fil_open_single_table_tablespace(): Remove output of LSN, because it was only valid for the system tablespace and the undo tablespaces, not user tablespaces. fil_validate_single_table_tablespace(): Remove output of LSN. checkpoint_now_set(): Use fil_write_flushed_lsn and output a error if operation fails. Remove lsn variable from fsp_open_info. recv_recovery_from_checkpoint_start(): Remove unnecessary second flush_lsn parameter. log_empty_and_mark_files_at_shutdown(): Use fil_writte_flushed_lsn and output error if it fails. open_or_create_data_files(): Pass only one flushed_lsn variable.
9 years ago
MDEV-12113: install_db shows corruption for rest encryption with innodb_data_file_path=ibdata1:3M; Problem was that FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION field that for encrypted pages even in system datafiles should contain key_version except very first page (0:0) is after encryption overwritten with flush lsn. Ported WL#7990 Repurpose FIL_PAGE_FLUSH_LSN to 10.1 The field FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION is consulted during InnoDB startup. At startup, InnoDB reads the FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION from the first page of each file in the InnoDB system tablespace. If there are multiple files, the minimum and maximum LSN can differ. These numbers are passed to InnoDB startup. Having the number in other files than the first file of the InnoDB system tablespace is not providing much additional value. It is conflicting with other use of the field, such as on InnoDB R-tree index pages and encryption key_version. This worklog will stop writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to other files than the first file of the InnoDB system tablespace (page number 0:0) when system tablespace is encrypted. If tablespace is not encrypted we continue writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to all first pages of system tablespace to avoid unnecessary warnings on downgrade. open_or_create_data_files(): pass only one flushed_lsn parameter xb_load_tablespaces(): pass only one flushed_lsn parameter. buf_page_create(): Improve comment about where FIL_PAGE_FIL_FLUSH_LSN_OR_KEY_VERSION is set. fil_write_flushed_lsn(): A new function, merged from fil_write_lsn_and_arch_no_to_file() and fil_write_flushed_lsn_to_data_files(). Only write to the first page of the system tablespace (page 0:0) if tablespace is encrypted, or write all first pages of system tablespace and invoke fil_flush_file_spaces(FIL_TYPE_TABLESPACE) afterwards. fil_read_first_page(): read flush_lsn and crypt_data only from first datafile. fil_open_single_table_tablespace(): Remove output of LSN, because it was only valid for the system tablespace and the undo tablespaces, not user tablespaces. fil_validate_single_table_tablespace(): Remove output of LSN. checkpoint_now_set(): Use fil_write_flushed_lsn and output a error if operation fails. Remove lsn variable from fsp_open_info. recv_recovery_from_checkpoint_start(): Remove unnecessary second flush_lsn parameter. log_empty_and_mark_files_at_shutdown(): Use fil_writte_flushed_lsn and output error if it fails. open_or_create_data_files(): Pass only one flushed_lsn variable.
9 years ago
MDEV-12113: install_db shows corruption for rest encryption with innodb_data_file_path=ibdata1:3M; Problem was that FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION field that for encrypted pages even in system datafiles should contain key_version except very first page (0:0) is after encryption overwritten with flush lsn. Ported WL#7990 Repurpose FIL_PAGE_FLUSH_LSN to 10.1 The field FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION is consulted during InnoDB startup. At startup, InnoDB reads the FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION from the first page of each file in the InnoDB system tablespace. If there are multiple files, the minimum and maximum LSN can differ. These numbers are passed to InnoDB startup. Having the number in other files than the first file of the InnoDB system tablespace is not providing much additional value. It is conflicting with other use of the field, such as on InnoDB R-tree index pages and encryption key_version. This worklog will stop writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to other files than the first file of the InnoDB system tablespace (page number 0:0) when system tablespace is encrypted. If tablespace is not encrypted we continue writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to all first pages of system tablespace to avoid unnecessary warnings on downgrade. open_or_create_data_files(): pass only one flushed_lsn parameter xb_load_tablespaces(): pass only one flushed_lsn parameter. buf_page_create(): Improve comment about where FIL_PAGE_FIL_FLUSH_LSN_OR_KEY_VERSION is set. fil_write_flushed_lsn(): A new function, merged from fil_write_lsn_and_arch_no_to_file() and fil_write_flushed_lsn_to_data_files(). Only write to the first page of the system tablespace (page 0:0) if tablespace is encrypted, or write all first pages of system tablespace and invoke fil_flush_file_spaces(FIL_TYPE_TABLESPACE) afterwards. fil_read_first_page(): read flush_lsn and crypt_data only from first datafile. fil_open_single_table_tablespace(): Remove output of LSN, because it was only valid for the system tablespace and the undo tablespaces, not user tablespaces. fil_validate_single_table_tablespace(): Remove output of LSN. checkpoint_now_set(): Use fil_write_flushed_lsn and output a error if operation fails. Remove lsn variable from fsp_open_info. recv_recovery_from_checkpoint_start(): Remove unnecessary second flush_lsn parameter. log_empty_and_mark_files_at_shutdown(): Use fil_writte_flushed_lsn and output error if it fails. open_or_create_data_files(): Pass only one flushed_lsn variable.
9 years ago
MDEV-12113: install_db shows corruption for rest encryption with innodb_data_file_path=ibdata1:3M; Problem was that FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION field that for encrypted pages even in system datafiles should contain key_version except very first page (0:0) is after encryption overwritten with flush lsn. Ported WL#7990 Repurpose FIL_PAGE_FLUSH_LSN to 10.1 The field FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION is consulted during InnoDB startup. At startup, InnoDB reads the FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION from the first page of each file in the InnoDB system tablespace. If there are multiple files, the minimum and maximum LSN can differ. These numbers are passed to InnoDB startup. Having the number in other files than the first file of the InnoDB system tablespace is not providing much additional value. It is conflicting with other use of the field, such as on InnoDB R-tree index pages and encryption key_version. This worklog will stop writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to other files than the first file of the InnoDB system tablespace (page number 0:0) when system tablespace is encrypted. If tablespace is not encrypted we continue writing FIL_PAGE_FLUSH_LSN_OR_KEY_VERSION to all first pages of system tablespace to avoid unnecessary warnings on downgrade. open_or_create_data_files(): pass only one flushed_lsn parameter xb_load_tablespaces(): pass only one flushed_lsn parameter. buf_page_create(): Improve comment about where FIL_PAGE_FIL_FLUSH_LSN_OR_KEY_VERSION is set. fil_write_flushed_lsn(): A new function, merged from fil_write_lsn_and_arch_no_to_file() and fil_write_flushed_lsn_to_data_files(). Only write to the first page of the system tablespace (page 0:0) if tablespace is encrypted, or write all first pages of system tablespace and invoke fil_flush_file_spaces(FIL_TYPE_TABLESPACE) afterwards. fil_read_first_page(): read flush_lsn and crypt_data only from first datafile. fil_open_single_table_tablespace(): Remove output of LSN, because it was only valid for the system tablespace and the undo tablespaces, not user tablespaces. fil_validate_single_table_tablespace(): Remove output of LSN. checkpoint_now_set(): Use fil_write_flushed_lsn and output a error if operation fails. Remove lsn variable from fsp_open_info. recv_recovery_from_checkpoint_start(): Remove unnecessary second flush_lsn parameter. log_empty_and_mark_files_at_shutdown(): Use fil_writte_flushed_lsn and output error if it fails. open_or_create_data_files(): Pass only one flushed_lsn variable.
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
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
15 years ago
15 years ago
15 years ago
MDEV-11638 Encryption causes race conditions in InnoDB shutdown InnoDB shutdown failed to properly take fil_crypt_thread() into account. The encryption threads were signalled to shut down together with other non-critical tasks. This could be much too early in case of slow shutdown, which could need minutes to complete the purge. Furthermore, InnoDB failed to wait for the fil_crypt_thread() to actually exit before proceeding to the final steps of shutdown, causing the race conditions. Furthermore, the log_scrub_thread() was shut down way too early. Also it should remain until the SRV_SHUTDOWN_FLUSH_PHASE. fil_crypt_threads_end(): Remove. This would cause the threads to be terminated way too early. srv_buf_dump_thread_active, srv_dict_stats_thread_active, lock_sys->timeout_thread_active, log_scrub_thread_active, srv_monitor_active, srv_error_monitor_active: Remove a race condition between startup and shutdown, by setting these in the startup thread that creates threads, not in each created thread. In this way, once the flag is cleared, it will remain cleared during shutdown. srv_n_fil_crypt_threads_started, fil_crypt_threads_event: Declare in global rather than static scope. log_scrub_event, srv_log_scrub_thread_active, log_scrub_thread(): Declare in static rather than global scope. Let these be created by log_init() and freed by log_shutdown(). rotate_thread_t::should_shutdown(): Do not shut down before the SRV_SHUTDOWN_FLUSH_PHASE. srv_any_background_threads_are_active(): Remove. These checks now exist in logs_empty_and_mark_files_at_shutdown(). logs_empty_and_mark_files_at_shutdown(): Shut down the threads in the proper order. Keep fil_crypt_thread() and log_scrub_thread() alive until SRV_SHUTDOWN_FLUSH_PHASE, and check that they actually terminate.
9 years ago
MDEV-11638 Encryption causes race conditions in InnoDB shutdown InnoDB shutdown failed to properly take fil_crypt_thread() into account. The encryption threads were signalled to shut down together with other non-critical tasks. This could be much too early in case of slow shutdown, which could need minutes to complete the purge. Furthermore, InnoDB failed to wait for the fil_crypt_thread() to actually exit before proceeding to the final steps of shutdown, causing the race conditions. Furthermore, the log_scrub_thread() was shut down way too early. Also it should remain until the SRV_SHUTDOWN_FLUSH_PHASE. fil_crypt_threads_end(): Remove. This would cause the threads to be terminated way too early. srv_buf_dump_thread_active, srv_dict_stats_thread_active, lock_sys->timeout_thread_active, log_scrub_thread_active, srv_monitor_active, srv_error_monitor_active: Remove a race condition between startup and shutdown, by setting these in the startup thread that creates threads, not in each created thread. In this way, once the flag is cleared, it will remain cleared during shutdown. srv_n_fil_crypt_threads_started, fil_crypt_threads_event: Declare in global rather than static scope. log_scrub_event, srv_log_scrub_thread_active, log_scrub_thread(): Declare in static rather than global scope. Let these be created by log_init() and freed by log_shutdown(). rotate_thread_t::should_shutdown(): Do not shut down before the SRV_SHUTDOWN_FLUSH_PHASE. srv_any_background_threads_are_active(): Remove. These checks now exist in logs_empty_and_mark_files_at_shutdown(). logs_empty_and_mark_files_at_shutdown(): Shut down the threads in the proper order. Keep fil_crypt_thread() and log_scrub_thread() alive until SRV_SHUTDOWN_FLUSH_PHASE, and check that they actually terminate.
9 years ago
9 years ago
9 years ago
15 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
15 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
15 years ago
15 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
Merge Google encryption commit 195158e9889365dc3298f8c1f3bcaa745992f27f Author: Minli Zhu <minliz@google.com> Date: Mon Nov 25 11:05:55 2013 -0800 Innodb redo log encryption/decryption. Use start lsn of a log block as part of AES CTR counter. Record key version with each checkpoint. Internally key version 0 means no encryption. Tests done (see test_innodb_log_encryption.sh for detail): - Verify flag innodb_encrypt_log on or off, combined with various key versions passed through CLI, and dynamically set after startup, will not corrupt database. This includes tests from being unencrypted to encrypted, and encrypted to unencrypted. - Verify start-up with no redo logs succeeds. - Verify fresh start-up succeeds. Change-Id: I4ce4c2afdf3076be2fce90ebbc2a7ce01184b612 commit c1b97273659f07866758c25f4a56f680a1fbad24 Author: Jonas Oreland <jonaso@google.com> Date: Tue Dec 3 18:47:27 2013 +0100 encryption of aria data&index files this patch implements encryption of aria data & index files. this is implemented as 1) add read/write hooks (renamed from callbacks) that does encrypt/decrypt (also add pre_read and post_write hooks) 2) modify page headers for data/index to contain key version (making the data-page header size different for with/without encryption) 3) modify index page 0 to contain IV (and crypt header) 4) AES CRT crypt functions 5) counter block is implemented using combination of page no, lsn and table specific id NOTE: 1) log files are not encrypted, this is not needed for if aria is only used for internal temporary tables and they are not transactional (i.e not logged) 2) all encrypted tables are using PAGE_CHECKSUM (crc) normal internal temporary tables are (currently) not CHECKSUM:ed 3) This patch adds insert-order semantics to aria block_format. The default behaviour of aria block-format is best-fit, meaning that rows gets allocated to page trying to fill the pages as much as possible. However, certain sql constructs materialize temporary result in tmp-tables, and expect that a table scan will later return the rows in the same order they were inserted. This implementation of insert-order is only enabled when explicitly requested by sql-layer. CHANGES: 1) found bug in ma_write that made code try to abort a record that was never written unsure why this is not exposed Change-Id: Ia82bbaa92e2c0629c08693c5add2f56b815c0509 commit 89dc1ab651fe0205d55b4eb588f62df550aa65fc Author: Jonas Oreland <jonaso@google.com> Date: Mon Feb 17 08:04:50 2014 -0800 Implement encryption of innodb datafiles. Pages are encrypted before written to disk and decrypted when read from disk. Each page except first page (page 0) in tablespace is encrypted. Page 0 is unencrypted and contains IV for the tablespace. FIL_PAGE_FILE_FLUSH_LSN on each page (except page 0) is used to store a 32-bit key-version, so that multiple keys can be active in a tablespace simultaneous. The other 32-bit of the FIL_PAGE_FILE_FLUSH_LSN field contains a checksum that is computed after encryption. This checksum is used by innochecksum and when restoring from double-write-buffer. The encryption is performed using AES CRT. Monitoring of encryption is enabled using new IS-table INNODB_TABLESPACES_ENCRYPTION. In addition to that new status variables innodb_encryption_rotation_{ pages_read_from_cache, pages_read_from_disk, pages_modified,pages_flushed } has been added. The following tunables are introduces - innodb_encrypt_tables - innodb_encryption_threads - innodb_encryption_rotate_key_age - innodb_encryption_rotation_iops Change-Id: I8f651795a30b52e71b16d6bc9cb7559be349d0b2 commit a17eef2f6948e58219c9e26fc35633d6fd4de1de Author: Andrew Ford <andrewford@google.com> Date: Thu Jan 2 15:43:09 2014 -0800 Key management skeleton with debug hooks. Change-Id: Ifd6aa3743d7ea291c70083f433a059c439aed866 commit 68a399838ad72264fd61b3dc67fecd29bbdb0af1 Author: Andrew Ford <andrewford@google.com> Date: Mon Oct 28 16:27:44 2013 -0700 Add AES-128 CTR and GCM encryption classes. Change-Id: I116305eced2a233db15306bc2ef5b9d398d1a3a2
11 years ago
Merge Google encryption commit 195158e9889365dc3298f8c1f3bcaa745992f27f Author: Minli Zhu <minliz@google.com> Date: Mon Nov 25 11:05:55 2013 -0800 Innodb redo log encryption/decryption. Use start lsn of a log block as part of AES CTR counter. Record key version with each checkpoint. Internally key version 0 means no encryption. Tests done (see test_innodb_log_encryption.sh for detail): - Verify flag innodb_encrypt_log on or off, combined with various key versions passed through CLI, and dynamically set after startup, will not corrupt database. This includes tests from being unencrypted to encrypted, and encrypted to unencrypted. - Verify start-up with no redo logs succeeds. - Verify fresh start-up succeeds. Change-Id: I4ce4c2afdf3076be2fce90ebbc2a7ce01184b612 commit c1b97273659f07866758c25f4a56f680a1fbad24 Author: Jonas Oreland <jonaso@google.com> Date: Tue Dec 3 18:47:27 2013 +0100 encryption of aria data&index files this patch implements encryption of aria data & index files. this is implemented as 1) add read/write hooks (renamed from callbacks) that does encrypt/decrypt (also add pre_read and post_write hooks) 2) modify page headers for data/index to contain key version (making the data-page header size different for with/without encryption) 3) modify index page 0 to contain IV (and crypt header) 4) AES CRT crypt functions 5) counter block is implemented using combination of page no, lsn and table specific id NOTE: 1) log files are not encrypted, this is not needed for if aria is only used for internal temporary tables and they are not transactional (i.e not logged) 2) all encrypted tables are using PAGE_CHECKSUM (crc) normal internal temporary tables are (currently) not CHECKSUM:ed 3) This patch adds insert-order semantics to aria block_format. The default behaviour of aria block-format is best-fit, meaning that rows gets allocated to page trying to fill the pages as much as possible. However, certain sql constructs materialize temporary result in tmp-tables, and expect that a table scan will later return the rows in the same order they were inserted. This implementation of insert-order is only enabled when explicitly requested by sql-layer. CHANGES: 1) found bug in ma_write that made code try to abort a record that was never written unsure why this is not exposed Change-Id: Ia82bbaa92e2c0629c08693c5add2f56b815c0509 commit 89dc1ab651fe0205d55b4eb588f62df550aa65fc Author: Jonas Oreland <jonaso@google.com> Date: Mon Feb 17 08:04:50 2014 -0800 Implement encryption of innodb datafiles. Pages are encrypted before written to disk and decrypted when read from disk. Each page except first page (page 0) in tablespace is encrypted. Page 0 is unencrypted and contains IV for the tablespace. FIL_PAGE_FILE_FLUSH_LSN on each page (except page 0) is used to store a 32-bit key-version, so that multiple keys can be active in a tablespace simultaneous. The other 32-bit of the FIL_PAGE_FILE_FLUSH_LSN field contains a checksum that is computed after encryption. This checksum is used by innochecksum and when restoring from double-write-buffer. The encryption is performed using AES CRT. Monitoring of encryption is enabled using new IS-table INNODB_TABLESPACES_ENCRYPTION. In addition to that new status variables innodb_encryption_rotation_{ pages_read_from_cache, pages_read_from_disk, pages_modified,pages_flushed } has been added. The following tunables are introduces - innodb_encrypt_tables - innodb_encryption_threads - innodb_encryption_rotate_key_age - innodb_encryption_rotation_iops Change-Id: I8f651795a30b52e71b16d6bc9cb7559be349d0b2 commit a17eef2f6948e58219c9e26fc35633d6fd4de1de Author: Andrew Ford <andrewford@google.com> Date: Thu Jan 2 15:43:09 2014 -0800 Key management skeleton with debug hooks. Change-Id: Ifd6aa3743d7ea291c70083f433a059c439aed866 commit 68a399838ad72264fd61b3dc67fecd29bbdb0af1 Author: Andrew Ford <andrewford@google.com> Date: Mon Oct 28 16:27:44 2013 -0700 Add AES-128 CTR and GCM encryption classes. Change-Id: I116305eced2a233db15306bc2ef5b9d398d1a3a2
11 years ago
MDEV-13039 innodb_fast_shutdown=0 may fail to purge all undo log When a slow shutdown is performed soon after spawning some work for background threads that can create or commit transactions, it is possible that new transactions are started or committed after the purge has finished. This is violating the specification of innodb_fast_shutdown=0, namely that the purge must be completed. (None of the history of the recent transactions would be purged.) Also, it is possible that the purge threads would exit in slow shutdown while there exist active transactions, such as recovered incomplete transactions that are being rolled back. Thus, the slow shutdown could fail to purge some undo log that becomes purgeable after the transaction commit or rollback. srv_undo_sources: A flag that indicates if undo log can be generated or the persistent, whether by background threads or by user SQL. Even when this flag is clear, active transactions that already exist in the system may be committed or rolled back. innodb_shutdown(): Renamed from innobase_shutdown_for_mysql(). Do not return an error code; the operation never fails. Clear the srv_undo_sources flag, and also ensure that the background DROP TABLE queue is empty. srv_purge_should_exit(): Do not allow the purge to exit if srv_undo_sources are active or the background DROP TABLE queue is not empty, or in slow shutdown, if any active transactions exist (and are being rolled back). srv_purge_coordinator_thread(): Remove some previous workarounds for this bug. innobase_start_or_create_for_mysql(): Set buf_page_cleaner_is_active and srv_dict_stats_thread_active directly. Set srv_undo_sources before starting the purge subsystem, to prevent immediate shutdown of the purge. Create dict_stats_thread and fts_optimize_thread immediately after setting srv_undo_sources, so that shutdown can use this flag to determine if these subsystems were started. dict_stats_shutdown(): Shut down dict_stats_thread. Backported from 10.2. srv_shutdown_table_bg_threads(): Remove (unused).
9 years ago
MDEV-13039 innodb_fast_shutdown=0 may fail to purge all undo log When a slow shutdown is performed soon after spawning some work for background threads that can create or commit transactions, it is possible that new transactions are started or committed after the purge has finished. This is violating the specification of innodb_fast_shutdown=0, namely that the purge must be completed. (None of the history of the recent transactions would be purged.) Also, it is possible that the purge threads would exit in slow shutdown while there exist active transactions, such as recovered incomplete transactions that are being rolled back. Thus, the slow shutdown could fail to purge some undo log that becomes purgeable after the transaction commit or rollback. srv_undo_sources: A flag that indicates if undo log can be generated or the persistent, whether by background threads or by user SQL. Even when this flag is clear, active transactions that already exist in the system may be committed or rolled back. innodb_shutdown(): Renamed from innobase_shutdown_for_mysql(). Do not return an error code; the operation never fails. Clear the srv_undo_sources flag, and also ensure that the background DROP TABLE queue is empty. srv_purge_should_exit(): Do not allow the purge to exit if srv_undo_sources are active or the background DROP TABLE queue is not empty, or in slow shutdown, if any active transactions exist (and are being rolled back). srv_purge_coordinator_thread(): Remove some previous workarounds for this bug. innobase_start_or_create_for_mysql(): Set buf_page_cleaner_is_active and srv_dict_stats_thread_active directly. Set srv_undo_sources before starting the purge subsystem, to prevent immediate shutdown of the purge. Create dict_stats_thread and fts_optimize_thread immediately after setting srv_undo_sources, so that shutdown can use this flag to determine if these subsystems were started. dict_stats_shutdown(): Shut down dict_stats_thread. Backported from 10.2. srv_shutdown_table_bg_threads(): Remove (unused).
9 years ago
MDEV-13039 innodb_fast_shutdown=0 may fail to purge all undo log When a slow shutdown is performed soon after spawning some work for background threads that can create or commit transactions, it is possible that new transactions are started or committed after the purge has finished. This is violating the specification of innodb_fast_shutdown=0, namely that the purge must be completed. (None of the history of the recent transactions would be purged.) Also, it is possible that the purge threads would exit in slow shutdown while there exist active transactions, such as recovered incomplete transactions that are being rolled back. Thus, the slow shutdown could fail to purge some undo log that becomes purgeable after the transaction commit or rollback. srv_undo_sources: A flag that indicates if undo log can be generated or the persistent, whether by background threads or by user SQL. Even when this flag is clear, active transactions that already exist in the system may be committed or rolled back. innodb_shutdown(): Renamed from innobase_shutdown_for_mysql(). Do not return an error code; the operation never fails. Clear the srv_undo_sources flag, and also ensure that the background DROP TABLE queue is empty. srv_purge_should_exit(): Do not allow the purge to exit if srv_undo_sources are active or the background DROP TABLE queue is not empty, or in slow shutdown, if any active transactions exist (and are being rolled back). srv_purge_coordinator_thread(): Remove some previous workarounds for this bug. innobase_start_or_create_for_mysql(): Set buf_page_cleaner_is_active and srv_dict_stats_thread_active directly. Set srv_undo_sources before starting the purge subsystem, to prevent immediate shutdown of the purge. Create dict_stats_thread and fts_optimize_thread immediately after setting srv_undo_sources, so that shutdown can use this flag to determine if these subsystems were started. dict_stats_shutdown(): Shut down dict_stats_thread. Backported from 10.2. srv_shutdown_table_bg_threads(): Remove (unused).
9 years ago
MDEV-13039 innodb_fast_shutdown=0 may fail to purge all undo log When a slow shutdown is performed soon after spawning some work for background threads that can create or commit transactions, it is possible that new transactions are started or committed after the purge has finished. This is violating the specification of innodb_fast_shutdown=0, namely that the purge must be completed. (None of the history of the recent transactions would be purged.) Also, it is possible that the purge threads would exit in slow shutdown while there exist active transactions, such as recovered incomplete transactions that are being rolled back. Thus, the slow shutdown could fail to purge some undo log that becomes purgeable after the transaction commit or rollback. srv_undo_sources: A flag that indicates if undo log can be generated or the persistent, whether by background threads or by user SQL. Even when this flag is clear, active transactions that already exist in the system may be committed or rolled back. innodb_shutdown(): Renamed from innobase_shutdown_for_mysql(). Do not return an error code; the operation never fails. Clear the srv_undo_sources flag, and also ensure that the background DROP TABLE queue is empty. srv_purge_should_exit(): Do not allow the purge to exit if srv_undo_sources are active or the background DROP TABLE queue is not empty, or in slow shutdown, if any active transactions exist (and are being rolled back). srv_purge_coordinator_thread(): Remove some previous workarounds for this bug. innobase_start_or_create_for_mysql(): Set buf_page_cleaner_is_active and srv_dict_stats_thread_active directly. Set srv_undo_sources before starting the purge subsystem, to prevent immediate shutdown of the purge. Create dict_stats_thread and fts_optimize_thread immediately after setting srv_undo_sources, so that shutdown can use this flag to determine if these subsystems were started. dict_stats_shutdown(): Shut down dict_stats_thread. Backported from 10.2. srv_shutdown_table_bg_threads(): Remove (unused).
9 years ago
15 years ago
15 years ago
10 years ago
Merge Google encryption commit 195158e9889365dc3298f8c1f3bcaa745992f27f Author: Minli Zhu <minliz@google.com> Date: Mon Nov 25 11:05:55 2013 -0800 Innodb redo log encryption/decryption. Use start lsn of a log block as part of AES CTR counter. Record key version with each checkpoint. Internally key version 0 means no encryption. Tests done (see test_innodb_log_encryption.sh for detail): - Verify flag innodb_encrypt_log on or off, combined with various key versions passed through CLI, and dynamically set after startup, will not corrupt database. This includes tests from being unencrypted to encrypted, and encrypted to unencrypted. - Verify start-up with no redo logs succeeds. - Verify fresh start-up succeeds. Change-Id: I4ce4c2afdf3076be2fce90ebbc2a7ce01184b612 commit c1b97273659f07866758c25f4a56f680a1fbad24 Author: Jonas Oreland <jonaso@google.com> Date: Tue Dec 3 18:47:27 2013 +0100 encryption of aria data&index files this patch implements encryption of aria data & index files. this is implemented as 1) add read/write hooks (renamed from callbacks) that does encrypt/decrypt (also add pre_read and post_write hooks) 2) modify page headers for data/index to contain key version (making the data-page header size different for with/without encryption) 3) modify index page 0 to contain IV (and crypt header) 4) AES CRT crypt functions 5) counter block is implemented using combination of page no, lsn and table specific id NOTE: 1) log files are not encrypted, this is not needed for if aria is only used for internal temporary tables and they are not transactional (i.e not logged) 2) all encrypted tables are using PAGE_CHECKSUM (crc) normal internal temporary tables are (currently) not CHECKSUM:ed 3) This patch adds insert-order semantics to aria block_format. The default behaviour of aria block-format is best-fit, meaning that rows gets allocated to page trying to fill the pages as much as possible. However, certain sql constructs materialize temporary result in tmp-tables, and expect that a table scan will later return the rows in the same order they were inserted. This implementation of insert-order is only enabled when explicitly requested by sql-layer. CHANGES: 1) found bug in ma_write that made code try to abort a record that was never written unsure why this is not exposed Change-Id: Ia82bbaa92e2c0629c08693c5add2f56b815c0509 commit 89dc1ab651fe0205d55b4eb588f62df550aa65fc Author: Jonas Oreland <jonaso@google.com> Date: Mon Feb 17 08:04:50 2014 -0800 Implement encryption of innodb datafiles. Pages are encrypted before written to disk and decrypted when read from disk. Each page except first page (page 0) in tablespace is encrypted. Page 0 is unencrypted and contains IV for the tablespace. FIL_PAGE_FILE_FLUSH_LSN on each page (except page 0) is used to store a 32-bit key-version, so that multiple keys can be active in a tablespace simultaneous. The other 32-bit of the FIL_PAGE_FILE_FLUSH_LSN field contains a checksum that is computed after encryption. This checksum is used by innochecksum and when restoring from double-write-buffer. The encryption is performed using AES CRT. Monitoring of encryption is enabled using new IS-table INNODB_TABLESPACES_ENCRYPTION. In addition to that new status variables innodb_encryption_rotation_{ pages_read_from_cache, pages_read_from_disk, pages_modified,pages_flushed } has been added. The following tunables are introduces - innodb_encrypt_tables - innodb_encryption_threads - innodb_encryption_rotate_key_age - innodb_encryption_rotation_iops Change-Id: I8f651795a30b52e71b16d6bc9cb7559be349d0b2 commit a17eef2f6948e58219c9e26fc35633d6fd4de1de Author: Andrew Ford <andrewford@google.com> Date: Thu Jan 2 15:43:09 2014 -0800 Key management skeleton with debug hooks. Change-Id: Ifd6aa3743d7ea291c70083f433a059c439aed866 commit 68a399838ad72264fd61b3dc67fecd29bbdb0af1 Author: Andrew Ford <andrewford@google.com> Date: Mon Oct 28 16:27:44 2013 -0700 Add AES-128 CTR and GCM encryption classes. Change-Id: I116305eced2a233db15306bc2ef5b9d398d1a3a2
11 years ago
Merge Google encryption commit 195158e9889365dc3298f8c1f3bcaa745992f27f Author: Minli Zhu <minliz@google.com> Date: Mon Nov 25 11:05:55 2013 -0800 Innodb redo log encryption/decryption. Use start lsn of a log block as part of AES CTR counter. Record key version with each checkpoint. Internally key version 0 means no encryption. Tests done (see test_innodb_log_encryption.sh for detail): - Verify flag innodb_encrypt_log on or off, combined with various key versions passed through CLI, and dynamically set after startup, will not corrupt database. This includes tests from being unencrypted to encrypted, and encrypted to unencrypted. - Verify start-up with no redo logs succeeds. - Verify fresh start-up succeeds. Change-Id: I4ce4c2afdf3076be2fce90ebbc2a7ce01184b612 commit c1b97273659f07866758c25f4a56f680a1fbad24 Author: Jonas Oreland <jonaso@google.com> Date: Tue Dec 3 18:47:27 2013 +0100 encryption of aria data&index files this patch implements encryption of aria data & index files. this is implemented as 1) add read/write hooks (renamed from callbacks) that does encrypt/decrypt (also add pre_read and post_write hooks) 2) modify page headers for data/index to contain key version (making the data-page header size different for with/without encryption) 3) modify index page 0 to contain IV (and crypt header) 4) AES CRT crypt functions 5) counter block is implemented using combination of page no, lsn and table specific id NOTE: 1) log files are not encrypted, this is not needed for if aria is only used for internal temporary tables and they are not transactional (i.e not logged) 2) all encrypted tables are using PAGE_CHECKSUM (crc) normal internal temporary tables are (currently) not CHECKSUM:ed 3) This patch adds insert-order semantics to aria block_format. The default behaviour of aria block-format is best-fit, meaning that rows gets allocated to page trying to fill the pages as much as possible. However, certain sql constructs materialize temporary result in tmp-tables, and expect that a table scan will later return the rows in the same order they were inserted. This implementation of insert-order is only enabled when explicitly requested by sql-layer. CHANGES: 1) found bug in ma_write that made code try to abort a record that was never written unsure why this is not exposed Change-Id: Ia82bbaa92e2c0629c08693c5add2f56b815c0509 commit 89dc1ab651fe0205d55b4eb588f62df550aa65fc Author: Jonas Oreland <jonaso@google.com> Date: Mon Feb 17 08:04:50 2014 -0800 Implement encryption of innodb datafiles. Pages are encrypted before written to disk and decrypted when read from disk. Each page except first page (page 0) in tablespace is encrypted. Page 0 is unencrypted and contains IV for the tablespace. FIL_PAGE_FILE_FLUSH_LSN on each page (except page 0) is used to store a 32-bit key-version, so that multiple keys can be active in a tablespace simultaneous. The other 32-bit of the FIL_PAGE_FILE_FLUSH_LSN field contains a checksum that is computed after encryption. This checksum is used by innochecksum and when restoring from double-write-buffer. The encryption is performed using AES CRT. Monitoring of encryption is enabled using new IS-table INNODB_TABLESPACES_ENCRYPTION. In addition to that new status variables innodb_encryption_rotation_{ pages_read_from_cache, pages_read_from_disk, pages_modified,pages_flushed } has been added. The following tunables are introduces - innodb_encrypt_tables - innodb_encryption_threads - innodb_encryption_rotate_key_age - innodb_encryption_rotation_iops Change-Id: I8f651795a30b52e71b16d6bc9cb7559be349d0b2 commit a17eef2f6948e58219c9e26fc35633d6fd4de1de Author: Andrew Ford <andrewford@google.com> Date: Thu Jan 2 15:43:09 2014 -0800 Key management skeleton with debug hooks. Change-Id: Ifd6aa3743d7ea291c70083f433a059c439aed866 commit 68a399838ad72264fd61b3dc67fecd29bbdb0af1 Author: Andrew Ford <andrewford@google.com> Date: Mon Oct 28 16:27:44 2013 -0700 Add AES-128 CTR and GCM encryption classes. Change-Id: I116305eced2a233db15306bc2ef5b9d398d1a3a2
11 years ago
9 years ago
10 years ago
15 years ago
10 years ago
10 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, 2017, MariaDB Corporation
  6. Portions of this file contain modifications contributed and copyrighted by
  7. Google, Inc. Those modifications are gratefully acknowledged and are described
  8. briefly in the InnoDB documentation. The contributions by Google are
  9. incorporated with their permission, and subject to the conditions contained in
  10. the file COPYING.Google.
  11. Portions of this file contain modifications contributed and copyrighted
  12. by Percona Inc.. Those modifications are
  13. gratefully acknowledged and are described briefly in the InnoDB
  14. documentation. The contributions by Percona Inc. are incorporated with
  15. their permission, and subject to the conditions contained in the file
  16. COPYING.Percona.
  17. This program is free software; you can redistribute it and/or modify it under
  18. the terms of the GNU General Public License as published by the Free Software
  19. Foundation; version 2 of the License.
  20. This program is distributed in the hope that it will be useful, but WITHOUT
  21. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  22. FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  23. You should have received a copy of the GNU General Public License along with
  24. this program; if not, write to the Free Software Foundation, Inc.,
  25. 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
  26. *****************************************************************************/
  27. /********************************************************************//**
  28. @file srv/srv0start.cc
  29. Starts the InnoDB database server
  30. Created 2/16/1996 Heikki Tuuri
  31. *************************************************************************/
  32. #include "mysqld.h"
  33. #include "pars0pars.h"
  34. #include "row0ftsort.h"
  35. #include "ut0mem.h"
  36. #include "mem0mem.h"
  37. #include "data0data.h"
  38. #include "data0type.h"
  39. #include "dict0dict.h"
  40. #include "buf0buf.h"
  41. #include "buf0dump.h"
  42. #include "os0file.h"
  43. #include "os0thread.h"
  44. #include "fil0fil.h"
  45. #include "fil0crypt.h"
  46. #include "fsp0fsp.h"
  47. #include "rem0rec.h"
  48. #include "mtr0mtr.h"
  49. #include "log0log.h"
  50. #include "log0online.h"
  51. #include "log0recv.h"
  52. #include "page0page.h"
  53. #include "page0cur.h"
  54. #include "trx0trx.h"
  55. #include "trx0sys.h"
  56. #include "btr0btr.h"
  57. #include "btr0cur.h"
  58. #include "rem0rec.h"
  59. #include "ibuf0ibuf.h"
  60. #include "srv0start.h"
  61. #include "srv0srv.h"
  62. #include "buf0flu.h"
  63. #include "btr0defragment.h"
  64. #include "ut0timer.h"
  65. #include "btr0scrub.h"
  66. #include "mysql/service_wsrep.h" /* wsrep_recovery */
  67. #ifndef UNIV_HOTBACKUP
  68. # include "trx0rseg.h"
  69. # include "os0proc.h"
  70. # include "sync0sync.h"
  71. # include "buf0flu.h"
  72. # include "buf0mtflu.h"
  73. # include "buf0rea.h"
  74. # include "dict0boot.h"
  75. # include "dict0load.h"
  76. # include "dict0stats_bg.h"
  77. # include "que0que.h"
  78. # include "usr0sess.h"
  79. # include "lock0lock.h"
  80. # include "trx0roll.h"
  81. # include "trx0purge.h"
  82. # include "lock0lock.h"
  83. # include "pars0pars.h"
  84. # include "btr0sea.h"
  85. # include "rem0cmp.h"
  86. # include "dict0crea.h"
  87. # include "row0ins.h"
  88. # include "row0sel.h"
  89. # include "row0upd.h"
  90. # include "row0row.h"
  91. # include "row0mysql.h"
  92. # include "btr0pcur.h"
  93. # include "os0sync.h"
  94. # include "zlib.h"
  95. # include "ut0crc32.h"
  96. # include "os0stacktrace.h"
  97. /** Log sequence number immediately after startup */
  98. UNIV_INTERN lsn_t srv_start_lsn;
  99. /** Log sequence number at shutdown */
  100. UNIV_INTERN lsn_t srv_shutdown_lsn;
  101. #ifdef HAVE_DARWIN_THREADS
  102. # include <sys/utsname.h>
  103. /** TRUE if the F_FULLFSYNC option is available */
  104. UNIV_INTERN ibool srv_have_fullfsync = FALSE;
  105. #endif
  106. /** TRUE if a raw partition is in use */
  107. UNIV_INTERN ibool srv_start_raw_disk_in_use = FALSE;
  108. /** UNDO tablespaces starts with space id. */
  109. ulint srv_undo_space_id_start;
  110. /** TRUE if the server is being started, before rolling back any
  111. incomplete transactions */
  112. UNIV_INTERN ibool srv_startup_is_before_trx_rollback_phase = FALSE;
  113. /** TRUE if the server is being started */
  114. UNIV_INTERN ibool srv_is_being_started = FALSE;
  115. /** TRUE if the server was successfully started */
  116. UNIV_INTERN ibool srv_was_started = FALSE;
  117. /** TRUE if innobase_start_or_create_for_mysql() has been called */
  118. static ibool srv_start_has_been_called;
  119. /** Whether any undo log records can be generated */
  120. UNIV_INTERN bool srv_undo_sources;
  121. #ifdef UNIV_DEBUG
  122. /** InnoDB system tablespace to set during recovery */
  123. UNIV_INTERN uint srv_sys_space_size_debug;
  124. #endif /* UNIV_DEBUG */
  125. /** At a shutdown this value climbs from SRV_SHUTDOWN_NONE to
  126. SRV_SHUTDOWN_CLEANUP and then to SRV_SHUTDOWN_LAST_PHASE, and so on */
  127. UNIV_INTERN enum srv_shutdown_state srv_shutdown_state = SRV_SHUTDOWN_NONE;
  128. /** Files comprising the system tablespace. Also used by Mariabackup. */
  129. UNIV_INTERN pfs_os_file_t files[1000];
  130. /** io_handler_thread parameters for thread identification */
  131. static ulint n[SRV_MAX_N_IO_THREADS];
  132. /** io_handler_thread identifiers, 32 is the maximum number of purge threads.
  133. The extra elements at the end are allocated as follows:
  134. SRV_MAX_N_IO_THREADS + 1: srv_master_thread
  135. SRV_MAX_N_IO_THREADS + 2: lock_wait_timeout_thread
  136. SRV_MAX_N_IO_THREADS + 3: srv_error_monitor_thread
  137. SRV_MAX_N_IO_THREADS + 4: srv_monitor_thread
  138. SRV_MAX_N_IO_THREADS + 5: srv_redo_log_follow_thread
  139. SRV_MAX_N_IO_THREADS + 6: srv_purge_coordinator_thread
  140. SRV_MAX_N_IO_THREADS + 7: srv_worker_thread
  141. ...
  142. SRV_MAX_N_IO_THREADS + 7 + srv_n_purge_threads - 1: srv_worker_thread */
  143. static os_thread_id_t thread_ids[SRV_MAX_N_IO_THREADS + 7
  144. + SRV_MAX_N_PURGE_THREADS
  145. + MTFLUSH_MAX_WORKER];
  146. /* Thread contex data for multi-threaded flush */
  147. void *mtflush_ctx=NULL;
  148. /** Thead handles */
  149. static os_thread_t thread_handles[SRV_MAX_N_IO_THREADS + 7 + SRV_MAX_N_PURGE_THREADS];
  150. static os_thread_t buf_flush_page_cleaner_thread_handle;
  151. static os_thread_t buf_dump_thread_handle;
  152. static os_thread_t dict_stats_thread_handle;
  153. static os_thread_t buf_flush_lru_manager_thread_handle;
  154. static os_thread_t srv_redo_log_follow_thread_handle;
  155. /** Status variables, is thread started ?*/
  156. static bool thread_started[SRV_MAX_N_IO_THREADS + 7 + SRV_MAX_N_PURGE_THREADS] = {false};
  157. static bool buf_flush_page_cleaner_thread_started = false;
  158. static bool buf_dump_thread_started = false;
  159. static bool dict_stats_thread_started = false;
  160. static bool buf_flush_lru_manager_thread_started = false;
  161. static bool srv_redo_log_follow_thread_started = false;
  162. /** We use this mutex to test the return value of pthread_mutex_trylock
  163. on successful locking. HP-UX does NOT return 0, though Linux et al do. */
  164. static os_fast_mutex_t srv_os_test_mutex;
  165. /** Name of srv_monitor_file */
  166. static char* srv_monitor_file_name;
  167. #endif /* !UNIV_HOTBACKUP */
  168. /** Default undo tablespace size in UNIV_PAGEs count (10MB). */
  169. static const ulint SRV_UNDO_TABLESPACE_SIZE_IN_PAGES =
  170. ((1024 * 1024) * 10) / UNIV_PAGE_SIZE_DEF;
  171. /** */
  172. #define SRV_N_PENDING_IOS_PER_THREAD OS_AIO_N_PENDING_IOS_PER_THREAD
  173. #define SRV_MAX_N_PENDING_SYNC_IOS 100
  174. #ifdef UNIV_PFS_THREAD
  175. /* Keys to register InnoDB threads with performance schema */
  176. UNIV_INTERN mysql_pfs_key_t io_handler_thread_key;
  177. UNIV_INTERN mysql_pfs_key_t srv_lock_timeout_thread_key;
  178. UNIV_INTERN mysql_pfs_key_t srv_error_monitor_thread_key;
  179. UNIV_INTERN mysql_pfs_key_t srv_monitor_thread_key;
  180. UNIV_INTERN mysql_pfs_key_t srv_master_thread_key;
  181. UNIV_INTERN mysql_pfs_key_t srv_purge_thread_key;
  182. UNIV_INTERN mysql_pfs_key_t srv_log_tracking_thread_key;
  183. #endif /* UNIV_PFS_THREAD */
  184. /** Innobase start-up aborted. Perform cleanup actions.
  185. @param[in] create_new_db TRUE if new db is being created
  186. @param[in] file File name
  187. @param[in] line Line number
  188. @param[in] err Reason for aborting InnoDB startup
  189. @return DB_SUCCESS or error code. */
  190. static
  191. dberr_t
  192. srv_init_abort(
  193. bool create_new_db,
  194. const char* file,
  195. ulint line,
  196. dberr_t err)
  197. {
  198. if (create_new_db) {
  199. ib_logf(IB_LOG_LEVEL_ERROR,
  200. "Database creation was aborted"
  201. " at %s [" ULINTPF "]"
  202. " with error %s. You may need"
  203. " to delete the ibdata1 file before trying to start"
  204. " up again.",
  205. file, line, ut_strerr(err));
  206. } else {
  207. ib_logf(IB_LOG_LEVEL_ERROR,
  208. "Plugin initialization aborted"
  209. " at %s [" ULINTPF "]"
  210. " with error %s.",
  211. file, line, ut_strerr(err));
  212. }
  213. return(err);
  214. }
  215. /*********************************************************************//**
  216. Convert a numeric string that optionally ends in G or M or K, to a number
  217. containing megabytes.
  218. @return next character in string */
  219. static
  220. char*
  221. srv_parse_megabytes(
  222. /*================*/
  223. char* str, /*!< in: string containing a quantity in bytes */
  224. ulint* megs) /*!< out: the number in megabytes */
  225. {
  226. char* endp;
  227. ulint size;
  228. size = strtoul(str, &endp, 10);
  229. str = endp;
  230. switch (*str) {
  231. case 'G': case 'g':
  232. size *= 1024;
  233. /* fall through */
  234. case 'M': case 'm':
  235. str++;
  236. break;
  237. case 'K': case 'k':
  238. size /= 1024;
  239. str++;
  240. break;
  241. default:
  242. size /= 1024 * 1024;
  243. break;
  244. }
  245. *megs = size;
  246. return(str);
  247. }
  248. /*********************************************************************//**
  249. Check if a file can be opened in read-write mode.
  250. @return true if it doesn't exist or can be opened in rw mode. */
  251. static
  252. bool
  253. srv_file_check_mode(
  254. /*================*/
  255. const char* name) /*!< in: filename to check */
  256. {
  257. os_file_stat_t stat;
  258. memset(&stat, 0x0, sizeof(stat));
  259. dberr_t err = os_file_get_status(name, &stat, true);
  260. if (err == DB_FAIL) {
  261. ib_logf(IB_LOG_LEVEL_ERROR,
  262. "os_file_get_status() failed on '%s'. Can't determine "
  263. "file permissions", name);
  264. return(false);
  265. } else if (err == DB_SUCCESS) {
  266. /* Note: stat.rw_perm is only valid of files */
  267. if (stat.type == OS_FILE_TYPE_FILE) {
  268. if (!stat.rw_perm) {
  269. ib_logf(IB_LOG_LEVEL_ERROR,
  270. "%s can't be opened in %s mode",
  271. name,
  272. srv_read_only_mode
  273. ? "read" : "read-write");
  274. return(false);
  275. }
  276. } else {
  277. /* Not a regular file, bail out. */
  278. ib_logf(IB_LOG_LEVEL_ERROR,
  279. "'%s' not a regular file.", name);
  280. return(false);
  281. }
  282. } else {
  283. /* This is OK. If the file create fails on RO media, there
  284. is nothing we can do. */
  285. ut_a(err == DB_NOT_FOUND);
  286. }
  287. return(true);
  288. }
  289. /*********************************************************************//**
  290. Reads the data files and their sizes from a character string given in
  291. the .cnf file.
  292. @return TRUE if ok, FALSE on parse error */
  293. UNIV_INTERN
  294. ibool
  295. srv_parse_data_file_paths_and_sizes(
  296. /*================================*/
  297. char* str) /*!< in/out: the data file path string */
  298. {
  299. char* input_str;
  300. char* path;
  301. ulint size;
  302. ulint i = 0;
  303. srv_auto_extend_last_data_file = FALSE;
  304. srv_last_file_size_max = 0;
  305. srv_data_file_names = NULL;
  306. srv_data_file_sizes = NULL;
  307. srv_data_file_is_raw_partition = NULL;
  308. input_str = str;
  309. /* First calculate the number of data files and check syntax:
  310. path:size[M | G];path:size[M | G]... . Note that a Windows path may
  311. contain a drive name and a ':'. */
  312. while (*str != '\0') {
  313. path = str;
  314. while ((*str != ':' && *str != '\0')
  315. || (*str == ':'
  316. && (*(str + 1) == '\\' || *(str + 1) == '/'
  317. || *(str + 1) == ':'))) {
  318. str++;
  319. }
  320. if (*str == '\0') {
  321. return(FALSE);
  322. }
  323. str++;
  324. str = srv_parse_megabytes(str, &size);
  325. if (0 == strncmp(str, ":autoextend",
  326. (sizeof ":autoextend") - 1)) {
  327. str += (sizeof ":autoextend") - 1;
  328. if (0 == strncmp(str, ":max:",
  329. (sizeof ":max:") - 1)) {
  330. str += (sizeof ":max:") - 1;
  331. str = srv_parse_megabytes(str, &size);
  332. }
  333. if (*str != '\0') {
  334. return(FALSE);
  335. }
  336. }
  337. if (strlen(str) >= 6
  338. && *str == 'n'
  339. && *(str + 1) == 'e'
  340. && *(str + 2) == 'w') {
  341. str += 3;
  342. }
  343. if (*str == 'r' && *(str + 1) == 'a' && *(str + 2) == 'w') {
  344. str += 3;
  345. }
  346. if (size == 0) {
  347. return(FALSE);
  348. }
  349. i++;
  350. if (*str == ';') {
  351. str++;
  352. } else if (*str != '\0') {
  353. return(FALSE);
  354. }
  355. }
  356. if (i == 0) {
  357. /* If innodb_data_file_path was defined it must contain
  358. at least one data file definition */
  359. return(FALSE);
  360. }
  361. srv_data_file_names = static_cast<char**>(
  362. malloc(i * sizeof *srv_data_file_names));
  363. srv_data_file_sizes = static_cast<ulint*>(
  364. malloc(i * sizeof *srv_data_file_sizes));
  365. srv_data_file_is_raw_partition = static_cast<ulint*>(
  366. malloc(i * sizeof *srv_data_file_is_raw_partition));
  367. srv_n_data_files = i;
  368. /* Then store the actual values to our arrays */
  369. str = input_str;
  370. i = 0;
  371. while (*str != '\0') {
  372. path = str;
  373. /* Note that we must step over the ':' in a Windows path;
  374. a Windows path normally looks like C:\ibdata\ibdata1:1G, but
  375. a Windows raw partition may have a specification like
  376. \\.\C::1Gnewraw or \\.\PHYSICALDRIVE2:1Gnewraw */
  377. while ((*str != ':' && *str != '\0')
  378. || (*str == ':'
  379. && (*(str + 1) == '\\' || *(str + 1) == '/'
  380. || *(str + 1) == ':'))) {
  381. str++;
  382. }
  383. if (*str == ':') {
  384. /* Make path a null-terminated string */
  385. *str = '\0';
  386. str++;
  387. }
  388. str = srv_parse_megabytes(str, &size);
  389. srv_data_file_names[i] = path;
  390. srv_data_file_sizes[i] = size;
  391. if (0 == strncmp(str, ":autoextend",
  392. (sizeof ":autoextend") - 1)) {
  393. srv_auto_extend_last_data_file = TRUE;
  394. str += (sizeof ":autoextend") - 1;
  395. if (0 == strncmp(str, ":max:",
  396. (sizeof ":max:") - 1)) {
  397. str += (sizeof ":max:") - 1;
  398. str = srv_parse_megabytes(
  399. str, &srv_last_file_size_max);
  400. }
  401. if (*str != '\0') {
  402. return(FALSE);
  403. }
  404. }
  405. (srv_data_file_is_raw_partition)[i] = 0;
  406. if (strlen(str) >= 6
  407. && *str == 'n'
  408. && *(str + 1) == 'e'
  409. && *(str + 2) == 'w') {
  410. str += 3;
  411. /* Initialize new raw device only during bootstrap */
  412. (srv_data_file_is_raw_partition)[i] =
  413. opt_bootstrap ? SRV_NEW_RAW : SRV_OLD_RAW;
  414. }
  415. if (*str == 'r' && *(str + 1) == 'a' && *(str + 2) == 'w') {
  416. str += 3;
  417. /* Initialize new raw device only during bootstrap */
  418. if ((srv_data_file_is_raw_partition)[i] == 0) {
  419. (srv_data_file_is_raw_partition)[i] =
  420. opt_bootstrap ? SRV_NEW_RAW : SRV_OLD_RAW;
  421. }
  422. }
  423. i++;
  424. if (*str == ';') {
  425. str++;
  426. }
  427. }
  428. return(TRUE);
  429. }
  430. /*********************************************************************//**
  431. Frees the memory allocated by srv_parse_data_file_paths_and_sizes()
  432. and srv_parse_log_group_home_dirs(). */
  433. UNIV_INTERN
  434. void
  435. srv_free_paths_and_sizes(void)
  436. /*==========================*/
  437. {
  438. free(srv_data_file_names);
  439. srv_data_file_names = NULL;
  440. free(srv_data_file_sizes);
  441. srv_data_file_sizes = NULL;
  442. free(srv_data_file_is_raw_partition);
  443. srv_data_file_is_raw_partition = NULL;
  444. }
  445. #ifndef UNIV_HOTBACKUP
  446. static ulint io_tid_i = 0;
  447. /********************************************************************//**
  448. I/o-handler thread function.
  449. @return OS_THREAD_DUMMY_RETURN */
  450. extern "C" UNIV_INTERN
  451. os_thread_ret_t
  452. DECLARE_THREAD(io_handler_thread)(
  453. /*==============================*/
  454. void* arg) /*!< in: pointer to the number of the segment in
  455. the aio array */
  456. {
  457. ulint segment;
  458. ulint tid_i = os_atomic_increment_ulint(&io_tid_i, 1) - 1;
  459. ut_ad(tid_i < srv_n_file_io_threads);
  460. segment = *((ulint*) arg);
  461. srv_io_tids[tid_i] = os_thread_get_tid();
  462. os_thread_set_priority(srv_io_tids[tid_i], srv_sched_priority_io);
  463. #ifdef UNIV_DEBUG_THREAD_CREATION
  464. ib_logf(IB_LOG_LEVEL_INFO,
  465. "Io handler thread %lu starts, id %lu\n", segment,
  466. os_thread_pf(os_thread_get_curr_id()));
  467. #endif
  468. #ifdef UNIV_PFS_THREAD
  469. pfs_register_thread(io_handler_thread_key);
  470. #endif /* UNIV_PFS_THREAD */
  471. while (srv_shutdown_state != SRV_SHUTDOWN_EXIT_THREADS) {
  472. srv_current_thread_priority = srv_io_thread_priority;
  473. fil_aio_wait(segment);
  474. }
  475. /* We count the number of threads in os_thread_exit(). A created
  476. thread should always use that to exit and not use return() to exit.
  477. The thread actually never comes here because it is exited in an
  478. os_event_wait(). */
  479. os_thread_exit(NULL);
  480. OS_THREAD_DUMMY_RETURN;
  481. }
  482. #endif /* !UNIV_HOTBACKUP */
  483. /*********************************************************************//**
  484. Normalizes a directory path for Windows: converts slashes to backslashes. */
  485. UNIV_INTERN
  486. void
  487. srv_normalize_path_for_win(
  488. /*=======================*/
  489. char* str MY_ATTRIBUTE((unused))) /*!< in/out: null-terminated
  490. character string */
  491. {
  492. #ifdef __WIN__
  493. for (; *str; str++) {
  494. if (*str == '/') {
  495. *str = '\\';
  496. }
  497. }
  498. #endif
  499. }
  500. #ifndef UNIV_HOTBACKUP
  501. /*********************************************************************//**
  502. Creates a log file.
  503. @return DB_SUCCESS or error code */
  504. static MY_ATTRIBUTE((nonnull, warn_unused_result))
  505. dberr_t
  506. create_log_file(
  507. /*============*/
  508. pfs_os_file_t* file, /*!< out: file handle */
  509. const char* name) /*!< in: log file name */
  510. {
  511. ibool ret;
  512. *file = os_file_create(
  513. innodb_file_log_key, name,
  514. OS_FILE_CREATE|OS_FILE_ON_ERROR_NO_EXIT, OS_FILE_NORMAL,
  515. OS_LOG_FILE, &ret, FALSE);
  516. if (!ret) {
  517. ib_logf(IB_LOG_LEVEL_ERROR, "Cannot create %s", name);
  518. return(DB_ERROR);
  519. }
  520. ib_logf(IB_LOG_LEVEL_INFO,
  521. "Setting log file %s size to %lu MB",
  522. name, (ulong) srv_log_file_size
  523. >> (20 - UNIV_PAGE_SIZE_SHIFT));
  524. ret = os_file_set_size(name, *file,
  525. (os_offset_t) srv_log_file_size
  526. << UNIV_PAGE_SIZE_SHIFT);
  527. if (!ret) {
  528. ib_logf(IB_LOG_LEVEL_ERROR, "Cannot set log file"
  529. " %s to size %lu MB", name, (ulong) srv_log_file_size
  530. >> (20 - UNIV_PAGE_SIZE_SHIFT));
  531. return(DB_ERROR);
  532. }
  533. ret = os_file_close(*file);
  534. ut_a(ret);
  535. return(DB_SUCCESS);
  536. }
  537. /** Initial number of the first redo log file */
  538. #define INIT_LOG_FILE0 (SRV_N_LOG_FILES_MAX + 1)
  539. /*********************************************************************//**
  540. Creates all log files.
  541. @return DB_SUCCESS or error code */
  542. static
  543. dberr_t
  544. create_log_files(
  545. /*=============*/
  546. bool create_new_db, /*!< in: TRUE if new database is being
  547. created */
  548. char* logfilename, /*!< in/out: buffer for log file name */
  549. size_t dirnamelen, /*!< in: length of the directory path */
  550. lsn_t lsn, /*!< in: FIL_PAGE_FILE_FLUSH_LSN value */
  551. char*& logfile0) /*!< out: name of the first log file */
  552. {
  553. if (srv_read_only_mode) {
  554. ib_logf(IB_LOG_LEVEL_ERROR,
  555. "Cannot create log files in read-only mode");
  556. return(DB_READ_ONLY);
  557. }
  558. /* We prevent system tablespace creation with existing files in
  559. data directory. So we do not delete log files when creating new system
  560. tablespace */
  561. if (!create_new_db) {
  562. /* Remove any old log files. */
  563. for (unsigned i = 0; i <= INIT_LOG_FILE0; i++) {
  564. sprintf(logfilename + dirnamelen, "ib_logfile%u", i);
  565. /* Ignore errors about non-existent files or files
  566. that cannot be removed. The create_log_file() will
  567. return an error when the file exists. */
  568. #ifdef __WIN__
  569. DeleteFile((LPCTSTR) logfilename);
  570. #else
  571. unlink(logfilename);
  572. #endif
  573. /* Crashing after deleting the first
  574. file should be recoverable. The buffer
  575. pool was clean, and we can simply create
  576. all log files from the scratch. */
  577. DBUG_EXECUTE_IF("innodb_log_abort_6",
  578. return(DB_ERROR););
  579. }
  580. }
  581. ut_ad(!buf_pool_check_no_pending_io());
  582. DBUG_EXECUTE_IF("innodb_log_abort_7", return(DB_ERROR););
  583. for (unsigned i = 0; i < srv_n_log_files; i++) {
  584. sprintf(logfilename + dirnamelen,
  585. "ib_logfile%u", i ? i : INIT_LOG_FILE0);
  586. dberr_t err = create_log_file(&files[i], logfilename);
  587. if (err != DB_SUCCESS) {
  588. return(err);
  589. }
  590. }
  591. DBUG_EXECUTE_IF("innodb_log_abort_8", return(DB_ERROR););
  592. /* We did not create the first log file initially as
  593. ib_logfile0, so that crash recovery cannot find it until it
  594. has been completed and renamed. */
  595. sprintf(logfilename + dirnamelen, "ib_logfile%u", INIT_LOG_FILE0);
  596. fil_space_create(
  597. logfilename, SRV_LOG_SPACE_FIRST_ID, 0,
  598. FIL_LOG,
  599. NULL /* no encryption yet */,
  600. true /* this is create */);
  601. ut_a(fil_validate());
  602. logfile0 = fil_node_create(
  603. logfilename, (ulint) srv_log_file_size,
  604. SRV_LOG_SPACE_FIRST_ID, FALSE);
  605. ut_a(logfile0);
  606. for (unsigned i = 1; i < srv_n_log_files; i++) {
  607. sprintf(logfilename + dirnamelen, "ib_logfile%u", i);
  608. if (!fil_node_create(
  609. logfilename,
  610. (ulint) srv_log_file_size,
  611. SRV_LOG_SPACE_FIRST_ID, FALSE)) {
  612. ut_error;
  613. }
  614. }
  615. #ifdef UNIV_LOG_ARCHIVE
  616. /* Create the file space object for archived logs. */
  617. fil_space_create("arch_log_space", SRV_LOG_SPACE_FIRST_ID + 1,
  618. 0, FIL_LOG, NULL /* no encryption yet */, true /* create */);
  619. #endif
  620. log_group_init(0, srv_n_log_files,
  621. srv_log_file_size * UNIV_PAGE_SIZE,
  622. SRV_LOG_SPACE_FIRST_ID,
  623. SRV_LOG_SPACE_FIRST_ID + 1);
  624. fil_open_log_and_system_tablespace_files();
  625. /* Create a log checkpoint. */
  626. mutex_enter(&log_sys->mutex);
  627. ut_d(recv_no_log_write = srv_apply_log_only);
  628. recv_reset_logs(
  629. #ifdef UNIV_LOG_ARCHIVE
  630. UT_LIST_GET_FIRST(log_sys->log_groups)->archived_file_no,
  631. TRUE,
  632. #endif
  633. lsn);
  634. mutex_exit(&log_sys->mutex);
  635. return(DB_SUCCESS);
  636. }
  637. /** Rename the first redo log file.
  638. @param[in,out] logfilename buffer for the log file name
  639. @param[in] dirnamelen length of the directory path
  640. @param[in] lsn FIL_PAGE_FILE_FLUSH_LSN value
  641. @param[in,out] logfile0 name of the first log file
  642. @return error code
  643. @retval DB_SUCCESS on successful operation */
  644. MY_ATTRIBUTE((warn_unused_result, nonnull))
  645. static
  646. dberr_t
  647. create_log_files_rename(
  648. /*====================*/
  649. char* logfilename, /*!< in/out: buffer for log file name */
  650. size_t dirnamelen, /*!< in: length of the directory path */
  651. lsn_t lsn, /*!< in: FIL_PAGE_FILE_FLUSH_LSN value */
  652. char* logfile0) /*!< in/out: name of the first log file */
  653. {
  654. /* If innodb_flush_method=O_DSYNC,
  655. we need to explicitly flush the log buffers. */
  656. fil_flush(SRV_LOG_SPACE_FIRST_ID);
  657. DBUG_EXECUTE_IF("innodb_log_abort_9", return(DB_ERROR););
  658. /* Close the log files, so that we can rename
  659. the first one. */
  660. fil_close_log_files(false);
  661. /* Rename the first log file, now that a log
  662. checkpoint has been created. */
  663. sprintf(logfilename + dirnamelen, "ib_logfile%u", 0);
  664. ib_logf(IB_LOG_LEVEL_INFO,
  665. "Renaming log file %s to %s", logfile0, logfilename);
  666. mutex_enter(&log_sys->mutex);
  667. ut_ad(strlen(logfile0) == 2 + strlen(logfilename));
  668. dberr_t err = os_file_rename(
  669. innodb_file_log_key, logfile0, logfilename)
  670. ? DB_SUCCESS : DB_ERROR;
  671. /* Replace the first file with ib_logfile0. */
  672. strcpy(logfile0, logfilename);
  673. mutex_exit(&log_sys->mutex);
  674. DBUG_EXECUTE_IF("innodb_log_abort_10", err = DB_ERROR;);
  675. if (err == DB_SUCCESS) {
  676. fil_open_log_and_system_tablespace_files();
  677. ib_logf(IB_LOG_LEVEL_WARN,
  678. "New log files created, LSN=" LSN_PF, lsn);
  679. }
  680. return(err);
  681. }
  682. /*********************************************************************//**
  683. Opens a log file.
  684. @return DB_SUCCESS or error code */
  685. static MY_ATTRIBUTE((nonnull, warn_unused_result))
  686. dberr_t
  687. open_log_file(
  688. /*==========*/
  689. pfs_os_file_t* file, /*!< out: file handle */
  690. const char* name, /*!< in: log file name */
  691. os_offset_t* size) /*!< out: file size */
  692. {
  693. ibool ret;
  694. *file = os_file_create(innodb_file_log_key, name,
  695. OS_FILE_OPEN, OS_FILE_AIO,
  696. OS_LOG_FILE, &ret, FALSE);
  697. if (!ret) {
  698. ib_logf(IB_LOG_LEVEL_ERROR, "Unable to open '%s'", name);
  699. return(DB_ERROR);
  700. }
  701. *size = os_file_get_size(*file);
  702. ret = os_file_close(*file);
  703. ut_a(ret);
  704. return(DB_SUCCESS);
  705. }
  706. /** Creates or opens database data files and closes them.
  707. @param[out] create_new_db true = create new database
  708. @param[out] min_arch_log_no min of archived log numbers in
  709. data files
  710. @param[out] max_arch_log_no max of archived log numbers in
  711. data files
  712. @param[out] flushed_lsn flushed lsn in fist datafile
  713. @param[out] sum_of_new_sizes sum of sizes of the new files
  714. added
  715. @return DB_SUCCESS or error code */
  716. MY_ATTRIBUTE((nonnull, warn_unused_result))
  717. dberr_t
  718. open_or_create_data_files(
  719. bool* create_new_db,
  720. #ifdef UNIV_LOG_ARCHIVE
  721. lsn_t* min_arch_log_no,
  722. lsn_t* max_arch_log_no,
  723. #endif /* UNIV_LOG_ARCHIVE */
  724. lsn_t* flushed_lsn,
  725. ulint* sum_of_new_sizes)
  726. {
  727. ibool ret;
  728. ulint i;
  729. bool one_opened = false;
  730. bool one_created = false;
  731. os_offset_t size;
  732. ulint flags;
  733. ulint space = 0;
  734. ulint rounded_size_pages;
  735. char name[10000];
  736. fil_space_crypt_t* crypt_data=NULL;
  737. if (srv_n_data_files >= 1000) {
  738. ib_logf(IB_LOG_LEVEL_ERROR,
  739. "Can only have < 1000 data files, you have "
  740. "defined %lu", (ulong) srv_n_data_files);
  741. return(DB_ERROR);
  742. }
  743. *sum_of_new_sizes = 0;
  744. *create_new_db = false;
  745. srv_normalize_path_for_win(srv_data_home);
  746. for (i = 0; i < srv_n_data_files; i++) {
  747. ulint dirnamelen;
  748. srv_normalize_path_for_win(srv_data_file_names[i]);
  749. dirnamelen = strlen(srv_data_home);
  750. ut_a(dirnamelen + strlen(srv_data_file_names[i])
  751. < (sizeof name) - 1);
  752. memcpy(name, srv_data_home, dirnamelen);
  753. /* Add a path separator if needed. */
  754. if (dirnamelen && name[dirnamelen - 1] != SRV_PATH_SEPARATOR) {
  755. name[dirnamelen++] = SRV_PATH_SEPARATOR;
  756. }
  757. strcpy(name + dirnamelen, srv_data_file_names[i]);
  758. /* Note: It will return true if the file doesn' exist. */
  759. if (!srv_file_check_mode(name)) {
  760. return(DB_FAIL);
  761. } else if (srv_data_file_is_raw_partition[i] == 0) {
  762. /* First we try to create the file: if it already
  763. exists, ret will get value FALSE */
  764. files[i] = os_file_create(
  765. innodb_file_data_key, name, OS_FILE_CREATE,
  766. OS_FILE_NORMAL, OS_DATA_FILE, &ret, FALSE);
  767. if (srv_read_only_mode) {
  768. if (ret) {
  769. goto size_check;
  770. }
  771. ib_logf(IB_LOG_LEVEL_ERROR,
  772. "Opening %s failed!", name);
  773. return(DB_ERROR);
  774. } else if (!ret
  775. && os_file_get_last_error(false)
  776. != OS_FILE_ALREADY_EXISTS
  777. #ifdef UNIV_AIX
  778. /* AIX 5.1 after security patch ML7 may have
  779. errno set to 0 here, which causes our
  780. function to return 100; work around that
  781. AIX problem */
  782. && os_file_get_last_error(false) != 100
  783. #endif /* UNIV_AIX */
  784. ) {
  785. ib_logf(IB_LOG_LEVEL_ERROR,
  786. "Creating or opening %s failed!",
  787. name);
  788. return(DB_ERROR);
  789. }
  790. } else if (srv_data_file_is_raw_partition[i] == SRV_NEW_RAW) {
  791. ut_a(!srv_read_only_mode);
  792. /* The partition is opened, not created; then it is
  793. written over */
  794. srv_start_raw_disk_in_use = TRUE;
  795. srv_created_new_raw = TRUE;
  796. files[i] = os_file_create(
  797. innodb_file_data_key, name, OS_FILE_OPEN_RAW,
  798. OS_FILE_NORMAL, OS_DATA_FILE, &ret, FALSE);
  799. if (!ret) {
  800. ib_logf(IB_LOG_LEVEL_ERROR,
  801. "Error in opening %s", name);
  802. return(DB_ERROR);
  803. }
  804. const char* check_msg;
  805. check_msg = fil_read_first_page(
  806. files[i], FALSE, &flags, &space,
  807. flushed_lsn, NULL);
  808. /* If first page is valid, don't overwrite DB.
  809. It prevents overwriting DB when mysql_install_db
  810. starts mysqld multiple times during bootstrap. */
  811. if (check_msg == NULL) {
  812. srv_created_new_raw = FALSE;
  813. ret = FALSE;
  814. }
  815. } else if (srv_data_file_is_raw_partition[i] == SRV_OLD_RAW) {
  816. srv_start_raw_disk_in_use = TRUE;
  817. ret = FALSE;
  818. } else {
  819. ut_a(0);
  820. }
  821. if (ret == FALSE) {
  822. const char* check_msg;
  823. /* We open the data file */
  824. if (one_created) {
  825. ib_logf(IB_LOG_LEVEL_ERROR,
  826. "Data files can only be added at "
  827. "the end of a tablespace, but "
  828. "data file %s existed beforehand.",
  829. name);
  830. return(DB_ERROR);
  831. }
  832. if (srv_data_file_is_raw_partition[i] == SRV_OLD_RAW) {
  833. ut_a(!srv_read_only_mode);
  834. files[i] = os_file_create(
  835. innodb_file_data_key,
  836. name, OS_FILE_OPEN_RAW,
  837. OS_FILE_NORMAL, OS_DATA_FILE, &ret, FALSE);
  838. } else if (i == 0) {
  839. files[i] = os_file_create(
  840. innodb_file_data_key,
  841. name, OS_FILE_OPEN_RETRY,
  842. OS_FILE_NORMAL, OS_DATA_FILE, &ret, FALSE);
  843. } else {
  844. files[i] = os_file_create(
  845. innodb_file_data_key,
  846. name, OS_FILE_OPEN, OS_FILE_NORMAL,
  847. OS_DATA_FILE, &ret, FALSE);
  848. }
  849. if (!ret) {
  850. os_file_get_last_error(true);
  851. ib_logf(IB_LOG_LEVEL_ERROR,
  852. "Can't open '%s'", name);
  853. return(DB_ERROR);
  854. }
  855. if (srv_data_file_is_raw_partition[i] == SRV_OLD_RAW) {
  856. goto skip_size_check;
  857. }
  858. size_check:
  859. size = os_file_get_size(files[i]);
  860. ut_a(size != (os_offset_t) -1);
  861. /* If InnoDB encountered an error or was killed
  862. while extending the data file, the last page
  863. could be incomplete. */
  864. rounded_size_pages = static_cast<ulint>(
  865. size >> UNIV_PAGE_SIZE_SHIFT);
  866. if (i == srv_n_data_files - 1
  867. && srv_auto_extend_last_data_file) {
  868. if (srv_data_file_sizes[i] > rounded_size_pages
  869. || (srv_last_file_size_max > 0
  870. && srv_last_file_size_max
  871. < rounded_size_pages)) {
  872. ib_logf(IB_LOG_LEVEL_ERROR,
  873. "auto-extending "
  874. "data file %s is "
  875. "of a different size "
  876. ULINTPF " pages (rounded "
  877. "down to MB) than specified "
  878. "in the .cnf file: "
  879. "initial " ULINTPF " pages, "
  880. "max " ULINTPF " (relevant if "
  881. "non-zero) pages!",
  882. name,
  883. rounded_size_pages,
  884. srv_data_file_sizes[i],
  885. srv_last_file_size_max);
  886. return(DB_ERROR);
  887. }
  888. srv_data_file_sizes[i] = rounded_size_pages;
  889. }
  890. if (rounded_size_pages != srv_data_file_sizes[i]) {
  891. ib_logf(IB_LOG_LEVEL_ERROR,
  892. "Data file %s is of a different "
  893. "size " ULINTPF " pages (rounded down to MB) "
  894. "than specified in the .cnf file "
  895. ULINTPF " pages!",
  896. name,
  897. rounded_size_pages,
  898. srv_data_file_sizes[i]);
  899. return(DB_ERROR);
  900. }
  901. skip_size_check:
  902. /* This is the earliest location where we can load
  903. the double write buffer. */
  904. if (i == 0) {
  905. /* XtraBackup never loads corrupted pages from
  906. the doublewrite buffer */
  907. buf_dblwr_init_or_load_pages(
  908. files[i], srv_data_file_names[i], !IS_XTRABACKUP());
  909. }
  910. bool retry = true;
  911. check_first_page:
  912. check_msg = fil_read_first_page(
  913. files[i], one_opened, &flags, &space,
  914. flushed_lsn, &crypt_data);
  915. if (check_msg) {
  916. if (retry) {
  917. fsp_open_info fsp;
  918. const ulint page_no = 0;
  919. retry = false;
  920. fsp.id = 0;
  921. fsp.filepath = srv_data_file_names[i];
  922. fsp.file = files[i];
  923. if (fil_user_tablespace_restore_page(
  924. &fsp, page_no)) {
  925. goto check_first_page;
  926. }
  927. }
  928. ib_logf(IB_LOG_LEVEL_ERROR,
  929. "%s in data file %s",
  930. check_msg, name);
  931. return(DB_ERROR);
  932. }
  933. /* The first file of the system tablespace must
  934. have space ID = TRX_SYS_SPACE. The FSP_SPACE_ID
  935. field in files greater than ibdata1 are unreliable. */
  936. ut_a(one_opened || space == TRX_SYS_SPACE);
  937. /* Check the flags for the first system tablespace
  938. file only. */
  939. if (!one_opened
  940. && UNIV_PAGE_SIZE
  941. != fsp_flags_get_page_size(flags)) {
  942. ib_logf(IB_LOG_LEVEL_ERROR,
  943. "Data file \"%s\" uses page size " ULINTPF " ,"
  944. "but the start-up parameter "
  945. "is --innodb-page-size=" ULINTPF " .",
  946. name,
  947. fsp_flags_get_page_size(flags),
  948. UNIV_PAGE_SIZE);
  949. return(DB_ERROR);
  950. }
  951. one_opened = TRUE;
  952. } else if (!srv_read_only_mode) {
  953. /* We created the data file and now write it full of
  954. zeros */
  955. one_created = TRUE;
  956. if (i > 0) {
  957. ib_logf(IB_LOG_LEVEL_INFO,
  958. "Data file %s did not"
  959. " exist: new to be created",
  960. name);
  961. } else {
  962. ib_logf(IB_LOG_LEVEL_INFO,
  963. "The first specified "
  964. "data file %s did not exist: "
  965. "a new database to be created!",
  966. name);
  967. *create_new_db = TRUE;
  968. }
  969. ib_logf(IB_LOG_LEVEL_INFO,
  970. "Setting file %s size to " ULINTPF " MB",
  971. name,
  972. (srv_data_file_sizes[i]
  973. >> (20 - UNIV_PAGE_SIZE_SHIFT)));
  974. ret = os_file_set_size(
  975. name, files[i],
  976. (os_offset_t) srv_data_file_sizes[i]
  977. << UNIV_PAGE_SIZE_SHIFT
  978. /* TODO: enable page_compression on the
  979. system tablespace and add
  980. , FSP_FLAGS_HAS_PAGE_COMPRESSION(flags)*/);
  981. if (!ret) {
  982. ib_logf(IB_LOG_LEVEL_ERROR,
  983. "Error in creating %s: "
  984. "probably out of disk space",
  985. name);
  986. return(DB_ERROR);
  987. }
  988. *sum_of_new_sizes += srv_data_file_sizes[i];
  989. }
  990. ret = os_file_close(files[i]);
  991. ut_a(ret);
  992. if (i == 0) {
  993. flags = FSP_FLAGS_PAGE_SSIZE();
  994. fil_space_create(name, 0, flags, FIL_TABLESPACE,
  995. crypt_data, (*create_new_db) == true);
  996. }
  997. ut_a(fil_validate());
  998. if (!fil_node_create(name, srv_data_file_sizes[i], 0,
  999. srv_data_file_is_raw_partition[i] != 0)) {
  1000. return(DB_ERROR);
  1001. }
  1002. }
  1003. return(DB_SUCCESS);
  1004. }
  1005. /*********************************************************************//**
  1006. Create undo tablespace.
  1007. @return DB_SUCCESS or error code */
  1008. static
  1009. dberr_t
  1010. srv_undo_tablespace_create(
  1011. /*=======================*/
  1012. const char* name, /*!< in: tablespace name */
  1013. ulint size) /*!< in: tablespace size in pages */
  1014. {
  1015. pfs_os_file_t fh;
  1016. ibool ret;
  1017. dberr_t err = DB_SUCCESS;
  1018. os_file_create_subdirs_if_needed(name);
  1019. fh = os_file_create(
  1020. innodb_file_data_key,
  1021. name,
  1022. srv_read_only_mode ? OS_FILE_OPEN : OS_FILE_CREATE,
  1023. OS_FILE_NORMAL, OS_DATA_FILE, &ret, FALSE);
  1024. if (srv_read_only_mode && ret) {
  1025. ib_logf(IB_LOG_LEVEL_INFO,
  1026. "%s opened in read-only mode", name);
  1027. } else if (ret == FALSE) {
  1028. if (os_file_get_last_error(false) != OS_FILE_ALREADY_EXISTS
  1029. #ifdef UNIV_AIX
  1030. /* AIX 5.1 after security patch ML7 may have
  1031. errno set to 0 here, which causes our function
  1032. to return 100; work around that AIX problem */
  1033. && os_file_get_last_error(false) != 100
  1034. #endif /* UNIV_AIX */
  1035. ) {
  1036. ib_logf(IB_LOG_LEVEL_ERROR,
  1037. "Can't create UNDO tablespace %s", name);
  1038. } else {
  1039. ib_logf(IB_LOG_LEVEL_ERROR,
  1040. "Creating system tablespace with"
  1041. " existing undo tablespaces is not"
  1042. " supported. Please delete all undo"
  1043. " tablespaces before creating new"
  1044. " system tablespace.");
  1045. }
  1046. err = DB_ERROR;
  1047. } else {
  1048. ut_a(!srv_read_only_mode);
  1049. /* We created the data file and now write it full of zeros */
  1050. ib_logf(IB_LOG_LEVEL_INFO,
  1051. "Data file %s did not exist: new to be created",
  1052. name);
  1053. ib_logf(IB_LOG_LEVEL_INFO,
  1054. "Setting file %s size to %lu MB",
  1055. name, size >> (20 - UNIV_PAGE_SIZE_SHIFT));
  1056. ret = os_file_set_size(name, fh, size << UNIV_PAGE_SIZE_SHIFT
  1057. /* TODO: enable page_compression on the
  1058. system tablespace and add
  1059. FSP_FLAGS_HAS_PAGE_COMPRESSION(flags)
  1060. */);
  1061. if (!ret) {
  1062. ib_logf(IB_LOG_LEVEL_INFO,
  1063. "Error in creating %s: probably out of "
  1064. "disk space", name);
  1065. err = DB_ERROR;
  1066. }
  1067. os_file_close(fh);
  1068. }
  1069. return(err);
  1070. }
  1071. /*********************************************************************//**
  1072. Open an undo tablespace.
  1073. @return DB_SUCCESS or error code */
  1074. static
  1075. dberr_t
  1076. srv_undo_tablespace_open(
  1077. /*=====================*/
  1078. const char* name, /*!< in: tablespace name */
  1079. ulint space) /*!< in: tablespace id */
  1080. {
  1081. pfs_os_file_t fh;
  1082. dberr_t err = DB_ERROR;
  1083. ibool ret;
  1084. ulint flags;
  1085. if (!srv_file_check_mode(name)) {
  1086. ib_logf(IB_LOG_LEVEL_ERROR,
  1087. "UNDO tablespaces must be %s!",
  1088. srv_read_only_mode ? "writable" : "readable");
  1089. return(DB_ERROR);
  1090. }
  1091. fh = os_file_create(
  1092. innodb_file_data_key, name,
  1093. OS_FILE_OPEN_RETRY
  1094. | OS_FILE_ON_ERROR_NO_EXIT
  1095. | OS_FILE_ON_ERROR_SILENT,
  1096. OS_FILE_NORMAL,
  1097. OS_DATA_FILE,
  1098. &ret,
  1099. FALSE);
  1100. /* If the file open was successful then load the tablespace. */
  1101. if (ret) {
  1102. os_offset_t size;
  1103. size = os_file_get_size(fh);
  1104. ut_a(size != (os_offset_t) -1);
  1105. /* Load the tablespace into InnoDB's internal
  1106. data structures. */
  1107. const char* check_msg;
  1108. fil_space_crypt_t* crypt_data = NULL;
  1109. /* Set the compressed page size to 0 (non-compressed) */
  1110. flags = FSP_FLAGS_PAGE_SSIZE();
  1111. /* Read first page to find out does the crypt_info
  1112. exists on undo tablespace. */
  1113. check_msg = fil_read_first_page(
  1114. fh, FALSE, &flags, &space,
  1115. NULL, &crypt_data, false);
  1116. ret = os_file_close(fh);
  1117. ut_a(ret);
  1118. if (check_msg) {
  1119. ib_logf(IB_LOG_LEVEL_ERROR,
  1120. "%s in data file %s",
  1121. check_msg, name);
  1122. return (err);
  1123. }
  1124. /* We set the biggest space id to the undo tablespace
  1125. because InnoDB hasn't opened any other tablespace apart
  1126. from the system tablespace. */
  1127. fil_set_max_space_id_if_bigger(space);
  1128. fil_space_create(name, space, flags, FIL_TABLESPACE,
  1129. crypt_data,
  1130. true /* create */);
  1131. ut_a(fil_validate());
  1132. os_offset_t n_pages = size / UNIV_PAGE_SIZE;
  1133. /* On 64 bit Windows ulint can be 32 bit and os_offset_t
  1134. is 64 bit. It is OK to cast the n_pages to ulint because
  1135. the unit has been scaled to pages and they are always
  1136. 32 bit. */
  1137. if (fil_node_create(name, (ulint) n_pages, space, FALSE)) {
  1138. err = DB_SUCCESS;
  1139. }
  1140. }
  1141. return(err);
  1142. }
  1143. /********************************************************************
  1144. Opens the configured number of undo tablespaces.
  1145. @return DB_SUCCESS or error code */
  1146. dberr_t
  1147. srv_undo_tablespaces_init(
  1148. /*======================*/
  1149. ibool create_new_db, /*!< in: TRUE if new db being
  1150. created */
  1151. ibool backup_mode, /*!< in: TRUE disables reading
  1152. the system tablespace (used in
  1153. XtraBackup), FALSE is passed on
  1154. recovery. */
  1155. const ulint n_conf_tablespaces, /*!< in: configured undo
  1156. tablespaces */
  1157. ulint* n_opened) /*!< out: number of UNDO
  1158. tablespaces successfully
  1159. discovered and opened */
  1160. {
  1161. ulint i;
  1162. dberr_t err = DB_SUCCESS;
  1163. ulint prev_space_id = 0;
  1164. ulint n_undo_tablespaces;
  1165. ulint undo_tablespace_ids[TRX_SYS_N_RSEGS + 1];
  1166. *n_opened = 0;
  1167. ut_a(n_conf_tablespaces <= TRX_SYS_N_RSEGS);
  1168. memset(undo_tablespace_ids, 0x0, sizeof(undo_tablespace_ids));
  1169. /* Create the undo spaces only if we are creating a new
  1170. instance. We don't allow creating of new undo tablespaces
  1171. in an existing instance (yet). This restriction exists because
  1172. we check in several places for SYSTEM tablespaces to be less than
  1173. the min of user defined tablespace ids. Once we implement saving
  1174. the location of the undo tablespaces and their space ids this
  1175. restriction will/should be lifted. */
  1176. for (i = 0; create_new_db && i < n_conf_tablespaces; ++i) {
  1177. char name[OS_FILE_MAX_PATH];
  1178. ulint space_id = i + 1;
  1179. DBUG_EXECUTE_IF("innodb_undo_upgrade",
  1180. space_id = i + 3;);
  1181. ut_snprintf(
  1182. name, sizeof(name),
  1183. "%s%cundo%03lu",
  1184. srv_undo_dir, SRV_PATH_SEPARATOR, space_id);
  1185. if (i == 0) {
  1186. srv_undo_space_id_start = space_id;
  1187. prev_space_id = srv_undo_space_id_start - 1;
  1188. }
  1189. undo_tablespace_ids[i] = space_id;
  1190. err = srv_undo_tablespace_create(
  1191. name, SRV_UNDO_TABLESPACE_SIZE_IN_PAGES);
  1192. if (err != DB_SUCCESS) {
  1193. ib_logf(IB_LOG_LEVEL_ERROR,
  1194. "Could not create undo tablespace '%s'.",
  1195. name);
  1196. return(err);
  1197. }
  1198. }
  1199. /* Get the tablespace ids of all the undo segments excluding
  1200. the system tablespace (0). If we are creating a new instance then
  1201. we build the undo_tablespace_ids ourselves since they don't
  1202. already exist. */
  1203. if (!create_new_db && !backup_mode) {
  1204. n_undo_tablespaces = trx_rseg_get_n_undo_tablespaces(
  1205. undo_tablespace_ids);
  1206. if (n_undo_tablespaces != 0) {
  1207. srv_undo_space_id_start = undo_tablespace_ids[0];
  1208. prev_space_id = srv_undo_space_id_start - 1;
  1209. }
  1210. } else {
  1211. n_undo_tablespaces = n_conf_tablespaces;
  1212. undo_tablespace_ids[n_conf_tablespaces] = ULINT_UNDEFINED;
  1213. if (backup_mode) {
  1214. ut_ad(!create_new_db);
  1215. /* MDEV-13561 FIXME: Determine srv_undo_space_id_start
  1216. from the undo001 file. */
  1217. srv_undo_space_id_start = 1;
  1218. for (i = 0; i < n_undo_tablespaces; i++) {
  1219. undo_tablespace_ids[i]
  1220. = i + srv_undo_space_id_start;
  1221. }
  1222. }
  1223. }
  1224. /* Open all the undo tablespaces that are currently in use. If we
  1225. fail to open any of these it is a fatal error. The tablespace ids
  1226. should be contiguous. It is a fatal error because they are required
  1227. for recovery and are referenced by the UNDO logs (a.k.a RBS). */
  1228. for (i = 0; i < n_undo_tablespaces; ++i) {
  1229. char name[OS_FILE_MAX_PATH];
  1230. ut_snprintf(
  1231. name, sizeof(name),
  1232. "%s%cundo%03lu",
  1233. srv_undo_dir, SRV_PATH_SEPARATOR,
  1234. undo_tablespace_ids[i]);
  1235. /* Should be no gaps in undo tablespace ids. */
  1236. ut_a(prev_space_id + 1 == undo_tablespace_ids[i]);
  1237. /* The system space id should not be in this array. */
  1238. ut_a(undo_tablespace_ids[i] != 0);
  1239. ut_a(undo_tablespace_ids[i] != ULINT_UNDEFINED);
  1240. err = srv_undo_tablespace_open(name, undo_tablespace_ids[i]);
  1241. if (err != DB_SUCCESS) {
  1242. ib_logf(IB_LOG_LEVEL_ERROR,
  1243. "Unable to open undo tablespace '%s'.", name);
  1244. return(err);
  1245. }
  1246. prev_space_id = undo_tablespace_ids[i];
  1247. ++*n_opened;
  1248. }
  1249. /* Open any extra unused undo tablespaces. These must be contiguous.
  1250. We stop at the first failure. These are undo tablespaces that are
  1251. not in use and therefore not required by recovery. We only check
  1252. that there are no gaps. */
  1253. for (i = prev_space_id + 1; i < TRX_SYS_N_RSEGS; ++i) {
  1254. char name[OS_FILE_MAX_PATH];
  1255. ut_snprintf(
  1256. name, sizeof(name),
  1257. "%s%cundo%03lu", srv_undo_dir, SRV_PATH_SEPARATOR, i);
  1258. /* Undo space ids start from 1. */
  1259. err = srv_undo_tablespace_open(name, i);
  1260. if (err != DB_SUCCESS) {
  1261. break;
  1262. }
  1263. /** Note the first undo tablespace id in case of
  1264. no active undo tablespace. */
  1265. if (n_undo_tablespaces == 0) {
  1266. srv_undo_space_id_start = i;
  1267. }
  1268. ++n_undo_tablespaces;
  1269. ++*n_opened;
  1270. }
  1271. /** Explictly specify the srv_undo_space_id_start
  1272. as zero when there are no undo tablespaces. */
  1273. if (n_undo_tablespaces == 0) {
  1274. srv_undo_space_id_start = 0;
  1275. }
  1276. /* If the user says that there are fewer than what we find we
  1277. tolerate that discrepancy but not the inverse. Because there could
  1278. be unused undo tablespaces for future use. */
  1279. if (n_conf_tablespaces > n_undo_tablespaces) {
  1280. ut_print_timestamp(stderr);
  1281. fprintf(stderr,
  1282. " InnoDB: Expected to open %lu undo "
  1283. "tablespaces but was able\n",
  1284. n_conf_tablespaces);
  1285. ut_print_timestamp(stderr);
  1286. fprintf(stderr,
  1287. " InnoDB: to find only %lu undo "
  1288. "tablespaces.\n", n_undo_tablespaces);
  1289. ut_print_timestamp(stderr);
  1290. fprintf(stderr,
  1291. " InnoDB: Set the "
  1292. "innodb_undo_tablespaces parameter to "
  1293. "the\n");
  1294. ut_print_timestamp(stderr);
  1295. fprintf(stderr,
  1296. " InnoDB: correct value and retry. Suggested "
  1297. "value is %lu\n", n_undo_tablespaces);
  1298. return(err != DB_SUCCESS ? err : DB_ERROR);
  1299. } else if (n_undo_tablespaces > 0) {
  1300. ib_logf(IB_LOG_LEVEL_INFO, "Opened %lu undo tablespaces",
  1301. n_undo_tablespaces);
  1302. if (n_conf_tablespaces == 0) {
  1303. ib_logf(IB_LOG_LEVEL_WARN,
  1304. "Using the system tablespace for all UNDO "
  1305. "logging because innodb_undo_tablespaces=0");
  1306. }
  1307. }
  1308. if (create_new_db) {
  1309. mtr_t mtr;
  1310. mtr_start(&mtr);
  1311. /* The undo log tablespace */
  1312. for (i = 0; i < n_undo_tablespaces; ++i) {
  1313. fsp_header_init(
  1314. undo_tablespace_ids[i],
  1315. SRV_UNDO_TABLESPACE_SIZE_IN_PAGES, &mtr);
  1316. }
  1317. mtr_commit(&mtr);
  1318. }
  1319. return(DB_SUCCESS);
  1320. }
  1321. /********************************************************************
  1322. Wait for the purge thread(s) to start up. */
  1323. static
  1324. void
  1325. srv_start_wait_for_purge_to_start()
  1326. /*===============================*/
  1327. {
  1328. /* Wait for the purge coordinator and master thread to startup. */
  1329. purge_state_t state = trx_purge_state();
  1330. ut_a(state != PURGE_STATE_DISABLED);
  1331. while (srv_shutdown_state == SRV_SHUTDOWN_NONE
  1332. && srv_force_recovery < SRV_FORCE_NO_BACKGROUND
  1333. && state == PURGE_STATE_INIT) {
  1334. switch (state = trx_purge_state()) {
  1335. case PURGE_STATE_RUN:
  1336. case PURGE_STATE_STOP:
  1337. break;
  1338. case PURGE_STATE_INIT:
  1339. ib_logf(IB_LOG_LEVEL_INFO,
  1340. "Waiting for purge to start");
  1341. os_thread_sleep(50000);
  1342. break;
  1343. case PURGE_STATE_EXIT:
  1344. case PURGE_STATE_DISABLED:
  1345. ut_error;
  1346. }
  1347. }
  1348. }
  1349. /*********************************************************************//**
  1350. Initializes the log tracking subsystem and starts its thread. */
  1351. static
  1352. void
  1353. init_log_online(void)
  1354. /*=================*/
  1355. {
  1356. if (UNIV_UNLIKELY(srv_force_recovery > 0 || srv_read_only_mode)) {
  1357. srv_track_changed_pages = FALSE;
  1358. return;
  1359. }
  1360. if (srv_track_changed_pages) {
  1361. log_online_read_init();
  1362. /* Create the thread that follows the redo log to output the
  1363. changed page bitmap */
  1364. srv_redo_log_follow_thread_handle = os_thread_create(&srv_redo_log_follow_thread, NULL,
  1365. thread_ids + 5 + SRV_MAX_N_IO_THREADS);
  1366. srv_redo_log_follow_thread_started = true;
  1367. }
  1368. }
  1369. /********************************************************************
  1370. Starts InnoDB and creates a new database if database files
  1371. are not found and the user wants.
  1372. @return DB_SUCCESS or error code */
  1373. UNIV_INTERN
  1374. dberr_t
  1375. innobase_start_or_create_for_mysql()
  1376. {
  1377. bool create_new_db;
  1378. lsn_t flushed_lsn;
  1379. #ifdef UNIV_LOG_ARCHIVE
  1380. lsn_t min_arch_log_no = LSN_MAX;
  1381. lsn_t max_arch_log_no = LSN_MAX;
  1382. #endif /* UNIV_LOG_ARCHIVE */
  1383. ulint sum_of_new_sizes;
  1384. dberr_t err;
  1385. unsigned i;
  1386. ulint srv_n_log_files_found = srv_n_log_files;
  1387. ulint io_limit;
  1388. mtr_t mtr;
  1389. ib_bh_t* ib_bh;
  1390. ulint n_recovered_trx;
  1391. char logfilename[10000];
  1392. char* logfile0 = NULL;
  1393. size_t dirnamelen;
  1394. bool sys_datafiles_created = false;
  1395. /* Check that os_fast_mutexes work as expected */
  1396. os_fast_mutex_init(PFS_NOT_INSTRUMENTED, &srv_os_test_mutex);
  1397. ut_a(0 == os_fast_mutex_trylock(&srv_os_test_mutex));
  1398. os_fast_mutex_unlock(&srv_os_test_mutex);
  1399. os_fast_mutex_lock(&srv_os_test_mutex);
  1400. os_fast_mutex_unlock(&srv_os_test_mutex);
  1401. os_fast_mutex_free(&srv_os_test_mutex);
  1402. /* This should be initialized early */
  1403. ut_init_timer();
  1404. if (srv_force_recovery == SRV_FORCE_NO_LOG_REDO) {
  1405. srv_read_only_mode = 1;
  1406. }
  1407. high_level_read_only = srv_read_only_mode
  1408. || srv_force_recovery > SRV_FORCE_NO_TRX_UNDO;
  1409. if (srv_read_only_mode) {
  1410. ib_logf(IB_LOG_LEVEL_INFO, "Started in read only mode");
  1411. }
  1412. #ifdef HAVE_DARWIN_THREADS
  1413. # ifdef F_FULLFSYNC
  1414. /* This executable has been compiled on Mac OS X 10.3 or later.
  1415. Assume that F_FULLFSYNC is available at run-time. */
  1416. srv_have_fullfsync = TRUE;
  1417. # else /* F_FULLFSYNC */
  1418. /* This executable has been compiled on Mac OS X 10.2
  1419. or earlier. Determine if the executable is running
  1420. on Mac OS X 10.3 or later. */
  1421. struct utsname utsname;
  1422. if (uname(&utsname)) {
  1423. ut_print_timestamp(stderr);
  1424. fputs(" InnoDB: cannot determine Mac OS X version!\n", stderr);
  1425. } else {
  1426. srv_have_fullfsync = strcmp(utsname.release, "7.") >= 0;
  1427. }
  1428. if (!srv_have_fullfsync) {
  1429. ut_print_timestamp(stderr);
  1430. fputs(" InnoDB: On Mac OS X, fsync() may be "
  1431. "broken on internal drives,\n", stderr);
  1432. ut_print_timestamp(stderr);
  1433. fputs(" InnoDB: making transactions unsafe!\n", stderr);
  1434. }
  1435. # endif /* F_FULLFSYNC */
  1436. #endif /* HAVE_DARWIN_THREADS */
  1437. ib_logf(IB_LOG_LEVEL_INFO,
  1438. "Using %s to ref count buffer pool pages",
  1439. #ifdef PAGE_ATOMIC_REF_COUNT
  1440. "atomics"
  1441. #else
  1442. "mutexes"
  1443. #endif /* PAGE_ATOMIC_REF_COUNT */
  1444. );
  1445. compile_time_assert(sizeof(ulint) == sizeof(void*));
  1446. /* If stacktrace is used we set up signal handler for SIGUSR2 signal
  1447. here. If signal handler set fails we report that and disable
  1448. stacktrace feature. */
  1449. if (srv_use_stacktrace) {
  1450. #if defined (__linux__) && HAVE_BACKTRACE && HAVE_BACKTRACE_SYMBOLS
  1451. struct sigaction sigact;
  1452. sigact.sa_sigaction = os_stacktrace_print;
  1453. sigact.sa_flags = SA_RESTART | SA_SIGINFO;
  1454. if (sigaction(SIGUSR2, &sigact, (struct sigaction *)NULL) != 0)
  1455. {
  1456. fprintf(stderr, " InnoDB:error setting signal handler for %d (%s)\n",
  1457. SIGUSR2, strsignal(SIGUSR2));
  1458. srv_use_stacktrace = FALSE;
  1459. }
  1460. #endif /* defined (__linux__) && HAVE_BACKTRACE && HAVE_BACKTRACE_SYMBOLS */
  1461. }
  1462. #ifdef UNIV_DEBUG
  1463. ib_logf(IB_LOG_LEVEL_INFO,
  1464. " InnoDB: !!!!!!!! UNIV_DEBUG switched on !!!!!!!!!");
  1465. #endif
  1466. #ifdef UNIV_IBUF_DEBUG
  1467. ib_logf(IB_LOG_LEVEL_INFO,
  1468. " InnoDB: !!!!!!!! UNIV_IBUF_DEBUG switched on !!!!!!!!!");
  1469. # ifdef UNIV_IBUF_COUNT_DEBUG
  1470. ib_logf(IB_LOG_LEVEL_INFO,
  1471. " InnoDB: !!!!!!!! UNIV_IBUF_COUNT_DEBUG switched on "
  1472. "!!!!!!!!!");
  1473. ib_logf(IB_LOG_LEVEL_INFO,
  1474. " InnoDB: Crash recovery will fail with UNIV_IBUF_COUNT_DEBUG");
  1475. # endif
  1476. #endif
  1477. #ifdef UNIV_BLOB_DEBUG
  1478. ib_logf(IB_LOG_LEVEL_INFO,
  1479. "InnoDB: !!!!!!!! UNIV_BLOB_DEBUG switched on !!!!!!!!!\n"
  1480. "InnoDB: Server restart may fail with UNIV_BLOB_DEBUG");
  1481. #endif /* UNIV_BLOB_DEBUG */
  1482. #ifdef UNIV_SYNC_DEBUG
  1483. ib_logf(IB_LOG_LEVEL_INFO,
  1484. " InnoDB: !!!!!!!! UNIV_SYNC_DEBUG switched on !!!!!!!!!");
  1485. #endif
  1486. #ifdef UNIV_SEARCH_DEBUG
  1487. ib_logf(IB_LOG_LEVEL_INFO,
  1488. " InnoDB: !!!!!!!! UNIV_SEARCH_DEBUG switched on !!!!!!!!!");
  1489. #endif
  1490. #ifdef UNIV_LOG_LSN_DEBUG
  1491. ib_logf(IB_LOG_LEVEL_INFO,
  1492. " InnoDB: !!!!!!!! UNIV_LOG_LSN_DEBUG switched on !!!!!!!!!");
  1493. #endif /* UNIV_LOG_LSN_DEBUG */
  1494. #ifdef UNIV_MEM_DEBUG
  1495. ib_logf(IB_LOG_LEVEL_INFO,
  1496. " InnoDB: !!!!!!!! UNIV_MEM_DEBUG switched on !!!!!!!!!");
  1497. #endif
  1498. if (srv_use_sys_malloc) {
  1499. ib_logf(IB_LOG_LEVEL_INFO,
  1500. "The InnoDB memory heap is disabled");
  1501. }
  1502. #if defined(COMPILER_HINTS_ENABLED)
  1503. ib_logf(IB_LOG_LEVEL_INFO,
  1504. " InnoDB: Compiler hints enabled.");
  1505. #endif /* defined(COMPILER_HINTS_ENABLED) */
  1506. ib_logf(IB_LOG_LEVEL_INFO,
  1507. "" IB_ATOMICS_STARTUP_MSG "");
  1508. ib_logf(IB_LOG_LEVEL_INFO,
  1509. "" IB_MEMORY_BARRIER_STARTUP_MSG "");
  1510. #ifndef HAVE_MEMORY_BARRIER
  1511. #if defined __i386__ || defined __x86_64__ || defined _M_IX86 || defined _M_X64 || defined __WIN__
  1512. #else
  1513. ib_logf(IB_LOG_LEVEL_WARN,
  1514. "MySQL was built without a memory barrier capability on this"
  1515. " architecture, which might allow a mutex/rw_lock violation"
  1516. " under high thread concurrency. This may cause a hang.");
  1517. #endif /* IA32 or AMD64 */
  1518. #endif /* HAVE_MEMORY_BARRIER */
  1519. ib_logf(IB_LOG_LEVEL_INFO,
  1520. "Compressed tables use zlib " ZLIB_VERSION
  1521. #ifdef UNIV_ZIP_DEBUG
  1522. " with validation"
  1523. #endif /* UNIV_ZIP_DEBUG */
  1524. );
  1525. #ifdef UNIV_ZIP_COPY
  1526. ib_logf(IB_LOG_LEVEL_INFO, "and extra copying");
  1527. #endif /* UNIV_ZIP_COPY */
  1528. /* Since InnoDB does not currently clean up all its internal data
  1529. structures in MySQL Embedded Server Library server_end(), we
  1530. print an error message if someone tries to start up InnoDB a
  1531. second time during the process lifetime. */
  1532. if (srv_start_has_been_called) {
  1533. ut_print_timestamp(stderr);
  1534. fprintf(stderr, " InnoDB: Error: startup called second time "
  1535. "during the process\n");
  1536. ut_print_timestamp(stderr);
  1537. fprintf(stderr, " InnoDB: lifetime. In the MySQL Embedded "
  1538. "Server Library you\n");
  1539. ut_print_timestamp(stderr);
  1540. fprintf(stderr, " InnoDB: cannot call server_init() more "
  1541. "than once during the\n");
  1542. ut_print_timestamp(stderr);
  1543. fprintf(stderr, " InnoDB: process lifetime.\n");
  1544. }
  1545. srv_start_has_been_called = TRUE;
  1546. #ifdef UNIV_DEBUG
  1547. log_do_write = TRUE;
  1548. #endif /* UNIV_DEBUG */
  1549. /* yydebug = TRUE; */
  1550. srv_is_being_started = TRUE;
  1551. srv_startup_is_before_trx_rollback_phase = TRUE;
  1552. #ifdef __WIN__
  1553. switch (os_get_os_version()) {
  1554. case OS_WIN95:
  1555. case OS_WIN31:
  1556. case OS_WINNT:
  1557. srv_use_native_conditions = FALSE;
  1558. /* On Win 95, 98, ME, Win32 subsystem for Windows 3.1,
  1559. and NT use simulated aio. In NT Windows provides async i/o,
  1560. but when run in conjunction with InnoDB Hot Backup, it seemed
  1561. to corrupt the data files. */
  1562. srv_use_native_aio = FALSE;
  1563. break;
  1564. case OS_WIN2000:
  1565. case OS_WINXP:
  1566. /* On 2000 and XP, async IO is available, but no condition variables. */
  1567. srv_use_native_aio = TRUE;
  1568. srv_use_native_conditions = FALSE;
  1569. break;
  1570. default:
  1571. /* Vista and later have both async IO and condition variables */
  1572. srv_use_native_aio = TRUE;
  1573. srv_use_native_conditions = TRUE;
  1574. break;
  1575. }
  1576. #elif defined(LINUX_NATIVE_AIO)
  1577. if (srv_use_native_aio) {
  1578. ib_logf(IB_LOG_LEVEL_INFO, "Using Linux native AIO");
  1579. }
  1580. #else
  1581. /* Currently native AIO is supported only on windows and linux
  1582. and that also when the support is compiled in. In all other
  1583. cases, we ignore the setting of innodb_use_native_aio. */
  1584. srv_use_native_aio = FALSE;
  1585. #endif /* __WIN__ */
  1586. if (srv_file_flush_method_str == NULL) {
  1587. /* These are the default options */
  1588. srv_unix_file_flush_method = SRV_UNIX_FSYNC;
  1589. srv_win_file_flush_method = SRV_WIN_IO_UNBUFFERED;
  1590. } else if (0 == ut_strcmp(srv_file_flush_method_str, "fsync")) {
  1591. srv_unix_file_flush_method = SRV_UNIX_FSYNC;
  1592. } else if (0 == ut_strcmp(srv_file_flush_method_str, "O_DSYNC")) {
  1593. srv_unix_file_flush_method = SRV_UNIX_O_DSYNC;
  1594. } else if (0 == ut_strcmp(srv_file_flush_method_str, "O_DIRECT")) {
  1595. srv_unix_file_flush_method = SRV_UNIX_O_DIRECT;
  1596. } else if (0 == ut_strcmp(srv_file_flush_method_str, "ALL_O_DIRECT")) {
  1597. srv_unix_file_flush_method = SRV_UNIX_ALL_O_DIRECT;
  1598. } else if (0 == ut_strcmp(srv_file_flush_method_str, "O_DIRECT_NO_FSYNC")) {
  1599. srv_unix_file_flush_method = SRV_UNIX_O_DIRECT_NO_FSYNC;
  1600. } else if (0 == ut_strcmp(srv_file_flush_method_str, "littlesync")) {
  1601. srv_unix_file_flush_method = SRV_UNIX_LITTLESYNC;
  1602. } else if (0 == ut_strcmp(srv_file_flush_method_str, "nosync")) {
  1603. srv_unix_file_flush_method = SRV_UNIX_NOSYNC;
  1604. #ifdef _WIN32
  1605. } else if (0 == ut_strcmp(srv_file_flush_method_str, "normal")) {
  1606. srv_win_file_flush_method = SRV_WIN_IO_NORMAL;
  1607. srv_use_native_aio = FALSE;
  1608. } else if (0 == ut_strcmp(srv_file_flush_method_str, "unbuffered")) {
  1609. srv_win_file_flush_method = SRV_WIN_IO_UNBUFFERED;
  1610. srv_use_native_aio = FALSE;
  1611. } else if (0 == ut_strcmp(srv_file_flush_method_str,
  1612. "async_unbuffered")) {
  1613. srv_win_file_flush_method = SRV_WIN_IO_UNBUFFERED;
  1614. srv_use_native_aio = TRUE;
  1615. #endif /* __WIN__ */
  1616. } else {
  1617. ib_logf(IB_LOG_LEVEL_ERROR,
  1618. "Unrecognized value %s for innodb_flush_method",
  1619. srv_file_flush_method_str);
  1620. return(DB_ERROR);
  1621. }
  1622. /* Note that the call srv_boot() also changes the values of
  1623. some variables to the units used by InnoDB internally */
  1624. /* Set the maximum number of threads which can wait for a semaphore
  1625. inside InnoDB: this is the 'sync wait array' size, as well as the
  1626. maximum number of threads that can wait in the 'srv_conc array' for
  1627. their time to enter InnoDB. */
  1628. #define BUF_POOL_SIZE_THRESHOLD (1024 * 1024 * 1024)
  1629. srv_max_n_threads = 1 /* io_ibuf_thread */
  1630. + 1 /* io_log_thread */
  1631. + 1 /* lock_wait_timeout_thread */
  1632. + 1 /* srv_error_monitor_thread */
  1633. + 1 /* srv_monitor_thread */
  1634. + 1 /* srv_master_thread */
  1635. + 1 /* srv_redo_log_follow_thread */
  1636. + 1 /* srv_purge_coordinator_thread */
  1637. + 1 /* buf_dump_thread */
  1638. + 1 /* dict_stats_thread */
  1639. + 1 /* fts_optimize_thread */
  1640. + 1 /* recv_writer_thread */
  1641. + 1 /* buf_flush_page_cleaner_thread */
  1642. + 1 /* trx_rollback_or_clean_all_recovered */
  1643. + 128 /* added as margin, for use of
  1644. InnoDB Memcached etc. */
  1645. + max_connections
  1646. + srv_n_read_io_threads
  1647. + srv_n_write_io_threads
  1648. + srv_n_purge_threads
  1649. /* FTS Parallel Sort */
  1650. + fts_sort_pll_degree * FTS_NUM_AUX_INDEX
  1651. * max_connections;
  1652. if (srv_buf_pool_size < BUF_POOL_SIZE_THRESHOLD) {
  1653. /* If buffer pool is less than 1 GB,
  1654. use only one buffer pool instance */
  1655. srv_buf_pool_instances = 1;
  1656. }
  1657. srv_boot();
  1658. if (ut_crc32_sse2_enabled) {
  1659. ib_logf(IB_LOG_LEVEL_INFO, "Using SSE crc32 instructions");
  1660. } else if (ut_crc32_power8_enabled) {
  1661. ib_logf(IB_LOG_LEVEL_INFO, "Using POWER8 crc32 instructions");
  1662. } else {
  1663. ib_logf(IB_LOG_LEVEL_INFO, "Using generic crc32 instructions");
  1664. }
  1665. if (!srv_read_only_mode) {
  1666. mutex_create(srv_monitor_file_mutex_key,
  1667. &srv_monitor_file_mutex, SYNC_NO_ORDER_CHECK);
  1668. if (srv_innodb_status) {
  1669. srv_monitor_file_name = static_cast<char*>(
  1670. mem_alloc(
  1671. strlen(fil_path_to_mysql_datadir)
  1672. + 20 + sizeof "/innodb_status."));
  1673. sprintf(srv_monitor_file_name, "%s/innodb_status.%lu",
  1674. fil_path_to_mysql_datadir,
  1675. os_proc_get_number());
  1676. srv_monitor_file = fopen(srv_monitor_file_name, "w+");
  1677. if (!srv_monitor_file) {
  1678. ib_logf(IB_LOG_LEVEL_ERROR,
  1679. "Unable to create %s: %s",
  1680. srv_monitor_file_name,
  1681. strerror(errno));
  1682. return(DB_ERROR);
  1683. }
  1684. } else {
  1685. srv_monitor_file_name = NULL;
  1686. srv_monitor_file = os_file_create_tmpfile(NULL);
  1687. if (!srv_monitor_file) {
  1688. return(DB_ERROR);
  1689. }
  1690. }
  1691. mutex_create(srv_dict_tmpfile_mutex_key,
  1692. &srv_dict_tmpfile_mutex, SYNC_DICT_OPERATION);
  1693. srv_dict_tmpfile = os_file_create_tmpfile(NULL);
  1694. if (!srv_dict_tmpfile) {
  1695. return(DB_ERROR);
  1696. }
  1697. mutex_create(srv_misc_tmpfile_mutex_key,
  1698. &srv_misc_tmpfile_mutex, SYNC_ANY_LATCH);
  1699. srv_misc_tmpfile = os_file_create_tmpfile(NULL);
  1700. if (!srv_misc_tmpfile) {
  1701. return(DB_ERROR);
  1702. }
  1703. }
  1704. /* If user has set the value of innodb_file_io_threads then
  1705. we'll emit a message telling the user that this parameter
  1706. is now deprecated. */
  1707. if (srv_n_file_io_threads != 4) {
  1708. ib_logf(IB_LOG_LEVEL_WARN,
  1709. "innodb_file_io_threads is deprecated. Please use "
  1710. "innodb_read_io_threads and innodb_write_io_threads "
  1711. "instead");
  1712. }
  1713. /* Now overwrite the value on srv_n_file_io_threads */
  1714. srv_n_file_io_threads = srv_n_read_io_threads;
  1715. if (!srv_read_only_mode) {
  1716. /* Add the log and ibuf IO threads. */
  1717. srv_n_file_io_threads += 2;
  1718. srv_n_file_io_threads += srv_n_write_io_threads;
  1719. } else {
  1720. ib_logf(IB_LOG_LEVEL_INFO,
  1721. "Disabling background IO write threads.");
  1722. srv_n_write_io_threads = 0;
  1723. }
  1724. ut_a(srv_n_file_io_threads <= SRV_MAX_N_IO_THREADS);
  1725. io_limit = 8 * SRV_N_PENDING_IOS_PER_THREAD;
  1726. /* On Windows when using native aio the number of aio requests
  1727. that a thread can handle at a given time is limited to 32
  1728. i.e.: SRV_N_PENDING_IOS_PER_THREAD */
  1729. # ifdef __WIN__
  1730. if (srv_use_native_aio) {
  1731. io_limit = SRV_N_PENDING_IOS_PER_THREAD;
  1732. }
  1733. # endif /* __WIN__ */
  1734. if (!os_aio_init(io_limit,
  1735. srv_n_read_io_threads,
  1736. srv_n_write_io_threads,
  1737. SRV_MAX_N_PENDING_SYNC_IOS)) {
  1738. ib_logf(IB_LOG_LEVEL_ERROR,
  1739. "Fatal : Cannot initialize AIO sub-system");
  1740. #if defined(LINUX_NATIVE_AIO)
  1741. ib_logf(IB_LOG_LEVEL_INFO,
  1742. "You can try increasing system fs.aio-max-nr to 1048576 "
  1743. "or larger or setting innodb_use_native_aio = 0 in my.cnf");
  1744. #endif
  1745. return(DB_ERROR);
  1746. }
  1747. fil_init(srv_file_per_table ? 50000 : 5000, srv_max_n_open_files);
  1748. double size;
  1749. char unit;
  1750. if (srv_buf_pool_size >= 1024 * 1024 * 1024) {
  1751. size = ((double) srv_buf_pool_size) / (1024 * 1024 * 1024);
  1752. unit = 'G';
  1753. } else {
  1754. size = ((double) srv_buf_pool_size) / (1024 * 1024);
  1755. unit = 'M';
  1756. }
  1757. /* Print time to initialize the buffer pool */
  1758. ib_logf(IB_LOG_LEVEL_INFO,
  1759. "Initializing buffer pool, size = %.1f%c", size, unit);
  1760. err = buf_pool_init(srv_buf_pool_size, srv_buf_pool_instances);
  1761. if (err != DB_SUCCESS) {
  1762. ib_logf(IB_LOG_LEVEL_ERROR,
  1763. "Cannot allocate memory for the buffer pool");
  1764. return(DB_ERROR);
  1765. }
  1766. ib_logf(IB_LOG_LEVEL_INFO,
  1767. "Completed initialization of buffer pool");
  1768. #ifdef UNIV_DEBUG
  1769. /* We have observed deadlocks with a 5MB buffer pool but
  1770. the actual lower limit could very well be a little higher. */
  1771. if (srv_buf_pool_size <= 5 * 1024 * 1024) {
  1772. ib_logf(IB_LOG_LEVEL_INFO,
  1773. "Small buffer pool size (%luM), the flst_validate() "
  1774. "debug function can cause a deadlock if the "
  1775. "buffer pool fills up.",
  1776. srv_buf_pool_size / 1024 / 1024);
  1777. }
  1778. #endif /* UNIV_DEBUG */
  1779. fsp_init();
  1780. log_init();
  1781. log_online_init();
  1782. lock_sys_create(srv_lock_table_size);
  1783. /* Create i/o-handler threads: */
  1784. for (i = 0; i < srv_n_file_io_threads; ++i) {
  1785. n[i] = i;
  1786. thread_handles[i] = os_thread_create(io_handler_thread, n + i, thread_ids + i);
  1787. thread_started[i] = true;
  1788. }
  1789. if (srv_n_log_files * srv_log_file_size * UNIV_PAGE_SIZE
  1790. >= 512ULL * 1024ULL * 1024ULL * 1024ULL) {
  1791. /* log_block_convert_lsn_to_no() limits the returned block
  1792. number to 1G and given that OS_FILE_LOG_BLOCK_SIZE is 512
  1793. bytes, then we have a limit of 512 GB. If that limit is to
  1794. be raised, then log_block_convert_lsn_to_no() must be
  1795. modified. */
  1796. ib_logf(IB_LOG_LEVEL_ERROR,
  1797. "Combined size of log files must be < 512 GB");
  1798. return(DB_ERROR);
  1799. }
  1800. if (srv_n_log_files * srv_log_file_size >= ULINT_MAX) {
  1801. /* fil_io() takes ulint as an argument and we are passing
  1802. (next_offset / UNIV_PAGE_SIZE) to it in log_group_write_buf().
  1803. So (next_offset / UNIV_PAGE_SIZE) must be less than ULINT_MAX.
  1804. So next_offset must be < ULINT_MAX * UNIV_PAGE_SIZE. This
  1805. means that we are limited to ULINT_MAX * UNIV_PAGE_SIZE which
  1806. is 64 TB on 32 bit systems. */
  1807. fprintf(stderr,
  1808. " InnoDB: Error: combined size of log files"
  1809. " must be < %lu GB\n",
  1810. ULINT_MAX / 1073741824 * UNIV_PAGE_SIZE);
  1811. return(DB_ERROR);
  1812. }
  1813. sum_of_new_sizes = 0;
  1814. for (i = 0; i < srv_n_data_files; i++) {
  1815. #ifndef __WIN__
  1816. if (sizeof(off_t) < 5
  1817. && srv_data_file_sizes[i]
  1818. >= (ulint) (1 << (32 - UNIV_PAGE_SIZE_SHIFT))) {
  1819. ut_print_timestamp(stderr);
  1820. fprintf(stderr,
  1821. " InnoDB: Error: file size must be < 4 GB"
  1822. " with this MySQL binary\n");
  1823. ut_print_timestamp(stderr);
  1824. fprintf(stderr,
  1825. " InnoDB: and operating system combination,"
  1826. " in some OS's < 2 GB\n");
  1827. return(DB_ERROR);
  1828. }
  1829. #endif
  1830. sum_of_new_sizes += srv_data_file_sizes[i];
  1831. }
  1832. if (!srv_auto_extend_last_data_file && sum_of_new_sizes < 640) {
  1833. ib_logf(IB_LOG_LEVEL_ERROR,
  1834. "Combined size in innodb_data_file_path"
  1835. " must be at least %u MiB",
  1836. 640 >> (20 - UNIV_PAGE_SIZE_SHIFT));
  1837. return(DB_ERROR);
  1838. }
  1839. recv_sys_create();
  1840. recv_sys_init(buf_pool_get_curr_size());
  1841. err = open_or_create_data_files(&create_new_db,
  1842. #ifdef UNIV_LOG_ARCHIVE
  1843. &min_arch_log_no, &max_arch_log_no,
  1844. #endif /* UNIV_LOG_ARCHIVE */
  1845. &flushed_lsn,
  1846. &sum_of_new_sizes);
  1847. if (err == DB_FAIL) {
  1848. ib_logf(IB_LOG_LEVEL_ERROR,
  1849. "The system tablespace must be writable!");
  1850. return(DB_ERROR);
  1851. } else if (err != DB_SUCCESS) {
  1852. ib_logf(IB_LOG_LEVEL_ERROR,
  1853. "Could not open or create the system tablespace. If "
  1854. "you tried to add new data files to the system "
  1855. "tablespace, and it failed here, you should now "
  1856. "edit innodb_data_file_path in my.cnf back to what "
  1857. "it was, and remove the new ibdata files InnoDB "
  1858. "created in this failed attempt. InnoDB only wrote "
  1859. "those files full of zeros, but did not yet use "
  1860. "them in any way. But be careful: do not remove "
  1861. "old data files which contain your precious data!");
  1862. return(err);
  1863. }
  1864. #ifdef UNIV_LOG_ARCHIVE
  1865. srv_normalize_path_for_win(srv_arch_dir);
  1866. #endif /* UNIV_LOG_ARCHIVE */
  1867. dirnamelen = strlen(srv_log_group_home_dir);
  1868. ut_a(dirnamelen < (sizeof logfilename) - 10 - sizeof "ib_logfile");
  1869. memcpy(logfilename, srv_log_group_home_dir, dirnamelen);
  1870. /* Add a path separator if needed. */
  1871. if (dirnamelen && logfilename[dirnamelen - 1] != SRV_PATH_SEPARATOR) {
  1872. logfilename[dirnamelen++] = SRV_PATH_SEPARATOR;
  1873. }
  1874. srv_log_file_size_requested = srv_log_file_size;
  1875. if (create_new_db) {
  1876. bool success = buf_flush_list(ULINT_MAX, LSN_MAX, NULL);
  1877. ut_a(success);
  1878. flushed_lsn = log_get_lsn();
  1879. buf_flush_wait_batch_end(NULL, BUF_FLUSH_LIST);
  1880. err = create_log_files(create_new_db, logfilename, dirnamelen,
  1881. flushed_lsn, logfile0);
  1882. if (err != DB_SUCCESS) {
  1883. return(err);
  1884. }
  1885. } else {
  1886. ut_d(fil_space_get(0)->recv_size = srv_sys_space_size_debug);
  1887. for (i = 0; i < SRV_N_LOG_FILES_MAX; i++) {
  1888. os_offset_t size;
  1889. os_file_stat_t stat_info;
  1890. sprintf(logfilename + dirnamelen,
  1891. "ib_logfile%u", i);
  1892. err = os_file_get_status(
  1893. logfilename, &stat_info, false);
  1894. if (err == DB_NOT_FOUND) {
  1895. if (i == 0) {
  1896. if (flushed_lsn < (lsn_t) 1000) {
  1897. ib_logf(IB_LOG_LEVEL_ERROR,
  1898. "Cannot create"
  1899. " log files because"
  1900. " data files are"
  1901. " corrupt or the"
  1902. " database was not"
  1903. " shut down cleanly"
  1904. " after creating"
  1905. " the data files.");
  1906. return(DB_ERROR);
  1907. }
  1908. err = create_log_files(
  1909. create_new_db, logfilename,
  1910. dirnamelen, flushed_lsn,
  1911. logfile0);
  1912. if (err == DB_SUCCESS) {
  1913. err = create_log_files_rename(
  1914. logfilename,
  1915. dirnamelen,
  1916. flushed_lsn,
  1917. logfile0);
  1918. }
  1919. if (err != DB_SUCCESS) {
  1920. return(err);
  1921. }
  1922. /* Suppress the message about
  1923. crash recovery. */
  1924. flushed_lsn = log_get_lsn();
  1925. goto files_checked;
  1926. } else if (i < 2 && !IS_XTRABACKUP()) {
  1927. /* must have at least 2 log files */
  1928. ib_logf(IB_LOG_LEVEL_ERROR,
  1929. "Only one log file found.");
  1930. return(err);
  1931. }
  1932. /* opened all files */
  1933. break;
  1934. }
  1935. if (!srv_file_check_mode(logfilename)) {
  1936. return(DB_ERROR);
  1937. }
  1938. err = open_log_file(&files[i], logfilename, &size);
  1939. if (err != DB_SUCCESS) {
  1940. return(err);
  1941. }
  1942. ut_a(size != (os_offset_t) -1);
  1943. if (size & ((1 << UNIV_PAGE_SIZE_SHIFT) - 1)) {
  1944. ib_logf(IB_LOG_LEVEL_ERROR,
  1945. "Log file %s size "
  1946. UINT64PF " is not a multiple of"
  1947. " innodb_page_size",
  1948. logfilename, size);
  1949. return(DB_ERROR);
  1950. }
  1951. size >>= UNIV_PAGE_SIZE_SHIFT;
  1952. if (i == 0) {
  1953. srv_log_file_size = size;
  1954. } else if (size != srv_log_file_size) {
  1955. ib_logf(IB_LOG_LEVEL_ERROR,
  1956. "Log file %s is"
  1957. " of different size " UINT64PF " bytes"
  1958. " than other log"
  1959. " files " UINT64PF " bytes!",
  1960. logfilename,
  1961. size << UNIV_PAGE_SIZE_SHIFT,
  1962. (os_offset_t) srv_log_file_size
  1963. << UNIV_PAGE_SIZE_SHIFT);
  1964. return(DB_ERROR);
  1965. }
  1966. }
  1967. srv_n_log_files_found = i;
  1968. /* Create the in-memory file space objects. */
  1969. sprintf(logfilename + dirnamelen, "ib_logfile%u", 0);
  1970. fil_space_create(logfilename,
  1971. SRV_LOG_SPACE_FIRST_ID, 0, FIL_LOG,
  1972. NULL /* no encryption yet */,
  1973. true /* create */);
  1974. ut_a(fil_validate());
  1975. /* srv_log_file_size is measured in pages; if page size is 16KB,
  1976. then we have a limit of 64TB on 32 bit systems */
  1977. ut_a(srv_log_file_size <= ULINT_MAX);
  1978. for (unsigned j = 0; j < i; j++) {
  1979. sprintf(logfilename + dirnamelen, "ib_logfile%u", j);
  1980. if (!fil_node_create(logfilename,
  1981. (ulint) srv_log_file_size,
  1982. SRV_LOG_SPACE_FIRST_ID, FALSE)) {
  1983. return(DB_ERROR);
  1984. }
  1985. }
  1986. #ifdef UNIV_LOG_ARCHIVE
  1987. /* Create the file space object for archived logs. Under
  1988. MySQL, no archiving ever done. */
  1989. fil_space_create("arch_log_space", SRV_LOG_SPACE_FIRST_ID + 1,
  1990. 0, FIL_LOG, NULL /* no encryption yet */,
  1991. true /* create */);
  1992. #endif /* UNIV_LOG_ARCHIVE */
  1993. log_group_init(0, i, srv_log_file_size * UNIV_PAGE_SIZE,
  1994. SRV_LOG_SPACE_FIRST_ID,
  1995. SRV_LOG_SPACE_FIRST_ID + 1);
  1996. }
  1997. files_checked:
  1998. /* Open all log files and data files in the system
  1999. tablespace: we keep them open until database
  2000. shutdown */
  2001. fil_open_log_and_system_tablespace_files();
  2002. err = srv_undo_tablespaces_init(
  2003. create_new_db,
  2004. FALSE,
  2005. srv_undo_tablespaces,
  2006. &srv_undo_tablespaces_open);
  2007. /* If the force recovery is set very high then we carry on regardless
  2008. of all errors. Basically this is fingers crossed mode. */
  2009. if (err != DB_SUCCESS
  2010. && srv_force_recovery < SRV_FORCE_NO_UNDO_LOG_SCAN) {
  2011. return(err);
  2012. }
  2013. /* Initialize objects used by dict stats gathering thread, which
  2014. can also be used by recovery if it tries to drop some table */
  2015. if (!srv_read_only_mode) {
  2016. dict_stats_thread_init();
  2017. }
  2018. trx_sys_file_format_init();
  2019. trx_sys_create();
  2020. if (create_new_db) {
  2021. ut_a(!srv_read_only_mode);
  2022. init_log_online();
  2023. mtr_start(&mtr);
  2024. fsp_header_init(0, sum_of_new_sizes, &mtr);
  2025. compile_time_assert(TRX_SYS_SPACE == 0);
  2026. compile_time_assert(IBUF_SPACE_ID == 0);
  2027. ulint ibuf_root = btr_create(
  2028. DICT_CLUSTERED | DICT_UNIVERSAL | DICT_IBUF,
  2029. 0, 0, DICT_IBUF_ID_MIN,
  2030. dict_ind_redundant, &mtr);
  2031. mtr_commit(&mtr);
  2032. if (ibuf_root == FIL_NULL) {
  2033. return(srv_init_abort(true, __FILE__, __LINE__,
  2034. DB_ERROR));
  2035. }
  2036. ut_ad(ibuf_root == IBUF_TREE_ROOT_PAGE_NO);
  2037. /* To maintain backward compatibility we create only
  2038. the first rollback segment before the double write buffer.
  2039. All the remaining rollback segments will be created later,
  2040. after the double write buffer has been created. */
  2041. trx_sys_create_sys_pages();
  2042. ib_bh = trx_sys_init_at_db_start();
  2043. n_recovered_trx = UT_LIST_GET_LEN(trx_sys->rw_trx_list);
  2044. /* The purge system needs to create the purge view and
  2045. therefore requires that the trx_sys is inited. */
  2046. trx_purge_sys_create(srv_n_purge_threads, ib_bh);
  2047. err = dict_create();
  2048. if (err != DB_SUCCESS) {
  2049. return(err);
  2050. }
  2051. srv_startup_is_before_trx_rollback_phase = FALSE;
  2052. bool success = buf_flush_list(ULINT_MAX, LSN_MAX, NULL);
  2053. ut_a(success);
  2054. flushed_lsn = log_get_lsn();
  2055. buf_flush_wait_batch_end(NULL, BUF_FLUSH_LIST);
  2056. /* Stamp the LSN to the data files. */
  2057. err = fil_write_flushed_lsn(flushed_lsn);
  2058. if (err != DB_SUCCESS) {
  2059. return(err);
  2060. }
  2061. err = create_log_files_rename(logfilename, dirnamelen,
  2062. flushed_lsn, logfile0);
  2063. if (err != DB_SUCCESS) {
  2064. return(err);
  2065. }
  2066. } else {
  2067. /* Check if we support the max format that is stamped
  2068. on the system tablespace.
  2069. Note: We are NOT allowed to make any modifications to
  2070. the TRX_SYS_PAGE_NO page before recovery because this
  2071. page also contains the max_trx_id etc. important system
  2072. variables that are required for recovery. We need to
  2073. ensure that we return the system to a state where normal
  2074. recovery is guaranteed to work. We do this by
  2075. invalidating the buffer cache, this will force the
  2076. reread of the page and restoration to its last known
  2077. consistent state, this is REQUIRED for the recovery
  2078. process to work. */
  2079. err = trx_sys_file_format_max_check(
  2080. srv_max_file_format_at_startup);
  2081. if (err != DB_SUCCESS) {
  2082. return(err);
  2083. }
  2084. /* Invalidate the buffer pool to ensure that we reread
  2085. the page that we read above, during recovery.
  2086. Note that this is not as heavy weight as it seems. At
  2087. this point there will be only ONE page in the buf_LRU
  2088. and there must be no page in the buf_flush list. */
  2089. buf_pool_invalidate();
  2090. /* Start monitor thread early enough so that e.g. crash
  2091. recovery failing to find free pages in the buffer pool is
  2092. diagnosed. */
  2093. if (!srv_read_only_mode)
  2094. {
  2095. /* Create the thread which prints InnoDB monitor
  2096. info */
  2097. srv_monitor_active = true;
  2098. thread_handles[4 + SRV_MAX_N_IO_THREADS] =
  2099. os_thread_create(
  2100. srv_monitor_thread,
  2101. NULL,
  2102. thread_ids + 4 + SRV_MAX_N_IO_THREADS);
  2103. thread_started[4 + SRV_MAX_N_IO_THREADS] = true;
  2104. }
  2105. /* We always try to do a recovery, even if the database had
  2106. been shut down normally: this is the normal startup path */
  2107. err = recv_recovery_from_checkpoint_start(
  2108. LOG_CHECKPOINT, LSN_MAX,
  2109. flushed_lsn);
  2110. if (err != DB_SUCCESS) {
  2111. return(err);
  2112. }
  2113. init_log_online();
  2114. /* Initialize the change buffer. */
  2115. err = dict_boot();
  2116. if (err != DB_SUCCESS) {
  2117. return(err);
  2118. }
  2119. /* This must precede recv_apply_hashed_log_recs(true). */
  2120. ib_bh = trx_sys_init_at_db_start();
  2121. if (srv_force_recovery < SRV_FORCE_NO_LOG_REDO) {
  2122. /* Apply the hashed log records to the
  2123. respective file pages, for the last batch of
  2124. recv_group_scan_log_recs(). */
  2125. recv_apply_hashed_log_recs(true);
  2126. if (recv_sys->found_corrupt_log) {
  2127. return (DB_CORRUPTION);
  2128. }
  2129. DBUG_PRINT("ib_log", ("apply completed"));
  2130. }
  2131. if (!srv_read_only_mode) {
  2132. const ulint flags = FSP_FLAGS_PAGE_SSIZE();
  2133. for (ulint id = 0; id <= srv_undo_tablespaces; id++) {
  2134. if (fil_space_get(id)) {
  2135. fsp_flags_try_adjust(id, flags);
  2136. }
  2137. }
  2138. if (sum_of_new_sizes > 0) {
  2139. /* New data file(s) were added */
  2140. mtr_start(&mtr);
  2141. fsp_header_inc_size(0, sum_of_new_sizes, &mtr);
  2142. mtr_commit(&mtr);
  2143. /* Immediately write the log record about
  2144. increased tablespace size to disk, so that it
  2145. is durable even if mysqld would crash
  2146. quickly */
  2147. log_buffer_flush_to_disk();
  2148. }
  2149. }
  2150. const ulint tablespace_size_in_header
  2151. = fsp_header_get_tablespace_size();
  2152. #ifdef UNIV_DEBUG
  2153. /* buf_debug_prints = TRUE; */
  2154. #endif /* UNIV_DEBUG */
  2155. ulint sum_of_data_file_sizes = 0;
  2156. for (ulint d = 0; d < srv_n_data_files; d++) {
  2157. sum_of_data_file_sizes += srv_data_file_sizes[d];
  2158. }
  2159. /* Compare the system tablespace file size to what is
  2160. stored in FSP_SIZE. In open_or_create_data_files()
  2161. we already checked that the file sizes match the
  2162. innodb_data_file_path specification. */
  2163. if (srv_read_only_mode
  2164. || sum_of_data_file_sizes == tablespace_size_in_header) {
  2165. /* Do not complain about the size. */
  2166. } else if (!srv_auto_extend_last_data_file
  2167. || sum_of_data_file_sizes
  2168. < tablespace_size_in_header) {
  2169. ib_logf(IB_LOG_LEVEL_ERROR,
  2170. "Tablespace size stored in header is " ULINTPF
  2171. " pages, but the sum of data file sizes is "
  2172. ULINTPF " pages",
  2173. tablespace_size_in_header,
  2174. sum_of_data_file_sizes);
  2175. if (srv_force_recovery == 0
  2176. && sum_of_data_file_sizes
  2177. < tablespace_size_in_header) {
  2178. ib_logf(IB_LOG_LEVEL_ERROR,
  2179. "Cannot start InnoDB. The tail of"
  2180. " the system tablespace is"
  2181. " missing. Have you edited"
  2182. " innodb_data_file_path in my.cnf"
  2183. " in an inappropriate way, removing"
  2184. " data files from there?"
  2185. " You can set innodb_force_recovery=1"
  2186. " in my.cnf to force"
  2187. " a startup if you are trying to"
  2188. " recover a badly corrupt database.");
  2189. return(DB_ERROR);
  2190. }
  2191. }
  2192. n_recovered_trx = UT_LIST_GET_LEN(trx_sys->rw_trx_list);
  2193. /* The purge system needs to create the purge view and
  2194. therefore requires that the trx_sys is inited. */
  2195. trx_purge_sys_create(srv_n_purge_threads, ib_bh);
  2196. /* recv_recovery_from_checkpoint_finish needs trx lists which
  2197. are initialized in trx_sys_init_at_db_start(). */
  2198. recv_recovery_from_checkpoint_finish();
  2199. if (srv_apply_log_only) {
  2200. ut_ad(IS_XTRABACKUP());
  2201. goto skip_processes;
  2202. }
  2203. if (srv_force_recovery < SRV_FORCE_NO_IBUF_MERGE) {
  2204. /* The following call is necessary for the insert
  2205. buffer to work with multiple tablespaces. We must
  2206. know the mapping between space id's and .ibd file
  2207. names.
  2208. In a crash recovery, we check that the info in data
  2209. dictionary is consistent with what we already know
  2210. about space id's from the call of
  2211. fil_load_single_table_tablespaces().
  2212. In a normal startup, we create the space objects for
  2213. every table in the InnoDB data dictionary that has
  2214. an .ibd file.
  2215. We also determine the maximum tablespace id used. */
  2216. dict_check_t dict_check;
  2217. if (recv_needed_recovery) {
  2218. dict_check = DICT_CHECK_ALL_LOADED;
  2219. } else if (n_recovered_trx) {
  2220. dict_check = DICT_CHECK_SOME_LOADED;
  2221. } else {
  2222. dict_check = DICT_CHECK_NONE_LOADED;
  2223. }
  2224. /* Create the SYS_TABLESPACES and SYS_DATAFILES system table */
  2225. err = dict_create_or_check_sys_tablespace();
  2226. if (err != DB_SUCCESS) {
  2227. return(err);
  2228. }
  2229. sys_datafiles_created = true;
  2230. /* This function assumes that SYS_DATAFILES exists */
  2231. dict_check_tablespaces_and_store_max_id(dict_check);
  2232. }
  2233. if (IS_XTRABACKUP()
  2234. && !srv_backup_mode
  2235. && srv_read_only_mode
  2236. && srv_log_file_size_requested != srv_log_file_size) {
  2237. ib_logf(IB_LOG_LEVEL_WARN,
  2238. "Log files size mismatch, ignored in readonly mode");
  2239. srv_log_file_size_requested = srv_log_file_size;
  2240. }
  2241. if (!srv_force_recovery
  2242. && !recv_sys->found_corrupt_log
  2243. && (srv_log_file_size_requested != srv_log_file_size
  2244. || srv_n_log_files_found != srv_n_log_files)) {
  2245. /* Prepare to replace the redo log files. */
  2246. if (srv_read_only_mode) {
  2247. ib_logf(IB_LOG_LEVEL_ERROR,
  2248. "Cannot resize log files "
  2249. "in read-only mode.");
  2250. return(DB_READ_ONLY);
  2251. }
  2252. /* Clean the buffer pool. */
  2253. bool success = buf_flush_list(
  2254. ULINT_MAX, LSN_MAX, NULL);
  2255. ut_a(success);
  2256. DBUG_EXECUTE_IF("innodb_log_abort_1",
  2257. return(DB_ERROR););
  2258. flushed_lsn = log_get_lsn();
  2259. ib_logf(IB_LOG_LEVEL_WARN,
  2260. "Resizing redo log from %u*%u to %u*%u pages"
  2261. ", LSN=" LSN_PF,
  2262. (unsigned) i,
  2263. (unsigned) srv_log_file_size,
  2264. (unsigned) srv_n_log_files,
  2265. (unsigned) srv_log_file_size_requested,
  2266. flushed_lsn);
  2267. buf_flush_wait_batch_end(NULL, BUF_FLUSH_LIST);
  2268. /* Flush the old log files. */
  2269. log_buffer_flush_to_disk();
  2270. /* If innodb_flush_method=O_DSYNC,
  2271. we need to explicitly flush the log buffers. */
  2272. fil_flush(SRV_LOG_SPACE_FIRST_ID);
  2273. ut_ad(flushed_lsn == log_get_lsn());
  2274. /* Prohibit redo log writes from any other
  2275. threads until creating a log checkpoint at the
  2276. end of create_log_files(). */
  2277. ut_d(recv_no_log_write = TRUE);
  2278. ut_ad(!buf_pool_check_no_pending_io());
  2279. DBUG_EXECUTE_IF("innodb_log_abort_3",
  2280. return(DB_ERROR););
  2281. /* Stamp the LSN to the data files. */
  2282. err = fil_write_flushed_lsn(flushed_lsn);
  2283. DBUG_EXECUTE_IF("innodb_log_abort_4", err = DB_ERROR;);
  2284. if (err != DB_SUCCESS) {
  2285. return(err);
  2286. }
  2287. /* Close and free the redo log files, so that
  2288. we can replace them. */
  2289. fil_close_log_files(true);
  2290. DBUG_EXECUTE_IF("innodb_log_abort_5",
  2291. return(DB_ERROR););
  2292. /* Free the old log file space. */
  2293. log_group_close_all();
  2294. ib_logf(IB_LOG_LEVEL_WARN,
  2295. "Starting to delete and rewrite log files.");
  2296. srv_log_file_size = srv_log_file_size_requested;
  2297. err = create_log_files(create_new_db, logfilename,
  2298. dirnamelen, flushed_lsn,
  2299. logfile0);
  2300. if (err != DB_SUCCESS) {
  2301. return(err);
  2302. }
  2303. err = create_log_files_rename(logfilename, dirnamelen,
  2304. log_get_lsn(), logfile0);
  2305. if (err != DB_SUCCESS) {
  2306. return(err);
  2307. }
  2308. }
  2309. recv_recovery_rollback_active();
  2310. srv_startup_is_before_trx_rollback_phase = FALSE;
  2311. /* It is possible that file_format tag has never
  2312. been set. In this case we initialize it to minimum
  2313. value. Important to note that we can do it ONLY after
  2314. we have finished the recovery process so that the
  2315. image of TRX_SYS_PAGE_NO is not stale. */
  2316. trx_sys_file_format_tag_init();
  2317. }
  2318. ut_ad(err == DB_SUCCESS);
  2319. ut_a(sum_of_new_sizes != ULINT_UNDEFINED);
  2320. #ifdef UNIV_LOG_ARCHIVE
  2321. if (!srv_read_only_mode) {
  2322. if (!srv_log_archive_on) {
  2323. ut_a(DB_SUCCESS == log_archive_noarchivelog());
  2324. } else {
  2325. bool start_archive;
  2326. mutex_enter(&(log_sys->mutex));
  2327. start_archive = false;
  2328. if (log_sys->archiving_state == LOG_ARCH_OFF) {
  2329. start_archive = true;
  2330. }
  2331. mutex_exit(&(log_sys->mutex));
  2332. if (start_archive) {
  2333. ut_a(DB_SUCCESS == log_archive_archivelog());
  2334. }
  2335. }
  2336. }
  2337. #endif /* UNIV_LOG_ARCHIVE */
  2338. /* fprintf(stderr, "Max allowed record size %lu\n",
  2339. page_get_free_space_of_empty() / 2); */
  2340. if (!buf_dblwr_create()) {
  2341. return(srv_init_abort(create_new_db, __FILE__, __LINE__,
  2342. DB_ERROR));
  2343. }
  2344. /* Here the double write buffer has already been created and so
  2345. any new rollback segments will be allocated after the double
  2346. write buffer. The default segment should already exist.
  2347. We create the new segments only if it's a new database or
  2348. the database was shutdown cleanly. */
  2349. /* Note: When creating the extra rollback segments during an upgrade
  2350. we violate the latching order, even if the change buffer is empty.
  2351. We make an exception in sync0sync.cc and check srv_is_being_started
  2352. for that violation. It cannot create a deadlock because we are still
  2353. running in single threaded mode essentially. Only the IO threads
  2354. should be running at this stage. */
  2355. ut_a(srv_undo_logs > 0);
  2356. ut_a(srv_undo_logs <= TRX_SYS_N_RSEGS);
  2357. /* The number of rsegs that exist in InnoDB is given by status
  2358. variable srv_available_undo_logs. The number of rsegs to use can
  2359. be set using the dynamic global variable srv_undo_logs. */
  2360. srv_available_undo_logs = trx_sys_create_rsegs(
  2361. srv_undo_tablespaces, srv_undo_logs);
  2362. if (srv_available_undo_logs == ULINT_UNDEFINED) {
  2363. /* Can only happen if server is read only. */
  2364. ut_a(srv_read_only_mode);
  2365. srv_undo_logs = ULONG_UNDEFINED;
  2366. } else if (srv_available_undo_logs < srv_undo_logs) {
  2367. /* Should due to out of file space. */
  2368. return (srv_init_abort(create_new_db, __FILE__, __LINE__, DB_ERROR));
  2369. }
  2370. if (!srv_read_only_mode) {
  2371. /* Create the thread which watches the timeouts
  2372. for lock waits */
  2373. thread_handles[2 + SRV_MAX_N_IO_THREADS] = os_thread_create(
  2374. lock_wait_timeout_thread,
  2375. NULL, thread_ids + 2 + SRV_MAX_N_IO_THREADS);
  2376. thread_started[2 + SRV_MAX_N_IO_THREADS] = true;
  2377. lock_sys->timeout_thread_active = true;
  2378. /* Create the thread which warns of long semaphore waits */
  2379. srv_error_monitor_active = true;
  2380. thread_handles[3 + SRV_MAX_N_IO_THREADS] = os_thread_create(
  2381. srv_error_monitor_thread,
  2382. NULL, thread_ids + 3 + SRV_MAX_N_IO_THREADS);
  2383. thread_started[3 + SRV_MAX_N_IO_THREADS] = true;
  2384. /* Create the thread which prints InnoDB monitor info */
  2385. if (!thread_started[4 + SRV_MAX_N_IO_THREADS]) {
  2386. /* srv_monitor_thread not yet started */
  2387. srv_monitor_active = true;
  2388. thread_handles[4 + SRV_MAX_N_IO_THREADS] = os_thread_create(
  2389. srv_monitor_thread,
  2390. NULL, thread_ids + 4 + SRV_MAX_N_IO_THREADS);
  2391. thread_started[4 + SRV_MAX_N_IO_THREADS] = true;
  2392. }
  2393. }
  2394. /* Create the SYS_FOREIGN and SYS_FOREIGN_COLS system tables */
  2395. err = dict_create_or_check_foreign_constraint_tables();
  2396. if (err != DB_SUCCESS) {
  2397. return(err);
  2398. }
  2399. /* Create the SYS_TABLESPACES and SYS_DATAFILES system tables if we
  2400. have not done that already on crash recovery. */
  2401. if (sys_datafiles_created == false) {
  2402. err = dict_create_or_check_sys_tablespace();
  2403. if (err != DB_SUCCESS) {
  2404. return(err);
  2405. }
  2406. }
  2407. srv_is_being_started = FALSE;
  2408. ut_a(trx_purge_state() == PURGE_STATE_INIT);
  2409. /* Create the master thread which does purge and other utility
  2410. operations */
  2411. if (!srv_read_only_mode) {
  2412. thread_handles[1 + SRV_MAX_N_IO_THREADS] = os_thread_create(
  2413. srv_master_thread,
  2414. NULL, thread_ids + (1 + SRV_MAX_N_IO_THREADS));
  2415. thread_started[1 + SRV_MAX_N_IO_THREADS] = true;
  2416. srv_undo_sources = true;
  2417. /* Create the dict stats gathering thread */
  2418. srv_dict_stats_thread_active = true;
  2419. dict_stats_thread_handle = os_thread_create(
  2420. dict_stats_thread, NULL, NULL);
  2421. dict_stats_thread_started = true;
  2422. /* Create the thread that will optimize the FTS sub-system. */
  2423. fts_optimize_init();
  2424. }
  2425. if (!srv_read_only_mode
  2426. && srv_force_recovery < SRV_FORCE_NO_BACKGROUND) {
  2427. thread_handles[6 + SRV_MAX_N_IO_THREADS] = os_thread_create(
  2428. srv_purge_coordinator_thread,
  2429. NULL, thread_ids + 6 + SRV_MAX_N_IO_THREADS);
  2430. thread_started[6 + SRV_MAX_N_IO_THREADS] = true;
  2431. ut_a(UT_ARR_SIZE(thread_ids)
  2432. > 6 + srv_n_purge_threads + SRV_MAX_N_IO_THREADS);
  2433. /* We've already created the purge coordinator thread above. */
  2434. for (i = 1; i < srv_n_purge_threads; ++i) {
  2435. thread_handles[6 + i + SRV_MAX_N_IO_THREADS] = os_thread_create(
  2436. srv_worker_thread, NULL,
  2437. thread_ids + 6 + i + SRV_MAX_N_IO_THREADS);
  2438. thread_started[6 + i + SRV_MAX_N_IO_THREADS] = true;
  2439. }
  2440. srv_start_wait_for_purge_to_start();
  2441. } else {
  2442. purge_sys->state = PURGE_STATE_DISABLED;
  2443. }
  2444. if (!srv_read_only_mode) {
  2445. if (srv_use_mtflush) {
  2446. /* Start multi-threaded flush threads */
  2447. mtflush_ctx = buf_mtflu_handler_init(
  2448. srv_mtflush_threads,
  2449. srv_buf_pool_instances);
  2450. /* Set up the thread ids */
  2451. buf_mtflu_set_thread_ids(
  2452. srv_mtflush_threads,
  2453. mtflush_ctx,
  2454. (thread_ids + 6 + SRV_MAX_N_PURGE_THREADS));
  2455. }
  2456. buf_page_cleaner_is_active = true;
  2457. buf_flush_page_cleaner_thread_handle = os_thread_create(
  2458. buf_flush_page_cleaner_thread, NULL, NULL);
  2459. buf_flush_page_cleaner_thread_started = true;
  2460. buf_lru_manager_is_active = true;
  2461. buf_flush_lru_manager_thread_handle = os_thread_create(
  2462. buf_flush_lru_manager_thread, NULL, NULL);
  2463. buf_flush_lru_manager_thread_started = true;
  2464. }
  2465. if (!srv_file_per_table && srv_pass_corrupt_table) {
  2466. fprintf(stderr, "InnoDB: Warning:"
  2467. " The option innodb_file_per_table is disabled,"
  2468. " so using the option innodb_pass_corrupt_table doesn't make sense.\n");
  2469. }
  2470. if (srv_print_verbose_log) {
  2471. ib_logf(IB_LOG_LEVEL_INFO,
  2472. " Percona XtraDB (http://www.percona.com) %s started; "
  2473. "log sequence number " LSN_PF "",
  2474. INNODB_VERSION_STR, srv_start_lsn);
  2475. }
  2476. if (srv_force_recovery > 0) {
  2477. ib_logf(IB_LOG_LEVEL_INFO,
  2478. "!!! innodb_force_recovery is set to %lu !!!",
  2479. (ulong) srv_force_recovery);
  2480. }
  2481. if (!srv_read_only_mode) {
  2482. /*
  2483. Create a checkpoint before logging anything new, so that
  2484. the current encryption key in use is definitely logged
  2485. before any log blocks encrypted with that key.
  2486. */
  2487. log_make_checkpoint_at(LSN_MAX, TRUE);
  2488. }
  2489. if (srv_force_recovery == 0) {
  2490. /* In the insert buffer we may have even bigger tablespace
  2491. id's, because we may have dropped those tablespaces, but
  2492. insert buffer merge has not had time to clean the records from
  2493. the ibuf tree. */
  2494. ibuf_update_max_tablespace_id();
  2495. }
  2496. if (!srv_read_only_mode) {
  2497. #ifdef WITH_WSREP
  2498. /*
  2499. Create the dump/load thread only when not running with
  2500. --wsrep-recover.
  2501. */
  2502. if (!wsrep_recovery) {
  2503. #endif /* WITH_WSREP */
  2504. /* Create the buffer pool dump/load thread */
  2505. srv_buf_dump_thread_active = true;
  2506. buf_dump_thread_handle=
  2507. os_thread_create(buf_dump_thread, NULL, NULL);
  2508. buf_dump_thread_started = true;
  2509. #ifdef WITH_WSREP
  2510. } else {
  2511. ib_logf(IB_LOG_LEVEL_WARN,
  2512. "Skipping buffer pool dump/restore during "
  2513. "wsrep recovery.");
  2514. }
  2515. #endif /* WITH_WSREP */
  2516. /* Create thread(s) that handles key rotation */
  2517. fil_system_enter();
  2518. btr_scrub_init();
  2519. fil_crypt_threads_init();
  2520. fil_system_exit();
  2521. /* Initialize online defragmentation. */
  2522. btr_defragment_init();
  2523. btr_defragment_thread_active = true;
  2524. os_thread_create(btr_defragment_thread, NULL, NULL);
  2525. }
  2526. skip_processes:
  2527. srv_was_started = TRUE;
  2528. return(DB_SUCCESS);
  2529. }
  2530. #if 0
  2531. /********************************************************************
  2532. Sync all FTS cache before shutdown */
  2533. static
  2534. void
  2535. srv_fts_close(void)
  2536. /*===============*/
  2537. {
  2538. dict_table_t* table;
  2539. for (table = UT_LIST_GET_FIRST(dict_sys->table_LRU);
  2540. table; table = UT_LIST_GET_NEXT(table_LRU, table)) {
  2541. fts_t* fts = table->fts;
  2542. if (fts != NULL) {
  2543. fts_sync_table(table);
  2544. }
  2545. }
  2546. for (table = UT_LIST_GET_FIRST(dict_sys->table_non_LRU);
  2547. table; table = UT_LIST_GET_NEXT(table_LRU, table)) {
  2548. fts_t* fts = table->fts;
  2549. if (fts != NULL) {
  2550. fts_sync_table(table);
  2551. }
  2552. }
  2553. }
  2554. #endif
  2555. /** Shut down InnoDB. */
  2556. UNIV_INTERN
  2557. void
  2558. innodb_shutdown()
  2559. {
  2560. ulint i;
  2561. if (!srv_was_started) {
  2562. if (srv_is_being_started) {
  2563. ib_logf(IB_LOG_LEVEL_WARN,
  2564. "Shutting down an improperly started, "
  2565. "or created database!");
  2566. }
  2567. }
  2568. if (srv_undo_sources) {
  2569. ut_ad(!srv_read_only_mode);
  2570. /* Shutdown the FTS optimize sub system. */
  2571. fts_optimize_start_shutdown();
  2572. fts_optimize_end();
  2573. dict_stats_shutdown();
  2574. while (row_get_background_drop_list_len_low()) {
  2575. srv_wake_master_thread();
  2576. os_thread_yield();
  2577. }
  2578. srv_undo_sources = false;
  2579. }
  2580. /* 1. Flush the buffer pool to disk, write the current lsn to
  2581. the tablespace header(s), and copy all log data to archive.
  2582. The step 1 is the real InnoDB shutdown. The remaining steps 2 - ...
  2583. just free data structures after the shutdown. */
  2584. logs_empty_and_mark_files_at_shutdown();
  2585. if (srv_conc_get_active_threads() != 0) {
  2586. ib_logf(IB_LOG_LEVEL_WARN,
  2587. "Query counter shows %ld queries still "
  2588. "inside InnoDB at shutdown",
  2589. srv_conc_get_active_threads());
  2590. }
  2591. /* 2. Make all threads created by InnoDB to exit */
  2592. srv_shutdown_state = SRV_SHUTDOWN_EXIT_THREADS;
  2593. /* All threads end up waiting for certain events. Put those events
  2594. to the signaled state. Then the threads will exit themselves after
  2595. os_event_wait(). */
  2596. for (i = 0; i < 1000; i++) {
  2597. /* NOTE: IF YOU CREATE THREADS IN INNODB, YOU MUST EXIT THEM
  2598. HERE OR EARLIER */
  2599. if (!srv_read_only_mode) {
  2600. /* a. Let the lock timeout thread exit */
  2601. os_event_set(lock_sys->timeout_event);
  2602. /* b. srv error monitor thread exits automatically,
  2603. no need to do anything here */
  2604. /* c. We wake the master thread so that it exits */
  2605. srv_wake_master_thread();
  2606. /* d. Wakeup purge threads. */
  2607. srv_purge_wakeup();
  2608. }
  2609. /* e. Exit the i/o threads */
  2610. os_aio_wake_all_threads_at_shutdown();
  2611. /* f. dict_stats_thread is signaled from
  2612. logs_empty_and_mark_files_at_shutdown() and should have
  2613. already quit or is quitting right now. */
  2614. if (srv_use_mtflush) {
  2615. /* g. Exit the multi threaded flush threads */
  2616. buf_mtflu_io_thread_exit();
  2617. }
  2618. os_rmb;
  2619. if (os_thread_count == 0) {
  2620. /* All the threads have exited or are just exiting;
  2621. NOTE that the threads may not have completed their
  2622. exit yet. Should we use pthread_join() to make sure
  2623. they have exited? If we did, we would have to
  2624. remove the pthread_detach() from
  2625. os_thread_exit(). Now we just sleep 0.1
  2626. seconds and hope that is enough! */
  2627. os_thread_sleep(100000);
  2628. break;
  2629. }
  2630. os_thread_sleep(100000);
  2631. }
  2632. if (i == 1000) {
  2633. ib_logf(IB_LOG_LEVEL_WARN,
  2634. "%lu threads created by InnoDB"
  2635. " had not exited at shutdown!",
  2636. (ulong) os_thread_count);
  2637. }
  2638. if (srv_monitor_file) {
  2639. fclose(srv_monitor_file);
  2640. srv_monitor_file = 0;
  2641. if (srv_monitor_file_name) {
  2642. unlink(srv_monitor_file_name);
  2643. mem_free(srv_monitor_file_name);
  2644. }
  2645. }
  2646. if (srv_dict_tmpfile) {
  2647. fclose(srv_dict_tmpfile);
  2648. srv_dict_tmpfile = 0;
  2649. }
  2650. if (srv_misc_tmpfile) {
  2651. fclose(srv_misc_tmpfile);
  2652. srv_misc_tmpfile = 0;
  2653. }
  2654. if (!srv_read_only_mode && !srv_apply_log_only) {
  2655. dict_stats_thread_deinit();
  2656. fil_crypt_threads_cleanup();
  2657. btr_scrub_cleanup();
  2658. btr_defragment_shutdown();
  2659. }
  2660. #ifdef __WIN__
  2661. /* MDEV-361: ha_innodb.dll leaks handles on Windows
  2662. MDEV-7403: should not pass recv_writer_thread_handle to
  2663. CloseHandle().
  2664. On Windows we should call CloseHandle() for all
  2665. open thread handles. */
  2666. if (os_thread_count == 0) {
  2667. for (i = 0; i < SRV_MAX_N_IO_THREADS + 6 + 32; ++i) {
  2668. if (thread_started[i]) {
  2669. CloseHandle(thread_handles[i]);
  2670. }
  2671. }
  2672. if (buf_flush_page_cleaner_thread_started) {
  2673. CloseHandle(buf_flush_page_cleaner_thread_handle);
  2674. }
  2675. if (buf_dump_thread_started) {
  2676. CloseHandle(buf_dump_thread_handle);
  2677. }
  2678. if (dict_stats_thread_started) {
  2679. CloseHandle(dict_stats_thread_handle);
  2680. }
  2681. if (buf_flush_lru_manager_thread_started) {
  2682. CloseHandle(buf_flush_lru_manager_thread_handle);
  2683. }
  2684. if (srv_redo_log_follow_thread_started) {
  2685. CloseHandle(srv_redo_log_follow_thread_handle);
  2686. }
  2687. }
  2688. #endif /* __WIN __ */
  2689. /* This must be disabled before closing the buffer pool
  2690. and closing the data dictionary. */
  2691. btr_search_disable();
  2692. ibuf_close();
  2693. log_online_shutdown();
  2694. log_shutdown();
  2695. trx_sys_file_format_close();
  2696. trx_sys_close();
  2697. lock_sys_close();
  2698. /* We don't create these mutexes in RO mode because we don't create
  2699. the temp files that the cover. */
  2700. if (!srv_read_only_mode) {
  2701. mutex_free(&srv_monitor_file_mutex);
  2702. mutex_free(&srv_dict_tmpfile_mutex);
  2703. mutex_free(&srv_misc_tmpfile_mutex);
  2704. }
  2705. dict_close();
  2706. btr_search_sys_free();
  2707. /* 3. Free all InnoDB's own mutexes and the os_fast_mutexes inside
  2708. them */
  2709. os_aio_free();
  2710. que_close();
  2711. row_mysql_close();
  2712. srv_mon_free();
  2713. srv_free();
  2714. fil_close();
  2715. /* 4. Free all allocated memory */
  2716. pars_lexer_close();
  2717. log_mem_free();
  2718. buf_pool_free(srv_buf_pool_instances);
  2719. mem_close();
  2720. sync_close();
  2721. /* ut_free_all_mem() frees all allocated memory not freed yet
  2722. in shutdown, and it will also free the ut_list_mutex, so it
  2723. should be the last one for all operation */
  2724. ut_free_all_mem();
  2725. os_rmb;
  2726. if (os_thread_count != 0
  2727. || os_event_count != 0
  2728. || os_mutex_count != 0
  2729. || os_fast_mutex_count != 0) {
  2730. ib_logf(IB_LOG_LEVEL_WARN,
  2731. "Some resources were not cleaned up in shutdown: "
  2732. "threads %lu, events %lu, os_mutexes %lu, "
  2733. "os_fast_mutexes %lu",
  2734. (ulong) os_thread_count, (ulong) os_event_count,
  2735. (ulong) os_mutex_count, (ulong) os_fast_mutex_count);
  2736. }
  2737. if (dict_foreign_err_file) {
  2738. fclose(dict_foreign_err_file);
  2739. }
  2740. if (srv_print_verbose_log) {
  2741. ib_logf(IB_LOG_LEVEL_INFO,
  2742. "Shutdown completed; log sequence number " LSN_PF "",
  2743. srv_shutdown_lsn);
  2744. }
  2745. srv_was_started = FALSE;
  2746. srv_start_has_been_called = FALSE;
  2747. /* reset io_tid_i, in case current process does second innodb start (xtrabackup might do that).*/
  2748. io_tid_i = 0;
  2749. }
  2750. #endif /* !UNIV_HOTBACKUP */
  2751. /*****************************************************************//**
  2752. Get the meta-data filename from the table name. */
  2753. UNIV_INTERN
  2754. void
  2755. srv_get_meta_data_filename(
  2756. /*=======================*/
  2757. dict_table_t* table, /*!< in: table */
  2758. char* filename, /*!< out: filename */
  2759. ulint max_len) /*!< in: filename max length */
  2760. {
  2761. ulint len;
  2762. char* path;
  2763. char* suffix;
  2764. static const ulint suffix_len = strlen(".cfg");
  2765. if (DICT_TF_HAS_DATA_DIR(table->flags)) {
  2766. dict_get_and_save_data_dir_path(table, false);
  2767. ut_a(table->data_dir_path);
  2768. path = os_file_make_remote_pathname(
  2769. table->data_dir_path, table->name, "cfg");
  2770. } else {
  2771. path = fil_make_ibd_name(table->name, false);
  2772. }
  2773. ut_a(path);
  2774. len = ut_strlen(path);
  2775. ut_a(max_len >= len);
  2776. suffix = path + (len - suffix_len);
  2777. if (strncmp(suffix, ".cfg", suffix_len) == 0) {
  2778. strcpy(filename, path);
  2779. } else {
  2780. ut_ad(strncmp(suffix, ".ibd", suffix_len) == 0);
  2781. strncpy(filename, path, len - suffix_len);
  2782. suffix = filename + (len - suffix_len);
  2783. strcpy(suffix, ".cfg");
  2784. }
  2785. mem_free(path);
  2786. srv_normalize_path_for_win(filename);
  2787. }