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.

5115 lines
138 KiB

12 years ago
10 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
12 years ago
12 years ago
12 years ago
11 years ago
11 years ago
11 years ago
11 years ago
MDEV-12634: Uninitialised ROW_MERGE_RESERVE_SIZE bytes written to tem… …porary file Fixed by removing writing key version to start of every block that was encrypted. Instead we will use single key version from log_sys crypt info. After this MDEV also blocks writen to row log are encrypted and blocks read from row log aren decrypted if encryption is configured for the table. innodb_status_variables[], struct srv_stats_t Added status variables for merge block and row log block encryption and decryption amounts. Removed ROW_MERGE_RESERVE_SIZE define. row_merge_fts_doc_tokenize Remove ROW_MERGE_RESERVE_SIZE row_log_t Add index, crypt_tail, crypt_head to be used in case of encryption. row_log_online_op, row_log_table_close_func Before writing a block encrypt it if encryption is enabled row_log_table_apply_ops, row_log_apply_ops After reading a block decrypt it if encryption is enabled row_log_allocate Allocate temporary buffers crypt_head and crypt_tail if needed. row_log_free Free temporary buffers crypt_head and crypt_tail if they exist. row_merge_encrypt_buf, row_merge_decrypt_buf Removed. row_merge_buf_create, row_merge_buf_write Remove ROW_MERGE_RESERVE_SIZE row_merge_build_indexes Allocate temporary buffer used in decryption and encryption if needed. log_tmp_blocks_crypt, log_tmp_block_encrypt, log_temp_block_decrypt New functions used in block encryption and decryption log_tmp_is_encrypted New function to check is encryption enabled. Added test case innodb-rowlog to force creating a row log and verify that operations are done using introduced status variables.
8 years ago
11 years ago
10 years ago
MDEV-12634: Uninitialised ROW_MERGE_RESERVE_SIZE bytes written to tem… …porary file Fixed by removing writing key version to start of every block that was encrypted. Instead we will use single key version from log_sys crypt info. After this MDEV also blocks writen to row log are encrypted and blocks read from row log aren decrypted if encryption is configured for the table. innodb_status_variables[], struct srv_stats_t Added status variables for merge block and row log block encryption and decryption amounts. Removed ROW_MERGE_RESERVE_SIZE define. row_merge_fts_doc_tokenize Remove ROW_MERGE_RESERVE_SIZE row_log_t Add index, crypt_tail, crypt_head to be used in case of encryption. row_log_online_op, row_log_table_close_func Before writing a block encrypt it if encryption is enabled row_log_table_apply_ops, row_log_apply_ops After reading a block decrypt it if encryption is enabled row_log_allocate Allocate temporary buffers crypt_head and crypt_tail if needed. row_log_free Free temporary buffers crypt_head and crypt_tail if they exist. row_merge_encrypt_buf, row_merge_decrypt_buf Removed. row_merge_buf_create, row_merge_buf_write Remove ROW_MERGE_RESERVE_SIZE row_merge_build_indexes Allocate temporary buffer used in decryption and encryption if needed. log_tmp_blocks_crypt, log_tmp_block_encrypt, log_temp_block_decrypt New functions used in block encryption and decryption log_tmp_is_encrypted New function to check is encryption enabled. Added test case innodb-rowlog to force creating a row log and verify that operations are done using introduced status variables.
8 years ago
MDEV-12634: Uninitialised ROW_MERGE_RESERVE_SIZE bytes written to tem… …porary file Fixed by removing writing key version to start of every block that was encrypted. Instead we will use single key version from log_sys crypt info. After this MDEV also blocks writen to row log are encrypted and blocks read from row log aren decrypted if encryption is configured for the table. innodb_status_variables[], struct srv_stats_t Added status variables for merge block and row log block encryption and decryption amounts. Removed ROW_MERGE_RESERVE_SIZE define. row_merge_fts_doc_tokenize Remove ROW_MERGE_RESERVE_SIZE row_log_t Add index, crypt_tail, crypt_head to be used in case of encryption. row_log_online_op, row_log_table_close_func Before writing a block encrypt it if encryption is enabled row_log_table_apply_ops, row_log_apply_ops After reading a block decrypt it if encryption is enabled row_log_allocate Allocate temporary buffers crypt_head and crypt_tail if needed. row_log_free Free temporary buffers crypt_head and crypt_tail if they exist. row_merge_encrypt_buf, row_merge_decrypt_buf Removed. row_merge_buf_create, row_merge_buf_write Remove ROW_MERGE_RESERVE_SIZE row_merge_build_indexes Allocate temporary buffer used in decryption and encryption if needed. log_tmp_blocks_crypt, log_tmp_block_encrypt, log_temp_block_decrypt New functions used in block encryption and decryption log_tmp_is_encrypted New function to check is encryption enabled. Added test case innodb-rowlog to force creating a row log and verify that operations are done using introduced status variables.
8 years ago
MDEV-12634: Uninitialised ROW_MERGE_RESERVE_SIZE bytes written to tem… …porary file Fixed by removing writing key version to start of every block that was encrypted. Instead we will use single key version from log_sys crypt info. After this MDEV also blocks writen to row log are encrypted and blocks read from row log aren decrypted if encryption is configured for the table. innodb_status_variables[], struct srv_stats_t Added status variables for merge block and row log block encryption and decryption amounts. Removed ROW_MERGE_RESERVE_SIZE define. row_merge_fts_doc_tokenize Remove ROW_MERGE_RESERVE_SIZE row_log_t Add index, crypt_tail, crypt_head to be used in case of encryption. row_log_online_op, row_log_table_close_func Before writing a block encrypt it if encryption is enabled row_log_table_apply_ops, row_log_apply_ops After reading a block decrypt it if encryption is enabled row_log_allocate Allocate temporary buffers crypt_head and crypt_tail if needed. row_log_free Free temporary buffers crypt_head and crypt_tail if they exist. row_merge_encrypt_buf, row_merge_decrypt_buf Removed. row_merge_buf_create, row_merge_buf_write Remove ROW_MERGE_RESERVE_SIZE row_merge_build_indexes Allocate temporary buffer used in decryption and encryption if needed. log_tmp_blocks_crypt, log_tmp_block_encrypt, log_temp_block_decrypt New functions used in block encryption and decryption log_tmp_is_encrypted New function to check is encryption enabled. Added test case innodb-rowlog to force creating a row log and verify that operations are done using introduced status variables.
8 years ago
MDEV-12634: Uninitialised ROW_MERGE_RESERVE_SIZE bytes written to tem… …porary file Fixed by removing writing key version to start of every block that was encrypted. Instead we will use single key version from log_sys crypt info. After this MDEV also blocks writen to row log are encrypted and blocks read from row log aren decrypted if encryption is configured for the table. innodb_status_variables[], struct srv_stats_t Added status variables for merge block and row log block encryption and decryption amounts. Removed ROW_MERGE_RESERVE_SIZE define. row_merge_fts_doc_tokenize Remove ROW_MERGE_RESERVE_SIZE row_log_t Add index, crypt_tail, crypt_head to be used in case of encryption. row_log_online_op, row_log_table_close_func Before writing a block encrypt it if encryption is enabled row_log_table_apply_ops, row_log_apply_ops After reading a block decrypt it if encryption is enabled row_log_allocate Allocate temporary buffers crypt_head and crypt_tail if needed. row_log_free Free temporary buffers crypt_head and crypt_tail if they exist. row_merge_encrypt_buf, row_merge_decrypt_buf Removed. row_merge_buf_create, row_merge_buf_write Remove ROW_MERGE_RESERVE_SIZE row_merge_build_indexes Allocate temporary buffer used in decryption and encryption if needed. log_tmp_blocks_crypt, log_tmp_block_encrypt, log_temp_block_decrypt New functions used in block encryption and decryption log_tmp_is_encrypted New function to check is encryption enabled. Added test case innodb-rowlog to force creating a row log and verify that operations are done using introduced status variables.
8 years ago
MDEV-12634: Uninitialised ROW_MERGE_RESERVE_SIZE bytes written to tem… …porary file Fixed by removing writing key version to start of every block that was encrypted. Instead we will use single key version from log_sys crypt info. After this MDEV also blocks writen to row log are encrypted and blocks read from row log aren decrypted if encryption is configured for the table. innodb_status_variables[], struct srv_stats_t Added status variables for merge block and row log block encryption and decryption amounts. Removed ROW_MERGE_RESERVE_SIZE define. row_merge_fts_doc_tokenize Remove ROW_MERGE_RESERVE_SIZE row_log_t Add index, crypt_tail, crypt_head to be used in case of encryption. row_log_online_op, row_log_table_close_func Before writing a block encrypt it if encryption is enabled row_log_table_apply_ops, row_log_apply_ops After reading a block decrypt it if encryption is enabled row_log_allocate Allocate temporary buffers crypt_head and crypt_tail if needed. row_log_free Free temporary buffers crypt_head and crypt_tail if they exist. row_merge_encrypt_buf, row_merge_decrypt_buf Removed. row_merge_buf_create, row_merge_buf_write Remove ROW_MERGE_RESERVE_SIZE row_merge_build_indexes Allocate temporary buffer used in decryption and encryption if needed. log_tmp_blocks_crypt, log_tmp_block_encrypt, log_temp_block_decrypt New functions used in block encryption and decryption log_tmp_is_encrypted New function to check is encryption enabled. Added test case innodb-rowlog to force creating a row log and verify that operations are done using introduced status variables.
8 years ago
MDEV-12634: Uninitialised ROW_MERGE_RESERVE_SIZE bytes written to tem… …porary file Fixed by removing writing key version to start of every block that was encrypted. Instead we will use single key version from log_sys crypt info. After this MDEV also blocks writen to row log are encrypted and blocks read from row log aren decrypted if encryption is configured for the table. innodb_status_variables[], struct srv_stats_t Added status variables for merge block and row log block encryption and decryption amounts. Removed ROW_MERGE_RESERVE_SIZE define. row_merge_fts_doc_tokenize Remove ROW_MERGE_RESERVE_SIZE row_log_t Add index, crypt_tail, crypt_head to be used in case of encryption. row_log_online_op, row_log_table_close_func Before writing a block encrypt it if encryption is enabled row_log_table_apply_ops, row_log_apply_ops After reading a block decrypt it if encryption is enabled row_log_allocate Allocate temporary buffers crypt_head and crypt_tail if needed. row_log_free Free temporary buffers crypt_head and crypt_tail if they exist. row_merge_encrypt_buf, row_merge_decrypt_buf Removed. row_merge_buf_create, row_merge_buf_write Remove ROW_MERGE_RESERVE_SIZE row_merge_build_indexes Allocate temporary buffer used in decryption and encryption if needed. log_tmp_blocks_crypt, log_tmp_block_encrypt, log_temp_block_decrypt New functions used in block encryption and decryption log_tmp_is_encrypted New function to check is encryption enabled. Added test case innodb-rowlog to force creating a row log and verify that operations are done using introduced status variables.
8 years ago
MDEV-12634: Uninitialised ROW_MERGE_RESERVE_SIZE bytes written to tem… …porary file Fixed by removing writing key version to start of every block that was encrypted. Instead we will use single key version from log_sys crypt info. After this MDEV also blocks writen to row log are encrypted and blocks read from row log aren decrypted if encryption is configured for the table. innodb_status_variables[], struct srv_stats_t Added status variables for merge block and row log block encryption and decryption amounts. Removed ROW_MERGE_RESERVE_SIZE define. row_merge_fts_doc_tokenize Remove ROW_MERGE_RESERVE_SIZE row_log_t Add index, crypt_tail, crypt_head to be used in case of encryption. row_log_online_op, row_log_table_close_func Before writing a block encrypt it if encryption is enabled row_log_table_apply_ops, row_log_apply_ops After reading a block decrypt it if encryption is enabled row_log_allocate Allocate temporary buffers crypt_head and crypt_tail if needed. row_log_free Free temporary buffers crypt_head and crypt_tail if they exist. row_merge_encrypt_buf, row_merge_decrypt_buf Removed. row_merge_buf_create, row_merge_buf_write Remove ROW_MERGE_RESERVE_SIZE row_merge_build_indexes Allocate temporary buffer used in decryption and encryption if needed. log_tmp_blocks_crypt, log_tmp_block_encrypt, log_temp_block_decrypt New functions used in block encryption and decryption log_tmp_is_encrypted New function to check is encryption enabled. Added test case innodb-rowlog to force creating a row log and verify that operations are done using introduced status variables.
8 years ago
MDEV-12634: Uninitialised ROW_MERGE_RESERVE_SIZE bytes written to tem… …porary file Fixed by removing writing key version to start of every block that was encrypted. Instead we will use single key version from log_sys crypt info. After this MDEV also blocks writen to row log are encrypted and blocks read from row log aren decrypted if encryption is configured for the table. innodb_status_variables[], struct srv_stats_t Added status variables for merge block and row log block encryption and decryption amounts. Removed ROW_MERGE_RESERVE_SIZE define. row_merge_fts_doc_tokenize Remove ROW_MERGE_RESERVE_SIZE row_log_t Add index, crypt_tail, crypt_head to be used in case of encryption. row_log_online_op, row_log_table_close_func Before writing a block encrypt it if encryption is enabled row_log_table_apply_ops, row_log_apply_ops After reading a block decrypt it if encryption is enabled row_log_allocate Allocate temporary buffers crypt_head and crypt_tail if needed. row_log_free Free temporary buffers crypt_head and crypt_tail if they exist. row_merge_encrypt_buf, row_merge_decrypt_buf Removed. row_merge_buf_create, row_merge_buf_write Remove ROW_MERGE_RESERVE_SIZE row_merge_build_indexes Allocate temporary buffer used in decryption and encryption if needed. log_tmp_blocks_crypt, log_tmp_block_encrypt, log_temp_block_decrypt New functions used in block encryption and decryption log_tmp_is_encrypted New function to check is encryption enabled. Added test case innodb-rowlog to force creating a row log and verify that operations are done using introduced status variables.
8 years ago
MDEV-12634: Uninitialised ROW_MERGE_RESERVE_SIZE bytes written to tem… …porary file Fixed by removing writing key version to start of every block that was encrypted. Instead we will use single key version from log_sys crypt info. After this MDEV also blocks writen to row log are encrypted and blocks read from row log aren decrypted if encryption is configured for the table. innodb_status_variables[], struct srv_stats_t Added status variables for merge block and row log block encryption and decryption amounts. Removed ROW_MERGE_RESERVE_SIZE define. row_merge_fts_doc_tokenize Remove ROW_MERGE_RESERVE_SIZE row_log_t Add index, crypt_tail, crypt_head to be used in case of encryption. row_log_online_op, row_log_table_close_func Before writing a block encrypt it if encryption is enabled row_log_table_apply_ops, row_log_apply_ops After reading a block decrypt it if encryption is enabled row_log_allocate Allocate temporary buffers crypt_head and crypt_tail if needed. row_log_free Free temporary buffers crypt_head and crypt_tail if they exist. row_merge_encrypt_buf, row_merge_decrypt_buf Removed. row_merge_buf_create, row_merge_buf_write Remove ROW_MERGE_RESERVE_SIZE row_merge_build_indexes Allocate temporary buffer used in decryption and encryption if needed. log_tmp_blocks_crypt, log_tmp_block_encrypt, log_temp_block_decrypt New functions used in block encryption and decryption log_tmp_is_encrypted New function to check is encryption enabled. Added test case innodb-rowlog to force creating a row log and verify that operations are done using introduced status variables.
8 years ago
MDEV-12634: Uninitialised ROW_MERGE_RESERVE_SIZE bytes written to tem… …porary file Fixed by removing writing key version to start of every block that was encrypted. Instead we will use single key version from log_sys crypt info. After this MDEV also blocks writen to row log are encrypted and blocks read from row log aren decrypted if encryption is configured for the table. innodb_status_variables[], struct srv_stats_t Added status variables for merge block and row log block encryption and decryption amounts. Removed ROW_MERGE_RESERVE_SIZE define. row_merge_fts_doc_tokenize Remove ROW_MERGE_RESERVE_SIZE row_log_t Add index, crypt_tail, crypt_head to be used in case of encryption. row_log_online_op, row_log_table_close_func Before writing a block encrypt it if encryption is enabled row_log_table_apply_ops, row_log_apply_ops After reading a block decrypt it if encryption is enabled row_log_allocate Allocate temporary buffers crypt_head and crypt_tail if needed. row_log_free Free temporary buffers crypt_head and crypt_tail if they exist. row_merge_encrypt_buf, row_merge_decrypt_buf Removed. row_merge_buf_create, row_merge_buf_write Remove ROW_MERGE_RESERVE_SIZE row_merge_build_indexes Allocate temporary buffer used in decryption and encryption if needed. log_tmp_blocks_crypt, log_tmp_block_encrypt, log_temp_block_decrypt New functions used in block encryption and decryption log_tmp_is_encrypted New function to check is encryption enabled. Added test case innodb-rowlog to force creating a row log and verify that operations are done using introduced status variables.
8 years ago
MDEV-12634: Uninitialised ROW_MERGE_RESERVE_SIZE bytes written to tem… …porary file Fixed by removing writing key version to start of every block that was encrypted. Instead we will use single key version from log_sys crypt info. After this MDEV also blocks writen to row log are encrypted and blocks read from row log aren decrypted if encryption is configured for the table. innodb_status_variables[], struct srv_stats_t Added status variables for merge block and row log block encryption and decryption amounts. Removed ROW_MERGE_RESERVE_SIZE define. row_merge_fts_doc_tokenize Remove ROW_MERGE_RESERVE_SIZE row_log_t Add index, crypt_tail, crypt_head to be used in case of encryption. row_log_online_op, row_log_table_close_func Before writing a block encrypt it if encryption is enabled row_log_table_apply_ops, row_log_apply_ops After reading a block decrypt it if encryption is enabled row_log_allocate Allocate temporary buffers crypt_head and crypt_tail if needed. row_log_free Free temporary buffers crypt_head and crypt_tail if they exist. row_merge_encrypt_buf, row_merge_decrypt_buf Removed. row_merge_buf_create, row_merge_buf_write Remove ROW_MERGE_RESERVE_SIZE row_merge_build_indexes Allocate temporary buffer used in decryption and encryption if needed. log_tmp_blocks_crypt, log_tmp_block_encrypt, log_temp_block_decrypt New functions used in block encryption and decryption log_tmp_is_encrypted New function to check is encryption enabled. Added test case innodb-rowlog to force creating a row log and verify that operations are done using introduced status variables.
8 years ago
MDEV-12634: Uninitialised ROW_MERGE_RESERVE_SIZE bytes written to tem… …porary file Fixed by removing writing key version to start of every block that was encrypted. Instead we will use single key version from log_sys crypt info. After this MDEV also blocks writen to row log are encrypted and blocks read from row log aren decrypted if encryption is configured for the table. innodb_status_variables[], struct srv_stats_t Added status variables for merge block and row log block encryption and decryption amounts. Removed ROW_MERGE_RESERVE_SIZE define. row_merge_fts_doc_tokenize Remove ROW_MERGE_RESERVE_SIZE row_log_t Add index, crypt_tail, crypt_head to be used in case of encryption. row_log_online_op, row_log_table_close_func Before writing a block encrypt it if encryption is enabled row_log_table_apply_ops, row_log_apply_ops After reading a block decrypt it if encryption is enabled row_log_allocate Allocate temporary buffers crypt_head and crypt_tail if needed. row_log_free Free temporary buffers crypt_head and crypt_tail if they exist. row_merge_encrypt_buf, row_merge_decrypt_buf Removed. row_merge_buf_create, row_merge_buf_write Remove ROW_MERGE_RESERVE_SIZE row_merge_build_indexes Allocate temporary buffer used in decryption and encryption if needed. log_tmp_blocks_crypt, log_tmp_block_encrypt, log_temp_block_decrypt New functions used in block encryption and decryption log_tmp_is_encrypted New function to check is encryption enabled. Added test case innodb-rowlog to force creating a row log and verify that operations are done using introduced status variables.
8 years ago
MDEV-12634: Uninitialised ROW_MERGE_RESERVE_SIZE bytes written to tem… …porary file Fixed by removing writing key version to start of every block that was encrypted. Instead we will use single key version from log_sys crypt info. After this MDEV also blocks writen to row log are encrypted and blocks read from row log aren decrypted if encryption is configured for the table. innodb_status_variables[], struct srv_stats_t Added status variables for merge block and row log block encryption and decryption amounts. Removed ROW_MERGE_RESERVE_SIZE define. row_merge_fts_doc_tokenize Remove ROW_MERGE_RESERVE_SIZE row_log_t Add index, crypt_tail, crypt_head to be used in case of encryption. row_log_online_op, row_log_table_close_func Before writing a block encrypt it if encryption is enabled row_log_table_apply_ops, row_log_apply_ops After reading a block decrypt it if encryption is enabled row_log_allocate Allocate temporary buffers crypt_head and crypt_tail if needed. row_log_free Free temporary buffers crypt_head and crypt_tail if they exist. row_merge_encrypt_buf, row_merge_decrypt_buf Removed. row_merge_buf_create, row_merge_buf_write Remove ROW_MERGE_RESERVE_SIZE row_merge_build_indexes Allocate temporary buffer used in decryption and encryption if needed. log_tmp_blocks_crypt, log_tmp_block_encrypt, log_temp_block_decrypt New functions used in block encryption and decryption log_tmp_is_encrypted New function to check is encryption enabled. Added test case innodb-rowlog to force creating a row log and verify that operations are done using introduced status variables.
8 years ago
MDEV-12634: Uninitialised ROW_MERGE_RESERVE_SIZE bytes written to tem… …porary file Fixed by removing writing key version to start of every block that was encrypted. Instead we will use single key version from log_sys crypt info. After this MDEV also blocks writen to row log are encrypted and blocks read from row log aren decrypted if encryption is configured for the table. innodb_status_variables[], struct srv_stats_t Added status variables for merge block and row log block encryption and decryption amounts. Removed ROW_MERGE_RESERVE_SIZE define. row_merge_fts_doc_tokenize Remove ROW_MERGE_RESERVE_SIZE row_log_t Add index, crypt_tail, crypt_head to be used in case of encryption. row_log_online_op, row_log_table_close_func Before writing a block encrypt it if encryption is enabled row_log_table_apply_ops, row_log_apply_ops After reading a block decrypt it if encryption is enabled row_log_allocate Allocate temporary buffers crypt_head and crypt_tail if needed. row_log_free Free temporary buffers crypt_head and crypt_tail if they exist. row_merge_encrypt_buf, row_merge_decrypt_buf Removed. row_merge_buf_create, row_merge_buf_write Remove ROW_MERGE_RESERVE_SIZE row_merge_build_indexes Allocate temporary buffer used in decryption and encryption if needed. log_tmp_blocks_crypt, log_tmp_block_encrypt, log_temp_block_decrypt New functions used in block encryption and decryption log_tmp_is_encrypted New function to check is encryption enabled. Added test case innodb-rowlog to force creating a row log and verify that operations are done using introduced status variables.
8 years ago
MDEV-12634: Uninitialised ROW_MERGE_RESERVE_SIZE bytes written to tem… …porary file Fixed by removing writing key version to start of every block that was encrypted. Instead we will use single key version from log_sys crypt info. After this MDEV also blocks writen to row log are encrypted and blocks read from row log aren decrypted if encryption is configured for the table. innodb_status_variables[], struct srv_stats_t Added status variables for merge block and row log block encryption and decryption amounts. Removed ROW_MERGE_RESERVE_SIZE define. row_merge_fts_doc_tokenize Remove ROW_MERGE_RESERVE_SIZE row_log_t Add index, crypt_tail, crypt_head to be used in case of encryption. row_log_online_op, row_log_table_close_func Before writing a block encrypt it if encryption is enabled row_log_table_apply_ops, row_log_apply_ops After reading a block decrypt it if encryption is enabled row_log_allocate Allocate temporary buffers crypt_head and crypt_tail if needed. row_log_free Free temporary buffers crypt_head and crypt_tail if they exist. row_merge_encrypt_buf, row_merge_decrypt_buf Removed. row_merge_buf_create, row_merge_buf_write Remove ROW_MERGE_RESERVE_SIZE row_merge_build_indexes Allocate temporary buffer used in decryption and encryption if needed. log_tmp_blocks_crypt, log_tmp_block_encrypt, log_temp_block_decrypt New functions used in block encryption and decryption log_tmp_is_encrypted New function to check is encryption enabled. Added test case innodb-rowlog to force creating a row log and verify that operations are done using introduced status variables.
8 years ago
MDEV-12634: Uninitialised ROW_MERGE_RESERVE_SIZE bytes written to tem… …porary file Fixed by removing writing key version to start of every block that was encrypted. Instead we will use single key version from log_sys crypt info. After this MDEV also blocks writen to row log are encrypted and blocks read from row log aren decrypted if encryption is configured for the table. innodb_status_variables[], struct srv_stats_t Added status variables for merge block and row log block encryption and decryption amounts. Removed ROW_MERGE_RESERVE_SIZE define. row_merge_fts_doc_tokenize Remove ROW_MERGE_RESERVE_SIZE row_log_t Add index, crypt_tail, crypt_head to be used in case of encryption. row_log_online_op, row_log_table_close_func Before writing a block encrypt it if encryption is enabled row_log_table_apply_ops, row_log_apply_ops After reading a block decrypt it if encryption is enabled row_log_allocate Allocate temporary buffers crypt_head and crypt_tail if needed. row_log_free Free temporary buffers crypt_head and crypt_tail if they exist. row_merge_encrypt_buf, row_merge_decrypt_buf Removed. row_merge_buf_create, row_merge_buf_write Remove ROW_MERGE_RESERVE_SIZE row_merge_build_indexes Allocate temporary buffer used in decryption and encryption if needed. log_tmp_blocks_crypt, log_tmp_block_encrypt, log_temp_block_decrypt New functions used in block encryption and decryption log_tmp_is_encrypted New function to check is encryption enabled. Added test case innodb-rowlog to force creating a row log and verify that operations are done using introduced status variables.
8 years ago
MDEV-12634: Uninitialised ROW_MERGE_RESERVE_SIZE bytes written to tem… …porary file Fixed by removing writing key version to start of every block that was encrypted. Instead we will use single key version from log_sys crypt info. After this MDEV also blocks writen to row log are encrypted and blocks read from row log aren decrypted if encryption is configured for the table. innodb_status_variables[], struct srv_stats_t Added status variables for merge block and row log block encryption and decryption amounts. Removed ROW_MERGE_RESERVE_SIZE define. row_merge_fts_doc_tokenize Remove ROW_MERGE_RESERVE_SIZE row_log_t Add index, crypt_tail, crypt_head to be used in case of encryption. row_log_online_op, row_log_table_close_func Before writing a block encrypt it if encryption is enabled row_log_table_apply_ops, row_log_apply_ops After reading a block decrypt it if encryption is enabled row_log_allocate Allocate temporary buffers crypt_head and crypt_tail if needed. row_log_free Free temporary buffers crypt_head and crypt_tail if they exist. row_merge_encrypt_buf, row_merge_decrypt_buf Removed. row_merge_buf_create, row_merge_buf_write Remove ROW_MERGE_RESERVE_SIZE row_merge_build_indexes Allocate temporary buffer used in decryption and encryption if needed. log_tmp_blocks_crypt, log_tmp_block_encrypt, log_temp_block_decrypt New functions used in block encryption and decryption log_tmp_is_encrypted New function to check is encryption enabled. Added test case innodb-rowlog to force creating a row log and verify that operations are done using introduced status variables.
8 years ago
MDEV-12634: Uninitialised ROW_MERGE_RESERVE_SIZE bytes written to tem… …porary file Fixed by removing writing key version to start of every block that was encrypted. Instead we will use single key version from log_sys crypt info. After this MDEV also blocks writen to row log are encrypted and blocks read from row log aren decrypted if encryption is configured for the table. innodb_status_variables[], struct srv_stats_t Added status variables for merge block and row log block encryption and decryption amounts. Removed ROW_MERGE_RESERVE_SIZE define. row_merge_fts_doc_tokenize Remove ROW_MERGE_RESERVE_SIZE row_log_t Add index, crypt_tail, crypt_head to be used in case of encryption. row_log_online_op, row_log_table_close_func Before writing a block encrypt it if encryption is enabled row_log_table_apply_ops, row_log_apply_ops After reading a block decrypt it if encryption is enabled row_log_allocate Allocate temporary buffers crypt_head and crypt_tail if needed. row_log_free Free temporary buffers crypt_head and crypt_tail if they exist. row_merge_encrypt_buf, row_merge_decrypt_buf Removed. row_merge_buf_create, row_merge_buf_write Remove ROW_MERGE_RESERVE_SIZE row_merge_build_indexes Allocate temporary buffer used in decryption and encryption if needed. log_tmp_blocks_crypt, log_tmp_block_encrypt, log_temp_block_decrypt New functions used in block encryption and decryption log_tmp_is_encrypted New function to check is encryption enabled. Added test case innodb-rowlog to force creating a row log and verify that operations are done using introduced status variables.
8 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
11 years ago
MDEV-13654 Various crashes due to DB_TRX_ID mismatch in table-rebuilding ALTER TABLE…LOCK=NONE After MDEV-12288 and MDEV-13536, the DB_TRX_ID of old clustered index records for which no history is available should be reset to 0. This caused crashes in online table-rebuilding ALTER, because the row_log_table_apply() is built on the assumption that the PRIMARY KEY together with DB_TRX_ID,DB_ROLL_PTR identifies the record. Both when copying the old table and when writing log about changes to the old table, we must map "old" DB_TRX_ID to 0. "old" here is simply "older than the trx_id of the ALTER TABLE transaction", because the MDL_EXCLUSIVE (and exclusive InnoDB table lock) in ha_innobase::prepare_inplace_alter_table() forces any transactions accessing the table to commit or rollback. So, we know that we can safely reset any DB_TRX_ID in the table that is older than the transaction ID of the ALTER TABLE, because the undo log history would be lost in a table-rebuilding ALTER. Note: After a table-rebuilding online ALTER TABLE, the rebuilt table may end up containing some nonzero DB_TRX_ID columns. The apply logic identifies the rows by the combination of PRIMARY KEY and DB_TRX_ID. These nonzero DB_TRX_ID would necessarily refer to concurrent DML operations that were started during ha_innobase::inplace_alter_table(). row_log_allocate(): Add a parameter for the ALTER TABLE transaction. row_log_t::min_trx: The ALTER TABLE transaction ID. trx_id_check(): A debug function to check that DB_TRX_ID makes sense (is either 0 or bigger than the ALTER TABLE transaction ID). reset_trx_id[]: The reset DB_TRX_ID,DB_ROLL_PTR columns. row_log_table_delete(), row_log_table_get_pk(): Reset the DB_TRX_ID,DB_ROLL_PTR when they precede the ALTER TABLE transaction. row_log_table_apply_delete(), row_log_table_apply_update(): Assert trx_id_check(). row_merge_insert_index_tuples(): Remove the unused parameter trx_id. row_merge_read_clustered_index(): In a table-rebuilding ALTER, reset the DB_TRX_ID,DB_ROLL_PTR when they precede the ALTER TABLE transaction. Assert trx_id_check() on clustered index records that are being buffered.
8 years ago
MDEV-13654 Various crashes due to DB_TRX_ID mismatch in table-rebuilding ALTER TABLE…LOCK=NONE After MDEV-12288 and MDEV-13536, the DB_TRX_ID of old clustered index records for which no history is available should be reset to 0. This caused crashes in online table-rebuilding ALTER, because the row_log_table_apply() is built on the assumption that the PRIMARY KEY together with DB_TRX_ID,DB_ROLL_PTR identifies the record. Both when copying the old table and when writing log about changes to the old table, we must map "old" DB_TRX_ID to 0. "old" here is simply "older than the trx_id of the ALTER TABLE transaction", because the MDL_EXCLUSIVE (and exclusive InnoDB table lock) in ha_innobase::prepare_inplace_alter_table() forces any transactions accessing the table to commit or rollback. So, we know that we can safely reset any DB_TRX_ID in the table that is older than the transaction ID of the ALTER TABLE, because the undo log history would be lost in a table-rebuilding ALTER. Note: After a table-rebuilding online ALTER TABLE, the rebuilt table may end up containing some nonzero DB_TRX_ID columns. The apply logic identifies the rows by the combination of PRIMARY KEY and DB_TRX_ID. These nonzero DB_TRX_ID would necessarily refer to concurrent DML operations that were started during ha_innobase::inplace_alter_table(). row_log_allocate(): Add a parameter for the ALTER TABLE transaction. row_log_t::min_trx: The ALTER TABLE transaction ID. trx_id_check(): A debug function to check that DB_TRX_ID makes sense (is either 0 or bigger than the ALTER TABLE transaction ID). reset_trx_id[]: The reset DB_TRX_ID,DB_ROLL_PTR columns. row_log_table_delete(), row_log_table_get_pk(): Reset the DB_TRX_ID,DB_ROLL_PTR when they precede the ALTER TABLE transaction. row_log_table_apply_delete(), row_log_table_apply_update(): Assert trx_id_check(). row_merge_insert_index_tuples(): Remove the unused parameter trx_id. row_merge_read_clustered_index(): In a table-rebuilding ALTER, reset the DB_TRX_ID,DB_ROLL_PTR when they precede the ALTER TABLE transaction. Assert trx_id_check() on clustered index records that are being buffered.
8 years ago
MDEV-11369 Instant ADD COLUMN for InnoDB For InnoDB tables, adding, dropping and reordering columns has required a rebuild of the table and all its indexes. Since MySQL 5.6 (and MariaDB 10.0) this has been supported online (LOCK=NONE), allowing concurrent modification of the tables. This work revises the InnoDB ROW_FORMAT=REDUNDANT, ROW_FORMAT=COMPACT and ROW_FORMAT=DYNAMIC so that columns can be appended instantaneously, with only minor changes performed to the table structure. The counter innodb_instant_alter_column in INFORMATION_SCHEMA.GLOBAL_STATUS is incremented whenever a table rebuild operation is converted into an instant ADD COLUMN operation. ROW_FORMAT=COMPRESSED tables will not support instant ADD COLUMN. Some usability limitations will be addressed in subsequent work: MDEV-13134 Introduce ALTER TABLE attributes ALGORITHM=NOCOPY and ALGORITHM=INSTANT MDEV-14016 Allow instant ADD COLUMN, ADD INDEX, LOCK=NONE The format of the clustered index (PRIMARY KEY) is changed as follows: (1) The FIL_PAGE_TYPE of the root page will be FIL_PAGE_TYPE_INSTANT, and a new field PAGE_INSTANT will contain the original number of fields in the clustered index ('core' fields). If instant ADD COLUMN has not been used or the table becomes empty, or the very first instant ADD COLUMN operation is rolled back, the fields PAGE_INSTANT and FIL_PAGE_TYPE will be reset to 0 and FIL_PAGE_INDEX. (2) A special 'default row' record is inserted into the leftmost leaf, between the page infimum and the first user record. This record is distinguished by the REC_INFO_MIN_REC_FLAG, and it is otherwise in the same format as records that contain values for the instantly added columns. This 'default row' always has the same number of fields as the clustered index according to the table definition. The values of 'core' fields are to be ignored. For other fields, the 'default row' will contain the default values as they were during the ALTER TABLE statement. (If the column default values are changed later, those values will only be stored in the .frm file. The 'default row' will contain the original evaluated values, which must be the same for every row.) The 'default row' must be completely hidden from higher-level access routines. Assertions have been added to ensure that no 'default row' is ever present in the adaptive hash index or in locked records. The 'default row' is never delete-marked. (3) In clustered index leaf page records, the number of fields must reside between the number of 'core' fields (dict_index_t::n_core_fields introduced in this work) and dict_index_t::n_fields. If the number of fields is less than dict_index_t::n_fields, the missing fields are replaced with the column value of the 'default row'. Note: The number of fields in the record may shrink if some of the last instantly added columns are updated to the value that is in the 'default row'. The function btr_cur_trim() implements this 'compression' on update and rollback; dtuple::trim() implements it on insert. (4) In ROW_FORMAT=COMPACT and ROW_FORMAT=DYNAMIC records, the new status value REC_STATUS_COLUMNS_ADDED will indicate the presence of a new record header that will encode n_fields-n_core_fields-1 in 1 or 2 bytes. (In ROW_FORMAT=REDUNDANT records, the record header always explicitly encodes the number of fields.) We introduce the undo log record type TRX_UNDO_INSERT_DEFAULT for covering the insert of the 'default row' record when instant ADD COLUMN is used for the first time. Subsequent instant ADD COLUMN can use TRX_UNDO_UPD_EXIST_REC. This is joint work with Vin Chen (陈福荣) from Tencent. The design that was discussed in April 2017 would not have allowed import or export of data files, because instead of the 'default row' it would have introduced a data dictionary table. The test rpl.rpl_alter_instant is exactly as contributed in pull request #408. The test innodb.instant_alter is based on a contributed test. The redo log record format changes for ROW_FORMAT=DYNAMIC and ROW_FORMAT=COMPACT are as contributed. (With this change present, crash recovery from MariaDB 10.3.1 will fail in spectacular ways!) Also the semantics of higher-level redo log records that modify the PAGE_INSTANT field is changed. The redo log format version identifier was already changed to LOG_HEADER_FORMAT_CURRENT=103 in MariaDB 10.3.1. Everything else has been rewritten by me. Thanks to Elena Stepanova, the code has been tested extensively. When rolling back an instant ADD COLUMN operation, we must empty the PAGE_FREE list after deleting or shortening the 'default row' record, by calling either btr_page_empty() or btr_page_reorganize(). We must know the size of each entry in the PAGE_FREE list. If rollback left a freed copy of the 'default row' in the PAGE_FREE list, we would be unable to determine its size (if it is in ROW_FORMAT=COMPACT or ROW_FORMAT=DYNAMIC) because it would contain more fields than the rolled-back definition of the clustered index. UNIV_SQL_DEFAULT: A new special constant that designates an instantly added column that is not present in the clustered index record. len_is_stored(): Check if a length is an actual length. There are two magic length values: UNIV_SQL_DEFAULT, UNIV_SQL_NULL. dict_col_t::def_val: The 'default row' value of the column. If the column is not added instantly, def_val.len will be UNIV_SQL_DEFAULT. dict_col_t: Add the accessors is_virtual(), is_nullable(), is_instant(), instant_value(). dict_col_t::remove_instant(): Remove the 'instant ADD' status of a column. dict_col_t::name(const dict_table_t& table): Replaces dict_table_get_col_name(). dict_index_t::n_core_fields: The original number of fields. For secondary indexes and if instant ADD COLUMN has not been used, this will be equal to dict_index_t::n_fields. dict_index_t::n_core_null_bytes: Number of bytes needed to represent the null flags; usually equal to UT_BITS_IN_BYTES(n_nullable). dict_index_t::NO_CORE_NULL_BYTES: Magic value signalling that n_core_null_bytes was not initialized yet from the clustered index root page. dict_index_t: Add the accessors is_instant(), is_clust(), get_n_nullable(), instant_field_value(). dict_index_t::instant_add_field(): Adjust clustered index metadata for instant ADD COLUMN. dict_index_t::remove_instant(): Remove the 'instant ADD' status of a clustered index when the table becomes empty, or the very first instant ADD COLUMN operation is rolled back. dict_table_t: Add the accessors is_instant(), is_temporary(), supports_instant(). dict_table_t::instant_add_column(): Adjust metadata for instant ADD COLUMN. dict_table_t::rollback_instant(): Adjust metadata on the rollback of instant ADD COLUMN. prepare_inplace_alter_table_dict(): First create the ctx->new_table, and only then decide if the table really needs to be rebuilt. We must split the creation of table or index metadata from the creation of the dictionary table records and the creation of the data. In this way, we can transform a table-rebuilding operation into an instant ADD COLUMN operation. Dictionary objects will only be added to cache when table rebuilding or index creation is needed. The ctx->instant_table will never be added to cache. dict_table_t::add_to_cache(): Modified and renamed from dict_table_add_to_cache(). Do not modify the table metadata. Let the callers invoke dict_table_add_system_columns() and if needed, set can_be_evicted. dict_create_sys_tables_tuple(), dict_create_table_step(): Omit the system columns (which will now exist in the dict_table_t object already at this point). dict_create_table_step(): Expect the callers to invoke dict_table_add_system_columns(). pars_create_table(): Before creating the table creation execution graph, invoke dict_table_add_system_columns(). row_create_table_for_mysql(): Expect all callers to invoke dict_table_add_system_columns(). create_index_dict(): Replaces row_merge_create_index_graph(). innodb_update_n_cols(): Renamed from innobase_update_n_virtual(). Call my_error() if an error occurs. btr_cur_instant_init(), btr_cur_instant_init_low(), btr_cur_instant_root_init(): Load additional metadata from the clustered index and set dict_index_t::n_core_null_bytes. This is invoked when table metadata is first loaded into the data dictionary. dict_boot(): Initialize n_core_null_bytes for the four hard-coded dictionary tables. dict_create_index_step(): Initialize n_core_null_bytes. This is executed as part of CREATE TABLE. dict_index_build_internal_clust(): Initialize n_core_null_bytes to NO_CORE_NULL_BYTES if table->supports_instant(). row_create_index_for_mysql(): Initialize n_core_null_bytes for CREATE TEMPORARY TABLE. commit_cache_norebuild(): Call the code to rename or enlarge columns in the cache only if instant ADD COLUMN is not being used. (Instant ADD COLUMN would copy all column metadata from instant_table to old_table, including the names and lengths.) PAGE_INSTANT: A new 13-bit field for storing dict_index_t::n_core_fields. This is repurposing the 16-bit field PAGE_DIRECTION, of which only the least significant 3 bits were used. The original byte containing PAGE_DIRECTION will be accessible via the new constant PAGE_DIRECTION_B. page_get_instant(), page_set_instant(): Accessors for the PAGE_INSTANT. page_ptr_get_direction(), page_get_direction(), page_ptr_set_direction(): Accessors for PAGE_DIRECTION. page_direction_reset(): Reset PAGE_DIRECTION, PAGE_N_DIRECTION. page_direction_increment(): Increment PAGE_N_DIRECTION and set PAGE_DIRECTION. rec_get_offsets(): Use the 'leaf' parameter for non-debug purposes, and assume that heap_no is always set. Initialize all dict_index_t::n_fields for ROW_FORMAT=REDUNDANT records, even if the record contains fewer fields. rec_offs_make_valid(): Add the parameter 'leaf'. rec_copy_prefix_to_dtuple(): Assert that the tuple is only built on the core fields. Instant ADD COLUMN only applies to the clustered index, and we should never build a search key that has more than the PRIMARY KEY and possibly DB_TRX_ID,DB_ROLL_PTR. All these columns are always present. dict_index_build_data_tuple(): Remove assertions that would be duplicated in rec_copy_prefix_to_dtuple(). rec_init_offsets(): Support ROW_FORMAT=REDUNDANT records whose number of fields is between n_core_fields and n_fields. cmp_rec_rec_with_match(): Implement the comparison between two MIN_REC_FLAG records. trx_t::in_rollback: Make the field available in non-debug builds. trx_start_for_ddl_low(): Remove dangerous error-tolerance. A dictionary transaction must be flagged as such before it has generated any undo log records. This is because trx_undo_assign_undo() will mark the transaction as a dictionary transaction in the undo log header right before the very first undo log record is being written. btr_index_rec_validate(): Account for instant ADD COLUMN row_undo_ins_remove_clust_rec(): On the rollback of an insert into SYS_COLUMNS, revert instant ADD COLUMN in the cache by removing the last column from the table and the clustered index. row_search_on_row_ref(), row_undo_mod_parse_undo_rec(), row_undo_mod(), trx_undo_update_rec_get_update(): Handle the 'default row' as a special case. dtuple_t::trim(index): Omit a redundant suffix of an index tuple right before insert or update. After instant ADD COLUMN, if the last fields of a clustered index tuple match the 'default row', there is no need to store them. While trimming the entry, we must hold a page latch, so that the table cannot be emptied and the 'default row' be deleted. btr_cur_optimistic_update(), btr_cur_pessimistic_update(), row_upd_clust_rec_by_insert(), row_ins_clust_index_entry_low(): Invoke dtuple_t::trim() if needed. row_ins_clust_index_entry(): Restore dtuple_t::n_fields after calling row_ins_clust_index_entry_low(). rec_get_converted_size(), rec_get_converted_size_comp(): Allow the number of fields to be between n_core_fields and n_fields. Do not support infimum,supremum. They are never supposed to be stored in dtuple_t, because page creation nowadays uses a lower-level method for initializing them. rec_convert_dtuple_to_rec_comp(): Assign the status bits based on the number of fields. btr_cur_trim(): In an update, trim the index entry as needed. For the 'default row', handle rollback specially. For user records, omit fields that match the 'default row'. btr_cur_optimistic_delete_func(), btr_cur_pessimistic_delete(): Skip locking and adaptive hash index for the 'default row'. row_log_table_apply_convert_mrec(): Replace 'default row' values if needed. In the temporary file that is applied by row_log_table_apply(), we must identify whether the records contain the extra header for instantly added columns. For now, we will allocate an additional byte for this for ROW_T_INSERT and ROW_T_UPDATE records when the source table has been subject to instant ADD COLUMN. The ROW_T_DELETE records are fine, as they will be converted and will only contain 'core' columns (PRIMARY KEY and some system columns) that are converted from dtuple_t. rec_get_converted_size_temp(), rec_init_offsets_temp(), rec_convert_dtuple_to_temp(): Add the parameter 'status'. REC_INFO_DEFAULT_ROW = REC_INFO_MIN_REC_FLAG | REC_STATUS_COLUMNS_ADDED: An info_bits constant for distinguishing the 'default row' record. rec_comp_status_t: An enum of the status bit values. rec_leaf_format: An enum that replaces the bool parameter of rec_init_offsets_comp_ordinary().
8 years ago
11 years ago
MDEV-13654 Various crashes due to DB_TRX_ID mismatch in table-rebuilding ALTER TABLE…LOCK=NONE After MDEV-12288 and MDEV-13536, the DB_TRX_ID of old clustered index records for which no history is available should be reset to 0. This caused crashes in online table-rebuilding ALTER, because the row_log_table_apply() is built on the assumption that the PRIMARY KEY together with DB_TRX_ID,DB_ROLL_PTR identifies the record. Both when copying the old table and when writing log about changes to the old table, we must map "old" DB_TRX_ID to 0. "old" here is simply "older than the trx_id of the ALTER TABLE transaction", because the MDL_EXCLUSIVE (and exclusive InnoDB table lock) in ha_innobase::prepare_inplace_alter_table() forces any transactions accessing the table to commit or rollback. So, we know that we can safely reset any DB_TRX_ID in the table that is older than the transaction ID of the ALTER TABLE, because the undo log history would be lost in a table-rebuilding ALTER. Note: After a table-rebuilding online ALTER TABLE, the rebuilt table may end up containing some nonzero DB_TRX_ID columns. The apply logic identifies the rows by the combination of PRIMARY KEY and DB_TRX_ID. These nonzero DB_TRX_ID would necessarily refer to concurrent DML operations that were started during ha_innobase::inplace_alter_table(). row_log_allocate(): Add a parameter for the ALTER TABLE transaction. row_log_t::min_trx: The ALTER TABLE transaction ID. trx_id_check(): A debug function to check that DB_TRX_ID makes sense (is either 0 or bigger than the ALTER TABLE transaction ID). reset_trx_id[]: The reset DB_TRX_ID,DB_ROLL_PTR columns. row_log_table_delete(), row_log_table_get_pk(): Reset the DB_TRX_ID,DB_ROLL_PTR when they precede the ALTER TABLE transaction. row_log_table_apply_delete(), row_log_table_apply_update(): Assert trx_id_check(). row_merge_insert_index_tuples(): Remove the unused parameter trx_id. row_merge_read_clustered_index(): In a table-rebuilding ALTER, reset the DB_TRX_ID,DB_ROLL_PTR when they precede the ALTER TABLE transaction. Assert trx_id_check() on clustered index records that are being buffered.
8 years ago
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-13654 Various crashes due to DB_TRX_ID mismatch in table-rebuilding ALTER TABLE…LOCK=NONE After MDEV-12288 and MDEV-13536, the DB_TRX_ID of old clustered index records for which no history is available should be reset to 0. This caused crashes in online table-rebuilding ALTER, because the row_log_table_apply() is built on the assumption that the PRIMARY KEY together with DB_TRX_ID,DB_ROLL_PTR identifies the record. Both when copying the old table and when writing log about changes to the old table, we must map "old" DB_TRX_ID to 0. "old" here is simply "older than the trx_id of the ALTER TABLE transaction", because the MDL_EXCLUSIVE (and exclusive InnoDB table lock) in ha_innobase::prepare_inplace_alter_table() forces any transactions accessing the table to commit or rollback. So, we know that we can safely reset any DB_TRX_ID in the table that is older than the transaction ID of the ALTER TABLE, because the undo log history would be lost in a table-rebuilding ALTER. Note: After a table-rebuilding online ALTER TABLE, the rebuilt table may end up containing some nonzero DB_TRX_ID columns. The apply logic identifies the rows by the combination of PRIMARY KEY and DB_TRX_ID. These nonzero DB_TRX_ID would necessarily refer to concurrent DML operations that were started during ha_innobase::inplace_alter_table(). row_log_allocate(): Add a parameter for the ALTER TABLE transaction. row_log_t::min_trx: The ALTER TABLE transaction ID. trx_id_check(): A debug function to check that DB_TRX_ID makes sense (is either 0 or bigger than the ALTER TABLE transaction ID). reset_trx_id[]: The reset DB_TRX_ID,DB_ROLL_PTR columns. row_log_table_delete(), row_log_table_get_pk(): Reset the DB_TRX_ID,DB_ROLL_PTR when they precede the ALTER TABLE transaction. row_log_table_apply_delete(), row_log_table_apply_update(): Assert trx_id_check(). row_merge_insert_index_tuples(): Remove the unused parameter trx_id. row_merge_read_clustered_index(): In a table-rebuilding ALTER, reset the DB_TRX_ID,DB_ROLL_PTR when they precede the ALTER TABLE transaction. Assert trx_id_check() on clustered index records that are being buffered.
8 years ago
MDEV-13654 Various crashes due to DB_TRX_ID mismatch in table-rebuilding ALTER TABLE…LOCK=NONE After MDEV-12288 and MDEV-13536, the DB_TRX_ID of old clustered index records for which no history is available should be reset to 0. This caused crashes in online table-rebuilding ALTER, because the row_log_table_apply() is built on the assumption that the PRIMARY KEY together with DB_TRX_ID,DB_ROLL_PTR identifies the record. Both when copying the old table and when writing log about changes to the old table, we must map "old" DB_TRX_ID to 0. "old" here is simply "older than the trx_id of the ALTER TABLE transaction", because the MDL_EXCLUSIVE (and exclusive InnoDB table lock) in ha_innobase::prepare_inplace_alter_table() forces any transactions accessing the table to commit or rollback. So, we know that we can safely reset any DB_TRX_ID in the table that is older than the transaction ID of the ALTER TABLE, because the undo log history would be lost in a table-rebuilding ALTER. Note: After a table-rebuilding online ALTER TABLE, the rebuilt table may end up containing some nonzero DB_TRX_ID columns. The apply logic identifies the rows by the combination of PRIMARY KEY and DB_TRX_ID. These nonzero DB_TRX_ID would necessarily refer to concurrent DML operations that were started during ha_innobase::inplace_alter_table(). row_log_allocate(): Add a parameter for the ALTER TABLE transaction. row_log_t::min_trx: The ALTER TABLE transaction ID. trx_id_check(): A debug function to check that DB_TRX_ID makes sense (is either 0 or bigger than the ALTER TABLE transaction ID). reset_trx_id[]: The reset DB_TRX_ID,DB_ROLL_PTR columns. row_log_table_delete(), row_log_table_get_pk(): Reset the DB_TRX_ID,DB_ROLL_PTR when they precede the ALTER TABLE transaction. row_log_table_apply_delete(), row_log_table_apply_update(): Assert trx_id_check(). row_merge_insert_index_tuples(): Remove the unused parameter trx_id. row_merge_read_clustered_index(): In a table-rebuilding ALTER, reset the DB_TRX_ID,DB_ROLL_PTR when they precede the ALTER TABLE transaction. Assert trx_id_check() on clustered index records that are being buffered.
8 years ago
MDEV-13654 Various crashes due to DB_TRX_ID mismatch in table-rebuilding ALTER TABLE…LOCK=NONE After MDEV-12288 and MDEV-13536, the DB_TRX_ID of old clustered index records for which no history is available should be reset to 0. This caused crashes in online table-rebuilding ALTER, because the row_log_table_apply() is built on the assumption that the PRIMARY KEY together with DB_TRX_ID,DB_ROLL_PTR identifies the record. Both when copying the old table and when writing log about changes to the old table, we must map "old" DB_TRX_ID to 0. "old" here is simply "older than the trx_id of the ALTER TABLE transaction", because the MDL_EXCLUSIVE (and exclusive InnoDB table lock) in ha_innobase::prepare_inplace_alter_table() forces any transactions accessing the table to commit or rollback. So, we know that we can safely reset any DB_TRX_ID in the table that is older than the transaction ID of the ALTER TABLE, because the undo log history would be lost in a table-rebuilding ALTER. Note: After a table-rebuilding online ALTER TABLE, the rebuilt table may end up containing some nonzero DB_TRX_ID columns. The apply logic identifies the rows by the combination of PRIMARY KEY and DB_TRX_ID. These nonzero DB_TRX_ID would necessarily refer to concurrent DML operations that were started during ha_innobase::inplace_alter_table(). row_log_allocate(): Add a parameter for the ALTER TABLE transaction. row_log_t::min_trx: The ALTER TABLE transaction ID. trx_id_check(): A debug function to check that DB_TRX_ID makes sense (is either 0 or bigger than the ALTER TABLE transaction ID). reset_trx_id[]: The reset DB_TRX_ID,DB_ROLL_PTR columns. row_log_table_delete(), row_log_table_get_pk(): Reset the DB_TRX_ID,DB_ROLL_PTR when they precede the ALTER TABLE transaction. row_log_table_apply_delete(), row_log_table_apply_update(): Assert trx_id_check(). row_merge_insert_index_tuples(): Remove the unused parameter trx_id. row_merge_read_clustered_index(): In a table-rebuilding ALTER, reset the DB_TRX_ID,DB_ROLL_PTR when they precede the ALTER TABLE transaction. Assert trx_id_check() on clustered index records that are being buffered.
8 years ago
MDEV-13654 Various crashes due to DB_TRX_ID mismatch in table-rebuilding ALTER TABLE…LOCK=NONE After MDEV-12288 and MDEV-13536, the DB_TRX_ID of old clustered index records for which no history is available should be reset to 0. This caused crashes in online table-rebuilding ALTER, because the row_log_table_apply() is built on the assumption that the PRIMARY KEY together with DB_TRX_ID,DB_ROLL_PTR identifies the record. Both when copying the old table and when writing log about changes to the old table, we must map "old" DB_TRX_ID to 0. "old" here is simply "older than the trx_id of the ALTER TABLE transaction", because the MDL_EXCLUSIVE (and exclusive InnoDB table lock) in ha_innobase::prepare_inplace_alter_table() forces any transactions accessing the table to commit or rollback. So, we know that we can safely reset any DB_TRX_ID in the table that is older than the transaction ID of the ALTER TABLE, because the undo log history would be lost in a table-rebuilding ALTER. Note: After a table-rebuilding online ALTER TABLE, the rebuilt table may end up containing some nonzero DB_TRX_ID columns. The apply logic identifies the rows by the combination of PRIMARY KEY and DB_TRX_ID. These nonzero DB_TRX_ID would necessarily refer to concurrent DML operations that were started during ha_innobase::inplace_alter_table(). row_log_allocate(): Add a parameter for the ALTER TABLE transaction. row_log_t::min_trx: The ALTER TABLE transaction ID. trx_id_check(): A debug function to check that DB_TRX_ID makes sense (is either 0 or bigger than the ALTER TABLE transaction ID). reset_trx_id[]: The reset DB_TRX_ID,DB_ROLL_PTR columns. row_log_table_delete(), row_log_table_get_pk(): Reset the DB_TRX_ID,DB_ROLL_PTR when they precede the ALTER TABLE transaction. row_log_table_apply_delete(), row_log_table_apply_update(): Assert trx_id_check(). row_merge_insert_index_tuples(): Remove the unused parameter trx_id. row_merge_read_clustered_index(): In a table-rebuilding ALTER, reset the DB_TRX_ID,DB_ROLL_PTR when they precede the ALTER TABLE transaction. Assert trx_id_check() on clustered index records that are being buffered.
8 years ago
MDEV-13654 Various crashes due to DB_TRX_ID mismatch in table-rebuilding ALTER TABLE…LOCK=NONE After MDEV-12288 and MDEV-13536, the DB_TRX_ID of old clustered index records for which no history is available should be reset to 0. This caused crashes in online table-rebuilding ALTER, because the row_log_table_apply() is built on the assumption that the PRIMARY KEY together with DB_TRX_ID,DB_ROLL_PTR identifies the record. Both when copying the old table and when writing log about changes to the old table, we must map "old" DB_TRX_ID to 0. "old" here is simply "older than the trx_id of the ALTER TABLE transaction", because the MDL_EXCLUSIVE (and exclusive InnoDB table lock) in ha_innobase::prepare_inplace_alter_table() forces any transactions accessing the table to commit or rollback. So, we know that we can safely reset any DB_TRX_ID in the table that is older than the transaction ID of the ALTER TABLE, because the undo log history would be lost in a table-rebuilding ALTER. Note: After a table-rebuilding online ALTER TABLE, the rebuilt table may end up containing some nonzero DB_TRX_ID columns. The apply logic identifies the rows by the combination of PRIMARY KEY and DB_TRX_ID. These nonzero DB_TRX_ID would necessarily refer to concurrent DML operations that were started during ha_innobase::inplace_alter_table(). row_log_allocate(): Add a parameter for the ALTER TABLE transaction. row_log_t::min_trx: The ALTER TABLE transaction ID. trx_id_check(): A debug function to check that DB_TRX_ID makes sense (is either 0 or bigger than the ALTER TABLE transaction ID). reset_trx_id[]: The reset DB_TRX_ID,DB_ROLL_PTR columns. row_log_table_delete(), row_log_table_get_pk(): Reset the DB_TRX_ID,DB_ROLL_PTR when they precede the ALTER TABLE transaction. row_log_table_apply_delete(), row_log_table_apply_update(): Assert trx_id_check(). row_merge_insert_index_tuples(): Remove the unused parameter trx_id. row_merge_read_clustered_index(): In a table-rebuilding ALTER, reset the DB_TRX_ID,DB_ROLL_PTR when they precede the ALTER TABLE transaction. Assert trx_id_check() on clustered index records that are being buffered.
8 years ago
MDEV-13654 Various crashes due to DB_TRX_ID mismatch in table-rebuilding ALTER TABLE…LOCK=NONE After MDEV-12288 and MDEV-13536, the DB_TRX_ID of old clustered index records for which no history is available should be reset to 0. This caused crashes in online table-rebuilding ALTER, because the row_log_table_apply() is built on the assumption that the PRIMARY KEY together with DB_TRX_ID,DB_ROLL_PTR identifies the record. Both when copying the old table and when writing log about changes to the old table, we must map "old" DB_TRX_ID to 0. "old" here is simply "older than the trx_id of the ALTER TABLE transaction", because the MDL_EXCLUSIVE (and exclusive InnoDB table lock) in ha_innobase::prepare_inplace_alter_table() forces any transactions accessing the table to commit or rollback. So, we know that we can safely reset any DB_TRX_ID in the table that is older than the transaction ID of the ALTER TABLE, because the undo log history would be lost in a table-rebuilding ALTER. Note: After a table-rebuilding online ALTER TABLE, the rebuilt table may end up containing some nonzero DB_TRX_ID columns. The apply logic identifies the rows by the combination of PRIMARY KEY and DB_TRX_ID. These nonzero DB_TRX_ID would necessarily refer to concurrent DML operations that were started during ha_innobase::inplace_alter_table(). row_log_allocate(): Add a parameter for the ALTER TABLE transaction. row_log_t::min_trx: The ALTER TABLE transaction ID. trx_id_check(): A debug function to check that DB_TRX_ID makes sense (is either 0 or bigger than the ALTER TABLE transaction ID). reset_trx_id[]: The reset DB_TRX_ID,DB_ROLL_PTR columns. row_log_table_delete(), row_log_table_get_pk(): Reset the DB_TRX_ID,DB_ROLL_PTR when they precede the ALTER TABLE transaction. row_log_table_apply_delete(), row_log_table_apply_update(): Assert trx_id_check(). row_merge_insert_index_tuples(): Remove the unused parameter trx_id. row_merge_read_clustered_index(): In a table-rebuilding ALTER, reset the DB_TRX_ID,DB_ROLL_PTR when they precede the ALTER TABLE transaction. Assert trx_id_check() on clustered index records that are being buffered.
8 years ago
MDEV-13654 Various crashes due to DB_TRX_ID mismatch in table-rebuilding ALTER TABLE…LOCK=NONE After MDEV-12288 and MDEV-13536, the DB_TRX_ID of old clustered index records for which no history is available should be reset to 0. This caused crashes in online table-rebuilding ALTER, because the row_log_table_apply() is built on the assumption that the PRIMARY KEY together with DB_TRX_ID,DB_ROLL_PTR identifies the record. Both when copying the old table and when writing log about changes to the old table, we must map "old" DB_TRX_ID to 0. "old" here is simply "older than the trx_id of the ALTER TABLE transaction", because the MDL_EXCLUSIVE (and exclusive InnoDB table lock) in ha_innobase::prepare_inplace_alter_table() forces any transactions accessing the table to commit or rollback. So, we know that we can safely reset any DB_TRX_ID in the table that is older than the transaction ID of the ALTER TABLE, because the undo log history would be lost in a table-rebuilding ALTER. Note: After a table-rebuilding online ALTER TABLE, the rebuilt table may end up containing some nonzero DB_TRX_ID columns. The apply logic identifies the rows by the combination of PRIMARY KEY and DB_TRX_ID. These nonzero DB_TRX_ID would necessarily refer to concurrent DML operations that were started during ha_innobase::inplace_alter_table(). row_log_allocate(): Add a parameter for the ALTER TABLE transaction. row_log_t::min_trx: The ALTER TABLE transaction ID. trx_id_check(): A debug function to check that DB_TRX_ID makes sense (is either 0 or bigger than the ALTER TABLE transaction ID). reset_trx_id[]: The reset DB_TRX_ID,DB_ROLL_PTR columns. row_log_table_delete(), row_log_table_get_pk(): Reset the DB_TRX_ID,DB_ROLL_PTR when they precede the ALTER TABLE transaction. row_log_table_apply_delete(), row_log_table_apply_update(): Assert trx_id_check(). row_merge_insert_index_tuples(): Remove the unused parameter trx_id. row_merge_read_clustered_index(): In a table-rebuilding ALTER, reset the DB_TRX_ID,DB_ROLL_PTR when they precede the ALTER TABLE transaction. Assert trx_id_check() on clustered index records that are being buffered.
8 years ago
MDEV-13654 Various crashes due to DB_TRX_ID mismatch in table-rebuilding ALTER TABLE…LOCK=NONE After MDEV-12288 and MDEV-13536, the DB_TRX_ID of old clustered index records for which no history is available should be reset to 0. This caused crashes in online table-rebuilding ALTER, because the row_log_table_apply() is built on the assumption that the PRIMARY KEY together with DB_TRX_ID,DB_ROLL_PTR identifies the record. Both when copying the old table and when writing log about changes to the old table, we must map "old" DB_TRX_ID to 0. "old" here is simply "older than the trx_id of the ALTER TABLE transaction", because the MDL_EXCLUSIVE (and exclusive InnoDB table lock) in ha_innobase::prepare_inplace_alter_table() forces any transactions accessing the table to commit or rollback. So, we know that we can safely reset any DB_TRX_ID in the table that is older than the transaction ID of the ALTER TABLE, because the undo log history would be lost in a table-rebuilding ALTER. Note: After a table-rebuilding online ALTER TABLE, the rebuilt table may end up containing some nonzero DB_TRX_ID columns. The apply logic identifies the rows by the combination of PRIMARY KEY and DB_TRX_ID. These nonzero DB_TRX_ID would necessarily refer to concurrent DML operations that were started during ha_innobase::inplace_alter_table(). row_log_allocate(): Add a parameter for the ALTER TABLE transaction. row_log_t::min_trx: The ALTER TABLE transaction ID. trx_id_check(): A debug function to check that DB_TRX_ID makes sense (is either 0 or bigger than the ALTER TABLE transaction ID). reset_trx_id[]: The reset DB_TRX_ID,DB_ROLL_PTR columns. row_log_table_delete(), row_log_table_get_pk(): Reset the DB_TRX_ID,DB_ROLL_PTR when they precede the ALTER TABLE transaction. row_log_table_apply_delete(), row_log_table_apply_update(): Assert trx_id_check(). row_merge_insert_index_tuples(): Remove the unused parameter trx_id. row_merge_read_clustered_index(): In a table-rebuilding ALTER, reset the DB_TRX_ID,DB_ROLL_PTR when they precede the ALTER TABLE transaction. Assert trx_id_check() on clustered index records that are being buffered.
8 years ago
MDEV-13654 Various crashes due to DB_TRX_ID mismatch in table-rebuilding ALTER TABLE…LOCK=NONE After MDEV-12288 and MDEV-13536, the DB_TRX_ID of old clustered index records for which no history is available should be reset to 0. This caused crashes in online table-rebuilding ALTER, because the row_log_table_apply() is built on the assumption that the PRIMARY KEY together with DB_TRX_ID,DB_ROLL_PTR identifies the record. Both when copying the old table and when writing log about changes to the old table, we must map "old" DB_TRX_ID to 0. "old" here is simply "older than the trx_id of the ALTER TABLE transaction", because the MDL_EXCLUSIVE (and exclusive InnoDB table lock) in ha_innobase::prepare_inplace_alter_table() forces any transactions accessing the table to commit or rollback. So, we know that we can safely reset any DB_TRX_ID in the table that is older than the transaction ID of the ALTER TABLE, because the undo log history would be lost in a table-rebuilding ALTER. Note: After a table-rebuilding online ALTER TABLE, the rebuilt table may end up containing some nonzero DB_TRX_ID columns. The apply logic identifies the rows by the combination of PRIMARY KEY and DB_TRX_ID. These nonzero DB_TRX_ID would necessarily refer to concurrent DML operations that were started during ha_innobase::inplace_alter_table(). row_log_allocate(): Add a parameter for the ALTER TABLE transaction. row_log_t::min_trx: The ALTER TABLE transaction ID. trx_id_check(): A debug function to check that DB_TRX_ID makes sense (is either 0 or bigger than the ALTER TABLE transaction ID). reset_trx_id[]: The reset DB_TRX_ID,DB_ROLL_PTR columns. row_log_table_delete(), row_log_table_get_pk(): Reset the DB_TRX_ID,DB_ROLL_PTR when they precede the ALTER TABLE transaction. row_log_table_apply_delete(), row_log_table_apply_update(): Assert trx_id_check(). row_merge_insert_index_tuples(): Remove the unused parameter trx_id. row_merge_read_clustered_index(): In a table-rebuilding ALTER, reset the DB_TRX_ID,DB_ROLL_PTR when they precede the ALTER TABLE transaction. Assert trx_id_check() on clustered index records that are being buffered.
8 years ago
MDEV-13654 Various crashes due to DB_TRX_ID mismatch in table-rebuilding ALTER TABLE…LOCK=NONE After MDEV-12288 and MDEV-13536, the DB_TRX_ID of old clustered index records for which no history is available should be reset to 0. This caused crashes in online table-rebuilding ALTER, because the row_log_table_apply() is built on the assumption that the PRIMARY KEY together with DB_TRX_ID,DB_ROLL_PTR identifies the record. Both when copying the old table and when writing log about changes to the old table, we must map "old" DB_TRX_ID to 0. "old" here is simply "older than the trx_id of the ALTER TABLE transaction", because the MDL_EXCLUSIVE (and exclusive InnoDB table lock) in ha_innobase::prepare_inplace_alter_table() forces any transactions accessing the table to commit or rollback. So, we know that we can safely reset any DB_TRX_ID in the table that is older than the transaction ID of the ALTER TABLE, because the undo log history would be lost in a table-rebuilding ALTER. Note: After a table-rebuilding online ALTER TABLE, the rebuilt table may end up containing some nonzero DB_TRX_ID columns. The apply logic identifies the rows by the combination of PRIMARY KEY and DB_TRX_ID. These nonzero DB_TRX_ID would necessarily refer to concurrent DML operations that were started during ha_innobase::inplace_alter_table(). row_log_allocate(): Add a parameter for the ALTER TABLE transaction. row_log_t::min_trx: The ALTER TABLE transaction ID. trx_id_check(): A debug function to check that DB_TRX_ID makes sense (is either 0 or bigger than the ALTER TABLE transaction ID). reset_trx_id[]: The reset DB_TRX_ID,DB_ROLL_PTR columns. row_log_table_delete(), row_log_table_get_pk(): Reset the DB_TRX_ID,DB_ROLL_PTR when they precede the ALTER TABLE transaction. row_log_table_apply_delete(), row_log_table_apply_update(): Assert trx_id_check(). row_merge_insert_index_tuples(): Remove the unused parameter trx_id. row_merge_read_clustered_index(): In a table-rebuilding ALTER, reset the DB_TRX_ID,DB_ROLL_PTR when they precede the ALTER TABLE transaction. Assert trx_id_check() on clustered index records that are being buffered.
8 years ago
MDEV-13654 Various crashes due to DB_TRX_ID mismatch in table-rebuilding ALTER TABLE…LOCK=NONE After MDEV-12288 and MDEV-13536, the DB_TRX_ID of old clustered index records for which no history is available should be reset to 0. This caused crashes in online table-rebuilding ALTER, because the row_log_table_apply() is built on the assumption that the PRIMARY KEY together with DB_TRX_ID,DB_ROLL_PTR identifies the record. Both when copying the old table and when writing log about changes to the old table, we must map "old" DB_TRX_ID to 0. "old" here is simply "older than the trx_id of the ALTER TABLE transaction", because the MDL_EXCLUSIVE (and exclusive InnoDB table lock) in ha_innobase::prepare_inplace_alter_table() forces any transactions accessing the table to commit or rollback. So, we know that we can safely reset any DB_TRX_ID in the table that is older than the transaction ID of the ALTER TABLE, because the undo log history would be lost in a table-rebuilding ALTER. Note: After a table-rebuilding online ALTER TABLE, the rebuilt table may end up containing some nonzero DB_TRX_ID columns. The apply logic identifies the rows by the combination of PRIMARY KEY and DB_TRX_ID. These nonzero DB_TRX_ID would necessarily refer to concurrent DML operations that were started during ha_innobase::inplace_alter_table(). row_log_allocate(): Add a parameter for the ALTER TABLE transaction. row_log_t::min_trx: The ALTER TABLE transaction ID. trx_id_check(): A debug function to check that DB_TRX_ID makes sense (is either 0 or bigger than the ALTER TABLE transaction ID). reset_trx_id[]: The reset DB_TRX_ID,DB_ROLL_PTR columns. row_log_table_delete(), row_log_table_get_pk(): Reset the DB_TRX_ID,DB_ROLL_PTR when they precede the ALTER TABLE transaction. row_log_table_apply_delete(), row_log_table_apply_update(): Assert trx_id_check(). row_merge_insert_index_tuples(): Remove the unused parameter trx_id. row_merge_read_clustered_index(): In a table-rebuilding ALTER, reset the DB_TRX_ID,DB_ROLL_PTR when they precede the ALTER TABLE transaction. Assert trx_id_check() on clustered index records that are being buffered.
8 years ago
MDEV-13654 Various crashes due to DB_TRX_ID mismatch in table-rebuilding ALTER TABLE…LOCK=NONE After MDEV-12288 and MDEV-13536, the DB_TRX_ID of old clustered index records for which no history is available should be reset to 0. This caused crashes in online table-rebuilding ALTER, because the row_log_table_apply() is built on the assumption that the PRIMARY KEY together with DB_TRX_ID,DB_ROLL_PTR identifies the record. Both when copying the old table and when writing log about changes to the old table, we must map "old" DB_TRX_ID to 0. "old" here is simply "older than the trx_id of the ALTER TABLE transaction", because the MDL_EXCLUSIVE (and exclusive InnoDB table lock) in ha_innobase::prepare_inplace_alter_table() forces any transactions accessing the table to commit or rollback. So, we know that we can safely reset any DB_TRX_ID in the table that is older than the transaction ID of the ALTER TABLE, because the undo log history would be lost in a table-rebuilding ALTER. Note: After a table-rebuilding online ALTER TABLE, the rebuilt table may end up containing some nonzero DB_TRX_ID columns. The apply logic identifies the rows by the combination of PRIMARY KEY and DB_TRX_ID. These nonzero DB_TRX_ID would necessarily refer to concurrent DML operations that were started during ha_innobase::inplace_alter_table(). row_log_allocate(): Add a parameter for the ALTER TABLE transaction. row_log_t::min_trx: The ALTER TABLE transaction ID. trx_id_check(): A debug function to check that DB_TRX_ID makes sense (is either 0 or bigger than the ALTER TABLE transaction ID). reset_trx_id[]: The reset DB_TRX_ID,DB_ROLL_PTR columns. row_log_table_delete(), row_log_table_get_pk(): Reset the DB_TRX_ID,DB_ROLL_PTR when they precede the ALTER TABLE transaction. row_log_table_apply_delete(), row_log_table_apply_update(): Assert trx_id_check(). row_merge_insert_index_tuples(): Remove the unused parameter trx_id. row_merge_read_clustered_index(): In a table-rebuilding ALTER, reset the DB_TRX_ID,DB_ROLL_PTR when they precede the ALTER TABLE transaction. Assert trx_id_check() on clustered index records that are being buffered.
8 years ago
11 years ago
11 years ago
11 years ago
12 years ago
12 years ago
12 years ago
MDEV-13654 Various crashes due to DB_TRX_ID mismatch in table-rebuilding ALTER TABLE…LOCK=NONE After MDEV-12288 and MDEV-13536, the DB_TRX_ID of old clustered index records for which no history is available should be reset to 0. This caused crashes in online table-rebuilding ALTER, because the row_log_table_apply() is built on the assumption that the PRIMARY KEY together with DB_TRX_ID,DB_ROLL_PTR identifies the record. Both when copying the old table and when writing log about changes to the old table, we must map "old" DB_TRX_ID to 0. "old" here is simply "older than the trx_id of the ALTER TABLE transaction", because the MDL_EXCLUSIVE (and exclusive InnoDB table lock) in ha_innobase::prepare_inplace_alter_table() forces any transactions accessing the table to commit or rollback. So, we know that we can safely reset any DB_TRX_ID in the table that is older than the transaction ID of the ALTER TABLE, because the undo log history would be lost in a table-rebuilding ALTER. Note: After a table-rebuilding online ALTER TABLE, the rebuilt table may end up containing some nonzero DB_TRX_ID columns. The apply logic identifies the rows by the combination of PRIMARY KEY and DB_TRX_ID. These nonzero DB_TRX_ID would necessarily refer to concurrent DML operations that were started during ha_innobase::inplace_alter_table(). row_log_allocate(): Add a parameter for the ALTER TABLE transaction. row_log_t::min_trx: The ALTER TABLE transaction ID. trx_id_check(): A debug function to check that DB_TRX_ID makes sense (is either 0 or bigger than the ALTER TABLE transaction ID). reset_trx_id[]: The reset DB_TRX_ID,DB_ROLL_PTR columns. row_log_table_delete(), row_log_table_get_pk(): Reset the DB_TRX_ID,DB_ROLL_PTR when they precede the ALTER TABLE transaction. row_log_table_apply_delete(), row_log_table_apply_update(): Assert trx_id_check(). row_merge_insert_index_tuples(): Remove the unused parameter trx_id. row_merge_read_clustered_index(): In a table-rebuilding ALTER, reset the DB_TRX_ID,DB_ROLL_PTR when they precede the ALTER TABLE transaction. Assert trx_id_check() on clustered index records that are being buffered.
8 years ago
MDEV-13654 Various crashes due to DB_TRX_ID mismatch in table-rebuilding ALTER TABLE…LOCK=NONE After MDEV-12288 and MDEV-13536, the DB_TRX_ID of old clustered index records for which no history is available should be reset to 0. This caused crashes in online table-rebuilding ALTER, because the row_log_table_apply() is built on the assumption that the PRIMARY KEY together with DB_TRX_ID,DB_ROLL_PTR identifies the record. Both when copying the old table and when writing log about changes to the old table, we must map "old" DB_TRX_ID to 0. "old" here is simply "older than the trx_id of the ALTER TABLE transaction", because the MDL_EXCLUSIVE (and exclusive InnoDB table lock) in ha_innobase::prepare_inplace_alter_table() forces any transactions accessing the table to commit or rollback. So, we know that we can safely reset any DB_TRX_ID in the table that is older than the transaction ID of the ALTER TABLE, because the undo log history would be lost in a table-rebuilding ALTER. Note: After a table-rebuilding online ALTER TABLE, the rebuilt table may end up containing some nonzero DB_TRX_ID columns. The apply logic identifies the rows by the combination of PRIMARY KEY and DB_TRX_ID. These nonzero DB_TRX_ID would necessarily refer to concurrent DML operations that were started during ha_innobase::inplace_alter_table(). row_log_allocate(): Add a parameter for the ALTER TABLE transaction. row_log_t::min_trx: The ALTER TABLE transaction ID. trx_id_check(): A debug function to check that DB_TRX_ID makes sense (is either 0 or bigger than the ALTER TABLE transaction ID). reset_trx_id[]: The reset DB_TRX_ID,DB_ROLL_PTR columns. row_log_table_delete(), row_log_table_get_pk(): Reset the DB_TRX_ID,DB_ROLL_PTR when they precede the ALTER TABLE transaction. row_log_table_apply_delete(), row_log_table_apply_update(): Assert trx_id_check(). row_merge_insert_index_tuples(): Remove the unused parameter trx_id. row_merge_read_clustered_index(): In a table-rebuilding ALTER, reset the DB_TRX_ID,DB_ROLL_PTR when they precede the ALTER TABLE transaction. Assert trx_id_check() on clustered index records that are being buffered.
8 years ago
10 years ago
11 years ago
11 years ago
MDEV-12634: Uninitialised ROW_MERGE_RESERVE_SIZE bytes written to tem… …porary file Fixed by removing writing key version to start of every block that was encrypted. Instead we will use single key version from log_sys crypt info. After this MDEV also blocks writen to row log are encrypted and blocks read from row log aren decrypted if encryption is configured for the table. innodb_status_variables[], struct srv_stats_t Added status variables for merge block and row log block encryption and decryption amounts. Removed ROW_MERGE_RESERVE_SIZE define. row_merge_fts_doc_tokenize Remove ROW_MERGE_RESERVE_SIZE row_log_t Add index, crypt_tail, crypt_head to be used in case of encryption. row_log_online_op, row_log_table_close_func Before writing a block encrypt it if encryption is enabled row_log_table_apply_ops, row_log_apply_ops After reading a block decrypt it if encryption is enabled row_log_allocate Allocate temporary buffers crypt_head and crypt_tail if needed. row_log_free Free temporary buffers crypt_head and crypt_tail if they exist. row_merge_encrypt_buf, row_merge_decrypt_buf Removed. row_merge_buf_create, row_merge_buf_write Remove ROW_MERGE_RESERVE_SIZE row_merge_build_indexes Allocate temporary buffer used in decryption and encryption if needed. log_tmp_blocks_crypt, log_tmp_block_encrypt, log_temp_block_decrypt New functions used in block encryption and decryption log_tmp_is_encrypted New function to check is encryption enabled. Added test case innodb-rowlog to force creating a row log and verify that operations are done using introduced status variables.
8 years ago
11 years ago
12 years ago
12 years ago
12 years ago
12 years ago
10 years ago
12 years ago
12 years ago
MDEV-12634: Uninitialised ROW_MERGE_RESERVE_SIZE bytes written to tem… …porary file Fixed by removing writing key version to start of every block that was encrypted. Instead we will use single key version from log_sys crypt info. After this MDEV also blocks writen to row log are encrypted and blocks read from row log aren decrypted if encryption is configured for the table. innodb_status_variables[], struct srv_stats_t Added status variables for merge block and row log block encryption and decryption amounts. Removed ROW_MERGE_RESERVE_SIZE define. row_merge_fts_doc_tokenize Remove ROW_MERGE_RESERVE_SIZE row_log_t Add index, crypt_tail, crypt_head to be used in case of encryption. row_log_online_op, row_log_table_close_func Before writing a block encrypt it if encryption is enabled row_log_table_apply_ops, row_log_apply_ops After reading a block decrypt it if encryption is enabled row_log_allocate Allocate temporary buffers crypt_head and crypt_tail if needed. row_log_free Free temporary buffers crypt_head and crypt_tail if they exist. row_merge_encrypt_buf, row_merge_decrypt_buf Removed. row_merge_buf_create, row_merge_buf_write Remove ROW_MERGE_RESERVE_SIZE row_merge_build_indexes Allocate temporary buffer used in decryption and encryption if needed. log_tmp_blocks_crypt, log_tmp_block_encrypt, log_temp_block_decrypt New functions used in block encryption and decryption log_tmp_is_encrypted New function to check is encryption enabled. Added test case innodb-rowlog to force creating a row log and verify that operations are done using introduced status variables.
8 years ago
MDEV-12634: Uninitialised ROW_MERGE_RESERVE_SIZE bytes written to tem… …porary file Fixed by removing writing key version to start of every block that was encrypted. Instead we will use single key version from log_sys crypt info. After this MDEV also blocks writen to row log are encrypted and blocks read from row log aren decrypted if encryption is configured for the table. innodb_status_variables[], struct srv_stats_t Added status variables for merge block and row log block encryption and decryption amounts. Removed ROW_MERGE_RESERVE_SIZE define. row_merge_fts_doc_tokenize Remove ROW_MERGE_RESERVE_SIZE row_log_t Add index, crypt_tail, crypt_head to be used in case of encryption. row_log_online_op, row_log_table_close_func Before writing a block encrypt it if encryption is enabled row_log_table_apply_ops, row_log_apply_ops After reading a block decrypt it if encryption is enabled row_log_allocate Allocate temporary buffers crypt_head and crypt_tail if needed. row_log_free Free temporary buffers crypt_head and crypt_tail if they exist. row_merge_encrypt_buf, row_merge_decrypt_buf Removed. row_merge_buf_create, row_merge_buf_write Remove ROW_MERGE_RESERVE_SIZE row_merge_build_indexes Allocate temporary buffer used in decryption and encryption if needed. log_tmp_blocks_crypt, log_tmp_block_encrypt, log_temp_block_decrypt New functions used in block encryption and decryption log_tmp_is_encrypted New function to check is encryption enabled. Added test case innodb-rowlog to force creating a row log and verify that operations are done using introduced status variables.
8 years ago
MDEV-12634: Uninitialised ROW_MERGE_RESERVE_SIZE bytes written to tem… …porary file Fixed by removing writing key version to start of every block that was encrypted. Instead we will use single key version from log_sys crypt info. After this MDEV also blocks writen to row log are encrypted and blocks read from row log aren decrypted if encryption is configured for the table. innodb_status_variables[], struct srv_stats_t Added status variables for merge block and row log block encryption and decryption amounts. Removed ROW_MERGE_RESERVE_SIZE define. row_merge_fts_doc_tokenize Remove ROW_MERGE_RESERVE_SIZE row_log_t Add index, crypt_tail, crypt_head to be used in case of encryption. row_log_online_op, row_log_table_close_func Before writing a block encrypt it if encryption is enabled row_log_table_apply_ops, row_log_apply_ops After reading a block decrypt it if encryption is enabled row_log_allocate Allocate temporary buffers crypt_head and crypt_tail if needed. row_log_free Free temporary buffers crypt_head and crypt_tail if they exist. row_merge_encrypt_buf, row_merge_decrypt_buf Removed. row_merge_buf_create, row_merge_buf_write Remove ROW_MERGE_RESERVE_SIZE row_merge_build_indexes Allocate temporary buffer used in decryption and encryption if needed. log_tmp_blocks_crypt, log_tmp_block_encrypt, log_temp_block_decrypt New functions used in block encryption and decryption log_tmp_is_encrypted New function to check is encryption enabled. Added test case innodb-rowlog to force creating a row log and verify that operations are done using introduced status variables.
8 years ago
MDEV-12634: Uninitialised ROW_MERGE_RESERVE_SIZE bytes written to tem… …porary file Fixed by removing writing key version to start of every block that was encrypted. Instead we will use single key version from log_sys crypt info. After this MDEV also blocks writen to row log are encrypted and blocks read from row log aren decrypted if encryption is configured for the table. innodb_status_variables[], struct srv_stats_t Added status variables for merge block and row log block encryption and decryption amounts. Removed ROW_MERGE_RESERVE_SIZE define. row_merge_fts_doc_tokenize Remove ROW_MERGE_RESERVE_SIZE row_log_t Add index, crypt_tail, crypt_head to be used in case of encryption. row_log_online_op, row_log_table_close_func Before writing a block encrypt it if encryption is enabled row_log_table_apply_ops, row_log_apply_ops After reading a block decrypt it if encryption is enabled row_log_allocate Allocate temporary buffers crypt_head and crypt_tail if needed. row_log_free Free temporary buffers crypt_head and crypt_tail if they exist. row_merge_encrypt_buf, row_merge_decrypt_buf Removed. row_merge_buf_create, row_merge_buf_write Remove ROW_MERGE_RESERVE_SIZE row_merge_build_indexes Allocate temporary buffer used in decryption and encryption if needed. log_tmp_blocks_crypt, log_tmp_block_encrypt, log_temp_block_decrypt New functions used in block encryption and decryption log_tmp_is_encrypted New function to check is encryption enabled. Added test case innodb-rowlog to force creating a row log and verify that operations are done using introduced status variables.
8 years ago
MDEV-12634: Uninitialised ROW_MERGE_RESERVE_SIZE bytes written to tem… …porary file Fixed by removing writing key version to start of every block that was encrypted. Instead we will use single key version from log_sys crypt info. After this MDEV also blocks writen to row log are encrypted and blocks read from row log aren decrypted if encryption is configured for the table. innodb_status_variables[], struct srv_stats_t Added status variables for merge block and row log block encryption and decryption amounts. Removed ROW_MERGE_RESERVE_SIZE define. row_merge_fts_doc_tokenize Remove ROW_MERGE_RESERVE_SIZE row_log_t Add index, crypt_tail, crypt_head to be used in case of encryption. row_log_online_op, row_log_table_close_func Before writing a block encrypt it if encryption is enabled row_log_table_apply_ops, row_log_apply_ops After reading a block decrypt it if encryption is enabled row_log_allocate Allocate temporary buffers crypt_head and crypt_tail if needed. row_log_free Free temporary buffers crypt_head and crypt_tail if they exist. row_merge_encrypt_buf, row_merge_decrypt_buf Removed. row_merge_buf_create, row_merge_buf_write Remove ROW_MERGE_RESERVE_SIZE row_merge_build_indexes Allocate temporary buffer used in decryption and encryption if needed. log_tmp_blocks_crypt, log_tmp_block_encrypt, log_temp_block_decrypt New functions used in block encryption and decryption log_tmp_is_encrypted New function to check is encryption enabled. Added test case innodb-rowlog to force creating a row log and verify that operations are done using introduced status variables.
8 years ago
MDEV-12634: Uninitialised ROW_MERGE_RESERVE_SIZE bytes written to tem… …porary file Fixed by removing writing key version to start of every block that was encrypted. Instead we will use single key version from log_sys crypt info. After this MDEV also blocks writen to row log are encrypted and blocks read from row log aren decrypted if encryption is configured for the table. innodb_status_variables[], struct srv_stats_t Added status variables for merge block and row log block encryption and decryption amounts. Removed ROW_MERGE_RESERVE_SIZE define. row_merge_fts_doc_tokenize Remove ROW_MERGE_RESERVE_SIZE row_log_t Add index, crypt_tail, crypt_head to be used in case of encryption. row_log_online_op, row_log_table_close_func Before writing a block encrypt it if encryption is enabled row_log_table_apply_ops, row_log_apply_ops After reading a block decrypt it if encryption is enabled row_log_allocate Allocate temporary buffers crypt_head and crypt_tail if needed. row_log_free Free temporary buffers crypt_head and crypt_tail if they exist. row_merge_encrypt_buf, row_merge_decrypt_buf Removed. row_merge_buf_create, row_merge_buf_write Remove ROW_MERGE_RESERVE_SIZE row_merge_build_indexes Allocate temporary buffer used in decryption and encryption if needed. log_tmp_blocks_crypt, log_tmp_block_encrypt, log_temp_block_decrypt New functions used in block encryption and decryption log_tmp_is_encrypted New function to check is encryption enabled. Added test case innodb-rowlog to force creating a row log and verify that operations are done using introduced status variables.
8 years ago
MDEV-12634: Uninitialised ROW_MERGE_RESERVE_SIZE bytes written to tem… …porary file Fixed by removing writing key version to start of every block that was encrypted. Instead we will use single key version from log_sys crypt info. After this MDEV also blocks writen to row log are encrypted and blocks read from row log aren decrypted if encryption is configured for the table. innodb_status_variables[], struct srv_stats_t Added status variables for merge block and row log block encryption and decryption amounts. Removed ROW_MERGE_RESERVE_SIZE define. row_merge_fts_doc_tokenize Remove ROW_MERGE_RESERVE_SIZE row_log_t Add index, crypt_tail, crypt_head to be used in case of encryption. row_log_online_op, row_log_table_close_func Before writing a block encrypt it if encryption is enabled row_log_table_apply_ops, row_log_apply_ops After reading a block decrypt it if encryption is enabled row_log_allocate Allocate temporary buffers crypt_head and crypt_tail if needed. row_log_free Free temporary buffers crypt_head and crypt_tail if they exist. row_merge_encrypt_buf, row_merge_decrypt_buf Removed. row_merge_buf_create, row_merge_buf_write Remove ROW_MERGE_RESERVE_SIZE row_merge_build_indexes Allocate temporary buffer used in decryption and encryption if needed. log_tmp_blocks_crypt, log_tmp_block_encrypt, log_temp_block_decrypt New functions used in block encryption and decryption log_tmp_is_encrypted New function to check is encryption enabled. Added test case innodb-rowlog to force creating a row log and verify that operations are done using introduced status variables.
8 years ago
MDEV-12634: Uninitialised ROW_MERGE_RESERVE_SIZE bytes written to tem… …porary file Fixed by removing writing key version to start of every block that was encrypted. Instead we will use single key version from log_sys crypt info. After this MDEV also blocks writen to row log are encrypted and blocks read from row log aren decrypted if encryption is configured for the table. innodb_status_variables[], struct srv_stats_t Added status variables for merge block and row log block encryption and decryption amounts. Removed ROW_MERGE_RESERVE_SIZE define. row_merge_fts_doc_tokenize Remove ROW_MERGE_RESERVE_SIZE row_log_t Add index, crypt_tail, crypt_head to be used in case of encryption. row_log_online_op, row_log_table_close_func Before writing a block encrypt it if encryption is enabled row_log_table_apply_ops, row_log_apply_ops After reading a block decrypt it if encryption is enabled row_log_allocate Allocate temporary buffers crypt_head and crypt_tail if needed. row_log_free Free temporary buffers crypt_head and crypt_tail if they exist. row_merge_encrypt_buf, row_merge_decrypt_buf Removed. row_merge_buf_create, row_merge_buf_write Remove ROW_MERGE_RESERVE_SIZE row_merge_build_indexes Allocate temporary buffer used in decryption and encryption if needed. log_tmp_blocks_crypt, log_tmp_block_encrypt, log_temp_block_decrypt New functions used in block encryption and decryption log_tmp_is_encrypted New function to check is encryption enabled. Added test case innodb-rowlog to force creating a row log and verify that operations are done using introduced status variables.
8 years ago
MDEV-13485 MTR tests fail massively with --innodb-sync-debug The parameter --innodb-sync-debug, which is disabled by default, aims to find potential deadlocks in InnoDB. When the parameter is enabled, lots of tests failed. Most of these failures were due to bogus diagnostics. But, as part of this fix, we are also fixing a bug in error handling code and removing dead code, and fixing cases where an uninitialized mutex was being locked and unlocked. dict_create_foreign_constraints_low(): Remove an extraneous mutex_exit() call that could cause corruption in an error handling path. Also, do not unnecessarily acquire dict_foreign_err_mutex. Its only purpose is to control concurrent access to dict_foreign_err_file. row_ins_foreign_trx_print(): Replace a redundant condition with a debug assertion. srv_dict_tmpfile, srv_dict_tmpfile_mutex: Remove. The temporary file is never being written to or read from. log_free_check(): Allow SYNC_FTS_CACHE (fts_cache_t::lock) to be held. ha_innobase::inplace_alter_table(), row_merge_insert_index_tuples(): Assert that no unexpected latches are being held. sync_latch_meta_init(): Properly initialize dict_operation_lock_key at SYNC_DICT_OPERATION. dict_sys->mutex is SYNC_DICT, and the now-removed SRV_DICT_TMPFILE was wrongly registered at SYNC_DICT_OPERATION. buf_block_init(): Correctly register buf_block_t::debug_latch. It was previously misleadingly reported as LATCH_ID_DICT_FOREIGN_ERR. latch_level_t: Correct the relative latching order of SYNC_IBUF_PESS_INSERT_MUTEX,SYNC_INDEX_TREE and SYNC_FILE_FORMAT_TAG,SYNC_DICT_OPERATION to avoid bogus failures. row_drop_table_for_mysql(): Avoid accessing btr_defragment_mutex if the defragmentation thread has not been started. This is the case during fts_drop_orphaned_tables() in recv_recovery_rollback_active(). fil_space_destroy_crypt_data(): Avoid acquiring fil_crypt_threads_mutex when it is uninitialized. We may have created crypt_data before the mutex was created, and the mutex creation would be skipped if InnoDB startup failed or --innodb-read-only was specified.
8 years ago
MDEV-13485 MTR tests fail massively with --innodb-sync-debug The parameter --innodb-sync-debug, which is disabled by default, aims to find potential deadlocks in InnoDB. When the parameter is enabled, lots of tests failed. Most of these failures were due to bogus diagnostics. But, as part of this fix, we are also fixing a bug in error handling code and removing dead code, and fixing cases where an uninitialized mutex was being locked and unlocked. dict_create_foreign_constraints_low(): Remove an extraneous mutex_exit() call that could cause corruption in an error handling path. Also, do not unnecessarily acquire dict_foreign_err_mutex. Its only purpose is to control concurrent access to dict_foreign_err_file. row_ins_foreign_trx_print(): Replace a redundant condition with a debug assertion. srv_dict_tmpfile, srv_dict_tmpfile_mutex: Remove. The temporary file is never being written to or read from. log_free_check(): Allow SYNC_FTS_CACHE (fts_cache_t::lock) to be held. ha_innobase::inplace_alter_table(), row_merge_insert_index_tuples(): Assert that no unexpected latches are being held. sync_latch_meta_init(): Properly initialize dict_operation_lock_key at SYNC_DICT_OPERATION. dict_sys->mutex is SYNC_DICT, and the now-removed SRV_DICT_TMPFILE was wrongly registered at SYNC_DICT_OPERATION. buf_block_init(): Correctly register buf_block_t::debug_latch. It was previously misleadingly reported as LATCH_ID_DICT_FOREIGN_ERR. latch_level_t: Correct the relative latching order of SYNC_IBUF_PESS_INSERT_MUTEX,SYNC_INDEX_TREE and SYNC_FILE_FORMAT_TAG,SYNC_DICT_OPERATION to avoid bogus failures. row_drop_table_for_mysql(): Avoid accessing btr_defragment_mutex if the defragmentation thread has not been started. This is the case during fts_drop_orphaned_tables() in recv_recovery_rollback_active(). fil_space_destroy_crypt_data(): Avoid acquiring fil_crypt_threads_mutex when it is uninitialized. We may have created crypt_data before the mutex was created, and the mutex creation would be skipped if InnoDB startup failed or --innodb-read-only was specified.
8 years ago
10 years ago
10 years ago
9 years ago
9 years ago
9 years ago
10 years ago
9 years ago
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-11369 Instant ADD COLUMN for InnoDB For InnoDB tables, adding, dropping and reordering columns has required a rebuild of the table and all its indexes. Since MySQL 5.6 (and MariaDB 10.0) this has been supported online (LOCK=NONE), allowing concurrent modification of the tables. This work revises the InnoDB ROW_FORMAT=REDUNDANT, ROW_FORMAT=COMPACT and ROW_FORMAT=DYNAMIC so that columns can be appended instantaneously, with only minor changes performed to the table structure. The counter innodb_instant_alter_column in INFORMATION_SCHEMA.GLOBAL_STATUS is incremented whenever a table rebuild operation is converted into an instant ADD COLUMN operation. ROW_FORMAT=COMPRESSED tables will not support instant ADD COLUMN. Some usability limitations will be addressed in subsequent work: MDEV-13134 Introduce ALTER TABLE attributes ALGORITHM=NOCOPY and ALGORITHM=INSTANT MDEV-14016 Allow instant ADD COLUMN, ADD INDEX, LOCK=NONE The format of the clustered index (PRIMARY KEY) is changed as follows: (1) The FIL_PAGE_TYPE of the root page will be FIL_PAGE_TYPE_INSTANT, and a new field PAGE_INSTANT will contain the original number of fields in the clustered index ('core' fields). If instant ADD COLUMN has not been used or the table becomes empty, or the very first instant ADD COLUMN operation is rolled back, the fields PAGE_INSTANT and FIL_PAGE_TYPE will be reset to 0 and FIL_PAGE_INDEX. (2) A special 'default row' record is inserted into the leftmost leaf, between the page infimum and the first user record. This record is distinguished by the REC_INFO_MIN_REC_FLAG, and it is otherwise in the same format as records that contain values for the instantly added columns. This 'default row' always has the same number of fields as the clustered index according to the table definition. The values of 'core' fields are to be ignored. For other fields, the 'default row' will contain the default values as they were during the ALTER TABLE statement. (If the column default values are changed later, those values will only be stored in the .frm file. The 'default row' will contain the original evaluated values, which must be the same for every row.) The 'default row' must be completely hidden from higher-level access routines. Assertions have been added to ensure that no 'default row' is ever present in the adaptive hash index or in locked records. The 'default row' is never delete-marked. (3) In clustered index leaf page records, the number of fields must reside between the number of 'core' fields (dict_index_t::n_core_fields introduced in this work) and dict_index_t::n_fields. If the number of fields is less than dict_index_t::n_fields, the missing fields are replaced with the column value of the 'default row'. Note: The number of fields in the record may shrink if some of the last instantly added columns are updated to the value that is in the 'default row'. The function btr_cur_trim() implements this 'compression' on update and rollback; dtuple::trim() implements it on insert. (4) In ROW_FORMAT=COMPACT and ROW_FORMAT=DYNAMIC records, the new status value REC_STATUS_COLUMNS_ADDED will indicate the presence of a new record header that will encode n_fields-n_core_fields-1 in 1 or 2 bytes. (In ROW_FORMAT=REDUNDANT records, the record header always explicitly encodes the number of fields.) We introduce the undo log record type TRX_UNDO_INSERT_DEFAULT for covering the insert of the 'default row' record when instant ADD COLUMN is used for the first time. Subsequent instant ADD COLUMN can use TRX_UNDO_UPD_EXIST_REC. This is joint work with Vin Chen (陈福荣) from Tencent. The design that was discussed in April 2017 would not have allowed import or export of data files, because instead of the 'default row' it would have introduced a data dictionary table. The test rpl.rpl_alter_instant is exactly as contributed in pull request #408. The test innodb.instant_alter is based on a contributed test. The redo log record format changes for ROW_FORMAT=DYNAMIC and ROW_FORMAT=COMPACT are as contributed. (With this change present, crash recovery from MariaDB 10.3.1 will fail in spectacular ways!) Also the semantics of higher-level redo log records that modify the PAGE_INSTANT field is changed. The redo log format version identifier was already changed to LOG_HEADER_FORMAT_CURRENT=103 in MariaDB 10.3.1. Everything else has been rewritten by me. Thanks to Elena Stepanova, the code has been tested extensively. When rolling back an instant ADD COLUMN operation, we must empty the PAGE_FREE list after deleting or shortening the 'default row' record, by calling either btr_page_empty() or btr_page_reorganize(). We must know the size of each entry in the PAGE_FREE list. If rollback left a freed copy of the 'default row' in the PAGE_FREE list, we would be unable to determine its size (if it is in ROW_FORMAT=COMPACT or ROW_FORMAT=DYNAMIC) because it would contain more fields than the rolled-back definition of the clustered index. UNIV_SQL_DEFAULT: A new special constant that designates an instantly added column that is not present in the clustered index record. len_is_stored(): Check if a length is an actual length. There are two magic length values: UNIV_SQL_DEFAULT, UNIV_SQL_NULL. dict_col_t::def_val: The 'default row' value of the column. If the column is not added instantly, def_val.len will be UNIV_SQL_DEFAULT. dict_col_t: Add the accessors is_virtual(), is_nullable(), is_instant(), instant_value(). dict_col_t::remove_instant(): Remove the 'instant ADD' status of a column. dict_col_t::name(const dict_table_t& table): Replaces dict_table_get_col_name(). dict_index_t::n_core_fields: The original number of fields. For secondary indexes and if instant ADD COLUMN has not been used, this will be equal to dict_index_t::n_fields. dict_index_t::n_core_null_bytes: Number of bytes needed to represent the null flags; usually equal to UT_BITS_IN_BYTES(n_nullable). dict_index_t::NO_CORE_NULL_BYTES: Magic value signalling that n_core_null_bytes was not initialized yet from the clustered index root page. dict_index_t: Add the accessors is_instant(), is_clust(), get_n_nullable(), instant_field_value(). dict_index_t::instant_add_field(): Adjust clustered index metadata for instant ADD COLUMN. dict_index_t::remove_instant(): Remove the 'instant ADD' status of a clustered index when the table becomes empty, or the very first instant ADD COLUMN operation is rolled back. dict_table_t: Add the accessors is_instant(), is_temporary(), supports_instant(). dict_table_t::instant_add_column(): Adjust metadata for instant ADD COLUMN. dict_table_t::rollback_instant(): Adjust metadata on the rollback of instant ADD COLUMN. prepare_inplace_alter_table_dict(): First create the ctx->new_table, and only then decide if the table really needs to be rebuilt. We must split the creation of table or index metadata from the creation of the dictionary table records and the creation of the data. In this way, we can transform a table-rebuilding operation into an instant ADD COLUMN operation. Dictionary objects will only be added to cache when table rebuilding or index creation is needed. The ctx->instant_table will never be added to cache. dict_table_t::add_to_cache(): Modified and renamed from dict_table_add_to_cache(). Do not modify the table metadata. Let the callers invoke dict_table_add_system_columns() and if needed, set can_be_evicted. dict_create_sys_tables_tuple(), dict_create_table_step(): Omit the system columns (which will now exist in the dict_table_t object already at this point). dict_create_table_step(): Expect the callers to invoke dict_table_add_system_columns(). pars_create_table(): Before creating the table creation execution graph, invoke dict_table_add_system_columns(). row_create_table_for_mysql(): Expect all callers to invoke dict_table_add_system_columns(). create_index_dict(): Replaces row_merge_create_index_graph(). innodb_update_n_cols(): Renamed from innobase_update_n_virtual(). Call my_error() if an error occurs. btr_cur_instant_init(), btr_cur_instant_init_low(), btr_cur_instant_root_init(): Load additional metadata from the clustered index and set dict_index_t::n_core_null_bytes. This is invoked when table metadata is first loaded into the data dictionary. dict_boot(): Initialize n_core_null_bytes for the four hard-coded dictionary tables. dict_create_index_step(): Initialize n_core_null_bytes. This is executed as part of CREATE TABLE. dict_index_build_internal_clust(): Initialize n_core_null_bytes to NO_CORE_NULL_BYTES if table->supports_instant(). row_create_index_for_mysql(): Initialize n_core_null_bytes for CREATE TEMPORARY TABLE. commit_cache_norebuild(): Call the code to rename or enlarge columns in the cache only if instant ADD COLUMN is not being used. (Instant ADD COLUMN would copy all column metadata from instant_table to old_table, including the names and lengths.) PAGE_INSTANT: A new 13-bit field for storing dict_index_t::n_core_fields. This is repurposing the 16-bit field PAGE_DIRECTION, of which only the least significant 3 bits were used. The original byte containing PAGE_DIRECTION will be accessible via the new constant PAGE_DIRECTION_B. page_get_instant(), page_set_instant(): Accessors for the PAGE_INSTANT. page_ptr_get_direction(), page_get_direction(), page_ptr_set_direction(): Accessors for PAGE_DIRECTION. page_direction_reset(): Reset PAGE_DIRECTION, PAGE_N_DIRECTION. page_direction_increment(): Increment PAGE_N_DIRECTION and set PAGE_DIRECTION. rec_get_offsets(): Use the 'leaf' parameter for non-debug purposes, and assume that heap_no is always set. Initialize all dict_index_t::n_fields for ROW_FORMAT=REDUNDANT records, even if the record contains fewer fields. rec_offs_make_valid(): Add the parameter 'leaf'. rec_copy_prefix_to_dtuple(): Assert that the tuple is only built on the core fields. Instant ADD COLUMN only applies to the clustered index, and we should never build a search key that has more than the PRIMARY KEY and possibly DB_TRX_ID,DB_ROLL_PTR. All these columns are always present. dict_index_build_data_tuple(): Remove assertions that would be duplicated in rec_copy_prefix_to_dtuple(). rec_init_offsets(): Support ROW_FORMAT=REDUNDANT records whose number of fields is between n_core_fields and n_fields. cmp_rec_rec_with_match(): Implement the comparison between two MIN_REC_FLAG records. trx_t::in_rollback: Make the field available in non-debug builds. trx_start_for_ddl_low(): Remove dangerous error-tolerance. A dictionary transaction must be flagged as such before it has generated any undo log records. This is because trx_undo_assign_undo() will mark the transaction as a dictionary transaction in the undo log header right before the very first undo log record is being written. btr_index_rec_validate(): Account for instant ADD COLUMN row_undo_ins_remove_clust_rec(): On the rollback of an insert into SYS_COLUMNS, revert instant ADD COLUMN in the cache by removing the last column from the table and the clustered index. row_search_on_row_ref(), row_undo_mod_parse_undo_rec(), row_undo_mod(), trx_undo_update_rec_get_update(): Handle the 'default row' as a special case. dtuple_t::trim(index): Omit a redundant suffix of an index tuple right before insert or update. After instant ADD COLUMN, if the last fields of a clustered index tuple match the 'default row', there is no need to store them. While trimming the entry, we must hold a page latch, so that the table cannot be emptied and the 'default row' be deleted. btr_cur_optimistic_update(), btr_cur_pessimistic_update(), row_upd_clust_rec_by_insert(), row_ins_clust_index_entry_low(): Invoke dtuple_t::trim() if needed. row_ins_clust_index_entry(): Restore dtuple_t::n_fields after calling row_ins_clust_index_entry_low(). rec_get_converted_size(), rec_get_converted_size_comp(): Allow the number of fields to be between n_core_fields and n_fields. Do not support infimum,supremum. They are never supposed to be stored in dtuple_t, because page creation nowadays uses a lower-level method for initializing them. rec_convert_dtuple_to_rec_comp(): Assign the status bits based on the number of fields. btr_cur_trim(): In an update, trim the index entry as needed. For the 'default row', handle rollback specially. For user records, omit fields that match the 'default row'. btr_cur_optimistic_delete_func(), btr_cur_pessimistic_delete(): Skip locking and adaptive hash index for the 'default row'. row_log_table_apply_convert_mrec(): Replace 'default row' values if needed. In the temporary file that is applied by row_log_table_apply(), we must identify whether the records contain the extra header for instantly added columns. For now, we will allocate an additional byte for this for ROW_T_INSERT and ROW_T_UPDATE records when the source table has been subject to instant ADD COLUMN. The ROW_T_DELETE records are fine, as they will be converted and will only contain 'core' columns (PRIMARY KEY and some system columns) that are converted from dtuple_t. rec_get_converted_size_temp(), rec_init_offsets_temp(), rec_convert_dtuple_to_temp(): Add the parameter 'status'. REC_INFO_DEFAULT_ROW = REC_INFO_MIN_REC_FLAG | REC_STATUS_COLUMNS_ADDED: An info_bits constant for distinguishing the 'default row' record. rec_comp_status_t: An enum of the status bit values. rec_leaf_format: An enum that replaces the bool parameter of rec_init_offsets_comp_ordinary().
8 years ago
MDEV-11738: Mariadb uses 100% of several of my 8 cpus doing nothing MDEV-11581: Mariadb starts InnoDB encryption threads when key has not changed or data scrubbing turned off Background: Key rotation is based on background threads (innodb-encryption-threads) periodically going through all tablespaces on fil_system. For each tablespace current used key version is compared to max key age (innodb-encryption-rotate-key-age). This process naturally takes CPU. Similarly, in same time need for scrubbing is investigated. Currently, key rotation is fully supported on Amazon AWS key management plugin only but InnoDB does not have knowledge what key management plugin is used. This patch re-purposes innodb-encryption-rotate-key-age=0 to disable key rotation and background data scrubbing. All new tables are added to special list for key rotation and key rotation is based on sending a event to background encryption threads instead of using periodic checking (i.e. timeout). fil0fil.cc: Added functions fil_space_acquire_low() to acquire a tablespace when it could be dropped concurrently. This function is used from fil_space_acquire() or fil_space_acquire_silent() that will not print any messages if we try to acquire space that does not exist. fil_space_release() to release a acquired tablespace. fil_space_next() to iterate tablespaces in fil_system using fil_space_acquire() and fil_space_release(). Similarly, fil_space_keyrotation_next() to iterate new list fil_system->rotation_list where new tables. are added if key rotation is disabled. Removed unnecessary functions fil_get_first_space_safe() fil_get_next_space_safe() fil_node_open_file(): After page 0 is read read also crypt_info if it is not yet read. btr_scrub_lock_dict_func() buf_page_check_corrupt() buf_page_encrypt_before_write() buf_merge_or_delete_for_page() lock_print_info_all_transactions() row_fts_psort_info_init() row_truncate_table_for_mysql() row_drop_table_for_mysql() Use fil_space_acquire()/release() to access fil_space_t. buf_page_decrypt_after_read(): Use fil_space_get_crypt_data() because at this point we might not yet have read page 0. fil0crypt.cc/fil0fil.h: Lot of changes. Pass fil_space_t* directly to functions needing it and store fil_space_t* to rotation state. Use fil_space_acquire()/release() when iterating tablespaces and removed unnecessary is_closing from fil_crypt_t. Use fil_space_t::is_stopping() to detect when access to tablespace should be stopped. Removed unnecessary fil_space_get_crypt_data(). fil_space_create(): Inform key rotation that there could be something to do if key rotation is disabled and new table with encryption enabled is created. Remove unnecessary functions fil_get_first_space_safe() and fil_get_next_space_safe(). fil_space_acquire() and fil_space_release() are used instead. Moved fil_space_get_crypt_data() and fil_space_set_crypt_data() to fil0crypt.cc. fsp_header_init(): Acquire fil_space_t*, write crypt_data and release space. check_table_options() Renamed FIL_SPACE_ENCRYPTION_* TO FIL_ENCRYPTION_* i_s.cc: Added ROTATING_OR_FLUSHING field to information_schema.innodb_tablespace_encryption to show current status of key rotation.
9 years ago
12 years ago
MDEV-12634: Uninitialised ROW_MERGE_RESERVE_SIZE bytes written to tem… …porary file Fixed by removing writing key version to start of every block that was encrypted. Instead we will use single key version from log_sys crypt info. After this MDEV also blocks writen to row log are encrypted and blocks read from row log aren decrypted if encryption is configured for the table. innodb_status_variables[], struct srv_stats_t Added status variables for merge block and row log block encryption and decryption amounts. Removed ROW_MERGE_RESERVE_SIZE define. row_merge_fts_doc_tokenize Remove ROW_MERGE_RESERVE_SIZE row_log_t Add index, crypt_tail, crypt_head to be used in case of encryption. row_log_online_op, row_log_table_close_func Before writing a block encrypt it if encryption is enabled row_log_table_apply_ops, row_log_apply_ops After reading a block decrypt it if encryption is enabled row_log_allocate Allocate temporary buffers crypt_head and crypt_tail if needed. row_log_free Free temporary buffers crypt_head and crypt_tail if they exist. row_merge_encrypt_buf, row_merge_decrypt_buf Removed. row_merge_buf_create, row_merge_buf_write Remove ROW_MERGE_RESERVE_SIZE row_merge_build_indexes Allocate temporary buffer used in decryption and encryption if needed. log_tmp_blocks_crypt, log_tmp_block_encrypt, log_temp_block_decrypt New functions used in block encryption and decryption log_tmp_is_encrypted New function to check is encryption enabled. Added test case innodb-rowlog to force creating a row log and verify that operations are done using introduced status variables.
8 years ago
12 years ago
12 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-13654 Various crashes due to DB_TRX_ID mismatch in table-rebuilding ALTER TABLE…LOCK=NONE After MDEV-12288 and MDEV-13536, the DB_TRX_ID of old clustered index records for which no history is available should be reset to 0. This caused crashes in online table-rebuilding ALTER, because the row_log_table_apply() is built on the assumption that the PRIMARY KEY together with DB_TRX_ID,DB_ROLL_PTR identifies the record. Both when copying the old table and when writing log about changes to the old table, we must map "old" DB_TRX_ID to 0. "old" here is simply "older than the trx_id of the ALTER TABLE transaction", because the MDL_EXCLUSIVE (and exclusive InnoDB table lock) in ha_innobase::prepare_inplace_alter_table() forces any transactions accessing the table to commit or rollback. So, we know that we can safely reset any DB_TRX_ID in the table that is older than the transaction ID of the ALTER TABLE, because the undo log history would be lost in a table-rebuilding ALTER. Note: After a table-rebuilding online ALTER TABLE, the rebuilt table may end up containing some nonzero DB_TRX_ID columns. The apply logic identifies the rows by the combination of PRIMARY KEY and DB_TRX_ID. These nonzero DB_TRX_ID would necessarily refer to concurrent DML operations that were started during ha_innobase::inplace_alter_table(). row_log_allocate(): Add a parameter for the ALTER TABLE transaction. row_log_t::min_trx: The ALTER TABLE transaction ID. trx_id_check(): A debug function to check that DB_TRX_ID makes sense (is either 0 or bigger than the ALTER TABLE transaction ID). reset_trx_id[]: The reset DB_TRX_ID,DB_ROLL_PTR columns. row_log_table_delete(), row_log_table_get_pk(): Reset the DB_TRX_ID,DB_ROLL_PTR when they precede the ALTER TABLE transaction. row_log_table_apply_delete(), row_log_table_apply_update(): Assert trx_id_check(). row_merge_insert_index_tuples(): Remove the unused parameter trx_id. row_merge_read_clustered_index(): In a table-rebuilding ALTER, reset the DB_TRX_ID,DB_ROLL_PTR when they precede the ALTER TABLE transaction. Assert trx_id_check() on clustered index records that are being buffered.
8 years ago
12 years ago
12 years ago
  1. /*****************************************************************************
  2. Copyright (c) 2005, 2017, Oracle and/or its affiliates. All Rights Reserved.
  3. Copyright (c) 2014, 2018, 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, Suite 500, Boston, MA 02110-1335 USA
  13. *****************************************************************************/
  14. /**************************************************//**
  15. @file row/row0merge.cc
  16. New index creation routines using a merge sort
  17. Created 12/4/2005 Jan Lindstrom
  18. Completed by Sunny Bains and Marko Makela
  19. *******************************************************/
  20. #include <my_global.h>
  21. #include <log.h>
  22. #include <sql_class.h>
  23. #include <math.h>
  24. #include "ha_prototypes.h"
  25. #include "row0merge.h"
  26. #include "row0ext.h"
  27. #include "row0log.h"
  28. #include "row0ins.h"
  29. #include "row0row.h"
  30. #include "row0sel.h"
  31. #include "log0crypt.h"
  32. #include "dict0crea.h"
  33. #include "trx0purge.h"
  34. #include "lock0lock.h"
  35. #include "pars0pars.h"
  36. #include "ut0sort.h"
  37. #include "row0ftsort.h"
  38. #include "row0import.h"
  39. #include "row0vers.h"
  40. #include "handler0alter.h"
  41. #include "btr0bulk.h"
  42. #include "fsp0sysspace.h"
  43. #include "ut0new.h"
  44. #include "ut0stage.h"
  45. #include "fil0crypt.h"
  46. float my_log2f(float n)
  47. {
  48. /* log(n) / log(2) is log2. */
  49. return (float)(log((double)n) / log((double)2));
  50. }
  51. /* Ignore posix_fadvise() on those platforms where it does not exist */
  52. #if defined _WIN32
  53. # define posix_fadvise(fd, offset, len, advice) /* nothing */
  54. #endif /* _WIN32 */
  55. /* Whether to disable file system cache */
  56. char srv_disable_sort_file_cache;
  57. /** Class that caches index row tuples made from a single cluster
  58. index page scan, and then insert into corresponding index tree */
  59. class index_tuple_info_t {
  60. public:
  61. /** constructor
  62. @param[in] heap memory heap
  63. @param[in] index index to be created */
  64. index_tuple_info_t(
  65. mem_heap_t* heap,
  66. dict_index_t* index) UNIV_NOTHROW
  67. {
  68. m_heap = heap;
  69. m_index = index;
  70. m_dtuple_vec = UT_NEW_NOKEY(idx_tuple_vec());
  71. }
  72. /** destructor */
  73. ~index_tuple_info_t()
  74. {
  75. UT_DELETE(m_dtuple_vec);
  76. }
  77. /** Get the index object
  78. @return the index object */
  79. dict_index_t* get_index() UNIV_NOTHROW
  80. {
  81. return(m_index);
  82. }
  83. /** Caches an index row into index tuple vector
  84. @param[in] row table row
  85. @param[in] ext externally stored column
  86. prefixes, or NULL */
  87. void add(
  88. const dtuple_t* row,
  89. const row_ext_t* ext) UNIV_NOTHROW
  90. {
  91. dtuple_t* dtuple;
  92. dtuple = row_build_index_entry(row, ext, m_index, m_heap);
  93. ut_ad(dtuple);
  94. m_dtuple_vec->push_back(dtuple);
  95. }
  96. /** Insert spatial index rows cached in vector into spatial index
  97. @param[in] trx_id transaction id
  98. @param[in,out] row_heap memory heap
  99. @param[in] pcur cluster index scanning cursor
  100. @param[in,out] scan_mtr mini-transaction for pcur
  101. @param[out] mtr_committed whether scan_mtr got committed
  102. @return DB_SUCCESS if successful, else error number */
  103. dberr_t insert(
  104. trx_id_t trx_id,
  105. mem_heap_t* row_heap,
  106. btr_pcur_t* pcur,
  107. mtr_t* scan_mtr,
  108. bool* mtr_committed)
  109. {
  110. big_rec_t* big_rec;
  111. rec_t* rec;
  112. btr_cur_t ins_cur;
  113. mtr_t mtr;
  114. rtr_info_t rtr_info;
  115. ulint* ins_offsets = NULL;
  116. dberr_t error = DB_SUCCESS;
  117. dtuple_t* dtuple;
  118. ulint count = 0;
  119. const ulint flag = BTR_NO_UNDO_LOG_FLAG
  120. | BTR_NO_LOCKING_FLAG
  121. | BTR_KEEP_SYS_FLAG | BTR_CREATE_FLAG;
  122. ut_ad(dict_index_is_spatial(m_index));
  123. DBUG_EXECUTE_IF("row_merge_instrument_log_check_flush",
  124. log_sys->check_flush_or_checkpoint = true;
  125. );
  126. for (idx_tuple_vec::iterator it = m_dtuple_vec->begin();
  127. it != m_dtuple_vec->end();
  128. ++it) {
  129. dtuple = *it;
  130. ut_ad(dtuple);
  131. if (log_sys->check_flush_or_checkpoint) {
  132. if (!(*mtr_committed)) {
  133. btr_pcur_move_to_prev_on_page(pcur);
  134. btr_pcur_store_position(pcur, scan_mtr);
  135. mtr_commit(scan_mtr);
  136. *mtr_committed = true;
  137. }
  138. log_free_check();
  139. }
  140. mtr.start();
  141. m_index->set_modified(mtr);
  142. ins_cur.index = m_index;
  143. rtr_init_rtr_info(&rtr_info, false, &ins_cur, m_index,
  144. false);
  145. rtr_info_update_btr(&ins_cur, &rtr_info);
  146. btr_cur_search_to_nth_level(m_index, 0, dtuple,
  147. PAGE_CUR_RTREE_INSERT,
  148. BTR_MODIFY_LEAF, &ins_cur,
  149. 0, __FILE__, __LINE__,
  150. &mtr);
  151. /* It need to update MBR in parent entry,
  152. so change search mode to BTR_MODIFY_TREE */
  153. if (rtr_info.mbr_adj) {
  154. mtr_commit(&mtr);
  155. rtr_clean_rtr_info(&rtr_info, true);
  156. rtr_init_rtr_info(&rtr_info, false, &ins_cur,
  157. m_index, false);
  158. rtr_info_update_btr(&ins_cur, &rtr_info);
  159. mtr_start(&mtr);
  160. m_index->set_modified(mtr);
  161. btr_cur_search_to_nth_level(
  162. m_index, 0, dtuple,
  163. PAGE_CUR_RTREE_INSERT,
  164. BTR_MODIFY_TREE, &ins_cur, 0,
  165. __FILE__, __LINE__, &mtr);
  166. }
  167. error = btr_cur_optimistic_insert(
  168. flag, &ins_cur, &ins_offsets, &row_heap,
  169. dtuple, &rec, &big_rec, 0, NULL, &mtr);
  170. if (error == DB_FAIL) {
  171. ut_ad(!big_rec);
  172. mtr.commit();
  173. mtr.start();
  174. m_index->set_modified(mtr);
  175. rtr_clean_rtr_info(&rtr_info, true);
  176. rtr_init_rtr_info(&rtr_info, false,
  177. &ins_cur, m_index, false);
  178. rtr_info_update_btr(&ins_cur, &rtr_info);
  179. btr_cur_search_to_nth_level(
  180. m_index, 0, dtuple,
  181. PAGE_CUR_RTREE_INSERT,
  182. BTR_MODIFY_TREE,
  183. &ins_cur, 0,
  184. __FILE__, __LINE__, &mtr);
  185. error = btr_cur_pessimistic_insert(
  186. flag, &ins_cur, &ins_offsets,
  187. &row_heap, dtuple, &rec,
  188. &big_rec, 0, NULL, &mtr);
  189. }
  190. DBUG_EXECUTE_IF(
  191. "row_merge_ins_spatial_fail",
  192. error = DB_FAIL;
  193. );
  194. if (error == DB_SUCCESS) {
  195. if (rtr_info.mbr_adj) {
  196. error = rtr_ins_enlarge_mbr(
  197. &ins_cur, NULL, &mtr);
  198. }
  199. if (error == DB_SUCCESS) {
  200. page_update_max_trx_id(
  201. btr_cur_get_block(&ins_cur),
  202. btr_cur_get_page_zip(&ins_cur),
  203. trx_id, &mtr);
  204. }
  205. }
  206. mtr_commit(&mtr);
  207. rtr_clean_rtr_info(&rtr_info, true);
  208. count++;
  209. }
  210. m_dtuple_vec->clear();
  211. return(error);
  212. }
  213. private:
  214. /** Cache index rows made from a cluster index scan. Usually
  215. for rows on single cluster index page */
  216. typedef std::vector<dtuple_t*, ut_allocator<dtuple_t*> >
  217. idx_tuple_vec;
  218. /** vector used to cache index rows made from cluster index scan */
  219. idx_tuple_vec* m_dtuple_vec;
  220. /** the index being built */
  221. dict_index_t* m_index;
  222. /** memory heap for creating index tuples */
  223. mem_heap_t* m_heap;
  224. };
  225. /* Maximum pending doc memory limit in bytes for a fts tokenization thread */
  226. #define FTS_PENDING_DOC_MEMORY_LIMIT 1000000
  227. /** Insert sorted data tuples to the index.
  228. @param[in] index index to be inserted
  229. @param[in] old_table old table
  230. @param[in] fd file descriptor
  231. @param[in,out] block file buffer
  232. @param[in] row_buf row_buf the sorted data tuples,
  233. or NULL if fd, block will be used instead
  234. @param[in,out] btr_bulk btr bulk instance
  235. @param[in,out] stage performance schema accounting object, used by
  236. ALTER TABLE. If not NULL stage->begin_phase_insert() will be called initially
  237. and then stage->inc() will be called for each record that is processed.
  238. @return DB_SUCCESS or error number */
  239. static MY_ATTRIBUTE((warn_unused_result))
  240. dberr_t
  241. row_merge_insert_index_tuples(
  242. dict_index_t* index,
  243. const dict_table_t* old_table,
  244. int fd,
  245. row_merge_block_t* block,
  246. const row_merge_buf_t* row_buf,
  247. BtrBulk* btr_bulk,
  248. const ib_uint64_t table_total_rows, /*!< in: total rows of old table */
  249. const double pct_progress, /*!< in: total progress
  250. percent until now */
  251. const double pct_cost, /*!< in: current progress percent
  252. */
  253. row_merge_block_t* crypt_block, /*!< in: crypt buf or NULL */
  254. ulint space, /*!< in: space id */
  255. ut_stage_alter_t* stage = NULL);
  256. /******************************************************//**
  257. Encode an index record. */
  258. static MY_ATTRIBUTE((nonnull))
  259. void
  260. row_merge_buf_encode(
  261. /*=================*/
  262. byte** b, /*!< in/out: pointer to
  263. current end of output buffer */
  264. const dict_index_t* index, /*!< in: index */
  265. const mtuple_t* entry, /*!< in: index fields
  266. of the record to encode */
  267. ulint n_fields) /*!< in: number of fields
  268. in the entry */
  269. {
  270. ulint size;
  271. ulint extra_size;
  272. size = rec_get_converted_size_temp(
  273. index, entry->fields, n_fields, &extra_size);
  274. ut_ad(size >= extra_size);
  275. /* Encode extra_size + 1 */
  276. if (extra_size + 1 < 0x80) {
  277. *(*b)++ = (byte) (extra_size + 1);
  278. } else {
  279. ut_ad((extra_size + 1) < 0x8000);
  280. *(*b)++ = (byte) (0x80 | ((extra_size + 1) >> 8));
  281. *(*b)++ = (byte) (extra_size + 1);
  282. }
  283. rec_convert_dtuple_to_temp(*b + extra_size, index,
  284. entry->fields, n_fields);
  285. *b += size;
  286. }
  287. /******************************************************//**
  288. Allocate a sort buffer.
  289. @return own: sort buffer */
  290. static MY_ATTRIBUTE((malloc, nonnull))
  291. row_merge_buf_t*
  292. row_merge_buf_create_low(
  293. /*=====================*/
  294. mem_heap_t* heap, /*!< in: heap where allocated */
  295. dict_index_t* index, /*!< in: secondary index */
  296. ulint max_tuples, /*!< in: maximum number of
  297. data tuples */
  298. ulint buf_size) /*!< in: size of the buffer,
  299. in bytes */
  300. {
  301. row_merge_buf_t* buf;
  302. ut_ad(max_tuples > 0);
  303. ut_ad(max_tuples <= srv_sort_buf_size);
  304. buf = static_cast<row_merge_buf_t*>(mem_heap_zalloc(heap, buf_size));
  305. buf->heap = heap;
  306. buf->index = index;
  307. buf->max_tuples = max_tuples;
  308. buf->tuples = static_cast<mtuple_t*>(
  309. ut_malloc_nokey(2 * max_tuples * sizeof *buf->tuples));
  310. buf->tmp_tuples = buf->tuples + max_tuples;
  311. return(buf);
  312. }
  313. /******************************************************//**
  314. Allocate a sort buffer.
  315. @return own: sort buffer */
  316. row_merge_buf_t*
  317. row_merge_buf_create(
  318. /*=================*/
  319. dict_index_t* index) /*!< in: secondary index */
  320. {
  321. row_merge_buf_t* buf;
  322. ulint max_tuples;
  323. ulint buf_size;
  324. mem_heap_t* heap;
  325. max_tuples = srv_sort_buf_size
  326. / ut_max(static_cast<ulint>(1),
  327. dict_index_get_min_size(index));
  328. buf_size = (sizeof *buf);
  329. heap = mem_heap_create(buf_size);
  330. buf = row_merge_buf_create_low(heap, index, max_tuples, buf_size);
  331. return(buf);
  332. }
  333. /******************************************************//**
  334. Empty a sort buffer.
  335. @return sort buffer */
  336. row_merge_buf_t*
  337. row_merge_buf_empty(
  338. /*================*/
  339. row_merge_buf_t* buf) /*!< in,own: sort buffer */
  340. {
  341. ulint buf_size = sizeof *buf;
  342. ulint max_tuples = buf->max_tuples;
  343. mem_heap_t* heap = buf->heap;
  344. dict_index_t* index = buf->index;
  345. mtuple_t* tuples = buf->tuples;
  346. mem_heap_empty(heap);
  347. buf = static_cast<row_merge_buf_t*>(mem_heap_zalloc(heap, buf_size));
  348. buf->heap = heap;
  349. buf->index = index;
  350. buf->max_tuples = max_tuples;
  351. buf->tuples = tuples;
  352. buf->tmp_tuples = buf->tuples + max_tuples;
  353. return(buf);
  354. }
  355. /******************************************************//**
  356. Deallocate a sort buffer. */
  357. void
  358. row_merge_buf_free(
  359. /*===============*/
  360. row_merge_buf_t* buf) /*!< in,own: sort buffer to be freed */
  361. {
  362. ut_free(buf->tuples);
  363. mem_heap_free(buf->heap);
  364. }
  365. /** Convert the field data from compact to redundant format.
  366. @param[in] row_field field to copy from
  367. @param[out] field field to copy to
  368. @param[in] len length of the field data
  369. @param[in] zip_size compressed BLOB page size,
  370. zero for uncompressed BLOBs
  371. @param[in,out] heap memory heap where to allocate data when
  372. converting to ROW_FORMAT=REDUNDANT, or NULL
  373. when not to invoke
  374. row_merge_buf_redundant_convert(). */
  375. static
  376. void
  377. row_merge_buf_redundant_convert(
  378. const dfield_t* row_field,
  379. dfield_t* field,
  380. ulint len,
  381. const page_size_t& page_size,
  382. mem_heap_t* heap)
  383. {
  384. ut_ad(field->type.mbminlen == 1);
  385. ut_ad(field->type.mbmaxlen > 1);
  386. byte* buf = (byte*) mem_heap_alloc(heap, len);
  387. ulint field_len = row_field->len;
  388. ut_ad(field_len <= len);
  389. if (row_field->ext) {
  390. const byte* field_data = static_cast<byte*>(
  391. dfield_get_data(row_field));
  392. ulint ext_len;
  393. ut_a(field_len >= BTR_EXTERN_FIELD_REF_SIZE);
  394. ut_a(memcmp(field_data + field_len - BTR_EXTERN_FIELD_REF_SIZE,
  395. field_ref_zero, BTR_EXTERN_FIELD_REF_SIZE));
  396. byte* data = btr_copy_externally_stored_field(
  397. &ext_len, field_data, page_size, field_len, heap);
  398. ut_ad(ext_len < len);
  399. memcpy(buf, data, ext_len);
  400. field_len = ext_len;
  401. } else {
  402. memcpy(buf, row_field->data, field_len);
  403. }
  404. memset(buf + field_len, 0x20, len - field_len);
  405. dfield_set_data(field, buf, len);
  406. }
  407. /** Insert a data tuple into a sort buffer.
  408. @param[in,out] buf sort buffer
  409. @param[in] fts_index fts index to be created
  410. @param[in] old_table original table
  411. @param[in] new_table new table
  412. @param[in,out] psort_info parallel sort info
  413. @param[in] row table row
  414. @param[in] ext cache of externally stored
  415. column prefixes, or NULL
  416. @param[in,out] doc_id Doc ID if we are creating
  417. FTS index
  418. @param[in,out] conv_heap memory heap where to allocate data when
  419. converting to ROW_FORMAT=REDUNDANT, or NULL
  420. when not to invoke
  421. row_merge_buf_redundant_convert()
  422. @param[in,out] err set if error occurs
  423. @param[in,out] v_heap heap memory to process data for virtual column
  424. @param[in,out] my_table mysql table object
  425. @param[in] trx transaction object
  426. @return number of rows added, 0 if out of space */
  427. static
  428. ulint
  429. row_merge_buf_add(
  430. row_merge_buf_t* buf,
  431. dict_index_t* fts_index,
  432. const dict_table_t* old_table,
  433. const dict_table_t* new_table,
  434. fts_psort_t* psort_info,
  435. const dtuple_t* row,
  436. const row_ext_t* ext,
  437. doc_id_t* doc_id,
  438. mem_heap_t* conv_heap,
  439. dberr_t* err,
  440. mem_heap_t** v_heap,
  441. TABLE* my_table,
  442. trx_t* trx)
  443. {
  444. ulint i;
  445. const dict_index_t* index;
  446. mtuple_t* entry;
  447. dfield_t* field;
  448. const dict_field_t* ifield;
  449. ulint n_fields;
  450. ulint data_size;
  451. ulint extra_size;
  452. ulint bucket = 0;
  453. doc_id_t write_doc_id;
  454. ulint n_row_added = 0;
  455. DBUG_ENTER("row_merge_buf_add");
  456. if (buf->n_tuples >= buf->max_tuples) {
  457. DBUG_RETURN(0);
  458. }
  459. DBUG_EXECUTE_IF(
  460. "ib_row_merge_buf_add_two",
  461. if (buf->n_tuples >= 2) DBUG_RETURN(0););
  462. UNIV_PREFETCH_R(row->fields);
  463. /* If we are building FTS index, buf->index points to
  464. the 'fts_sort_idx', and real FTS index is stored in
  465. fts_index */
  466. index = (buf->index->type & DICT_FTS) ? fts_index : buf->index;
  467. /* create spatial index should not come here */
  468. ut_ad(!dict_index_is_spatial(index));
  469. n_fields = dict_index_get_n_fields(index);
  470. entry = &buf->tuples[buf->n_tuples];
  471. field = entry->fields = static_cast<dfield_t*>(
  472. mem_heap_alloc(buf->heap, n_fields * sizeof *entry->fields));
  473. data_size = 0;
  474. extra_size = UT_BITS_IN_BYTES(index->n_nullable);
  475. ifield = dict_index_get_nth_field(index, 0);
  476. for (i = 0; i < n_fields; i++, field++, ifield++) {
  477. ulint len;
  478. const dict_col_t* col;
  479. ulint col_no;
  480. ulint fixed_len;
  481. const dfield_t* row_field;
  482. col = ifield->col;
  483. const dict_v_col_t* v_col = NULL;
  484. if (dict_col_is_virtual(col)) {
  485. v_col = reinterpret_cast<const dict_v_col_t*>(col);
  486. }
  487. col_no = dict_col_get_no(col);
  488. /* Process the Doc ID column */
  489. if (*doc_id > 0
  490. && col_no == index->table->fts->doc_col
  491. && !dict_col_is_virtual(col)) {
  492. fts_write_doc_id((byte*) &write_doc_id, *doc_id);
  493. /* Note: field->data now points to a value on the
  494. stack: &write_doc_id after dfield_set_data(). Because
  495. there is only one doc_id per row, it shouldn't matter.
  496. We allocate a new buffer before we leave the function
  497. later below. */
  498. dfield_set_data(
  499. field, &write_doc_id, sizeof(write_doc_id));
  500. field->type.mtype = ifield->col->mtype;
  501. field->type.prtype = ifield->col->prtype;
  502. field->type.mbminlen = 0;
  503. field->type.mbmaxlen = 0;
  504. field->type.len = ifield->col->len;
  505. } else {
  506. /* Use callback to get the virtual column value */
  507. if (dict_col_is_virtual(col)) {
  508. dict_index_t* clust_index
  509. = dict_table_get_first_index(new_table);
  510. row_field = innobase_get_computed_value(
  511. row, v_col, clust_index,
  512. v_heap, NULL, ifield, trx->mysql_thd,
  513. my_table, old_table, NULL, NULL);
  514. if (row_field == NULL) {
  515. *err = DB_COMPUTE_VALUE_FAILED;
  516. DBUG_RETURN(0);
  517. }
  518. dfield_copy(field, row_field);
  519. } else {
  520. row_field = dtuple_get_nth_field(row, col_no);
  521. dfield_copy(field, row_field);
  522. }
  523. /* Tokenize and process data for FTS */
  524. if (index->type & DICT_FTS) {
  525. fts_doc_item_t* doc_item;
  526. byte* value;
  527. void* ptr;
  528. const ulint max_trial_count = 10000;
  529. ulint trial_count = 0;
  530. /* fetch Doc ID if it already exists
  531. in the row, and not supplied by the
  532. caller. Even if the value column is
  533. NULL, we still need to get the Doc
  534. ID so to maintain the correct max
  535. Doc ID */
  536. if (*doc_id == 0) {
  537. const dfield_t* doc_field;
  538. doc_field = dtuple_get_nth_field(
  539. row,
  540. index->table->fts->doc_col);
  541. *doc_id = (doc_id_t) mach_read_from_8(
  542. static_cast<byte*>(
  543. dfield_get_data(doc_field)));
  544. if (*doc_id == 0) {
  545. ib::warn() << "FTS Doc ID is"
  546. " zero. Record"
  547. " skipped";
  548. DBUG_RETURN(0);
  549. }
  550. }
  551. if (dfield_is_null(field)) {
  552. n_row_added = 1;
  553. continue;
  554. }
  555. ptr = ut_malloc_nokey(sizeof(*doc_item)
  556. + field->len);
  557. doc_item = static_cast<fts_doc_item_t*>(ptr);
  558. value = static_cast<byte*>(ptr)
  559. + sizeof(*doc_item);
  560. memcpy(value, field->data, field->len);
  561. field->data = value;
  562. doc_item->field = field;
  563. doc_item->doc_id = *doc_id;
  564. bucket = *doc_id % fts_sort_pll_degree;
  565. /* Add doc item to fts_doc_list */
  566. mutex_enter(&psort_info[bucket].mutex);
  567. if (psort_info[bucket].error == DB_SUCCESS) {
  568. UT_LIST_ADD_LAST(
  569. psort_info[bucket].fts_doc_list,
  570. doc_item);
  571. psort_info[bucket].memory_used +=
  572. sizeof(*doc_item) + field->len;
  573. } else {
  574. ut_free(doc_item);
  575. }
  576. mutex_exit(&psort_info[bucket].mutex);
  577. /* Sleep when memory used exceeds limit*/
  578. while (psort_info[bucket].memory_used
  579. > FTS_PENDING_DOC_MEMORY_LIMIT
  580. && trial_count++ < max_trial_count) {
  581. os_thread_sleep(1000);
  582. }
  583. n_row_added = 1;
  584. continue;
  585. }
  586. if (field->len != UNIV_SQL_NULL
  587. && col->mtype == DATA_MYSQL
  588. && col->len != field->len) {
  589. if (conv_heap != NULL) {
  590. row_merge_buf_redundant_convert(
  591. row_field, field, col->len,
  592. dict_table_page_size(old_table),
  593. conv_heap);
  594. } else {
  595. /* Field length mismatch should not
  596. happen when rebuilding redundant row
  597. format table. */
  598. ut_ad(dict_table_is_comp(index->table));
  599. }
  600. }
  601. }
  602. len = dfield_get_len(field);
  603. if (dfield_is_null(field)) {
  604. ut_ad(!(col->prtype & DATA_NOT_NULL));
  605. continue;
  606. } else if (!ext) {
  607. } else if (dict_index_is_clust(index)) {
  608. /* Flag externally stored fields. */
  609. const byte* buf = row_ext_lookup(ext, col_no,
  610. &len);
  611. if (UNIV_LIKELY_NULL(buf)) {
  612. ut_a(buf != field_ref_zero);
  613. if (i < dict_index_get_n_unique(index)) {
  614. dfield_set_data(field, buf, len);
  615. } else {
  616. dfield_set_ext(field);
  617. len = dfield_get_len(field);
  618. }
  619. }
  620. } else if (!dict_col_is_virtual(col)) {
  621. /* Only non-virtual column are stored externally */
  622. const byte* buf = row_ext_lookup(ext, col_no,
  623. &len);
  624. if (UNIV_LIKELY_NULL(buf)) {
  625. ut_a(buf != field_ref_zero);
  626. dfield_set_data(field, buf, len);
  627. }
  628. }
  629. /* If a column prefix index, take only the prefix */
  630. if (ifield->prefix_len) {
  631. len = dtype_get_at_most_n_mbchars(
  632. col->prtype,
  633. col->mbminlen, col->mbmaxlen,
  634. ifield->prefix_len,
  635. len,
  636. static_cast<char*>(dfield_get_data(field)));
  637. dfield_set_len(field, len);
  638. }
  639. ut_ad(len <= col->len
  640. || DATA_LARGE_MTYPE(col->mtype));
  641. fixed_len = ifield->fixed_len;
  642. if (fixed_len && !dict_table_is_comp(index->table)
  643. && col->mbminlen != col->mbmaxlen) {
  644. /* CHAR in ROW_FORMAT=REDUNDANT is always
  645. fixed-length, but in the temporary file it is
  646. variable-length for variable-length character
  647. sets. */
  648. fixed_len = 0;
  649. }
  650. if (fixed_len) {
  651. #ifdef UNIV_DEBUG
  652. /* len should be between size calcualted base on
  653. mbmaxlen and mbminlen */
  654. ut_ad(len <= fixed_len);
  655. ut_ad(!col->mbmaxlen || len >= col->mbminlen
  656. * (fixed_len / col->mbmaxlen));
  657. ut_ad(!dfield_is_ext(field));
  658. #endif /* UNIV_DEBUG */
  659. } else if (dfield_is_ext(field)) {
  660. extra_size += 2;
  661. } else if (len < 128
  662. || (!DATA_BIG_COL(col))) {
  663. extra_size++;
  664. } else {
  665. /* For variable-length columns, we look up the
  666. maximum length from the column itself. If this
  667. is a prefix index column shorter than 256 bytes,
  668. this will waste one byte. */
  669. extra_size += 2;
  670. }
  671. data_size += len;
  672. }
  673. /* If this is FTS index, we already populated the sort buffer, return
  674. here */
  675. if (index->type & DICT_FTS) {
  676. DBUG_RETURN(n_row_added);
  677. }
  678. #ifdef UNIV_DEBUG
  679. {
  680. ulint size;
  681. ulint extra;
  682. size = rec_get_converted_size_temp(
  683. index, entry->fields, n_fields, &extra);
  684. ut_ad(data_size + extra_size == size);
  685. ut_ad(extra_size == extra);
  686. }
  687. #endif /* UNIV_DEBUG */
  688. /* Add to the total size of the record in row_merge_block_t
  689. the encoded length of extra_size and the extra bytes (extra_size).
  690. See row_merge_buf_write() for the variable-length encoding
  691. of extra_size. */
  692. data_size += (extra_size + 1) + ((extra_size + 1) >= 0x80);
  693. /* Record size can exceed page size while converting to
  694. redundant row format. But there is assert
  695. ut_ad(size < UNIV_PAGE_SIZE) in rec_offs_data_size().
  696. It may hit the assert before attempting to insert the row. */
  697. if (conv_heap != NULL && data_size > UNIV_PAGE_SIZE) {
  698. *err = DB_TOO_BIG_RECORD;
  699. }
  700. ut_ad(data_size < srv_sort_buf_size);
  701. /* Reserve bytes for the end marker of row_merge_block_t. */
  702. if (buf->total_size + data_size >= srv_sort_buf_size) {
  703. DBUG_RETURN(0);
  704. }
  705. buf->total_size += data_size;
  706. buf->n_tuples++;
  707. n_row_added++;
  708. field = entry->fields;
  709. /* Copy the data fields. */
  710. do {
  711. dfield_dup(field++, buf->heap);
  712. } while (--n_fields);
  713. if (conv_heap != NULL) {
  714. mem_heap_empty(conv_heap);
  715. }
  716. DBUG_RETURN(n_row_added);
  717. }
  718. /*************************************************************//**
  719. Report a duplicate key. */
  720. void
  721. row_merge_dup_report(
  722. /*=================*/
  723. row_merge_dup_t* dup, /*!< in/out: for reporting duplicates */
  724. const dfield_t* entry) /*!< in: duplicate index entry */
  725. {
  726. if (!dup->n_dup++) {
  727. /* Only report the first duplicate record,
  728. but count all duplicate records. */
  729. innobase_fields_to_mysql(dup->table, dup->index, entry);
  730. }
  731. }
  732. /*************************************************************//**
  733. Compare two tuples.
  734. @return positive, 0, negative if a is greater, equal, less, than b,
  735. respectively */
  736. static MY_ATTRIBUTE((warn_unused_result))
  737. int
  738. row_merge_tuple_cmp(
  739. /*================*/
  740. ulint n_uniq, /*!< in: number of unique fields */
  741. ulint n_field,/*!< in: number of fields */
  742. const mtuple_t& a, /*!< in: first tuple to be compared */
  743. const mtuple_t& b, /*!< in: second tuple to be compared */
  744. row_merge_dup_t* dup) /*!< in/out: for reporting duplicates,
  745. NULL if non-unique index */
  746. {
  747. int cmp;
  748. const dfield_t* af = a.fields;
  749. const dfield_t* bf = b.fields;
  750. ulint n = n_uniq;
  751. ut_ad(n_uniq > 0);
  752. ut_ad(n_uniq <= n_field);
  753. /* Compare the fields of the tuples until a difference is
  754. found or we run out of fields to compare. If !cmp at the
  755. end, the tuples are equal. */
  756. do {
  757. cmp = cmp_dfield_dfield(af++, bf++);
  758. } while (!cmp && --n);
  759. if (cmp) {
  760. return(cmp);
  761. }
  762. if (dup) {
  763. /* Report a duplicate value error if the tuples are
  764. logically equal. NULL columns are logically inequal,
  765. although they are equal in the sorting order. Find
  766. out if any of the fields are NULL. */
  767. for (const dfield_t* df = a.fields; df != af; df++) {
  768. if (dfield_is_null(df)) {
  769. goto no_report;
  770. }
  771. }
  772. row_merge_dup_report(dup, a.fields);
  773. }
  774. no_report:
  775. /* The n_uniq fields were equal, but we compare all fields so
  776. that we will get the same (internal) order as in the B-tree. */
  777. for (n = n_field - n_uniq + 1; --n; ) {
  778. cmp = cmp_dfield_dfield(af++, bf++);
  779. if (cmp) {
  780. return(cmp);
  781. }
  782. }
  783. /* This should never be reached, except in a secondary index
  784. when creating a secondary index and a PRIMARY KEY, and there
  785. is a duplicate in the PRIMARY KEY that has not been detected
  786. yet. Internally, an index must never contain duplicates. */
  787. return(cmp);
  788. }
  789. /** Wrapper for row_merge_tuple_sort() to inject some more context to
  790. UT_SORT_FUNCTION_BODY().
  791. @param tuples array of tuples that being sorted
  792. @param aux work area, same size as tuples[]
  793. @param low lower bound of the sorting area, inclusive
  794. @param high upper bound of the sorting area, inclusive */
  795. #define row_merge_tuple_sort_ctx(tuples, aux, low, high) \
  796. row_merge_tuple_sort(n_uniq, n_field, dup, tuples, aux, low, high)
  797. /** Wrapper for row_merge_tuple_cmp() to inject some more context to
  798. UT_SORT_FUNCTION_BODY().
  799. @param a first tuple to be compared
  800. @param b second tuple to be compared
  801. @return positive, 0, negative, if a is greater, equal, less, than b,
  802. respectively */
  803. #define row_merge_tuple_cmp_ctx(a,b) \
  804. row_merge_tuple_cmp(n_uniq, n_field, a, b, dup)
  805. /**********************************************************************//**
  806. Merge sort the tuple buffer in main memory. */
  807. static
  808. void
  809. row_merge_tuple_sort(
  810. /*=================*/
  811. ulint n_uniq, /*!< in: number of unique fields */
  812. ulint n_field,/*!< in: number of fields */
  813. row_merge_dup_t* dup, /*!< in/out: reporter of duplicates
  814. (NULL if non-unique index) */
  815. mtuple_t* tuples, /*!< in/out: tuples */
  816. mtuple_t* aux, /*!< in/out: work area */
  817. ulint low, /*!< in: lower bound of the
  818. sorting area, inclusive */
  819. ulint high) /*!< in: upper bound of the
  820. sorting area, exclusive */
  821. {
  822. ut_ad(n_field > 0);
  823. ut_ad(n_uniq <= n_field);
  824. UT_SORT_FUNCTION_BODY(row_merge_tuple_sort_ctx,
  825. tuples, aux, low, high, row_merge_tuple_cmp_ctx);
  826. }
  827. /******************************************************//**
  828. Sort a buffer. */
  829. void
  830. row_merge_buf_sort(
  831. /*===============*/
  832. row_merge_buf_t* buf, /*!< in/out: sort buffer */
  833. row_merge_dup_t* dup) /*!< in/out: reporter of duplicates
  834. (NULL if non-unique index) */
  835. {
  836. ut_ad(!dict_index_is_spatial(buf->index));
  837. row_merge_tuple_sort(dict_index_get_n_unique(buf->index),
  838. dict_index_get_n_fields(buf->index),
  839. dup,
  840. buf->tuples, buf->tmp_tuples, 0, buf->n_tuples);
  841. }
  842. /******************************************************//**
  843. Write a buffer to a block. */
  844. void
  845. row_merge_buf_write(
  846. /*================*/
  847. const row_merge_buf_t* buf, /*!< in: sorted buffer */
  848. const merge_file_t* of UNIV_UNUSED,
  849. /*!< in: output file */
  850. row_merge_block_t* block) /*!< out: buffer for writing to file */
  851. {
  852. const dict_index_t* index = buf->index;
  853. ulint n_fields= dict_index_get_n_fields(index);
  854. byte* b = &block[0];
  855. DBUG_ENTER("row_merge_buf_write");
  856. for (ulint i = 0; i < buf->n_tuples; i++) {
  857. const mtuple_t* entry = &buf->tuples[i];
  858. row_merge_buf_encode(&b, index, entry, n_fields);
  859. ut_ad(b < &block[srv_sort_buf_size]);
  860. DBUG_LOG("ib_merge_sort",
  861. reinterpret_cast<const void*>(b) << ','
  862. << of->fd << ',' << of->offset << ' ' <<
  863. i << ": " <<
  864. rec_printer(entry->fields, n_fields).str());
  865. }
  866. /* Write an "end-of-chunk" marker. */
  867. ut_a(b < &block[srv_sort_buf_size]);
  868. ut_a(b == &block[0] + buf->total_size);
  869. *b++ = 0;
  870. #ifdef UNIV_DEBUG_VALGRIND
  871. /* The rest of the block is uninitialized. Initialize it
  872. to avoid bogus warnings. */
  873. memset(b, 0xff, &block[srv_sort_buf_size] - b);
  874. #endif /* UNIV_DEBUG_VALGRIND */
  875. DBUG_LOG("ib_merge_sort",
  876. "write " << reinterpret_cast<const void*>(b) << ','
  877. << of->fd << ',' << of->offset << " EOF");
  878. DBUG_VOID_RETURN;
  879. }
  880. /******************************************************//**
  881. Create a memory heap and allocate space for row_merge_rec_offsets()
  882. and mrec_buf_t[3].
  883. @return memory heap */
  884. static
  885. mem_heap_t*
  886. row_merge_heap_create(
  887. /*==================*/
  888. const dict_index_t* index, /*!< in: record descriptor */
  889. mrec_buf_t** buf, /*!< out: 3 buffers */
  890. ulint** offsets1, /*!< out: offsets */
  891. ulint** offsets2) /*!< out: offsets */
  892. {
  893. ulint i = 1 + REC_OFFS_HEADER_SIZE
  894. + dict_index_get_n_fields(index);
  895. mem_heap_t* heap = mem_heap_create(2 * i * sizeof **offsets1
  896. + 3 * sizeof **buf);
  897. *buf = static_cast<mrec_buf_t*>(
  898. mem_heap_alloc(heap, 3 * sizeof **buf));
  899. *offsets1 = static_cast<ulint*>(
  900. mem_heap_alloc(heap, i * sizeof **offsets1));
  901. *offsets2 = static_cast<ulint*>(
  902. mem_heap_alloc(heap, i * sizeof **offsets2));
  903. (*offsets1)[0] = (*offsets2)[0] = i;
  904. (*offsets1)[1] = (*offsets2)[1] = dict_index_get_n_fields(index);
  905. return(heap);
  906. }
  907. /** Read a merge block from the file system.
  908. @return whether the request was completed successfully */
  909. bool
  910. row_merge_read(
  911. /*===========*/
  912. int fd, /*!< in: file descriptor */
  913. ulint offset, /*!< in: offset where to read
  914. in number of row_merge_block_t
  915. elements */
  916. row_merge_block_t* buf, /*!< out: data */
  917. row_merge_block_t* crypt_buf, /*!< in: crypt buf or NULL */
  918. ulint space) /*!< in: space id */
  919. {
  920. os_offset_t ofs = ((os_offset_t) offset) * srv_sort_buf_size;
  921. DBUG_ENTER("row_merge_read");
  922. DBUG_LOG("ib_merge_sort", "fd=" << fd << " ofs=" << ofs);
  923. DBUG_EXECUTE_IF("row_merge_read_failure", DBUG_RETURN(FALSE););
  924. IORequest request(IORequest::READ);
  925. const bool success = os_file_read_no_error_handling_int_fd(
  926. request, fd, buf, ofs, srv_sort_buf_size);
  927. /* If encryption is enabled decrypt buffer */
  928. if (success && log_tmp_is_encrypted()) {
  929. if (!log_tmp_block_decrypt(buf, srv_sort_buf_size,
  930. crypt_buf, ofs, space)) {
  931. return (FALSE);
  932. }
  933. srv_stats.n_merge_blocks_decrypted.inc();
  934. memcpy(buf, crypt_buf, srv_sort_buf_size);
  935. }
  936. #ifdef POSIX_FADV_DONTNEED
  937. /* Each block is read exactly once. Free up the file cache. */
  938. posix_fadvise(fd, ofs, srv_sort_buf_size, POSIX_FADV_DONTNEED);
  939. #endif /* POSIX_FADV_DONTNEED */
  940. if (!success) {
  941. ib::error() << "Failed to read merge block at " << ofs;
  942. }
  943. DBUG_RETURN(success);
  944. }
  945. /********************************************************************//**
  946. Write a merge block to the file system.
  947. @return whether the request was completed successfully */
  948. UNIV_INTERN
  949. bool
  950. row_merge_write(
  951. /*============*/
  952. int fd, /*!< in: file descriptor */
  953. ulint offset, /*!< in: offset where to write,
  954. in number of row_merge_block_t elements */
  955. const void* buf, /*!< in: data */
  956. void* crypt_buf, /*!< in: crypt buf or NULL */
  957. ulint space) /*!< in: space id */
  958. {
  959. size_t buf_len = srv_sort_buf_size;
  960. os_offset_t ofs = buf_len * (os_offset_t) offset;
  961. void* out_buf = (void *)buf;
  962. DBUG_ENTER("row_merge_write");
  963. DBUG_LOG("ib_merge_sort", "fd=" << fd << " ofs=" << ofs);
  964. DBUG_EXECUTE_IF("row_merge_write_failure", DBUG_RETURN(FALSE););
  965. /* For encrypted tables, encrypt data before writing */
  966. if (log_tmp_is_encrypted()) {
  967. if (!log_tmp_block_encrypt(static_cast<const byte*>(buf),
  968. buf_len,
  969. static_cast<byte*>(crypt_buf),
  970. ofs, space)) {
  971. return false;
  972. }
  973. srv_stats.n_merge_blocks_encrypted.inc();
  974. out_buf = crypt_buf;
  975. }
  976. IORequest request(IORequest::WRITE);
  977. const bool success = os_file_write_int_fd(
  978. request, "(merge)", fd, out_buf, ofs, buf_len);
  979. #ifdef POSIX_FADV_DONTNEED
  980. /* The block will be needed on the next merge pass,
  981. but it can be evicted from the file cache meanwhile. */
  982. posix_fadvise(fd, ofs, buf_len, POSIX_FADV_DONTNEED);
  983. #endif /* POSIX_FADV_DONTNEED */
  984. DBUG_RETURN(success);
  985. }
  986. /********************************************************************//**
  987. Read a merge record.
  988. @return pointer to next record, or NULL on I/O error or end of list */
  989. const byte*
  990. row_merge_read_rec(
  991. /*===============*/
  992. row_merge_block_t* block, /*!< in/out: file buffer */
  993. mrec_buf_t* buf, /*!< in/out: secondary buffer */
  994. const byte* b, /*!< in: pointer to record */
  995. const dict_index_t* index, /*!< in: index of the record */
  996. int fd, /*!< in: file descriptor */
  997. ulint* foffs, /*!< in/out: file offset */
  998. const mrec_t** mrec, /*!< out: pointer to merge record,
  999. or NULL on end of list
  1000. (non-NULL on I/O error) */
  1001. ulint* offsets,/*!< out: offsets of mrec */
  1002. row_merge_block_t* crypt_block, /*!< in: crypt buf or NULL */
  1003. ulint space) /*!< in: space id */
  1004. {
  1005. ulint extra_size;
  1006. ulint data_size;
  1007. ulint avail_size;
  1008. ut_ad(b >= &block[0]);
  1009. ut_ad(b < &block[srv_sort_buf_size]);
  1010. ut_ad(*offsets == 1 + REC_OFFS_HEADER_SIZE
  1011. + dict_index_get_n_fields(index));
  1012. DBUG_ENTER("row_merge_read_rec");
  1013. extra_size = *b++;
  1014. if (UNIV_UNLIKELY(!extra_size)) {
  1015. /* End of list */
  1016. *mrec = NULL;
  1017. DBUG_LOG("ib_merge_sort",
  1018. "read " << reinterpret_cast<const void*>(b) << ',' <<
  1019. reinterpret_cast<const void*>(block) << ',' <<
  1020. fd << ',' << *foffs << " EOF");
  1021. DBUG_RETURN(NULL);
  1022. }
  1023. if (extra_size >= 0x80) {
  1024. /* Read another byte of extra_size. */
  1025. if (UNIV_UNLIKELY(b >= &block[srv_sort_buf_size])) {
  1026. if (!row_merge_read(fd, ++(*foffs), block,
  1027. crypt_block,
  1028. space)) {
  1029. err_exit:
  1030. /* Signal I/O error. */
  1031. *mrec = b;
  1032. DBUG_RETURN(NULL);
  1033. }
  1034. /* Wrap around to the beginning of the buffer. */
  1035. b = &block[0];
  1036. }
  1037. extra_size = (extra_size & 0x7f) << 8;
  1038. extra_size |= *b++;
  1039. }
  1040. /* Normalize extra_size. Above, value 0 signals "end of list". */
  1041. extra_size--;
  1042. /* Read the extra bytes. */
  1043. if (UNIV_UNLIKELY(b + extra_size >= &block[srv_sort_buf_size])) {
  1044. /* The record spans two blocks. Copy the entire record
  1045. to the auxiliary buffer and handle this as a special
  1046. case. */
  1047. avail_size = &block[srv_sort_buf_size] - b;
  1048. ut_ad(avail_size < sizeof *buf);
  1049. memcpy(*buf, b, avail_size);
  1050. if (!row_merge_read(fd, ++(*foffs), block,
  1051. crypt_block,
  1052. space)) {
  1053. goto err_exit;
  1054. }
  1055. /* Wrap around to the beginning of the buffer. */
  1056. b = &block[0];
  1057. /* Copy the record. */
  1058. memcpy(*buf + avail_size, b, extra_size - avail_size);
  1059. b += extra_size - avail_size;
  1060. *mrec = *buf + extra_size;
  1061. rec_init_offsets_temp(*mrec, index, offsets);
  1062. data_size = rec_offs_data_size(offsets);
  1063. /* These overflows should be impossible given that
  1064. records are much smaller than either buffer, and
  1065. the record starts near the beginning of each buffer. */
  1066. ut_a(extra_size + data_size < sizeof *buf);
  1067. ut_a(b + data_size < &block[srv_sort_buf_size]);
  1068. /* Copy the data bytes. */
  1069. memcpy(*buf + extra_size, b, data_size);
  1070. b += data_size;
  1071. goto func_exit;
  1072. }
  1073. *mrec = b + extra_size;
  1074. rec_init_offsets_temp(*mrec, index, offsets);
  1075. data_size = rec_offs_data_size(offsets);
  1076. ut_ad(extra_size + data_size < sizeof *buf);
  1077. b += extra_size + data_size;
  1078. if (UNIV_LIKELY(b < &block[srv_sort_buf_size])) {
  1079. /* The record fits entirely in the block.
  1080. This is the normal case. */
  1081. goto func_exit;
  1082. }
  1083. /* The record spans two blocks. Copy it to buf. */
  1084. b -= extra_size + data_size;
  1085. avail_size = &block[srv_sort_buf_size] - b;
  1086. memcpy(*buf, b, avail_size);
  1087. *mrec = *buf + extra_size;
  1088. /* We cannot invoke rec_offs_make_valid() here, because there
  1089. are no REC_N_NEW_EXTRA_BYTES between extra_size and data_size.
  1090. Similarly, rec_offs_validate() would fail, because it invokes
  1091. rec_get_status(). */
  1092. ut_d(offsets[2] = (ulint) *mrec);
  1093. ut_d(offsets[3] = (ulint) index);
  1094. if (!row_merge_read(fd, ++(*foffs), block,
  1095. crypt_block,
  1096. space)) {
  1097. goto err_exit;
  1098. }
  1099. /* Wrap around to the beginning of the buffer. */
  1100. b = &block[0];
  1101. /* Copy the rest of the record. */
  1102. memcpy(*buf + avail_size, b, extra_size + data_size - avail_size);
  1103. b += extra_size + data_size - avail_size;
  1104. func_exit:
  1105. DBUG_LOG("ib_merge_sort",
  1106. reinterpret_cast<const void*>(b) << ',' <<
  1107. reinterpret_cast<const void*>(block)
  1108. << ",fd=" << fd << ',' << *foffs << ": "
  1109. << rec_printer(*mrec, 0, offsets).str());
  1110. DBUG_RETURN(b);
  1111. }
  1112. /********************************************************************//**
  1113. Write a merge record. */
  1114. static
  1115. void
  1116. row_merge_write_rec_low(
  1117. /*====================*/
  1118. byte* b, /*!< out: buffer */
  1119. ulint e, /*!< in: encoded extra_size */
  1120. #ifndef DBUG_OFF
  1121. ulint size, /*!< in: total size to write */
  1122. int fd, /*!< in: file descriptor */
  1123. ulint foffs, /*!< in: file offset */
  1124. #endif /* !DBUG_OFF */
  1125. const mrec_t* mrec, /*!< in: record to write */
  1126. const ulint* offsets)/*!< in: offsets of mrec */
  1127. #ifdef DBUG_OFF
  1128. # define row_merge_write_rec_low(b, e, size, fd, foffs, mrec, offsets) \
  1129. row_merge_write_rec_low(b, e, mrec, offsets)
  1130. #endif /* DBUG_OFF */
  1131. {
  1132. DBUG_ENTER("row_merge_write_rec_low");
  1133. #ifndef DBUG_OFF
  1134. const byte* const end = b + size;
  1135. #endif /* DBUG_OFF */
  1136. DBUG_ASSERT(e == rec_offs_extra_size(offsets) + 1);
  1137. DBUG_LOG("ib_merge_sort",
  1138. reinterpret_cast<const void*>(b) << ",fd=" << fd << ','
  1139. << foffs << ": " << rec_printer(mrec, 0, offsets).str());
  1140. if (e < 0x80) {
  1141. *b++ = (byte) e;
  1142. } else {
  1143. *b++ = (byte) (0x80 | (e >> 8));
  1144. *b++ = (byte) e;
  1145. }
  1146. memcpy(b, mrec - rec_offs_extra_size(offsets), rec_offs_size(offsets));
  1147. DBUG_SLOW_ASSERT(b + rec_offs_size(offsets) == end);
  1148. DBUG_VOID_RETURN;
  1149. }
  1150. /********************************************************************//**
  1151. Write a merge record.
  1152. @return pointer to end of block, or NULL on error */
  1153. static
  1154. byte*
  1155. row_merge_write_rec(
  1156. /*================*/
  1157. row_merge_block_t* block, /*!< in/out: file buffer */
  1158. mrec_buf_t* buf, /*!< in/out: secondary buffer */
  1159. byte* b, /*!< in: pointer to end of block */
  1160. int fd, /*!< in: file descriptor */
  1161. ulint* foffs, /*!< in/out: file offset */
  1162. const mrec_t* mrec, /*!< in: record to write */
  1163. const ulint* offsets,/*!< in: offsets of mrec */
  1164. row_merge_block_t* crypt_block, /*!< in: crypt buf or NULL */
  1165. ulint space) /*!< in: space id */
  1166. {
  1167. ulint extra_size;
  1168. ulint size;
  1169. ulint avail_size;
  1170. ut_ad(block);
  1171. ut_ad(buf);
  1172. ut_ad(b >= &block[0]);
  1173. ut_ad(b < &block[srv_sort_buf_size]);
  1174. ut_ad(mrec);
  1175. ut_ad(foffs);
  1176. ut_ad(mrec < &block[0] || mrec > &block[srv_sort_buf_size]);
  1177. ut_ad(mrec < buf[0] || mrec > buf[1]);
  1178. /* Normalize extra_size. Value 0 signals "end of list". */
  1179. extra_size = rec_offs_extra_size(offsets) + 1;
  1180. size = extra_size + (extra_size >= 0x80)
  1181. + rec_offs_data_size(offsets);
  1182. if (UNIV_UNLIKELY(b + size >= &block[srv_sort_buf_size])) {
  1183. /* The record spans two blocks.
  1184. Copy it to the temporary buffer first. */
  1185. avail_size = &block[srv_sort_buf_size] - b;
  1186. row_merge_write_rec_low(buf[0],
  1187. extra_size, size, fd, *foffs,
  1188. mrec, offsets);
  1189. /* Copy the head of the temporary buffer, write
  1190. the completed block, and copy the tail of the
  1191. record to the head of the new block. */
  1192. memcpy(b, buf[0], avail_size);
  1193. if (!row_merge_write(fd, (*foffs)++, block,
  1194. crypt_block,
  1195. space)) {
  1196. return(NULL);
  1197. }
  1198. UNIV_MEM_INVALID(&block[0], srv_sort_buf_size);
  1199. /* Copy the rest. */
  1200. b = &block[0];
  1201. memcpy(b, buf[0] + avail_size, size - avail_size);
  1202. b += size - avail_size;
  1203. } else {
  1204. row_merge_write_rec_low(b, extra_size, size, fd, *foffs,
  1205. mrec, offsets);
  1206. b += size;
  1207. }
  1208. return(b);
  1209. }
  1210. /********************************************************************//**
  1211. Write an end-of-list marker.
  1212. @return pointer to end of block, or NULL on error */
  1213. static
  1214. byte*
  1215. row_merge_write_eof(
  1216. /*================*/
  1217. row_merge_block_t* block, /*!< in/out: file buffer */
  1218. byte* b, /*!< in: pointer to end of block */
  1219. int fd, /*!< in: file descriptor */
  1220. ulint* foffs, /*!< in/out: file offset */
  1221. row_merge_block_t* crypt_block, /*!< in: crypt buf or NULL */
  1222. ulint space) /*!< in: space id */
  1223. {
  1224. ut_ad(block);
  1225. ut_ad(b >= &block[0]);
  1226. ut_ad(b < &block[srv_sort_buf_size]);
  1227. ut_ad(foffs);
  1228. DBUG_ENTER("row_merge_write_eof");
  1229. DBUG_LOG("ib_merge_sort",
  1230. reinterpret_cast<const void*>(b) << ',' <<
  1231. reinterpret_cast<const void*>(block) <<
  1232. ",fd=" << fd << ',' << *foffs);
  1233. *b++ = 0;
  1234. UNIV_MEM_ASSERT_RW(&block[0], b - &block[0]);
  1235. UNIV_MEM_ASSERT_W(&block[0], srv_sort_buf_size);
  1236. #ifdef UNIV_DEBUG_VALGRIND
  1237. /* The rest of the block is uninitialized. Initialize it
  1238. to avoid bogus warnings. */
  1239. memset(b, 0xff, &block[srv_sort_buf_size] - b);
  1240. #endif /* UNIV_DEBUG_VALGRIND */
  1241. if (!row_merge_write(fd, (*foffs)++, block, crypt_block, space)) {
  1242. DBUG_RETURN(NULL);
  1243. }
  1244. UNIV_MEM_INVALID(&block[0], srv_sort_buf_size);
  1245. DBUG_RETURN(&block[0]);
  1246. }
  1247. /** Create a temporary file if it has not been created already.
  1248. @param[in,out] tmpfd temporary file handle
  1249. @param[in] path location for creating temporary file
  1250. @return file descriptor, or -1 on failure */
  1251. static MY_ATTRIBUTE((warn_unused_result))
  1252. int
  1253. row_merge_tmpfile_if_needed(
  1254. int* tmpfd,
  1255. const char* path)
  1256. {
  1257. if (*tmpfd < 0) {
  1258. *tmpfd = row_merge_file_create_low(path);
  1259. if (*tmpfd >= 0) {
  1260. MONITOR_ATOMIC_INC(MONITOR_ALTER_TABLE_SORT_FILES);
  1261. }
  1262. }
  1263. return(*tmpfd);
  1264. }
  1265. /** Create a temporary file for merge sort if it was not created already.
  1266. @param[in,out] file merge file structure
  1267. @param[in] nrec number of records in the file
  1268. @param[in] path location for creating temporary file
  1269. @return file descriptor, or -1 on failure */
  1270. static MY_ATTRIBUTE((warn_unused_result))
  1271. int
  1272. row_merge_file_create_if_needed(
  1273. merge_file_t* file,
  1274. int* tmpfd,
  1275. ulint nrec,
  1276. const char* path)
  1277. {
  1278. ut_ad(file->fd < 0 || *tmpfd >=0);
  1279. if (file->fd < 0 && row_merge_file_create(file, path) >= 0) {
  1280. MONITOR_ATOMIC_INC(MONITOR_ALTER_TABLE_SORT_FILES);
  1281. if (row_merge_tmpfile_if_needed(tmpfd, path) < 0) {
  1282. return(-1);
  1283. }
  1284. file->n_rec = nrec;
  1285. }
  1286. ut_ad(file->fd < 0 || *tmpfd >=0);
  1287. return(file->fd);
  1288. }
  1289. /** Copy the merge data tuple from another merge data tuple.
  1290. @param[in] mtuple source merge data tuple
  1291. @param[in,out] prev_mtuple destination merge data tuple
  1292. @param[in] n_unique number of unique fields exist in the mtuple
  1293. @param[in,out] heap memory heap where last_mtuple allocated */
  1294. static
  1295. void
  1296. row_mtuple_create(
  1297. const mtuple_t* mtuple,
  1298. mtuple_t* prev_mtuple,
  1299. ulint n_unique,
  1300. mem_heap_t* heap)
  1301. {
  1302. memcpy(prev_mtuple->fields, mtuple->fields,
  1303. n_unique * sizeof *mtuple->fields);
  1304. dfield_t* field = prev_mtuple->fields;
  1305. for (ulint i = 0; i < n_unique; i++) {
  1306. dfield_dup(field++, heap);
  1307. }
  1308. }
  1309. /** Compare two merge data tuples.
  1310. @param[in] prev_mtuple merge data tuple
  1311. @param[in] current_mtuple merge data tuple
  1312. @param[in,out] dup reporter of duplicates
  1313. @retval positive, 0, negative if current_mtuple is greater, equal, less, than
  1314. last_mtuple. */
  1315. static
  1316. int
  1317. row_mtuple_cmp(
  1318. const mtuple_t* prev_mtuple,
  1319. const mtuple_t* current_mtuple,
  1320. row_merge_dup_t* dup)
  1321. {
  1322. ut_ad(dict_index_is_clust(dup->index));
  1323. const ulint n_unique = dict_index_get_n_unique(dup->index);
  1324. return(row_merge_tuple_cmp(
  1325. n_unique, n_unique, *current_mtuple, *prev_mtuple, dup));
  1326. }
  1327. /** Insert cached spatial index rows.
  1328. @param[in] trx_id transaction id
  1329. @param[in] sp_tuples cached spatial rows
  1330. @param[in] num_spatial number of spatial indexes
  1331. @param[in,out] row_heap heap for insert
  1332. @param[in,out] sp_heap heap for tuples
  1333. @param[in,out] pcur cluster index cursor
  1334. @param[in,out] mtr mini transaction
  1335. @param[in,out] mtr_committed whether scan_mtr got committed
  1336. @return DB_SUCCESS or error number */
  1337. static
  1338. dberr_t
  1339. row_merge_spatial_rows(
  1340. trx_id_t trx_id,
  1341. index_tuple_info_t** sp_tuples,
  1342. ulint num_spatial,
  1343. mem_heap_t* row_heap,
  1344. mem_heap_t* sp_heap,
  1345. btr_pcur_t* pcur,
  1346. mtr_t* mtr,
  1347. bool* mtr_committed)
  1348. {
  1349. dberr_t err = DB_SUCCESS;
  1350. if (sp_tuples == NULL) {
  1351. return(DB_SUCCESS);
  1352. }
  1353. ut_ad(sp_heap != NULL);
  1354. for (ulint j = 0; j < num_spatial; j++) {
  1355. err = sp_tuples[j]->insert(
  1356. trx_id, row_heap,
  1357. pcur, mtr, mtr_committed);
  1358. if (err != DB_SUCCESS) {
  1359. return(err);
  1360. }
  1361. }
  1362. mem_heap_empty(sp_heap);
  1363. return(err);
  1364. }
  1365. /** Check if the geometry field is valid.
  1366. @param[in] row the row
  1367. @param[in] index spatial index
  1368. @return true if it's valid, false if it's invalid. */
  1369. static
  1370. bool
  1371. row_geo_field_is_valid(
  1372. const dtuple_t* row,
  1373. dict_index_t* index)
  1374. {
  1375. const dict_field_t* ind_field
  1376. = dict_index_get_nth_field(index, 0);
  1377. const dict_col_t* col
  1378. = ind_field->col;
  1379. ulint col_no
  1380. = dict_col_get_no(col);
  1381. const dfield_t* dfield
  1382. = dtuple_get_nth_field(row, col_no);
  1383. if (dfield_is_null(dfield)
  1384. || dfield_get_len(dfield) < GEO_DATA_HEADER_SIZE) {
  1385. return(false);
  1386. }
  1387. return(true);
  1388. }
  1389. /** Reads clustered index of the table and create temporary files
  1390. containing the index entries for the indexes to be built.
  1391. @param[in] trx transaction
  1392. @param[in,out] table MySQL table object, for reporting erroneous
  1393. records
  1394. @param[in] old_table table where rows are read from
  1395. @param[in] new_table table where indexes are created; identical to
  1396. old_table unless creating a PRIMARY KEY
  1397. @param[in] online true if creating indexes online
  1398. @param[in] index indexes to be created
  1399. @param[in] fts_sort_idx full-text index to be created, or NULL
  1400. @param[in] psort_info parallel sort info for fts_sort_idx creation,
  1401. or NULL
  1402. @param[in] files temporary files
  1403. @param[in] key_numbers MySQL key numbers to create
  1404. @param[in] n_index number of indexes to create
  1405. @param[in] add_cols default values of added columns, or NULL
  1406. @param[in] add_v newly added virtual columns along with indexes
  1407. @param[in] col_map mapping of old column numbers to new ones, or
  1408. NULL if old_table == new_table
  1409. @param[in] add_autoinc number of added AUTO_INCREMENT columns, or
  1410. ULINT_UNDEFINED if none is added
  1411. @param[in,out] sequence autoinc sequence
  1412. @param[in,out] block file buffer
  1413. @param[in] skip_pk_sort whether the new PRIMARY KEY will follow
  1414. existing order
  1415. @param[in,out] tmpfd temporary file handle
  1416. @param[in,out] stage performance schema accounting object, used by
  1417. ALTER TABLE. stage->n_pk_recs_inc() will be called for each record read and
  1418. stage->inc() will be called for each page read.
  1419. @param[in] pct_cost percent of task weight out of total alter job
  1420. @param[in,out] crypt_block crypted file buffer
  1421. @param[in] eval_table mysql table used to evaluate virtual column
  1422. value, see innobase_get_computed_value().
  1423. @return DB_SUCCESS or error */
  1424. static MY_ATTRIBUTE((warn_unused_result))
  1425. dberr_t
  1426. row_merge_read_clustered_index(
  1427. trx_t* trx,
  1428. struct TABLE* table,
  1429. const dict_table_t* old_table,
  1430. const dict_table_t* new_table,
  1431. bool online,
  1432. dict_index_t** index,
  1433. dict_index_t* fts_sort_idx,
  1434. fts_psort_t* psort_info,
  1435. merge_file_t* files,
  1436. const ulint* key_numbers,
  1437. ulint n_index,
  1438. const dtuple_t* add_cols,
  1439. const dict_add_v_col_t* add_v,
  1440. const ulint* col_map,
  1441. ulint add_autoinc,
  1442. ib_sequence_t& sequence,
  1443. row_merge_block_t* block,
  1444. bool skip_pk_sort,
  1445. int* tmpfd,
  1446. ut_stage_alter_t* stage,
  1447. double pct_cost,
  1448. row_merge_block_t* crypt_block,
  1449. struct TABLE* eval_table,
  1450. bool drop_historical)
  1451. {
  1452. dict_index_t* clust_index; /* Clustered index */
  1453. mem_heap_t* row_heap; /* Heap memory to create
  1454. clustered index tuples */
  1455. row_merge_buf_t** merge_buf; /* Temporary list for records*/
  1456. mem_heap_t* v_heap = NULL; /* Heap memory to process large
  1457. data for virtual column */
  1458. btr_pcur_t pcur; /* Cursor on the clustered
  1459. index */
  1460. mtr_t mtr; /* Mini transaction */
  1461. dberr_t err = DB_SUCCESS;/* Return code */
  1462. ulint n_nonnull = 0; /* number of columns
  1463. changed to NOT NULL */
  1464. ulint* nonnull = NULL; /* NOT NULL columns */
  1465. dict_index_t* fts_index = NULL;/* FTS index */
  1466. doc_id_t doc_id = 0;
  1467. doc_id_t max_doc_id = 0;
  1468. ibool add_doc_id = FALSE;
  1469. os_event_t fts_parallel_sort_event = NULL;
  1470. ibool fts_pll_sort = FALSE;
  1471. int64_t sig_count = 0;
  1472. index_tuple_info_t** sp_tuples = NULL;
  1473. mem_heap_t* sp_heap = NULL;
  1474. ulint num_spatial = 0;
  1475. BtrBulk* clust_btr_bulk = NULL;
  1476. bool clust_temp_file = false;
  1477. mem_heap_t* mtuple_heap = NULL;
  1478. mtuple_t prev_mtuple;
  1479. mem_heap_t* conv_heap = NULL;
  1480. FlushObserver* observer = trx->flush_observer;
  1481. double curr_progress = 0.0;
  1482. ib_uint64_t read_rows = 0;
  1483. ib_uint64_t table_total_rows = 0;
  1484. char new_sys_trx_start[8];
  1485. char new_sys_trx_end[8];
  1486. byte any_autoinc_data[8] = {0};
  1487. bool vers_update_trt = false;
  1488. DBUG_ENTER("row_merge_read_clustered_index");
  1489. ut_ad((old_table == new_table) == !col_map);
  1490. ut_ad(!add_cols || col_map);
  1491. ut_ad(trx_state_eq(trx, TRX_STATE_ACTIVE));
  1492. ut_ad(trx->id);
  1493. table_total_rows = dict_table_get_n_rows(old_table);
  1494. if(table_total_rows == 0) {
  1495. /* We don't know total row count */
  1496. table_total_rows = 1;
  1497. }
  1498. trx->op_info = "reading clustered index";
  1499. #ifdef FTS_INTERNAL_DIAG_PRINT
  1500. DEBUG_FTS_SORT_PRINT("FTS_SORT: Start Create Index\n");
  1501. #endif
  1502. /* Create and initialize memory for record buffers */
  1503. merge_buf = static_cast<row_merge_buf_t**>(
  1504. ut_malloc_nokey(n_index * sizeof *merge_buf));
  1505. row_merge_dup_t clust_dup = {index[0], table, col_map, 0};
  1506. dfield_t* prev_fields;
  1507. const ulint n_uniq = dict_index_get_n_unique(index[0]);
  1508. ut_ad(trx->mysql_thd != NULL);
  1509. const char* path = thd_innodb_tmpdir(trx->mysql_thd);
  1510. ut_ad(!skip_pk_sort || dict_index_is_clust(index[0]));
  1511. /* There is no previous tuple yet. */
  1512. prev_mtuple.fields = NULL;
  1513. for (ulint i = 0; i < n_index; i++) {
  1514. if (index[i]->type & DICT_FTS) {
  1515. /* We are building a FT index, make sure
  1516. we have the temporary 'fts_sort_idx' */
  1517. ut_a(fts_sort_idx);
  1518. fts_index = index[i];
  1519. merge_buf[i] = row_merge_buf_create(fts_sort_idx);
  1520. add_doc_id = DICT_TF2_FLAG_IS_SET(
  1521. new_table, DICT_TF2_FTS_ADD_DOC_ID);
  1522. /* If Doc ID does not exist in the table itself,
  1523. fetch the first FTS Doc ID */
  1524. if (add_doc_id) {
  1525. fts_get_next_doc_id(
  1526. (dict_table_t*) new_table,
  1527. &doc_id);
  1528. ut_ad(doc_id > 0);
  1529. }
  1530. fts_pll_sort = TRUE;
  1531. row_fts_start_psort(psort_info);
  1532. fts_parallel_sort_event =
  1533. psort_info[0].psort_common->sort_event;
  1534. } else {
  1535. if (dict_index_is_spatial(index[i])) {
  1536. num_spatial++;
  1537. }
  1538. merge_buf[i] = row_merge_buf_create(index[i]);
  1539. }
  1540. }
  1541. if (num_spatial > 0) {
  1542. ulint count = 0;
  1543. sp_heap = mem_heap_create(512);
  1544. sp_tuples = static_cast<index_tuple_info_t**>(
  1545. ut_malloc_nokey(num_spatial
  1546. * sizeof(*sp_tuples)));
  1547. for (ulint i = 0; i < n_index; i++) {
  1548. if (dict_index_is_spatial(index[i])) {
  1549. sp_tuples[count]
  1550. = UT_NEW_NOKEY(
  1551. index_tuple_info_t(
  1552. sp_heap,
  1553. index[i]));
  1554. count++;
  1555. }
  1556. }
  1557. ut_ad(count == num_spatial);
  1558. }
  1559. mtr_start(&mtr);
  1560. /* Find the clustered index and create a persistent cursor
  1561. based on that. */
  1562. clust_index = dict_table_get_first_index(old_table);
  1563. const ulint old_trx_id_col = DATA_TRX_ID - DATA_N_SYS_COLS
  1564. + old_table->n_cols;
  1565. ut_ad(old_table->cols[old_trx_id_col].mtype == DATA_SYS);
  1566. ut_ad(old_table->cols[old_trx_id_col].prtype
  1567. == (DATA_TRX_ID | DATA_NOT_NULL));
  1568. ut_ad(old_table->cols[old_trx_id_col + 1].mtype == DATA_SYS);
  1569. ut_ad(old_table->cols[old_trx_id_col + 1].prtype
  1570. == (DATA_ROLL_PTR | DATA_NOT_NULL));
  1571. const ulint new_trx_id_col = col_map
  1572. ? col_map[old_trx_id_col] : old_trx_id_col;
  1573. btr_pcur_open_at_index_side(
  1574. true, clust_index, BTR_SEARCH_LEAF, &pcur, true, 0, &mtr);
  1575. btr_pcur_move_to_next_user_rec(&pcur, &mtr);
  1576. if (rec_is_default_row(btr_pcur_get_rec(&pcur), clust_index)) {
  1577. ut_ad(btr_pcur_is_on_user_rec(&pcur));
  1578. /* Skip the 'default row' pseudo-record. */
  1579. } else {
  1580. ut_ad(!clust_index->is_instant());
  1581. btr_pcur_move_to_prev_on_page(&pcur);
  1582. }
  1583. if (old_table != new_table) {
  1584. /* The table is being rebuilt. Identify the columns
  1585. that were flagged NOT NULL in the new table, so that
  1586. we can quickly check that the records in the old table
  1587. do not violate the added NOT NULL constraints. */
  1588. nonnull = static_cast<ulint*>(
  1589. ut_malloc_nokey(dict_table_get_n_cols(new_table)
  1590. * sizeof *nonnull));
  1591. for (ulint i = 0; i < dict_table_get_n_cols(old_table); i++) {
  1592. if (dict_table_get_nth_col(old_table, i)->prtype
  1593. & DATA_NOT_NULL) {
  1594. continue;
  1595. }
  1596. const ulint j = col_map[i];
  1597. if (j == ULINT_UNDEFINED) {
  1598. /* The column was dropped. */
  1599. continue;
  1600. }
  1601. if (dict_table_get_nth_col(new_table, j)->prtype
  1602. & DATA_NOT_NULL) {
  1603. nonnull[n_nonnull++] = j;
  1604. }
  1605. }
  1606. if (!n_nonnull) {
  1607. ut_free(nonnull);
  1608. nonnull = NULL;
  1609. }
  1610. }
  1611. row_heap = mem_heap_create(sizeof(mrec_buf_t));
  1612. if (dict_table_is_comp(old_table)
  1613. && !dict_table_is_comp(new_table)) {
  1614. conv_heap = mem_heap_create(sizeof(mrec_buf_t));
  1615. }
  1616. if (skip_pk_sort) {
  1617. prev_fields = static_cast<dfield_t*>(
  1618. ut_malloc_nokey(n_uniq * sizeof *prev_fields));
  1619. mtuple_heap = mem_heap_create(sizeof(mrec_buf_t));
  1620. } else {
  1621. prev_fields = NULL;
  1622. }
  1623. mach_write_to_8(new_sys_trx_start, trx->id);
  1624. mach_write_to_8(new_sys_trx_end, TRX_ID_MAX);
  1625. /* Scan the clustered index. */
  1626. for (;;) {
  1627. const rec_t* rec;
  1628. trx_id_t rec_trx_id;
  1629. ulint* offsets;
  1630. const dtuple_t* row;
  1631. row_ext_t* ext;
  1632. page_cur_t* cur = btr_pcur_get_page_cur(&pcur);
  1633. mem_heap_empty(row_heap);
  1634. /* Do not continue if table pages are still encrypted */
  1635. if (!old_table->is_readable() ||
  1636. !new_table->is_readable()) {
  1637. err = DB_DECRYPTION_FAILED;
  1638. trx->error_key_num = 0;
  1639. goto func_exit;
  1640. }
  1641. mem_heap_empty(row_heap);
  1642. page_cur_move_to_next(cur);
  1643. stage->n_pk_recs_inc();
  1644. if (page_cur_is_after_last(cur)) {
  1645. stage->inc();
  1646. if (UNIV_UNLIKELY(trx_is_interrupted(trx))) {
  1647. err = DB_INTERRUPTED;
  1648. trx->error_key_num = 0;
  1649. goto func_exit;
  1650. }
  1651. if (online && old_table != new_table) {
  1652. err = row_log_table_get_error(clust_index);
  1653. if (err != DB_SUCCESS) {
  1654. trx->error_key_num = 0;
  1655. goto func_exit;
  1656. }
  1657. }
  1658. #ifdef DBUG_OFF
  1659. # define dbug_run_purge false
  1660. #else /* DBUG_OFF */
  1661. bool dbug_run_purge = false;
  1662. #endif /* DBUG_OFF */
  1663. DBUG_EXECUTE_IF(
  1664. "ib_purge_on_create_index_page_switch",
  1665. dbug_run_purge = true;);
  1666. /* Insert the cached spatial index rows. */
  1667. bool mtr_committed = false;
  1668. err = row_merge_spatial_rows(
  1669. trx->id, sp_tuples, num_spatial,
  1670. row_heap, sp_heap, &pcur,
  1671. &mtr, &mtr_committed);
  1672. if (err != DB_SUCCESS) {
  1673. goto func_exit;
  1674. }
  1675. if (mtr_committed) {
  1676. goto scan_next;
  1677. }
  1678. if (dbug_run_purge
  1679. || my_atomic_load32_explicit(&clust_index->lock.waiters,
  1680. MY_MEMORY_ORDER_RELAXED)) {
  1681. /* There are waiters on the clustered
  1682. index tree lock, likely the purge
  1683. thread. Store and restore the cursor
  1684. position, and yield so that scanning a
  1685. large table will not starve other
  1686. threads. */
  1687. /* Store the cursor position on the last user
  1688. record on the page. */
  1689. btr_pcur_move_to_prev_on_page(&pcur);
  1690. /* Leaf pages must never be empty, unless
  1691. this is the only page in the index tree. */
  1692. ut_ad(btr_pcur_is_on_user_rec(&pcur)
  1693. || btr_pcur_get_block(
  1694. &pcur)->page.id.page_no()
  1695. == clust_index->page);
  1696. btr_pcur_store_position(&pcur, &mtr);
  1697. mtr_commit(&mtr);
  1698. if (dbug_run_purge) {
  1699. /* This is for testing
  1700. purposes only (see
  1701. DBUG_EXECUTE_IF above). We
  1702. signal the purge thread and
  1703. hope that the purge batch will
  1704. complete before we execute
  1705. btr_pcur_restore_position(). */
  1706. trx_purge_run();
  1707. os_thread_sleep(1000000);
  1708. }
  1709. /* Give the waiters a chance to proceed. */
  1710. os_thread_yield();
  1711. scan_next:
  1712. mtr_start(&mtr);
  1713. /* Restore position on the record, or its
  1714. predecessor if the record was purged
  1715. meanwhile. */
  1716. btr_pcur_restore_position(
  1717. BTR_SEARCH_LEAF, &pcur, &mtr);
  1718. /* Move to the successor of the
  1719. original record. */
  1720. if (!btr_pcur_move_to_next_user_rec(
  1721. &pcur, &mtr)) {
  1722. end_of_index:
  1723. row = NULL;
  1724. mtr_commit(&mtr);
  1725. mem_heap_free(row_heap);
  1726. ut_free(nonnull);
  1727. goto write_buffers;
  1728. }
  1729. } else {
  1730. ulint next_page_no;
  1731. buf_block_t* block;
  1732. next_page_no = btr_page_get_next(
  1733. page_cur_get_page(cur), &mtr);
  1734. if (next_page_no == FIL_NULL) {
  1735. goto end_of_index;
  1736. }
  1737. block = page_cur_get_block(cur);
  1738. block = btr_block_get(
  1739. page_id_t(block->page.id.space(),
  1740. next_page_no),
  1741. block->page.size,
  1742. BTR_SEARCH_LEAF,
  1743. clust_index, &mtr);
  1744. btr_leaf_page_release(page_cur_get_block(cur),
  1745. BTR_SEARCH_LEAF, &mtr);
  1746. page_cur_set_before_first(block, cur);
  1747. page_cur_move_to_next(cur);
  1748. ut_ad(!page_cur_is_after_last(cur));
  1749. }
  1750. }
  1751. rec = page_cur_get_rec(cur);
  1752. if (online) {
  1753. offsets = rec_get_offsets(rec, clust_index, NULL, true,
  1754. ULINT_UNDEFINED, &row_heap);
  1755. rec_trx_id = row_get_rec_trx_id(rec, clust_index,
  1756. offsets);
  1757. /* Perform a REPEATABLE READ.
  1758. When rebuilding the table online,
  1759. row_log_table_apply() must not see a newer
  1760. state of the table when applying the log.
  1761. This is mainly to prevent false duplicate key
  1762. errors, because the log will identify records
  1763. by the PRIMARY KEY, and also to prevent unsafe
  1764. BLOB access.
  1765. When creating a secondary index online, this
  1766. table scan must not see records that have only
  1767. been inserted to the clustered index, but have
  1768. not been written to the online_log of
  1769. index[]. If we performed READ UNCOMMITTED, it
  1770. could happen that the ADD INDEX reaches
  1771. ONLINE_INDEX_COMPLETE state between the time
  1772. the DML thread has updated the clustered index
  1773. but has not yet accessed secondary index. */
  1774. ut_ad(trx->read_view.is_open());
  1775. ut_ad(rec_trx_id != trx->id);
  1776. if (!trx->read_view.changes_visible(
  1777. rec_trx_id, old_table->name)) {
  1778. rec_t* old_vers;
  1779. row_vers_build_for_consistent_read(
  1780. rec, &mtr, clust_index, &offsets,
  1781. &trx->read_view, &row_heap,
  1782. row_heap, &old_vers, NULL);
  1783. if (!old_vers) {
  1784. continue;
  1785. }
  1786. /* The old version must necessarily be
  1787. in the "prehistory", because the
  1788. exclusive lock in
  1789. ha_innobase::prepare_inplace_alter_table()
  1790. forced the completion of any transactions
  1791. that accessed this table. */
  1792. ut_ad(row_get_rec_trx_id(old_vers, clust_index,
  1793. offsets) < trx->id);
  1794. rec = old_vers;
  1795. rec_trx_id = 0;
  1796. }
  1797. if (rec_get_deleted_flag(
  1798. rec,
  1799. dict_table_is_comp(old_table))) {
  1800. /* In delete-marked records, DB_TRX_ID must
  1801. always refer to an existing undo log record.
  1802. Above, we did reset rec_trx_id = 0
  1803. for rec = old_vers.*/
  1804. ut_ad(rec == page_cur_get_rec(cur)
  1805. ? rec_trx_id
  1806. : !rec_trx_id);
  1807. /* This record was deleted in the latest
  1808. committed version, or it was deleted and
  1809. then reinserted-by-update before purge
  1810. kicked in. Skip it. */
  1811. continue;
  1812. }
  1813. ut_ad(!rec_offs_any_null_extern(rec, offsets));
  1814. } else if (rec_get_deleted_flag(
  1815. rec, dict_table_is_comp(old_table))) {
  1816. /* In delete-marked records, DB_TRX_ID must
  1817. always refer to an existing undo log record. */
  1818. ut_d(rec_trx_id = rec_get_trx_id(rec, clust_index));
  1819. ut_ad(rec_trx_id);
  1820. /* This must be a purgeable delete-marked record,
  1821. and the transaction that delete-marked the record
  1822. must have been committed before this
  1823. !online ALTER TABLE transaction. */
  1824. ut_ad(rec_trx_id < trx->id);
  1825. /* Skip delete-marked records.
  1826. Skipping delete-marked records will make the
  1827. created indexes unuseable for transactions
  1828. whose read views were created before the index
  1829. creation completed, but an attempt to preserve
  1830. the history would make it tricky to detect
  1831. duplicate keys. */
  1832. continue;
  1833. } else {
  1834. offsets = rec_get_offsets(rec, clust_index, NULL, true,
  1835. ULINT_UNDEFINED, &row_heap);
  1836. /* This is a locking ALTER TABLE.
  1837. If we are not rebuilding the table, the
  1838. DB_TRX_ID does not matter, as it is not being
  1839. written to any secondary indexes; see
  1840. if (old_table == new_table) below.
  1841. If we are rebuilding the table, the
  1842. DB_TRX_ID,DB_ROLL_PTR should be reset, because
  1843. there will be no history available. */
  1844. ut_ad(rec_get_trx_id(rec, clust_index) < trx->id);
  1845. rec_trx_id = 0;
  1846. }
  1847. /* When !online, we are holding a lock on old_table, preventing
  1848. any inserts that could have written a record 'stub' before
  1849. writing out off-page columns. */
  1850. ut_ad(!rec_offs_any_null_extern(rec, offsets));
  1851. /* Build a row based on the clustered index. */
  1852. row = row_build_w_add_vcol(ROW_COPY_POINTERS, clust_index,
  1853. rec, offsets, new_table,
  1854. add_cols, add_v, col_map, &ext,
  1855. row_heap);
  1856. ut_ad(row);
  1857. for (ulint i = 0; i < n_nonnull; i++) {
  1858. const dfield_t* field = &row->fields[nonnull[i]];
  1859. ut_ad(dfield_get_type(field)->prtype & DATA_NOT_NULL);
  1860. if (dfield_is_null(field)) {
  1861. err = DB_INVALID_NULL;
  1862. trx->error_key_num = 0;
  1863. goto func_exit;
  1864. }
  1865. }
  1866. /* Get the next Doc ID */
  1867. if (add_doc_id) {
  1868. doc_id++;
  1869. } else {
  1870. doc_id = 0;
  1871. }
  1872. ut_ad(row->fields[new_trx_id_col].type.mtype == DATA_SYS);
  1873. ut_ad(row->fields[new_trx_id_col].type.prtype
  1874. == (DATA_TRX_ID | DATA_NOT_NULL));
  1875. ut_ad(row->fields[new_trx_id_col].len == DATA_TRX_ID_LEN);
  1876. ut_ad(row->fields[new_trx_id_col + 1].type.mtype == DATA_SYS);
  1877. ut_ad(row->fields[new_trx_id_col + 1].type.prtype
  1878. == (DATA_ROLL_PTR | DATA_NOT_NULL));
  1879. ut_ad(row->fields[new_trx_id_col + 1].len == DATA_ROLL_PTR_LEN);
  1880. if (old_table == new_table) {
  1881. /* Do not bother touching DB_TRX_ID,DB_ROLL_PTR
  1882. because they are not going to be written into
  1883. secondary indexes. */
  1884. } else if (rec_trx_id < trx->id) {
  1885. /* Reset the DB_TRX_ID,DB_ROLL_PTR of old rows
  1886. for which history is not going to be
  1887. available after the rebuild operation.
  1888. This essentially mimics row_purge_reset_trx_id(). */
  1889. row->fields[new_trx_id_col].data
  1890. = const_cast<byte*>(reset_trx_id);
  1891. row->fields[new_trx_id_col + 1].data
  1892. = const_cast<byte*>(reset_trx_id
  1893. + DATA_TRX_ID_LEN);
  1894. }
  1895. if (add_autoinc != ULINT_UNDEFINED) {
  1896. ut_ad(add_autoinc
  1897. < dict_table_get_n_user_cols(new_table));
  1898. bool history_row = false;
  1899. if (new_table->versioned()) {
  1900. const dfield_t* dfield = dtuple_get_nth_field(
  1901. row, new_table->vers_end);
  1902. history_row = dfield->vers_history_row();
  1903. }
  1904. dfield_t* dfield;
  1905. dfield = dtuple_get_nth_field(row, add_autoinc);
  1906. if (new_table->versioned()) {
  1907. if (history_row) {
  1908. if (dfield_get_type(dfield)->prtype & DATA_NOT_NULL) {
  1909. err = DB_UNSUPPORTED;
  1910. my_error(ER_UNSUPPORTED_EXTENSION, MYF(0),
  1911. old_table->name.m_name);
  1912. goto func_exit;
  1913. }
  1914. dfield_set_null(dfield);
  1915. } else {
  1916. // set not null
  1917. ulint len = dfield_get_type(dfield)->len;
  1918. dfield_set_data(dfield, any_autoinc_data, len);
  1919. }
  1920. }
  1921. if (dfield_is_null(dfield)) {
  1922. goto write_buffers;
  1923. }
  1924. const dtype_t* dtype = dfield_get_type(dfield);
  1925. byte* b = static_cast<byte*>(dfield_get_data(dfield));
  1926. if (sequence.eof()) {
  1927. err = DB_ERROR;
  1928. trx->error_key_num = 0;
  1929. ib_errf(trx->mysql_thd, IB_LOG_LEVEL_ERROR,
  1930. ER_AUTOINC_READ_FAILED, "[NULL]");
  1931. goto func_exit;
  1932. }
  1933. ulonglong value = sequence++;
  1934. switch (dtype_get_mtype(dtype)) {
  1935. case DATA_INT: {
  1936. ibool usign;
  1937. ulint len = dfield_get_len(dfield);
  1938. usign = dtype_get_prtype(dtype) & DATA_UNSIGNED;
  1939. mach_write_ulonglong(b, value, len, usign);
  1940. break;
  1941. }
  1942. case DATA_FLOAT:
  1943. mach_float_write(
  1944. b, static_cast<float>(value));
  1945. break;
  1946. case DATA_DOUBLE:
  1947. mach_double_write(
  1948. b, static_cast<double>(value));
  1949. break;
  1950. default:
  1951. ut_ad(0);
  1952. }
  1953. }
  1954. if (old_table->versioned()) {
  1955. if ((!new_table->versioned() || drop_historical)
  1956. && clust_index->vers_history_row(rec, offsets)) {
  1957. continue;
  1958. }
  1959. } else if (new_table->versioned()) {
  1960. dfield_t* start =
  1961. dtuple_get_nth_field(row, new_table->vers_start);
  1962. dfield_t* end =
  1963. dtuple_get_nth_field(row, new_table->vers_end);
  1964. dfield_set_data(start, new_sys_trx_start, 8);
  1965. dfield_set_data(end, new_sys_trx_end, 8);
  1966. vers_update_trt = true;
  1967. }
  1968. write_buffers:
  1969. /* Build all entries for all the indexes to be created
  1970. in a single scan of the clustered index. */
  1971. ulint s_idx_cnt = 0;
  1972. bool skip_sort = skip_pk_sort
  1973. && dict_index_is_clust(merge_buf[0]->index);
  1974. for (ulint i = 0; i < n_index; i++, skip_sort = false) {
  1975. row_merge_buf_t* buf = merge_buf[i];
  1976. merge_file_t* file = &files[i];
  1977. ulint rows_added = 0;
  1978. if (dict_index_is_spatial(buf->index)) {
  1979. if (!row) {
  1980. continue;
  1981. }
  1982. ut_ad(sp_tuples[s_idx_cnt]->get_index()
  1983. == buf->index);
  1984. /* If the geometry field is invalid, report
  1985. error. */
  1986. if (!row_geo_field_is_valid(row, buf->index)) {
  1987. err = DB_CANT_CREATE_GEOMETRY_OBJECT;
  1988. break;
  1989. }
  1990. sp_tuples[s_idx_cnt]->add(row, ext);
  1991. s_idx_cnt++;
  1992. continue;
  1993. }
  1994. ut_ad(!row
  1995. || !dict_index_is_clust(buf->index)
  1996. || trx_id_check(row->fields[new_trx_id_col].data,
  1997. trx->id));
  1998. if (UNIV_LIKELY
  1999. (row && (rows_added = row_merge_buf_add(
  2000. buf, fts_index, old_table, new_table,
  2001. psort_info, row, ext, &doc_id,
  2002. conv_heap, &err,
  2003. &v_heap, eval_table, trx)))) {
  2004. /* If we are creating FTS index,
  2005. a single row can generate more
  2006. records for tokenized word */
  2007. file->n_rec += rows_added;
  2008. if (err != DB_SUCCESS) {
  2009. ut_ad(err == DB_TOO_BIG_RECORD);
  2010. break;
  2011. }
  2012. if (doc_id > max_doc_id) {
  2013. max_doc_id = doc_id;
  2014. }
  2015. if (buf->index->type & DICT_FTS) {
  2016. /* Check if error occurs in child thread */
  2017. for (ulint j = 0;
  2018. j < fts_sort_pll_degree; j++) {
  2019. if (psort_info[j].error
  2020. != DB_SUCCESS) {
  2021. err = psort_info[j].error;
  2022. trx->error_key_num = i;
  2023. break;
  2024. }
  2025. }
  2026. if (err != DB_SUCCESS) {
  2027. break;
  2028. }
  2029. }
  2030. if (skip_sort) {
  2031. ut_ad(buf->n_tuples > 0);
  2032. const mtuple_t* curr =
  2033. &buf->tuples[buf->n_tuples - 1];
  2034. ut_ad(i == 0);
  2035. ut_ad(dict_index_is_clust(merge_buf[0]->index));
  2036. /* Detect duplicates by comparing the
  2037. current record with previous record.
  2038. When temp file is not used, records
  2039. should be in sorted order. */
  2040. if (prev_mtuple.fields != NULL
  2041. && (row_mtuple_cmp(
  2042. &prev_mtuple, curr,
  2043. &clust_dup) == 0)) {
  2044. err = DB_DUPLICATE_KEY;
  2045. trx->error_key_num
  2046. = key_numbers[0];
  2047. goto func_exit;
  2048. }
  2049. prev_mtuple.fields = curr->fields;
  2050. }
  2051. continue;
  2052. }
  2053. if (err == DB_COMPUTE_VALUE_FAILED) {
  2054. trx->error_key_num = i;
  2055. goto func_exit;
  2056. }
  2057. if (buf->index->type & DICT_FTS) {
  2058. if (!row || !doc_id) {
  2059. continue;
  2060. }
  2061. }
  2062. /* The buffer must be sufficiently large
  2063. to hold at least one record. It may only
  2064. be empty when we reach the end of the
  2065. clustered index. row_merge_buf_add()
  2066. must not have been called in this loop. */
  2067. ut_ad(buf->n_tuples || row == NULL);
  2068. /* We have enough data tuples to form a block.
  2069. Sort them and write to disk if temp file is used
  2070. or insert into index if temp file is not used. */
  2071. ut_ad(old_table == new_table
  2072. ? !dict_index_is_clust(buf->index)
  2073. : (i == 0) == dict_index_is_clust(buf->index));
  2074. /* We have enough data tuples to form a block.
  2075. Sort them (if !skip_sort) and write to disk. */
  2076. if (buf->n_tuples) {
  2077. if (skip_sort) {
  2078. /* Temporary File is not used.
  2079. so insert sorted block to the index */
  2080. if (row != NULL) {
  2081. bool mtr_committed = false;
  2082. /* We have to do insert the
  2083. cached spatial index rows, since
  2084. after the mtr_commit, the cluster
  2085. index page could be updated, then
  2086. the data in cached rows become
  2087. invalid. */
  2088. err = row_merge_spatial_rows(
  2089. trx->id, sp_tuples,
  2090. num_spatial,
  2091. row_heap, sp_heap,
  2092. &pcur, &mtr,
  2093. &mtr_committed);
  2094. if (err != DB_SUCCESS) {
  2095. goto func_exit;
  2096. }
  2097. /* We are not at the end of
  2098. the scan yet. We must
  2099. mtr_commit() in order to be
  2100. able to call log_free_check()
  2101. in row_merge_insert_index_tuples().
  2102. Due to mtr_commit(), the
  2103. current row will be invalid, and
  2104. we must reread it on the next
  2105. loop iteration. */
  2106. if (!mtr_committed) {
  2107. btr_pcur_move_to_prev_on_page(
  2108. &pcur);
  2109. btr_pcur_store_position(
  2110. &pcur, &mtr);
  2111. mtr_commit(&mtr);
  2112. }
  2113. }
  2114. mem_heap_empty(mtuple_heap);
  2115. prev_mtuple.fields = prev_fields;
  2116. row_mtuple_create(
  2117. &buf->tuples[buf->n_tuples - 1],
  2118. &prev_mtuple, n_uniq,
  2119. mtuple_heap);
  2120. if (clust_btr_bulk == NULL) {
  2121. clust_btr_bulk = UT_NEW_NOKEY(
  2122. BtrBulk(index[i],
  2123. trx->id,
  2124. observer));
  2125. clust_btr_bulk->init();
  2126. } else {
  2127. clust_btr_bulk->latch();
  2128. }
  2129. err = row_merge_insert_index_tuples(
  2130. index[i], old_table,
  2131. -1, NULL, buf, clust_btr_bulk,
  2132. table_total_rows,
  2133. curr_progress,
  2134. pct_cost,
  2135. crypt_block,
  2136. new_table->space);
  2137. if (row == NULL) {
  2138. err = clust_btr_bulk->finish(
  2139. err);
  2140. UT_DELETE(clust_btr_bulk);
  2141. clust_btr_bulk = NULL;
  2142. } else {
  2143. /* Release latches for possible
  2144. log_free_chck in spatial index
  2145. build. */
  2146. clust_btr_bulk->release();
  2147. }
  2148. if (err != DB_SUCCESS) {
  2149. break;
  2150. }
  2151. if (row != NULL) {
  2152. /* Restore the cursor on the
  2153. previous clustered index record,
  2154. and empty the buffer. The next
  2155. iteration of the outer loop will
  2156. advance the cursor and read the
  2157. next record (the one which we
  2158. had to ignore due to the buffer
  2159. overflow). */
  2160. mtr_start(&mtr);
  2161. btr_pcur_restore_position(
  2162. BTR_SEARCH_LEAF, &pcur,
  2163. &mtr);
  2164. buf = row_merge_buf_empty(buf);
  2165. /* Restart the outer loop on the
  2166. record. We did not insert it
  2167. into any index yet. */
  2168. ut_ad(i == 0);
  2169. break;
  2170. }
  2171. } else if (dict_index_is_unique(buf->index)) {
  2172. row_merge_dup_t dup = {
  2173. buf->index, table, col_map, 0};
  2174. row_merge_buf_sort(buf, &dup);
  2175. if (dup.n_dup) {
  2176. err = DB_DUPLICATE_KEY;
  2177. trx->error_key_num
  2178. = key_numbers[i];
  2179. break;
  2180. }
  2181. } else {
  2182. row_merge_buf_sort(buf, NULL);
  2183. }
  2184. } else if (online && new_table == old_table) {
  2185. /* Note the newest transaction that
  2186. modified this index when the scan was
  2187. completed. We prevent older readers
  2188. from accessing this index, to ensure
  2189. read consistency. */
  2190. trx_id_t max_trx_id;
  2191. ut_a(row == NULL);
  2192. rw_lock_x_lock(
  2193. dict_index_get_lock(buf->index));
  2194. ut_a(dict_index_get_online_status(buf->index)
  2195. == ONLINE_INDEX_CREATION);
  2196. max_trx_id = row_log_get_max_trx(buf->index);
  2197. if (max_trx_id > buf->index->trx_id) {
  2198. buf->index->trx_id = max_trx_id;
  2199. }
  2200. rw_lock_x_unlock(
  2201. dict_index_get_lock(buf->index));
  2202. }
  2203. /* Secondary index and clustered index which is
  2204. not in sorted order can use the temporary file.
  2205. Fulltext index should not use the temporary file. */
  2206. if (!skip_sort && !(buf->index->type & DICT_FTS)) {
  2207. /* In case we can have all rows in sort buffer,
  2208. we can insert directly into the index without
  2209. temporary file if clustered index does not uses
  2210. temporary file. */
  2211. if (row == NULL && file->fd == -1
  2212. && !clust_temp_file) {
  2213. DBUG_EXECUTE_IF(
  2214. "row_merge_write_failure",
  2215. err = DB_TEMP_FILE_WRITE_FAIL;
  2216. trx->error_key_num = i;
  2217. goto all_done;);
  2218. DBUG_EXECUTE_IF(
  2219. "row_merge_tmpfile_fail",
  2220. err = DB_OUT_OF_MEMORY;
  2221. trx->error_key_num = i;
  2222. goto all_done;);
  2223. BtrBulk btr_bulk(index[i], trx->id,
  2224. observer);
  2225. btr_bulk.init();
  2226. err = row_merge_insert_index_tuples(
  2227. index[i], old_table,
  2228. -1, NULL, buf, &btr_bulk,
  2229. table_total_rows,
  2230. curr_progress,
  2231. pct_cost,
  2232. crypt_block,
  2233. new_table->space);
  2234. err = btr_bulk.finish(err);
  2235. DBUG_EXECUTE_IF(
  2236. "row_merge_insert_big_row",
  2237. err = DB_TOO_BIG_RECORD;);
  2238. if (err != DB_SUCCESS) {
  2239. break;
  2240. }
  2241. } else {
  2242. if (row_merge_file_create_if_needed(
  2243. file, tmpfd,
  2244. buf->n_tuples, path) < 0) {
  2245. err = DB_OUT_OF_MEMORY;
  2246. trx->error_key_num = i;
  2247. goto func_exit;
  2248. }
  2249. /* Ensure that duplicates in the
  2250. clustered index will be detected before
  2251. inserting secondary index records. */
  2252. if (dict_index_is_clust(buf->index)) {
  2253. clust_temp_file = true;
  2254. }
  2255. ut_ad(file->n_rec > 0);
  2256. row_merge_buf_write(buf, file, block);
  2257. if (!row_merge_write(
  2258. file->fd, file->offset++,
  2259. block, crypt_block,
  2260. new_table->space)) {
  2261. err = DB_TEMP_FILE_WRITE_FAIL;
  2262. trx->error_key_num = i;
  2263. break;
  2264. }
  2265. UNIV_MEM_INVALID(
  2266. &block[0], srv_sort_buf_size);
  2267. }
  2268. }
  2269. merge_buf[i] = row_merge_buf_empty(buf);
  2270. if (UNIV_LIKELY(row != NULL)) {
  2271. /* Try writing the record again, now
  2272. that the buffer has been written out
  2273. and emptied. */
  2274. if (UNIV_UNLIKELY
  2275. (!(rows_added = row_merge_buf_add(
  2276. buf, fts_index, old_table,
  2277. new_table, psort_info, row, ext,
  2278. &doc_id, conv_heap,
  2279. &err, &v_heap, table, trx)))) {
  2280. /* An empty buffer should have enough
  2281. room for at least one record. */
  2282. ut_error;
  2283. }
  2284. if (err != DB_SUCCESS) {
  2285. break;
  2286. }
  2287. file->n_rec += rows_added;
  2288. }
  2289. }
  2290. if (row == NULL) {
  2291. goto all_done;
  2292. }
  2293. if (err != DB_SUCCESS) {
  2294. goto func_exit;
  2295. }
  2296. if (v_heap) {
  2297. mem_heap_empty(v_heap);
  2298. }
  2299. /* Increment innodb_onlineddl_pct_progress status variable */
  2300. read_rows++;
  2301. if(read_rows % 1000 == 0) {
  2302. /* Update progress for each 1000 rows */
  2303. curr_progress = (read_rows >= table_total_rows) ?
  2304. pct_cost :
  2305. ((pct_cost * read_rows) / table_total_rows);
  2306. /* presenting 10.12% as 1012 integer */
  2307. onlineddl_pct_progress = (ulint) (curr_progress * 100);
  2308. }
  2309. }
  2310. func_exit:
  2311. /* row_merge_spatial_rows may have committed
  2312. the mtr before an error occurs. */
  2313. if (mtr.is_active()) {
  2314. mtr_commit(&mtr);
  2315. }
  2316. mem_heap_free(row_heap);
  2317. ut_free(nonnull);
  2318. all_done:
  2319. if (clust_btr_bulk != NULL) {
  2320. ut_ad(err != DB_SUCCESS);
  2321. clust_btr_bulk->latch();
  2322. err = clust_btr_bulk->finish(
  2323. err);
  2324. UT_DELETE(clust_btr_bulk);
  2325. }
  2326. if (prev_fields != NULL) {
  2327. ut_free(prev_fields);
  2328. mem_heap_free(mtuple_heap);
  2329. }
  2330. if (v_heap) {
  2331. mem_heap_free(v_heap);
  2332. }
  2333. if (conv_heap != NULL) {
  2334. mem_heap_free(conv_heap);
  2335. }
  2336. #ifdef FTS_INTERNAL_DIAG_PRINT
  2337. DEBUG_FTS_SORT_PRINT("FTS_SORT: Complete Scan Table\n");
  2338. #endif
  2339. if (fts_pll_sort) {
  2340. bool all_exit = false;
  2341. ulint trial_count = 0;
  2342. const ulint max_trial_count = 10000;
  2343. wait_again:
  2344. /* Check if error occurs in child thread */
  2345. for (ulint j = 0; j < fts_sort_pll_degree; j++) {
  2346. if (psort_info[j].error != DB_SUCCESS) {
  2347. err = psort_info[j].error;
  2348. trx->error_key_num = j;
  2349. break;
  2350. }
  2351. }
  2352. /* Tell all children that parent has done scanning */
  2353. for (ulint i = 0; i < fts_sort_pll_degree; i++) {
  2354. if (err == DB_SUCCESS) {
  2355. psort_info[i].state = FTS_PARENT_COMPLETE;
  2356. } else {
  2357. psort_info[i].state = FTS_PARENT_EXITING;
  2358. }
  2359. }
  2360. /* Now wait all children to report back to be completed */
  2361. os_event_wait_time_low(fts_parallel_sort_event,
  2362. 1000000, sig_count);
  2363. for (ulint i = 0; i < fts_sort_pll_degree; i++) {
  2364. if (psort_info[i].child_status != FTS_CHILD_COMPLETE
  2365. && psort_info[i].child_status != FTS_CHILD_EXITING) {
  2366. sig_count = os_event_reset(
  2367. fts_parallel_sort_event);
  2368. goto wait_again;
  2369. }
  2370. }
  2371. /* Now all children should complete, wait a bit until
  2372. they all finish setting the event, before we free everything.
  2373. This has a 10 second timeout */
  2374. do {
  2375. all_exit = true;
  2376. for (ulint j = 0; j < fts_sort_pll_degree; j++) {
  2377. if (psort_info[j].child_status
  2378. != FTS_CHILD_EXITING) {
  2379. all_exit = false;
  2380. os_thread_sleep(1000);
  2381. break;
  2382. }
  2383. }
  2384. trial_count++;
  2385. } while (!all_exit && trial_count < max_trial_count);
  2386. if (!all_exit) {
  2387. ib::fatal() << "Not all child sort threads exited"
  2388. " when creating FTS index '"
  2389. << fts_sort_idx->name << "'";
  2390. }
  2391. }
  2392. #ifdef FTS_INTERNAL_DIAG_PRINT
  2393. DEBUG_FTS_SORT_PRINT("FTS_SORT: Complete Tokenization\n");
  2394. #endif
  2395. for (ulint i = 0; i < n_index; i++) {
  2396. row_merge_buf_free(merge_buf[i]);
  2397. }
  2398. row_fts_free_pll_merge_buf(psort_info);
  2399. ut_free(merge_buf);
  2400. btr_pcur_close(&pcur);
  2401. if (sp_tuples != NULL) {
  2402. for (ulint i = 0; i < num_spatial; i++) {
  2403. UT_DELETE(sp_tuples[i]);
  2404. }
  2405. ut_free(sp_tuples);
  2406. if (sp_heap) {
  2407. mem_heap_free(sp_heap);
  2408. }
  2409. }
  2410. /* Update the next Doc ID we used. Table should be locked, so
  2411. no concurrent DML */
  2412. if (max_doc_id && err == DB_SUCCESS) {
  2413. /* Sync fts cache for other fts indexes to keep all
  2414. fts indexes consistent in sync_doc_id. */
  2415. err = fts_sync_table(const_cast<dict_table_t*>(new_table),
  2416. false, true, false);
  2417. if (err == DB_SUCCESS) {
  2418. fts_update_next_doc_id(
  2419. 0, new_table,
  2420. old_table->name.m_name, max_doc_id);
  2421. }
  2422. }
  2423. if (vers_update_trt) {
  2424. trx_mod_table_time_t& time =
  2425. trx->mod_tables
  2426. .insert(trx_mod_tables_t::value_type(
  2427. const_cast<dict_table_t*>(new_table), 0))
  2428. .first->second;
  2429. time.set_versioned(0);
  2430. }
  2431. trx->op_info = "";
  2432. DBUG_RETURN(err);
  2433. }
  2434. /** Write a record via buffer 2 and read the next record to buffer N.
  2435. @param N number of the buffer (0 or 1)
  2436. @param INDEX record descriptor
  2437. @param AT_END statement to execute at end of input */
  2438. #define ROW_MERGE_WRITE_GET_NEXT_LOW(N, INDEX, AT_END) \
  2439. do { \
  2440. b2 = row_merge_write_rec(&block[2 * srv_sort_buf_size], \
  2441. &buf[2], b2, \
  2442. of->fd, &of->offset, \
  2443. mrec##N, offsets##N, \
  2444. crypt_block ? &crypt_block[2 * srv_sort_buf_size] : NULL , \
  2445. space); \
  2446. if (UNIV_UNLIKELY(!b2 || ++of->n_rec > file->n_rec)) { \
  2447. goto corrupt; \
  2448. } \
  2449. b##N = row_merge_read_rec(&block[N * srv_sort_buf_size],\
  2450. &buf[N], b##N, INDEX, \
  2451. file->fd, foffs##N, \
  2452. &mrec##N, offsets##N, \
  2453. crypt_block ? &crypt_block[N * srv_sort_buf_size] : NULL, \
  2454. space); \
  2455. \
  2456. if (UNIV_UNLIKELY(!b##N)) { \
  2457. if (mrec##N) { \
  2458. goto corrupt; \
  2459. } \
  2460. AT_END; \
  2461. } \
  2462. } while (0)
  2463. #ifdef HAVE_PSI_STAGE_INTERFACE
  2464. #define ROW_MERGE_WRITE_GET_NEXT(N, INDEX, AT_END) \
  2465. do { \
  2466. if (stage != NULL) { \
  2467. stage->inc(); \
  2468. } \
  2469. ROW_MERGE_WRITE_GET_NEXT_LOW(N, INDEX, AT_END); \
  2470. } while (0)
  2471. #else /* HAVE_PSI_STAGE_INTERFACE */
  2472. #define ROW_MERGE_WRITE_GET_NEXT(N, INDEX, AT_END) \
  2473. ROW_MERGE_WRITE_GET_NEXT_LOW(N, INDEX, AT_END)
  2474. #endif /* HAVE_PSI_STAGE_INTERFACE */
  2475. /** Merge two blocks of records on disk and write a bigger block.
  2476. @param[in] dup descriptor of index being created
  2477. @param[in] file file containing index entries
  2478. @param[in,out] block 3 buffers
  2479. @param[in,out] foffs0 offset of first source list in the file
  2480. @param[in,out] foffs1 offset of second source list in the file
  2481. @param[in,out] of output file
  2482. @param[in,out] stage performance schema accounting object, used by
  2483. @param[in,out] crypt_block encryption buffer
  2484. @param[in] space tablespace ID for encryption
  2485. ALTER TABLE. If not NULL stage->inc() will be called for each record
  2486. processed.
  2487. @return DB_SUCCESS or error code */
  2488. static MY_ATTRIBUTE((warn_unused_result))
  2489. dberr_t
  2490. row_merge_blocks(
  2491. const row_merge_dup_t* dup,
  2492. const merge_file_t* file,
  2493. row_merge_block_t* block,
  2494. ulint* foffs0,
  2495. ulint* foffs1,
  2496. merge_file_t* of,
  2497. ut_stage_alter_t* stage,
  2498. row_merge_block_t* crypt_block,
  2499. ulint space)
  2500. {
  2501. mem_heap_t* heap; /*!< memory heap for offsets0, offsets1 */
  2502. mrec_buf_t* buf; /*!< buffer for handling
  2503. split mrec in block[] */
  2504. const byte* b0; /*!< pointer to block[0] */
  2505. const byte* b1; /*!< pointer to block[srv_sort_buf_size] */
  2506. byte* b2; /*!< pointer to block[2 * srv_sort_buf_size] */
  2507. const mrec_t* mrec0; /*!< merge rec, points to block[0] or buf[0] */
  2508. const mrec_t* mrec1; /*!< merge rec, points to
  2509. block[srv_sort_buf_size] or buf[1] */
  2510. ulint* offsets0;/* offsets of mrec0 */
  2511. ulint* offsets1;/* offsets of mrec1 */
  2512. DBUG_ENTER("row_merge_blocks");
  2513. DBUG_LOG("ib_merge_sort",
  2514. "fd=" << file->fd << ',' << *foffs0 << '+' << *foffs1
  2515. << " to fd=" << of->fd << ',' << of->offset);
  2516. heap = row_merge_heap_create(dup->index, &buf, &offsets0, &offsets1);
  2517. /* Write a record and read the next record. Split the output
  2518. file in two halves, which can be merged on the following pass. */
  2519. if (!row_merge_read(file->fd, *foffs0, &block[0],
  2520. crypt_block ? &crypt_block[0] : NULL,
  2521. space) ||
  2522. !row_merge_read(file->fd, *foffs1, &block[srv_sort_buf_size],
  2523. crypt_block ? &crypt_block[srv_sort_buf_size] : NULL,
  2524. space)) {
  2525. corrupt:
  2526. mem_heap_free(heap);
  2527. DBUG_RETURN(DB_CORRUPTION);
  2528. }
  2529. b0 = &block[0];
  2530. b1 = &block[srv_sort_buf_size];
  2531. b2 = &block[2 * srv_sort_buf_size];
  2532. b0 = row_merge_read_rec(
  2533. &block[0], &buf[0], b0, dup->index,
  2534. file->fd, foffs0, &mrec0, offsets0,
  2535. crypt_block ? &crypt_block[0] : NULL,
  2536. space);
  2537. b1 = row_merge_read_rec(
  2538. &block[srv_sort_buf_size],
  2539. &buf[srv_sort_buf_size], b1, dup->index,
  2540. file->fd, foffs1, &mrec1, offsets1,
  2541. crypt_block ? &crypt_block[srv_sort_buf_size] : NULL,
  2542. space);
  2543. if (UNIV_UNLIKELY(!b0 && mrec0)
  2544. || UNIV_UNLIKELY(!b1 && mrec1)) {
  2545. goto corrupt;
  2546. }
  2547. while (mrec0 && mrec1) {
  2548. int cmp = cmp_rec_rec_simple(
  2549. mrec0, mrec1, offsets0, offsets1,
  2550. dup->index, dup->table);
  2551. if (cmp < 0) {
  2552. ROW_MERGE_WRITE_GET_NEXT(0, dup->index, goto merged);
  2553. } else if (cmp) {
  2554. ROW_MERGE_WRITE_GET_NEXT(1, dup->index, goto merged);
  2555. } else {
  2556. mem_heap_free(heap);
  2557. DBUG_RETURN(DB_DUPLICATE_KEY);
  2558. }
  2559. }
  2560. merged:
  2561. if (mrec0) {
  2562. /* append all mrec0 to output */
  2563. for (;;) {
  2564. ROW_MERGE_WRITE_GET_NEXT(0, dup->index, goto done0);
  2565. }
  2566. }
  2567. done0:
  2568. if (mrec1) {
  2569. /* append all mrec1 to output */
  2570. for (;;) {
  2571. ROW_MERGE_WRITE_GET_NEXT(1, dup->index, goto done1);
  2572. }
  2573. }
  2574. done1:
  2575. mem_heap_free(heap);
  2576. b2 = row_merge_write_eof(
  2577. &block[2 * srv_sort_buf_size],
  2578. b2, of->fd, &of->offset,
  2579. crypt_block ? &crypt_block[2 * srv_sort_buf_size] : NULL,
  2580. space);
  2581. DBUG_RETURN(b2 ? DB_SUCCESS : DB_CORRUPTION);
  2582. }
  2583. /** Copy a block of index entries.
  2584. @param[in] index index being created
  2585. @param[in] file input file
  2586. @param[in,out] block 3 buffers
  2587. @param[in,out] foffs0 input file offset
  2588. @param[in,out] of output file
  2589. @param[in,out] stage performance schema accounting object, used by
  2590. @param[in,out] crypt_block encryption buffer
  2591. @param[in] space tablespace ID for encryption
  2592. ALTER TABLE. If not NULL stage->inc() will be called for each record
  2593. processed.
  2594. @return TRUE on success, FALSE on failure */
  2595. static MY_ATTRIBUTE((warn_unused_result))
  2596. ibool
  2597. row_merge_blocks_copy(
  2598. const dict_index_t* index,
  2599. const merge_file_t* file,
  2600. row_merge_block_t* block,
  2601. ulint* foffs0,
  2602. merge_file_t* of,
  2603. ut_stage_alter_t* stage,
  2604. row_merge_block_t* crypt_block,
  2605. ulint space)
  2606. {
  2607. mem_heap_t* heap; /*!< memory heap for offsets0, offsets1 */
  2608. mrec_buf_t* buf; /*!< buffer for handling
  2609. split mrec in block[] */
  2610. const byte* b0; /*!< pointer to block[0] */
  2611. byte* b2; /*!< pointer to block[2 * srv_sort_buf_size] */
  2612. const mrec_t* mrec0; /*!< merge rec, points to block[0] */
  2613. ulint* offsets0;/* offsets of mrec0 */
  2614. ulint* offsets1;/* dummy offsets */
  2615. DBUG_ENTER("row_merge_blocks_copy");
  2616. DBUG_LOG("ib_merge_sort",
  2617. "fd=" << file->fd << ',' << foffs0
  2618. << " to fd=" << of->fd << ',' << of->offset);
  2619. heap = row_merge_heap_create(index, &buf, &offsets0, &offsets1);
  2620. /* Write a record and read the next record. Split the output
  2621. file in two halves, which can be merged on the following pass. */
  2622. if (!row_merge_read(file->fd, *foffs0, &block[0],
  2623. crypt_block ? &crypt_block[0] : NULL,
  2624. space)) {
  2625. corrupt:
  2626. mem_heap_free(heap);
  2627. DBUG_RETURN(FALSE);
  2628. }
  2629. b0 = &block[0];
  2630. b2 = &block[2 * srv_sort_buf_size];
  2631. b0 = row_merge_read_rec(&block[0], &buf[0], b0, index,
  2632. file->fd, foffs0, &mrec0, offsets0,
  2633. crypt_block ? &crypt_block[0] : NULL,
  2634. space);
  2635. if (UNIV_UNLIKELY(!b0 && mrec0)) {
  2636. goto corrupt;
  2637. }
  2638. if (mrec0) {
  2639. /* append all mrec0 to output */
  2640. for (;;) {
  2641. ROW_MERGE_WRITE_GET_NEXT(0, index, goto done0);
  2642. }
  2643. }
  2644. done0:
  2645. /* The file offset points to the beginning of the last page
  2646. that has been read. Update it to point to the next block. */
  2647. (*foffs0)++;
  2648. mem_heap_free(heap);
  2649. DBUG_RETURN(row_merge_write_eof(
  2650. &block[2 * srv_sort_buf_size],
  2651. b2, of->fd, &of->offset,
  2652. crypt_block
  2653. ? &crypt_block[2 * srv_sort_buf_size]
  2654. : NULL, space)
  2655. != NULL);
  2656. }
  2657. /** Merge disk files.
  2658. @param[in] trx transaction
  2659. @param[in] dup descriptor of index being created
  2660. @param[in,out] file file containing index entries
  2661. @param[in,out] block 3 buffers
  2662. @param[in,out] tmpfd temporary file handle
  2663. @param[in,out] num_run Number of runs that remain to be merged
  2664. @param[in,out] run_offset Array that contains the first offset number
  2665. for each merge run
  2666. @param[in,out] stage performance schema accounting object, used by
  2667. @param[in,out] crypt_block encryption buffer
  2668. @param[in] space tablespace ID for encryption
  2669. ALTER TABLE. If not NULL stage->inc() will be called for each record
  2670. processed.
  2671. @return DB_SUCCESS or error code */
  2672. static
  2673. dberr_t
  2674. row_merge(
  2675. trx_t* trx,
  2676. const row_merge_dup_t* dup,
  2677. merge_file_t* file,
  2678. row_merge_block_t* block,
  2679. int* tmpfd,
  2680. ulint* num_run,
  2681. ulint* run_offset,
  2682. ut_stage_alter_t* stage,
  2683. row_merge_block_t* crypt_block,
  2684. ulint space)
  2685. {
  2686. ulint foffs0; /*!< first input offset */
  2687. ulint foffs1; /*!< second input offset */
  2688. dberr_t error; /*!< error code */
  2689. merge_file_t of; /*!< output file */
  2690. const ulint ihalf = run_offset[*num_run / 2];
  2691. /*!< half the input file */
  2692. ulint n_run = 0;
  2693. /*!< num of runs generated from this merge */
  2694. UNIV_MEM_ASSERT_W(&block[0], 3 * srv_sort_buf_size);
  2695. if (crypt_block) {
  2696. UNIV_MEM_ASSERT_W(&crypt_block[0], 3 * srv_sort_buf_size);
  2697. }
  2698. ut_ad(ihalf < file->offset);
  2699. of.fd = *tmpfd;
  2700. of.offset = 0;
  2701. of.n_rec = 0;
  2702. #ifdef POSIX_FADV_SEQUENTIAL
  2703. /* The input file will be read sequentially, starting from the
  2704. beginning and the middle. In Linux, the POSIX_FADV_SEQUENTIAL
  2705. affects the entire file. Each block will be read exactly once. */
  2706. posix_fadvise(file->fd, 0, 0,
  2707. POSIX_FADV_SEQUENTIAL | POSIX_FADV_NOREUSE);
  2708. #endif /* POSIX_FADV_SEQUENTIAL */
  2709. /* Merge blocks to the output file. */
  2710. foffs0 = 0;
  2711. foffs1 = ihalf;
  2712. UNIV_MEM_INVALID(run_offset, *num_run * sizeof *run_offset);
  2713. for (; foffs0 < ihalf && foffs1 < file->offset; foffs0++, foffs1++) {
  2714. if (trx_is_interrupted(trx)) {
  2715. return(DB_INTERRUPTED);
  2716. }
  2717. /* Remember the offset number for this run */
  2718. run_offset[n_run++] = of.offset;
  2719. error = row_merge_blocks(dup, file, block,
  2720. &foffs0, &foffs1, &of, stage,
  2721. crypt_block, space);
  2722. if (error != DB_SUCCESS) {
  2723. return(error);
  2724. }
  2725. }
  2726. /* Copy the last blocks, if there are any. */
  2727. while (foffs0 < ihalf) {
  2728. if (UNIV_UNLIKELY(trx_is_interrupted(trx))) {
  2729. return(DB_INTERRUPTED);
  2730. }
  2731. /* Remember the offset number for this run */
  2732. run_offset[n_run++] = of.offset;
  2733. if (!row_merge_blocks_copy(dup->index, file, block,
  2734. &foffs0, &of, stage,
  2735. crypt_block, space)) {
  2736. return(DB_CORRUPTION);
  2737. }
  2738. }
  2739. ut_ad(foffs0 == ihalf);
  2740. while (foffs1 < file->offset) {
  2741. if (trx_is_interrupted(trx)) {
  2742. return(DB_INTERRUPTED);
  2743. }
  2744. /* Remember the offset number for this run */
  2745. run_offset[n_run++] = of.offset;
  2746. if (!row_merge_blocks_copy(dup->index, file, block,
  2747. &foffs1, &of, stage,
  2748. crypt_block, space)) {
  2749. return(DB_CORRUPTION);
  2750. }
  2751. }
  2752. ut_ad(foffs1 == file->offset);
  2753. if (UNIV_UNLIKELY(of.n_rec != file->n_rec)) {
  2754. return(DB_CORRUPTION);
  2755. }
  2756. ut_ad(n_run <= *num_run);
  2757. *num_run = n_run;
  2758. /* Each run can contain one or more offsets. As merge goes on,
  2759. the number of runs (to merge) will reduce until we have one
  2760. single run. So the number of runs will always be smaller than
  2761. the number of offsets in file */
  2762. ut_ad((*num_run) <= file->offset);
  2763. /* The number of offsets in output file is always equal or
  2764. smaller than input file */
  2765. ut_ad(of.offset <= file->offset);
  2766. /* Swap file descriptors for the next pass. */
  2767. *tmpfd = file->fd;
  2768. *file = of;
  2769. UNIV_MEM_INVALID(&block[0], 3 * srv_sort_buf_size);
  2770. return(DB_SUCCESS);
  2771. }
  2772. /** Merge disk files.
  2773. @param[in] trx transaction
  2774. @param[in] dup descriptor of index being created
  2775. @param[in,out] file file containing index entries
  2776. @param[in,out] block 3 buffers
  2777. @param[in,out] tmpfd temporary file handle
  2778. @param[in,out] stage performance schema accounting object, used by
  2779. ALTER TABLE. If not NULL, stage->begin_phase_sort() will be called initially
  2780. and then stage->inc() will be called for each record processed.
  2781. @return DB_SUCCESS or error code */
  2782. dberr_t
  2783. row_merge_sort(
  2784. trx_t* trx,
  2785. const row_merge_dup_t* dup,
  2786. merge_file_t* file,
  2787. row_merge_block_t* block,
  2788. int* tmpfd,
  2789. const bool update_progress,
  2790. /*!< in: update progress
  2791. status variable or not */
  2792. const double pct_progress,
  2793. /*!< in: total progress percent
  2794. until now */
  2795. const double pct_cost, /*!< in: current progress percent */
  2796. row_merge_block_t* crypt_block, /*!< in: crypt buf or NULL */
  2797. ulint space, /*!< in: space id */
  2798. ut_stage_alter_t* stage)
  2799. {
  2800. const ulint half = file->offset / 2;
  2801. ulint num_runs;
  2802. ulint* run_offset;
  2803. dberr_t error = DB_SUCCESS;
  2804. ulint merge_count = 0;
  2805. ulint total_merge_sort_count;
  2806. double curr_progress = 0;
  2807. DBUG_ENTER("row_merge_sort");
  2808. /* Record the number of merge runs we need to perform */
  2809. num_runs = file->offset;
  2810. if (stage != NULL) {
  2811. stage->begin_phase_sort(log2(num_runs));
  2812. }
  2813. /* Find the number N which 2^N is greater or equal than num_runs */
  2814. /* N is merge sort running count */
  2815. total_merge_sort_count = (ulint) ceil(my_log2f((float)num_runs));
  2816. if(total_merge_sort_count <= 0) {
  2817. total_merge_sort_count=1;
  2818. }
  2819. /* If num_runs are less than 1, nothing to merge */
  2820. if (num_runs <= 1) {
  2821. DBUG_RETURN(error);
  2822. }
  2823. /* "run_offset" records each run's first offset number */
  2824. run_offset = (ulint*) ut_malloc_nokey(file->offset * sizeof(ulint));
  2825. /* This tells row_merge() where to start for the first round
  2826. of merge. */
  2827. run_offset[half] = half;
  2828. /* The file should always contain at least one byte (the end
  2829. of file marker). Thus, it must be at least one block. */
  2830. ut_ad(file->offset > 0);
  2831. /* These thd_progress* calls will crash on sol10-64 when innodb_plugin
  2832. is used. MDEV-9356: innodb.innodb_bug53290 fails (crashes) on
  2833. sol10-64 in buildbot.
  2834. */
  2835. #ifndef UNIV_SOLARIS
  2836. /* Progress report only for "normal" indexes. */
  2837. if (!(dup->index->type & DICT_FTS)) {
  2838. thd_progress_init(trx->mysql_thd, 1);
  2839. }
  2840. #endif /* UNIV_SOLARIS */
  2841. if (global_system_variables.log_warnings > 2) {
  2842. sql_print_information("InnoDB: Online DDL : merge-sorting"
  2843. " has estimated " ULINTPF " runs",
  2844. num_runs);
  2845. }
  2846. /* Merge the runs until we have one big run */
  2847. do {
  2848. /* Report progress of merge sort to MySQL for
  2849. show processlist progress field */
  2850. /* Progress report only for "normal" indexes. */
  2851. #ifndef UNIV_SOLARIS
  2852. if (!(dup->index->type & DICT_FTS)) {
  2853. thd_progress_report(trx->mysql_thd, file->offset - num_runs, file->offset);
  2854. }
  2855. #endif /* UNIV_SOLARIS */
  2856. error = row_merge(trx, dup, file, block, tmpfd,
  2857. &num_runs, run_offset, stage,
  2858. crypt_block, space);
  2859. if(update_progress) {
  2860. merge_count++;
  2861. curr_progress = (merge_count >= total_merge_sort_count) ?
  2862. pct_cost :
  2863. ((pct_cost * merge_count) / total_merge_sort_count);
  2864. /* presenting 10.12% as 1012 integer */;
  2865. onlineddl_pct_progress = (ulint) ((pct_progress + curr_progress) * 100);
  2866. }
  2867. if (error != DB_SUCCESS) {
  2868. break;
  2869. }
  2870. UNIV_MEM_ASSERT_RW(run_offset, num_runs * sizeof *run_offset);
  2871. } while (num_runs > 1);
  2872. ut_free(run_offset);
  2873. /* Progress report only for "normal" indexes. */
  2874. #ifndef UNIV_SOLARIS
  2875. if (!(dup->index->type & DICT_FTS)) {
  2876. thd_progress_end(trx->mysql_thd);
  2877. }
  2878. #endif /* UNIV_SOLARIS */
  2879. DBUG_RETURN(error);
  2880. }
  2881. /** Copy externally stored columns to the data tuple.
  2882. @param[in] mrec record containing BLOB pointers,
  2883. or NULL to use tuple instead
  2884. @param[in] offsets offsets of mrec
  2885. @param[in] zip_size compressed page size in bytes, or 0
  2886. @param[in,out] tuple data tuple
  2887. @param[in,out] heap memory heap */
  2888. static
  2889. void
  2890. row_merge_copy_blobs(
  2891. const mrec_t* mrec,
  2892. const ulint* offsets,
  2893. const page_size_t& page_size,
  2894. dtuple_t* tuple,
  2895. mem_heap_t* heap)
  2896. {
  2897. ut_ad(mrec == NULL || rec_offs_any_extern(offsets));
  2898. for (ulint i = 0; i < dtuple_get_n_fields(tuple); i++) {
  2899. ulint len;
  2900. const void* data;
  2901. dfield_t* field = dtuple_get_nth_field(tuple, i);
  2902. ulint field_len;
  2903. const byte* field_data;
  2904. if (!dfield_is_ext(field)) {
  2905. continue;
  2906. }
  2907. ut_ad(!dfield_is_null(field));
  2908. /* During the creation of a PRIMARY KEY, the table is
  2909. X-locked, and we skip copying records that have been
  2910. marked for deletion. Therefore, externally stored
  2911. columns cannot possibly be freed between the time the
  2912. BLOB pointers are read (row_merge_read_clustered_index())
  2913. and dereferenced (below). */
  2914. if (mrec == NULL) {
  2915. field_data
  2916. = static_cast<byte*>(dfield_get_data(field));
  2917. field_len = dfield_get_len(field);
  2918. ut_a(field_len >= BTR_EXTERN_FIELD_REF_SIZE);
  2919. ut_a(memcmp(field_data + field_len
  2920. - BTR_EXTERN_FIELD_REF_SIZE,
  2921. field_ref_zero,
  2922. BTR_EXTERN_FIELD_REF_SIZE));
  2923. data = btr_copy_externally_stored_field(
  2924. &len, field_data, page_size, field_len, heap);
  2925. } else {
  2926. data = btr_rec_copy_externally_stored_field(
  2927. mrec, offsets, page_size, i, &len, heap);
  2928. }
  2929. /* Because we have locked the table, any records
  2930. written by incomplete transactions must have been
  2931. rolled back already. There must not be any incomplete
  2932. BLOB columns. */
  2933. ut_a(data);
  2934. dfield_set_data(field, data, len);
  2935. }
  2936. }
  2937. /** Convert a merge record to a typed data tuple. Note that externally
  2938. stored fields are not copied to heap.
  2939. @param[in,out] index index on the table
  2940. @param[in] mtuple merge record
  2941. @param[in] heap memory heap from which memory needed is allocated
  2942. @return index entry built. */
  2943. static
  2944. void
  2945. row_merge_mtuple_to_dtuple(
  2946. dict_index_t* index,
  2947. dtuple_t* dtuple,
  2948. const mtuple_t* mtuple)
  2949. {
  2950. ut_ad(!dict_index_is_ibuf(index));
  2951. memcpy(dtuple->fields, mtuple->fields,
  2952. dtuple->n_fields * sizeof *mtuple->fields);
  2953. }
  2954. /** Insert sorted data tuples to the index.
  2955. @param[in] index index to be inserted
  2956. @param[in] old_table old table
  2957. @param[in] fd file descriptor
  2958. @param[in,out] block file buffer
  2959. @param[in] row_buf row_buf the sorted data tuples,
  2960. or NULL if fd, block will be used instead
  2961. @param[in,out] btr_bulk btr bulk instance
  2962. @param[in,out] stage performance schema accounting object, used by
  2963. ALTER TABLE. If not NULL stage->begin_phase_insert() will be called initially
  2964. and then stage->inc() will be called for each record that is processed.
  2965. @return DB_SUCCESS or error number */
  2966. static MY_ATTRIBUTE((warn_unused_result))
  2967. dberr_t
  2968. row_merge_insert_index_tuples(
  2969. dict_index_t* index,
  2970. const dict_table_t* old_table,
  2971. int fd,
  2972. row_merge_block_t* block,
  2973. const row_merge_buf_t* row_buf,
  2974. BtrBulk* btr_bulk,
  2975. const ib_uint64_t table_total_rows, /*!< in: total rows of old table */
  2976. const double pct_progress, /*!< in: total progress
  2977. percent until now */
  2978. const double pct_cost, /*!< in: current progress percent
  2979. */
  2980. row_merge_block_t* crypt_block, /*!< in: crypt buf or NULL */
  2981. ulint space, /*!< in: space id */
  2982. ut_stage_alter_t* stage)
  2983. {
  2984. const byte* b;
  2985. mem_heap_t* heap;
  2986. mem_heap_t* tuple_heap;
  2987. dberr_t error = DB_SUCCESS;
  2988. ulint foffs = 0;
  2989. ulint* offsets;
  2990. mrec_buf_t* buf;
  2991. ulint n_rows = 0;
  2992. dtuple_t* dtuple;
  2993. ib_uint64_t inserted_rows = 0;
  2994. double curr_progress = 0;
  2995. dict_index_t* old_index = NULL;
  2996. const mrec_t* mrec = NULL;
  2997. ulint n_ext = 0;
  2998. mtr_t mtr;
  2999. DBUG_ENTER("row_merge_insert_index_tuples");
  3000. ut_ad(!srv_read_only_mode);
  3001. ut_ad(!(index->type & DICT_FTS));
  3002. ut_ad(!dict_index_is_spatial(index));
  3003. if (stage != NULL) {
  3004. stage->begin_phase_insert();
  3005. }
  3006. tuple_heap = mem_heap_create(1000);
  3007. {
  3008. ulint i = 1 + REC_OFFS_HEADER_SIZE
  3009. + dict_index_get_n_fields(index);
  3010. heap = mem_heap_create(sizeof *buf + i * sizeof *offsets);
  3011. offsets = static_cast<ulint*>(
  3012. mem_heap_alloc(heap, i * sizeof *offsets));
  3013. offsets[0] = i;
  3014. offsets[1] = dict_index_get_n_fields(index);
  3015. }
  3016. if (row_buf != NULL) {
  3017. ut_ad(fd == -1);
  3018. ut_ad(block == NULL);
  3019. DBUG_EXECUTE_IF("row_merge_read_failure",
  3020. error = DB_CORRUPTION;
  3021. goto err_exit;);
  3022. buf = NULL;
  3023. b = NULL;
  3024. dtuple = dtuple_create(
  3025. heap, dict_index_get_n_fields(index));
  3026. dtuple_set_n_fields_cmp(
  3027. dtuple, dict_index_get_n_unique_in_tree(index));
  3028. } else {
  3029. b = block;
  3030. dtuple = NULL;
  3031. if (!row_merge_read(fd, foffs, block, crypt_block, space)) {
  3032. error = DB_CORRUPTION;
  3033. goto err_exit;
  3034. } else {
  3035. buf = static_cast<mrec_buf_t*>(
  3036. mem_heap_alloc(heap, sizeof *buf));
  3037. }
  3038. }
  3039. for (;;) {
  3040. if (stage != NULL) {
  3041. stage->inc();
  3042. }
  3043. if (row_buf != NULL) {
  3044. if (n_rows >= row_buf->n_tuples) {
  3045. break;
  3046. }
  3047. /* Convert merge tuple record from
  3048. row buffer to data tuple record */
  3049. row_merge_mtuple_to_dtuple(
  3050. index, dtuple, &row_buf->tuples[n_rows]);
  3051. n_ext = dtuple_get_n_ext(dtuple);
  3052. n_rows++;
  3053. /* BLOB pointers must be copied from dtuple */
  3054. mrec = NULL;
  3055. } else {
  3056. b = row_merge_read_rec(block, buf, b, index,
  3057. fd, &foffs, &mrec, offsets,
  3058. crypt_block,
  3059. space);
  3060. if (UNIV_UNLIKELY(!b)) {
  3061. /* End of list, or I/O error */
  3062. if (mrec) {
  3063. error = DB_CORRUPTION;
  3064. }
  3065. break;
  3066. }
  3067. dtuple = row_rec_to_index_entry_low(
  3068. mrec, index, offsets, &n_ext, tuple_heap);
  3069. }
  3070. old_index = dict_table_get_first_index(old_table);
  3071. if (dict_index_is_clust(index)
  3072. && dict_index_is_online_ddl(old_index)) {
  3073. error = row_log_table_get_error(old_index);
  3074. if (error != DB_SUCCESS) {
  3075. break;
  3076. }
  3077. }
  3078. if (!n_ext) {
  3079. /* There are no externally stored columns. */
  3080. } else {
  3081. ut_ad(dict_index_is_clust(index));
  3082. /* Off-page columns can be fetched safely
  3083. when concurrent modifications to the table
  3084. are disabled. (Purge can process delete-marked
  3085. records, but row_merge_read_clustered_index()
  3086. would have skipped them.)
  3087. When concurrent modifications are enabled,
  3088. row_merge_read_clustered_index() will
  3089. only see rows from transactions that were
  3090. committed before the ALTER TABLE started
  3091. (REPEATABLE READ).
  3092. Any modifications after the
  3093. row_merge_read_clustered_index() scan
  3094. will go through row_log_table_apply().
  3095. Any modifications to off-page columns
  3096. will be tracked by
  3097. row_log_table_blob_alloc() and
  3098. row_log_table_blob_free(). */
  3099. row_merge_copy_blobs(
  3100. mrec, offsets,
  3101. dict_table_page_size(old_table),
  3102. dtuple, tuple_heap);
  3103. }
  3104. #ifdef UNIV_DEBUG
  3105. static const latch_level_t latches[] = {
  3106. SYNC_INDEX_TREE, /* index->lock */
  3107. SYNC_LEVEL_VARYING /* btr_bulk->m_page_bulks */
  3108. };
  3109. #endif /* UNIV_DEBUG */
  3110. ut_ad(dtuple_validate(dtuple));
  3111. ut_ad(!sync_check_iterate(sync_allowed_latches(latches,
  3112. latches + 2)));
  3113. error = btr_bulk->insert(dtuple);
  3114. if (error != DB_SUCCESS) {
  3115. goto err_exit;
  3116. }
  3117. mem_heap_empty(tuple_heap);
  3118. /* Increment innodb_onlineddl_pct_progress status variable */
  3119. inserted_rows++;
  3120. if(inserted_rows % 1000 == 0) {
  3121. /* Update progress for each 1000 rows */
  3122. curr_progress = (inserted_rows >= table_total_rows ||
  3123. table_total_rows <= 0) ?
  3124. pct_cost :
  3125. ((pct_cost * inserted_rows) / table_total_rows);
  3126. /* presenting 10.12% as 1012 integer */;
  3127. onlineddl_pct_progress = (ulint) ((pct_progress + curr_progress) * 100);
  3128. }
  3129. }
  3130. err_exit:
  3131. mem_heap_free(tuple_heap);
  3132. mem_heap_free(heap);
  3133. DBUG_RETURN(error);
  3134. }
  3135. /*********************************************************************//**
  3136. Sets an exclusive lock on a table, for the duration of creating indexes.
  3137. @return error code or DB_SUCCESS */
  3138. dberr_t
  3139. row_merge_lock_table(
  3140. /*=================*/
  3141. trx_t* trx, /*!< in/out: transaction */
  3142. dict_table_t* table, /*!< in: table to lock */
  3143. enum lock_mode mode) /*!< in: LOCK_X or LOCK_S */
  3144. {
  3145. ut_ad(!srv_read_only_mode);
  3146. ut_ad(mode == LOCK_X || mode == LOCK_S);
  3147. trx->op_info = "setting table lock for creating or dropping index";
  3148. trx->ddl = true;
  3149. return(lock_table_for_trx(table, trx, mode));
  3150. }
  3151. /*********************************************************************//**
  3152. Drop an index that was created before an error occurred.
  3153. The data dictionary must have been locked exclusively by the caller,
  3154. because the transaction will not be committed. */
  3155. static
  3156. void
  3157. row_merge_drop_index_dict(
  3158. /*======================*/
  3159. trx_t* trx, /*!< in/out: dictionary transaction */
  3160. index_id_t index_id)/*!< in: index identifier */
  3161. {
  3162. static const char sql[] =
  3163. "PROCEDURE DROP_INDEX_PROC () IS\n"
  3164. "BEGIN\n"
  3165. "DELETE FROM SYS_FIELDS WHERE INDEX_ID=:indexid;\n"
  3166. "DELETE FROM SYS_INDEXES WHERE ID=:indexid;\n"
  3167. "END;\n";
  3168. dberr_t error;
  3169. pars_info_t* info;
  3170. ut_ad(!srv_read_only_mode);
  3171. ut_ad(mutex_own(&dict_sys->mutex));
  3172. ut_ad(trx->dict_operation_lock_mode == RW_X_LATCH);
  3173. ut_ad(trx_get_dict_operation(trx) == TRX_DICT_OP_INDEX);
  3174. ut_ad(rw_lock_own(dict_operation_lock, RW_LOCK_X));
  3175. info = pars_info_create();
  3176. pars_info_add_ull_literal(info, "indexid", index_id);
  3177. trx->op_info = "dropping index from dictionary";
  3178. error = que_eval_sql(info, sql, FALSE, trx);
  3179. if (error != DB_SUCCESS) {
  3180. /* Even though we ensure that DDL transactions are WAIT
  3181. and DEADLOCK free, we could encounter other errors e.g.,
  3182. DB_TOO_MANY_CONCURRENT_TRXS. */
  3183. trx->error_state = DB_SUCCESS;
  3184. ib::error() << "row_merge_drop_index_dict failed with error "
  3185. << error;
  3186. }
  3187. trx->op_info = "";
  3188. }
  3189. /*********************************************************************//**
  3190. Drop indexes that were created before an error occurred.
  3191. The data dictionary must have been locked exclusively by the caller,
  3192. because the transaction will not be committed. */
  3193. void
  3194. row_merge_drop_indexes_dict(
  3195. /*========================*/
  3196. trx_t* trx, /*!< in/out: dictionary transaction */
  3197. table_id_t table_id)/*!< in: table identifier */
  3198. {
  3199. static const char sql[] =
  3200. "PROCEDURE DROP_INDEXES_PROC () IS\n"
  3201. "ixid CHAR;\n"
  3202. "found INT;\n"
  3203. "DECLARE CURSOR index_cur IS\n"
  3204. " SELECT ID FROM SYS_INDEXES\n"
  3205. " WHERE TABLE_ID=:tableid AND\n"
  3206. " SUBSTR(NAME,0,1)='" TEMP_INDEX_PREFIX_STR "'\n"
  3207. "FOR UPDATE;\n"
  3208. "BEGIN\n"
  3209. "found := 1;\n"
  3210. "OPEN index_cur;\n"
  3211. "WHILE found = 1 LOOP\n"
  3212. " FETCH index_cur INTO ixid;\n"
  3213. " IF (SQL % NOTFOUND) THEN\n"
  3214. " found := 0;\n"
  3215. " ELSE\n"
  3216. " DELETE FROM SYS_FIELDS WHERE INDEX_ID=ixid;\n"
  3217. " DELETE FROM SYS_INDEXES WHERE CURRENT OF index_cur;\n"
  3218. " END IF;\n"
  3219. "END LOOP;\n"
  3220. "CLOSE index_cur;\n"
  3221. "END;\n";
  3222. dberr_t error;
  3223. pars_info_t* info;
  3224. ut_ad(!srv_read_only_mode);
  3225. ut_ad(mutex_own(&dict_sys->mutex));
  3226. ut_ad(trx->dict_operation_lock_mode == RW_X_LATCH);
  3227. ut_ad(trx_get_dict_operation(trx) == TRX_DICT_OP_INDEX);
  3228. ut_ad(rw_lock_own(dict_operation_lock, RW_LOCK_X));
  3229. /* It is possible that table->n_ref_count > 1 when
  3230. locked=TRUE. In this case, all code that should have an open
  3231. handle to the table be waiting for the next statement to execute,
  3232. or waiting for a meta-data lock.
  3233. A concurrent purge will be prevented by dict_operation_lock. */
  3234. info = pars_info_create();
  3235. pars_info_add_ull_literal(info, "tableid", table_id);
  3236. trx->op_info = "dropping indexes";
  3237. error = que_eval_sql(info, sql, FALSE, trx);
  3238. switch (error) {
  3239. case DB_SUCCESS:
  3240. break;
  3241. default:
  3242. /* Even though we ensure that DDL transactions are WAIT
  3243. and DEADLOCK free, we could encounter other errors e.g.,
  3244. DB_TOO_MANY_CONCURRENT_TRXS. */
  3245. ib::error() << "row_merge_drop_indexes_dict failed with error "
  3246. << error;
  3247. /* fall through */
  3248. case DB_TOO_MANY_CONCURRENT_TRXS:
  3249. trx->error_state = DB_SUCCESS;
  3250. }
  3251. trx->op_info = "";
  3252. }
  3253. /*********************************************************************//**
  3254. Drop indexes that were created before an error occurred.
  3255. The data dictionary must have been locked exclusively by the caller,
  3256. because the transaction will not be committed. */
  3257. void
  3258. row_merge_drop_indexes(
  3259. /*===================*/
  3260. trx_t* trx, /*!< in/out: dictionary transaction */
  3261. dict_table_t* table, /*!< in/out: table containing the indexes */
  3262. ibool locked) /*!< in: TRUE=table locked,
  3263. FALSE=may need to do a lazy drop */
  3264. {
  3265. dict_index_t* index;
  3266. dict_index_t* next_index;
  3267. ut_ad(!srv_read_only_mode);
  3268. ut_ad(mutex_own(&dict_sys->mutex));
  3269. ut_ad(trx->dict_operation_lock_mode == RW_X_LATCH);
  3270. ut_ad(trx_get_dict_operation(trx) == TRX_DICT_OP_INDEX);
  3271. ut_ad(rw_lock_own(dict_operation_lock, RW_LOCK_X));
  3272. index = dict_table_get_first_index(table);
  3273. ut_ad(dict_index_is_clust(index));
  3274. ut_ad(dict_index_get_online_status(index) == ONLINE_INDEX_COMPLETE);
  3275. /* the caller should have an open handle to the table */
  3276. ut_ad(table->get_ref_count() >= 1);
  3277. /* It is possible that table->n_ref_count > 1 when
  3278. locked=TRUE. In this case, all code that should have an open
  3279. handle to the table be waiting for the next statement to execute,
  3280. or waiting for a meta-data lock.
  3281. A concurrent purge will be prevented by dict_operation_lock. */
  3282. if (!locked && table->get_ref_count() > 1) {
  3283. /* We will have to drop the indexes later, when the
  3284. table is guaranteed to be no longer in use. Mark the
  3285. indexes as incomplete and corrupted, so that other
  3286. threads will stop using them. Let dict_table_close()
  3287. or crash recovery or the next invocation of
  3288. prepare_inplace_alter_table() take care of dropping
  3289. the indexes. */
  3290. while ((index = dict_table_get_next_index(index)) != NULL) {
  3291. ut_ad(!dict_index_is_clust(index));
  3292. switch (dict_index_get_online_status(index)) {
  3293. case ONLINE_INDEX_ABORTED_DROPPED:
  3294. continue;
  3295. case ONLINE_INDEX_COMPLETE:
  3296. if (index->is_committed()) {
  3297. /* Do nothing to already
  3298. published indexes. */
  3299. } else if (index->type & DICT_FTS) {
  3300. /* Drop a completed FULLTEXT
  3301. index, due to a timeout during
  3302. MDL upgrade for
  3303. commit_inplace_alter_table().
  3304. Because only concurrent reads
  3305. are allowed (and they are not
  3306. seeing this index yet) we
  3307. are safe to drop the index. */
  3308. dict_index_t* prev = UT_LIST_GET_PREV(
  3309. indexes, index);
  3310. /* At least there should be
  3311. the clustered index before
  3312. this one. */
  3313. ut_ad(prev);
  3314. ut_a(table->fts);
  3315. fts_drop_index(table, index, trx);
  3316. /* Since
  3317. INNOBASE_SHARE::idx_trans_tbl
  3318. is shared between all open
  3319. ha_innobase handles to this
  3320. table, no thread should be
  3321. accessing this dict_index_t
  3322. object. Also, we should be
  3323. holding LOCK=SHARED MDL on the
  3324. table even after the MDL
  3325. upgrade timeout. */
  3326. /* We can remove a DICT_FTS
  3327. index from the cache, because
  3328. we do not allow ADD FULLTEXT INDEX
  3329. with LOCK=NONE. If we allowed that,
  3330. we should exclude FTS entries from
  3331. prebuilt->ins_node->entry_list
  3332. in ins_node_create_entry_list(). */
  3333. dict_index_remove_from_cache(
  3334. table, index);
  3335. index = prev;
  3336. } else {
  3337. rw_lock_x_lock(
  3338. dict_index_get_lock(index));
  3339. dict_index_set_online_status(
  3340. index, ONLINE_INDEX_ABORTED);
  3341. index->type |= DICT_CORRUPT;
  3342. table->drop_aborted = TRUE;
  3343. goto drop_aborted;
  3344. }
  3345. continue;
  3346. case ONLINE_INDEX_CREATION:
  3347. rw_lock_x_lock(dict_index_get_lock(index));
  3348. ut_ad(!index->is_committed());
  3349. row_log_abort_sec(index);
  3350. drop_aborted:
  3351. rw_lock_x_unlock(dict_index_get_lock(index));
  3352. DEBUG_SYNC_C("merge_drop_index_after_abort");
  3353. /* covered by dict_sys->mutex */
  3354. MONITOR_INC(MONITOR_BACKGROUND_DROP_INDEX);
  3355. /* fall through */
  3356. case ONLINE_INDEX_ABORTED:
  3357. /* Drop the index tree from the
  3358. data dictionary and free it from
  3359. the tablespace, but keep the object
  3360. in the data dictionary cache. */
  3361. row_merge_drop_index_dict(trx, index->id);
  3362. rw_lock_x_lock(dict_index_get_lock(index));
  3363. dict_index_set_online_status(
  3364. index, ONLINE_INDEX_ABORTED_DROPPED);
  3365. rw_lock_x_unlock(dict_index_get_lock(index));
  3366. table->drop_aborted = TRUE;
  3367. continue;
  3368. }
  3369. ut_error;
  3370. }
  3371. return;
  3372. }
  3373. row_merge_drop_indexes_dict(trx, table->id);
  3374. /* Invalidate all row_prebuilt_t::ins_graph that are referring
  3375. to this table. That is, force row_get_prebuilt_insert_row() to
  3376. rebuild prebuilt->ins_node->entry_list). */
  3377. ut_ad(table->def_trx_id <= trx->id);
  3378. table->def_trx_id = trx->id;
  3379. next_index = dict_table_get_next_index(index);
  3380. while ((index = next_index) != NULL) {
  3381. /* read the next pointer before freeing the index */
  3382. next_index = dict_table_get_next_index(index);
  3383. ut_ad(!dict_index_is_clust(index));
  3384. if (!index->is_committed()) {
  3385. /* If it is FTS index, drop from table->fts
  3386. and also drop its auxiliary tables */
  3387. if (index->type & DICT_FTS) {
  3388. ut_a(table->fts);
  3389. fts_drop_index(table, index, trx);
  3390. }
  3391. switch (dict_index_get_online_status(index)) {
  3392. case ONLINE_INDEX_CREATION:
  3393. /* This state should only be possible
  3394. when prepare_inplace_alter_table() fails
  3395. after invoking row_merge_create_index().
  3396. In inplace_alter_table(),
  3397. row_merge_build_indexes()
  3398. should never leave the index in this state.
  3399. It would invoke row_log_abort_sec() on
  3400. failure. */
  3401. case ONLINE_INDEX_COMPLETE:
  3402. /* In these cases, we are able to drop
  3403. the index straight. The DROP INDEX was
  3404. never deferred. */
  3405. break;
  3406. case ONLINE_INDEX_ABORTED:
  3407. case ONLINE_INDEX_ABORTED_DROPPED:
  3408. /* covered by dict_sys->mutex */
  3409. MONITOR_DEC(MONITOR_BACKGROUND_DROP_INDEX);
  3410. }
  3411. dict_index_remove_from_cache(table, index);
  3412. }
  3413. }
  3414. table->drop_aborted = FALSE;
  3415. ut_d(dict_table_check_for_dup_indexes(table, CHECK_ALL_COMPLETE));
  3416. }
  3417. /*********************************************************************//**
  3418. Drop all partially created indexes during crash recovery. */
  3419. void
  3420. row_merge_drop_temp_indexes(void)
  3421. /*=============================*/
  3422. {
  3423. static const char sql[] =
  3424. "PROCEDURE DROP_TEMP_INDEXES_PROC () IS\n"
  3425. "ixid CHAR;\n"
  3426. "found INT;\n"
  3427. "DECLARE CURSOR index_cur IS\n"
  3428. " SELECT ID FROM SYS_INDEXES\n"
  3429. " WHERE SUBSTR(NAME,0,1)='" TEMP_INDEX_PREFIX_STR "'\n"
  3430. "FOR UPDATE;\n"
  3431. "BEGIN\n"
  3432. "found := 1;\n"
  3433. "OPEN index_cur;\n"
  3434. "WHILE found = 1 LOOP\n"
  3435. " FETCH index_cur INTO ixid;\n"
  3436. " IF (SQL % NOTFOUND) THEN\n"
  3437. " found := 0;\n"
  3438. " ELSE\n"
  3439. " DELETE FROM SYS_FIELDS WHERE INDEX_ID=ixid;\n"
  3440. " DELETE FROM SYS_INDEXES WHERE CURRENT OF index_cur;\n"
  3441. " END IF;\n"
  3442. "END LOOP;\n"
  3443. "CLOSE index_cur;\n"
  3444. "END;\n";
  3445. trx_t* trx;
  3446. dberr_t error;
  3447. /* Load the table definitions that contain partially defined
  3448. indexes, so that the data dictionary information can be checked
  3449. when accessing the tablename.ibd files. */
  3450. trx = trx_allocate_for_background();
  3451. trx->op_info = "dropping partially created indexes";
  3452. row_mysql_lock_data_dictionary(trx);
  3453. /* Ensure that this transaction will be rolled back and locks
  3454. will be released, if the server gets killed before the commit
  3455. gets written to the redo log. */
  3456. trx_set_dict_operation(trx, TRX_DICT_OP_INDEX);
  3457. trx->op_info = "dropping indexes";
  3458. error = que_eval_sql(NULL, sql, FALSE, trx);
  3459. if (error != DB_SUCCESS) {
  3460. /* Even though we ensure that DDL transactions are WAIT
  3461. and DEADLOCK free, we could encounter other errors e.g.,
  3462. DB_TOO_MANY_CONCURRENT_TRXS. */
  3463. trx->error_state = DB_SUCCESS;
  3464. ib::error() << "row_merge_drop_temp_indexes failed with error"
  3465. << error;
  3466. }
  3467. trx_commit_for_mysql(trx);
  3468. row_mysql_unlock_data_dictionary(trx);
  3469. trx_free_for_background(trx);
  3470. }
  3471. /** Create temporary merge files in the given paramater path, and if
  3472. UNIV_PFS_IO defined, register the file descriptor with Performance Schema.
  3473. @param[in] path location for creating temporary merge files, or NULL
  3474. @return File descriptor */
  3475. int
  3476. row_merge_file_create_low(
  3477. const char* path)
  3478. {
  3479. int fd;
  3480. #ifdef UNIV_PFS_IO
  3481. /* This temp file open does not go through normal
  3482. file APIs, add instrumentation to register with
  3483. performance schema */
  3484. struct PSI_file_locker* locker;
  3485. PSI_file_locker_state state;
  3486. locker = PSI_FILE_CALL(get_thread_file_name_locker)(
  3487. &state, innodb_temp_file_key, PSI_FILE_OPEN,
  3488. "Innodb Merge Temp File", &locker);
  3489. if (locker != NULL) {
  3490. PSI_FILE_CALL(start_file_open_wait)(locker,
  3491. __FILE__,
  3492. __LINE__);
  3493. }
  3494. #endif
  3495. fd = innobase_mysql_tmpfile(path);
  3496. #ifdef UNIV_PFS_IO
  3497. if (locker != NULL) {
  3498. PSI_FILE_CALL(end_file_open_wait_and_bind_to_descriptor)(
  3499. locker, fd);
  3500. }
  3501. #endif
  3502. if (fd < 0) {
  3503. ib::error() << "Cannot create temporary merge file";
  3504. return(-1);
  3505. }
  3506. return(fd);
  3507. }
  3508. /** Create a merge file in the given location.
  3509. @param[out] merge_file merge file structure
  3510. @param[in] path location for creating temporary file, or NULL
  3511. @return file descriptor, or -1 on failure */
  3512. int
  3513. row_merge_file_create(
  3514. merge_file_t* merge_file,
  3515. const char* path)
  3516. {
  3517. merge_file->fd = row_merge_file_create_low(path);
  3518. merge_file->offset = 0;
  3519. merge_file->n_rec = 0;
  3520. if (merge_file->fd >= 0) {
  3521. if (srv_disable_sort_file_cache) {
  3522. os_file_set_nocache(merge_file->fd,
  3523. "row0merge.cc", "sort");
  3524. }
  3525. }
  3526. return(merge_file->fd);
  3527. }
  3528. /*********************************************************************//**
  3529. Destroy a merge file. And de-register the file from Performance Schema
  3530. if UNIV_PFS_IO is defined. */
  3531. void
  3532. row_merge_file_destroy_low(
  3533. /*=======================*/
  3534. int fd) /*!< in: merge file descriptor */
  3535. {
  3536. #ifdef UNIV_PFS_IO
  3537. struct PSI_file_locker* locker = NULL;
  3538. PSI_file_locker_state state;
  3539. locker = PSI_FILE_CALL(get_thread_file_descriptor_locker)(
  3540. &state, fd, PSI_FILE_CLOSE);
  3541. if (locker != NULL) {
  3542. PSI_FILE_CALL(start_file_wait)(
  3543. locker, 0, __FILE__, __LINE__);
  3544. }
  3545. #endif
  3546. if (fd >= 0) {
  3547. close(fd);
  3548. }
  3549. #ifdef UNIV_PFS_IO
  3550. if (locker != NULL) {
  3551. PSI_FILE_CALL(end_file_wait)(locker, 0);
  3552. }
  3553. #endif
  3554. }
  3555. /*********************************************************************//**
  3556. Destroy a merge file. */
  3557. void
  3558. row_merge_file_destroy(
  3559. /*===================*/
  3560. merge_file_t* merge_file) /*!< in/out: merge file structure */
  3561. {
  3562. ut_ad(!srv_read_only_mode);
  3563. if (merge_file->fd != -1) {
  3564. row_merge_file_destroy_low(merge_file->fd);
  3565. merge_file->fd = -1;
  3566. }
  3567. }
  3568. /*********************************************************************//**
  3569. Rename an index in the dictionary that was created. The data
  3570. dictionary must have been locked exclusively by the caller, because
  3571. the transaction will not be committed.
  3572. @return DB_SUCCESS if all OK */
  3573. dberr_t
  3574. row_merge_rename_index_to_add(
  3575. /*==========================*/
  3576. trx_t* trx, /*!< in/out: transaction */
  3577. table_id_t table_id, /*!< in: table identifier */
  3578. index_id_t index_id) /*!< in: index identifier */
  3579. {
  3580. dberr_t err = DB_SUCCESS;
  3581. pars_info_t* info = pars_info_create();
  3582. /* We use the private SQL parser of Innobase to generate the
  3583. query graphs needed in renaming indexes. */
  3584. static const char rename_index[] =
  3585. "PROCEDURE RENAME_INDEX_PROC () IS\n"
  3586. "BEGIN\n"
  3587. "UPDATE SYS_INDEXES SET NAME=SUBSTR(NAME,1,LENGTH(NAME)-1)\n"
  3588. "WHERE TABLE_ID = :tableid AND ID = :indexid;\n"
  3589. "END;\n";
  3590. ut_ad(trx);
  3591. ut_a(trx->dict_operation_lock_mode == RW_X_LATCH);
  3592. ut_ad(trx_get_dict_operation(trx) == TRX_DICT_OP_INDEX);
  3593. trx->op_info = "renaming index to add";
  3594. pars_info_add_ull_literal(info, "tableid", table_id);
  3595. pars_info_add_ull_literal(info, "indexid", index_id);
  3596. err = que_eval_sql(info, rename_index, FALSE, trx);
  3597. if (err != DB_SUCCESS) {
  3598. /* Even though we ensure that DDL transactions are WAIT
  3599. and DEADLOCK free, we could encounter other errors e.g.,
  3600. DB_TOO_MANY_CONCURRENT_TRXS. */
  3601. trx->error_state = DB_SUCCESS;
  3602. ib::error() << "row_merge_rename_index_to_add failed with"
  3603. " error " << err;
  3604. }
  3605. trx->op_info = "";
  3606. return(err);
  3607. }
  3608. /*********************************************************************//**
  3609. Rename an index in the dictionary that is to be dropped. The data
  3610. dictionary must have been locked exclusively by the caller, because
  3611. the transaction will not be committed.
  3612. @return DB_SUCCESS if all OK */
  3613. dberr_t
  3614. row_merge_rename_index_to_drop(
  3615. /*===========================*/
  3616. trx_t* trx, /*!< in/out: transaction */
  3617. table_id_t table_id, /*!< in: table identifier */
  3618. index_id_t index_id) /*!< in: index identifier */
  3619. {
  3620. dberr_t err;
  3621. pars_info_t* info = pars_info_create();
  3622. ut_ad(!srv_read_only_mode);
  3623. /* We use the private SQL parser of Innobase to generate the
  3624. query graphs needed in renaming indexes. */
  3625. static const char rename_index[] =
  3626. "PROCEDURE RENAME_INDEX_PROC () IS\n"
  3627. "BEGIN\n"
  3628. "UPDATE SYS_INDEXES SET NAME=CONCAT('"
  3629. TEMP_INDEX_PREFIX_STR "',NAME)\n"
  3630. "WHERE TABLE_ID = :tableid AND ID = :indexid;\n"
  3631. "END;\n";
  3632. ut_ad(trx);
  3633. ut_a(trx->dict_operation_lock_mode == RW_X_LATCH);
  3634. ut_ad(trx_get_dict_operation(trx) == TRX_DICT_OP_INDEX);
  3635. trx->op_info = "renaming index to drop";
  3636. pars_info_add_ull_literal(info, "tableid", table_id);
  3637. pars_info_add_ull_literal(info, "indexid", index_id);
  3638. err = que_eval_sql(info, rename_index, FALSE, trx);
  3639. if (err != DB_SUCCESS) {
  3640. /* Even though we ensure that DDL transactions are WAIT
  3641. and DEADLOCK free, we could encounter other errors e.g.,
  3642. DB_TOO_MANY_CONCURRENT_TRXS. */
  3643. trx->error_state = DB_SUCCESS;
  3644. ib::error() << "row_merge_rename_index_to_drop failed with"
  3645. " error " << err;
  3646. }
  3647. trx->op_info = "";
  3648. return(err);
  3649. }
  3650. /*********************************************************************//**
  3651. Provide a new pathname for a table that is being renamed if it belongs to
  3652. a file-per-table tablespace. The caller is responsible for freeing the
  3653. memory allocated for the return value.
  3654. @return new pathname of tablespace file, or NULL if space = 0 */
  3655. char*
  3656. row_make_new_pathname(
  3657. /*==================*/
  3658. dict_table_t* table, /*!< in: table to be renamed */
  3659. const char* new_name) /*!< in: new name */
  3660. {
  3661. char* new_path;
  3662. char* old_path;
  3663. ut_ad(!is_system_tablespace(table->space));
  3664. old_path = fil_space_get_first_path(table->space);
  3665. ut_a(old_path);
  3666. new_path = os_file_make_new_pathname(old_path, new_name);
  3667. ut_free(old_path);
  3668. return(new_path);
  3669. }
  3670. /*********************************************************************//**
  3671. Rename the tables in the data dictionary. The data dictionary must
  3672. have been locked exclusively by the caller, because the transaction
  3673. will not be committed.
  3674. @return error code or DB_SUCCESS */
  3675. dberr_t
  3676. row_merge_rename_tables_dict(
  3677. /*=========================*/
  3678. dict_table_t* old_table, /*!< in/out: old table, renamed to
  3679. tmp_name */
  3680. dict_table_t* new_table, /*!< in/out: new table, renamed to
  3681. old_table->name */
  3682. const char* tmp_name, /*!< in: new name for old_table */
  3683. trx_t* trx) /*!< in/out: dictionary transaction */
  3684. {
  3685. dberr_t err = DB_ERROR;
  3686. pars_info_t* info;
  3687. ut_ad(!srv_read_only_mode);
  3688. ut_ad(old_table != new_table);
  3689. ut_ad(mutex_own(&dict_sys->mutex));
  3690. ut_a(trx->dict_operation_lock_mode == RW_X_LATCH);
  3691. ut_ad(trx_get_dict_operation(trx) == TRX_DICT_OP_TABLE
  3692. || trx_get_dict_operation(trx) == TRX_DICT_OP_INDEX);
  3693. trx->op_info = "renaming tables";
  3694. /* We use the private SQL parser of Innobase to generate the query
  3695. graphs needed in updating the dictionary data in system tables. */
  3696. info = pars_info_create();
  3697. pars_info_add_str_literal(info, "new_name", new_table->name.m_name);
  3698. pars_info_add_str_literal(info, "old_name", old_table->name.m_name);
  3699. pars_info_add_str_literal(info, "tmp_name", tmp_name);
  3700. err = que_eval_sql(info,
  3701. "PROCEDURE RENAME_TABLES () IS\n"
  3702. "BEGIN\n"
  3703. "UPDATE SYS_TABLES SET NAME = :tmp_name\n"
  3704. " WHERE NAME = :old_name;\n"
  3705. "UPDATE SYS_TABLES SET NAME = :old_name\n"
  3706. " WHERE NAME = :new_name;\n"
  3707. "END;\n", FALSE, trx);
  3708. /* Update SYS_TABLESPACES and SYS_DATAFILES if the old table being
  3709. renamed is a single-table tablespace, which must be implicitly
  3710. renamed along with the table. */
  3711. if (err == DB_SUCCESS
  3712. && dict_table_is_file_per_table(old_table)
  3713. && fil_space_get(old_table->space) != NULL) {
  3714. /* Make pathname to update SYS_DATAFILES. */
  3715. char* tmp_path = row_make_new_pathname(old_table, tmp_name);
  3716. info = pars_info_create();
  3717. pars_info_add_str_literal(info, "tmp_name", tmp_name);
  3718. pars_info_add_str_literal(info, "tmp_path", tmp_path);
  3719. pars_info_add_int4_literal(info, "old_space",
  3720. (lint) old_table->space);
  3721. err = que_eval_sql(info,
  3722. "PROCEDURE RENAME_OLD_SPACE () IS\n"
  3723. "BEGIN\n"
  3724. "UPDATE SYS_TABLESPACES"
  3725. " SET NAME = :tmp_name\n"
  3726. " WHERE SPACE = :old_space;\n"
  3727. "UPDATE SYS_DATAFILES"
  3728. " SET PATH = :tmp_path\n"
  3729. " WHERE SPACE = :old_space;\n"
  3730. "END;\n", FALSE, trx);
  3731. ut_free(tmp_path);
  3732. }
  3733. /* Update SYS_TABLESPACES and SYS_DATAFILES if the new table being
  3734. renamed is a single-table tablespace, which must be implicitly
  3735. renamed along with the table. */
  3736. if (err == DB_SUCCESS
  3737. && dict_table_is_file_per_table(new_table)) {
  3738. /* Make pathname to update SYS_DATAFILES. */
  3739. char* old_path = row_make_new_pathname(
  3740. new_table, old_table->name.m_name);
  3741. info = pars_info_create();
  3742. pars_info_add_str_literal(info, "old_name",
  3743. old_table->name.m_name);
  3744. pars_info_add_str_literal(info, "old_path", old_path);
  3745. pars_info_add_int4_literal(info, "new_space",
  3746. (lint) new_table->space);
  3747. err = que_eval_sql(info,
  3748. "PROCEDURE RENAME_NEW_SPACE () IS\n"
  3749. "BEGIN\n"
  3750. "UPDATE SYS_TABLESPACES"
  3751. " SET NAME = :old_name\n"
  3752. " WHERE SPACE = :new_space;\n"
  3753. "UPDATE SYS_DATAFILES"
  3754. " SET PATH = :old_path\n"
  3755. " WHERE SPACE = :new_space;\n"
  3756. "END;\n", FALSE, trx);
  3757. ut_free(old_path);
  3758. }
  3759. if (err == DB_SUCCESS && dict_table_is_discarded(new_table)) {
  3760. err = row_import_update_discarded_flag(
  3761. trx, new_table->id, true, true);
  3762. }
  3763. trx->op_info = "";
  3764. return(err);
  3765. }
  3766. /** Create the index and load in to the dictionary.
  3767. @param[in,out] table the index is on this table
  3768. @param[in] index_def the index definition
  3769. @param[in] add_v new virtual columns added along with add
  3770. index call
  3771. @return index, or NULL on error */
  3772. dict_index_t*
  3773. row_merge_create_index(
  3774. dict_table_t* table,
  3775. const index_def_t* index_def,
  3776. const dict_add_v_col_t* add_v)
  3777. {
  3778. dict_index_t* index;
  3779. ulint n_fields = index_def->n_fields;
  3780. ulint i;
  3781. DBUG_ENTER("row_merge_create_index");
  3782. ut_ad(!srv_read_only_mode);
  3783. /* Create the index prototype, using the passed in def, this is not
  3784. a persistent operation. We pass 0 as the space id, and determine at
  3785. a lower level the space id where to store the table. */
  3786. index = dict_mem_index_create(table, index_def->name,
  3787. index_def->ind_type, n_fields);
  3788. index->set_committed(index_def->rebuild);
  3789. for (i = 0; i < n_fields; i++) {
  3790. const char* name;
  3791. index_field_t* ifield = &index_def->fields[i];
  3792. if (ifield->is_v_col) {
  3793. if (ifield->col_no >= table->n_v_def) {
  3794. ut_ad(ifield->col_no < table->n_v_def
  3795. + add_v->n_v_col);
  3796. ut_ad(ifield->col_no >= table->n_v_def);
  3797. name = add_v->v_col_name[
  3798. ifield->col_no - table->n_v_def];
  3799. index->has_new_v_col = true;
  3800. } else {
  3801. name = dict_table_get_v_col_name(
  3802. table, ifield->col_no);
  3803. }
  3804. } else {
  3805. name = dict_table_get_col_name(table, ifield->col_no);
  3806. }
  3807. dict_mem_index_add_field(index, name, ifield->prefix_len);
  3808. }
  3809. DBUG_RETURN(index);
  3810. }
  3811. /*********************************************************************//**
  3812. Check if a transaction can use an index. */
  3813. bool
  3814. row_merge_is_index_usable(
  3815. /*======================*/
  3816. const trx_t* trx, /*!< in: transaction */
  3817. const dict_index_t* index) /*!< in: index to check */
  3818. {
  3819. if (!dict_index_is_clust(index)
  3820. && dict_index_is_online_ddl(index)) {
  3821. /* Indexes that are being created are not useable. */
  3822. return(false);
  3823. }
  3824. return(!dict_index_is_corrupted(index)
  3825. && (dict_table_is_temporary(index->table)
  3826. || index->trx_id == 0
  3827. || !trx->read_view.is_open()
  3828. || trx->read_view.changes_visible(
  3829. index->trx_id,
  3830. index->table->name)));
  3831. }
  3832. /*********************************************************************//**
  3833. Drop a table. The caller must have ensured that the background stats
  3834. thread is not processing the table. This can be done by calling
  3835. dict_stats_wait_bg_to_stop_using_table() after locking the dictionary and
  3836. before calling this function.
  3837. @return DB_SUCCESS or error code */
  3838. dberr_t
  3839. row_merge_drop_table(
  3840. /*=================*/
  3841. trx_t* trx, /*!< in: transaction */
  3842. dict_table_t* table) /*!< in: table to drop */
  3843. {
  3844. ut_ad(!srv_read_only_mode);
  3845. /* There must be no open transactions on the table. */
  3846. ut_a(table->get_ref_count() == 0);
  3847. return(row_drop_table_for_mysql(table->name.m_name,
  3848. trx, false, false, false));
  3849. }
  3850. /** Write an MLOG_INDEX_LOAD record to indicate in the redo-log
  3851. that redo-logging of individual index pages was disabled, and
  3852. the flushing of such pages to the data files was completed.
  3853. @param[in] index an index tree on which redo logging was disabled */
  3854. static
  3855. void
  3856. row_merge_write_redo(
  3857. const dict_index_t* index)
  3858. {
  3859. mtr_t mtr;
  3860. byte* log_ptr;
  3861. ut_ad(!index->table->is_temporary());
  3862. mtr.start();
  3863. log_ptr = mlog_open(&mtr, 11 + 8);
  3864. log_ptr = mlog_write_initial_log_record_low(
  3865. MLOG_INDEX_LOAD,
  3866. index->table->space, index->page, log_ptr, &mtr);
  3867. mach_write_to_8(log_ptr, index->id);
  3868. mlog_close(&mtr, log_ptr + 8);
  3869. mtr.commit();
  3870. }
  3871. /** Build indexes on a table by reading a clustered index, creating a temporary
  3872. file containing index entries, merge sorting these index entries and inserting
  3873. sorted index entries to indexes.
  3874. @param[in] trx transaction
  3875. @param[in] old_table table where rows are read from
  3876. @param[in] new_table table where indexes are created; identical to
  3877. old_table unless creating a PRIMARY KEY
  3878. @param[in] online true if creating indexes online
  3879. @param[in] indexes indexes to be created
  3880. @param[in] key_numbers MySQL key numbers
  3881. @param[in] n_indexes size of indexes[]
  3882. @param[in,out] table MySQL table, for reporting erroneous key value
  3883. if applicable
  3884. @param[in] add_cols default values of added columns, or NULL
  3885. @param[in] col_map mapping of old column numbers to new ones, or
  3886. NULL if old_table == new_table
  3887. @param[in] add_autoinc number of added AUTO_INCREMENT columns, or
  3888. ULINT_UNDEFINED if none is added
  3889. @param[in,out] sequence autoinc sequence
  3890. @param[in] skip_pk_sort whether the new PRIMARY KEY will follow
  3891. existing order
  3892. @param[in,out] stage performance schema accounting object, used by
  3893. ALTER TABLE. stage->begin_phase_read_pk() will be called at the beginning of
  3894. this function and it will be passed to other functions for further accounting.
  3895. @param[in] add_v new virtual columns added along with indexes
  3896. @param[in] eval_table mysql table used to evaluate virtual column
  3897. value, see innobase_get_computed_value().
  3898. @param[in] drop_historical whether to drop historical system rows
  3899. @return DB_SUCCESS or error code */
  3900. dberr_t
  3901. row_merge_build_indexes(
  3902. trx_t* trx,
  3903. dict_table_t* old_table,
  3904. dict_table_t* new_table,
  3905. bool online,
  3906. dict_index_t** indexes,
  3907. const ulint* key_numbers,
  3908. ulint n_indexes,
  3909. struct TABLE* table,
  3910. const dtuple_t* add_cols,
  3911. const ulint* col_map,
  3912. ulint add_autoinc,
  3913. ib_sequence_t& sequence,
  3914. bool skip_pk_sort,
  3915. ut_stage_alter_t* stage,
  3916. const dict_add_v_col_t* add_v,
  3917. struct TABLE* eval_table,
  3918. bool drop_historical)
  3919. {
  3920. merge_file_t* merge_files;
  3921. row_merge_block_t* block;
  3922. ut_new_pfx_t block_pfx;
  3923. size_t block_size;
  3924. ut_new_pfx_t crypt_pfx;
  3925. row_merge_block_t* crypt_block = NULL;
  3926. ulint i;
  3927. ulint j;
  3928. dberr_t error;
  3929. int tmpfd = -1;
  3930. dict_index_t* fts_sort_idx = NULL;
  3931. fts_psort_t* psort_info = NULL;
  3932. fts_psort_t* merge_info = NULL;
  3933. int64_t sig_count = 0;
  3934. bool fts_psort_initiated = false;
  3935. double total_static_cost = 0;
  3936. double total_dynamic_cost = 0;
  3937. ulint total_index_blocks = 0;
  3938. double pct_cost=0;
  3939. double pct_progress=0;
  3940. DBUG_ENTER("row_merge_build_indexes");
  3941. ut_ad(!srv_read_only_mode);
  3942. ut_ad((old_table == new_table) == !col_map);
  3943. ut_ad(!add_cols || col_map);
  3944. stage->begin_phase_read_pk(skip_pk_sort && new_table != old_table
  3945. ? n_indexes - 1
  3946. : n_indexes);
  3947. /* Allocate memory for merge file data structure and initialize
  3948. fields */
  3949. ut_allocator<row_merge_block_t> alloc(mem_key_row_merge_sort);
  3950. /* This will allocate "3 * srv_sort_buf_size" elements of type
  3951. row_merge_block_t. The latter is defined as byte. */
  3952. block_size = 3 * srv_sort_buf_size;
  3953. block = alloc.allocate_large(block_size, &block_pfx);
  3954. if (block == NULL) {
  3955. DBUG_RETURN(DB_OUT_OF_MEMORY);
  3956. }
  3957. TRASH_ALLOC(&crypt_pfx, sizeof crypt_pfx);
  3958. if (log_tmp_is_encrypted()) {
  3959. crypt_block = static_cast<row_merge_block_t*>(
  3960. alloc.allocate_large(block_size,
  3961. &crypt_pfx));
  3962. if (crypt_block == NULL) {
  3963. DBUG_RETURN(DB_OUT_OF_MEMORY);
  3964. }
  3965. }
  3966. trx_start_if_not_started_xa(trx, true);
  3967. /* Check if we need a flush observer to flush dirty pages.
  3968. Since we disable redo logging in bulk load, so we should flush
  3969. dirty pages before online log apply, because online log apply enables
  3970. redo logging(we can do further optimization here).
  3971. 1. online add index: flush dirty pages right before row_log_apply().
  3972. 2. table rebuild: flush dirty pages before row_log_table_apply().
  3973. we use bulk load to create all types of indexes except spatial index,
  3974. for which redo logging is enabled. If we create only spatial indexes,
  3975. we don't need to flush dirty pages at all. */
  3976. bool need_flush_observer = (old_table != new_table);
  3977. for (i = 0; i < n_indexes; i++) {
  3978. if (!dict_index_is_spatial(indexes[i])) {
  3979. need_flush_observer = true;
  3980. }
  3981. }
  3982. FlushObserver* flush_observer = NULL;
  3983. if (need_flush_observer) {
  3984. flush_observer = UT_NEW_NOKEY(
  3985. FlushObserver(new_table->space, trx, stage));
  3986. trx_set_flush_observer(trx, flush_observer);
  3987. }
  3988. merge_files = static_cast<merge_file_t*>(
  3989. ut_malloc_nokey(n_indexes * sizeof *merge_files));
  3990. /* Initialize all the merge file descriptors, so that we
  3991. don't call row_merge_file_destroy() on uninitialized
  3992. merge file descriptor */
  3993. for (i = 0; i < n_indexes; i++) {
  3994. merge_files[i].fd = -1;
  3995. merge_files[i].offset = 0;
  3996. }
  3997. total_static_cost = COST_BUILD_INDEX_STATIC * n_indexes + COST_READ_CLUSTERED_INDEX;
  3998. total_dynamic_cost = COST_BUILD_INDEX_DYNAMIC * n_indexes;
  3999. for (i = 0; i < n_indexes; i++) {
  4000. if (indexes[i]->type & DICT_FTS) {
  4001. ibool opt_doc_id_size = FALSE;
  4002. /* To build FTS index, we would need to extract
  4003. doc's word, Doc ID, and word's position, so
  4004. we need to build a "fts sort index" indexing
  4005. on above three 'fields' */
  4006. fts_sort_idx = row_merge_create_fts_sort_index(
  4007. indexes[i], old_table, &opt_doc_id_size);
  4008. row_merge_dup_t* dup
  4009. = static_cast<row_merge_dup_t*>(
  4010. ut_malloc_nokey(sizeof *dup));
  4011. dup->index = fts_sort_idx;
  4012. dup->table = table;
  4013. dup->col_map = col_map;
  4014. dup->n_dup = 0;
  4015. /* This can fail e.g. if temporal files can't be
  4016. created */
  4017. if (!row_fts_psort_info_init(
  4018. trx, dup, new_table, opt_doc_id_size,
  4019. &psort_info, &merge_info)) {
  4020. error = DB_CORRUPTION;
  4021. goto func_exit;
  4022. }
  4023. /* We need to ensure that we free the resources
  4024. allocated */
  4025. fts_psort_initiated = true;
  4026. }
  4027. }
  4028. if (global_system_variables.log_warnings > 2) {
  4029. sql_print_information("InnoDB: Online DDL : Start reading"
  4030. " clustered index of the table"
  4031. " and create temporary files");
  4032. }
  4033. pct_cost = COST_READ_CLUSTERED_INDEX * 100 / (total_static_cost + total_dynamic_cost);
  4034. /* Do not continue if we can't encrypt table pages */
  4035. if (!old_table->is_readable() ||
  4036. !new_table->is_readable()) {
  4037. error = DB_DECRYPTION_FAILED;
  4038. ib_push_warning(trx->mysql_thd, DB_DECRYPTION_FAILED,
  4039. "Table %s is encrypted but encryption service or"
  4040. " used key_id is not available. "
  4041. " Can't continue reading table.",
  4042. !old_table->is_readable() ? old_table->name.m_name :
  4043. new_table->name.m_name);
  4044. goto func_exit;
  4045. }
  4046. /* Read clustered index of the table and create files for
  4047. secondary index entries for merge sort */
  4048. error = row_merge_read_clustered_index(
  4049. trx, table, old_table, new_table, online, indexes,
  4050. fts_sort_idx, psort_info, merge_files, key_numbers,
  4051. n_indexes, add_cols, add_v, col_map, add_autoinc,
  4052. sequence, block, skip_pk_sort, &tmpfd, stage,
  4053. pct_cost, crypt_block, eval_table, drop_historical);
  4054. stage->end_phase_read_pk();
  4055. pct_progress += pct_cost;
  4056. if (global_system_variables.log_warnings > 2) {
  4057. sql_print_information("InnoDB: Online DDL : End of reading "
  4058. "clustered index of the table"
  4059. " and create temporary files");
  4060. }
  4061. for (i = 0; i < n_indexes; i++) {
  4062. total_index_blocks += merge_files[i].offset;
  4063. }
  4064. if (error != DB_SUCCESS) {
  4065. goto func_exit;
  4066. }
  4067. DEBUG_SYNC_C("row_merge_after_scan");
  4068. /* Now we have files containing index entries ready for
  4069. sorting and inserting. */
  4070. for (i = 0; i < n_indexes; i++) {
  4071. dict_index_t* sort_idx = indexes[i];
  4072. if (dict_index_is_spatial(sort_idx)) {
  4073. continue;
  4074. }
  4075. if (indexes[i]->type & DICT_FTS) {
  4076. os_event_t fts_parallel_merge_event;
  4077. sort_idx = fts_sort_idx;
  4078. fts_parallel_merge_event
  4079. = merge_info[0].psort_common->merge_event;
  4080. if (FTS_PLL_MERGE) {
  4081. ulint trial_count = 0;
  4082. bool all_exit = false;
  4083. os_event_reset(fts_parallel_merge_event);
  4084. row_fts_start_parallel_merge(merge_info);
  4085. wait_again:
  4086. os_event_wait_time_low(
  4087. fts_parallel_merge_event, 1000000,
  4088. sig_count);
  4089. for (j = 0; j < FTS_NUM_AUX_INDEX; j++) {
  4090. if (merge_info[j].child_status
  4091. != FTS_CHILD_COMPLETE
  4092. && merge_info[j].child_status
  4093. != FTS_CHILD_EXITING) {
  4094. sig_count = os_event_reset(
  4095. fts_parallel_merge_event);
  4096. goto wait_again;
  4097. }
  4098. }
  4099. /* Now all children should complete, wait
  4100. a bit until they all finish using event */
  4101. while (!all_exit && trial_count < 10000) {
  4102. all_exit = true;
  4103. for (j = 0; j < FTS_NUM_AUX_INDEX;
  4104. j++) {
  4105. if (merge_info[j].child_status
  4106. != FTS_CHILD_EXITING) {
  4107. all_exit = false;
  4108. os_thread_sleep(1000);
  4109. break;
  4110. }
  4111. }
  4112. trial_count++;
  4113. }
  4114. if (!all_exit) {
  4115. ib::error() << "Not all child merge"
  4116. " threads exited when creating"
  4117. " FTS index '"
  4118. << indexes[i]->name << "'";
  4119. } else {
  4120. for (j = 0; j < FTS_NUM_AUX_INDEX;
  4121. j++) {
  4122. os_thread_join(merge_info[j]
  4123. .thread_hdl);
  4124. }
  4125. }
  4126. } else {
  4127. /* This cannot report duplicates; an
  4128. assertion would fail in that case. */
  4129. error = row_fts_merge_insert(
  4130. sort_idx, new_table,
  4131. psort_info, 0);
  4132. }
  4133. #ifdef FTS_INTERNAL_DIAG_PRINT
  4134. DEBUG_FTS_SORT_PRINT("FTS_SORT: Complete Insert\n");
  4135. #endif
  4136. } else if (merge_files[i].fd >= 0) {
  4137. char buf[NAME_LEN + 1];
  4138. row_merge_dup_t dup = {
  4139. sort_idx, table, col_map, 0};
  4140. pct_cost = (COST_BUILD_INDEX_STATIC +
  4141. (total_dynamic_cost * merge_files[i].offset /
  4142. total_index_blocks)) /
  4143. (total_static_cost + total_dynamic_cost)
  4144. * PCT_COST_MERGESORT_INDEX * 100;
  4145. char* bufend = innobase_convert_name(
  4146. buf, sizeof buf,
  4147. indexes[i]->name,
  4148. strlen(indexes[i]->name),
  4149. trx->mysql_thd);
  4150. buf[bufend - buf]='\0';
  4151. if (global_system_variables.log_warnings > 2) {
  4152. sql_print_information("InnoDB: Online DDL :"
  4153. " Start merge-sorting"
  4154. " index %s"
  4155. " (" ULINTPF
  4156. " / " ULINTPF "),"
  4157. " estimated cost :"
  4158. " %2.4f",
  4159. buf, i + 1, n_indexes,
  4160. pct_cost);
  4161. }
  4162. error = row_merge_sort(
  4163. trx, &dup, &merge_files[i],
  4164. block, &tmpfd, true,
  4165. pct_progress, pct_cost,
  4166. crypt_block, new_table->space, stage);
  4167. pct_progress += pct_cost;
  4168. if (global_system_variables.log_warnings > 2) {
  4169. sql_print_information("InnoDB: Online DDL :"
  4170. " End of "
  4171. " merge-sorting index %s"
  4172. " (" ULINTPF
  4173. " / " ULINTPF ")",
  4174. buf, i + 1, n_indexes);
  4175. }
  4176. DBUG_EXECUTE_IF(
  4177. "ib_merge_wait_after_sort",
  4178. os_thread_sleep(20000000);); /* 20 sec */
  4179. if (error == DB_SUCCESS) {
  4180. BtrBulk btr_bulk(sort_idx, trx->id,
  4181. flush_observer);
  4182. btr_bulk.init();
  4183. pct_cost = (COST_BUILD_INDEX_STATIC +
  4184. (total_dynamic_cost * merge_files[i].offset /
  4185. total_index_blocks)) /
  4186. (total_static_cost + total_dynamic_cost) *
  4187. PCT_COST_INSERT_INDEX * 100;
  4188. if (global_system_variables.log_warnings > 2) {
  4189. sql_print_information(
  4190. "InnoDB: Online DDL : Start "
  4191. "building index %s"
  4192. " (" ULINTPF
  4193. " / " ULINTPF "), estimated "
  4194. "cost : %2.4f", buf, i + 1,
  4195. n_indexes, pct_cost);
  4196. }
  4197. error = row_merge_insert_index_tuples(
  4198. sort_idx, old_table,
  4199. merge_files[i].fd, block, NULL,
  4200. &btr_bulk,
  4201. merge_files[i].n_rec, pct_progress, pct_cost,
  4202. crypt_block, new_table->space, stage);
  4203. error = btr_bulk.finish(error);
  4204. pct_progress += pct_cost;
  4205. if (global_system_variables.log_warnings > 2) {
  4206. sql_print_information(
  4207. "InnoDB: Online DDL : "
  4208. "End of building index %s"
  4209. " (" ULINTPF " / " ULINTPF ")",
  4210. buf, i + 1, n_indexes);
  4211. }
  4212. }
  4213. }
  4214. /* Close the temporary file to free up space. */
  4215. row_merge_file_destroy(&merge_files[i]);
  4216. if (indexes[i]->type & DICT_FTS) {
  4217. row_fts_psort_info_destroy(psort_info, merge_info);
  4218. fts_psort_initiated = false;
  4219. } else if (error != DB_SUCCESS || !online) {
  4220. /* Do not apply any online log. */
  4221. } else if (old_table != new_table) {
  4222. ut_ad(!sort_idx->online_log);
  4223. ut_ad(sort_idx->online_status
  4224. == ONLINE_INDEX_COMPLETE);
  4225. } else {
  4226. ut_ad(need_flush_observer);
  4227. if (global_system_variables.log_warnings > 2) {
  4228. sql_print_information(
  4229. "InnoDB: Online DDL : Applying"
  4230. " log to index");
  4231. }
  4232. flush_observer->flush();
  4233. row_merge_write_redo(indexes[i]);
  4234. DEBUG_SYNC_C("row_log_apply_before");
  4235. error = row_log_apply(trx, sort_idx, table, stage);
  4236. DEBUG_SYNC_C("row_log_apply_after");
  4237. }
  4238. if (error != DB_SUCCESS) {
  4239. trx->error_key_num = key_numbers[i];
  4240. goto func_exit;
  4241. }
  4242. if (indexes[i]->type & DICT_FTS && fts_enable_diag_print) {
  4243. ib::info() << "Finished building full-text index "
  4244. << indexes[i]->name;
  4245. }
  4246. }
  4247. func_exit:
  4248. DBUG_EXECUTE_IF(
  4249. "ib_build_indexes_too_many_concurrent_trxs",
  4250. error = DB_TOO_MANY_CONCURRENT_TRXS;
  4251. trx->error_state = error;);
  4252. if (fts_psort_initiated) {
  4253. /* Clean up FTS psort related resource */
  4254. row_fts_psort_info_destroy(psort_info, merge_info);
  4255. fts_psort_initiated = false;
  4256. }
  4257. row_merge_file_destroy_low(tmpfd);
  4258. for (i = 0; i < n_indexes; i++) {
  4259. row_merge_file_destroy(&merge_files[i]);
  4260. }
  4261. if (fts_sort_idx) {
  4262. dict_mem_index_free(fts_sort_idx);
  4263. }
  4264. ut_free(merge_files);
  4265. alloc.deallocate_large(block, &block_pfx, block_size);
  4266. if (crypt_block) {
  4267. alloc.deallocate_large(crypt_block, &crypt_pfx, block_size);
  4268. }
  4269. DICT_TF2_FLAG_UNSET(new_table, DICT_TF2_FTS_ADD_DOC_ID);
  4270. if (online && old_table == new_table && error != DB_SUCCESS) {
  4271. /* On error, flag all online secondary index creation
  4272. as aborted. */
  4273. for (i = 0; i < n_indexes; i++) {
  4274. ut_ad(!(indexes[i]->type & DICT_FTS));
  4275. ut_ad(!indexes[i]->is_committed());
  4276. ut_ad(!dict_index_is_clust(indexes[i]));
  4277. /* Completed indexes should be dropped as
  4278. well, and indexes whose creation was aborted
  4279. should be dropped from the persistent
  4280. storage. However, at this point we can only
  4281. set some flags in the not-yet-published
  4282. indexes. These indexes will be dropped later
  4283. in row_merge_drop_indexes(), called by
  4284. rollback_inplace_alter_table(). */
  4285. switch (dict_index_get_online_status(indexes[i])) {
  4286. case ONLINE_INDEX_COMPLETE:
  4287. break;
  4288. case ONLINE_INDEX_CREATION:
  4289. rw_lock_x_lock(
  4290. dict_index_get_lock(indexes[i]));
  4291. row_log_abort_sec(indexes[i]);
  4292. indexes[i]->type |= DICT_CORRUPT;
  4293. rw_lock_x_unlock(
  4294. dict_index_get_lock(indexes[i]));
  4295. new_table->drop_aborted = TRUE;
  4296. /* fall through */
  4297. case ONLINE_INDEX_ABORTED_DROPPED:
  4298. case ONLINE_INDEX_ABORTED:
  4299. MONITOR_ATOMIC_INC(
  4300. MONITOR_BACKGROUND_DROP_INDEX);
  4301. }
  4302. }
  4303. }
  4304. DBUG_EXECUTE_IF("ib_index_crash_after_bulk_load", DBUG_SUICIDE(););
  4305. if (flush_observer != NULL) {
  4306. ut_ad(need_flush_observer);
  4307. DBUG_EXECUTE_IF("ib_index_build_fail_before_flush",
  4308. error = DB_INTERRUPTED;
  4309. );
  4310. if (error != DB_SUCCESS) {
  4311. flush_observer->interrupted();
  4312. }
  4313. flush_observer->flush();
  4314. UT_DELETE(flush_observer);
  4315. if (trx_is_interrupted(trx)) {
  4316. error = DB_INTERRUPTED;
  4317. }
  4318. if (error == DB_SUCCESS && old_table != new_table) {
  4319. for (const dict_index_t* index
  4320. = dict_table_get_first_index(new_table);
  4321. index != NULL;
  4322. index = dict_table_get_next_index(index)) {
  4323. row_merge_write_redo(index);
  4324. }
  4325. }
  4326. }
  4327. DBUG_RETURN(error);
  4328. }