Skip to content

Commit 5a2b02b

Browse files
committed
Add integration test for batch warnings
1 parent d20c72d commit 5a2b02b

4 files changed

Lines changed: 70 additions & 0 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
drop table if exists gh_ost_test;
2+
create table gh_ost_test (
3+
id int auto_increment,
4+
email varchar(255) not null,
5+
primary key (id)
6+
) auto_increment=1;
7+
8+
-- Insert initial data - all unique emails
9+
insert into gh_ost_test (email) values ('alice@example.com');
10+
insert into gh_ost_test (email) values ('bob@example.com');
11+
insert into gh_ost_test (email) values ('charlie@example.com');
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ERROR warnings detected in statement 1 of 2
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--default-retries=1 --panic-on-warnings --alter "add unique index email_idx(email)" --postpone-cut-over-flag-file=/tmp/gh-ost-test.postpone-cutover
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/bash
2+
# Custom test: inject batched DML events AFTER row copy completes
3+
# Tests that warnings in the middle of a DML batch are detected
4+
5+
# Create postpone flag file (referenced in extra_args)
6+
postpone_flag_file=/tmp/gh-ost-test.postpone-cutover
7+
touch $postpone_flag_file
8+
9+
# Set table names (required by build_ghost_command)
10+
table_name="gh_ost_test"
11+
ghost_table_name="_gh_ost_test_gho"
12+
13+
# Build gh-ost command using framework function
14+
build_ghost_command
15+
16+
# Run in background
17+
echo_dot
18+
echo > $test_logfile
19+
bash -c "$cmd" >>$test_logfile 2>&1 &
20+
ghost_pid=$!
21+
22+
# Wait for row copy to complete
23+
echo_dot
24+
for i in {1..30}; do
25+
grep -q "Row copy complete" $test_logfile && break
26+
ps -p $ghost_pid > /dev/null || { echo; echo "ERROR gh-ost exited early"; rm -f $postpone_flag_file; return 1; }
27+
sleep 1; echo_dot
28+
done
29+
30+
# Inject batched DML events that will create warnings
31+
# These must be in a single transaction to be batched during binlog replay
32+
echo_dot
33+
gh-ost-test-mysql-master test << 'EOF'
34+
BEGIN;
35+
-- INSERT with duplicate PRIMARY KEY - warning on migration key (filtered by gh-ost)
36+
INSERT IGNORE INTO gh_ost_test (id, email) VALUES (1, 'duplicate_pk@example.com');
37+
-- INSERT with duplicate email - warning on unique index (should trigger failure)
38+
INSERT IGNORE INTO gh_ost_test (email) VALUES ('alice@example.com');
39+
-- INSERT with unique data - would succeed if not for previous warning
40+
INSERT IGNORE INTO gh_ost_test (email) VALUES ('new@example.com');
41+
COMMIT;
42+
EOF
43+
44+
# Wait for binlog events to replicate and be applied
45+
sleep 10; echo_dot
46+
47+
# Complete cutover by removing postpone flag
48+
rm -f $postpone_flag_file
49+
50+
# Wait for gh-ost to complete
51+
wait $ghost_pid
52+
execution_result=$?
53+
rm -f $postpone_flag_file
54+
55+
# Validate using framework function
56+
validate_expected_failure
57+
return $?

0 commit comments

Comments
 (0)