Skip to content

Commit 288f0a8

Browse files
committed
5. single-with-hooks
1 parent 4d61e5d commit 288f0a8

7 files changed

Lines changed: 187 additions & 0 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
drop table if exists gh_ost_test;
2+
create table gh_ost_test (
3+
id bigint(20) NOT NULL AUTO_INCREMENT,
4+
column1 int(11) NOT NULL,
5+
column2 smallint(5) unsigned NOT NULL,
6+
column3 mediumint(8) unsigned NOT NULL,
7+
column4 tinyint(3) unsigned NOT NULL,
8+
column5 int(11) NOT NULL,
9+
column6 int(11) NOT NULL,
10+
PRIMARY KEY (id),
11+
KEY c12_ix (column1, column2)
12+
) auto_increment=1;
13+
14+
insert into gh_ost_test values
15+
(NULL, 1001, 100, 500000, 10, 1700000001, 1700000002),
16+
(NULL, 1002, 200, 600000, 20, 1700000003, 1700000004),
17+
(NULL, 1003, 300, 700000, 30, 1700000005, 1700000006),
18+
(NULL, 1004, 400, 800000, 40, 1700000007, 1700000008),
19+
(NULL, 1005, 500, 900000, 50, 1700000009, 1700000010),
20+
(NULL, 1006, 600, 1000000, 60, 1700000011, 1700000012),
21+
(NULL, 1007, 700, 1100000, 70, 1700000013, 1700000014),
22+
(NULL, 1008, 800, 1200000, 80, 1700000015, 1700000016),
23+
(NULL, 1009, 900, 1300000, 90, 1700000017, 1700000018),
24+
(NULL, 1010, 1000, 1400000, 100, 1700000019, 1700000020),
25+
(NULL, 1011, 1100, 1500000, 110, 1700000021, 1700000022),
26+
(NULL, 1012, 1200, 1600000, 120, 1700000023, 1700000024),
27+
(NULL, 1013, 1300, 1700000, 130, 1700000025, 1700000026),
28+
(NULL, 1014, 1400, 1800000, 140, 1700000027, 1700000028),
29+
(NULL, 1015, 1500, 1900000, 150, 1700000029, 1700000030),
30+
(NULL, 1016, 1600, 2000000, 160, 1700000031, 1700000032),
31+
(NULL, 1017, 1700, 2100000, 170, 1700000033, 1700000034),
32+
(NULL, 1018, 1800, 2200000, 180, 1700000035, 1700000036),
33+
(NULL, 1019, 1900, 2300000, 190, 1700000037, 1700000038),
34+
(NULL, 1020, 2000, 2400000, 200, 1700000039, 1700000040);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
repo_root=$(git rev-parse --show-toplevel)
4+
source $repo_root/localtests/move-tables/single-with-hooks/hooks/util.sh
5+
6+
# dump environment variables on dirty exit
7+
trap '[[ $? -eq 0 ]] || dump_env' EXIT
8+
9+
set -e
10+
11+
assert_common_envs
12+
13+
# touch file to mark completion of on-row-copy-complete hook
14+
touch /tmp/gh-ost-hooks/on-before-cut-over
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
repo_root=$(git rev-parse --show-toplevel)
4+
source $repo_root/localtests/move-tables/single-with-hooks/hooks/util.sh
5+
6+
# dump environment variables on dirty exit
7+
trap '[[ $? -eq 0 ]] || dump_env' EXIT
8+
9+
set -e
10+
11+
assert_common_envs
12+
13+
# touch file to mark completion of on-row-copy-complete hook
14+
touch /tmp/gh-ost-hooks/on-row-copy-complete
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
repo_root=$(git rev-parse --show-toplevel)
4+
source $repo_root/localtests/move-tables/single-with-hooks/hooks/util.sh
5+
6+
# dump environment variables on dirty exit
7+
trap '[[ $? -eq 0 ]] || dump_env' EXIT
8+
9+
set -e
10+
11+
assert_common_envs
12+
13+
assert_env_present "GH_OST_DRAIN_GTID"
14+
15+
# touch file to mark completion of on-row-copy-complete hook
16+
touch /tmp/gh-ost-hooks/on-success
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#/bin/bash
2+
3+
assert_env_equal() {
4+
env_name=$1
5+
expected=$2
6+
7+
if [ "${!env_name}" != "${expected}" ]; then
8+
echo "ERROR: Expected '${expected}' for ${env_name}, but got '${!env_name}'"
9+
exit 1
10+
fi
11+
}
12+
13+
assert_env_present() {
14+
env_name=$1
15+
16+
echo "checking '${env_name}=${!env_name}'"
17+
if [[ -z "${!env_name}" ]]; then
18+
echo "ERROR: Expected '${env_name}' to be set but not present"
19+
exit 1
20+
fi
21+
}
22+
23+
assert_common_envs() {
24+
assert_env_present "GH_OST_TARGET_HOST"
25+
26+
assert_env_equal "GH_OST_TARGET_DATABASE_NAME" "test"
27+
assert_env_equal "GH_OST_TABLE_NAME" "gh_ost_test"
28+
assert_env_equal "GH_OST_OLD_TABLE_NAME" "_gh_ost_test_del"
29+
assert_env_equal "GH_OST_TARGET_TABLE_NAME" "gh_ost_test"
30+
assert_env_equal "GH_OST_MOVE_TABLES" "true"
31+
assert_env_equal "GH_OST_REVERT" "false"
32+
}
33+
34+
dump_env() {
35+
echo "-----------------------------------------------------"
36+
echo "----------------- ENVIRONS --------------------------"
37+
echo "-----------------------------------------------------"
38+
env | grep "GH_OST_"
39+
echo "-----------------------------------------------------"
40+
echo "-----------------------------------------------------"
41+
echo "-----------------------------------------------------"
42+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
gh_ost_test
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
2+
#!/bin/bash
3+
# Custom test:
4+
# - panic during row copy stage, prior to cutover
5+
# - resume and complete the migration
6+
7+
database=test
8+
table_name=gh_ost_test
9+
10+
# Build gh-ost command from scratch using framework function
11+
build_binary
12+
13+
######################################################################################################
14+
### Run gh-ost with custom hooks neabled
15+
######################################################################################################
16+
17+
echo "⚙️ Running gh-ost with custom hooks..."
18+
19+
# ensure hook files are executable
20+
chmod +x $tests_path/$test_name/hooks/*
21+
22+
# clean up any existing test hook files
23+
rm -rf /tmp/gh-ost-hooks/
24+
mkdir -p /tmp/gh-ost-hooks/
25+
26+
# Build the gh-ost command using the framework function
27+
build_ghost_command
28+
cmd="$cmd --hooks-path=$tests_path/$test_name/hooks"
29+
30+
# queue up removal of the postpone cutover flag, otherwise gh-ost hangs on the cutover
31+
(
32+
sleep 2;
33+
echo "⏩ Sending unpostpone cutover"
34+
rm $postpone_cutover_flag_file &> /dev/null;
35+
) &
36+
37+
# Run the gh-ost command
38+
echo_dot
39+
echo > $test_logfile
40+
bash -c "$cmd" >>$test_logfile 2>&1
41+
ghost_result=$?
42+
43+
if [ $ghost_result -ne 0 ]; then
44+
echo "ERROR: gh-ost failed unexpectedly."
45+
return 1
46+
fi
47+
48+
echo "✅ gh-ost move-tables succeeded!"
49+
50+
echo -e "\n\n\n\n\n"
51+
52+
53+
######################################################################################################
54+
### Validate hook status
55+
######################################################################################################
56+
57+
echo "⚙️ Validating hook status after execution..."
58+
59+
for expected in on-row-copy-complete on-before-cut-over on-success; do
60+
if [ ! -f "/tmp/gh-ost-hooks/$expected" ]; then
61+
echo "ERROR: Expected test hook file '/tmp/gh-ost-hooks/$expected' was not found."
62+
return 1
63+
fi
64+
done
65+
66+
echo "✅ Hook status validated successfully."

0 commit comments

Comments
 (0)