[mariadb] Stop running threads on sigkill

Stop monitor cluster and leader election threads on sigkill.
This allows to terminate all threads from start.py and actually
exit earlier than terminationGracePeriod in statefulset.
Drop preStop hook which is redundant with stop_mysqld() function call.

Change-Id: Ibc4b7604f00b1c5b3a398370dafed4d19929fd7d
This commit is contained in:
Vasyl Saienko 2023-05-28 18:44:09 +00:00
parent 6d7fba0c43
commit ef707fa3f3
6 changed files with 18 additions and 34 deletions

View File

@ -15,7 +15,7 @@ apiVersion: v1
appVersion: v10.6.7
description: OpenStack-Helm MariaDB
name: mariadb
version: 0.2.55
version: 0.2.56
home: https://mariadb.com/kb/en/
icon: http://badges.mariadb.org/mariadb-badge-180x60.png
sources:

View File

@ -762,18 +762,23 @@ def check_if_i_lead():
return False
def monitor_cluster():
def monitor_cluster(stop_event):
"""Function to kick off grastate configmap updating thread"""
while True:
if stop_event.is_set():
logger.info("Stopped monitor_cluster thread")
break
try:
update_grastate_configmap()
except Exception as error:
logger.error("Error updating grastate configmap: {0}".format(error))
time.sleep(state_configmap_update_period)
# Stop event
stop_event = threading.Event()
# Setup the thread for the cluster monitor
monitor_cluster_thread = threading.Thread(target=monitor_cluster, args=())
monitor_cluster_thread = threading.Thread(target=monitor_cluster, args=(stop_event,))
monitor_cluster_thread.daemon = True
@ -783,9 +788,12 @@ def launch_cluster_monitor():
monitor_cluster_thread.start()
def leader_election():
def leader_election(stop_event):
"""Function to kick off leader election thread"""
while True:
if stop_event.is_set():
logger.info("Stopped leader_election thread")
break
try:
deadmans_leader_election()
except Exception as error:
@ -794,7 +802,7 @@ def leader_election():
# Setup the thread for the leader election
leader_election_thread = threading.Thread(target=leader_election, args=())
leader_election_thread = threading.Thread(target=leader_election, args=(stop_event,))
leader_election_thread.daemon = True
@ -886,7 +894,11 @@ def mysqld_reboot():
def sigterm_shutdown(x, y):
"""Shutdown the instance of mysqld on shutdown signal."""
logger.info("Got a sigterm from the container runtime, time to go.")
stop_event.set()
stop_mysqld()
monitor_cluster_thread.join()
leader_election_thread.join()
sys.exit(0)
# Register the signal to the handler

View File

@ -1,22 +0,0 @@
#!/bin/bash
{{/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/}}
set -xe
exec mysqladmin \
--defaults-file=/etc/mysql/admin_user.cnf \
--host=localhost \
--connect-timeout 2 \
shutdown

View File

@ -33,8 +33,6 @@ data:
{{ tuple "bin/_liveness.sh.tpl" . | include "helm-toolkit.utils.template" | indent 4 }}
start.py: |
{{ tuple "bin/_start.py.tpl" . | include "helm-toolkit.utils.template" | indent 4 }}
stop.sh: |
{{ tuple "bin/_stop.sh.tpl" . | include "helm-toolkit.utils.template" | indent 4 }}
test.sh: |
{{ tuple "bin/_test.sh.tpl" . | include "helm-toolkit.utils.template" | indent 4 }}
{{- if .Values.conf.backup.enabled }}

View File

@ -208,11 +208,6 @@ spec:
containerPort: {{ tuple "oslo_db" "direct" "sst" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }}
command:
- /tmp/start.py
lifecycle:
preStop:
exec:
command:
- /tmp/stop.sh
{{ dict "envAll" . "component" "server" "container" "mariadb" "type" "readiness" "probeTemplate" (include "mariadbReadinessProbe" . | fromYaml) | include "helm-toolkit.snippets.kubernetes_probe" | indent 10 }}
{{ dict "envAll" . "component" "server" "container" "mariadb" "type" "liveness" "probeTemplate" (include "mariadbLivenessProbe" . | fromYaml) | include "helm-toolkit.snippets.kubernetes_probe" | indent 10 }}
volumeMounts:

View File

@ -71,4 +71,5 @@ mariadb:
- 0.2.53 Use constant for mysql binary name
- 0.2.54 Improve leader election on cold start
- 0.2.55 Improve python3 compatibility
- 0.2.56 Stop running threads on sigkill
...