@@ -15,6 +15,7 @@ import (
15
15
"os"
16
16
"path"
17
17
"strconv"
18
+ "strings"
18
19
"sync"
19
20
"time"
20
21
@@ -51,8 +52,21 @@ const (
51
52
hcPromoteRetries = 200
52
53
53
54
syncContainerStopTimeout = 2 * time .Minute
55
+ supportedSysctlPrefix = "fs.mqueue."
54
56
)
55
57
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
+
56
70
// PhysicalInitial describes a job for preparing a physical initial snapshot.
57
71
type PhysicalInitial struct {
58
72
name string
@@ -73,6 +87,7 @@ type PhysicalOptions struct {
73
87
DockerImage string `yaml:"dockerImage"`
74
88
PreprocessingScript string `yaml:"preprocessingScript"`
75
89
Configs map [string ]string `yaml:"configs"`
90
+ Sysctls map [string ]string `yaml:"sysctls"`
76
91
Scheduler * Scheduler `yaml:"scheduler"`
77
92
}
78
93
@@ -104,6 +119,10 @@ func NewPhysicalInitialJob(cfg config.JobConfig, docker *client.Client, cloneMan
104
119
return nil , errors .Wrap (err , "failed to unmarshal configuration options" )
105
120
}
106
121
122
+ if err := p .validateConfig (); err != nil {
123
+ return nil , errors .Wrap (err , "invalid physicalSnapshot configuration" )
124
+ }
125
+
107
126
if err := p .setupScheduler (); err != nil {
108
127
return nil , errors .Wrap (err , "failed to set up scheduler" )
109
128
}
@@ -132,6 +151,23 @@ func (p *PhysicalInitial) setupScheduler() error {
132
151
return nil
133
152
}
134
153
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
+
135
171
func (p * PhysicalInitial ) syncInstanceName () string {
136
172
return tools .SyncInstanceContainerPrefix + p .globalCfg .InstanceID
137
173
}
@@ -478,7 +514,9 @@ func (p *PhysicalInitial) buildContainerConfig(clonePath, promoteImage, password
478
514
}
479
515
480
516
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
+ }
482
520
483
521
if err := tools .AddVolumesToHostConfig (ctx , p .dockerClient , hostConfig ,
484
522
p .globalCfg .MountDir , clonePath ); err != nil {
0 commit comments