Skip to content

Commit 19f0b96

Browse files
committed
MDEV-27682: bundled wsrep_notify.sh causes mariadbd to freeze during start
This commit adds automation that will reduce the possibility of user errors when customizing wsrep_notify.sh (in particular caused by user-specified parameters). Now all leading and trailing spaces are removed from the user-specified parameters and automatic port and host address substitution has been added to scripts, as well as automatic password substitution to the client command line, only if it is specified in the wsrep_notify.sh and not as empty strings. Also added support for automatic substitution of the all SSL-related parameters and improved parsing for ipv6 addresses (to allow "[...]" notation for ipv6 addresses). Also added a test to check if the wsrep notify script will works with SSL.
1 parent c0817da commit 19f0b96

File tree

8 files changed

+465
-30
lines changed

8 files changed

+465
-30
lines changed

mysql-test/include/ipv6.inc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,3 @@ eval SET PASSWORD FOR testuser1@'$IPv6' = PASSWORD ('9876');
2222
--replace_result ::1 localhost
2323
SELECT USER();
2424
eval DROP USER testuser1@'$IPv6';
25-

mysql-test/std_data/wsrep_notify.sh

Lines changed: 110 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,31 @@
44
# It will create 'wsrep' schema and two tables in it: 'membeship' and 'status'
55
# and fill them on every membership or node status change.
66
#
7-
# Edit parameters below to specify the address and login to server.
8-
7+
# Edit parameters below to specify the address and login to server:
8+
#
99
USER=root
10+
PSWD=
11+
#
12+
# If these parameters are not set, then the values
13+
# passed by the server are taken:
14+
#
1015
HOST=127.0.0.1
1116
PORT=$NODE_MYPORT_1
17+
#
18+
# Edit parameters below to specify SSL parameters:
19+
#
20+
ssl_key=
21+
ssl_cert=
22+
ssl_ca=
23+
ssl_capath=
24+
ssl_cipher=
25+
ssl_crl=
26+
ssl_crlpath=
27+
ssl_verify_server_cert=0
28+
#
29+
# Client executable path:
30+
#
31+
CLIENT="$EXE_MYSQL"
1232

1333
SCHEMA="mtr_wsrep_notify"
1434
MEMB_TABLE="$SCHEMA.membership"
@@ -19,7 +39,7 @@ SET wsrep_on=0;
1939
CREATE SCHEMA IF NOT EXISTS $SCHEMA;
2040
CREATE TABLE IF NOT EXISTS $MEMB_TABLE (
2141
idx INT,
22-
uuid CHAR(40), /* node UUID */
42+
uuid CHAR(40), /* node UUID */
2343
name VARCHAR(32), /* node name */
2444
addr VARCHAR(256) /* node address */
2545
) ENGINE=MEMORY;
@@ -40,7 +60,7 @@ configuration_change()
4060

4161
local idx=0
4262

43-
for NODE in $(echo $MEMBERS | sed s/,/\ /g)
63+
for NODE in $(echo "$MEMBERS" | sed s/,/\ /g)
4464
do
4565
echo "INSERT INTO $MEMB_TABLE VALUES ( $idx, "
4666
# Don't forget to properly quote string values
@@ -59,17 +79,44 @@ status_update()
5979
echo "SET wsrep_on=0; BEGIN; UPDATE $STATUS_TABLE SET status='$STATUS'; COMMIT;"
6080
}
6181

82+
trim_string()
83+
{
84+
if [ -n "${BASH_VERSION:-}" ]; then
85+
local pattern="[![:space:]${2:-}]"
86+
local x="${1#*$pattern}"
87+
local z=${#1}
88+
x=${#x}
89+
if [ $x -ne $z ]; then
90+
local y="${1%$pattern*}"
91+
y=${#y}
92+
x=$(( z-x-1 ))
93+
y=$(( y-x+1 ))
94+
printf '%s' "${1:$x:$y}"
95+
else
96+
printf ''
97+
fi
98+
else
99+
local pattern="[[:space:]${2:-}]"
100+
echo "$1" | sed -E "s/^$pattern+|$pattern+\$//g"
101+
fi
102+
}
103+
62104
COM=status_update # not a configuration change by default
63105

64-
while [ $# -gt 0 ]
65-
do
106+
STATUS=""
107+
CLUSTER_UUID=""
108+
PRIMARY="0"
109+
INDEX=""
110+
MEMBERS=""
111+
112+
while [ $# -gt 0 ]; do
66113
case $1 in
67114
--status)
68-
STATUS=$2
115+
STATUS=$(trim_string "$2")
69116
shift
70117
;;
71118
--uuid)
72-
CLUSTER_UUID=$2
119+
CLUSTER_UUID=$(trim_string "$2")
73120
shift
74121
;;
75122
--primary)
@@ -78,22 +125,71 @@ do
78125
shift
79126
;;
80127
--index)
81-
INDEX=$2
128+
INDEX=$(trim_string "$2")
82129
shift
83130
;;
84131
--members)
85-
MEMBERS=$2
132+
MEMBERS=$(trim_string "$2")
86133
shift
87134
;;
88135
esac
89136
shift
90137
done
91138

