Skip to content

Commit ace1801

Browse files
committed
Merge branch 'mount-points' into 'master'
fix volume paths for socket mount points - compare with mount point directory by a prefix - add a new line to recovery configuration - mount a socket directory even if the prefix does not match exactly See merge request postgres-ai/database-lab!177
2 parents 2669d84 + 640319d commit ace1801

File tree

8 files changed

+21
-22
lines changed

8 files changed

+21
-22
lines changed

pkg/retrieval/engine/postgres/logical/dump.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,7 @@ func (d *DumpJob) buildHostConfig(ctx context.Context) (*container.HostConfig, e
361361
NetworkMode: d.getContainerNetworkMode(),
362362
}
363363

364-
if err := tools.AddVolumesToHostConfig(ctx, d.dockerClient, hostConfig,
365-
d.globalCfg.MountDir, d.globalCfg.DataDir()); err != nil {
364+
if err := tools.AddVolumesToHostConfig(ctx, d.dockerClient, hostConfig, d.globalCfg.DataDir()); err != nil {
366365
return nil, err
367366
}
368367

pkg/retrieval/engine/postgres/logical/restore.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,7 @@ func (r *RestoreJob) buildContainerConfig(password string) *container.Config {
215215
func (r *RestoreJob) buildHostConfig(ctx context.Context) (*container.HostConfig, error) {
216216
hostConfig := &container.HostConfig{}
217217

218-
if err := tools.AddVolumesToHostConfig(ctx, r.dockerClient, hostConfig,
219-
r.globalCfg.MountDir, r.globalCfg.DataDir()); err != nil {
218+
if err := tools.AddVolumesToHostConfig(ctx, r.dockerClient, hostConfig, r.globalCfg.DataDir()); err != nil {
220219
return nil, err
221220
}
222221

pkg/retrieval/engine/postgres/physical/custom.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func (c *custom) GetRecoveryConfig() []byte {
3838
buffer := bytes.Buffer{}
3939

4040
if c.options.RestoreCommand != "" {
41+
buffer.WriteString("\n")
4142
buffer.WriteString("standby_mode = 'on'\n")
4243
buffer.WriteString(fmt.Sprintf("restore_command = '%s'\n", c.options.RestoreCommand))
4344
}

pkg/retrieval/engine/postgres/physical/physical.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,7 @@ func (r *RestoreJob) buildContainerConfig(password, label string) *container.Con
392392
func (r *RestoreJob) buildHostConfig(ctx context.Context) (*container.HostConfig, error) {
393393
hostConfig := &container.HostConfig{}
394394

395-
if err := tools.AddVolumesToHostConfig(ctx, r.dockerClient, hostConfig,
396-
r.globalCfg.MountDir, r.globalCfg.DataDir()); err != nil {
395+
if err := tools.AddVolumesToHostConfig(ctx, r.dockerClient, hostConfig, r.globalCfg.DataDir()); err != nil {
397396
return nil, err
398397
}
399398

pkg/retrieval/engine/postgres/physical/wal_g.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func (w *walg) GetRestoreCommand() string {
3939
func (w *walg) GetRecoveryConfig() []byte {
4040
buffer := bytes.Buffer{}
4141

42+
buffer.WriteString("\n")
4243
buffer.WriteString("standby_mode = 'on'\n")
4344
buffer.WriteString("restore_command = 'wal-g wal-fetch %f %p'\n")
4445

pkg/retrieval/engine/postgres/snapshot/physical.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,7 @@ func (p *PhysicalInitial) buildHostConfig(ctx context.Context, clonePath string)
518518
Sysctls: p.options.Sysctls,
519519
}
520520

521-
if err := tools.AddVolumesToHostConfig(ctx, p.dockerClient, hostConfig,
522-
p.globalCfg.MountDir, clonePath); err != nil {
521+
if err := tools.AddVolumesToHostConfig(ctx, p.dockerClient, hostConfig, clonePath); err != nil {
523522
return nil, err
524523
}
525524

pkg/retrieval/engine/postgres/tools/tools.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func StartingPostgresConfig(pgDataDir, pgVersion string) types.ExecConfig {
116116

117117
// AddVolumesToHostConfig adds volumes to container host configuration depends on process environment.
118118
func AddVolumesToHostConfig(ctx context.Context, dockerClient *client.Client, hostConfig *container.HostConfig,
119-
mountDir, dataDir string) error {
119+
dataDir string) error {
120120
hostInfo, err := host.Info()
121121
if err != nil {
122122
return errors.Wrap(err, "failed to get host info")
@@ -130,7 +130,7 @@ func AddVolumesToHostConfig(ctx context.Context, dockerClient *client.Client, ho
130130
return err
131131
}
132132

133-
hostConfig.Mounts = GetMountsFromMountPoints(mountDir, dataDir, inspection.Mounts)
133+
hostConfig.Mounts = GetMountsFromMountPoints(dataDir, inspection.Mounts)
134134

135135
log.Dbg(hostConfig.Mounts)
136136
} else {
@@ -145,12 +145,12 @@ func AddVolumesToHostConfig(ctx context.Context, dockerClient *client.Client, ho
145145
}
146146

147147
// GetMountsFromMountPoints creates a list of mounts.
148-
func GetMountsFromMountPoints(mountDir, dataDir string, mountPoints []types.MountPoint) []mount.Mount {
148+
func GetMountsFromMountPoints(dataDir string, mountPoints []types.MountPoint) []mount.Mount {
149149
mounts := make([]mount.Mount, 0, len(mountPoints))
150150

151151
for _, mountPoint := range mountPoints {
152152
// Rewrite mounting to data directory.
153-
if mountDir == mountPoint.Destination {
153+
if strings.HasPrefix(dataDir, mountPoint.Destination) {
154154
suffix := strings.TrimPrefix(dataDir, mountPoint.Destination)
155155
mountPoint.Source = path.Join(mountPoint.Source, suffix)
156156
mountPoint.Destination = dataDir

pkg/services/provision/docker/docker.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,18 @@ func buildMountVolumes(r runners.Runner, c *resources.AppConfig, containerID str
7979
return nil, errors.Wrap(err, "failed to interpret mount paths")
8080
}
8181

82-
mounts := tools.GetMountsFromMountPoints(c.MountDir, c.DataDir(), mountPoints)
82+
mounts := tools.GetMountsFromMountPoints(c.DataDir(), mountPoints)
8383
volumes := make([]string, 0, len(mounts))
8484

85-
for _, mount := range mounts {
85+
for _, mountPoint := range mountPoints {
8686
// Add extra mount for socket directories.
87-
if mount.Target == c.DataDir() && strings.HasPrefix(c.UnixSocketCloneDir, c.MountDir) {
88-
volumes = append(volumes, buildSocketMount(c, mount.Source))
87+
if strings.HasPrefix(c.UnixSocketCloneDir, mountPoint.Destination) {
88+
volumes = append(volumes, buildSocketMount(c.UnixSocketCloneDir, mountPoint.Source, mountPoint.Destination))
89+
break
8990
}
91+
}
9092

93+
for _, mount := range mounts {
9194
volume := fmt.Sprintf("--volume %s:%s", mount.Source, mount.Target)
9295

9396
if mount.BindOptions != nil && mount.BindOptions.Propagation != "" {
@@ -101,13 +104,11 @@ func buildMountVolumes(r runners.Runner, c *resources.AppConfig, containerID str
101104
}
102105

103106
// buildSocketMount builds a socket directory mounting rely on dataDir mounting.
104-
func buildSocketMount(c *resources.AppConfig, hostDataDir string) string {
105-
socketPath := strings.TrimPrefix(c.UnixSocketCloneDir, c.MountDir)
106-
dataPath := strings.TrimPrefix(c.DataDir(), c.MountDir)
107-
externalMount := strings.TrimSuffix(hostDataDir, dataPath)
108-
hostSocketDir := path.Join(externalMount, socketPath)
107+
func buildSocketMount(socketDir, hostDataDir, destinationDir string) string {
108+
socketPath := strings.TrimPrefix(socketDir, destinationDir)
109+
hostSocketDir := path.Join(hostDataDir, socketPath)
109110

110-
return fmt.Sprintf(" --volume %s:%s:rshared", hostSocketDir, c.UnixSocketCloneDir)
111+
return fmt.Sprintf(" --volume %s:%s:rshared", hostSocketDir, socketDir)
111112
}
112113

113114
func createSocketCloneDir(socketCloneDir string) error {

0 commit comments

Comments
 (0)