Skip to content

Commit c7423cd

Browse files
committed
address feedback
1 parent 7f7e11c commit c7423cd

7 files changed

Lines changed: 75 additions & 13 deletions

File tree

go/logic/migrator.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,7 +1386,7 @@ func (mgtr *Migrator) moveTablesCutOver() (err error) {
13861386
}
13871387
}
13881388

1389-
mgtr.migrationContext.NewFailPoint("panic-before-drain-completion", base.WithFailPointWait(2*time.Second))
1389+
mgtr.migrationContext.NewFailPoint("move-tables-panic-before-drain-completion", base.WithFailPointWait(2*time.Second))
13901390

13911391
// ------ T3: draining applier to drain GTID -----------
13921392
if err := mgtr.drainMoveTablesCutOver(drainGTID); err != nil {
@@ -1406,7 +1406,7 @@ func (mgtr *Migrator) moveTablesCutOver() (err error) {
14061406
atomic.StoreInt64(&mgtr.migrationContext.CutOverCompleteFlag, 1)
14071407
mgtr.migrationContext.Log.Debugf("T4: CutOverCompleteFlag set")
14081408

1409-
mgtr.migrationContext.NewFailPoint("panic-before-on-success-hook", base.WithFailPointWait(2*time.Second))
1409+
mgtr.migrationContext.NewFailPoint("move-tables-panic-before-on-success-hook", base.WithFailPointWait(2*time.Second))
14101410

14111411
// ----- T5: on-success hook -----
14121412
// Hook unlocks user_rw@target via db-user-management and flips the
@@ -2515,7 +2515,7 @@ func (mgtr *Migrator) iterateChunks() error {
25152515
return terminateRowIteration(err)
25162516
}
25172517

2518-
mgtr.migrationContext.NewFailPoint("panic-after-row-copy", base.WithFailPointWait(2*time.Second))
2518+
mgtr.migrationContext.NewFailPoint("move-tables-panic-after-row-copy", base.WithFailPointWait(2*time.Second))
25192519
}
25202520
}
25212521

localtests/move-tables/resume-panic-before-drain-complete/test.sh

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ build_binary
2121
echo "⚙️ Starting migration with failpoint (run #1)..."
2222

2323
# Build the gh-ost command using the framework function
24-
GO_FAILPOINTS="github.com/github/gh-ost/go/base/panic-before-drain-completion=return(true)" build_ghost_command
24+
GO_FAILPOINTS="github.com/github/gh-ost/go/base/move-tables-panic-before-drain-completion=return(true)" build_ghost_command
2525

