Merge "Fix race condition for grastate.dat"

This commit is contained in:
Zuul 2021-04-19 21:49:20 +00:00 committed by Gerrit Code Review
commit 688ad137e4
3 changed files with 15 additions and 3 deletions

View File

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

View File

@ -497,8 +497,19 @@ def get_grastate_val(key):
"""
logger.debug("Reading grastate.dat key={0}".format(key))
try:
with open("/var/lib/mysql/grastate.dat", "r") as myfile:
grastate_raw = [s.strip() for s in myfile.readlines()]
# This attempts to address a potential race condition with the initial
# creation of the grastate.date file where the file would exist
# however, it is not immediately populated. Testing indicated it could
# take 15-20 seconds for the file to be populated. So loop and keep
# checking up to 60 seconds. If it still isn't populated afterwards,
# the IndexError will still occur as we are seeing now without the loop.
time_end = time.time() + 60
while time.time() < time_end:
with open("/var/lib/mysql/grastate.dat", "r") as myfile:
grastate_raw = [s.strip() for s in myfile.readlines()]
if grastate_raw:
break
time.sleep(1)
return [i for i in grastate_raw
if i.startswith("{0}:".format(key))][0].split(':')[1].strip()
except IndexError:

View File

@ -13,4 +13,5 @@ mariadb:
- 0.1.10 Rename mariadb backup identities
- 0.1.11 Disable mariadb mysql history client logging
- 0.1.12 Set strict permission on mariadb data dir
- 0.1.13 Fix race condition for grastate.dat
...