Skip to content

Commit e658c89

Browse files
committed
migrate experimental-memory-mlock flag to memory-mlock
Signed-off-by: Jiayin Mao <[email protected]>
1 parent e757a45 commit e658c89

File tree

7 files changed

+82
-7
lines changed

7 files changed

+82
-7
lines changed

server/config/config.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,13 @@ type ServerConfig struct {
184184

185185
DowngradeCheckTime time.Duration
186186

187-
// ExperimentalMemoryMlock enables mlocking of etcd owned memory pages.
187+
// MemoryMlock enables mlocking of etcd owned memory pages.
188188
// The setting improves etcd tail latency in environments were:
189189
// - memory pressure might lead to swapping pages to disk
190190
// - disk latency might be unstable
191191
// Currently all etcd memory gets mlocked, but in future the flag can
192192
// be refined to mlock in-use area of bbolt only.
193-
ExperimentalMemoryMlock bool `json:"experimental-memory-mlock"`
193+
MemoryMlock bool `json:"memory-mlock"`
194194

195195
// ExperimentalTxnModeWriteWithSharedBuffer enable write transaction to use
196196
// a shared buffer in its readonly check operations.

server/embed/config.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -484,12 +484,17 @@ type Config struct {
484484

485485
ExperimentalDowngradeCheckTime time.Duration `json:"experimental-downgrade-check-time"`
486486

487-
// ExperimentalMemoryMlock enables mlocking of etcd owned memory pages.
487+
// MemoryMlock enables mlocking of etcd owned memory pages.
488488
// The setting improves etcd tail latency in environments were:
489489
// - memory pressure might lead to swapping pages to disk
490490
// - disk latency might be unstable
491491
// Currently all etcd memory gets mlocked, but in future the flag can
492492
// be refined to mlock in-use area of bbolt only.
493+
MemoryMlock bool `json:"memory-mlock"`
494+
495+
// ExperimentalMemoryMlock enables mlocking of etcd owned memory pages.
496+
// Deprecated in v3.6 and will be decommissioned in v3.7. Use MemoryMlock instead.
497+
// TODO: Delete in v3.7
493498
ExperimentalMemoryMlock bool `json:"experimental-memory-mlock"`
494499

495500
// ExperimentalTxnModeWriteWithSharedBuffer enables write transaction to use a shared buffer in its readonly check operations.
@@ -606,7 +611,9 @@ func NewConfig() *Config {
606611
LogRotationConfigJSON: DefaultLogRotationConfig,
607612
EnableGRPCGateway: true,
608613

609-
ExperimentalDowngradeCheckTime: DefaultDowngradeCheckTime,
614+
ExperimentalDowngradeCheckTime: DefaultDowngradeCheckTime,
615+
MemoryMlock: false,
616+
// TODO: delete in v3.7
610617
ExperimentalMemoryMlock: false,
611618
ExperimentalStopGRPCServiceOnDefrag: false,
612619
ExperimentalMaxLearners: membership.DefaultMaxLearners,
@@ -819,7 +826,9 @@ func (cfg *Config) AddFlags(fs *flag.FlagSet) {
819826
fs.DurationVar(&cfg.WarningApplyDuration, "warning-apply-duration", cfg.WarningApplyDuration, "Time duration after which a warning is generated if watch progress takes more time.")
820827
fs.DurationVar(&cfg.WarningUnaryRequestDuration, "warning-unary-request-duration", cfg.WarningUnaryRequestDuration, "Time duration after which a warning is generated if a unary request takes more time.")
821828
fs.DurationVar(&cfg.ExperimentalWarningUnaryRequestDuration, "experimental-warning-unary-request-duration", cfg.ExperimentalWarningUnaryRequestDuration, "Time duration after which a warning is generated if a unary request takes more time. It's deprecated, and will be decommissioned in v3.7. Use --warning-unary-request-duration instead.")
829+
// TODO: delete in v3.7
822830
fs.BoolVar(&cfg.ExperimentalMemoryMlock, "experimental-memory-mlock", cfg.ExperimentalMemoryMlock, "Enable to enforce etcd pages (in particular bbolt) to stay in RAM.")
831+
fs.BoolVar(&cfg.MemoryMlock, "memory-mlock", cfg.MemoryMlock, "Enable to enforce etcd pages (in particular bbolt) to stay in RAM.")
823832
fs.BoolVar(&cfg.ExperimentalTxnModeWriteWithSharedBuffer, "experimental-txn-mode-write-with-shared-buffer", true, "Enable the write transaction to use a shared buffer in its readonly check operations.")
824833
fs.BoolVar(&cfg.ExperimentalStopGRPCServiceOnDefrag, "experimental-stop-grpc-service-on-defrag", cfg.ExperimentalStopGRPCServiceOnDefrag, "Enable etcd gRPC service to stop serving client requests on defragmentation.")
825834
// TODO: delete in v3.7

server/embed/etcd.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ func StartEtcd(inCfg *Config) (e *Etcd, err error) {
233233
DowngradeCheckTime: cfg.ExperimentalDowngradeCheckTime,
234234
WarningApplyDuration: cfg.WarningApplyDuration,
235235
WarningUnaryRequestDuration: cfg.WarningUnaryRequestDuration,
236-
ExperimentalMemoryMlock: cfg.ExperimentalMemoryMlock,
236+
MemoryMlock: cfg.MemoryMlock,
237237
BootstrapDefragThresholdMegabytes: cfg.BootstrapDefragThresholdMegabytes,
238238
ExperimentalMaxLearners: cfg.ExperimentalMaxLearners,
239239
V2Deprecation: cfg.V2DeprecationEffective(),

server/etcdmain/config.go

+5
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ var (
7070
"experimental-watch-progress-notify-interval": "--experimental-watch-progress-notify-interval is deprecated in v3.6 and will be decommissioned in v3.7. Use '--watch-progress-notify-interval' instead.",
7171
"experimental-warning-apply-duration": "--experimental-warning-apply-duration is deprecated in v3.6 and will be decommissioned in v3.7. Use '--warning-apply-duration' instead.",
7272
"experimental-bootstrap-defrag-threshold-megabytes": "--experimental-bootstrap-defrag-threshold-megabytes is deprecated in v3.6 and will be decommissioned in v3.7. Use '--bootstrap-defrag-threshold-megabytes' instead.",
73+
"experimental-memory-mlock": "--experimental-memory-mlock is deprecated in v3.6 and will be decommissioned in v3.7. Use '--memory-mlock' instead.",
7374
}
7475
)
7576

@@ -199,6 +200,10 @@ func (cfg *config) parse(arguments []string) error {
199200
cfg.ec.BootstrapDefragThresholdMegabytes = cfg.ec.ExperimentalBootstrapDefragThresholdMegabytes
200201
}
201202

203+
if cfg.ec.FlagsExplicitlySet["experimental-memory-mlock"] {
204+
cfg.ec.MemoryMlock = cfg.ec.ExperimentalMemoryMlock
205+
}
206+
202207
// `V2Deprecation` (--v2-deprecation) is deprecated and scheduled for removal in v3.8. The default value is enforced, ignoring user input.
203208
cfg.ec.V2Deprecation = cconfig.V2DeprDefault
204209

server/etcdmain/config_test.go

+59
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,65 @@ func TestBootstrapDefragThresholdMegabytesFlagMigration(t *testing.T) {
882882
}
883883
}
884884

885+
// TestMemoryMlockFlagMigration tests the migration from
886+
// --experimental-memory-mlock to --memory-mlock
887+
// TODO: delete in v3.7
888+
func TestMemoryMlockFlagMigration(t *testing.T) {
889+
testCases := []struct {
890+
name string
891+
memoryMlock bool
892+
experimentalMemoryMlock bool
893+
expectedMemoryMlock bool
894+
}{
895+
{
896+
name: "default",
897+
expectedMemoryMlock: false,
898+
},
899+
{
900+
name: "can set experimental flag",
901+
experimentalMemoryMlock: true,
902+
expectedMemoryMlock: true,
903+
},
904+
{
905+
name: "can set non experimental flag",
906+
memoryMlock: true,
907+
expectedMemoryMlock: true,
908+
},
909+
}
910+
for _, tc := range testCases {
911+
t.Run(tc.name, func(t *testing.T) {
912+
cmdLineArgs := []string{}
913+
yc := struct {
914+
MemoryMlock bool `json:"memory-mlock,omitempty"`
915+
ExperimentalMemoryMlock bool `json:"experimental-memory-mlock,omitempty"`
916+
}{}
917+
918+
if tc.memoryMlock {
919+
cmdLineArgs = append(cmdLineArgs, "--memory-mlock")
920+
yc.MemoryMlock = tc.memoryMlock
921+
}
922+
923+
if tc.experimentalMemoryMlock {
924+
cmdLineArgs = append(cmdLineArgs, "--experimental-memory-mlock")
925+
yc.ExperimentalMemoryMlock = tc.experimentalMemoryMlock
926+
}
927+
928+
cfgFromCmdLine, errFromCmdLine, cfgFromFile, errFromFile := generateCfgsFromFileAndCmdLine(t, yc, cmdLineArgs)
929+
930+
if errFromCmdLine != nil || errFromFile != nil {
931+
t.Fatal("error parsing config")
932+
}
933+
934+
if cfgFromCmdLine.ec.MemoryMlock != tc.expectedMemoryMlock {
935+
t.Errorf("expected MemoryMlock=%v, got %v", tc.expectedMemoryMlock, cfgFromCmdLine.ec.MemoryMlock)
936+
}
937+
if cfgFromFile.ec.MemoryMlock != tc.expectedMemoryMlock {
938+
t.Errorf("expected MemoryMlock=%v, got %v", tc.expectedMemoryMlock, cfgFromFile.ec.MemoryMlock)
939+
}
940+
})
941+
}
942+
}
943+
885944
// TODO delete in v3.7
886945
func generateCfgsFromFileAndCmdLine(t *testing.T, yc any, cmdLineArgs []string) (*config, error, *config, error) {
887946
b, err := yaml.Marshal(&yc)

server/etcdmain/help.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ Member:
7575
Maximum number of snapshot files to retain (0 is unlimited). Deprecated in v3.6 and will be decommissioned in v3.7.
7676
--max-wals '` + strconv.Itoa(embed.DefaultMaxWALs) + `'
7777
Maximum number of wal files to retain (0 is unlimited).
78+
--memory-mlock
79+
Enable to enforce etcd pages (in particular bbolt) to stay in RAM.
7880
--quota-backend-bytes '0'
7981
Raise alarms when backend size exceeds the given quota (0 defaults to low space quota).
8082
--backend-bbolt-freelist-type 'map'
@@ -320,7 +322,7 @@ Experimental feature:
320322
--experimental-enable-lease-checkpoint-persist 'false'
321323
Enable persisting remainingTTL to prevent indefinite auto-renewal of long lived leases. Always enabled in v3.6. Should be used to ensure smooth upgrade from v3.5 clusters with this feature enabled. Requires experimental-enable-lease-checkpoint to be enabled.
322324
--experimental-memory-mlock
323-
Enable to enforce etcd pages (in particular bbolt) to stay in RAM.
325+
Enable to enforce etcd pages (in particular bbolt) to stay in RAM. Deprecated in v3.6 and will be decommissioned in v3.7. Use '--memory-mlock' instead.
324326
--experimental-snapshot-catchup-entries
325327
Number of entries for a slow follower to catch up after compacting the raft storage entries.
326328
--experimental-stop-grpc-service-on-defrag

server/storage/backend.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func newBackend(cfg config.ServerConfig, hooks backend.Hooks) backend.Backend {
5050
// permit 10% excess over quota for disarm
5151
bcfg.MmapSize = uint64(cfg.QuotaBackendBytes + cfg.QuotaBackendBytes/10)
5252
}
53-
bcfg.Mlock = cfg.ExperimentalMemoryMlock
53+
bcfg.Mlock = cfg.MemoryMlock
5454
bcfg.Hooks = hooks
5555
return backend.New(bcfg)
5656
}

0 commit comments

Comments
 (0)