Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

K8SPS-283: Add HAProxy for group replication #399

Merged
merged 25 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 62 additions & 10 deletions api/v1alpha1/perconaservermysql_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ type MySQLSpec struct {
SidecarVolumes []corev1.Volume `json:"sidecarVolumes,omitempty"`
SidecarPVCs []SidecarPVC `json:"sidecarPVCs,omitempty"`

Configuration string `json:"configuration,omitempty"`

PodSpec `json:",inline"`
}

Expand Down Expand Up @@ -129,6 +127,9 @@ type ContainerSpec struct {
LivenessProbe corev1.Probe `json:"livenessProbe,omitempty"`

ContainerSecurityContext *corev1.SecurityContext `json:"containerSecurityContext,omitempty"`

Env []corev1.EnvVar `json:"env,omitempty"`
EnvFrom []corev1.EnvFromSource `json:"envFrom,omitempty"`
}

type PodSpec struct {
Expand All @@ -149,6 +150,8 @@ type PodSpec struct {
PodSecurityContext *corev1.PodSecurityContext `json:"podSecurityContext,omitempty"`
ServiceAccountName string `json:"serviceAccountName,omitempty"`

Configuration string `json:"configuration,omitempty"`

ContainerSpec `json:",inline"`
}

Expand Down Expand Up @@ -267,9 +270,9 @@ type ProxySpec struct {
}

type MySQLRouterSpec struct {
Expose ServiceExpose `json:"expose,omitempty"`
Enabled bool `json:"enabled,omitempty"`

Configuration string `json:"configuration,omitempty"`
Expose ServiceExpose `json:"expose,omitempty"`

PodSpec `json:",inline"`
}
Expand All @@ -279,8 +282,9 @@ type ToolkitSpec struct {
}

type HAProxySpec struct {
Enabled bool `json:"enabled,omitempty"`
Expose ServiceExpose `json:"expose,omitempty"`
Enabled bool `json:"enabled,omitempty"`

Expose ServiceExpose `json:"expose,omitempty"`

PodSpec `json:",inline"`
}
Expand Down Expand Up @@ -516,6 +520,36 @@ func (cr *PerconaServerMySQL) CheckNSetDefaults(ctx context.Context, serverVersi
cr.Spec.Proxy.Router.ReadinessProbe.TimeoutSeconds = 3
}

if cr.Spec.Proxy.HAProxy == nil {
cr.Spec.Proxy.HAProxy = new(HAProxySpec)
}

if cr.Spec.Proxy.HAProxy.LivenessProbe.PeriodSeconds == 0 {
cr.Spec.Proxy.HAProxy.LivenessProbe.PeriodSeconds = 5
}
if cr.Spec.Proxy.HAProxy.LivenessProbe.FailureThreshold == 0 {
cr.Spec.Proxy.HAProxy.LivenessProbe.FailureThreshold = 3
}
if cr.Spec.Proxy.HAProxy.LivenessProbe.SuccessThreshold == 0 {
cr.Spec.Proxy.HAProxy.LivenessProbe.SuccessThreshold = 1
}
if cr.Spec.Proxy.HAProxy.LivenessProbe.TimeoutSeconds == 0 {
cr.Spec.Proxy.HAProxy.LivenessProbe.TimeoutSeconds = 3
}

if cr.Spec.Proxy.HAProxy.ReadinessProbe.PeriodSeconds == 0 {
cr.Spec.Proxy.HAProxy.ReadinessProbe.PeriodSeconds = 5
}
if cr.Spec.Proxy.HAProxy.ReadinessProbe.FailureThreshold == 0 {
cr.Spec.Proxy.HAProxy.ReadinessProbe.FailureThreshold = 3
}
if cr.Spec.Proxy.HAProxy.ReadinessProbe.SuccessThreshold == 0 {
cr.Spec.Proxy.HAProxy.ReadinessProbe.SuccessThreshold = 1
}
if cr.Spec.Proxy.HAProxy.ReadinessProbe.TimeoutSeconds == 0 {
cr.Spec.Proxy.HAProxy.ReadinessProbe.TimeoutSeconds = 3
}

var fsgroup *int64
if serverVersion.Platform != platform.PlatformOpenshift {
var tp int64 = 1001
Expand Down Expand Up @@ -573,7 +607,11 @@ func (cr *PerconaServerMySQL) CheckNSetDefaults(ctx context.Context, serverVersi
}
}

if cr.Spec.MySQL.ClusterType == ClusterTypeGR && cr.Spec.Proxy.Router != nil && !cr.Spec.AllowUnsafeConfig {
if cr.RouterEnabled() && cr.HAProxyEnabled() {
return errors.New("MySQL Router and HAProxy can't be enabled at the same time")
}

if cr.RouterEnabled() && !cr.Spec.AllowUnsafeConfig {
if cr.Spec.Proxy.Router.Size < MinSafeProxySize {
cr.Spec.Proxy.Router.Size = MinSafeProxySize
}
Expand All @@ -583,7 +621,7 @@ func (cr *PerconaServerMySQL) CheckNSetDefaults(ctx context.Context, serverVersi
cr.Spec.Proxy.HAProxy = new(HAProxySpec)
}

if cr.HAProxyEnabled() && cr.Spec.MySQL.ClusterType != ClusterTypeGR && !cr.Spec.AllowUnsafeConfig {
if cr.HAProxyEnabled() && !cr.Spec.AllowUnsafeConfig {
if cr.Spec.Proxy.HAProxy.Size < MinSafeProxySize {
cr.Spec.Proxy.HAProxy.Size = MinSafeProxySize
}
Expand Down Expand Up @@ -801,17 +839,31 @@ func (pmm *PMMSpec) HasSecret(secret *corev1.Secret) bool {
return false
}

func (cr *PerconaServerMySQL) RouterEnabled() bool {
if cr.MySQLSpec().IsAsync() {
return false
}

return cr.Spec.Proxy.Router != nil && cr.Spec.Proxy.Router.Enabled
}

func (cr *PerconaServerMySQL) HAProxyEnabled() bool {
if !cr.Spec.AllowUnsafeConfig {
if cr.MySQLSpec().IsAsync() && !cr.Spec.AllowUnsafeConfig {
return true
}

return cr.Spec.Proxy.HAProxy != nil && cr.Spec.Proxy.HAProxy.Enabled
}

func (cr *PerconaServerMySQL) OrchestratorEnabled() bool {
if !cr.Spec.AllowUnsafeConfig {
if cr.MySQLSpec().IsGR() {
return false
}

if cr.MySQLSpec().IsAsync() && !cr.Spec.AllowUnsafeConfig {
return true
}

return cr.Spec.Orchestrator.Enabled
}

Expand Down
14 changes: 14 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 34 additions & 5 deletions build/haproxy-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,41 @@
set -e
set -o xtrace

log() {
local message=$1
local date=$(/usr/bin/date +"%d/%b/%Y:%H:%M:%S.%3N")

echo "{\"time\":\"${date}\", \"message\": \"${message}\"}"
}

echo "${CLUSTER_TYPE}" >/tmp/cluster_type

if [ "$1" = 'haproxy' ]; then
if [ ! -f '/etc/haproxy/mysql/haproxy.cfg' ]; then
cp /opt/percona/haproxy.cfg /etc/haproxy/mysql
fi
if [ ! -f '/etc/haproxy/mysql/haproxy.cfg' ]; then
cp /opt/percona/haproxy.cfg /etc/haproxy/mysql
fi

custom_conf='/etc/haproxy-custom/haproxy.cfg'
if [ -f "$custom_conf" ]; then
log "haproxy -c -f $custom_conf -f /etc/haproxy/mysql/haproxy.cfg"
haproxy -c -f $custom_conf -f /etc/haproxy/mysql/haproxy.cfg || EC=$?
if [ -n "$EC" ]; then
log "The custom config $custom_conf is not valid and will be ignored."
fi
fi

haproxy_opt='-W -db '
if [ -f "$custom_conf" -a -z "$EC" ]; then

Check warning on line 30 in build/haproxy-entrypoint.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] build/haproxy-entrypoint.sh#L30 <ShellCheck.SC2166>

Prefer [ p ] && [ q ] as [ p -a q ] is not well defined.
Raw output
./build/haproxy-entrypoint.sh:30:26: warning: Prefer [ p ] && [ q ] as [ p -a q ] is not well defined. (ShellCheck.SC2166)
haproxy_opt+="-f $custom_conf "
else
haproxy_opt+='-f /opt/percona/haproxy-global.cfg '
fi

haproxy_opt+='-f /etc/haproxy/mysql/haproxy.cfg -p /etc/haproxy/mysql/haproxy.pid -S /etc/haproxy/mysql/haproxy-main.sock'

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@egegunes please use the same approach for custom conf as we have for PXC operator
https://github.com/percona/percona-docker/blob/main/haproxy/dockerdir/entrypoint.sh#L17C5-L28

In case of custom config we need to replace whole conf

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

haproxy_opt='-W -db -f /opt/percona/haproxy-global.cfg -f /etc/haproxy/mysql/haproxy.cfg -p /etc/haproxy/mysql/haproxy.pid -S /etc/haproxy/mysql/haproxy-main.sock'
if [ -f '/etc/haproxy/config/haproxy.cfg' ]; then
haproxy_opt="${haproxy_opt} -f /etc/haproxy/config/haproxy.cfg"
fi
Comment on lines +16 to +40
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[shfmt] reported by reviewdog 🐶

Suggested change
if [ ! -f '/etc/haproxy/mysql/haproxy.cfg' ]; then
cp /opt/percona/haproxy.cfg /etc/haproxy/mysql
fi
custom_conf='/etc/haproxy-custom/haproxy.cfg'
if [ -f "$custom_conf" ]; then
log "haproxy -c -f $custom_conf -f /etc/haproxy/mysql/haproxy.cfg"
haproxy -c -f $custom_conf -f /etc/haproxy/mysql/haproxy.cfg || EC=$?
if [ -n "$EC" ]; then
log "The custom config $custom_conf is not valid and will be ignored."
fi
fi
haproxy_opt='-W -db '
if [ -f "$custom_conf" -a -z "$EC" ]; then
haproxy_opt+="-f $custom_conf "
else
haproxy_opt+='-f /opt/percona/haproxy-global.cfg '
fi
haproxy_opt+='-f /etc/haproxy/mysql/haproxy.cfg -p /etc/haproxy/mysql/haproxy.pid -S /etc/haproxy/mysql/haproxy-main.sock'
haproxy_opt='-W -db -f /opt/percona/haproxy-global.cfg -f /etc/haproxy/mysql/haproxy.cfg -p /etc/haproxy/mysql/haproxy.pid -S /etc/haproxy/mysql/haproxy-main.sock'
if [ -f '/etc/haproxy/config/haproxy.cfg' ]; then
haproxy_opt="${haproxy_opt} -f /etc/haproxy/config/haproxy.cfg"
fi
if [ ! -f '/etc/haproxy/mysql/haproxy.cfg' ]; then
cp /opt/percona/haproxy.cfg /etc/haproxy/mysql
fi
custom_conf='/etc/haproxy-custom/haproxy.cfg'
if [ -f "$custom_conf" ]; then
log "haproxy -c -f $custom_conf -f /etc/haproxy/mysql/haproxy.cfg"
haproxy -c -f $custom_conf -f /etc/haproxy/mysql/haproxy.cfg || EC=$?
if [ -n "$EC" ]; then
log "The custom config $custom_conf is not valid and will be ignored."
fi
fi
haproxy_opt='-W -db '
if [ -f "$custom_conf" -a -z "$EC" ]; then
haproxy_opt+="-f $custom_conf "
else
haproxy_opt+='-f /opt/percona/haproxy-global.cfg '
fi
haproxy_opt+='-f /etc/haproxy/mysql/haproxy.cfg -p /etc/haproxy/mysql/haproxy.pid -S /etc/haproxy/mysql/haproxy-main.sock'
if [ -f '/etc/haproxy/config/haproxy.cfg' ]; then
haproxy_opt="${haproxy_opt} -f /etc/haproxy/config/haproxy.cfg"
fi

fi

exec "$@" ${haproxy_opt}
exec "$@" "${haproxy_opt}"
12 changes: 12 additions & 0 deletions build/haproxy-global.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@
option clitcpka
default_backend mysql-replicas

frontend mysqlx-in
bind *:33060
mode tcp
option clitcpka
default_backend mysql-primary

frontend mysql-admin-in
bind *:33062
mode tcp
option clitcpka
default_backend mysql-primary

frontend stats
bind *:8404
mode http
Expand Down
59 changes: 46 additions & 13 deletions build/haproxy_check_primary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,63 @@

set -e

log() {
local level=$1
local message=$2
local date=$(/usr/bin/date +"%d/%b/%Y:%H:%M:%S.%3N")

echo "{\"time\":\"${date}\", \"level\": \"${level}\", \"message\": \"${message}\"}"
}

MYSQL_SERVER_IP=$3
MYSQL_SERVER_PORT='33062'

MONITOR_USER='monitor'
MONITOR_PASSWORD=$(/bin/cat /etc/mysql/mysql-users-secret/monitor)

TIMEOUT=${CUSTOM_TIMEOUT:-10}
TIMEOUT=${HA_CONNECTION_TIMEOUT:-10}
MYSQL_CMDLINE="/usr/bin/timeout $TIMEOUT /usr/bin/mysql -nNE -u${MONITOR_USER} -h ${MYSQL_SERVER_IP} -P ${MYSQL_SERVER_PORT}"

READ_ONLY=$(MYSQL_PWD="${MONITOR_PASSWORD}" ${MYSQL_CMDLINE} -e 'select @@super_read_only' | /usr/bin/sed -n -e '2p' | /usr/bin/tr -d '\n')
CLUSTER_TYPE=$(/bin/cat /tmp/cluster_type)

check_async() {
READ_ONLY=$(MYSQL_PWD="${MONITOR_PASSWORD}" ${MYSQL_CMDLINE} -e 'select @@super_read_only' | /usr/bin/sed -n -e '2p' | /usr/bin/tr -d '\n')

# ${REPLICATION_STATUS[0]} - Replica_IO_Running
# ${REPLICATION_STATUS[1]} - Replica_SQL_Running
REPLICATION_STATUS=($(MYSQL_PWD="${MONITOR_PASSWORD}" ${MYSQL_CMDLINE} -e 'SHOW REPLICA STATUS' | /usr/bin/sed -n -e '12p' -e '13p' | /usr/bin/tr '\n' ' '))

Check warning on line 29 in build/haproxy_check_primary.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] build/haproxy_check_primary.sh#L29 <ShellCheck.SC2207>

Prefer mapfile or read -a to split command output (or quote to avoid splitting).
Raw output
./build/haproxy_check_primary.sh:29:22: warning: Prefer mapfile or read -a to split command output (or quote to avoid splitting). (ShellCheck.SC2207)

log INFO "${MYSQL_SERVER_IP}:${MYSQL_SERVER_PORT} super_read_only: ${READ_ONLY} Replica_IO_Running: ${REPLICATION_STATUS[0]} Replica_SQL_Running: ${REPLICATION_STATUS[1]}"

if [[ ${READ_ONLY} == '0' ]] && [[ ${REPLICATION_STATUS[0]} != 'Yes' ]] && [[ ${REPLICATION_STATUS[1]} != 'Yes' ]]; then
log INFO "${MYSQL_SERVER_IP}:${MYSQL_SERVER_PORT} for backend ${HAPROXY_PROXY_NAME} is OK"
exit 0
else
log INFO "${MYSQL_SERVER_IP}:${MYSQL_SERVER_PORT} for backend ${HAPROXY_PROXY_NAME} is NOT OK"
exit 1
fi
}

check_gr() {
READ_ONLY=$(MYSQL_PWD="${MONITOR_PASSWORD}" ${MYSQL_CMDLINE} -e 'select @@super_read_only' | /usr/bin/sed -n -e '2p' | /usr/bin/tr -d '\n')
APPLIER_STATUS=$(MYSQL_PWD="${MONITOR_PASSWORD}" ${MYSQL_CMDLINE} -e "SELECT SERVICE_STATE FROM performance_schema.replication_connection_status WHERE channel_name = 'group_replication_applier'" | /usr/bin/sed -n -e '2p' | /usr/bin/tr -d '\n')

# ${REPLICATION_STATUS[0]} - Replica_IO_Running
# ${REPLICATION_STATUS[1]} - Replica_SQL_Running
REPLICATION_STATUS=($(MYSQL_PWD="${MONITOR_PASSWORD}" ${MYSQL_CMDLINE} -e 'SHOW REPLICA STATUS' | /usr/bin/sed -n -e '12p' -e '13p' | /usr/bin/tr '\n' ' '))
log INFO "${MYSQL_SERVER_IP}:${MYSQL_SERVER_PORT} @@super_read_only: ${READ_ONLY} Applier: ${APPLIER_STATUS}"

echo "MySQL node ${MYSQL_SERVER_IP}:${MYSQL_SERVER_PORT}"
echo "read_only: ${READ_ONLY}"
echo "Replica_IO_Running: ${REPLICATION_STATUS[0]}"
echo "Replica_SQL_Running: ${REPLICATION_STATUS[1]}"
if [[ ${READ_ONLY} == '0' ]] && [[ ${APPLIER_STATUS} == "ON" ]]; then
log INFO "${MYSQL_SERVER_IP}:${MYSQL_SERVER_PORT} for backend ${HAPROXY_PROXY_NAME} is OK"
exit 0
else
log INFO "${MYSQL_SERVER_IP}:${MYSQL_SERVER_PORT} for backend ${HAPROXY_PROXY_NAME} is NOT OK"
exit 1
fi
}

if [[ ${READ_ONLY} == '0' ]] && [[ ${REPLICATION_STATUS[0]} != 'Yes' ]] && [[ ${REPLICATION_STATUS[1]} != 'Yes' ]]; then
echo "MySQL node ${MYSQL_SERVER_IP}:${MYSQL_SERVER_PORT} for backend ${HAPROXY_PROXY_NAME} is ok"
exit 0
if [[ ${CLUSTER_TYPE} == "async" ]]; then
check_async
elif [[ ${CLUSTER_TYPE} == "group-replication" ]]; then
check_gr
else
echo "MySQL node ${MYSQL_SERVER_IP}:${MYSQL_SERVER_PORT} for backend ${HAPROXY_PROXY_NAME} is not ok"
log ERROR "Invalid cluster type: ${CLUSTER_TYPE}"
exit 1
fi
57 changes: 45 additions & 12 deletions build/haproxy_check_replicas.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

set -e

log() {
local level=$1
local message=$2
local date=$(/usr/bin/date +"%d/%b/%Y:%H:%M:%S.%3N")
egegunes marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[shfmt] reported by reviewdog 🐶

Suggested change
local level=$1
local message=$2
local date=$(/usr/bin/date +"%d/%b/%Y:%H:%M:%S.%3N")
local level=$1
local message=$2
local date=$(/usr/bin/date +"%d/%b/%Y:%H:%M:%S.%3N")


echo "{\"time\":\"${date}\", \"level\": \"${level}\", \"message\": \"${message}\"}"
egegunes marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[shfmt] reported by reviewdog 🐶

Suggested change
echo "{\"time\":\"${date}\", \"level\": \"${level}\", \"message\": \"${message}\"}"
echo "{\"time\":\"${date}\", \"level\": \"${level}\", \"message\": \"${message}\"}"

}

MYSQL_SERVER_IP=$3
MYSQL_SERVER_PORT='33062'

Expand All @@ -11,21 +19,46 @@
TIMEOUT=${CUSTOM_TIMEOUT:-10}
MYSQL_CMDLINE="/usr/bin/timeout $TIMEOUT /usr/bin/mysql -nNE -u${MONITOR_USER} -h ${MYSQL_SERVER_IP} -P ${MYSQL_SERVER_PORT}"

READ_ONLY=$(MYSQL_PWD="${MONITOR_PASSWORD}" ${MYSQL_CMDLINE} -e 'select @@super_read_only' | /usr/bin/sed -n -e '2p' | /usr/bin/tr -d '\n')
CLUSTER_TYPE=$(/bin/cat /tmp/cluster_type)

check_async() {
READ_ONLY=$(MYSQL_PWD="${MONITOR_PASSWORD}" ${MYSQL_CMDLINE} -e 'select @@super_read_only' | /usr/bin/sed -n -e '2p' | /usr/bin/tr -d '\n')

# ${REPLICATION_STATUS[0]} - Replica_IO_Running
# ${REPLICATION_STATUS[1]} - Replica_SQL_Running
REPLICATION_STATUS=($(MYSQL_PWD="${MONITOR_PASSWORD}" ${MYSQL_CMDLINE} -e 'SHOW REPLICA STATUS' | /usr/bin/sed -n -e '12p' -e '13p' | /usr/bin/tr '\n' ' '))

Check warning on line 29 in build/haproxy_check_replicas.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] build/haproxy_check_replicas.sh#L29 <ShellCheck.SC2207>

Prefer mapfile or read -a to split command output (or quote to avoid splitting).
Raw output
./build/haproxy_check_replicas.sh:29:22: warning: Prefer mapfile or read -a to split command output (or quote to avoid splitting). (ShellCheck.SC2207)

log INFO "${MYSQL_SERVER_IP}:${MYSQL_SERVER_PORT} @@super_read_only: ${READ_ONLY} Replica_IO_Running: ${REPLICATION_STATUS[0]} Replica_SQL_Running: ${REPLICATION_STATUS[1]}"

if [[ ${READ_ONLY} == '1' ]] && [[ ${REPLICATION_STATUS[0]} == 'Yes' ]] && [[ ${REPLICATION_STATUS[1]} == 'Yes' ]]; then
log INFO "${MYSQL_SERVER_IP}:${MYSQL_SERVER_PORT} for backend ${HAPROXY_PROXY_NAME} is OK"
exit 0
else
log INFO "${MYSQL_SERVER_IP}:${MYSQL_SERVER_PORT} for backend ${HAPROXY_PROXY_NAME} is NOT OK"
exit 1
fi
}

check_gr() {
READ_ONLY=$(MYSQL_PWD="${MONITOR_PASSWORD}" ${MYSQL_CMDLINE} -e 'SELECT @@super_read_only' | /usr/bin/sed -n -e '2p' | /usr/bin/tr -d '\n')
APPLIER_STATUS=$(MYSQL_PWD="${MONITOR_PASSWORD}" ${MYSQL_CMDLINE} -e "SELECT SERVICE_STATE FROM performance_schema.replication_connection_status WHERE channel_name = 'group_replication_applier'" | /usr/bin/sed -n -e '2p' | /usr/bin/tr -d '\n')

# ${REPLICATION_STATUS[0]} - Replica_IO_Running
# ${REPLICATION_STATUS[1]} - Replica_SQL_Running
REPLICATION_STATUS=($(MYSQL_PWD="${MONITOR_PASSWORD}" ${MYSQL_CMDLINE} -e 'SHOW REPLICA STATUS' | /usr/bin/sed -n -e '12p' -e '13p' | /usr/bin/tr '\n' ' '))
log INFO "${MYSQL_SERVER_IP}:${MYSQL_SERVER_PORT} @@super_read_only: ${READ_ONLY} Applier: ${APPLIER_STATUS}"

echo "MySQL node ${MYSQL_SERVER_IP}:${MYSQL_SERVER_PORT}"
echo "read_only: ${READ_ONLY}"
echo "Replica_IO_Running: ${REPLICATION_STATUS[0]}"
echo "Replica_SQL_Running: ${REPLICATION_STATUS[1]}"
if [[ ${READ_ONLY} == '1' ]] && [[ ${APPLIER_STATUS} == "ON" ]]; then
log INFO "${MYSQL_SERVER_IP}:${MYSQL_SERVER_PORT} for backend ${HAPROXY_PROXY_NAME} is OK"
exit 0
else
log INFO "${MYSQL_SERVER_IP}:${MYSQL_SERVER_PORT} for backend ${HAPROXY_PROXY_NAME} is NOT OK"
exit 1
fi
}

if [[ ${READ_ONLY} == '1' ]] && [[ ${REPLICATION_STATUS[0]} == 'Yes' ]] && [[ ${REPLICATION_STATUS[1]} == 'Yes' ]]; then
echo "MySQL node ${MYSQL_SERVER_IP}:${MYSQL_SERVER_PORT} for backend ${HAPROXY_PROXY_NAME} is ok"
exit 0
if [[ ${CLUSTER_TYPE} == "async" ]]; then
check_async
elif [[ ${CLUSTER_TYPE} == "group-replication" ]]; then
check_gr
else
echo "MySQL node ${MYSQL_SERVER_IP}:${MYSQL_SERVER_PORT} for backend ${HAPROXY_PROXY_NAME} is not ok"
log ERROR "Invalid cluster type: ${CLUSTER_TYPE}"
exit 1
fi
Loading
Loading