Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
Signed-off-by: Wenqi Mou <[email protected]>
  • Loading branch information
Tristan1900 committed Jan 21, 2025
1 parent 6180fb7 commit de2100f
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 2 deletions.
73 changes: 73 additions & 0 deletions br/tests/br_pitr/check/check_key_types.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/bin/sh

echo "=== Verifying Data Integrity ==="

# Verify original table key data is intact
run_sql "SELECT COUNT(*) as cnt FROM key_types_test.table_key_test;"
check_contains "cnt: 4"
run_sql "SELECT id, name, value FROM key_types_test.table_key_test ORDER BY id;"
check_contains "id: 1"
check_contains "name: test1"
check_contains "value: 100"
check_contains "id: 2"
check_contains "name: test2"
check_contains "value: 200"
check_contains "id: 3"
check_contains "name: test3"
check_contains "value: 300"

# Verify new table key data
run_sql "SELECT COUNT(*) as cnt FROM key_types_test.table_key_test2;"
check_contains "cnt: 1"
run_sql "SELECT id, name, value FROM key_types_test.table_key_test2 ORDER BY id;"
check_contains "id: 1"
check_contains "name: test1"
check_contains "value: 100"

# Verify original auto increment data
run_sql "SELECT COUNT(*) as cnt FROM key_types_test.auto_inc_test;"
check_contains "cnt: 4"
run_sql "SELECT id FROM key_types_test.auto_inc_test ORDER BY id;"
check_contains "id: 1"
check_contains "id: 2"
check_contains "id: 3"
check_contains "id: 4"

# Verify new auto increment data
run_sql "SELECT COUNT(*) as cnt FROM key_types_test.auto_inc_test2;"
check_contains "cnt: 2"
run_sql "SELECT id FROM key_types_test.auto_inc_test2 ORDER BY id;"
check_contains "id: 1"
check_contains "id: 2"

# Verify original sequence data
run_sql "SELECT COUNT(*) as cnt FROM key_types_test.sequence_test;"
check_contains "cnt: 4"
run_sql "SELECT id FROM key_types_test.sequence_test ORDER BY id;"
check_contains "id: 1"
check_contains "id: 3"
check_contains "id: 5"
check_contains "id: 7"

# Verify new sequence data
run_sql "SELECT COUNT(*) as cnt FROM key_types_test.sequence_test2;"
check_contains "cnt: 2"
run_sql "SELECT id FROM key_types_test.sequence_test2 ORDER BY id;"
check_contains "id: 1"
check_contains "id: 3"

# Verify original auto random data
run_sql "SELECT COUNT(*) as cnt FROM key_types_test.auto_random_test;"
check_contains "cnt: 4"
run_sql "SELECT name FROM key_types_test.auto_random_test ORDER BY id;"
check_contains "name: rand1"
check_contains "name: rand2"
check_contains "name: rand3"
check_contains "name: random4"

# Verify new auto random data
run_sql "SELECT COUNT(*) as cnt FROM key_types_test.auto_random_test2;"
check_contains "cnt: 2"
run_sql "SELECT name FROM key_types_test.auto_random_test2 ORDER BY id;"
check_contains "name: rand1"
check_contains "name: rand2"
38 changes: 38 additions & 0 deletions br/tests/br_pitr/incremental_data/key_types.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
-- incremental changes to test during log backup

-- test existing tables
INSERT INTO key_types_test.table_key_test VALUES (3, 'test3', 300);
INSERT INTO key_types_test.auto_inc_test (name) VALUES ('auto4');
INSERT INTO key_types_test.sequence_test (name) VALUES ('seq4');
INSERT INTO key_types_test.auto_random_test (name) VALUES ('random4');

-- Create new tables during log backup to test table creation with special keys
-- 1. New table with regular key
CREATE TABLE key_types_test.table_key_test2 (
id INT PRIMARY KEY NONCLUSTERED,
name VARCHAR(255),
value INT
);
INSERT INTO key_types_test.table_key_test2 VALUES (1, 'test1', 100);

-- 2. New table with auto increment
CREATE TABLE key_types_test.auto_inc_test2 (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(255)
);
INSERT INTO key_types_test.auto_inc_test2 (name) VALUES ('auto1'), ('auto2');

