Skip to content

Commit 3e65295

Browse files
authored
feat: create snapshot for MariaDB running in GTID mode (#320)
1 parent 85a560f commit 3e65295

File tree

4 files changed

+25
-15
lines changed

4 files changed

+25
-15
lines changed

devtools/replica-setup-mysql/checker.sh

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ check_server_params() {
1414

1515
# Retrieve the required MySQL server variables using mysqlsh
1616
result=$(mysqlsh --uri="$SOURCE_DSN" $SOURCE_PASSWORD_OPTION --sql -e "
17-
SHOW VARIABLES WHERE variable_name IN ('binlog_format', 'enforce_gtid_consistency', 'gtid_mode', 'gtid_strict_mode', 'log_bin');
17+
SHOW VARIABLES WHERE variable_name IN ('log_bin', 'binlog_format', 'gtid_mode', 'enforce_gtid_consistency', 'gtid_strict_mode', 'gtid_current_pos', 'gtid_executed');
1818
")
1919

2020
check_command "retrieving server parameters"
@@ -26,11 +26,19 @@ check_server_params() {
2626
fi
2727

2828
# Check for each parameter and validate their values
29+
log_bin=$(echo "$result" | grep -i "log_bin" | awk '{print $2}')
2930
binlog_format=$(echo "$result" | grep -i "binlog_format" | awk '{print $2}')
30-
enforce_gtid_consistency=$(echo "$result" | grep -i "enforce_gtid_consistency" | awk '{print $2}')
3131
gtid_mode=$(echo "$result" | grep -i "gtid_mode" | awk '{print $2}' | tr '[:lower:]' '[:upper:]')
32+
enforce_gtid_consistency=$(echo "$result" | grep -i "enforce_gtid_consistency" | awk '{print $2}')
3233
gtid_strict_mode=$(echo "$result" | grep -i "gtid_strict_mode" | awk '{print $2}' | tr '[:lower:]' '[:upper:]')
33-
log_bin=$(echo "$result" | grep -i "log_bin" | awk '{print $2}')
34+
gtid_current_pos=$(echo "$result" | grep -i "gtid_current_pos" | awk '{print $2}')
35+
gtid_executed=$(echo "$result" | grep -i "gtid_executed" | awk '{print $2}')
36+
37+
# Validate log_bin
38+
if [[ "$log_bin" != "ON" && "$log_bin" != "1" ]]; then
39+
echo "Error: log_bin is not enabled. Current value is '$log_bin'."
40+
return 1
41+
fi
3442

3543
# Validate binlog_format
3644
if [[ "$binlog_format" != "ROW" ]]; then
@@ -50,10 +58,12 @@ check_server_params() {
5058
return 1
5159
fi
5260

53-
# Validate log_bin
54-
if [[ "$log_bin" != "ON" && "$log_bin" != "1" ]]; then
55-
echo "Error: log_bin is not enabled. Current value is '$log_bin'."
56-
return 1
61+
# Set GTID_EXECUTED to either gtid_current_pos or gtid_executed
62+
if [[ -n "$gtid_strict_mode" ]]; then
63+
SOURCE_IS_MARIADB="true"
64+
GTID_EXECUTED="$gtid_current_pos"
65+
else
66+
GTID_EXECUTED="$gtid_executed"
5767
fi
5868

5969
echo "MySQL server parameters are correctly configured."

devtools/replica-setup-mysql/replica_setup.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ MYDUCK_USER=${MYDUCK_USER:-root}
1111
MYDUCK_PASSWORD=${MYDUCK_PASSWORD:-}
1212
MYDUCK_SERVER_ID=${MYDUCK_SERVER_ID:-2}
1313
GTID_MODE="ON"
14+
GTID_EXECUTED=""
15+
SOURCE_IS_MARIADB="false"
1416

1517
while [[ $# -gt 0 ]]; do
1618
case $1 in

devtools/replica-setup-mysql/snapshot.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ if [[ $GTID_MODE == "ON" ]]; then
5353
# Executed_GTID_set: 369107a6-a0a5-11ef-a255-0242ac110008:1-10
5454
EXECUTED_GTID_SET=$(echo "$output" | grep -i "EXECUTED_GTID_SET" | awk '{print $2}')
5555

56+
# If the source is MariaDB, we will get `Executed_GTID_set: ''`.
57+
# In this case, we will use GTID_EXECUTED instead.
58+
if [[ "$EXECUTED_GTID_SET" == "''" && "$SOURCE_IS_MARIADB" == "true" ]]; then
59+
EXECUTED_GTID_SET="$GTID_EXECUTED"
60+
fi
61+
5662
# Check if EXECUTED_GTID_SET is empty
5763
if [ -z "$EXECUTED_GTID_SET" ]; then
5864
echo "EXECUTED_GTID_SET is empty, exiting."

devtools/replica-setup-mysql/start_replication.sh

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@
33
# Detect OS platform (Linux or Darwin)
44
OS=$(uname -s)
55

6-
# if [[ $SOURCE_IS_EMPTY -eq 0 ]]; then
7-
# EXECUTED_GTID_SET=$(mysqlsh --host="$SOURCE_HOST" --user="$SOURCE_USER" --password="$SOURCE_PASSWORD" --sql -e "SHOW BINARY LOG STATUS\G" | grep -i "Executed_Gtid_Set" | awk -F': ' '{print $2}')
8-
# if [[ -z "$EXECUTED_GTID_SET" ]]; then
9-
# echo "Failed to get executed GTID set by statement 'SHOW BINARY LOG STATUS\G'. Trying to get it by statement 'SHOW MASTER STATUS\G'..."
10-
# EXECUTED_GTID_SET=$(mysqlsh --host="$SOURCE_HOST" --user="$SOURCE_USER" --password="$SOURCE_PASSWORD" --sql -e "SHOW MASTER STATUS\G" | grep -i "Executed_Gtid_Set" | awk -F': ' '{print $2}')
11-
# fi
12-
# fi
13-
146
# Use the EXECUTED_GTID_SET variable from the previous steps
157
if [ $GTID_MODE == "ON" ] && [ ! -z "$EXECUTED_GTID_SET" ]; then
168
mysqlsh --sql --host=${MYDUCK_HOST} --port=${MYDUCK_PORT} --user=${MYDUCK_USER} ${MYDUCK_PASSWORD_OPTION} <<EOF

0 commit comments

Comments
 (0)