diff --git a/mysql-test/suite/gcol/t/innodb_virtual_debug_purge.opt b/mysql-test/suite/gcol/t/innodb_virtual_debug_purge.opt index 20a4e60b8ec..9622465d71f 100644 --- a/mysql-test/suite/gcol/t/innodb_virtual_debug_purge.opt +++ b/mysql-test/suite/gcol/t/innodb_virtual_debug_purge.opt @@ -1 +1 @@ ---skip-innodb-unsafe-truncate +--loose-innodb-safe-truncate=1 diff --git a/mysql-test/suite/innodb/t/alter_copy.opt b/mysql-test/suite/innodb/t/alter_copy.opt index e76044be888..9622465d71f 100644 --- a/mysql-test/suite/innodb/t/alter_copy.opt +++ b/mysql-test/suite/innodb/t/alter_copy.opt @@ -1 +1 @@ ---loose-skip-innodb-unsafe-truncate +--loose-innodb-safe-truncate=1 diff --git a/mysql-test/suite/innodb/t/alter_crash.opt b/mysql-test/suite/innodb/t/alter_crash.opt index 96710441921..0e92a05802e 100644 --- a/mysql-test/suite/innodb/t/alter_crash.opt +++ b/mysql-test/suite/innodb/t/alter_crash.opt @@ -1,2 +1,2 @@ --loose-innodb-sys-tables ---loose-skip-innodb-unsafe-truncate +--loose-innodb-safe-truncate=1 diff --git a/mysql-test/suite/innodb/t/drop_table_background.opt b/mysql-test/suite/innodb/t/drop_table_background.opt index e76044be888..9622465d71f 100644 --- a/mysql-test/suite/innodb/t/drop_table_background.opt +++ b/mysql-test/suite/innodb/t/drop_table_background.opt @@ -1 +1 @@ ---loose-skip-innodb-unsafe-truncate +--loose-innodb-safe-truncate=1 diff --git a/mysql-test/suite/innodb/t/rename_table_debug.opt b/mysql-test/suite/innodb/t/rename_table_debug.opt index e76044be888..9622465d71f 100644 --- a/mysql-test/suite/innodb/t/rename_table_debug.opt +++ b/mysql-test/suite/innodb/t/rename_table_debug.opt @@ -1 +1 @@ ---loose-skip-innodb-unsafe-truncate +--loose-innodb-safe-truncate=1 diff --git a/mysql-test/suite/innodb/t/truncate.opt b/mysql-test/suite/innodb/t/truncate.opt index e76044be888..9622465d71f 100644 --- a/mysql-test/suite/innodb/t/truncate.opt +++ b/mysql-test/suite/innodb/t/truncate.opt @@ -1 +1 @@ ---loose-skip-innodb-unsafe-truncate +--loose-innodb-safe-truncate=1 diff --git a/mysql-test/suite/innodb/t/truncate_crash.opt b/mysql-test/suite/innodb/t/truncate_crash.opt index e76044be888..9622465d71f 100644 --- a/mysql-test/suite/innodb/t/truncate_crash.opt +++ b/mysql-test/suite/innodb/t/truncate_crash.opt @@ -1 +1 @@ ---loose-skip-innodb-unsafe-truncate +--loose-innodb-safe-truncate=1 diff --git a/mysql-test/suite/innodb/t/truncate_foreign.opt b/mysql-test/suite/innodb/t/truncate_foreign.opt index e76044be888..9622465d71f 100644 --- a/mysql-test/suite/innodb/t/truncate_foreign.opt +++ b/mysql-test/suite/innodb/t/truncate_foreign.opt @@ -1 +1 @@ ---loose-skip-innodb-unsafe-truncate +--loose-innodb-safe-truncate=1 diff --git a/mysql-test/suite/innodb/t/truncate_missing.opt b/mysql-test/suite/innodb/t/truncate_missing.opt index e76044be888..9622465d71f 100644 --- a/mysql-test/suite/innodb/t/truncate_missing.opt +++ b/mysql-test/suite/innodb/t/truncate_missing.opt @@ -1 +1 @@ ---loose-skip-innodb-unsafe-truncate +--loose-innodb-safe-truncate=1 diff --git a/mysql-test/suite/innodb_zip/t/restart.opt b/mysql-test/suite/innodb_zip/t/restart.opt index fd89db6cc1d..8101a8573fc 100644 --- a/mysql-test/suite/innodb_zip/t/restart.opt +++ b/mysql-test/suite/innodb_zip/t/restart.opt @@ -1,4 +1,4 @@ --loose-innodb-sys-tables --loose-innodb-sys-tablespaces --loose-innodb-sys-datafiles ---loose-skip-innodb-unsafe-truncate +--loose-innodb-safe-truncate=1 diff --git a/mysql-test/suite/mariabackup/truncate_during_backup.opt b/mysql-test/suite/mariabackup/truncate_during_backup.opt index e76044be888..9622465d71f 100644 --- a/mysql-test/suite/mariabackup/truncate_during_backup.opt +++ b/mysql-test/suite/mariabackup/truncate_during_backup.opt @@ -1 +1 @@ ---loose-skip-innodb-unsafe-truncate +--loose-innodb-safe-truncate=1 diff --git a/mysql-test/suite/sys_vars/r/sysvars_innodb.result b/mysql-test/suite/sys_vars/r/sysvars_innodb.result index 0673de0054a..a2b82df3dbc 100644 --- a/mysql-test/suite/sys_vars/r/sysvars_innodb.result +++ b/mysql-test/suite/sys_vars/r/sysvars_innodb.result @@ -2400,6 +2400,20 @@ NUMERIC_BLOCK_SIZE 0 ENUM_VALUE_LIST NULL READ_ONLY NO COMMAND_LINE_ARGUMENT OPTIONAL +VARIABLE_NAME INNODB_SAFE_TRUNCATE +SESSION_VALUE NULL +GLOBAL_VALUE OFF +GLOBAL_VALUE_ORIGIN COMPILE-TIME +DEFAULT_VALUE OFF +VARIABLE_SCOPE GLOBAL +VARIABLE_TYPE BOOLEAN +VARIABLE_COMMENT Use backup-safe TRUNCATE TABLE and crash-safe RENAME (incompatible with older MariaDB 10.2; OFF by default) +NUMERIC_MIN_VALUE NULL +NUMERIC_MAX_VALUE NULL +NUMERIC_BLOCK_SIZE NULL +ENUM_VALUE_LIST OFF,ON +READ_ONLY YES +COMMAND_LINE_ARGUMENT OPTIONAL VARIABLE_NAME INNODB_SAVED_PAGE_NUMBER_DEBUG SESSION_VALUE NULL GLOBAL_VALUE 0 @@ -2974,20 +2988,6 @@ NUMERIC_BLOCK_SIZE 0 ENUM_VALUE_LIST NULL READ_ONLY YES COMMAND_LINE_ARGUMENT REQUIRED -VARIABLE_NAME INNODB_UNSAFE_TRUNCATE -SESSION_VALUE NULL -GLOBAL_VALUE ON -GLOBAL_VALUE_ORIGIN COMPILE-TIME -DEFAULT_VALUE ON -VARIABLE_SCOPE GLOBAL -VARIABLE_TYPE BOOLEAN -VARIABLE_COMMENT Use backup-unsafe TRUNCATE TABLE for compatibility with xtrabackup (on by default) -NUMERIC_MIN_VALUE NULL -NUMERIC_MAX_VALUE NULL -NUMERIC_BLOCK_SIZE NULL -ENUM_VALUE_LIST OFF,ON -READ_ONLY YES -COMMAND_LINE_ARGUMENT OPTIONAL VARIABLE_NAME INNODB_USE_ATOMIC_WRITES SESSION_VALUE NULL GLOBAL_VALUE ON diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 26e169b1ec3..e7ec8488d45 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -13452,7 +13452,7 @@ int ha_innobase::truncate() update_thd(); - if (srv_57_truncate) { + if (!srv_safe_truncate) { if (!trx_is_started(m_prebuilt->trx)) { ++m_prebuilt->trx->will_lock; } @@ -20694,10 +20694,10 @@ static MYSQL_SYSVAR_BOOL(read_only, srv_read_only_mode, "Start InnoDB in read only mode (off by default)", NULL, NULL, FALSE); -static MYSQL_SYSVAR_BOOL(unsafe_truncate, srv_57_truncate, +static MYSQL_SYSVAR_BOOL(safe_truncate, srv_safe_truncate, PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_READONLY, - "Use backup-unsafe TRUNCATE TABLE for compatibility with xtrabackup (on by default)", - NULL, NULL, TRUE); + "Use backup-safe TRUNCATE TABLE and crash-safe RENAME (incompatible with older MariaDB 10.2; OFF by default)", + NULL, NULL, FALSE); static MYSQL_SYSVAR_BOOL(cmp_per_index_enabled, srv_cmp_per_index_enabled, PLUGIN_VAR_OPCMDARG, @@ -21078,7 +21078,7 @@ static struct st_mysql_sys_var* innobase_system_variables[]= { MYSQL_SYSVAR(random_read_ahead), MYSQL_SYSVAR(read_ahead_threshold), MYSQL_SYSVAR(read_only), - MYSQL_SYSVAR(unsafe_truncate), + MYSQL_SYSVAR(safe_truncate), MYSQL_SYSVAR(io_capacity), MYSQL_SYSVAR(io_capacity_max), MYSQL_SYSVAR(page_cleaners), diff --git a/storage/innobase/include/srv0srv.h b/storage/innobase/include/srv0srv.h index f40cbf7f730..832a67539da 100644 --- a/storage/innobase/include/srv0srv.h +++ b/storage/innobase/include/srv0srv.h @@ -256,9 +256,9 @@ extern my_bool high_level_read_only; /** store to its own file each table created by an user; data dictionary tables are in the system tablespace 0 */ extern my_bool srv_file_per_table; -/** whether to use the MySQL 5.7 WL#6501 TRUNCATE TABLE implementation -that does not work with backup */ -extern my_bool srv_57_truncate; +/** whether to use backup-safe TRUNCATE and crash-safe RENAME +instead of the MySQL 5.7 WL#6501 TRUNCATE TABLE implementation */ +extern my_bool srv_safe_truncate; /** Sleep delay for threads waiting to enter InnoDB. In micro-seconds. */ extern ulong srv_thread_sleep_delay; /** Maximum sleep delay (in micro-seconds), value of 0 disables it.*/ diff --git a/storage/innobase/log/log0log.cc b/storage/innobase/log/log0log.cc index b7d39440c75..8fa8662ca31 100644 --- a/storage/innobase/log/log0log.cc +++ b/storage/innobase/log/log0log.cc @@ -790,15 +790,15 @@ log_init(ulint n_files) log_group_t* group = &log_sys->log; group->n_files = n_files; - group->subformat = !srv_57_truncate; - if (srv_57_truncate) { - group->format = srv_encrypt_log - ? LOG_HEADER_FORMAT_10_2 | LOG_HEADER_FORMAT_ENCRYPTED - : LOG_HEADER_FORMAT_10_2; - } else { + group->subformat = srv_safe_truncate; + if (srv_safe_truncate) { group->format = srv_encrypt_log ? LOG_HEADER_FORMAT_10_3 | LOG_HEADER_FORMAT_ENCRYPTED : LOG_HEADER_FORMAT_10_3; + } else { + group->format = srv_encrypt_log + ? LOG_HEADER_FORMAT_10_2 | LOG_HEADER_FORMAT_ENCRYPTED + : LOG_HEADER_FORMAT_10_2; } group->file_size = srv_log_file_size; group->state = LOG_GROUP_OK; @@ -881,15 +881,15 @@ log_group_file_header_flush( ut_ad(!recv_no_log_write); ut_a(nth_file < group->n_files); ut_ad((group->format & ~LOG_HEADER_FORMAT_ENCRYPTED) - == (srv_57_truncate - ? LOG_HEADER_FORMAT_10_2 - : LOG_HEADER_FORMAT_10_3)); + == (srv_safe_truncate + ? LOG_HEADER_FORMAT_10_3 + : LOG_HEADER_FORMAT_10_2)); buf = *(group->file_header_bufs + nth_file); memset(buf, 0, OS_FILE_LOG_BLOCK_SIZE); mach_write_to_4(buf + LOG_HEADER_FORMAT, group->format); - mach_write_to_4(buf + LOG_HEADER_SUBFORMAT, !srv_57_truncate); + mach_write_to_4(buf + LOG_HEADER_SUBFORMAT, srv_safe_truncate); mach_write_to_8(buf + LOG_HEADER_START_LSN, start_lsn); strcpy(reinterpret_cast(buf) + LOG_HEADER_CREATOR, LOG_HEADER_CREATOR_CURRENT); diff --git a/storage/innobase/log/log0recv.cc b/storage/innobase/log/log0recv.cc index 2d2d9f2d674..880935e304e 100644 --- a/storage/innobase/log/log0recv.cc +++ b/storage/innobase/log/log0recv.cc @@ -3769,7 +3769,7 @@ recv_recovery_rollback_active(void) /* Drop partially created indexes. */ row_merge_drop_temp_indexes(); /* Drop garbage tables. */ - if (!srv_57_truncate) + if (srv_safe_truncate) row_mysql_drop_garbage_tables(); /* Drop any auxiliary tables that were not dropped when the diff --git a/storage/innobase/row/row0mysql.cc b/storage/innobase/row/row0mysql.cc index 5f558203ca4..02a71d2fa63 100644 --- a/storage/innobase/row/row0mysql.cc +++ b/storage/innobase/row/row0mysql.cc @@ -4403,7 +4403,7 @@ row_rename_table_for_mysql( goto funct_exit; } - if (!table->is_temporary() && !srv_57_truncate) { + if (!table->is_temporary() && srv_safe_truncate) { err = trx_undo_report_rename(trx, table); if (err != DB_SUCCESS) { diff --git a/storage/innobase/srv/srv0srv.cc b/storage/innobase/srv/srv0srv.cc index 10bd308ec53..0aebdb1cfd3 100644 --- a/storage/innobase/srv/srv0srv.cc +++ b/storage/innobase/srv/srv0srv.cc @@ -152,9 +152,9 @@ my_bool srv_read_only_mode; /** store to its own file each table created by an user; data dictionary tables are in the system tablespace 0 */ my_bool srv_file_per_table; -/** whether to use the MySQL 5.7 WL#6501 TRUNCATE TABLE implementation -that does not work with backup */ -my_bool srv_57_truncate; +/** whether to use backup-safe TRUNCATE and crash-safe RENAME +instead of the MySQL 5.7 WL#6501 TRUNCATE TABLE implementation */ +my_bool srv_safe_truncate; /** The file format to use on new *.ibd files. */ ulint srv_file_format; /** Whether to check file format during startup. A value of diff --git a/storage/innobase/srv/srv0start.cc b/storage/innobase/srv/srv0start.cc index c39a5ea1937..9349220234e 100644 --- a/storage/innobase/srv/srv0start.cc +++ b/storage/innobase/srv/srv0start.cc @@ -1393,15 +1393,15 @@ srv_prepare_to_delete_redo_log_files( ulint pending_io = 0; ulint count = 0; - if (srv_57_truncate) { + if (srv_safe_truncate) { if ((log_sys->log.format & ~LOG_HEADER_FORMAT_ENCRYPTED) - != LOG_HEADER_FORMAT_10_2) { + != LOG_HEADER_FORMAT_10_3 + || log_sys->log.subformat != 1) { srv_log_file_size = 0; } } else { if ((log_sys->log.format & ~LOG_HEADER_FORMAT_ENCRYPTED) - != LOG_HEADER_FORMAT_10_3 - || log_sys->log.subformat != 1) { + != LOG_HEADER_FORMAT_10_2) { srv_log_file_size = 0; } } @@ -2399,16 +2399,16 @@ files_checked: } else if (srv_log_file_size_requested == srv_log_file_size && srv_n_log_files_found == srv_n_log_files && log_sys->log.format - == (srv_57_truncate + == (srv_safe_truncate ? (srv_encrypt_log - ? LOG_HEADER_FORMAT_10_2 - | LOG_HEADER_FORMAT_ENCRYPTED - : LOG_HEADER_FORMAT_10_2) - : (srv_encrypt_log ? LOG_HEADER_FORMAT_10_3 | LOG_HEADER_FORMAT_ENCRYPTED - : LOG_HEADER_FORMAT_10_3)) - && log_sys->log.subformat == !srv_57_truncate) { + : LOG_HEADER_FORMAT_10_3) + : (srv_encrypt_log + ? LOG_HEADER_FORMAT_10_2 + | LOG_HEADER_FORMAT_ENCRYPTED + : LOG_HEADER_FORMAT_10_2)) + && log_sys->log.subformat == srv_safe_truncate) { /* No need to add or remove encryption, upgrade, downgrade, or resize. */ } else { diff --git a/storage/innobase/trx/trx0rec.cc b/storage/innobase/trx/trx0rec.cc index a50cdbaad6f..9f47fd89945 100644 --- a/storage/innobase/trx/trx0rec.cc +++ b/storage/innobase/trx/trx0rec.cc @@ -1938,7 +1938,7 @@ trx_undo_report_rename(trx_t* trx, const dict_table_t* table) ut_ad(!trx->read_only); ut_ad(trx->id); ut_ad(!table->is_temporary()); - ut_ad(!srv_57_truncate); + ut_ad(srv_safe_truncate); trx_rseg_t* rseg = trx->rsegs.m_redo.rseg; trx_undo_t** pundo = &trx->rsegs.m_redo.insert_undo;