92-
# Undefined means node is shutting down
93-
if [ "$STATUS" != "Undefined" ]
139+
USER=$(trim_string "$USER")
140+
PSWD=$(trim_string "$PSWD")
141+
142+
HOST=$(trim_string "$HOST")
143+
PORT=$(trim_string "$PORT")
144+
145+
case "$HOST" in
146+
\[*)
147+
HOST="${HOST##\[}"
148+
HOST=$(trim_string "${HOST%%\]}")
149+
;;
150+
esac
151+
152+
if [ -z "$HOST" ]; then
153+
HOST="${NOTIFY_HOST:-}"
154+
fi
155+
if [ -z "$PORT" ]; then
156+
PORT="${NOTIFY_PORT:-}"
157+
fi
158+
159+
ssl_key=$(trim_string "$ssl_key");
160+
ssl_cert=$(trim_string "$ssl_cert");
161+
ssl_ca=$(trim_string "$ssl_ca");
162+
ssl_capath=$(trim_string "$ssl_capath");
163+
ssl_cipher=$(trim_string "$ssl_cipher");
164+
ssl_crl=$(trim_string "$ssl_crl");
165+
ssl_crlpath=$(trim_string "$ssl_crlpath");
166+
ssl_verify_server_cert=$(trim_string "$ssl_verify_server_cert");
167+
168+
SSL_PARAM=""
169+
170+
if [ -n "$ssl_key" -o -n "$ssl_cert" -o \
171+
-n "$ssl_ca" -o -n "$ssl_capath" -o \
172+
-n "$ssl_cipher" ]
94173
then
95-
$COM | mysql -B -u$USER -h$HOST -P$PORT
174+
SSL_PARAM=' --ssl'
175+
[ -n "$ssl_key" ] && SSL_PARAM="$SSL_PARAM --ssl-key='$ssl_key'"
176+
[ -n "$ssl_cert" ] && SSL_PARAM="$SSL_PARAM --ssl-cert='$ssl_cert'"
177+
[ -n "$ssl_ca" ] && SSL_PARAM="$SSL_PARAM --ssl-ca='$ssl_ca'"
178+
[ -n "$ssl_capath" ] && SSL_PARAM="$SSL_PARAM --ssl-capath='$ssl_capath'"
179+
[ -n "$ssl_cipher" ] && SSL_PARAM="$SSL_PARAM --ssl-cipher='$ssl_cipher'"
180+
[ -n "$ssl_crl" ] && SSL_PARAM="$SSL_PARAM --ssl-crl='$ssl_crl'"
181+
[ -n "$ssl_crlpath" ] && SSL_PARAM="$SSL_PARAM --ssl-crlpath='$ssl_crlpath'"
182+
if [ -n "$ssl_verify_server_cert" ]; then
183+
if [ $ssl_verify_server_cert -ne 0 ]; then
184+
SSL_PARAM+=' --ssl-verify-server-cert'
185+
fi
186+
fi
187+
fi
188+
189+
# Undefined means node is shutting down
190+
if [ "$STATUS" != 'Undefined' ]; then
191+
"$COM" | eval "$CLIENT" -B "-u'$USER'"${PSWD:+" -p'$PSWD'"}\
192+
"-h'$HOST'" "-P$PORT"$SSL_PARAM
96193
fi
97194

