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.

1318 lines
36 KiB

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
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-12253: Buffer pool blocks are accessed after they have been freed Problem was that bpage was referenced after it was already freed from LRU. Fixed by adding a new variable encrypted that is passed down to buf_page_check_corrupt() and used in buf_page_get_gen() to stop processing page read. This patch should also address following test failures and bugs: MDEV-12419: IMPORT should not look up tablespace in PageConverter::validate(). This is now removed. MDEV-10099: encryption.innodb_onlinealter_encryption fails sporadically in buildbot MDEV-11420: encryption.innodb_encryption-page-compression failed in buildbot MDEV-11222: encryption.encrypt_and_grep failed in buildbot on P8 Removed dict_table_t::is_encrypted and dict_table_t::ibd_file_missing and replaced these with dict_table_t::file_unreadable. Table ibd file is missing if fil_get_space(space_id) returns NULL and encrypted if not. Removed dict_table_t::is_corrupted field. Ported FilSpace class from 10.2 and using that on buf_page_check_corrupt(), buf_page_decrypt_after_read(), buf_page_encrypt_before_write(), buf_dblwr_process(), buf_read_page(), dict_stats_save_defrag_stats(). Added test cases when enrypted page could be read while doing redo log crash recovery. Also added test case for row compressed blobs. btr_cur_open_at_index_side_func(), btr_cur_open_at_rnd_pos_func(): Avoid referencing block that is NULL. buf_page_get_zip(): Issue error if page read fails. buf_page_get_gen(): Use dberr_t for error detection and do not reference bpage after we hare freed it. buf_mark_space_corrupt(): remove bpage from LRU also when it is encrypted. buf_page_check_corrupt(): @return DB_SUCCESS if page has been read and is not corrupted, DB_PAGE_CORRUPTED if page based on checksum check is corrupted, DB_DECRYPTION_FAILED if page post encryption checksum matches but after decryption normal page checksum does not match. In read case only DB_SUCCESS is possible. buf_page_io_complete(): use dberr_t for error handling. buf_flush_write_block_low(), buf_read_ahead_random(), buf_read_page_async(), buf_read_ahead_linear(), buf_read_ibuf_merge_pages(), buf_read_recv_pages(), fil_aio_wait(): Issue error if page read fails. btr_pcur_move_to_next_page(): Do not reference page if it is NULL. Introduced dict_table_t::is_readable() and dict_index_t::is_readable() that will return true if tablespace exists and pages read from tablespace are not corrupted or page decryption failed. Removed buf_page_t::key_version. After page decryption the key version is not removed from page frame. For unencrypted pages, old key_version is removed at buf_page_encrypt_before_write() dict_stats_update_transient_for_index(), dict_stats_update_transient() Do not continue if table decryption failed or table is corrupted. dict0stats.cc: Introduced a dict_stats_report_error function to avoid code duplication. fil_parse_write_crypt_data(): Check that key read from redo log entry is found from encryption plugin and if it is not, refuse to start. PageConverter::validate(): Removed access to fil_space_t as tablespace is not available during import. Fixed error code on innodb.innodb test. Merged test cased innodb-bad-key-change5 and innodb-bad-key-shutdown to innodb-bad-key-change2. Removed innodb-bad-key-change5 test. Decreased unnecessary complexity on some long lasting tests. Removed fil_inc_pending_ops(), fil_decr_pending_ops(), fil_get_first_space(), fil_get_next_space(), fil_get_first_space_safe(), fil_get_next_space_safe() functions. fil_space_verify_crypt_checksum(): Fixed bug found using ASAN where FIL_PAGE_END_LSN_OLD_CHECKSUM field was incorrectly accessed from row compressed tables. Fixed out of page frame bug for row compressed tables in fil_space_verify_crypt_checksum() found using ASAN. Incorrect function was called for compressed table. Added new tests for discard, rename table and drop (we should allow them even when page decryption fails). Alter table rename is not allowed. Added test for restart with innodb-force-recovery=1 when page read on redo-recovery cant be decrypted. Added test for corrupted table where both page data and FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION is corrupted. Adjusted the test case innodb_bug14147491 so that it does not anymore expect crash. Instead table is just mostly not usable. fil0fil.h: fil_space_acquire_low is not visible function and fil_space_acquire and fil_space_acquire_silent are inline functions. FilSpace class uses fil_space_acquire_low directly. recv_apply_hashed_log_recs() does not return anything.
9 years ago
MDEV-12253: Buffer pool blocks are accessed after they have been freed Problem was that bpage was referenced after it was already freed from LRU. Fixed by adding a new variable encrypted that is passed down to buf_page_check_corrupt() and used in buf_page_get_gen() to stop processing page read. This patch should also address following test failures and bugs: MDEV-12419: IMPORT should not look up tablespace in PageConverter::validate(). This is now removed. MDEV-10099: encryption.innodb_onlinealter_encryption fails sporadically in buildbot MDEV-11420: encryption.innodb_encryption-page-compression failed in buildbot MDEV-11222: encryption.encrypt_and_grep failed in buildbot on P8 Removed dict_table_t::is_encrypted and dict_table_t::ibd_file_missing and replaced these with dict_table_t::file_unreadable. Table ibd file is missing if fil_get_space(space_id) returns NULL and encrypted if not. Removed dict_table_t::is_corrupted field. Ported FilSpace class from 10.2 and using that on buf_page_check_corrupt(), buf_page_decrypt_after_read(), buf_page_encrypt_before_write(), buf_dblwr_process(), buf_read_page(), dict_stats_save_defrag_stats(). Added test cases when enrypted page could be read while doing redo log crash recovery. Also added test case for row compressed blobs. btr_cur_open_at_index_side_func(), btr_cur_open_at_rnd_pos_func(): Avoid referencing block that is NULL. buf_page_get_zip(): Issue error if page read fails. buf_page_get_gen(): Use dberr_t for error detection and do not reference bpage after we hare freed it. buf_mark_space_corrupt(): remove bpage from LRU also when it is encrypted. buf_page_check_corrupt(): @return DB_SUCCESS if page has been read and is not corrupted, DB_PAGE_CORRUPTED if page based on checksum check is corrupted, DB_DECRYPTION_FAILED if page post encryption checksum matches but after decryption normal page checksum does not match. In read case only DB_SUCCESS is possible. buf_page_io_complete(): use dberr_t for error handling. buf_flush_write_block_low(), buf_read_ahead_random(), buf_read_page_async(), buf_read_ahead_linear(), buf_read_ibuf_merge_pages(), buf_read_recv_pages(), fil_aio_wait(): Issue error if page read fails. btr_pcur_move_to_next_page(): Do not reference page if it is NULL. Introduced dict_table_t::is_readable() and dict_index_t::is_readable() that will return true if tablespace exists and pages read from tablespace are not corrupted or page decryption failed. Removed buf_page_t::key_version. After page decryption the key version is not removed from page frame. For unencrypted pages, old key_version is removed at buf_page_encrypt_before_write() dict_stats_update_transient_for_index(), dict_stats_update_transient() Do not continue if table decryption failed or table is corrupted. dict0stats.cc: Introduced a dict_stats_report_error function to avoid code duplication. fil_parse_write_crypt_data(): Check that key read from redo log entry is found from encryption plugin and if it is not, refuse to start. PageConverter::validate(): Removed access to fil_space_t as tablespace is not available during import. Fixed error code on innodb.innodb test. Merged test cased innodb-bad-key-change5 and innodb-bad-key-shutdown to innodb-bad-key-change2. Removed innodb-bad-key-change5 test. Decreased unnecessary complexity on some long lasting tests. Removed fil_inc_pending_ops(), fil_decr_pending_ops(), fil_get_first_space(), fil_get_next_space(), fil_get_first_space_safe(), fil_get_next_space_safe() functions. fil_space_verify_crypt_checksum(): Fixed bug found using ASAN where FIL_PAGE_END_LSN_OLD_CHECKSUM field was incorrectly accessed from row compressed tables. Fixed out of page frame bug for row compressed tables in fil_space_verify_crypt_checksum() found using ASAN. Incorrect function was called for compressed table. Added new tests for discard, rename table and drop (we should allow them even when page decryption fails). Alter table rename is not allowed. Added test for restart with innodb-force-recovery=1 when page read on redo-recovery cant be decrypted. Added test for corrupted table where both page data and FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION is corrupted. Adjusted the test case innodb_bug14147491 so that it does not anymore expect crash. Instead table is just mostly not usable. fil0fil.h: fil_space_acquire_low is not visible function and fil_space_acquire and fil_space_acquire_silent are inline functions. FilSpace class uses fil_space_acquire_low directly. recv_apply_hashed_log_recs() does not return anything.
9 years ago
MDEV-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
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
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
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
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
  1. /*****************************************************************************
  2. Copyright (c) 1995, 2017, Oracle and/or its affiliates. All Rights Reserved.
  3. Copyright (c) 2013, 2020, MariaDB Corporation.
  4. This program is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU General Public License as published by the Free Software
  6. Foundation; version 2 of the License.
  7. This program is distributed in the hope that it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License along with
  11. this program; if not, write to the Free Software Foundation, Inc.,
  12. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
  13. *****************************************************************************/
  14. /**************************************************//**
  15. @file buf/buf0dblwr.cc
  16. Doublwrite buffer module
  17. Created 2011/12/19
  18. *******************************************************/
  19. #include "buf0dblwr.h"
  20. #ifdef UNIV_NONINL
  21. #include "buf0buf.ic"
  22. #endif
  23. #include "buf0buf.h"
  24. #include "buf0checksum.h"
  25. #include "srv0start.h"
  26. #include "srv0srv.h"
  27. #include "page0zip.h"
  28. #include "trx0sys.h"
  29. #include "fil0crypt.h"
  30. #include "fil0pagecompress.h"
  31. #ifndef UNIV_HOTBACKUP
  32. #ifdef UNIV_PFS_MUTEX
  33. /* Key to register the mutex with performance schema */
  34. UNIV_INTERN mysql_pfs_key_t buf_dblwr_mutex_key;
  35. #endif /* UNIV_PFS_RWLOCK */
  36. /** The doublewrite buffer */
  37. UNIV_INTERN buf_dblwr_t* buf_dblwr = NULL;
  38. /** Set to TRUE when the doublewrite buffer is being created */
  39. UNIV_INTERN ibool buf_dblwr_being_created = FALSE;
  40. #define TRX_SYS_DOUBLEWRITE_BLOCKS 2
  41. /****************************************************************//**
  42. Determines if a page number is located inside the doublewrite buffer.
  43. @return TRUE if the location is inside the two blocks of the
  44. doublewrite buffer */
  45. UNIV_INTERN
  46. ibool
  47. buf_dblwr_page_inside(
  48. /*==================*/
  49. ulint page_no) /*!< in: page number */
  50. {
  51. if (buf_dblwr == NULL) {
  52. return(FALSE);
  53. }
  54. if (page_no >= buf_dblwr->block1
  55. && page_no < buf_dblwr->block1
  56. + TRX_SYS_DOUBLEWRITE_BLOCK_SIZE) {
  57. return(TRUE);
  58. }
  59. if (page_no >= buf_dblwr->block2
  60. && page_no < buf_dblwr->block2
  61. + TRX_SYS_DOUBLEWRITE_BLOCK_SIZE) {
  62. return(TRUE);
  63. }
  64. return(FALSE);
  65. }
  66. /****************************************************************//**
  67. Calls buf_page_get() on the TRX_SYS_PAGE and returns a pointer to the
  68. doublewrite buffer within it.
  69. @return pointer to the doublewrite buffer within the filespace header
  70. page. */
  71. UNIV_INLINE
  72. byte*
  73. buf_dblwr_get(
  74. /*==========*/
  75. mtr_t* mtr) /*!< in/out: MTR to hold the page latch */
  76. {
  77. buf_block_t* block;
  78. block = buf_page_get(TRX_SYS_SPACE, 0, TRX_SYS_PAGE_NO,
  79. RW_X_LATCH, mtr);
  80. buf_block_dbg_add_level(block, SYNC_NO_ORDER_CHECK);
  81. return(buf_block_get_frame(block) + TRX_SYS_DOUBLEWRITE);
  82. }
  83. /********************************************************************//**
  84. Flush a batch of writes to the datafiles that have already been
  85. written to the dblwr buffer on disk. */
  86. UNIV_INLINE
  87. void
  88. buf_dblwr_sync_datafiles()
  89. /*======================*/
  90. {
  91. /* Wake possible simulated aio thread to actually post the
  92. writes to the operating system */
  93. os_aio_simulated_wake_handler_threads();
  94. /* Wait that all async writes to tablespaces have been posted to
  95. the OS */
  96. os_aio_wait_until_no_pending_writes();
  97. /* Now we flush the data to disk (for example, with fsync) */
  98. fil_flush_file_spaces(FIL_TABLESPACE);
  99. }
  100. /****************************************************************//**
  101. Creates or initialializes the doublewrite buffer at a database start. */
  102. static
  103. void
  104. buf_dblwr_init(
  105. /*===========*/
  106. byte* doublewrite) /*!< in: pointer to the doublewrite buf
  107. header on trx sys page */
  108. {
  109. ulint buf_size;
  110. buf_dblwr = static_cast<buf_dblwr_t*>(
  111. mem_zalloc(sizeof(buf_dblwr_t)));
  112. /* There are two blocks of same size in the doublewrite
  113. buffer. */
  114. buf_size = TRX_SYS_DOUBLEWRITE_BLOCKS * TRX_SYS_DOUBLEWRITE_BLOCK_SIZE;
  115. /* There must be atleast one buffer for single page writes
  116. and one buffer for batch writes. */
  117. ut_a(srv_doublewrite_batch_size > 0
  118. && srv_doublewrite_batch_size < buf_size);
  119. mutex_create(buf_dblwr_mutex_key,
  120. &buf_dblwr->mutex, SYNC_DOUBLEWRITE);
  121. buf_dblwr->b_event = os_event_create();
  122. buf_dblwr->s_event = os_event_create();
  123. buf_dblwr->first_free = 0;
  124. buf_dblwr->s_reserved = 0;
  125. buf_dblwr->b_reserved = 0;
  126. buf_dblwr->block1 = mach_read_from_4(
  127. doublewrite + TRX_SYS_DOUBLEWRITE_BLOCK1);
  128. buf_dblwr->block2 = mach_read_from_4(
  129. doublewrite + TRX_SYS_DOUBLEWRITE_BLOCK2);
  130. buf_dblwr->in_use = static_cast<bool*>(
  131. mem_zalloc(buf_size * sizeof(bool)));
  132. buf_dblwr->write_buf_unaligned = static_cast<byte*>(
  133. ut_malloc((1 + buf_size) * UNIV_PAGE_SIZE));
  134. buf_dblwr->write_buf = static_cast<byte*>(
  135. ut_align(buf_dblwr->write_buf_unaligned,
  136. UNIV_PAGE_SIZE));
  137. buf_dblwr->buf_block_arr = static_cast<buf_page_t**>(
  138. mem_zalloc(buf_size * sizeof(void*)));
  139. }
  140. /** Create the doublewrite buffer if the doublewrite buffer header
  141. is not present in the TRX_SYS page.
  142. @return whether the operation succeeded
  143. @retval true if the doublewrite buffer exists or was created
  144. @retval false if the creation failed (too small first data file) */
  145. UNIV_INTERN
  146. bool
  147. buf_dblwr_create()
  148. {
  149. buf_block_t* block2;
  150. buf_block_t* new_block;
  151. byte* doublewrite;
  152. byte* fseg_header;
  153. ulint page_no;
  154. ulint prev_page_no;
  155. ulint i;
  156. mtr_t mtr;
  157. if (buf_dblwr) {
  158. /* Already inited */
  159. return(true);
  160. }
  161. start_again:
  162. mtr_start(&mtr);
  163. buf_dblwr_being_created = TRUE;
  164. doublewrite = buf_dblwr_get(&mtr);
  165. if (mach_read_from_4(doublewrite + TRX_SYS_DOUBLEWRITE_MAGIC)
  166. == TRX_SYS_DOUBLEWRITE_MAGIC_N) {
  167. /* The doublewrite buffer has already been created:
  168. just read in some numbers */
  169. buf_dblwr_init(doublewrite);
  170. mtr_commit(&mtr);
  171. buf_dblwr_being_created = FALSE;
  172. return(true);
  173. }
  174. if (buf_pool_get_curr_size()
  175. < ((TRX_SYS_DOUBLEWRITE_BLOCKS * TRX_SYS_DOUBLEWRITE_BLOCK_SIZE
  176. + FSP_EXTENT_SIZE / 2 + 100)
  177. * UNIV_PAGE_SIZE)) {
  178. ib_logf(IB_LOG_LEVEL_ERROR,
  179. "Cannot create doublewrite buffer: "
  180. "innodb_buffer_pool_size is too small.");
  181. mtr_commit(&mtr);
  182. return(false);
  183. } else {
  184. fil_space_t* space = fil_space_acquire(TRX_SYS_SPACE);
  185. const bool fail = UT_LIST_GET_FIRST(space->chain)->size
  186. < 3 * FSP_EXTENT_SIZE;
  187. fil_space_release(space);
  188. if (fail) {
  189. goto too_small;
  190. }
  191. }
  192. block2 = fseg_create(TRX_SYS_SPACE, TRX_SYS_PAGE_NO,
  193. TRX_SYS_DOUBLEWRITE
  194. + TRX_SYS_DOUBLEWRITE_FSEG, &mtr);
  195. if (block2 == NULL) {
  196. too_small:
  197. ib_logf(IB_LOG_LEVEL_ERROR,
  198. "Cannot create doublewrite buffer: "
  199. "the first file in innodb_data_file_path"
  200. " must be at least %luM.",
  201. 3 * (FSP_EXTENT_SIZE * UNIV_PAGE_SIZE) >> 20);
  202. mtr_commit(&mtr);
  203. return(false);
  204. }
  205. ib_logf(IB_LOG_LEVEL_INFO,
  206. "Doublewrite buffer not found: creating new");
  207. /* FIXME: After this point, the doublewrite buffer creation
  208. is not atomic. The doublewrite buffer should not exist in
  209. the InnoDB system tablespace file in the first place.
  210. It could be located in separate optional file(s) in a
  211. user-specified location. */
  212. /* fseg_create acquires a second latch on the page,
  213. therefore we must declare it: */
  214. buf_block_dbg_add_level(block2, SYNC_NO_ORDER_CHECK);
  215. fseg_header = doublewrite + TRX_SYS_DOUBLEWRITE_FSEG;
  216. prev_page_no = 0;
  217. for (i = 0; i < TRX_SYS_DOUBLEWRITE_BLOCKS * TRX_SYS_DOUBLEWRITE_BLOCK_SIZE
  218. + FSP_EXTENT_SIZE / 2; i++) {
  219. new_block = fseg_alloc_free_page(
  220. fseg_header, prev_page_no + 1, FSP_UP, &mtr);
  221. if (new_block == NULL) {
  222. ib_logf(IB_LOG_LEVEL_FATAL,
  223. "Cannot create doublewrite buffer: you must "
  224. "increase your tablespace size. "
  225. "Cannot continue operation.");
  226. }
  227. /* We read the allocated pages to the buffer pool;
  228. when they are written to disk in a flush, the space
  229. id and page number fields are also written to the
  230. pages. When we at database startup read pages
  231. from the doublewrite buffer, we know that if the
  232. space id and page number in them are the same as
  233. the page position in the tablespace, then the page
  234. has not been written to in doublewrite. */
  235. ut_ad(rw_lock_get_x_lock_count(&new_block->lock) == 1);
  236. page_no = buf_block_get_page_no(new_block);
  237. /* We only do this in the debug build, to ensure that
  238. both the check in buf_flush_init_for_writing() and
  239. recv_parse_or_apply_log_rec_body() will see a valid
  240. page type. The flushes of new_block are actually
  241. unnecessary here. */
  242. ut_d(mlog_write_ulint(FIL_PAGE_TYPE + new_block->frame,
  243. FIL_PAGE_TYPE_SYS, MLOG_2BYTES, &mtr));
  244. if (i == FSP_EXTENT_SIZE / 2) {
  245. ut_a(page_no == FSP_EXTENT_SIZE);
  246. mlog_write_ulint(doublewrite
  247. + TRX_SYS_DOUBLEWRITE_BLOCK1,
  248. page_no, MLOG_4BYTES, &mtr);
  249. mlog_write_ulint(doublewrite
  250. + TRX_SYS_DOUBLEWRITE_REPEAT
  251. + TRX_SYS_DOUBLEWRITE_BLOCK1,
  252. page_no, MLOG_4BYTES, &mtr);
  253. } else if (i == FSP_EXTENT_SIZE / 2
  254. + TRX_SYS_DOUBLEWRITE_BLOCK_SIZE) {
  255. ut_a(page_no == 2 * FSP_EXTENT_SIZE);
  256. mlog_write_ulint(doublewrite
  257. + TRX_SYS_DOUBLEWRITE_BLOCK2,
  258. page_no, MLOG_4BYTES, &mtr);
  259. mlog_write_ulint(doublewrite
  260. + TRX_SYS_DOUBLEWRITE_REPEAT
  261. + TRX_SYS_DOUBLEWRITE_BLOCK2,
  262. page_no, MLOG_4BYTES, &mtr);
  263. } else if (i > FSP_EXTENT_SIZE / 2) {
  264. ut_a(page_no == prev_page_no + 1);
  265. }
  266. if (((i + 1) & 15) == 0) {
  267. /* rw_locks can only be recursively x-locked
  268. 2048 times. (on 32 bit platforms,
  269. (lint) 0 - (X_LOCK_DECR * 2049)
  270. is no longer a negative number, and thus
  271. lock_word becomes like a shared lock).
  272. For 4k page size this loop will
  273. lock the fseg header too many times. Since
  274. this code is not done while any other threads
  275. are active, restart the MTR occasionally. */
  276. mtr_commit(&mtr);
  277. mtr_start(&mtr);
  278. doublewrite = buf_dblwr_get(&mtr);
  279. fseg_header = doublewrite
  280. + TRX_SYS_DOUBLEWRITE_FSEG;
  281. }
  282. prev_page_no = page_no;
  283. }
  284. mlog_write_ulint(doublewrite + TRX_SYS_DOUBLEWRITE_MAGIC,
  285. TRX_SYS_DOUBLEWRITE_MAGIC_N,
  286. MLOG_4BYTES, &mtr);
  287. mlog_write_ulint(doublewrite + TRX_SYS_DOUBLEWRITE_MAGIC
  288. + TRX_SYS_DOUBLEWRITE_REPEAT,
  289. TRX_SYS_DOUBLEWRITE_MAGIC_N,
  290. MLOG_4BYTES, &mtr);
  291. mlog_write_ulint(doublewrite
  292. + TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED,
  293. TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED_N,
  294. MLOG_4BYTES, &mtr);
  295. mtr_commit(&mtr);
  296. /* Flush the modified pages to disk and make a checkpoint */
  297. log_make_checkpoint_at(LSN_MAX, TRUE);
  298. buf_dblwr_being_created = FALSE;
  299. /* Remove doublewrite pages from LRU */
  300. buf_pool_invalidate();
  301. ib_logf(IB_LOG_LEVEL_INFO, "Doublewrite buffer created");
  302. goto start_again;
  303. }
  304. /** Check if a page is all zeroes.
  305. @param[in] read_buf database page
  306. @param[in] zip_size ROW_FORMAT=COMPRESSED page size, or 0
  307. @return whether the page is all zeroes */
  308. static bool buf_page_is_zeroes(const byte* read_buf, ulint zip_size)
  309. {
  310. const ulint page_size = zip_size ? zip_size : UNIV_PAGE_SIZE;
  311. for (ulint i = 0; i < page_size; i++) {
  312. if (read_buf[i] != 0) {
  313. return false;
  314. }
  315. }
  316. return true;
  317. }
  318. /****************************************************************//**
  319. At a database startup initializes the doublewrite buffer memory structure if
  320. we already have a doublewrite buffer created in the data files. If we are
  321. upgrading to an InnoDB version which supports multiple tablespaces, then this
  322. function performs the necessary update operations. If we are in a crash
  323. recovery, this function loads the pages from double write buffer into memory. */
  324. void
  325. buf_dblwr_init_or_load_pages(
  326. /*=========================*/
  327. pfs_os_file_t file,
  328. char* path,
  329. bool load_corrupt_pages)
  330. {
  331. byte* buf;
  332. byte* read_buf;
  333. byte* unaligned_read_buf;
  334. ulint block1;
  335. ulint block2;
  336. byte* page;
  337. ibool reset_space_ids = FALSE;
  338. byte* doublewrite;
  339. ulint space_id;
  340. ulint i;
  341. ulint block_bytes = 0;
  342. recv_dblwr_t& recv_dblwr = recv_sys->dblwr;
  343. /* We do the file i/o past the buffer pool */
  344. unaligned_read_buf = static_cast<byte*>(ut_malloc(3 * UNIV_PAGE_SIZE));
  345. read_buf = static_cast<byte*>(
  346. ut_align(unaligned_read_buf, UNIV_PAGE_SIZE));
  347. /* Read the trx sys header to check if we are using the doublewrite
  348. buffer */
  349. off_t trx_sys_page = TRX_SYS_PAGE_NO * UNIV_PAGE_SIZE;
  350. os_file_read(file, read_buf, trx_sys_page, UNIV_PAGE_SIZE);
  351. doublewrite = read_buf + TRX_SYS_DOUBLEWRITE;
  352. /* TRX_SYS_PAGE_NO is not encrypted see fil_crypt_rotate_page() */
  353. if (mach_read_from_4(doublewrite + TRX_SYS_DOUBLEWRITE_MAGIC)
  354. == TRX_SYS_DOUBLEWRITE_MAGIC_N) {
  355. /* The doublewrite buffer has been created */
  356. buf_dblwr_init(doublewrite);
  357. block1 = buf_dblwr->block1;
  358. block2 = buf_dblwr->block2;
  359. buf = buf_dblwr->write_buf;
  360. } else {
  361. goto leave_func;
  362. }
  363. if (mach_read_from_4(doublewrite + TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED)
  364. != TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED_N) {
  365. /* We are upgrading from a version < 4.1.x to a version where
  366. multiple tablespaces are supported. We must reset the space id
  367. field in the pages in the doublewrite buffer because starting
  368. from this version the space id is stored to
  369. FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID. */
  370. reset_space_ids = TRUE;
  371. ib_logf(IB_LOG_LEVEL_INFO,
  372. "Resetting space id's in the doublewrite buffer");
  373. }
  374. /* Read the pages from the doublewrite buffer to memory */
  375. block_bytes = TRX_SYS_DOUBLEWRITE_BLOCK_SIZE * UNIV_PAGE_SIZE;
  376. os_file_read(file, buf, block1 * UNIV_PAGE_SIZE, block_bytes);
  377. os_file_read(file, buf + block_bytes, block2 * UNIV_PAGE_SIZE,
  378. block_bytes);
  379. /* Check if any of these pages is half-written in data files, in the
  380. intended position */
  381. page = buf;
  382. for (i = 0; i < TRX_SYS_DOUBLEWRITE_BLOCK_SIZE * TRX_SYS_DOUBLEWRITE_BLOCKS; i++) {
  383. ulint source_page_no;
  384. if (reset_space_ids) {
  385. space_id = 0;
  386. mach_write_to_4(page
  387. + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID, space_id);
  388. /* We do not need to calculate new checksums for the
  389. pages because the field .._SPACE_ID does not affect
  390. them. Write the page back to where we read it from. */
  391. if (i < TRX_SYS_DOUBLEWRITE_BLOCK_SIZE) {
  392. source_page_no = block1 + i;
  393. } else {
  394. source_page_no = block2
  395. + i - TRX_SYS_DOUBLEWRITE_BLOCK_SIZE;
  396. }
  397. os_file_write(path, file, page,
  398. source_page_no * UNIV_PAGE_SIZE,
  399. UNIV_PAGE_SIZE);
  400. } else if (load_corrupt_pages
  401. && !buf_page_is_zeroes(page, FIL_PAGE_DATA)) {
  402. /* Each valid page header must contain some
  403. nonzero bytes, such as FIL_PAGE_OFFSET
  404. or FIL_PAGE_LSN. */
  405. recv_dblwr.add(page);
  406. }
  407. page += UNIV_PAGE_SIZE;
  408. }
  409. if (reset_space_ids) {
  410. os_file_flush(file);
  411. }
  412. leave_func:
  413. ut_free(unaligned_read_buf);
  414. }
  415. /****************************************************************//**
  416. Process the double write buffer pages. */
  417. void
  418. buf_dblwr_process()
  419. /*===============*/
  420. {
  421. ulint space_id;
  422. ulint page_no;
  423. ulint page_no_dblwr = 0;
  424. byte* page;
  425. byte* read_buf;
  426. byte* unaligned_read_buf;
  427. recv_dblwr_t& recv_dblwr = recv_sys->dblwr;
  428. if (!buf_dblwr) {
  429. return;
  430. }
  431. ib_logf(IB_LOG_LEVEL_INFO,
  432. "Restoring possible half-written data pages "
  433. "from the doublewrite buffer...");
  434. unaligned_read_buf = static_cast<byte*>(ut_malloc(3 * UNIV_PAGE_SIZE));
  435. read_buf = static_cast<byte*>(
  436. ut_align(unaligned_read_buf, UNIV_PAGE_SIZE));
  437. byte* const buf = read_buf + UNIV_PAGE_SIZE;
  438. for (std::list<byte*>::iterator i = recv_dblwr.pages.begin();
  439. i != recv_dblwr.pages.end(); ++i, ++page_no_dblwr ) {
  440. page = *i;
  441. page_no = mach_read_from_4(page + FIL_PAGE_OFFSET);
  442. space_id = mach_read_from_4(page + FIL_PAGE_SPACE_ID);
  443. FilSpace space(space_id, true);
  444. if (!space()) {
  445. /* Maybe we have dropped the single-table tablespace
  446. and this page once belonged to it: do nothing */
  447. continue;
  448. }
  449. if (!space()->size) {
  450. fil_space_get_size(space_id);
  451. }
  452. if (UNIV_UNLIKELY(space()->size <= page_no)) {
  453. ib_logf(IB_LOG_LEVEL_WARN,
  454. "A copy of page " ULINTPF
  455. " in the doublewrite buffer slot " ULINTPF
  456. " is beyond the end of the tablespace "
  457. " %s (" ULINTPF " pages)",
  458. page_no, page_no_dblwr,
  459. space()->name, space()->size);
  460. continue;
  461. }
  462. ulint zip_size = fsp_flags_get_zip_size(space()->flags);
  463. ut_ad(!buf_page_is_zeroes(page, zip_size));
  464. /* Read in the actual page from the file */
  465. fil_io(OS_FILE_READ,
  466. true,
  467. space_id,
  468. zip_size,
  469. page_no,
  470. 0,
  471. zip_size ? zip_size : UNIV_PAGE_SIZE,
  472. read_buf,
  473. NULL,
  474. 0);
  475. const bool is_all_zero = buf_page_is_zeroes(
  476. read_buf, zip_size);
  477. const bool expect_encrypted = space()->crypt_data
  478. && space()->crypt_data->type
  479. != CRYPT_SCHEME_UNENCRYPTED;
  480. if (is_all_zero) {
  481. /* We will check if the copy in the
  482. doublewrite buffer is valid. If not, we will
  483. ignore this page (there should be redo log
  484. records to initialize it). */
  485. } else {
  486. /* Decompress the page before
  487. validating the checksum. */
  488. ulint decomp = fil_page_decompress(buf, read_buf);
  489. if (!decomp || (decomp != srv_page_size && zip_size)) {
  490. goto bad;
  491. }
  492. if (expect_encrypted && mach_read_from_4(
  493. read_buf
  494. + FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION)
  495. ? fil_space_verify_crypt_checksum(read_buf,
  496. zip_size)
  497. : !buf_page_is_corrupted(true, read_buf,
  498. zip_size, space())) {
  499. /* The page is good; there is no need
  500. to consult the doublewrite buffer. */
  501. continue;
  502. }
  503. bad:
  504. /* We intentionally skip this message for
  505. is_all_zero pages. */
  506. ib_logf(IB_LOG_LEVEL_INFO,
  507. "Trying to recover page " ULINTPF ":" ULINTPF
  508. " from the doublewrite buffer.",
  509. space_id, page_no);
  510. }
  511. ulint decomp = fil_page_decompress(buf, page);
  512. if (!decomp || (decomp != srv_page_size && zip_size)) {
  513. continue;
  514. }
  515. if (expect_encrypted && mach_read_from_4(
  516. page + FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION)
  517. ? !fil_space_verify_crypt_checksum(page, zip_size)
  518. : buf_page_is_corrupted(true, page, zip_size, space())) {
  519. /* Theoretically we could have another good
  520. copy for this page in the doublewrite
  521. buffer. If not, we will report a fatal error
  522. for a corrupted page somewhere else if that
  523. page was truly needed. */
  524. continue;
  525. }
  526. if (page_no == 0) {
  527. /* Check the FSP_SPACE_FLAGS. */
  528. ulint flags = fsp_header_get_flags(page);
  529. if (!fsp_flags_is_valid(flags, space_id)
  530. && fsp_flags_convert_from_101(flags)
  531. == ULINT_UNDEFINED) {
  532. ib_logf(IB_LOG_LEVEL_WARN,
  533. "Ignoring a doublewrite copy of page "
  534. ULINTPF ":0 due to invalid flags 0x%x",
  535. space_id, int(flags));
  536. continue;
  537. }
  538. /* The flags on the page should be converted later. */
  539. }
  540. /* Write the good page from the doublewrite buffer to
  541. the intended position. */
  542. fil_io(OS_FILE_WRITE, true, space_id, zip_size, page_no, 0,
  543. zip_size ? zip_size : UNIV_PAGE_SIZE,
  544. page, NULL, 0);
  545. ib_logf(IB_LOG_LEVEL_INFO,
  546. "Recovered page " ULINTPF ":" ULINTPF " from"
  547. " the doublewrite buffer.",
  548. space_id, page_no);
  549. }
  550. ut_free(unaligned_read_buf);
  551. fil_flush_file_spaces(FIL_TABLESPACE);
  552. {
  553. size_t bytes = TRX_SYS_DOUBLEWRITE_BLOCK_SIZE * UNIV_PAGE_SIZE;
  554. byte *unaligned_buf = static_cast<byte*>(
  555. ut_malloc(bytes + UNIV_PAGE_SIZE - 1));
  556. byte *buf = static_cast<byte*>(
  557. ut_align(unaligned_buf, UNIV_PAGE_SIZE));
  558. memset(buf, 0, bytes);
  559. fil_io(OS_FILE_WRITE, true, TRX_SYS_SPACE, 0,
  560. buf_dblwr->block1, 0, bytes, buf, NULL, NULL);
  561. fil_io(OS_FILE_WRITE, true, TRX_SYS_SPACE, 0,
  562. buf_dblwr->block2, 0, bytes, buf, NULL, NULL);
  563. ut_free(unaligned_buf);
  564. }
  565. }
  566. /****************************************************************//**
  567. Frees doublewrite buffer. */
  568. UNIV_INTERN
  569. void
  570. buf_dblwr_free(void)
  571. /*================*/
  572. {
  573. /* Free the double write data structures. */
  574. ut_a(buf_dblwr != NULL);
  575. ut_ad(buf_dblwr->s_reserved == 0);
  576. ut_ad(buf_dblwr->b_reserved == 0);
  577. os_event_free(buf_dblwr->b_event);
  578. os_event_free(buf_dblwr->s_event);
  579. ut_free(buf_dblwr->write_buf_unaligned);
  580. buf_dblwr->write_buf_unaligned = NULL;
  581. mem_free(buf_dblwr->buf_block_arr);
  582. buf_dblwr->buf_block_arr = NULL;
  583. mem_free(buf_dblwr->in_use);
  584. buf_dblwr->in_use = NULL;
  585. mutex_free(&buf_dblwr->mutex);
  586. mem_free(buf_dblwr);
  587. buf_dblwr = NULL;
  588. }
  589. /********************************************************************//**
  590. Updates the doublewrite buffer when an IO request is completed. */
  591. UNIV_INTERN
  592. void
  593. buf_dblwr_update(
  594. /*=============*/
  595. const buf_page_t* bpage, /*!< in: buffer block descriptor */
  596. buf_flush_t flush_type)/*!< in: flush type */
  597. {
  598. if (!srv_use_doublewrite_buf || buf_dblwr == NULL) {
  599. return;
  600. }
  601. switch (flush_type) {
  602. case BUF_FLUSH_LIST:
  603. case BUF_FLUSH_LRU:
  604. mutex_enter(&buf_dblwr->mutex);
  605. ut_ad(buf_dblwr->batch_running);
  606. ut_ad(buf_dblwr->b_reserved > 0);
  607. ut_ad(buf_dblwr->b_reserved <= buf_dblwr->first_free);
  608. buf_dblwr->b_reserved--;
  609. if (buf_dblwr->b_reserved == 0) {
  610. mutex_exit(&buf_dblwr->mutex);
  611. /* This will finish the batch. Sync data files
  612. to the disk. */
  613. fil_flush_file_spaces(FIL_TABLESPACE);
  614. mutex_enter(&buf_dblwr->mutex);
  615. /* We can now reuse the doublewrite memory buffer: */
  616. buf_dblwr->first_free = 0;
  617. buf_dblwr->batch_running = false;
  618. os_event_set(buf_dblwr->b_event);
  619. }
  620. mutex_exit(&buf_dblwr->mutex);
  621. break;
  622. case BUF_FLUSH_SINGLE_PAGE:
  623. {
  624. const ulint size = TRX_SYS_DOUBLEWRITE_BLOCKS * TRX_SYS_DOUBLEWRITE_BLOCK_SIZE;
  625. ulint i;
  626. mutex_enter(&buf_dblwr->mutex);
  627. for (i = srv_doublewrite_batch_size; i < size; ++i) {
  628. if (buf_dblwr->buf_block_arr[i] == bpage) {
  629. buf_dblwr->s_reserved--;
  630. buf_dblwr->buf_block_arr[i] = NULL;
  631. buf_dblwr->in_use[i] = false;
  632. break;
  633. }
  634. }
  635. /* The block we are looking for must exist as a
  636. reserved block. */
  637. ut_a(i < size);
  638. }
  639. os_event_set(buf_dblwr->s_event);
  640. mutex_exit(&buf_dblwr->mutex);
  641. break;
  642. case BUF_FLUSH_N_TYPES:
  643. ut_error;
  644. }
  645. }
  646. /********************************************************************//**
  647. Check the LSN values on the page. */
  648. static
  649. void
  650. buf_dblwr_check_page_lsn(
  651. /*=====================*/
  652. const page_t* page) /*!< in: page to check */
  653. {
  654. ibool page_compressed = (mach_read_from_2(page+FIL_PAGE_TYPE) == FIL_PAGE_PAGE_COMPRESSED);
  655. uint key_version = mach_read_from_4(page + FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION);
  656. /* Ignore page compressed or encrypted pages */
  657. if (page_compressed || key_version) {
  658. return;
  659. }
  660. if (memcmp(page + (FIL_PAGE_LSN + 4),
  661. page + (UNIV_PAGE_SIZE
  662. - FIL_PAGE_END_LSN_OLD_CHKSUM + 4),
  663. 4)) {
  664. ut_print_timestamp(stderr);
  665. fprintf(stderr,
  666. " InnoDB: ERROR: The page to be written"
  667. " seems corrupt!\n"
  668. "InnoDB: The low 4 bytes of LSN fields do not match "
  669. "(" ULINTPF " != " ULINTPF ")!"
  670. " Noticed in the buffer pool.\n",
  671. mach_read_from_4(
  672. page + FIL_PAGE_LSN + 4),
  673. mach_read_from_4(
  674. page + UNIV_PAGE_SIZE
  675. - FIL_PAGE_END_LSN_OLD_CHKSUM + 4));
  676. }
  677. }
  678. /********************************************************************//**
  679. Asserts when a corrupt block is find during writing out data to the
  680. disk. */
  681. static
  682. void
  683. buf_dblwr_assert_on_corrupt_block(
  684. /*==============================*/
  685. const buf_block_t* block) /*!< in: block to check */
  686. {
  687. buf_page_print(block->frame, 0);
  688. ut_print_timestamp(stderr);
  689. fprintf(stderr,
  690. " InnoDB: Apparent corruption of an"
  691. " index page n:o %lu in space %lu\n"
  692. "InnoDB: to be written to data file."
  693. " We intentionally crash server\n"
  694. "InnoDB: to prevent corrupt data"
  695. " from ending up in data\n"
  696. "InnoDB: files.\n",
  697. (ulong) buf_block_get_page_no(block),
  698. (ulong) buf_block_get_space(block));
  699. ut_error;
  700. }
  701. /********************************************************************//**
  702. Check the LSN values on the page with which this block is associated.
  703. Also validate the page if the option is set. */
  704. static
  705. void
  706. buf_dblwr_check_block(
  707. /*==================*/
  708. const buf_block_t* block) /*!< in: block to check */
  709. {
  710. if (buf_block_get_state(block) != BUF_BLOCK_FILE_PAGE
  711. || block->page.zip.data) {
  712. /* No simple validate for compressed pages exists. */
  713. return;
  714. }
  715. buf_dblwr_check_page_lsn(block->frame);
  716. if (!block->check_index_page_at_flush) {
  717. return;
  718. }
  719. if (page_is_comp(block->frame)) {
  720. if (!page_simple_validate_new(block->frame)) {
  721. buf_dblwr_assert_on_corrupt_block(block);
  722. }
  723. } else if (!page_simple_validate_old(block->frame)) {
  724. buf_dblwr_assert_on_corrupt_block(block);
  725. }
  726. }
  727. /********************************************************************//**
  728. Writes a page that has already been written to the doublewrite buffer
  729. to the datafile. It is the job of the caller to sync the datafile. */
  730. static
  731. void
  732. buf_dblwr_write_block_to_datafile(
  733. /*==============================*/
  734. const buf_page_t* bpage, /*!< in: page to write */
  735. bool sync) /*!< in: true if sync IO
  736. is requested */
  737. {
  738. ut_a(bpage);
  739. ut_a(buf_page_in_file(bpage));
  740. const ulint flags = sync
  741. ? OS_FILE_WRITE
  742. : OS_FILE_WRITE | OS_AIO_SIMULATED_WAKE_LATER;
  743. void * frame = buf_page_get_frame(bpage);
  744. if (bpage->zip.data) {
  745. fil_io(flags,
  746. sync,
  747. buf_page_get_space(bpage),
  748. buf_page_get_zip_size(bpage),
  749. buf_page_get_page_no(bpage),
  750. 0,
  751. buf_page_get_zip_size(bpage),
  752. frame,
  753. (void*) bpage,
  754. 0);
  755. return;
  756. }
  757. const buf_block_t* block = (buf_block_t*) bpage;
  758. ut_a(buf_block_get_state(block) == BUF_BLOCK_FILE_PAGE);
  759. buf_dblwr_check_page_lsn(block->frame);
  760. fil_io(flags,
  761. sync,
  762. buf_block_get_space(block),
  763. 0,
  764. buf_block_get_page_no(block),
  765. 0,
  766. bpage->real_size,
  767. frame,
  768. (void*) block,
  769. (ulint *)&bpage->write_size);
  770. }
  771. /********************************************************************//**
  772. Flushes possible buffered writes from the doublewrite memory buffer to disk,
  773. and also wakes up the aio thread if simulated aio is used. It is very
  774. important to call this function after a batch of writes has been posted,
  775. and also when we may have to wait for a page latch! Otherwise a deadlock
  776. of threads can occur. */
  777. UNIV_INTERN
  778. void
  779. buf_dblwr_flush_buffered_writes(void)
  780. /*=================================*/
  781. {
  782. byte* write_buf;
  783. ulint first_free;
  784. ulint len;
  785. if (!srv_use_doublewrite_buf || buf_dblwr == NULL) {
  786. /* Sync the writes to the disk. */
  787. buf_dblwr_sync_datafiles();
  788. return;
  789. }
  790. try_again:
  791. mutex_enter(&buf_dblwr->mutex);
  792. /* Write first to doublewrite buffer blocks. We use synchronous
  793. aio and thus know that file write has been completed when the
  794. control returns. */
  795. if (buf_dblwr->first_free == 0) {
  796. mutex_exit(&buf_dblwr->mutex);
  797. return;
  798. }
  799. if (buf_dblwr->batch_running) {
  800. /* Another thread is running the batch right now. Wait
  801. for it to finish. */
  802. ib_int64_t sig_count = os_event_reset(buf_dblwr->b_event);
  803. mutex_exit(&buf_dblwr->mutex);
  804. os_aio_simulated_wake_handler_threads();
  805. os_event_wait_low(buf_dblwr->b_event, sig_count);
  806. goto try_again;
  807. }
  808. ut_a(!buf_dblwr->batch_running);
  809. ut_ad(buf_dblwr->first_free == buf_dblwr->b_reserved);
  810. /* Disallow anyone else to post to doublewrite buffer or to
  811. start another batch of flushing. */
  812. buf_dblwr->batch_running = true;
  813. first_free = buf_dblwr->first_free;
  814. /* Now safe to release the mutex. Note that though no other
  815. thread is allowed to post to the doublewrite batch flushing
  816. but any threads working on single page flushes are allowed
  817. to proceed. */
  818. mutex_exit(&buf_dblwr->mutex);
  819. write_buf = buf_dblwr->write_buf;
  820. for (ulint len2 = 0, i = 0;
  821. i < buf_dblwr->first_free;
  822. len2 += UNIV_PAGE_SIZE, i++) {
  823. const buf_block_t* block;
  824. block = (buf_block_t*) buf_dblwr->buf_block_arr[i];
  825. if (buf_block_get_state(block) != BUF_BLOCK_FILE_PAGE
  826. || block->page.zip.data) {
  827. /* No simple validate for compressed
  828. pages exists. */
  829. continue;
  830. }
  831. /* Check that the actual page in the buffer pool is
  832. not corrupt and the LSN values are sane. */
  833. buf_dblwr_check_block(block);
  834. /* Check that the page as written to the doublewrite
  835. buffer has sane LSN values. */
  836. buf_dblwr_check_page_lsn(write_buf + len2);
  837. }
  838. /* Write out the first block of the doublewrite buffer */
  839. len = ut_min(TRX_SYS_DOUBLEWRITE_BLOCK_SIZE,
  840. buf_dblwr->first_free) * UNIV_PAGE_SIZE;
  841. fil_io(OS_FILE_WRITE,
  842. true,
  843. TRX_SYS_SPACE,
  844. 0,
  845. buf_dblwr->block1,
  846. 0,
  847. len,
  848. (void*)
  849. write_buf,
  850. NULL,
  851. 0);
  852. if (buf_dblwr->first_free <= TRX_SYS_DOUBLEWRITE_BLOCK_SIZE) {
  853. /* No unwritten pages in the second block. */
  854. goto flush;
  855. }
  856. /* Write out the second block of the doublewrite buffer. */
  857. len = (buf_dblwr->first_free - TRX_SYS_DOUBLEWRITE_BLOCK_SIZE)
  858. * UNIV_PAGE_SIZE;
  859. write_buf = buf_dblwr->write_buf
  860. + TRX_SYS_DOUBLEWRITE_BLOCK_SIZE * UNIV_PAGE_SIZE;
  861. fil_io(OS_FILE_WRITE,
  862. true,
  863. TRX_SYS_SPACE,
  864. 0,
  865. buf_dblwr->block2,
  866. 0,
  867. len,
  868. (void*) write_buf,
  869. NULL,
  870. 0);
  871. flush:
  872. /* increment the doublewrite flushed pages counter */
  873. srv_stats.dblwr_pages_written.add(buf_dblwr->first_free);
  874. srv_stats.dblwr_writes.inc();
  875. /* Now flush the doublewrite buffer data to disk */
  876. fil_flush(ulint(TRX_SYS_SPACE));
  877. /* We know that the writes have been flushed to disk now
  878. and in recovery we will find them in the doublewrite buffer
  879. blocks. Next do the writes to the intended positions. */
  880. /* Up to this point first_free and buf_dblwr->first_free are
  881. same because we have set the buf_dblwr->batch_running flag
  882. disallowing any other thread to post any request but we
  883. can't safely access buf_dblwr->first_free in the loop below.
  884. This is so because it is possible that after we are done with
  885. the last iteration and before we terminate the loop, the batch
  886. gets finished in the IO helper thread and another thread posts
  887. a new batch setting buf_dblwr->first_free to a higher value.
  888. If this happens and we are using buf_dblwr->first_free in the
  889. loop termination condition then we'll end up dispatching
  890. the same block twice from two different threads. */
  891. ut_ad(first_free == buf_dblwr->first_free);
  892. for (ulint i = 0; i < first_free; i++) {
  893. buf_dblwr_write_block_to_datafile(
  894. buf_dblwr->buf_block_arr[i], false);
  895. }
  896. /* Wake possible simulated aio thread to actually post the
  897. writes to the operating system. We don't flush the files
  898. at this point. We leave it to the IO helper thread to flush
  899. datafiles when the whole batch has been processed. */
  900. os_aio_simulated_wake_handler_threads();
  901. }
  902. /********************************************************************//**
  903. Posts a buffer page for writing. If the doublewrite memory buffer is
  904. full, calls buf_dblwr_flush_buffered_writes and waits for for free
  905. space to appear. */
  906. UNIV_INTERN
  907. void
  908. buf_dblwr_add_to_batch(
  909. /*====================*/
  910. buf_page_t* bpage) /*!< in: buffer block to write */
  911. {
  912. ulint zip_size;
  913. ut_a(buf_page_in_file(bpage));
  914. ut_ad(!mutex_own(&buf_pool_from_bpage(bpage)->LRU_list_mutex));
  915. try_again:
  916. mutex_enter(&buf_dblwr->mutex);
  917. ut_a(buf_dblwr->first_free <= srv_doublewrite_batch_size);
  918. if (buf_dblwr->batch_running) {
  919. /* This not nearly as bad as it looks. There is only
  920. page_cleaner thread which does background flushing
  921. in batches therefore it is unlikely to be a contention
  922. point. The only exception is when a user thread is
  923. forced to do a flush batch because of a sync
  924. checkpoint. */
  925. ib_int64_t sig_count = os_event_reset(buf_dblwr->b_event);
  926. mutex_exit(&buf_dblwr->mutex);
  927. os_aio_simulated_wake_handler_threads();
  928. os_event_wait_low(buf_dblwr->b_event, sig_count);
  929. goto try_again;
  930. }
  931. if (buf_dblwr->first_free == srv_doublewrite_batch_size) {
  932. mutex_exit(&(buf_dblwr->mutex));
  933. buf_dblwr_flush_buffered_writes();
  934. goto try_again;
  935. }
  936. zip_size = buf_page_get_zip_size(bpage);
  937. void * frame = buf_page_get_frame(bpage);
  938. if (zip_size) {
  939. UNIV_MEM_ASSERT_RW(bpage->zip.data, zip_size);
  940. /* Copy the compressed page and clear the rest. */
  941. memcpy(buf_dblwr->write_buf
  942. + UNIV_PAGE_SIZE * buf_dblwr->first_free,
  943. frame, zip_size);
  944. memset(buf_dblwr->write_buf
  945. + UNIV_PAGE_SIZE * buf_dblwr->first_free
  946. + zip_size, 0, UNIV_PAGE_SIZE - zip_size);
  947. } else {
  948. ut_a(buf_page_get_state(bpage) == BUF_BLOCK_FILE_PAGE);
  949. UNIV_MEM_ASSERT_RW(((buf_block_t*) bpage)->frame,
  950. UNIV_PAGE_SIZE);
  951. memcpy(buf_dblwr->write_buf
  952. + UNIV_PAGE_SIZE * buf_dblwr->first_free,
  953. frame, UNIV_PAGE_SIZE);
  954. }
  955. buf_dblwr->buf_block_arr[buf_dblwr->first_free] = bpage;
  956. buf_dblwr->first_free++;
  957. buf_dblwr->b_reserved++;
  958. ut_ad(!buf_dblwr->batch_running);
  959. ut_ad(buf_dblwr->first_free == buf_dblwr->b_reserved);
  960. ut_ad(buf_dblwr->b_reserved <= srv_doublewrite_batch_size);
  961. if (buf_dblwr->first_free == srv_doublewrite_batch_size) {
  962. mutex_exit(&(buf_dblwr->mutex));
  963. buf_dblwr_flush_buffered_writes();
  964. return;
  965. }
  966. mutex_exit(&(buf_dblwr->mutex));
  967. }
  968. /********************************************************************//**
  969. Writes a page to the doublewrite buffer on disk, sync it, then write
  970. the page to the datafile and sync the datafile. This function is used
  971. for single page flushes. If all the buffers allocated for single page
  972. flushes in the doublewrite buffer are in use we wait here for one to
  973. become free. We are guaranteed that a slot will become free because any
  974. thread that is using a slot must also release the slot before leaving
  975. this function. */
  976. UNIV_INTERN
  977. void
  978. buf_dblwr_write_single_page(
  979. /*========================*/
  980. buf_page_t* bpage, /*!< in: buffer block to write */
  981. bool sync) /*!< in: true if sync IO requested */
  982. {
  983. ulint n_slots;
  984. ulint size;
  985. ulint zip_size;
  986. ulint offset;
  987. ulint i;
  988. ut_a(buf_page_in_file(bpage));
  989. ut_a(srv_use_doublewrite_buf);
  990. ut_a(buf_dblwr != NULL);
  991. /* total number of slots available for single page flushes
  992. starts from srv_doublewrite_batch_size to the end of the
  993. buffer. */
  994. size = TRX_SYS_DOUBLEWRITE_BLOCKS * TRX_SYS_DOUBLEWRITE_BLOCK_SIZE;
  995. ut_a(size > srv_doublewrite_batch_size);
  996. n_slots = size - srv_doublewrite_batch_size;
  997. if (buf_page_get_state(bpage) == BUF_BLOCK_FILE_PAGE) {
  998. /* Check that the actual page in the buffer pool is
  999. not corrupt and the LSN values are sane. */
  1000. buf_dblwr_check_block((buf_block_t*) bpage);
  1001. /* Check that the page as written to the doublewrite
  1002. buffer has sane LSN values. */
  1003. if (!bpage->zip.data) {
  1004. buf_dblwr_check_page_lsn(
  1005. ((buf_block_t*) bpage)->frame);
  1006. }
  1007. }
  1008. retry:
  1009. mutex_enter(&buf_dblwr->mutex);
  1010. if (buf_dblwr->s_reserved == n_slots) {
  1011. /* All slots are reserved. */
  1012. ib_int64_t sig_count =
  1013. os_event_reset(buf_dblwr->s_event);
  1014. mutex_exit(&buf_dblwr->mutex);
  1015. os_event_wait_low(buf_dblwr->s_event, sig_count);
  1016. goto retry;
  1017. }
  1018. for (i = srv_doublewrite_batch_size; i < size; ++i) {
  1019. if (!buf_dblwr->in_use[i]) {
  1020. break;
  1021. }
  1022. }
  1023. /* We are guaranteed to find a slot. */
  1024. ut_a(i < size);
  1025. buf_dblwr->in_use[i] = true;
  1026. buf_dblwr->s_reserved++;
  1027. buf_dblwr->buf_block_arr[i] = bpage;
  1028. /* increment the doublewrite flushed pages counter */
  1029. srv_stats.dblwr_pages_written.inc();
  1030. srv_stats.dblwr_writes.inc();
  1031. mutex_exit(&buf_dblwr->mutex);
  1032. /* Lets see if we are going to write in the first or second
  1033. block of the doublewrite buffer. */
  1034. if (i < TRX_SYS_DOUBLEWRITE_BLOCK_SIZE) {
  1035. offset = buf_dblwr->block1 + i;
  1036. } else {
  1037. offset = buf_dblwr->block2 + i
  1038. - TRX_SYS_DOUBLEWRITE_BLOCK_SIZE;
  1039. }
  1040. /* We deal with compressed and uncompressed pages a little
  1041. differently here. In case of uncompressed pages we can
  1042. directly write the block to the allocated slot in the
  1043. doublewrite buffer in the system tablespace and then after
  1044. syncing the system table space we can proceed to write the page
  1045. in the datafile.
  1046. In case of compressed page we first do a memcpy of the block
  1047. to the in-memory buffer of doublewrite before proceeding to
  1048. write it. This is so because we want to pad the remaining
  1049. bytes in the doublewrite page with zeros. */
  1050. zip_size = buf_page_get_zip_size(bpage);
  1051. void * frame = buf_page_get_frame(bpage);
  1052. if (zip_size) {
  1053. memcpy(buf_dblwr->write_buf + UNIV_PAGE_SIZE * i,
  1054. frame, zip_size);
  1055. memset(buf_dblwr->write_buf + UNIV_PAGE_SIZE * i
  1056. + zip_size, 0, UNIV_PAGE_SIZE - zip_size);
  1057. fil_io(OS_FILE_WRITE,
  1058. true,
  1059. TRX_SYS_SPACE,
  1060. 0,
  1061. offset,
  1062. 0,
  1063. UNIV_PAGE_SIZE,
  1064. (void*) (buf_dblwr->write_buf + UNIV_PAGE_SIZE * i),
  1065. NULL,
  1066. 0);
  1067. } else {
  1068. /* It is a regular page. Write it directly to the
  1069. doublewrite buffer */
  1070. fil_io(OS_FILE_WRITE,
  1071. true,
  1072. TRX_SYS_SPACE,
  1073. 0,
  1074. offset,
  1075. 0,
  1076. bpage->real_size,
  1077. frame,
  1078. NULL,
  1079. 0);
  1080. }
  1081. /* Now flush the doublewrite buffer data to disk */
  1082. fil_flush(ulint(TRX_SYS_SPACE));
  1083. /* We know that the write has been flushed to disk now
  1084. and during recovery we will find it in the doublewrite buffer
  1085. blocks. Next do the write to the intended position. */
  1086. buf_dblwr_write_block_to_datafile(bpage, sync);
  1087. }
  1088. #endif /* !UNIV_HOTBACKUP */