Skip to content

Commit 08d1990

Browse files
committed
Merge branch '160-configure-sysctls' into 'master'
feat: allow configuring namespaced kernel parameters (sysctls) for a promotion stage (#160) - add a new section `sysctls` to physicalSnapshot parameters - validate sysctl names https://docs.docker.com/engine/reference/commandline/run/#configure-namespaced-kernel-parameters-sysctls-at-runtime - apply configured sysctls to promotion container See merge request postgres-ai/database-lab!171
2 parents e9ec9af + c0a4f57 commit 08d1990

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

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

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"os"
1616
"path"
1717
"strconv"
18+
"strings"
1819
"sync"
1920
"time"
2021

@@ -51,8 +52,21 @@ const (
5152
hcPromoteRetries = 200
5253

5354
syncContainerStopTimeout = 2 * time.Minute
55+
supportedSysctlPrefix = "fs.mqueue."
5456
)
5557

58+
// supportedSysctls describes supported sysctls for Promote Docker image.
59+
var supportedSysctls = map[string]struct{}{
60+
"kernel.msgmax": {},
61+
"kernel.msgmnb": {},
62+
"kernel.msgmni": {},
63+
"kernel.sem": {},
64+
"kernel.shmall": {},
65+
"kernel.shmmax": {},
66+
"kernel.shmmni": {},
67+
"kernel.shm_rmid_forced": {},
68+
}
69+
5670
// PhysicalInitial describes a job for preparing a physical initial snapshot.
5771
type PhysicalInitial struct {
5872
name string
@@ -73,6 +87,7 @@ type PhysicalOptions struct {
7387
DockerImage string `yaml:"dockerImage"`
7488
PreprocessingScript string `yaml:"preprocessingScript"`
7589
Configs map[string]string `yaml:"configs"`
90+
Sysctls map[string]string `yaml:"sysctls"`
7691
Scheduler *Scheduler `yaml:"scheduler"`
7792
}
7893

@@ -104,6 +119,10 @@ func NewPhysicalInitialJob(cfg config.JobConfig, docker *client.Client, cloneMan
104119
return nil, errors.Wrap(err, "failed to unmarshal configuration options")
105120
}
106121

122+
if err := p.validateConfig(); err != nil {
123+
return nil, errors.Wrap(err, "invalid physicalSnapshot configuration")
124+
}
125+
107126
if err := p.setupScheduler(); err != nil {
108127
return nil, errors.Wrap(err, "failed to set up scheduler")
109128
}
@@ -132,6 +151,23 @@ func (p *PhysicalInitial) setupScheduler() error {
132151
return nil
133152
}
134153

154+
func (p *PhysicalInitial) validateConfig() error {
155+
notSupportedSysctls := []string{}
156+
157+
for sysctl := range p.options.Sysctls {
158+
if _, ok := supportedSysctls[sysctl]; !ok && !strings.HasPrefix(sysctl, supportedSysctlPrefix) {
159+
notSupportedSysctls = append(notSupportedSysctls, sysctl)
160+
}
161+
}
162+
163+
if len(notSupportedSysctls) > 0 {
164+
return errors.Errorf("Docker does not support following kernel parameters (sysctls): %s",
165+
strings.Join(notSupportedSysctls, ", "))
166+
}
167+
168+
return nil
169+
}
170+
135171
func (p *PhysicalInitial) syncInstanceName() string {
136172
return tools.SyncInstanceContainerPrefix + p.globalCfg.InstanceID
137173
}
@@ -478,7 +514,9 @@ func (p *PhysicalInitial) buildContainerConfig(clonePath, promoteImage, password
478514
}
479515

480516
func (p *PhysicalInitial) buildHostConfig(ctx context.Context, clonePath string) (*container.HostConfig, error) {
481-
hostConfig := &container.HostConfig{}
517+
hostConfig := &container.HostConfig{
518+
Sysctls: p.options.Sysctls,
519+
}
482520

483521
if err := tools.AddVolumesToHostConfig(ctx, p.dockerClient, hostConfig,
484522
p.globalCfg.MountDir, clonePath); err != nil {

0 commit comments

Comments
 (0)