-- 3. New sequence and table using it
CREATE SEQUENCE key_types_test.seq2 START WITH 1 INCREMENT BY 2 NOCACHE;
CREATE TABLE key_types_test.sequence_test2 (
id INT PRIMARY KEY DEFAULT NEXT VALUE FOR key_types_test.seq2,
name VARCHAR(255)
);
INSERT INTO key_types_test.sequence_test2 (name) VALUES ('seq1'), ('seq2');

-- 4. New table with auto random
CREATE TABLE key_types_test.auto_random_test2 (
id BIGINT PRIMARY KEY AUTO_RANDOM(5),
name VARCHAR(255)
);
INSERT INTO key_types_test.auto_random_test2 (name) VALUES ('rand1'), ('rand2');
33 changes: 33 additions & 0 deletions br/tests/br_pitr/prepare_data/key_types.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
-- Test cases for different key types during PITR restore

-- 1. regular table key
CREATE DATABASE IF NOT EXISTS key_types_test;
CREATE TABLE key_types_test.table_key_test (
id INT PRIMARY KEY NONCLUSTERED,
name VARCHAR(255),
value INT
);
INSERT INTO key_types_test.table_key_test VALUES (1, 'test1', 100), (2, 'test2', 200);

-- 2. auto Increment ID Key Test
CREATE TABLE key_types_test.auto_inc_test (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(255)
);

INSERT INTO key_types_test.auto_inc_test (name) VALUES ('auto1'), ('auto2'), ('auto3');

-- 3. sequence Key Test
CREATE SEQUENCE key_types_test.seq1 START WITH 1 INCREMENT BY 2 NOCACHE;
CREATE TABLE key_types_test.sequence_test (
id INT PRIMARY KEY DEFAULT NEXT VALUE FOR key_types_test.seq1,
name VARCHAR(255)
);
INSERT INTO key_types_test.sequence_test (name) VALUES ('seq1'), ('seq2'), ('seq3');

-- 4. auto Random Table ID Key Test
CREATE TABLE key_types_test.auto_random_test (
id BIGINT PRIMARY KEY AUTO_RANDOM(5),
name VARCHAR(255)
);
INSERT INTO key_types_test.auto_random_test (name) VALUES ('rand1'), ('rand2'), ('rand3');
8 changes: 6 additions & 2 deletions br/tests/br_pitr/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ restart_services_allowing_huge_index
echo "prepare the data"
run_sql_file $CUR/prepare_data/delete_range.sql
run_sql_file $CUR/prepare_data/ingest_repair.sql
# ...
run_sql_file $CUR/prepare_data/key_types.sql

# check something after prepare the data
prepare_delete_range_count=$(run_sql "select count(*) DELETE_RANGE_CNT from (select * from mysql.gc_delete_range union all select * from mysql.gc_delete_range_done) del_range;" | tail -n 1 | awk '{print $2}')
Expand Down Expand Up @@ -65,7 +65,7 @@ run_br --pd $PD_ADDR backup full -s "local://$TEST_DIR/$PREFIX/inc" --lastbackup
echo "load the incremental data"
run_sql_file $CUR/incremental_data/delete_range.sql
run_sql_file $CUR/incremental_data/ingest_repair.sql
# ...
run_sql_file $CUR/incremental_data/key_types.sql

# run incremental snapshot backup, but this incremental backup will fail to restore. due to limitation of ddl.
echo "run incremental backup with special ddl jobs, modify column e.g."
Expand Down Expand Up @@ -95,6 +95,8 @@ check_result() {
check_contains "DELETE_RANGE_CNT: $expect_delete_range"
## check feature compatibility between PITR and accelerate indexing
bash $CUR/check/check_ingest_repair.sh
# check key types are restored correctly
bash $CUR/check/check_key_types.sh
}

# start a new cluster
Expand Down Expand Up @@ -191,3 +193,5 @@ if [ $restore_fail -ne 1 ]; then
echo 'pitr success on file lost'
exit 1
fi

echo "br pitr test passed"

0 comments on commit de2100f

Please sign in to comment.