98195
exit 0
99-
#
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
#!/bin/sh -eu
2+
3+
# This is a simple example of wsrep notification script (wsrep_notify_cmd).
4+
# It will create 'wsrep' schema and two tables in it: 'membeship' and 'status'
5+
# and fill them on every membership or node status change.
6+
#
7+
# Edit parameters below to specify the address and login to server:
8+
#
9+
USER=root
10+
PSWD=
11+
#
12+
# If these parameters are not set, then the values
13+
# passed by the server are taken:
14+
#
15+
HOST=127.0.0.1
16+
PORT=$NODE_MYPORT_1
17+
#
18+
# Edit parameters below to specify SSL parameters:
19+
#
20+
ssl_cert="$MYSQL_TEST_DIR/std_data/client-cert.pem"
21+
ssl_key="$MYSQL_TEST_DIR/std_data/client-key.pem"
22+
ssl_ca="$MYSQL_TEST_DIR/std_data/cacert.pem"
23+
ssl_capath=
24+
ssl_cipher=
25+
ssl_crl=
26+
ssl_crlpath=
27+
ssl_verify_server_cert=0
28+
#
29+
# Client executable path:
30+
#
31+
CLIENT="$EXE_MYSQL"
32+
33+
SCHEMA="mtr_wsrep_notify"
34+
MEMB_TABLE="$SCHEMA.membership"
35+
STATUS_TABLE="$SCHEMA.status"
36+
37+
BEGIN="
38+
SET wsrep_on=0;
39+
CREATE SCHEMA IF NOT EXISTS $SCHEMA;
40+
CREATE TABLE IF NOT EXISTS $MEMB_TABLE (
41+
idx INT,
42+
uuid CHAR(40), /* node UUID */
43+
name VARCHAR(32), /* node name */
44+
addr VARCHAR(256) /* node address */
45+
) ENGINE=MEMORY;
46+
CREATE TABLE IF NOT EXISTS $STATUS_TABLE (
47+
size INT, /* component size */
48+
idx INT, /* this node index */
49+
status CHAR(16), /* this node status */
50+
uuid CHAR(40), /* cluster UUID */
51+
prim BOOLEAN /* if component is primary */
52+
) ENGINE=MEMORY;
53+
BEGIN;
54+
"
55+
END="COMMIT;"
56+
57+
configuration_change()
58+
{
59+
echo "$BEGIN;"
60+
61+
local idx=0
62+
63+
for NODE in $(echo "$MEMBERS" | sed s/,/\ /g)
64+
do
65+
echo "INSERT INTO $MEMB_TABLE VALUES ( $idx, "
66+
# Don't forget to properly quote string values
67+
echo "'$NODE'" | sed s/\\//\',\'/g
68+
echo ");"
69+
idx=$(( $idx + 1 ))
70+
done
71+
72+
echo "INSERT INTO $STATUS_TABLE VALUES($idx, $INDEX, '$STATUS', '$CLUSTER_UUID', $PRIMARY);"
73+
74+
echo "$END"
75+
}
76+
77+
status_update()
78+
{
79+
echo "SET wsrep_on=0; BEGIN; UPDATE $STATUS_TABLE SET status='$STATUS'; COMMIT;"
80+
}
81+
82+
trim_string()
83+
{
84+
if [ -n "${BASH_VERSION:-}" ]; then
85+
local pattern="[![:space:]${2:-}]"
86+
local x="${1#*$pattern}"
87+
local z=${#1}
88+
x=${#x}
89+
if [ $x -ne $z ]; then
90+
local y="${1%$pattern*}"
91+
y=${#y}
92+
x=$(( z-x-1 ))
93+
y=$(( y-x+1 ))
94+
printf '%s' "${1:$x:$y}"
95+
else
96+
printf ''
97+
fi
98+
else
99+
local pattern="[[:space:]${2:-}]"
100+
echo "$1" | sed -E "s/^$pattern+|$pattern+\$//g"
101+
fi
102+
}
103+
104+
COM=status_update # not a configuration change by default
105+
106+
STATUS=""
107+
CLUSTER_UUID=""
108+
PRIMARY="0"
109+
INDEX=""
110+
MEMBERS=""
111+
112+
while [ $# -gt 0 ]; do
113+
case $1 in
114+
--status)
115+
STATUS=$(trim_string "$2")
116+
shift
117+
;;
118+
--uuid)
119+
CLUSTER_UUID=$(trim_string "$2")
120+
shift
121+
;;
122+
--primary)
123+
[ "$2" = "yes" ] && PRIMARY="1" || PRIMARY="0"
124+
COM=configuration_change
125+
shift
126+
;;
127+
--index)
128+
INDEX=$(trim_string "$2")
129+
shift
130+
;;
131+
--members)
132+
MEMBERS=$(trim_string "$2")
133+
shift
134+
;;
135+
esac
136+
shift
137+
done
138+
139+
USER=$(trim_string "$USER")
140+
PSWD=$(trim_string "$PSWD")
141+
142+
HOST=$(trim_string "$HOST")
143+
PORT=$(trim_string "$PORT")
144+
145+
case "$HOST" in
146+
\[*)
147+
HOST="${HOST##\[}"
148+
HOST=$(trim_string "${HOST%%\]}")
149+
;;
150+
esac
151+
152+
if [ -z "$HOST" ]; then
153+
HOST="${NOTIFY_HOST:-}"
154+
fi
155+
if [ -z "$PORT" ]; then
156+
PORT="${NOTIFY_PORT:-}"
157+
fi
158+
159+
ssl_key=$(trim_string "$ssl_key");
160+
ssl_cert=$(trim_string "$ssl_cert");
161+
ssl_ca=$(trim_string "$ssl_ca");
162+
ssl_capath=$(trim_string "$ssl_capath");
163+
ssl_cipher=$(trim_string "$ssl_cipher");
164+
ssl_crl=$(trim_string "$ssl_crl");
165+
ssl_crlpath=$(trim_string "$ssl_crlpath");
166+
ssl_verify_server_cert=$(trim_string "$ssl_verify_server_cert");
167+
168+
SSL_PARAM=""
169+
170+
if [ -n "$ssl_key" -o -n "$ssl_cert" -o \
171+
-n "$ssl_ca" -o -n "$ssl_capath" -o \
172+
-n "$ssl_cipher" ]
173+
then
174+
SSL_PARAM=' --ssl'
175+
[ -n "$ssl_key" ] && SSL_PARAM="$SSL_PARAM --ssl-key='$ssl_key'"
176+
[ -n "$ssl_cert" ] && SSL_PARAM="$SSL_PARAM --ssl-cert='$ssl_cert'"
177+
[ -n "$ssl_ca" ] && SSL_PARAM="$SSL_PARAM --ssl-ca='$ssl_ca'"
178+
[ -n "$ssl_capath" ] && SSL_PARAM="$SSL_PARAM --ssl-capath='$ssl_capath'"
179+
[ -n "$ssl_cipher" ] && SSL_PARAM="$SSL_PARAM --ssl-cipher='$ssl_cipher'"
180+
[ -n "$ssl_crl" ] && SSL_PARAM="$SSL_PARAM --ssl-crl='$ssl_crl'"
181+
[ -n "$ssl_crlpath" ] && SSL_PARAM="$SSL_PARAM --ssl-crlpath='$ssl_crlpath'"
182+
if [ -n "$ssl_verify_server_cert" ]; then
183+
if [ $ssl_verify_server_cert -ne 0 ]; then
184+
SSL_PARAM+=' --ssl-verify-server-cert'
185+
fi
186+
fi
187+
fi
188+
189+
# Undefined means node is shutting down
190+
if [ "$STATUS" != 'Undefined' ]; then
191+
"$COM" | eval "$CLIENT" -B "-u'$USER'"${PSWD:+" -p'$PSWD'"}\
192+
"-h'$HOST'" "-P$PORT"$SSL_PARAM
193+
fi
194+
195+
exit 0
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
connection node_1;
2+
SELECT COUNT(DISTINCT uuid) AS EXPECT_2 FROM mtr_wsrep_notify.membership;
3+
EXPECT_2
4+
2
5+
SELECT MAX(size) AS EXPECT_2 FROM mtr_wsrep_notify.status;
6+
EXPECT_2
7+
2
8+
SELECT COUNT(DISTINCT idx) AS EXPECT_2 FROM mtr_wsrep_notify.status;
9+
EXPECT_2
10+
2
11+
DROP SCHEMA mtr_wsrep_notify;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--wsrep_notify_cmd=$MYSQL_TEST_DIR/std_data/wsrep_notify_ssl.sh --wsrep-sync-wait=0

0 commit comments

Comments
 (0)