Browse Source

ipv6 support

pull/279/head
tnextday 10 years ago
parent
commit
3b18a2a13f
  1. 3
      go/topology/data_node.go
  2. 7
      go/topology/rack.go
  3. 3
      go/topology/store_replicate.go
  4. 5
      go/weed/master.go
  5. 19
      go/weed/server.go
  6. 7
      go/weed/volume.go
  7. 12
      go/weed/weed_server/master_server_handlers_admin.go

3
go/topology/data_node.go

@ -6,6 +6,7 @@ import (
"github.com/chrislusf/seaweedfs/go/glog" "github.com/chrislusf/seaweedfs/go/glog"
"github.com/chrislusf/seaweedfs/go/storage" "github.com/chrislusf/seaweedfs/go/storage"
"net"
) )
type DataNode struct { type DataNode struct {
@ -87,7 +88,7 @@ func (dn *DataNode) MatchLocation(ip string, port int) bool {
} }
func (dn *DataNode) Url() string { func (dn *DataNode) Url() string {
return dn.Ip + ":" + strconv.Itoa(dn.Port)
return net.JoinHostPort(dn.Ip, strconv.Itoa(dn.Port))
} }
func (dn *DataNode) ToMap() interface{} { func (dn *DataNode) ToMap() interface{} {

7
go/topology/rack.go

@ -1,6 +1,7 @@
package topology package topology
import ( import (
"net"
"strconv" "strconv"
"time" "time"
) )
@ -40,13 +41,13 @@ func (r *Rack) GetOrCreateDataNode(ip string, port int, publicUrl string, maxVol
return dn return dn
} }
} }
dn := NewDataNode(ip + ":" + strconv.Itoa(port))
dn := NewDataNode(net.JoinHostPort(ip, strconv.Itoa(port)))
dn.Ip = ip dn.Ip = ip
dn.Port = port dn.Port = port
if publicUrl == "" { if publicUrl == "" {
publicUrl = ip + ":" + strconv.Itoa(port)
publicUrl = net.JoinHostPort(ip, strconv.Itoa(port))
} else if publicUrl[0] == ':' { } else if publicUrl[0] == ':' {
publicUrl = ip + publicUrl
publicUrl = net.JoinHostPort(ip, publicUrl[1:])
} }
dn.PublicUrl = publicUrl dn.PublicUrl = publicUrl
dn.maxVolumeCount = maxVolumeCount dn.maxVolumeCount = maxVolumeCount

3
go/topology/store_replicate.go

