Skip to content

Commit e6baac3

Browse files
committed
Merge branch '225-customize-shared-memory' into 'master'
feat: be able to tune shared memory for clone containers (#225) Closes #225 See merge request postgres-ai/database-lab!241
2 parents 0375798 + 9af54a7 commit e6baac3

File tree

7 files changed

+39
-13
lines changed

7 files changed

+39
-13
lines changed

configs/config.example.logical_generic.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ provision:
9494
# existing users to log in with old passwords.
9595
keepUserPasswords: false
9696

97+
# Custom parameters for clone containers, see
98+
# https://docs.docker.com/engine/reference/run/#runtime-constraints-on-resources
99+
containerConfig:
100+
"shm-size": 256MB
101+
97102
# Data retrieval flow. This section defines both initial retrieval, and rules
98103
# to keep the data directory in a synchronized state with the source. Both are optional:
99104
# you may already have the data directory, so neither initial retrieval nor

configs/config.example.logical_rds_iam.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ provision:
9494
# existing users to log in with old passwords.
9595
keepUserPasswords: false
9696

97+
# Custom parameters for clone containers (https://docs.docker.com/engine/reference/run/#runtime-constraints-on-resources).
98+
containerConfig:
99+
"shm-size": 256MB
100+
97101
# Data retrieval flow. This section defines both initial retrieval, and rules
98102
# to keep the data directory in a synchronized state with the source. Both are optional:
99103
# you may already have the data directory, so neither initial retrieval nor

configs/config.example.physical_generic.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ provision:
9494
# existing users to log in with old passwords.
9595
keepUserPasswords: false
9696

97+
# Custom parameters for clone containers (https://docs.docker.com/engine/reference/run/#runtime-constraints-on-resources).
98+
containerConfig:
99+
"shm-size": 256MB
100+
97101
# Data retrieval flow. This section defines both initial retrieval, and rules
98102
# to keep the data directory in a synchronized state with the source. Both are optional:
99103
# you may already have the data directory, so neither initial retrieval nor

configs/config.example.physical_walg.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ provision:
9494
# existing users to log in with old passwords.
9595
keepUserPasswords: false
9696

97+
# Custom parameters for clone containers (https://docs.docker.com/engine/reference/run/#runtime-constraints-on-resources).
98+
containerConfig:
99+
"shm-size": 256MB
100+
97101
# Data retrieval flow. This section defines both initial retrieval, and rules
98102
# to keep the data directory in a synchronized state with the source. Both are optional:
99103
# you may already have the data directory, so neither initial retrieval nor

pkg/services/provision/docker/docker.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ func RunContainer(r runners.Runner, c *resources.AppConfig) (string, error) {
5151
return "", errors.Wrap(err, "failed to create socket clone directory")
5252
}
5353

54+
containerFlags := make([]string, 0, len(c.ContainerConf))
55+
for flagName, flagValue := range c.ContainerConf {
56+
containerFlags = append(containerFlags, fmt.Sprintf("--%s=%s", flagName, flagValue))
57+
}
58+
5459
instancePort := strconv.Itoa(int(c.Port))
5560
dockerRunCmd := strings.Join([]string{
5661
"docker run",
@@ -61,6 +66,7 @@ func RunContainer(r runners.Runner, c *resources.AppConfig) (string, error) {
6166
strings.Join(volumes, " "),
6267
"--label", labelClone,
6368
"--label", c.Pool.Name,
69+
strings.Join(containerFlags, " "),
6470
c.DockerImage,
6571
"-p", instancePort,
6672
"-k", unixSocketCloneDir,

pkg/services/provision/mode_local.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ type PortPool struct {
4343

4444
// Config defines configuration for provisioning.
4545
type Config struct {
46-
PortPool PortPool `yaml:"portPool"`
47-
DockerImage string `yaml:"dockerImage"`
48-
UseSudo bool `yaml:"useSudo"`
49-
KeepUserPasswords bool `yaml:"keepUserPasswords"`
46+
PortPool PortPool `yaml:"portPool"`
47+
DockerImage string `yaml:"dockerImage"`
48+
UseSudo bool `yaml:"useSudo"`
49+
KeepUserPasswords bool `yaml:"keepUserPasswords"`
50+
ContainerConfig map[string]string `yaml:"containerConfig"`
5051
}
5152

5253
// Provisioner describes a struct for ports and clones management.
@@ -465,12 +466,13 @@ func (p *Provisioner) stopPoolSessions(fsm pool.FSManager) error {
465466

466467
func (p *Provisioner) getAppConfig(pool *resources.Pool, name string, port uint) *resources.AppConfig {
467468
appConfig := &resources.AppConfig{
468-
CloneName: name,
469-
DockerImage: p.config.DockerImage,
470-
Host: pool.SocketCloneDir(name),
471-
Port: port,
472-
DB: p.dbCfg,
473-
Pool: *pool,
469+
CloneName: name,
470+
DockerImage: p.config.DockerImage,
471+
Host: pool.SocketCloneDir(name),
472+
Port: port,
473+
DB: p.dbCfg,
474+
Pool: *pool,
475+
ContainerConf: p.config.ContainerConfig,
474476
}
475477

476478
return appConfig

pkg/services/provision/resources/appconfig.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ type AppConfig struct {
1717
Port uint
1818
DB *DB
1919

20-
extraConf map[string]string
20+
ContainerConf map[string]string
21+
pgExtraConf map[string]string
2122
}
2223

2324
// DB describes a default database configuration.
@@ -34,10 +35,10 @@ func (c *AppConfig) DataDir() string {
3435

3536
// ExtraConf returns a map with an extra configuration.
3637
func (c *AppConfig) ExtraConf() map[string]string {
37-
return c.extraConf
38+
return c.pgExtraConf
3839
}
3940

4041
// SetExtraConf sets a map with an extra configuration.
4142
func (c *AppConfig) SetExtraConf(extraConf map[string]string) {
42-
c.extraConf = extraConf
43+
c.pgExtraConf = extraConf
4344
}

0 commit comments

Comments
 (0)