Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.5] Backport expose socket options #16435

Merged
merged 2 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions client/pkg/transport/sockopt.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ type SocketOpts struct {
// in which case lock on data file could result in unexpected
// condition. User should take caution to protect against lock race.
// [1] https://man7.org/linux/man-pages/man7/socket.7.html
ReusePort bool
ReusePort bool `json:"reuse-port"`
// ReuseAddress enables a socket option SO_REUSEADDR which allows
// binding to an address in `TIME_WAIT` state. Useful to improve MTTR
// in cases where etcd slow to restart due to excessive `TIME_WAIT`.
// [1] https://man7.org/linux/man-pages/man7/socket.7.html
ReuseAddress bool
ReuseAddress bool `json:"reuse-address"`
}

func getControls(sopts *SocketOpts) Controls {
Expand Down
7 changes: 5 additions & 2 deletions server/embed/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ type Config struct {
GRPCKeepAliveTimeout time.Duration `json:"grpc-keepalive-timeout"`

// SocketOpts are socket options passed to listener config.
SocketOpts transport.SocketOpts
SocketOpts transport.SocketOpts `json:"socket-options"`

// PreVote is true to enable Raft Pre-Vote.
// If enabled, Raft runs an additional election phase
Expand Down Expand Up @@ -470,7 +470,10 @@ func NewConfig() *Config {
GRPCKeepAliveInterval: DefaultGRPCKeepAliveInterval,
GRPCKeepAliveTimeout: DefaultGRPCKeepAliveTimeout,

SocketOpts: transport.SocketOpts{},
SocketOpts: transport.SocketOpts{
ReusePort: false,
ReuseAddress: false,
},

TickMs: 100,
ElectionMs: 1000,
Expand Down
26 changes: 16 additions & 10 deletions server/embed/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,23 @@ func TestConfigFileOtherFields(t *testing.T) {
ctls := securityConfig{TrustedCAFile: "cca", CertFile: "ccert", KeyFile: "ckey"}
ptls := securityConfig{TrustedCAFile: "pca", CertFile: "pcert", KeyFile: "pkey"}
yc := struct {
ClientSecurityCfgFile securityConfig `json:"client-transport-security"`
PeerSecurityCfgFile securityConfig `json:"peer-transport-security"`
ForceNewCluster bool `json:"force-new-cluster"`
Logger string `json:"logger"`
LogOutputs []string `json:"log-outputs"`
Debug bool `json:"debug"`
ClientSecurityCfgFile securityConfig `json:"client-transport-security"`
PeerSecurityCfgFile securityConfig `json:"peer-transport-security"`
ForceNewCluster bool `json:"force-new-cluster"`
Logger string `json:"logger"`
LogOutputs []string `json:"log-outputs"`
Debug bool `json:"debug"`
SocketOpts transport.SocketOpts `json:"socket-options"`
}{
ctls,
ptls,
true,
"zap",
[]string{"/dev/null"},
false,
transport.SocketOpts{
ReusePort: true,
},
}

b, err := yaml.Marshal(&yc)
Expand All @@ -70,16 +74,18 @@ func TestConfigFileOtherFields(t *testing.T) {
t.Fatal(err)
}

if !cfg.ForceNewCluster {
t.Errorf("ForceNewCluster = %v, want %v", cfg.ForceNewCluster, true)
}

if !ctls.equals(&cfg.ClientTLSInfo) {
t.Errorf("ClientTLS = %v, want %v", cfg.ClientTLSInfo, ctls)
}
if !ptls.equals(&cfg.PeerTLSInfo) {
t.Errorf("PeerTLS = %v, want %v", cfg.PeerTLSInfo, ptls)
}

assert.Equal(t, true, cfg.ForceNewCluster, "ForceNewCluster does not match")

assert.Equal(t, true, cfg.SocketOpts.ReusePort, "ReusePort does not match")

assert.Equal(t, false, cfg.SocketOpts.ReuseAddress, "ReuseAddress does not match")
}

// TestUpdateDefaultClusterFromName ensures that etcd can start with 'etcd --name=abc'.
Expand Down
Loading