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
This commit is contained in:
wu.chunyang 2024-01-08 16:34:46 +08:00
parent ca28382ed9
commit 9d31e46f00
5 changed files with 20 additions and 8 deletions

View File

@ -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 <https://storyboard.openstack.org/#!/story/2010599>`__

View File

@ -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"

View File

@ -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,

View File

@ -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,

View File

@ -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,