Skip to content

Commit 77d5f9d

Browse files
MOS CIGerrit Code Review
MOS CI
authored and
Gerrit Code Review
committed
Merge "[MariaDB] Update chart for work with 11.x version"
2 parents be2538c + 392deaf commit 77d5f9d

File tree

5 files changed

+62
-60
lines changed

5 files changed

+62
-60
lines changed

charts/infra/mariadb/templates/bin/_health.sh.tpl

+10-10
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
set -e
2020

21-
MYSQL="mysql \
21+
MYSQL="mariadb \
2222
--defaults-file=/etc/mysql/admin_user.cnf \
2323
--host=localhost \
2424
--connect-timeout 2"
@@ -54,7 +54,7 @@ shift $((OPTIND-1))
5454

5555
check_readiness () {
5656
if ! $MYSQL -e 'select 1' > /dev/null 2>&1 ; then
57-
echo "Select from mysql failed"
57+
echo "Select from mariadb failed"
5858
exit 1
5959
fi
6060

@@ -86,25 +86,25 @@ check_readiness () {
8686
}
8787

8888
check_liveness () {
89-
if pidof mysql_upgrade > /dev/null 2>&1 ; then
90-
echo "The process mysql_upgrade is active. Skip rest checks"
89+
if pidof mariadb-upgrade > /dev/null 2>&1 ; then
90+
echo "The process mariadb-upgrade is active. Skip rest checks"
9191
exit 0
9292
fi
93-
if ! pidof mysqld > /dev/null 2>&1 ; then
94-
echo "The mysqld pid not found"
93+
if ! pidof mariadbd > /dev/null 2>&1 ; then
94+
echo "The mariadbd pid not found"
9595
exit 1
9696
fi
9797
# NOTE(mkarpin): SST process may take significant time in case of large databases,
98-
# killing mysqld during SST may destroy all data on the node.
98+
# killing mariadbd during SST may destroy all data on the node.
9999
local datadir="/var/lib/mysql"
100100
if [ -f ${datadir}/sst_in_progress ]; then
101-
echo "SST is still in progress, skip further checks as mysql won't respond"
101+
echo "SST is still in progress, skip further checks as mariadb won't respond"
102102
else
103103
# NOTE(vsaienko): in some cases maria might stuck during IST, or when neighbours
104-
# IPs are changed. Here we check that we can connect to mysql socket to ensure
104+
# IPs are changed. Here we check that we can connect to mariadb socket to ensure
105105
# process is alive.
106106
if ! $MYSQL -e "show status like 'wsrep_cluster_status'" > /dev/null 2>&1 ; then
107-
echo "Can't connect to mysql socket"
107+
echo "Can't connect to mariadb socket"
108108
exit 1
109109
fi
110110
# Detect node that is not connected to wsrep provider

charts/infra/mariadb/templates/bin/_mariadb_resque.py.tpl

+16-19
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ r"""
1919
The script provides tooling for resque operations (e.g data backup, data restore) procedure
2020
for mariadb galera cluster (master-master) in k8s/helm environment.
2121
Currently supported:
22-
- physical data backup and restore using mariabackup.
22+
- physical data backup and restore using mariadb-backup.
2323
- upload of backups to remote storage (s3).
2424
- download of backups from remote storage, if local backups are not valid.
2525
@@ -564,11 +564,11 @@ def run_cmd(popenargs,
564564

565565

566566
def get_mariabackup_version():
567-
""" $ mariabackup --version
568-
mariabackup based on MariaDB server 10.6.17-MariaDB debian-linux-gnu (x86_64)
567+
""" $ mariadb-backup --version
568+
mariadb-backup based on MariaDB server 10.6.17-MariaDB debian-linux-gnu (x86_64)
569569
"""
570-
cmd_res = run_cmd(["mariabackup", "--version"], return_stderr=True)[2][0]
571-
res = re.search(MARIADB_VERSION_REGEX, cmd_res)
570+
cmd_res = run_cmd(["mariadb-backup", "--version"], return_stderr=True)[2]
571+
res = re.search(MARIADB_VERSION_REGEX, " ".join(cmd_res))
572572
return {"major": res.group(1), "minor": res.group(2), "patch": res.group(3)}
573573

574574

@@ -588,22 +588,19 @@ def find_latest_backup(path):
588588
raise Exception(f"Successful backup not found at {backup_path} !!!! Cannot proceed")
589589
return back_dir
590590

591+
def get_backup_version():
591592

592-
def get_backup_version(path=None):
593-
base_back_path = SETTINGS.base_back_path
594-
595-
def find_latest_xtrabackup_info(path):
593+
def find_latest_backup_info(path):
596594
back_dirs = sorted(get_dirs(path), reverse=True)
597595
for d in back_dirs:
598-
if "xtrabackup_info" in os.listdir(f"{path}/{d}"):
599-
return f"{path}/{d}/xtrabackup_info"
600-
601-
if path:
602-
xtrab_info = f"{path}/xtrabackup_info"
603-
else:
604-
xtrab_info = find_latest_xtrabackup_info(base_back_path)
605-
if xtrab_info:
606-
with open(xtrab_info) as f:
596+
for info_file in ["mariadb_backup_info", "xtrabackup_info"]:
597+
info_file_path = os.path.join(path, d, info_file)
598+
if os.path.exists(info_file_path):
599+
return info_file_path
600+
601+
backup_info = find_latest_backup_info(SETTINGS.base_back_path)
602+
if backup_info:
603+
with open(backup_info) as f:
607604
for line in f:
608605
if line.startswith("tool_version"):
609606
res = re.search(MARIADB_VERSION_REGEX, line.split("=")[1].strip())
@@ -1157,7 +1154,7 @@ def main():
11571154
pre_backup_sanity_check(ready_pods, synced_state)
11581155

11591156
logger.info(f"Target replica is: {SETTINGS.mariadb_target_replica}")
1160-
# we need pod ip as mariabackup util doesn't work with fqdn
1157+
# we need pod ip as mariadb-backup util doesn't work with fqdn
11611158
mariadb_pod_ip = get_target_replica_ip(ready_pods, SETTINGS.mariadb_target_replica)
11621159
# target_dir and incremental_base_dir are required in operation kwargs
11631160
# according to get_operation_cmd_args, we can remove them from operation

charts/infra/mariadb/templates/bin/_run_mariadb_resque.sh.tpl

+13-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ cat << EOF
88
The script provides tooling for resque operations (e.g data backup, data restore) of mariadb
99
galera cluster member.
1010
Currently supported:
11-
- physical data backup and restore using mariabackup.
11+
- physical data backup and restore using mariadb-backup.
1212
Example of resulting backup directory structure:
1313
1414
/var/backup
@@ -251,9 +251,9 @@ function post_operation_info(){
251251
}
252252

253253
function set_global_variables(){
254-
BACKCMD=mariabackup
254+
BACKCMD=mariadb-backup
255255
BACKDIR=/var/backup
256-
LOCKDIR="${BACKDIR}/mariabackup.lock"
256+
LOCKDIR="${BACKDIR}/mariadb-backup.lock"
257257
MARIADB_CLIENT_CONF=${MARIADB_CLIENT_CONF:-/etc/mysql/mariabackup_user.cnf}
258258
USEROPTIONS="--defaults-file=${MARIADB_CLIENT_CONF}"
259259
BASEBACKDIR="${BACKDIR}/base"
@@ -304,7 +304,7 @@ function pre_backup_sanity_check() {
304304
local available_space
305305
local db_size
306306
local required_space
307-
mysql $USEROPTIONS -s -e 'exit' || die $LINENO "FATAL ERROR: Could not connect to mysql with provided credentials"
307+
mariadb $USEROPTIONS -s -e 'exit' || die $LINENO "FATAL ERROR: Could not connect to mariadb with provided credentials"
308308
# check available space on device in KB
309309
available_space=$(df --output=avail -k ${BACKDIR} | sed 's/[^0-9]*//g' | tr -d '[:space:]')
310310
# Calculate current db size
@@ -384,7 +384,7 @@ function prepare_backup_for_restore(){
384384

385385
function run_restore() {
386386
# TODO: implement rollback of restore
387-
# mariabackup requires datadir to be clean
387+
# mariadb-backup requires datadir to be clean
388388
local latest_grastate_file
389389
if [[ ! "${TARGET_INCR_BACKUP_DIRS}" ]]; then
390390
echo "NO incremental backups found for base backup ${TARGET_BASE_BACKUP_DIR}, only base backup will be restored"
@@ -416,19 +416,24 @@ function cleanup_unarchieved_data(){
416416
}
417417

418418
function get_mariabackup_version() {
419-
echo "$(${BACKCMD} --version 2>&1 | sed -nE 's/.*(10\.[0-9]{1,2}\.[0-9]{1,2}-MariaDB).*/\1/p')"
419+
echo "$(${BACKCMD} --version 2>&1 | sed -nE 's/.*([0-9]{2}\.[0-9]{1,2}\.[0-9]{1,2}-MariaDB).*/\1/p')"
420420
}
421421

422422
function get_backup_version() {
423423
local backup=$1
424424
# if function called without params, we looking for latest full backup and return its version
425425
if [[ ! ${backup} ]]; then
426-
backup=$(find ${BASEBACKDIR} -mindepth 1 -name xtrabackup_info -printf "%h\n" | sort | tail -1)
426+
backup=$(find ${BASEBACKDIR} -mindepth 1 -name *backup_info -printf "%h\n" | sort | tail -1)
427427
fi
428428
if [[ ! ${backup} ]]; then
429429
echo "No-backups"
430430
else
431-
echo "$(cat ${backup}/xtrabackup_info | grep tool_version | cut -d' ' -f3)"
431+
for info_file in mariadb_backup_info xtrabackup_info; do
432+
if [[ -f ${backup}/${info_file} ]]; then
433+
echo "$(cat ${backup}/${info_file} | grep tool_version | cut -d' ' -f3)"
434+
break
435+
fi
436+
done
432437
fi
433438
}
434439

charts/infra/mariadb/templates/bin/_start.py.tpl

+22-22
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import kubernetes.client
3434
import kubernetes.config
3535

3636
#set one name for all commands, avoid "magic names"
37-
MYSQL_BINARY_NAME='mysqld'
37+
MYSQL_BINARY_NAME='mariadbd'
3838

3939
# Create logger, console handler and formatter
4040
logger = logging.getLogger('OpenStack-Helm Mariadb')
@@ -182,8 +182,8 @@ def wait_mysql_status(delay=30):
182182
i = 0
183183
res = 1
184184
while True:
185-
logger.info("Checking mysql status {0}".format(i))
186-
res = run_cmd_with_logging(['mysqladmin', 'status', "-u{0}".format(mysql_dbadmin_username),
185+
logger.info("Checking mariadb status {0}".format(i))
186+
res = run_cmd_with_logging(['mariadb-admin', 'status', "-u{0}".format(mysql_dbadmin_username),
187187
"-p{0}".format(mysql_dbadmin_password)], logger)
188188
if res == 0:
189189
logger.info("mariadb status check passed")
@@ -195,8 +195,8 @@ def wait_mysql_status(delay=30):
195195

196196

197197
def stop_mysqld():
198-
"""Stop mysqld, assuming pid file in default location."""
199-
logger.info("Shutting down any mysqld instance if required")
198+
"""Stop mariadbd, assuming pid file in default location."""
199+
logger.info("Shutting down any mariadbd instance if required")
200200
mysqld_pidfile_path = "/var/lib/mysql/{0}.pid".format(local_hostname)
201201

202202
def is_pid_running(pid):
@@ -213,7 +213,7 @@ def stop_mysqld():
213213
return False
214214

215215
if not os.path.isfile(mysqld_pidfile_path):
216-
logger.debug("No previous pid file found for mysqld")
216+
logger.debug("No previous pid file found for mariadbd")
217217
return
218218

219219
if os.stat(mysqld_pidfile_path).st_size == 0:
@@ -223,7 +223,7 @@ def stop_mysqld():
223223
return
224224

225225
logger.info(
226-
"Previous pid file found for mysqld, attempting to shut it down")
226+
"Previous pid file found for mariadbd, attempting to shut it down")
227227
with open(mysqld_pidfile_path, "r") as mysqld_pidfile:
228228
mysqld_pid = int(mysqld_pidfile.readlines()[0].rstrip('\n'))
229229

@@ -235,11 +235,11 @@ def stop_mysqld():
235235
return
236236
if not is_pid_mysqld(mysqld_pid):
237237
logger.error(
238-
"pidfile process is not mysqld, removing pidfile and panic")
238+
"pidfile process is not mariadbd, removing pidfile and panic")
239239
os.remove(mysqld_pidfile_path)
240240
sys.exit(1)
241241

242-
logger.info("pid from pidfile is mysqld")
242+
logger.info("pid from pidfile is mariadbd")
243243
os.kill(mysqld_pid, 15)
244244
try:
245245
pid, status = os.waitpid(mysqld_pid, 0)
@@ -283,7 +283,7 @@ def mysqld_write_cluster_conf(mode='run'):
283283
cluster_config.write(configfile)
284284

285285

286-
# Function to setup mysqld
286+
# Function to setup mariadbd
287287
def mysqld_bootstrap():
288288
"""Bootstrap the db if no data found in the 'bootstrap_test_dir'"""
289289
logger.info("Boostrapping Mariadb")
@@ -293,7 +293,7 @@ def mysqld_bootstrap():
293293
stop_mysqld()
294294
mysqld_write_cluster_conf(mode='bootstrap')
295295
run_cmd_with_logging([
296-
'mysql_install_db', '--user=mysql',
296+
'mariadb-install-db', '--user=mysql',
297297
"--datadir={0}".format(mysql_data_dir)
298298
], logger)
299299
if not mysql_dbaudit_username:
@@ -310,7 +310,7 @@ def mysqld_bootstrap():
310310
"GRANT PROCESS, RELOAD, LOCK TABLES, REPLICATION CLIENT ON *.* TO '{2}'@'127.0.0.1' ;\n"
311311
"CREATE OR REPLACE USER '{4}'@'%' IDENTIFIED BY '{5}' ;\n"
312312
"GRANT PROCESS, RELOAD, LOCK TABLES, REPLICATION CLIENT ON *.* TO '{4}'@'%' ;\n"
313-
# needed for mariabackup --history option
313+
# needed for mariadb-backup --history option
314314
"GRANT CREATE, INSERT ON PERCONA_SCHEMA.* TO '{4}'@'%';\n"
315315
"FLUSH PRIVILEGES ;\n"
316316
"SHUTDOWN ;".format(mysql_dbadmin_username, mysql_dbadmin_password,
@@ -328,7 +328,7 @@ def mysqld_bootstrap():
328328
"GRANT SELECT ON *.* TO '{4}'@'%' ;\n"
329329
"CREATE OR REPLACE USER '{6}'@'%' IDENTIFIED BY '{7}' ;\n"
330330
"GRANT PROCESS, RELOAD, LOCK TABLES, REPLICATION CLIENT ON *.* TO '{6}'@'%' ;\n"
331-
# needed for mariabackup --history option
331+
# needed for mariadb-backup --history option
332332
"GRANT CREATE, INSERT ON PERCONA_SCHEMA.* TO '{6}'@'%';\n"
333333
"FLUSH PRIVILEGES ;\n"
334334
"SHUTDOWN ;".format(mysql_dbadmin_username, mysql_dbadmin_password,
@@ -847,7 +847,7 @@ def launch_leader_election():
847847

848848

849849
def run_mysqld(cluster='existing'):
850-
"""Launch the mysqld instance for the pod. This will also run mysql upgrade
850+
"""Launch the mariadbd instance for the pod. This will also run mariadb upgrade
851851
if we are the 1st replica, and the rest of the cluster is already running.
852852
This senario will be triggerd either following a rolling update, as this
853853
works in reverse order for statefulset. Or restart of the 1st instance, in
@@ -868,7 +868,7 @@ def run_mysqld(cluster='existing'):
868868
mysql_data_dir = '/var/lib/mysql'
869869
db_test_dir = "{0}/mysql".format(mysql_data_dir)
870870
if os.path.isdir(db_test_dir):
871-
logger.info("Setting the admin passwords to the current value and upgrade mysql if needed")
871+
logger.info("Setting the admin passwords to the current value and upgrade mariadb if needed")
872872
if not mysql_dbaudit_username:
873873
template = (
874874
"CREATE OR REPLACE USER '{0}'@'%' IDENTIFIED BY \'{1}\' ;\n"
@@ -877,7 +877,7 @@ def run_mysqld(cluster='existing'):
877877
"GRANT PROCESS, RELOAD, LOCK TABLES, REPLICATION CLIENT ON *.* TO '{2}'@'127.0.0.1' ;\n"
878878
"CREATE OR REPLACE USER '{4}'@'%' IDENTIFIED BY '{5}' ;\n"
879879
"GRANT PROCESS, RELOAD, LOCK TABLES, REPLICATION CLIENT ON *.* TO '{4}'@'%' ;\n"
880-
# needed for mariabackup --history option
880+
# needed for mariadb-backup --history option
881881
"GRANT CREATE, INSERT ON PERCONA_SCHEMA.* TO '{4}'@'%';\n"
882882
"FLUSH PRIVILEGES ;".format(mysql_dbadmin_username, mysql_dbadmin_password,
883883
mysql_dbsst_username, mysql_dbsst_password,
@@ -892,7 +892,7 @@ def run_mysqld(cluster='existing'):
892892
"GRANT SELECT ON mysql.user TO '{4}'@'%' ;\n"
893893
"CREATE OR REPLACE USER '{6}'@'%' IDENTIFIED BY '{7}' ;\n"
894894
"GRANT PROCESS, RELOAD, LOCK TABLES, REPLICATION CLIENT ON *.* TO '{6}'@'%' ;\n"
895-
# needed for mariabackup --history option
895+
# needed for mariadb-backup --history option
896896
"GRANT CREATE, INSERT ON PERCONA_SCHEMA.* TO '{6}'@'%';\n"
897897
"FLUSH PRIVILEGES ;".format(mysql_dbadmin_username, mysql_dbadmin_password,
898898
mysql_dbsst_username, mysql_dbsst_password,
@@ -902,15 +902,15 @@ def run_mysqld(cluster='existing'):
902902
with open(bootstrap_sql_file, 'w') as f:
903903
f.write(template)
904904
f.close()
905-
# run mysqld as thread and check it's status in order to upgrade it
905+
# run mariadbd as thread and check it's status in order to upgrade it
906906
run_cmd_with_logging_thread = threading.Thread(target=run_cmd_with_logging, args=([
907907
MYSQL_BINARY_NAME, '--bind-address=127.0.0.1', '--wsrep-on=false',
908908
"--init-file={0}".format(bootstrap_sql_file)
909909
], logger))
910910
run_cmd_with_logging_thread.start()
911911
wait_mysql_status()
912-
logger.info("Upgrading local mysql instance")
913-
upgrade_res = run_cmd_with_logging(['mysql_upgrade', '--skip-write-binlog',
912+
logger.info("Upgrading local mariadb instance")
913+
upgrade_res = run_cmd_with_logging(['mariadb-upgrade', '--skip-write-binlog',
914914
"-u{0}".format(mysql_dbadmin_username), "-p{0}".format(mysql_dbadmin_password)], logger)
915915
if upgrade_res != 0:
916916
raise Exception('Mysql upgrade failed, cannot proceed')
@@ -930,14 +930,14 @@ def run_mysqld(cluster='existing'):
930930

931931

932932
def mysqld_reboot():
933-
"""Reboot a mysqld cluster."""
933+
"""Reboot a mariadbd cluster."""
934934
declare_myself_cluster_leader()
935935
set_grastate_val(key='safe_to_bootstrap', value='1')
936936
run_mysqld(cluster='new')
937937

938938

939939
def sigterm_shutdown(x, y):
940-
"""Shutdown the instance of mysqld on shutdown signal."""
940+
"""Shutdown the instance of mariadbd on shutdown signal."""
941941
logger.info("Got a sigterm from the container runtime, time to go.")
942942
stop_event.set()
943943
stop_mysqld()

charts/infra/mariadb/templates/bin/_test.sh.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ set -ex
1717

1818
rm -f /tmp/test-success
1919

20-
mysqlslap \
20+
mariadb-slap \
2121
--defaults-file=/etc/mysql/test-params.cnf \
2222
{{ include "helm-toolkit.utils.joinListWithSpace" $.Values.conf.tests.params }} -vv \
2323
--post-system="touch /tmp/test-success"

0 commit comments

Comments
 (0)