From 06d5bc01a26ad8014646cc954eb96370553aaf03 Mon Sep 17 00:00:00 2001 From: runkecheng <1131648942@qq.com> Date: Mon, 11 Apr 2022 15:30:14 +0800 Subject: [PATCH] *: Save Xenon's metadata to persistent storage. #406 Revert "Merge pull request #413 from runkecheng/save_xenon_metadata" This reverts commit a6386c7b821534527679aa60cece1d9726a1c06e, reversing changes made to f6932c6027d0d7a4b7ec51af97816f84e7eb24a1. Subpath does not work in some environments, so we decided to share DATA storage volumes directly. --- hack/xenon/Dockerfile | 6 +++--- mysqlcluster/container/backup.go | 1 - mysqlcluster/container/init_mysql.go | 1 - mysqlcluster/container/init_mysql_test.go | 1 - mysqlcluster/container/init_sidecar.go | 6 ------ mysqlcluster/container/init_sidecar_test.go | 13 +------------ mysqlcluster/container/mysql.go | 1 - mysqlcluster/container/mysql_test.go | 1 - mysqlcluster/container/xenon.go | 9 ++++----- mysqlcluster/container/xenon_test.go | 9 ++++----- sidecar/config.go | 2 +- sidecar/init.go | 4 ---- sidecar/util.go | 2 -- utils/constants.go | 19 ++++++++----------- 14 files changed, 21 insertions(+), 54 deletions(-) diff --git a/hack/xenon/Dockerfile b/hack/xenon/Dockerfile index 53f1d419..3e217b6b 100644 --- a/hack/xenon/Dockerfile +++ b/hack/xenon/Dockerfile @@ -22,11 +22,11 @@ FROM alpine:3.13 RUN set -ex \ && addgroup -g 1001 mysql && adduser -u 1001 -g 1001 -S mysql \ && apk add --no-cache curl bash jq \ - && mkdir -p /etc/xenon /var/lib/xenon /lib64 \ + && mkdir -p /etc/xenon /lib64 \ && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2 \ && echo "/etc/xenon/xenon.json" > /config.path \ # allow to change config files - && chown -R 1001:1001 /etc/xenon /var/lib/xenon + && chown -R 1001:1001 /etc/xenon COPY --from=builder /go/src/github.com/radondb/xenon/bin/xenon /usr/local/bin/xenon COPY --from=builder /go/src/github.com/radondb/xenon/bin/xenoncli /usr/local/bin/xenoncli @@ -34,7 +34,7 @@ COPY --from=builder /go/src/github.com/radondb/xenon/bin/xenoncli /usr/local/bin USER 1001 WORKDIR / EXPOSE 8801 -VOLUME ["/var/lib/xenon", "/etc/xenon"] +VOLUME ["/etc/xenon"] ENTRYPOINT ["xenon"] CMD ["-c", "/etc/xenon/xenon.json"] diff --git a/mysqlcluster/container/backup.go b/mysqlcluster/container/backup.go index 8a401a49..b42eae83 100644 --- a/mysqlcluster/container/backup.go +++ b/mysqlcluster/container/backup.go @@ -134,7 +134,6 @@ func (c *backupSidecar) getVolumeMounts() []corev1.VolumeMount { { Name: utils.DataVolumeName, MountPath: utils.DataVolumeMountPath, - SubPath: utils.MysqlDataSubPath, }, { Name: utils.LogsVolumeName, diff --git a/mysqlcluster/container/init_mysql.go b/mysqlcluster/container/init_mysql.go index b43992ef..54c8b541 100644 --- a/mysqlcluster/container/init_mysql.go +++ b/mysqlcluster/container/init_mysql.go @@ -115,7 +115,6 @@ func (c *initMysql) getVolumeMounts() []corev1.VolumeMount { { Name: utils.DataVolumeName, MountPath: utils.DataVolumeMountPath, - SubPath: utils.MysqlDataSubPath, }, { Name: utils.LogsVolumeName, diff --git a/mysqlcluster/container/init_mysql_test.go b/mysqlcluster/container/init_mysql_test.go index 6b51d9b4..b855be1e 100644 --- a/mysqlcluster/container/init_mysql_test.go +++ b/mysqlcluster/container/init_mysql_test.go @@ -59,7 +59,6 @@ var ( { Name: utils.DataVolumeName, MountPath: utils.DataVolumeMountPath, - SubPath: utils.MysqlDataSubPath, }, { Name: utils.LogsVolumeName, diff --git a/mysqlcluster/container/init_sidecar.go b/mysqlcluster/container/init_sidecar.go index f1e47502..9c16eb7f 100644 --- a/mysqlcluster/container/init_sidecar.go +++ b/mysqlcluster/container/init_sidecar.go @@ -202,12 +202,6 @@ func (c *initSidecar) getVolumeMounts() []corev1.VolumeMount { corev1.VolumeMount{ Name: utils.DataVolumeName, MountPath: utils.DataVolumeMountPath, - SubPath: utils.MysqlDataSubPath, - }, - corev1.VolumeMount{ - Name: utils.DataVolumeName, - MountPath: utils.XenonDataVolumeMountPath, - SubPath: utils.XenonDataSubPath, }, ) } diff --git a/mysqlcluster/container/init_sidecar_test.go b/mysqlcluster/container/init_sidecar_test.go index 86981882..3f6274d2 100644 --- a/mysqlcluster/container/init_sidecar_test.go +++ b/mysqlcluster/container/init_sidecar_test.go @@ -455,18 +455,7 @@ func TestGetInitSidecarVolumeMounts(t *testing.T) { persistenceCase := EnsureContainer("init-sidecar", &testPersistenceCluster) persistenceVolumeMounts := make([]corev1.VolumeMount, 6, 7) copy(persistenceVolumeMounts, defaultInitsidecarVolumeMounts) - persistenceVolumeMounts = append(persistenceVolumeMounts, - corev1.VolumeMount{ - Name: utils.DataVolumeName, - MountPath: utils.DataVolumeMountPath, - SubPath: utils.MysqlDataSubPath, - }, - corev1.VolumeMount{ - Name: utils.DataVolumeName, - MountPath: utils.XenonDataVolumeMountPath, - SubPath: utils.XenonDataSubPath, - }, - ) + persistenceVolumeMounts = append(persistenceVolumeMounts, corev1.VolumeMount{Name: utils.DataVolumeName, MountPath: utils.DataVolumeMountPath}) assert.Equal(t, persistenceVolumeMounts, persistenceCase.VolumeMounts) } } diff --git a/mysqlcluster/container/mysql.go b/mysqlcluster/container/mysql.go index 8a00fd61..d01f9f27 100644 --- a/mysqlcluster/container/mysql.go +++ b/mysqlcluster/container/mysql.go @@ -141,7 +141,6 @@ func (c *mysql) getVolumeMounts() []corev1.VolumeMount { { Name: utils.DataVolumeName, MountPath: utils.DataVolumeMountPath, - SubPath: utils.MysqlDataSubPath, }, { Name: utils.LogsVolumeName, diff --git a/mysqlcluster/container/mysql_test.go b/mysqlcluster/container/mysql_test.go index 49dddb53..e502021a 100644 --- a/mysqlcluster/container/mysql_test.go +++ b/mysqlcluster/container/mysql_test.go @@ -147,7 +147,6 @@ func TestGetMysqlVolumeMounts(t *testing.T) { { Name: "data", MountPath: "/var/lib/mysql", - SubPath: "mysql", }, { Name: "logs", diff --git a/mysqlcluster/container/xenon.go b/mysqlcluster/container/xenon.go index f1bd5c15..2bab3a71 100644 --- a/mysqlcluster/container/xenon.go +++ b/mysqlcluster/container/xenon.go @@ -114,15 +114,14 @@ func (c *xenon) getVolumeMounts() []corev1.VolumeMount { Name: utils.ScriptsVolumeName, MountPath: utils.ScriptsVolumeMountPath, }, - { - Name: utils.DataVolumeName, - MountPath: utils.XenonDataVolumeMountPath, - SubPath: utils.XenonDataSubPath, - }, { Name: utils.XenonVolumeName, MountPath: utils.XenonVolumeMountPath, }, + { + Name: utils.DataVolumeName, + MountPath: utils.DataVolumeMountPath, + }, { Name: utils.SysLocalTimeZone, MountPath: utils.SysLocalTimeZoneMountPath, diff --git a/mysqlcluster/container/xenon_test.go b/mysqlcluster/container/xenon_test.go index d67a18cf..3acd0f46 100644 --- a/mysqlcluster/container/xenon_test.go +++ b/mysqlcluster/container/xenon_test.go @@ -134,15 +134,14 @@ func TestGetXenonVolumeMounts(t *testing.T) { Name: "scripts", MountPath: "/scripts", }, - { - Name: "data", - MountPath: "/var/lib/xenon", - SubPath: "xenon", - }, { Name: "xenon", MountPath: "/etc/xenon", }, + { + Name: "data", + MountPath: "/var/lib/mysql", + }, { Name: utils.SysLocalTimeZone, MountPath: "/etc/localtime", diff --git a/sidecar/config.go b/sidecar/config.go index eeaa5552..a80d2aad 100644 --- a/sidecar/config.go +++ b/sidecar/config.go @@ -344,7 +344,7 @@ func (cfg *Config) buildXenonConf() []byte { "election-timeout": %d, "admit-defeat-hearbeat-count": %d, "heartbeat-timeout": %d, - "meta-datadir": "/var/lib/xenon/", + "meta-datadir": "/var/lib/mysql/xenon", "semi-sync-degrade": true, "purge-binlog-disabled": true, "super-idle": false diff --git a/sidecar/init.go b/sidecar/init.go index 6b8ba015..e41466df 100644 --- a/sidecar/init.go +++ b/sidecar/init.go @@ -133,10 +133,6 @@ func runInitCommand(cfg *Config) error { if err = os.Chown(dataPath, uid, gid); err != nil { return fmt.Errorf("failed to chown %s: %s", dataPath, err) } - // chown -R mysql:mysql /var/lib/xenon. - if err = os.Chown(xenonDataPath, uid, gid); err != nil { - return fmt.Errorf("failed to chown %s: %s", xenonDataPath, err) - } } // copy appropriate my.cnf from config-map to config mount. diff --git a/sidecar/util.go b/sidecar/util.go index 71570dd1..cfbf140b 100644 --- a/sidecar/util.go +++ b/sidecar/util.go @@ -45,8 +45,6 @@ var ( // dataPath is the mysql data path. dataPath = utils.DataVolumeMountPath - // xenonMetaDataPath is the xenon metadata path. - xenonDataPath = utils.XenonDataVolumeMountPath // // scriptsPath is the scripts path used for xenon. // scriptsPath = utils.ScriptsVolumeMountPath diff --git a/utils/constants.go b/utils/constants.go index b291caab..6736aea3 100644 --- a/utils/constants.go +++ b/utils/constants.go @@ -99,17 +99,14 @@ const ( InitFileVolumeName = "init-mysql" // volumes mount path. - ConfVolumeMountPath = "/etc/mysql" - ConfMapVolumeMountPath = "/mnt/config-map" - LogsVolumeMountPath = "/var/log/mysql" - DataVolumeMountPath = "/var/lib/mysql" - XenonDataVolumeMountPath = "/var/lib/xenon" - SysVolumeMountPath = "/host-sys" - ScriptsVolumeMountPath = "/scripts" - XenonVolumeMountPath = "/etc/xenon" - InitFileVolumeMountPath = "/docker-entrypoint-initdb.d" - MysqlDataSubPath = "mysql" - XenonDataSubPath = "xenon" + ConfVolumeMountPath = "/etc/mysql" + ConfMapVolumeMountPath = "/mnt/config-map" + LogsVolumeMountPath = "/var/log/mysql" + DataVolumeMountPath = "/var/lib/mysql" + SysVolumeMountPath = "/host-sys" + ScriptsVolumeMountPath = "/scripts" + XenonVolumeMountPath = "/etc/xenon" + InitFileVolumeMountPath = "/docker-entrypoint-initdb.d" // Volume timezone name. SysLocalTimeZone = "localtime"