From 9d31e46f00e5f07ef0f603469dbda98f0196aa14 Mon Sep 17 00:00:00 2001 From: "wu.chunyang" Date: Mon, 8 Jan 2024 16:34:46 +0800 Subject: [PATCH] Change mysql socket path to a persistent path. This patch changes the default socket patch on the host from "/var/run/mysqld" to "/var/lib/mysqld". ensuring that the database container starts properly after a Nova instance is restarted. Story: 2010599 Task: 47471 Change-Id: Idb0366ad1d73c85126e18fccd58f1e52176b63de --- .../fix-server-restart-bug-9746b2c2ed00a45a.yaml | 7 +++++++ trove/common/constants.py | 1 + trove/guestagent/datastore/mysql_common/manager.py | 4 +++- trove/guestagent/datastore/mysql_common/service.py | 13 +++++++------ .../guestagent/strategies/replication/mysql_base.py | 3 ++- 5 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 releasenotes/notes/fix-server-restart-bug-9746b2c2ed00a45a.yaml diff --git a/releasenotes/notes/fix-server-restart-bug-9746b2c2ed00a45a.yaml b/releasenotes/notes/fix-server-restart-bug-9746b2c2ed00a45a.yaml new file mode 100644 index 0000000000..06118f73a3 --- /dev/null +++ b/releasenotes/notes/fix-server-restart-bug-9746b2c2ed00a45a.yaml @@ -0,0 +1,7 @@ +--- + +fixes: + - | + Fix a bug where the mysql container is unable to recover + after a reboot of the Nova instance. + `Story 2010599 `__ \ No newline at end of file diff --git a/trove/common/constants.py b/trove/common/constants.py index ab2d27030c..afb05e0775 100644 --- a/trove/common/constants.py +++ b/trove/common/constants.py @@ -18,3 +18,4 @@ ETH1_CONFIG_PATH = "/etc/trove/eth1.json" DOCKER_NETWORK_NAME = "database-network" DOCKER_HOST_NIC_MODE = "docker-hostnic" DOCKER_BRIDGE_MODE = "bridge" +MYSQL_HOST_SOCKET_PATH = "/var/lib/mysqld" diff --git a/trove/guestagent/datastore/mysql_common/manager.py b/trove/guestagent/datastore/mysql_common/manager.py index 43580d0aac..715617f12d 100644 --- a/trove/guestagent/datastore/mysql_common/manager.py +++ b/trove/guestagent/datastore/mysql_common/manager.py @@ -21,6 +21,7 @@ from oslo_log import log as logging from trove.common import cfg from trove.common import configurations +from trove.common import constants from trove.common import exception from trove.common.notification import EndNotification from trove.common import utils @@ -115,7 +116,8 @@ class MySqlManager(manager.Manager): # Set /var/run/mysqld to allow localhost access. volumes_mapping = { '/var/lib/mysql': {'bind': '/var/lib/mysql', 'mode': 'rw'}, - "/var/run/mysqld": {"bind": "/var/run/mysqld", "mode": "ro"}, + constants.MYSQL_HOST_SOCKET_PATH: {"bind": "/var/run/mysqld", + "mode": "ro"}, '/tmp': {'bind': '/tmp', 'mode': 'rw'} } self.app.create_backup(context, backup_info, diff --git a/trove/guestagent/datastore/mysql_common/service.py b/trove/guestagent/datastore/mysql_common/service.py index 7dbb01a8f7..933977b6ef 100644 --- a/trove/guestagent/datastore/mysql_common/service.py +++ b/trove/guestagent/datastore/mysql_common/service.py @@ -44,8 +44,9 @@ from trove.instance import service_status LOG = logging.getLogger(__name__) CONF = cfg.CONF ADMIN_USER_NAME = "os_admin" -CONNECTION_STR_FORMAT = ("mysql+pymysql://%s:%s@localhost/?" - "unix_socket=/var/run/mysqld/mysqld.sock") +CONNECTION_STR_FORMAT = ("mysql+pymysql://%s:%s@localhost/?" + + f"unix_socket={constants.MYSQL_HOST_SOCKET_PATH}" + "/mysqld.sock") ENGINE = None INCLUDE_MARKER_OPERATORS = { True: ">=", @@ -590,7 +591,7 @@ class BaseMySqlApp(service.BaseDbApp): user = "%s:%s" % (CONF.database_service_uid, CONF.database_service_uid) # Create folders for mysql on localhost - for folder in ['/etc/mysql', '/var/run/mysqld', + for folder in ['/etc/mysql', constants.MYSQL_HOST_SOCKET_PATH, '/etc/mysql/mysql.conf.d']: operating_system.ensure_directory( folder, user=CONF.database_service_uid, @@ -599,8 +600,8 @@ class BaseMySqlApp(service.BaseDbApp): volumes = { "/etc/mysql": {"bind": "/etc/mysql", "mode": "rw"}, - "/var/run/mysqld": {"bind": "/var/run/mysqld", - "mode": "rw"}, + constants.MYSQL_HOST_SOCKET_PATH: {"bind": "/var/run/mysqld", + "mode": "rw"}, "/var/lib/mysql": {"bind": "/var/lib/mysql", "mode": "rw"}, } if extra_volumes: @@ -671,7 +672,7 @@ class BaseMySqlApp(service.BaseDbApp): LOG.info("Restarting mysql") # Ensure folders permission for database. - for folder in ['/etc/mysql', '/var/run/mysqld', + for folder in ['/etc/mysql', constants.MYSQL_HOST_SOCKET_PATH, '/etc/mysql/mysql.conf.d']: operating_system.ensure_directory( folder, user=CONF.database_service_uid, diff --git a/trove/guestagent/strategies/replication/mysql_base.py b/trove/guestagent/strategies/replication/mysql_base.py index d3ecc48324..3ed20de4b4 100644 --- a/trove/guestagent/strategies/replication/mysql_base.py +++ b/trove/guestagent/strategies/replication/mysql_base.py @@ -95,7 +95,8 @@ class MysqlReplicationBase(base.Replication): volumes_mapping = { '/var/lib/mysql': {'bind': '/var/lib/mysql', 'mode': 'rw'}, - "/var/run/mysqld": {"bind": "/var/run/mysqld", "mode": "ro"}, + constants.MYSQL_HOST_SOCKET_PATH: {"bind": "/var/run/mysqld", + "mode": "ro"}, '/tmp': {'bind': '/tmp', 'mode': 'rw'} } service.create_backup(context, snapshot_info,