SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
handle ipv6 addresses
Chris Lu0128239c0f88
diff --git a/other/java/client/src/main/java/seaweedfs/client/FilerGrpcClient.java b/other/java/client/src/main/java/seaweedfs/client/FilerGrpcClient.javaindex 6c57e2e0d3..56aa358765 100644--- a/other/java/client/src/main/java/seaweedfs/client/FilerGrpcClient.java+++ b/other/java/client/src/main/java/seaweedfs/client/FilerGrpcClient.java@@ -54,7 +54,7 @@ public class FilerGrpcClient {.negotiationType(NegotiationType.TLS).sslContext(sslContext));- filerAddress = String.format("%s:%d", host, grpcPort - 10000);+ filerAddress = SeaweedUtil.joinHostPort(host, grpcPort - 10000);FilerProto.GetFilerConfigurationResponse filerConfigurationResponse =this.getBlockingStub().getFilerConfiguration(diff --git a/other/java/client/src/main/java/seaweedfs/client/SeaweedUtil.java b/other/java/client/src/main/java/seaweedfs/client/SeaweedUtil.javaindex 66ea9a98d7..027e49b96e 100644--- a/other/java/client/src/main/java/seaweedfs/client/SeaweedUtil.java+++ b/other/java/client/src/main/java/seaweedfs/client/SeaweedUtil.java@@ -43,4 +43,14 @@ public class SeaweedUtil {String name = fullpath.substring(sep + 1);return new String[]{parent, name};}++ public static String joinHostPort(String host, int port) {+ if (host.startsWith("[") && host.endsWith("]")) {+ return host + ":" + port;+ }+ if (host.indexOf(':')>=0) {+ return "[" + host + "]:" + port;+ }+ return host + ":" + port;+ }}diff --git a/weed/command/filer.go b/weed/command/filer.goindex ddee0852c9..b1237cc3fb 100644--- a/weed/command/filer.go+++ b/weed/command/filer.go@@ -134,7 +134,7 @@ func runFiler(cmd *Command, args []string) bool {go stats_collect.StartMetricsServer(*f.metricsHttpPort)- filerAddress := fmt.Sprintf("%s:%d", *f.ip, *f.port)+ filerAddress := util.JoinHostPort(*f.ip, *f.port)startDelay := time.Duration(2)if *filerStartS3 {filerS3Options.filer = &filerAddressdiff --git a/weed/command/filer_copy.go b/weed/command/filer_copy.goindex 2cc0d245c6..05aa962921 100644--- a/weed/command/filer_copy.go+++ b/weed/command/filer_copy.go@@ -115,7 +115,7 @@ func runCopy(cmd *Command, args []string) bool {}filerGrpcPort := filerPort + 10000- filerGrpcAddress := fmt.Sprintf("%s:%d", filerUrl.Hostname(), filerGrpcPort)+ filerGrpcAddress := util.JoinHostPort(filerUrl.Hostname(), int(filerGrpcPort))copy.grpcDialOption = security.LoadClientTLS(util.GetViper(), "grpc.client")masters, collection, replication, dirBuckets, maxMB, cipher, err := readFilerConfiguration(copy.grpcDialOption, filerGrpcAddress)diff --git a/weed/command/server.go b/weed/command/server.goindex c784d90b96..b32d9d51e0 100644--- a/weed/command/server.go+++ b/weed/command/server.go@@ -194,7 +194,7 @@ func runServer(cmd *Command, args []string) bool {filerOptions.disableHttp = serverDisableHttpmasterOptions.disableHttp = serverDisableHttp- filerAddress := fmt.Sprintf("%s:%d", *serverIp, *filerOptions.port)+ filerAddress := util.JoinHostPort(*serverIp, *filerOptions.port)s3Options.filer = &filerAddresswebdavOptions.filer = &filerAddressmsgBrokerOptions.filer = &filerAddressdiff --git a/weed/ftpd/ftp_server.go b/weed/ftpd/ftp_server.goindex 4a0dca2c34..0abeeac02a 100644--- a/weed/ftpd/ftp_server.go+++ b/weed/ftpd/ftp_server.go@@ -51,7 +51,7 @@ func (s *SftpServer) GetSettings() (*ftpserver.Settings, error) {return &ftpserver.Settings{Listener: s.ftpListener,- ListenAddr: fmt.Sprintf("%s:%d", s.option.IpBind, s.option.Port),+ ListenAddr: util.JoinHostPort(s.option.IpBind, s.option.Port),PublicHost: s.option.IP,PassiveTransferPortRange: portRange,ActiveTransferPortNon20: true,diff --git a/weed/operation/grpc_client.go b/weed/operation/grpc_client.goindex 025a65b387..39f70343ae 100644--- a/weed/operation/grpc_client.go+++ b/weed/operation/grpc_client.go@@ -2,6 +2,7 @@ package operationimport ("fmt"+ "github.com/chrislusf/seaweedfs/weed/util""strconv""strings"@@ -35,7 +36,7 @@ func toVolumeServerGrpcAddress(volumeServer string) (grpcAddress string, err errglog.Errorf("failed to parse volume server address: %v", volumeServer)return "", err}- return fmt.Sprintf("%s:%d", volumeServer[0:sepIndex], port+10000), nil+ return util.JoinHostPort(volumeServer[0:sepIndex], port+10000), nil}func WithMasterServerClient(masterServer string, grpcDialOption grpc.DialOption, fn func(masterClient master_pb.SeaweedClient) error) error {diff --git a/weed/pb/grpc_client_server.go b/weed/pb/grpc_client_server.goindex 3a3dd05893..f296cf9831 100644--- a/weed/pb/grpc_client_server.go+++ b/weed/pb/grpc_client_server.go@@ -4,8 +4,8 @@ import ("context""fmt""github.com/chrislusf/seaweedfs/weed/glog"+ "github.com/chrislusf/seaweedfs/weed/util""math/rand"- "net""net/http""strconv""strings"@@ -159,7 +159,7 @@ func ParseServerAddress(server string, deltaPort int) (newServerAddress string,newPort := int(port) + deltaPort- return net.JoinHostPort(host, strconv.Itoa(newPort)), nil+ return util.JoinHostPort(host, newPort), nil}func hostAndPort(address string) (host string, port uint64, err error) {@@ -184,7 +184,7 @@ func ServerToGrpcAddress(server string) (serverGrpcAddress string) {grpcPort := int(port) + 10000- return net.JoinHostPort(host, strconv.Itoa(grpcPort))+ return util.JoinHostPort(host, grpcPort)}func GrpcAddressToServerAddress(grpcAddress string) (serverAddress string) {@@ -195,7 +195,7 @@ func GrpcAddressToServerAddress(grpcAddress string) (serverAddress string) {port := int(grpcPort) - 10000- return net.JoinHostPort(host, strconv.Itoa(port))+ return util.JoinHostPort(host, port)}func WithMasterClient(master string, grpcDialOption grpc.DialOption, fn func(client master_pb.SeaweedClient) error) error {diff --git a/weed/server/filer_grpc_server.go b/weed/server/filer_grpc_server.goindex e025e73dca..6a7df0f87d 100644--- a/weed/server/filer_grpc_server.go+++ b/weed/server/filer_grpc_server.go@@ -412,7 +412,7 @@ func (fs *FilerServer) KeepConnected(stream filer_pb.SeaweedFiler_KeepConnectedSreturn err}- clientName := fmt.Sprintf("%s:%d", req.Name, req.GrpcPort)+ clientName := util.JoinHostPort(req.Name, int(req.GrpcPort))m := make(map[string]bool)for _, tp := range req.Resources {m[tp] = truediff --git a/weed/server/filer_server.go b/weed/server/filer_server.goindex 534bc48401..7e5e986600 100644--- a/weed/server/filer_server.go+++ b/weed/server/filer_server.go@@ -143,7 +143,7 @@ func NewFilerServer(defaultMux, readonlyMux *http.ServeMux, option *FilerOption)readonlyMux.HandleFunc("/", fs.readonlyFilerHandler)}- fs.filer.AggregateFromPeers(fmt.Sprintf("%s:%d", option.Host, option.Port), option.Filers)+ fs.filer.AggregateFromPeers(util.JoinHostPort(option.Host, int(option.Port)), option.Filers)fs.filer.LoadBuckets()diff --git a/weed/server/master_grpc_server.go b/weed/server/master_grpc_server.goindex 7bb61b1bdf..80cd378795 100644--- a/weed/server/master_grpc_server.go+++ b/weed/server/master_grpc_server.go@@ -2,8 +2,8 @@ package weed_serverimport ("context"- "fmt""github.com/chrislusf/seaweedfs/weed/storage/backend"+ "github.com/chrislusf/seaweedfs/weed/util""net""strings""time"@@ -289,7 +289,7 @@ func findClientAddress(ctx context.Context, grpcPort uint32) string {}if tcpAddr, ok := pr.Addr.(*net.TCPAddr); ok {externalIP := tcpAddr.IP- return fmt.Sprintf("%s:%d", externalIP, grpcPort)+ return util.JoinHostPort(externalIP.String(), int(grpcPort))}return pr.Addr.String()diff --git a/weed/server/master_server.go b/weed/server/master_server.goindex d2edeb6cb5..7c78be379a 100644--- a/weed/server/master_server.go+++ b/weed/server/master_server.go@@ -224,7 +224,7 @@ func (ms *MasterServer) startAdminScripts() {scriptLines = append(scriptLines, "unlock")}- masterAddress := fmt.Sprintf("%s:%d", ms.option.Host, ms.option.Port)+ masterAddress := util.JoinHostPort(ms.option.Host, ms.option.Port)var shellOptions shell.ShellOptionsshellOptions.GrpcDialOption = security.LoadClientTLS(v, "grpc.master")@@ -299,7 +299,7 @@ func (ms *MasterServer) createSequencer(option *MasterOption) sequence.Sequencercase "snowflake":var err errorsnowflakeId := v.GetInt(SequencerSnowflakeId)- seq, err = sequence.NewSnowflakeSequencer(fmt.Sprintf("%s:%d", option.Host, option.Port), snowflakeId)+ seq, err = sequence.NewSnowflakeSequencer(util.JoinHostPort(option.Host, option.Port), snowflakeId)if err != nil {glog.Error(err)seq = nildiff --git a/weed/server/volume_server.go b/weed/server/volume_server.goindex 034521b4bd..9406b56010 100644--- a/weed/server/volume_server.go+++ b/weed/server/volume_server.go@@ -1,7 +1,6 @@package weed_serverimport (- "fmt""github.com/chrislusf/seaweedfs/weed/storage/types""net/http""sync"@@ -113,7 +112,7 @@ func NewVolumeServer(adminMux, publicMux *http.ServeMux, ip string,}go vs.heartbeat()- go stats.LoopPushingMetric("volumeServer", fmt.Sprintf("%s:%d", ip, port), vs.metricsAddress, vs.metricsIntervalSec)+ go stats.LoopPushingMetric("volumeServer", util.JoinHostPort(ip, port), vs.metricsAddress, vs.metricsIntervalSec)return vs}diff --git a/weed/shell/commands.go b/weed/shell/commands.goindex 5497e89cc0..aef71b419e 100644--- a/weed/shell/commands.go+++ b/weed/shell/commands.go@@ -98,7 +98,7 @@ var _ = filer_pb.FilerClient(&CommandEnv{})func (ce *CommandEnv) WithFilerClient(fn func(filer_pb.SeaweedFilerClient) error) error {- filerGrpcAddress := fmt.Sprintf("%s:%d", ce.option.FilerHost, ce.option.FilerPort+10000)+ filerGrpcAddress := util.JoinHostPort(ce.option.FilerHost, int(ce.option.FilerPort+10000))return pb.WithGrpcFilerClient(filerGrpcAddress, ce.option.GrpcDialOption, fn)}diff --git a/weed/stats/metrics.go b/weed/stats/metrics.goindex 48d9644183..1e1681f9a4 100644--- a/weed/stats/metrics.go+++ b/weed/stats/metrics.go@@ -3,8 +3,10 @@ package statsimport ("fmt""log"+ "net""net/http""os"+ "strconv""strings""time"@@ -180,5 +182,5 @@ func SourceName(port uint32) string {if err != nil {return "unknown"}- return fmt.Sprintf("%s:%d", hostname, port)+ return net.JoinHostPort(hostname, strconv.Itoa(int(port)))}diff --git a/weed/util/network.go b/weed/util/network.goindex 55a123667c..f9fad77714 100644--- a/weed/util/network.go+++ b/weed/util/network.go@@ -2,6 +2,8 @@ package utilimport ("net"+ "strconv"+ "strings""github.com/chrislusf/seaweedfs/weed/glog")@@ -33,3 +35,11 @@ func DetectedHostAddress() string {return "localhost"}++func JoinHostPort(host string, port int) string {+ portStr := strconv.Itoa(port)+ if strings.HasPrefix(host, "[") && strings.HasSuffix(host, "]") {+ return host + ":" + portStr+ }+ return net.JoinHostPort(host, portStr)+}\ No newline at end of file