Skip to content

Commit

Permalink
PXB-3034 - Adding test cases
Browse files Browse the repository at this point in the history
https://jira.percona.com/browse/PXB-3034

Added test cases under suite/lockless
Fixed test cases using --lock-ddl=false/true
  • Loading branch information
altmannmarcelo committed Dec 14, 2023
1 parent 38d7216 commit 3c89fe3
Show file tree
Hide file tree
Showing 43 changed files with 1,340 additions and 39 deletions.
1 change: 1 addition & 0 deletions storage/innobase/xtrabackup/src/backup_copy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1397,6 +1397,7 @@ bool backup_start(Backup_context &context) {
}
/* LTFB/LIFB has to be executed before copying MyISAM */
if (ddl_tracker != nullptr) {
debug_sync_point("ddl_tracker_before_lock_ddl");
if (!lock_tables_for_backup(mysql_connection, opt_backup_lock_timeout,
opt_backup_lock_retry_count)) {
return (false);
Expand Down
2 changes: 1 addition & 1 deletion storage/innobase/xtrabackup/test/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ main () {

case "${TYPE}" in
innodb80)
url="https://dev.mysql.com/get/Downloads/MySQL-8.1"
url="https://dev.mysql.com/get/Downloads/MySQL-8.2"
fallback_url="https://downloads.mysql.com/archives/get/p/23/file"
tarball="mysql-${VERSION}-linux-glibc2.17-${arch}.tar.xz"
if ! check_url "${url}" "${tarball}"; then
Expand Down
8 changes: 4 additions & 4 deletions storage/innobase/xtrabackup/test/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ Usage: $0 [-f] [-g] [-h] [-s suite] [-t test_name] [-d mysql_basedir] [-c build_
-k Make a copy of failed var directory
-t path Run only a single named test. This option can be passed multiple times.
-h Print this help message
-s suite Select a test suite to run. Possible values: binlog, experimental, gr, keyring, rocksdb, pagetracking, main, compression and xbcloud.
Default is 'binlog, main, gr, pagetracking, rocksdb, keyring, compression and xbcloud'.
-s suite Select a test suite to run. Possible values: binlog, experimental, gr, keyring, rocksdb, pagetracking, main, compression, lockless and xbcloud.
Default is 'binlog, main, gr, pagetracking, rocksdb, keyring, compression, lockless and xbcloud'.
-j N Run tests in N parallel processes.
-T seconds Test timeout (default is $TEST_TIMEOUT seconds).
-x options Extra options to pass to xtrabackup
Expand Down Expand Up @@ -939,8 +939,8 @@ if [ -n "$tname" ]
then
tests="$tname"
else
tests="suites/binlog/* suites/pagetracking/* suites/gr/*.sh suites/keyring/*.sh suites/xbcloud/*.sh suites/compression/*.sh suites/rocksdb/*.sh t/*.sh"
suites=" pagetracking binlog gr keyring compression rocksdb main xbcloud"
tests="suites/binlog/* suites/pagetracking/* suites/gr/*.sh suites/keyring/*.sh suites/xbcloud/*.sh suites/compression/*.sh suites/lockless/*.sh suites/rocksdb/*.sh t/*.sh"
suites=" pagetracking binlog gr keyring compression lockless rocksdb main xbcloud"
fi

export OUTFILE="$PWD/results/setup"
Expand Down
14 changes: 10 additions & 4 deletions storage/innobase/xtrabackup/test/suites/binlog/ib_slave_info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ run_cmd_expect_failure $XB_BIN $XB_ARGS --backup --slave-info --no-lock \
--target-dir=$topdir/backup

vlog "Full backup of the slave server"
xtrabackup --backup --lock-ddl=false --target-dir=$topdir/backup --slave-info --safe-slave-backup 2>&1 | tee $topdir/pxb.log
xtrabackup --backup --lock-ddl=OFF --target-dir=$topdir/backup --slave-info --safe-slave-backup 2>&1 | tee $topdir/pxb.log

grep_general_log > $topdir/log1

Expand All @@ -107,6 +107,12 @@ run_cmd egrep "MySQL slave binlog position: $pxb_log_slave_info_pattern" $topdir
# PXB-3033 - Execute STOP SLAVE before copying non-InnoDB tables
grep -A 5 'Slave is safe to backup.' $topdir/pxb.log | grep -q 'Starting to backup non-InnoDB tables and files' || die 'STOP SLAVE in wrong place'

# PXB-3034 - STOP SLAVE should be executed after copying InnoDB tables if lock-ddl=reduced
xtrabackup --backup --lock-ddl=REDUCED --target-dir=$topdir/backup_reduced --slave-info --safe-slave-backup 2>&1 | tee $topdir/pxb_reduced.log

grep -A 10 'Slave is safe to backup.' $topdir/pxb_reduced.log | grep -q 'Starting to backup non-InnoDB tables and files' || die 'STOP SLAVE in wrong place'


run_cmd egrep -q "$binlog_slave_info_pattern" \
$topdir/backup/xtrabackup_slave_info

Expand All @@ -117,7 +123,7 @@ mysql -e "TRUNCATE TABLE mysql.general_log;"
mkdir $topdir/xbstream_backup

vlog "Full backup of the slave server to a xbstream stream"
xtrabackup --backup --lock-ddl=false --slave-info --safe-slave-backup \
xtrabackup --backup --lock-ddl=OFF --slave-info --safe-slave-backup \
--stream=xbstream | xbstream -xv -C $topdir/xbstream_backup

cat $topdir/xbstream_backup/xtrabackup_slave_info
Expand Down Expand Up @@ -165,7 +171,7 @@ setup_slave GTID $slave2_id $master_id
mysql -e "SET GLOBAL general_log=1; SET GLOBAL log_output='TABLE';"

vlog "Full backup of the GTID with AUTO_POSITION slave server"
xtrabackup --backup --lock-ddl=false --slave-info --target-dir=$topdir/backup
xtrabackup --backup --lock-ddl=OFF --slave-info --target-dir=$topdir/backup

grep_general_log > $topdir/log3

Expand Down Expand Up @@ -196,7 +202,7 @@ start_server_with_id $slave3_id
setup_slave $slave3_id $master_id

vlog "Full backup of the GTID slave server"
xtrabackup --backup --lock-ddl=false --slave-info --target-dir=$topdir/backup
xtrabackup --backup --lock-ddl=OFF --slave-info --target-dir=$topdir/backup

run_cmd egrep -q "$binlog_slave_info_pattern" \
$topdir/backup/xtrabackup_slave_info
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ mkdir $topdir/backup

# Test 1 - should fail since we don't have any entry on keyring file yet
vlog "Test 1 - Should fail as keyring file does not have encryption information"
run_cmd_expect_failure $XB_BIN $XB_ARGS --innodb-log-file-size=80M --xtrabackup-plugin-dir=${plugin_dir} --lock-ddl=false --backup \
run_cmd_expect_failure $XB_BIN $XB_ARGS --innodb-log-file-size=80M --xtrabackup-plugin-dir=${plugin_dir} --lock-ddl=OFF --backup \
--target-dir=$topdir/backup --debug-sync="xtrabackup_pause_after_redo_catchup" 2> >(tee $topdir/backup.log)&

job_pid=$!
Expand Down Expand Up @@ -79,7 +79,7 @@ $MYSQL $MYSQL_ARGS -Ns -e "DROP TABLE tmp1" sakila
innodb_wait_for_flush_all


run_cmd $XB_BIN $XB_ARGS --innodb-log-file-size=80M --xtrabackup-plugin-dir=${plugin_dir} --lock-ddl=false --backup \
run_cmd $XB_BIN $XB_ARGS --innodb-log-file-size=80M --xtrabackup-plugin-dir=${plugin_dir} --lock-ddl=OFF --backup \
--target-dir=$topdir/backup --debug-sync="xtrabackup_pause_after_redo_catchup" &

job_pid=$!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ mysql -e "INSERT INTO t SELECT * FROM t" test
mysql -e "ALTER TABLE t ROW_FORMAT=REDUNDANT;" test
done ) >/dev/null 2>/dev/null &

xtrabackup --lock-ddl --backup --target-dir=$topdir/backup \
xtrabackup --backup --target-dir=$topdir/backup \
--xtrabackup-plugin-dir=${plugin_dir} ${keyring_args}

xtrabackup --prepare --target-dir=$topdir/backup \
Expand Down
4 changes: 2 additions & 2 deletions storage/innobase/xtrabackup/test/suites/keyring/rollback.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ trap "kill_bg_trx $uncommitted_trx" EXIT
wait_for_bg_trx

vlog "Backup"
xtrabackup --lock-ddl --backup --target-dir=$topdir/backup \
xtrabackup --backup --target-dir=$topdir/backup \
--xtrabackup-plugin-dir=${plugin_dir} ${keyring_args}

kill_bg_trx $uncommitted_trx
Expand Down Expand Up @@ -66,7 +66,7 @@ vlog "Test 2: No rollback on encrypted table. Lack of keyring shouldn't fail the

vlog "Backup"
rm -rf $topdir/backup
xtrabackup --lock-ddl --backup --target-dir=$topdir/backup \
xtrabackup --backup --target-dir=$topdir/backup \
--xtrabackup-plugin-dir=${plugin_dir} ${keyring_args}

vlog "Record db state"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@

. inc/common.sh

require_debug_pxb_version
require_debug_server

function run_test() {
ALL_TABLES_IN_BACKUP=$1
INSTANT=$2

vlog "Running test with ALL_TABLES_IN_BACKUP=$ALL_TABLES_IN_BACKUP and INSTANT=$INSTANT"

start_server
if [ "$ALL_TABLES_IN_BACKUP" = "false" ]; then
$MYSQL $MYSQL_ARGS -Ns -e "SET GLOBAL innodb_checkpoint_disabled=true;"
fi
$MYSQL $MYSQL_ARGS -Ns -e "CREATE TABLE test.keep (id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(50)); INSERT INTO test.keep VALUES(1, 'a'), (2, 'b');" test
$MYSQL $MYSQL_ARGS -Ns -e "CREATE TABLE test.rename (id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(50)); INSERT INTO test.rename VALUES(1, 'a'), (2, 'b');" test
$MYSQL $MYSQL_ARGS -Ns -e "CREATE TABLE test.drop (id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(50)); INSERT INTO test.drop VALUES(1, 'a'), (2, 'b');" test
$MYSQL $MYSQL_ARGS -Ns -e "CREATE TABLE test.default_val (id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(50)); INSERT INTO test.default_val VALUES(1, 'a'), (2, 'b');" test


if [ "$ALL_TABLES_IN_BACKUP" = "true" ]; then
innodb_wait_for_flush_all
fi


xtrabackup --backup --target-dir=$topdir/backup_add_column \
--debug-sync="ddl_tracker_before_lock_ddl" --lock-ddl=REDUCED \
2> >( tee $topdir/backup_with_add_column.log)&

job_pid=$!
pid_file=$topdir/backup_add_column/xtrabackup_debug_sync
wait_for_xb_to_suspend $pid_file
xb_pid=`cat $pid_file`
echo "backup pid is $job_pid"

# change default value and generate redo
QUERY="ALTER TABLE test.default_val ALTER COLUMN name SET DEFAULT 'no-name', ALGORITHM="
if [ "$INSTANT" = "true" ]; then
QUERY+="INSTANT"
else
QUERY+="INPLACE"
fi

$MYSQL $MYSQL_ARGS -Ns -e "${QUERY} ; INSERT INTO test.default_val VALUES (3, 'c'), (4, 'd');" test

# Add new column to table and generate redo
QUERY="ALTER TABLE test.keep ADD COLUMN new_col VARCHAR(50) AFTER id, ALGORITHM="
if [ "$INSTANT" = "true" ]; then
QUERY+="INSTANT"
else
QUERY+="INPLACE"
fi

$MYSQL $MYSQL_ARGS -Ns -e "${QUERY} ; INSERT INTO test.keep VALUES (3, 'col', 'c'), (4, 'col', 'd');" test

# Add new column to table, generate redo, rename the table and generate redo
QUERY="ALTER TABLE test.rename ADD COLUMN new_col VARCHAR(50) AFTER id, ALGORITHM="
if [ "$INSTANT" = "true" ]; then
QUERY+="INSTANT"
else
QUERY+="INPLACE"
fi

$MYSQL $MYSQL_ARGS -Ns -e "${QUERY} ; INSERT INTO test.rename VALUES (3, 'col', 'c'), (4, 'col', 'd');" test
$MYSQL $MYSQL_ARGS -Ns -e "RENAME TABLE test.rename TO test.after_rename; INSERT INTO test.after_rename VALUES (5, 'col', 'e'), (6, 'col', 'f');" test

# Add new column to table, generate redo, drop the table
QUERY="ALTER TABLE test.drop ADD COLUMN new_col VARCHAR(50) AFTER id, ALGORITHM="
if [ "$INSTANT" = "true" ]; then
QUERY+="INSTANT"
else
QUERY+="INPLACE"
fi
$MYSQL $MYSQL_ARGS -Ns -e "${QUERY} ; INSERT INTO test.drop VALUES (3, 'col', 'c'), (4, 'col', 'd'); DROP TABLE test.drop;" test

# Create table, generate redo and add column
QUERY="CREATE TABLE test.new (id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(50)); INSERT INTO test.new VALUES(1, 'a'), (2, 'b'); ALTER TABLE test.new ADD COLUMN new_col VARCHAR(50) AFTER id, ALGORITHM="
if [ "$INSTANT" = "true" ]; then
QUERY+="INSTANT"
else
QUERY+="INPLACE"
fi
$MYSQL $MYSQL_ARGS -Ns -e "${QUERY} ; INSERT INTO test.new VALUES (3, 'col', 'c'), (4, 'col', 'd');" test

# Resume the xtrabackup process
vlog "Resuming xtrabackup"
kill -SIGCONT $xb_pid
run_cmd wait $job_pid

xtrabackup --prepare --target-dir=$topdir/backup_add_column
record_db_state test
stop_server
rm -rf $mysql_datadir/*
xtrabackup --copy-back --target-dir=$topdir/backup_add_column
start_server
verify_db_state test

stop_server
rm -rf $mysql_datadir $topdir/backup_with_add_column.log $topdir/backup_add_column
}


# Run test with all tables in backup and algortihm inplace
run_test true false

# Run test with all tables in backup and algortihm instant
run_test true true

# Run test with all tables in redo and algortihm inplace
run_test false false

# Run test with all tables in redo and algortihm instant
run_test false true

Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@

. inc/common.sh

require_debug_pxb_version
require_debug_server

function run_test() {
ALL_TABLES_IN_BACKUP=$1
vlog "Running test with ALL_TABLES_IN_BACKUP=$ALL_TABLES_IN_BACKUP"

start_server
if [ "$ALL_TABLES_IN_BACKUP" = "false" ]; then
$MYSQL $MYSQL_ARGS -Ns -e "SET GLOBAL innodb_checkpoint_disabled=true;"
fi
$MYSQL $MYSQL_ARGS -Ns -e "CREATE TABLE test.secondary_idx_keep (id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(50)); INSERT INTO test.secondary_idx_keep VALUES(1, 'a'), (2, 'b');" test
$MYSQL $MYSQL_ARGS -Ns -e "CREATE TABLE test.secondary_idx_rename (id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(50)); INSERT INTO test.secondary_idx_rename VALUES(1, 'a'), (2, 'b');" test
$MYSQL $MYSQL_ARGS -Ns -e "CREATE TABLE test.secondary_idx_drop (id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(50)); INSERT INTO test.secondary_idx_drop VALUES(1, 'a'), (2, 'b');" test

if [ "$ALL_TABLES_IN_BACKUP" = "true" ]; then
innodb_wait_for_flush_all
fi


xtrabackup --backup --target-dir=$topdir/backup_optimized_ddl \
--debug-sync="ddl_tracker_before_lock_ddl" --lock-ddl=REDUCED \
2> >( tee $topdir/backup_with_optimized_ddl.log)&

job_pid=$!
pid_file=$topdir/backup_optimized_ddl/xtrabackup_debug_sync
wait_for_xb_to_suspend $pid_file
xb_pid=`cat $pid_file`
echo "backup pid is $job_pid"

# Add secondary index
$MYSQL $MYSQL_ARGS -Ns -e "ALTER TABLE test.secondary_idx_keep ADD INDEX(name);" test

# Add secondary index and rename table
$MYSQL $MYSQL_ARGS -Ns -e "ALTER TABLE test.secondary_idx_rename ADD INDEX(name); RENAME TABLE test.secondary_idx_rename TO test.secondary_idx_after_rename" test

# Add secondary index and drop table
$MYSQL $MYSQL_ARGS -Ns -e "ALTER TABLE test.secondary_idx_drop ADD INDEX(name); DROP TABLE test.secondary_idx_drop;" test

# Create table and generate redo
$MYSQL $MYSQL_ARGS -Ns -e "CREATE TABLE test.secondary_idx_new (id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(50)); INSERT INTO test.secondary_idx_new VALUES(1, 'a'), (2, 'b'); ALTER TABLE test.secondary_idx_new ADD INDEX(name);" test

# Resume the xtrabackup process
vlog "Resuming xtrabackup"
kill -SIGCONT $xb_pid
run_cmd wait $job_pid

original_keep_table_row_count=`$MYSQL $MYSQL_ARGS -Ns -e "SELECT COUNT(*) FROM test.secondary_idx_keep FORCE INDEX(name);" | awk {'print $1'}`
original_rename_table_row_count=`$MYSQL $MYSQL_ARGS -Ns -e "SELECT COUNT(*) FROM test.secondary_idx_after_rename FORCE INDEX(name);" | awk {'print $1'}`
xtrabackup --prepare --target-dir=$topdir/backup_optimized_ddl
record_db_state test
stop_server
rm -rf $mysql_datadir/*
xtrabackup --copy-back --target-dir=$topdir/backup_optimized_ddl
start_server
verify_db_state test
restored_keep_table_row_count=`$MYSQL $MYSQL_ARGS -Ns -e "SELECT COUNT(*) FROM test.secondary_idx_keep FORCE INDEX(name);" | awk {'print $1'}`
restored_rename_table_row_count=`$MYSQL $MYSQL_ARGS -Ns -e "SELECT COUNT(*) FROM test.secondary_idx_after_rename FORCE INDEX(name);" | awk {'print $1'}`

if [ "$original_keep_table_row_count" != "$restored_keep_table_row_count" ]; then
die "rows in table secondary_idx_keep is $restored_keep_table_row_count when it should be $original_keep_table_row_count"
fi

if [ "$original_rename_table_row_count" != "$restored_rename_table_row_count" ]; then
die "rows in table secondary_idx_after_rename is $restored_rename_table_row_count when it should be $original_rename_table_row_count"
fi
stop_server
rm -rf $mysql_datadir $topdir/backup_with_optimized_ddl.log $topdir/backup_optimized_ddl
}


# Run test with all tables in backup
run_test true

# Run test ensure DDL for create tables are part of redo log entries
run_test false
Loading

0 comments on commit 3c89fe3

Please sign in to comment.