mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
support IPv6
This commit is contained in:
parent
bcf32591b7
commit
e982b06bcd
|
@ -53,7 +53,7 @@ func RunMount(option *MountOptions, umask os.FileMode) bool {
|
||||||
|
|
||||||
filer := *option.filer
|
filer := *option.filer
|
||||||
// parse filer grpc address
|
// parse filer grpc address
|
||||||
filerGrpcAddress, err := pb.ParseFilerGrpcAddress(filer)
|
filerGrpcAddress, err := pb.ParseServerToGrpcAddress(filer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.V(0).Infof("ParseFilerGrpcAddress: %v", err)
|
glog.V(0).Infof("ParseFilerGrpcAddress: %v", err)
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -63,7 +63,7 @@ func (msgBrokerOpt *MessageBrokerOptions) startQueueServer() bool {
|
||||||
|
|
||||||
grace.SetupProfiling(*messageBrokerStandaloneOptions.cpuprofile, *messageBrokerStandaloneOptions.memprofile)
|
grace.SetupProfiling(*messageBrokerStandaloneOptions.cpuprofile, *messageBrokerStandaloneOptions.memprofile)
|
||||||
|
|
||||||
filerGrpcAddress, err := pb.ParseFilerGrpcAddress(*msgBrokerOpt.filer)
|
filerGrpcAddress, err := pb.ParseServerToGrpcAddress(*msgBrokerOpt.filer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatal(err)
|
glog.Fatal(err)
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -137,7 +137,7 @@ func runS3(cmd *Command, args []string) bool {
|
||||||
|
|
||||||
func (s3opt *S3Options) startS3Server() bool {
|
func (s3opt *S3Options) startS3Server() bool {
|
||||||
|
|
||||||
filerGrpcAddress, err := pb.ParseFilerGrpcAddress(*s3opt.filer)
|
filerGrpcAddress, err := pb.ParseServerToGrpcAddress(*s3opt.filer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatal(err)
|
glog.Fatal(err)
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -78,7 +78,7 @@ func (wo *WebDavOption) startWebDav() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse filer grpc address
|
// parse filer grpc address
|
||||||
filerGrpcAddress, err := pb.ParseFilerGrpcAddress(*wo.filer)
|
filerGrpcAddress, err := pb.ParseServerToGrpcAddress(*wo.filer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatal(err)
|
glog.Fatal(err)
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -3,6 +3,7 @@ package pb
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -108,51 +109,51 @@ func WithCachedGrpcClient(fn func(*grpc.ClientConn) error, address string, opts
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseServerToGrpcAddress(server string) (serverGrpcAddress string, err error) {
|
func ParseServerToGrpcAddress(server string) (serverGrpcAddress string, err error) {
|
||||||
colonIndex := strings.LastIndex(server, ":")
|
|
||||||
if colonIndex < 0 {
|
|
||||||
return "", fmt.Errorf("server should have hostname:port format: %v", server)
|
|
||||||
}
|
|
||||||
|
|
||||||
port, parseErr := strconv.ParseUint(server[colonIndex+1:], 10, 64)
|
host, port, parseErr := hostAndPort(server)
|
||||||
if parseErr != nil {
|
if parseErr != nil {
|
||||||
return "", fmt.Errorf("server port parse error: %v", parseErr)
|
return "", fmt.Errorf("server port parse error: %v", parseErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
grpcPort := int(port) + 10000
|
grpcPort := int(port) + 10000
|
||||||
|
|
||||||
return fmt.Sprintf("%s:%d", server[:colonIndex], grpcPort), nil
|
return fmt.Sprintf("%s:%d", host, grpcPort), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func hostAndPort(address string) (host string, port uint64, err error) {
|
||||||
|
colonIndex := strings.LastIndex(address, ":")
|
||||||
|
if colonIndex < 0 {
|
||||||
|
return "", 0, fmt.Errorf("server should have hostname:port format: %v", address)
|
||||||
|
}
|
||||||
|
port, err = strconv.ParseUint(address[colonIndex+1:], 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return "", 0, fmt.Errorf("server port parse error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return address[:colonIndex], port, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func ServerToGrpcAddress(server string) (serverGrpcAddress string) {
|
func ServerToGrpcAddress(server string) (serverGrpcAddress string) {
|
||||||
hostnameAndPort := strings.Split(server, ":")
|
|
||||||
if len(hostnameAndPort) != 2 {
|
|
||||||
return fmt.Sprintf("unexpected server address: %s", server)
|
|
||||||
}
|
|
||||||
|
|
||||||
port, parseErr := strconv.ParseUint(hostnameAndPort[1], 10, 64)
|
host, port, parseErr := hostAndPort(server)
|
||||||
if parseErr != nil {
|
if parseErr != nil {
|
||||||
return fmt.Sprintf("failed to parse port for %s:%s", hostnameAndPort[0], hostnameAndPort[1])
|
glog.Fatalf("server address %s parse error: %v", server, parseErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
grpcPort := int(port) + 10000
|
grpcPort := int(port) + 10000
|
||||||
|
|
||||||
return fmt.Sprintf("%s:%d", hostnameAndPort[0], grpcPort)
|
return fmt.Sprintf("%s:%d", host, grpcPort)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GrpcAddressToServerAddress(grpcAddress string) (serverAddress string) {
|
func GrpcAddressToServerAddress(grpcAddress string) (serverAddress string) {
|
||||||
hostnameAndPort := strings.Split(grpcAddress, ":")
|
host, grpcPort, parseErr := hostAndPort(grpcAddress)
|
||||||
if len(hostnameAndPort) != 2 {
|
|
||||||
return fmt.Sprintf("unexpected grpcAddress: %s", grpcAddress)
|
|
||||||
}
|
|
||||||
|
|
||||||
grpcPort, parseErr := strconv.ParseUint(hostnameAndPort[1], 10, 64)
|
|
||||||
if parseErr != nil {
|
if parseErr != nil {
|
||||||
return fmt.Sprintf("failed to parse port for %s:%s", hostnameAndPort[0], hostnameAndPort[1])
|
glog.Fatalf("server grpc address %s parse error: %v", grpcAddress, parseErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
port := int(grpcPort) - 10000
|
port := int(grpcPort) - 10000
|
||||||
|
|
||||||
return fmt.Sprintf("%s:%d", hostnameAndPort[0], port)
|
return fmt.Sprintf("%s:%d", host, port)
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithMasterClient(master string, grpcDialOption grpc.DialOption, fn func(client master_pb.SeaweedClient) error) error {
|
func WithMasterClient(master string, grpcDialOption grpc.DialOption, fn func(client master_pb.SeaweedClient) error) error {
|
||||||
|
@ -197,19 +198,3 @@ func WithGrpcFilerClient(filerGrpcAddress string, grpcDialOption grpc.DialOption
|
||||||
}, filerGrpcAddress, grpcDialOption)
|
}, filerGrpcAddress, grpcDialOption)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseFilerGrpcAddress(filer string) (filerGrpcAddress string, err error) {
|
|
||||||
hostnameAndPort := strings.Split(filer, ":")
|
|
||||||
if len(hostnameAndPort) != 2 {
|
|
||||||
return "", fmt.Errorf("filer should have hostname:port format: %v", hostnameAndPort)
|
|
||||||
}
|
|
||||||
|
|
||||||
filerPort, parseErr := strconv.ParseUint(hostnameAndPort[1], 10, 64)
|
|
||||||
if parseErr != nil {
|
|
||||||
return "", fmt.Errorf("filer port parse error: %v", parseErr)
|
|
||||||
}
|
|
||||||
|
|
||||||
filerGrpcPort := int(filerPort) + 10000
|
|
||||||
|
|
||||||
return fmt.Sprintf("%s:%d", hostnameAndPort[0], filerGrpcPort), nil
|
|
||||||
}
|
|
||||||
|
|
|
@ -153,7 +153,7 @@ func NewFilerServer(defaultMux, readonlyMux *http.ServeMux, option *FilerOption)
|
||||||
func (fs *FilerServer) checkWithMaster() {
|
func (fs *FilerServer) checkWithMaster() {
|
||||||
|
|
||||||
for _, master := range fs.option.Masters {
|
for _, master := range fs.option.Masters {
|
||||||
_, err := pb.ParseFilerGrpcAddress(master)
|
_, err := pb.ParseServerToGrpcAddress(master)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("invalid master address %s: %v", master, err)
|
glog.Fatalf("invalid master address %s: %v", master, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ var (
|
||||||
WriteTimeout: time.Second,
|
WriteTimeout: time.Second,
|
||||||
MaxIdleConnDuration: time.Minute,
|
MaxIdleConnDuration: time.Minute,
|
||||||
DisableHeaderNamesNormalizing: true, // If you set the case on your headers correctly you can enable this.
|
DisableHeaderNamesNormalizing: true, // If you set the case on your headers correctly you can enable this.
|
||||||
|
DialDualStack: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Put everything in pools to prevent garbage.
|
// Put everything in pools to prevent garbage.
|
||||||
|
|
Loading…
Reference in a new issue