@ -6,8 +6,8 @@ set -o pipefail
#
# The in-repo infra configures servers in hostgroup pairs like 1300/1301.
# The legacy test scripts (proxysql-tester.py benchmark) expect servers
# in hostgroups 0 and 1. This hook copies the first hostgroup pair into
# hostgroups 0/1 and remaps users/rules accordingly .
# in hostgroups 0 and 1. This hook moves everything from the original
# pair to 0/1 and removes the originals to avoid monitor conflicts .
#
export INFRA_ID = " ${ INFRA_ID :- dev - $USER } "
@ -15,43 +15,36 @@ PROXY_CONTAINER="proxysql.${INFRA_ID}"
MYSQL_CMD = " docker exec ${ PROXY_CONTAINER } mysql -uradmin -pradmin -h127.0.0.1 -P6032 -NB "
# Find the first writer/reader hostgroup pair from mysql_replication_hostgroups
PAIR = $( ${ MYSQL_CMD } -e "SELECT writer_hostgroup, reader_hostgroup FROM mysql_replication_hostgroups LIMIT 1;" 2>/dev/null)
# Find the first writer/reader hostgroup pair
PAIR = $( ${ MYSQL_CMD } -e "SELECT writer_hostgroup, reader_hostgroup FROM mysql_replication_hostgroups WHERE writer_hostgroup != 0 LIMIT 1;" 2>/dev/null)
if [ -z " ${ PAIR } " ] ; then
echo ">>> No replication hostgroups found. Skipping hostgroup alias ing."
echo ">>> No non-zero replication hostgroups found. Skipping."
exit 0
fi
WRITER_HG = $( echo " ${ PAIR } " | awk '{print $1}' )
READER_HG = $( echo " ${ PAIR } " | awk '{print $2}' )
if [ " ${ WRITER_HG } " = "0" ] && [ " ${ READER_HG } " = "1" ] ; then
echo ">>> Hostgroups already 0/1. Skipping aliasing."
exit 0
fi
echo " >>> Remapping hostgroup pair ${ WRITER_HG } / ${ READER_HG } -> 0/1 "
# Move servers: update hostgroup IDs in-place
${ MYSQL_CMD } -e " UPDATE mysql_servers SET hostgroup_id = 0 WHERE hostgroup_id = ${ WRITER_HG } ; "
${ MYSQL_CMD } -e " UPDATE mysql_servers SET hostgroup_id = 1 WHERE hostgroup_id = ${ READER_HG } ; "
echo " >>> Aliasing hostgroup pair ${ WRITER_HG } / ${ READER_HG } -> 0/1 "
# Copy servers from the original hostgroups into 0/1
${ MYSQL_CMD } -e "
INSERT OR IGNORE INTO mysql_servers ( hostgroup_id, hostname, port, max_connections, comment)
SELECT 0, hostname, port, max_connections, comment
FROM mysql_servers WHERE hostgroup_id = ${ WRITER_HG } ;
INSERT OR IGNORE INTO mysql_servers ( hostgroup_id, hostname, port, max_connections, comment)
SELECT 1, hostname, port, max_connections, comment
FROM mysql_servers WHERE hostgroup_id = ${ READER_HG } ;
INSERT OR IGNORE INTO mysql_replication_hostgroups ( writer_hostgroup, reader_hostgroup, comment)
VALUES ( 0, 1, 'basictests alias' ) ;
"
# Remap users, query rules, and replication hostgroups to 0/1
# Replace replication hostgroup mapping
${ MYSQL_CMD } -e " DELETE FROM mysql_replication_hostgroups WHERE writer_hostgroup = ${ WRITER_HG } ; "
${ MYSQL_CMD } -e "INSERT OR REPLACE INTO mysql_replication_hostgroups (writer_hostgroup, reader_hostgroup, comment) VALUES (0, 1, 'basictests');"
# Update users
${ MYSQL_CMD } -e " UPDATE mysql_users SET default_hostgroup = 0 WHERE default_hostgroup = ${ WRITER_HG } ; "
# Update query rules
${ MYSQL_CMD } -e " UPDATE mysql_query_rules SET destination_hostgroup = 0 WHERE destination_hostgroup = ${ WRITER_HG } ; "
${ MYSQL_CMD } -e " UPDATE mysql_query_rules SET destination_hostgroup = 1 WHERE destination_hostgroup = ${ READER_HG } ; "
# Load all changes to runtime
# Load all to runtime
${ MYSQL_CMD } -e "LOAD MYSQL SERVERS TO RUNTIME;"
${ MYSQL_CMD } -e "LOAD MYSQL USERS TO RUNTIME;"
${ MYSQL_CMD } -e "LOAD MYSQL QUERY RULES TO RUNTIME;"
echo ">>> Hostgroup alias ing done."
echo ">>> Hostgroup remapp ing done."