Skip to content

Commit

Permalink
MB-31109: Make ip:port binding on projector and indexer more lenient
Browse files Browse the repository at this point in the history
If the cluster is configured to use ipv4, allow GSI processes
to come up successfully even if they cannot bind to ipv6:port.

Similarly, if the cluster is configured to use ipv6, allow GSI
processes to come up successfully even if they cannot bind to
ipv4:port.

Note that the GSI clients will use the node names from cluster
info cache. And the cluster configuration change with respect
to ipv4/ipv6 protocol stack is not supported if the cluser
node names are based on the ip addresses.

Change-Id: Iadb546e60ef32a3edd8ce3e5e41be8d1e721b443
  • Loading branch information
amithk committed Jun 2, 2020
1 parent 02ed799 commit 8b5354f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
6 changes: 2 additions & 4 deletions secondary/common/util.go
Expand Up @@ -40,8 +40,6 @@ const (

var ErrInvalidIndexName = fmt.Errorf("Invalid index name")

var _isIpv6 bool

// ExcludeStrings will exclude strings in `excludes` from `strs`. preserves the
// order of `strs` in the result.
func ExcludeStrings(strs []string, excludes []string) []string {
Expand Down Expand Up @@ -1150,11 +1148,11 @@ func ComputePercent(a, b int64) int64 {
}

func SetIpv6(isIpv6 bool) {
_isIpv6 = isIpv6
security.SetIpv6(isIpv6)
}

func IsIpv6() bool {
return _isIpv6
return security.IsIpv6()
}

func validateAuth(w http.ResponseWriter, r *http.Request) bool {
Expand Down
2 changes: 1 addition & 1 deletion secondary/indexer/indexer.go
Expand Up @@ -647,7 +647,7 @@ func (idx *indexer) initHttpServer() error {
Handler: GetHTTPMux(),
}

lsnr, err := net.Listen("tcp", addr)
lsnr, err := security.MakeProtocolAwareTCPListener(addr)
if err != nil {
return fmt.Errorf("Error in creating TCP Listener: %v", err)
}
Expand Down
39 changes: 37 additions & 2 deletions secondary/security/tls.go
Expand Up @@ -285,7 +285,7 @@ func MakeAndSecureTCPListener(addr string) (net.Listener, error) {
return nil, err
}

tcpListener, err := makeTCPListener(addr)
tcpListener, err := MakeProtocolAwareTCPListener(addr)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -317,6 +317,27 @@ func makeTCPListener(addr string) (net.Listener, error) {
return tcpListener, nil
}

//
// Set up a TCP listener.
// If the cluster setting dictates ipv6, then listener will bind only on
// ipv6 addresses. Similarly if the cluster setting dictates ipv4, then
// the listener will bind only on ipv4 addresses.
//
func MakeProtocolAwareTCPListener(addr string) (net.Listener, error) {

protocol := "tcp4"
if IsIpv6() {
protocol = "tcp6"
}

tcpListener, err := net.Listen(protocol, addr)
if err != nil {
return nil, err
}

return tcpListener, nil
}

//
// Secure a TCP listener. If encryption is requird, listener must already
// setup with SSL port.
Expand All @@ -341,7 +362,7 @@ func MakeListener(addr string) (net.Listener, error) {
return nil, err
}

listener, err := makeTCPListener(addr)
listener, err := MakeProtocolAwareTCPListener(addr)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -726,3 +747,17 @@ func MakeHTTPServer(addr string) (*http.Server, error) {

return server, nil
}

//
// Cluster wide ipv6 setting.
//

var _isIpv6 bool

func SetIpv6(isIpv6 bool) {
_isIpv6 = isIpv6
}

func IsIpv6() bool {
return _isIpv6
}

0 comments on commit 8b5354f

Please sign in to comment.