2626
# queue up removal of the postpone cutover flag, otherwise gh-ost hangs on the cutover
2727
(
@@ -76,6 +76,19 @@ if [ $? -gt 0 ]; then
7676
return 1
7777
fi
7878

79+
# validate last checkpoint (cutover started and drain GTID are set)
80+
cutover_started=$(mysql-exec target primary $database -Ne "SELECT gh_ost_move_tables_cutover_started FROM _${table_name}_ghk ORDER BY gh_ost_chk_id DESC LIMIT 1;")
81+
if [ "$cutover_started" != 1 ]; then
82+
echo "ERROR: Expected cutover started to be set in last checkpoint."
83+
return 1
84+
fi
85+
86+
drain_gtid=$(mysql-exec target primary $database -Ne "SELECT gh_ost_move_tables_drain_gtid FROM _${table_name}_ghk ORDER BY gh_ost_chk_id DESC LIMIT 1;")
87+
if [ "$drain_gtid" == "" ]; then
88+
echo "ERROR: Expected drain GTID to be set in last checkpoint."
89+
return 1
90+
fi
91+
7992
echo "✅ Validated checkpointed state on unexpected exit..."
8093

8194
echo -e "\n\n\n\n\n"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
# touch file to mark completion of on-success hook
4+
touch /tmp/gh-ost-hooks/on-success

localtests/move-tables/resume-panic-before-on-success-hook/test.sh

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,23 @@ table_name=gh_ost_test
1313
rm $ghost_binary
1414
build_binary
1515

16+
# ensure hook files are executable
17+
chmod +x $tests_path/$test_name/hooks/*
18+
19+
# clean up any existing test hook files
20+
rm -rf /tmp/gh-ost-hooks/
21+
mkdir -p /tmp/gh-ost-hooks/
22+
1623
######################################################################################################
1724
### Run #1: Should panic after drain (T4) and before on-success (T5)
1825
######################################################################################################
1926

27+
2028
echo "⚙️ Starting migration with failpoint (run #1)..."
2129

2230
# Build the gh-ost command using the framework function
23-
GO_FAILPOINTS="github.com/github/gh-ost/go/base/panic-before-on-success-hook=return(true)" build_ghost_command
31+
GO_FAILPOINTS="github.com/github/gh-ost/go/base/move-tables-panic-before-on-success-hook=return(true)" build_ghost_command
32+
cmd="$cmd --hooks-path=$tests_path/$test_name/hooks"
2433

2534
# queue up removal of the postpone cutover flag, otherwise gh-ost hangs on the cutover
2635
(
@@ -84,8 +93,8 @@ if [ $? -gt 0 ]; then
8493
fi
8594

8695
# contents of table on source and target are the same
87-
source_contents_file=/tmp/gh-ost-test.resume-panic-before-on-success-hook-source_contents.txt
88-
target_contents_file=/tmp/gh-ost-test.resume-panic-before-on-success-hook-target_contents.txt
96+
source_contents_file=/tmp/gh-ost-test.resume-move-tables-panic-before-on-success-hook-source_contents.txt
97+
target_contents_file=/tmp/gh-ost-test.resume-move-tables-panic-before-on-success-hook-target_contents.txt
8998
mysql-exec source primary $database -sNe "SELECT * FROM _${table_name}_del;" > $source_contents_file
9099
mysql-exec target primary $database -sNe "SELECT * FROM ${table_name};" > $target_contents_file
91100

@@ -97,6 +106,12 @@ if ! diff $source_contents_file $target_contents_file; then
97106
return 1
98107
fi
99108

109+
# validate on-success hook was not called
110+
if [ -f /tmp/gh-ost-hooks/on-success ]; then
111+
echo "ERROR: on-success hook was called when it should not have been."
112+
return 1
113+
fi
114+
100115
echo "✅ Validated checkpointed state on unexpected exit..."
101116

102117
echo -e "\n\n\n\n\n"
@@ -109,7 +124,7 @@ echo "⚙️ Resuming migration (run #2)..."
109124

110125
# resume migration
111126
build_ghost_command
112-
cmd="$cmd --resume"
127+
cmd="$cmd --resume --hooks-path=$tests_path/$test_name/hooks"
113128

114129
# queue up removal of the postpone cutover flag, otherwise gh-ost hangs on the cutover
115130
(
@@ -126,4 +141,9 @@ if [ $ghost_result -ne 0 ]; then
126141
return 1
127142
fi
128143

144+
# validate on-success hook was was called
145+
if [ ! -f /tmp/gh-ost-hooks/on-success ]; then
146+
echo "ERROR: on-success hook was not called when it should have been."
147+
fi
148+
129149
echo -e "\n\n\n\n\n"

localtests/move-tables/resume-panic-on-row-copy/test.sh

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ build_binary
1818
echo "⚙️ Starting migration with failpoint (run #1)..."
1919

2020
# Build the gh-ost command using the framework function
21-
GO_FAILPOINTS="github.com/github/gh-ost/go/base/panic-after-row-copy=return(true)" build_ghost_command
21+
GO_FAILPOINTS="github.com/github/gh-ost/go/base/move-tables-panic-after-row-copy=return(true)" build_ghost_command
2222

2323
# Run the gh-ost command, expecting panic on the failpoint the first time
2424
echo_dot
@@ -39,10 +39,10 @@ echo -e "\n\n\n\n\n"
3939

4040
echo "⚙️ Validating checkpointed state on unexpected exit..."
4141

42-
# checkpoint file exists on target and is non-empty
42+
# checkpoint table exists on target and is non-empty
4343
mysql-exec target primary $database -sNe "SELECT 1 FROM _${table_name}_ghk LIMIT 1;"
4444
if [ $? -gt 0 ]; then
45-
echo "ERROR: Checkpoint file is empty or does not exist."
45+
echo "ERROR: Checkpoint table is empty or does not exist."
4646
return 1
4747
fi
4848

@@ -60,6 +60,13 @@ if [ $? -gt 0 ]; then
6060
return 1
6161
fi
6262

63+
# validate we processed a single row-copy chunk (10 rows) and there are 20 total to process
64+
rows_copied=$(mysql-exec target primary $database -Ne "SELECT gh_ost_rows_copied FROM _${table_name}_ghk ORDER BY gh_ost_chk_id DESC LIMIT 1;")
65+
if [ $rows_copied -ne 10 ]; then
66+
echo "ERROR: Expected last checkpoint to show 10 rows copied."
67+
return 1
68+
fi
69+
6370
echo "✅ Validating checkpointed state on unexpected exit..."
6471

6572
echo -e "\n\n\n\n\n"
@@ -90,3 +97,21 @@ if [ $ghost_result -ne 0 ]; then
9097
fi
9198

9299
echo -e "\n\n\n\n\n"
100+
101+
######################################################################################################
102+
### post-migration validation
103+
######################################################################################################
104+
105+
echo "⚙️ Validating checkpointed state after resumed migration..."
106+
107+
# validate we processed a single row-copy chunk (10 rows) and there are 20 total to process
108+
rows_copied=$(mysql-exec target primary $database -Ne "SELECT gh_ost_rows_copied FROM _${table_name}_ghk ORDER BY gh_ost_chk_id DESC LIMIT 1;")
109+
if [ $rows_copied -ne 20 ]; then
110+
echo "ERROR: Expected last checkpoint to show 20 rows copied."
111+
return 1
112+
fi
113+
114+
echo "✅ Validating checkpointed state on resumed migration."
115+
116+
echo -e "\n\n\n\n\n"
117+

localtests/move-tables/single-with-hooks/hooks/gh-ost-on-before-cut-over

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ set -e
1010

1111
assert_common_envs
1212

13-
# touch file to mark completion of on-row-copy-complete hook
13+
# touch file to mark completion of on-before-cut-over hook
1414
touch /tmp/gh-ost-hooks/on-before-cut-over

localtests/move-tables/single-with-hooks/hooks/gh-ost-on-success

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ assert_common_envs
1212

1313
assert_env_present "GH_OST_DRAIN_GTID"
1414

15-
# touch file to mark completion of on-row-copy-complete hook
15+
# touch file to mark completion of on-success hook
1616
touch /tmp/gh-ost-hooks/on-success

0 commit comments

Comments
 (0)