From 31774f0ede81d77d889061324930d3d0066c653a Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Mon, 11 Sep 2017 16:45:36 +0000 Subject: MDEV-13563 lock DDL for mariabackup in 10.2 Implement lock-ddl-per-table option that locks tables before it is copied to backup, and helds the lock until backup finished The "DDL-lock" itself is implemented as "SELECT * from LIMIT 0", inside a transaction, and "COMMIT" of this transaction is the DDL-unlock. --- extra/mariabackup/xtrabackup.cc | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'extra/mariabackup/xtrabackup.cc') diff --git a/extra/mariabackup/xtrabackup.cc b/extra/mariabackup/xtrabackup.cc index 65aa913cc29..5d8bc7eaaf3 100644 --- a/extra/mariabackup/xtrabackup.cc +++ b/extra/mariabackup/xtrabackup.cc @@ -296,6 +296,8 @@ my_bool opt_noversioncheck = FALSE; my_bool opt_no_backup_locks = FALSE; my_bool opt_decompress = FALSE; +my_bool opt_lock_ddl_per_table = FALSE; + static const char *binlog_info_values[] = {"off", "lockless", "on", "auto", NullS}; static TYPELIB binlog_info_typelib = {array_elements(binlog_info_values)-1, "", @@ -537,7 +539,8 @@ enum options_xtrabackup OPT_XTRA_TABLES_EXCLUDE, OPT_XTRA_DATABASES_EXCLUDE, - OPT_PROTOCOL + OPT_PROTOCOL, + OPT_LOCK_DDL_PER_TABLE }; struct my_option xb_client_options[] = @@ -1072,6 +1075,11 @@ struct my_option xb_server_options[] = (G_PTR*) &xb_open_files_limit, (G_PTR*) &xb_open_files_limit, 0, GET_ULONG, REQUIRED_ARG, 0, 0, UINT_MAX, 0, 1, 0}, + {"lock-ddl-per-table", OPT_LOCK_DDL_PER_TABLE, "Lock DDL for each table " + "before xtrabackup starts to copy it and until the backup is completed.", + (uchar*) &opt_lock_ddl_per_table, (uchar*) &opt_lock_ddl_per_table, 0, + GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, + { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} }; @@ -2205,6 +2213,10 @@ xtrabackup_copy_datafile(fil_node_t* node, uint thread_n) return(FALSE); } + if (opt_lock_ddl_per_table) { + mdl_lock_table(node->space->id); + } + if (!changed_page_bitmap) { read_filter = &rf_pass_through; } @@ -3552,6 +3564,10 @@ xtrabackup_backup_func() "or RENAME TABLE during the backup, inconsistent backup will be " "produced.\n"); + if (opt_lock_ddl_per_table) { + mdl_lock_init(); + } + /* initialize components */ if(innodb_init_param()) { fail: @@ -3930,6 +3946,10 @@ reread_log_header: goto fail; } + if (opt_lock_ddl_per_table) { + mdl_unlock_all(); + } + xtrabackup_destroy_datasinks(); msg("xtrabackup: Redo log (from LSN " LSN_PF " to " LSN_PF -- cgit v1.2.1