@ -10,6 +10,7 @@ import (
"github.com/chrislusf/seaweedfs/go/security" "github.com/chrislusf/seaweedfs/go/security"
"github.com/chrislusf/seaweedfs/go/storage" "github.com/chrislusf/seaweedfs/go/storage"
"github.com/chrislusf/seaweedfs/go/util" "github.com/chrislusf/seaweedfs/go/util"
"net"
) )
func ReplicatedWrite(masterNode string, s *storage.Store, func ReplicatedWrite(masterNode string, s *storage.Store,
@ -69,7 +70,7 @@ func ReplicatedDelete(masterNode string, store *storage.Store,
func distributedOperation(masterNode string, store *storage.Store, volumeId storage.VolumeId, op func(location operation.Location) bool) bool { func distributedOperation(masterNode string, store *storage.Store, volumeId storage.VolumeId, op func(location operation.Location) bool) bool {
if lookupResult, lookupErr := operation.LookupNoCache(masterNode, volumeId.String()); lookupErr == nil { if lookupResult, lookupErr := operation.LookupNoCache(masterNode, volumeId.String()); lookupErr == nil {
length := 0 length := 0
selfUrl := (store.Ip + ":" + strconv.Itoa(store.Port))
selfUrl := net.JoinHostPort(store.Ip, strconv.Itoa(store.Port))
results := make(chan bool) results := make(chan bool)
for _, location := range lookupResult.Locations { for _, location := range lookupResult.Locations {
if location.Url != selfUrl { if location.Url != selfUrl {

5
go/weed/master.go

@ -12,6 +12,7 @@ import (
"github.com/chrislusf/seaweedfs/go/util" "github.com/chrislusf/seaweedfs/go/util"
"github.com/chrislusf/seaweedfs/go/weed/weed_server" "github.com/chrislusf/seaweedfs/go/weed/weed_server"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"net"
) )
func init() { func init() {
@ -64,7 +65,7 @@ func runMaster(cmd *Command, args []string) bool {
masterWhiteList, *masterSecureKey, masterWhiteList, *masterSecureKey,
) )
listeningAddress := *masterBindIp + ":" + strconv.Itoa(*mport)
listeningAddress := net.JoinHostPort(*masterBindIp, strconv.Itoa(*mport))
glog.V(0).Infoln("Start Seaweed Master", util.VERSION, "at", listeningAddress) glog.V(0).Infoln("Start Seaweed Master", util.VERSION, "at", listeningAddress)
@ -75,7 +76,7 @@ func runMaster(cmd *Command, args []string) bool {
go func() { go func() {
time.Sleep(100 * time.Millisecond) time.Sleep(100 * time.Millisecond)
myMasterAddress := *masterIp + ":" + strconv.Itoa(*mport)
myMasterAddress := net.JoinHostPort(*masterIp, strconv.Itoa(*mport))
var peers []string var peers []string
if *masterPeers != "" { if *masterPeers != "" {
peers = strings.Split(*masterPeers, ",") peers = strings.Split(*masterPeers, ",")

19
go/weed/server.go

@ -15,6 +15,7 @@ import (
"github.com/chrislusf/seaweedfs/go/util" "github.com/chrislusf/seaweedfs/go/util"
"github.com/chrislusf/seaweedfs/go/weed/weed_server" "github.com/chrislusf/seaweedfs/go/weed/weed_server"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"net"
) )
type ServerOptions struct { type ServerOptions struct {
@ -107,7 +108,7 @@ func runServer(cmd *Command, args []string) bool {
*isStartingFiler = true *isStartingFiler = true
} }
*filerOptions.master = *serverIp + ":" + strconv.Itoa(*masterPort)
*filerOptions.master = net.JoinHostPort(*serverIp, strconv.Itoa(*masterPort))
if *filerOptions.defaultReplicaPlacement == "" { if *filerOptions.defaultReplicaPlacement == "" {
*filerOptions.defaultReplicaPlacement = *masterDefaultReplicaPlacement *filerOptions.defaultReplicaPlacement = *masterDefaultReplicaPlacement
@ -201,8 +202,8 @@ func runServer(cmd *Command, args []string) bool {
serverWhiteList, *serverSecureKey, serverWhiteList, *serverSecureKey,
) )
glog.V(0).Infoln("Start Seaweed Master", util.VERSION, "at", *serverIp+":"+strconv.Itoa(*masterPort))
masterListener, e := util.NewListener(*serverBindIp+":"+strconv.Itoa(*masterPort), time.Duration(*serverTimeout)*time.Second)
glog.V(0).Infoln("Start Seaweed Master", util.VERSION, "at", net.JoinHostPort(*serverIp, strconv.Itoa(*masterPort)))
masterListener, e := util.NewListener(net.JoinHostPort(*serverBindIp, strconv.Itoa(*masterPort)), time.Duration(*serverTimeout)*time.Second)
if e != nil { if e != nil {
glog.Fatalf("Master startup error: %v", e) glog.Fatalf("Master startup error: %v", e)
} }
@ -210,7 +211,7 @@ func runServer(cmd *Command, args []string) bool {
go func() { go func() {
raftWaitForMaster.Wait() raftWaitForMaster.Wait()
time.Sleep(100 * time.Millisecond) time.Sleep(100 * time.Millisecond)
myAddress := *serverIp + ":" + strconv.Itoa(*masterPort)
myAddress := net.JoinHostPort(*serverIp, strconv.Itoa(*masterPort))
var peers []string var peers []string
if *serverPeers != "" { if *serverPeers != "" {
peers = strings.Split(*serverPeers, ",") peers = strings.Split(*serverPeers, ",")
@ -232,7 +233,7 @@ func runServer(cmd *Command, args []string) bool {
*volumePublicPort = *volumePort *volumePublicPort = *volumePort
} }
if *volumeServerPublicUrl == "" { if *volumeServerPublicUrl == "" {
*volumeServerPublicUrl = *serverIp + ":" + strconv.Itoa(*volumePublicPort)
*volumeServerPublicUrl = net.JoinHostPort(*serverIp, strconv.Itoa(*volumePublicPort))
} }
isSeperatedPublicPort := *volumePublicPort != *volumePort isSeperatedPublicPort := *volumePublicPort != *volumePort
volumeMux := http.NewServeMux() volumeMux := http.NewServeMux()
@ -251,20 +252,20 @@ func runServer(cmd *Command, args []string) bool {
*serverIp, *volumePort, *volumeServerPublicUrl, *serverIp, *volumePort, *volumeServerPublicUrl,
folders, maxCounts, folders, maxCounts,
volumeNeedleMapKind, volumeNeedleMapKind,
*serverIp+":"+strconv.Itoa(*masterPort), *volumePulse, *serverDataCenter, *serverRack,
net.JoinHostPort(*serverIp, strconv.Itoa(*masterPort)), *volumePulse, *serverDataCenter, *serverRack,
serverWhiteList, *volumeFixJpgOrientation, *volumeReadRedirect, serverWhiteList, *volumeFixJpgOrientation, *volumeReadRedirect,
) )
glog.V(0).Infoln("Start Seaweed volume server", util.VERSION, "at", *serverIp+":"+strconv.Itoa(*volumePort))
glog.V(0).Infoln("Start Seaweed volume server", util.VERSION, "at", net.JoinHostPort(*serverIp, strconv.Itoa(*volumePort)))
volumeListener, eListen := util.NewListener( volumeListener, eListen := util.NewListener(
*serverBindIp+":"+strconv.Itoa(*volumePort),
net.JoinHostPort(*serverBindIp, strconv.Itoa(*volumePort)),
time.Duration(*serverTimeout)*time.Second, time.Duration(*serverTimeout)*time.Second,
) )
if eListen != nil { if eListen != nil {
glog.Fatalf("Volume server listener error: %v", eListen) glog.Fatalf("Volume server listener error: %v", eListen)
} }
if isSeperatedPublicPort { if isSeperatedPublicPort {
publicListeningAddress := *serverIp + ":" + strconv.Itoa(*volumePublicPort)
publicListeningAddress := net.JoinHostPort(*serverIp, strconv.Itoa(*volumePublicPort))
glog.V(0).Infoln("Start Seaweed volume server", util.VERSION, "public at", publicListeningAddress) glog.V(0).Infoln("Start Seaweed volume server", util.VERSION, "public at", publicListeningAddress)
publicListener, e := util.NewListener(publicListeningAddress, time.Duration(*serverTimeout)*time.Second) publicListener, e := util.NewListener(publicListeningAddress, time.Duration(*serverTimeout)*time.Second)
if e != nil { if e != nil {

7
go/weed/volume.go

@ -12,6 +12,7 @@ import (
"github.com/chrislusf/seaweedfs/go/storage" "github.com/chrislusf/seaweedfs/go/storage"
"github.com/chrislusf/seaweedfs/go/util" "github.com/chrislusf/seaweedfs/go/util"
"github.com/chrislusf/seaweedfs/go/weed/weed_server" "github.com/chrislusf/seaweedfs/go/weed/weed_server"
"net"
) )
var ( var (
@ -108,7 +109,7 @@ func runVolume(cmd *Command, args []string) bool {
*v.publicPort = *v.port *v.publicPort = *v.port
} }
if *v.publicUrl == "" { if *v.publicUrl == "" {
*v.publicUrl = *v.ip + ":" + strconv.Itoa(*v.publicPort)
*v.publicUrl = net.JoinHostPort(*v.ip, strconv.Itoa(*v.publicPort))
} }
isSeperatedPublicPort := *v.publicPort != *v.port isSeperatedPublicPort := *v.publicPort != *v.port
@ -134,14 +135,14 @@ func runVolume(cmd *Command, args []string) bool {
*v.fixJpgOrientation, *v.readRedirect, *v.fixJpgOrientation, *v.readRedirect,
) )
listeningAddress := *v.bindIp + ":" + strconv.Itoa(*v.port)
listeningAddress := net.JoinHostPort(*v.bindIp, strconv.Itoa(*v.port))
glog.V(0).Infoln("Start Seaweed volume server", util.VERSION, "at", listeningAddress) glog.V(0).Infoln("Start Seaweed volume server", util.VERSION, "at", listeningAddress)
listener, e := util.NewListener(listeningAddress, time.Duration(*v.idleConnectionTimeout)*time.Second) listener, e := util.NewListener(listeningAddress, time.Duration(*v.idleConnectionTimeout)*time.Second)
if e != nil { if e != nil {
glog.Fatalf("Volume server listener error:%v", e) glog.Fatalf("Volume server listener error:%v", e)
} }
if isSeperatedPublicPort { if isSeperatedPublicPort {
publicListeningAddress := *v.bindIp + ":" + strconv.Itoa(*v.publicPort)
publicListeningAddress := net.JoinHostPort(*v.bindIp, strconv.Itoa(*v.publicPort))
glog.V(0).Infoln("Start Seaweed volume server", util.VERSION, "public at", publicListeningAddress) glog.V(0).Infoln("Start Seaweed volume server", util.VERSION, "public at", publicListeningAddress)
publicListener, e := util.NewListener(publicListeningAddress, time.Duration(*v.idleConnectionTimeout)*time.Second) publicListener, e := util.NewListener(publicListeningAddress, time.Duration(*v.idleConnectionTimeout)*time.Second)
if e != nil { if e != nil {

12
go/weed/weed_server/master_server_handlers_admin.go

@ -7,11 +7,12 @@ import (
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"strconv" "strconv"
"strings"
"net/url" "net/url"
"sync" "sync"
"net"
"github.com/chrislusf/seaweedfs/go/glog" "github.com/chrislusf/seaweedfs/go/glog"
"github.com/chrislusf/seaweedfs/go/operation" "github.com/chrislusf/seaweedfs/go/operation"
"github.com/chrislusf/seaweedfs/go/storage" "github.com/chrislusf/seaweedfs/go/storage"
@ -27,7 +28,7 @@ func (ms *MasterServer) collectionDeleteHandler(w http.ResponseWriter, r *http.R
return return
} }
for _, server := range collection.ListVolumeServers() { for _, server := range collection.ListVolumeServers() {
_, err := util.Get(server.Ip+":"+strconv.Itoa(server.Port), "/admin/delete_collection", url.Values{"collection": r.Form["collection"]})
_, err := util.Get(net.JoinHostPort(server.Ip, strconv.Itoa(server.Port)), "/admin/delete_collection", url.Values{"collection": r.Form["collection"]})
if err != nil { if err != nil {
writeJsonError(w, r, http.StatusInternalServerError, err) writeJsonError(w, r, http.StatusInternalServerError, err)
return return
@ -48,7 +49,12 @@ func (ms *MasterServer) dirJoinHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
if *joinMessage.Ip == "" { if *joinMessage.Ip == "" {
*joinMessage.Ip = r.RemoteAddr[0:strings.Index(r.RemoteAddr, ":")]
if ip, _, e := net.SplitHostPort(r.RemoteAddr); e == nil {
*joinMessage.Ip = ip
} else {
glog.V(2).Infof("SplitHostPort (%s) error, %v", r.RemoteAddr, e)
*joinMessage.Ip = r.RemoteAddr
}
} }
if glog.V(4) { if glog.V(4) {
if jsonData, jsonError := json.Marshal(joinMessage); jsonError != nil { if jsonData, jsonError := json.Marshal(joinMessage); jsonError != nil {

Loading…
Cancel
Save