-
Notifications
You must be signed in to change notification settings - Fork 2
/
fix-binlog-conflict.sh
executable file
·51 lines (43 loc) · 1.1 KB
/
fix-binlog-conflict.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/sh
port=$1
cmd="/usr/local/mysql-5.7.13/bin/mysql -S /var/run/mysqld/mysqld-$port.sock"
get_binlog_error()
{
# 1032: delete-row fails
$cmd -Ns -e 'SELECT LAST_SEEN_TRANSACTION FROM performance_schema.replication_applier_status_by_worker WHERE LAST_ERROR_NUMBER = 1032 limit 1;'
}
while ``; do
for i in $(seq 20); do
gtid="$(get_binlog_error)"
if [ -n "$gtid" ]; then
echo found error gtid: $gtid
break
else
sleep 0.1
fi
done
if [ -z "$gtid" ]; then
# replication_applier_status_by_worker sometimes does not report error occured while applying binlog
# re-setup replication fixes it.
echo "re-setup replication to find more error"
./mysqlops.py --cmd setup_replication --ports $port
sleep 3
gtid="$(get_binlog_error)"
if [ -z "$gtid" ]; then
echo "no error found"
exit 0
else
continue
fi
fi
{
cat <<END
STOP SLAVE;
SET GTID_NEXT='$gtid';
BEGIN;
COMMIT;
SET GTID_NEXT='AUTOMATIC';
START SLAVE;
END
} | $cmd
done