|
| 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