Skip to content

Commit

Permalink
*: Save Xenon's metadata to persistent storage. radondb#406
Browse files Browse the repository at this point in the history
  • Loading branch information
runkecheng committed Mar 15, 2022
1 parent 49384da commit 39dccf5
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 10 deletions.
1 change: 1 addition & 0 deletions mysqlcluster/container/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ func (c *backupSidecar) getVolumeMounts() []corev1.VolumeMount {
{
Name: utils.DataVolumeName,
MountPath: utils.DataVolumeMountPath,
SubPath: utils.MysqlDataSubPath,
},
{
Name: utils.LogsVolumeName,
Expand Down
1 change: 1 addition & 0 deletions mysqlcluster/container/init_mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func (c *initMysql) getVolumeMounts() []corev1.VolumeMount {
{
Name: utils.DataVolumeName,
MountPath: utils.DataVolumeMountPath,
SubPath: utils.MysqlDataSubPath,
},
{
Name: utils.LogsVolumeName,
Expand Down
1 change: 1 addition & 0 deletions mysqlcluster/container/init_mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ var (
{
Name: utils.DataVolumeName,
MountPath: utils.DataVolumeMountPath,
SubPath: utils.MysqlDataSubPath,
},
{
Name: utils.LogsVolumeName,
Expand Down
6 changes: 6 additions & 0 deletions mysqlcluster/container/init_sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,12 @@ 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.XenonMetaDataSubPath,
},
)
}
Expand Down
12 changes: 10 additions & 2 deletions mysqlcluster/container/init_sidecar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,10 +455,18 @@ func TestGetInitSidecarVolumeMounts(t *testing.T) {
persistenceCase := EnsureContainer("init-sidecar", &testPersistenceCluster)
persistenceVolumeMounts := make([]corev1.VolumeMount, 6, 7)
copy(persistenceVolumeMounts, defaultInitsidecarVolumeMounts)
persistenceVolumeMounts = append(persistenceVolumeMounts, corev1.VolumeMount{
persistenceVolumeMounts = append(persistenceVolumeMounts,
corev1.VolumeMount{
Name: utils.DataVolumeName,
MountPath: utils.DataVolumeMountPath,
})
SubPath: utils.MysqlDataSubPath,
},
corev1.VolumeMount{
Name: utils.DataVolumeName,
MountPath: utils.XenonDataVolumeMountPath,
SubPath: utils.XenonMetaDataSubPath,
},
)
assert.Equal(t, persistenceVolumeMounts, persistenceCase.VolumeMounts)
}
}
1 change: 1 addition & 0 deletions mysqlcluster/container/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ func (c *mysql) getVolumeMounts() []corev1.VolumeMount {
{
Name: utils.DataVolumeName,
MountPath: utils.DataVolumeMountPath,
SubPath: utils.MysqlDataSubPath,
},
{
Name: utils.LogsVolumeName,
Expand Down
1 change: 1 addition & 0 deletions mysqlcluster/container/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ func TestGetMysqlVolumeMounts(t *testing.T) {
{
Name: "data",
MountPath: "/var/lib/mysql",
SubPath: "mysql",
},
{
Name: "logs",
Expand Down
5 changes: 5 additions & 0 deletions mysqlcluster/container/xenon.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ func (c *xenon) getVolumeMounts() []corev1.VolumeMount {
Name: utils.ScriptsVolumeName,
MountPath: utils.ScriptsVolumeMountPath,
},
{
Name: utils.DataVolumeName,
MountPath: utils.XenonDataVolumeMountPath,
SubPath: utils.XenonMetaDataSubPath,
},
{
Name: utils.XenonVolumeName,
MountPath: utils.XenonVolumeMountPath,
Expand Down
5 changes: 5 additions & 0 deletions mysqlcluster/container/xenon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ func TestGetXenonVolumeMounts(t *testing.T) {
Name: "scripts",
MountPath: "/scripts",
},
{
Name: "data",
MountPath: "/var/lib/xenon",
SubPath: "xenon",
},
{
Name: "xenon",
MountPath: "/etc/xenon",
Expand Down
4 changes: 4 additions & 0 deletions sidecar/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ 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(xenonMetaDataPath, uid, gid); err != nil {
return fmt.Errorf("failed to chown %s: %s", xenonMetaDataPath, err)
}
}

// copy appropriate my.cnf from config-map to config mount.
Expand Down
2 changes: 2 additions & 0 deletions sidecar/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ var (
// dataPath is the mysql data path.
dataPath = utils.DataVolumeMountPath

xenonMetaDataPath = utils.XenonDataVolumeMountPath

// // scriptsPath is the scripts path used for xenon.
// scriptsPath = utils.ScriptsVolumeMountPath

Expand Down
19 changes: 11 additions & 8 deletions utils/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,17 @@ const (
InitFileVolumeName = "init-mysql"

// volumes mount path.
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"
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"
XenonMetaDataSubPath = "xenon"

// Volume timezone name.
SysLocalTimeZone = "localtime"
Expand Down

0 comments on commit 39dccf5

Please sign in to comment.