From d344e87de098be4954f1ce7d32b21e6d73144de1 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Fri, 25 Apr 2014 22:09:42 -0700 Subject: [PATCH] Adjust command line options. 1. switch to use -publicIp instead of -publicUrl 2. -ip can be empty. It will listen to all available interfaces. 3. For "weed master", these options are changed: -masterPort => -master.port -peers => -master.peers -mdir => -master.dir -volumeSizeLimitMB => -master.volumeSizeLimitMB -conf => -master.conf -defaultReplicaPlacement => -master.defaultReplicaPlacement -port => -volume.port -max => -volume.max --- go/weed/master.go | 23 +++++++----- go/weed/server.go | 52 ++++++++++++++++------------ go/weed/volume.go | 24 +++++++------ go/weed/weed_server/volume_server.go | 4 ++- 4 files changed, 61 insertions(+), 42 deletions(-) diff --git a/go/weed/master.go b/go/weed/master.go index c494ff42b..b95ca5cb1 100644 --- a/go/weed/master.go +++ b/go/weed/master.go @@ -28,7 +28,8 @@ var cmdMaster = &Command{ var ( mport = cmdMaster.Flag.Int("port", 9333, "http listen port") - masterIp = cmdMaster.Flag.String("ip", "localhost", "master ip address") + masterIp = cmdMaster.Flag.String("ip", "", "master listening ip address, default to listen on all network interfaces") + mPublicIp = cmdMaster.Flag.String("publicIp", "", "peer accessible |") metaFolder = cmdMaster.Flag.String("mdir", os.TempDir(), "data directory to store meta data") masterPeers = cmdMaster.Flag.String("peers", "", "other master nodes in comma separated ip:port list") volumeSizeLimitMB = cmdMaster.Flag.Uint("volumeSizeLimitMB", 30*1000, "Master stops directing writes to oversized volumes.") @@ -60,24 +61,30 @@ func runMaster(cmd *Command, args []string) bool { *volumeSizeLimitMB, *mpulse, *confFile, *defaultReplicaPlacement, *garbageThreshold, masterWhiteList, ) - glog.V(0).Infoln("Start Weed Master", util.VERSION, "at port", *masterIp+":"+strconv.Itoa(*mport)) + listeningAddress := *masterIp + ":" + strconv.Itoa(*mport) - listener, e := util.NewListener( - *masterIp+":"+strconv.Itoa(*mport), - time.Duration(*mTimeout)*time.Second, - ) + glog.V(0).Infoln("Start Weed Master", util.VERSION, "at", listeningAddress) + + listener, e := util.NewListener(listeningAddress, time.Duration(*mTimeout)*time.Second) if e != nil { glog.Fatalf(e.Error()) } go func() { time.Sleep(100 * time.Millisecond) - myAddress := *masterIp + ":" + strconv.Itoa(*mport) + if *mPublicIp == "" { + if *masterIp == "" { + *mPublicIp = "localhost" + } else { + *mPublicIp = *masterIp + } + } + myPublicMasterAddress := *mPublicIp + ":" + strconv.Itoa(*mport) var peers []string if *masterPeers != "" { peers = strings.Split(*masterPeers, ",") } - raftServer := weed_server.NewRaftServer(r, peers, myAddress, *metaFolder, ms.Topo, *mpulse) + raftServer := weed_server.NewRaftServer(r, peers, myPublicMasterAddress, *metaFolder, ms.Topo, *mpulse) ms.SetRaftServer(raftServer) }() diff --git a/go/weed/server.go b/go/weed/server.go index dde896c09..a99ed0423 100644 --- a/go/weed/server.go +++ b/go/weed/server.go @@ -29,29 +29,33 @@ var cmdServer = &Command{ and a master server to provide volume=>location mapping service and sequence number of file ids This is provided as a convenient way to start both volume server and master server. - The servers are the same as starting them separately. + The servers are exactly the same as starting them separately. + So other volume servers can use this embedded master server also. + Optionally, one filer server can be started. Logically, filer servers should not be in a cluster. + They run with meta data on disk, not shared. So each filer server is different. + `, } var ( - serverIp = cmdServer.Flag.String("ip", "localhost", "ip or server name") + serverIp = cmdServer.Flag.String("ip", "", "ip or server name") + serverPublicIp = cmdServer.Flag.String("publicIp", "", "ip or server name") serverMaxCpu = cmdServer.Flag.Int("maxCpu", 0, "maximum number of CPUs. 0 means all available CPUs") serverTimeout = cmdServer.Flag.Int("idleTimeout", 10, "connection idle seconds") serverDataCenter = cmdServer.Flag.String("dataCenter", "", "current volume server's data center name") serverRack = cmdServer.Flag.String("rack", "", "current volume server's rack name") serverWhiteListOption = cmdServer.Flag.String("whiteList", "", "comma separated Ip addresses having write permission. No limit if empty.") - serverPeers = cmdServer.Flag.String("peers", "", "other master nodes in comma separated ip:masterPort list") - masterPort = cmdServer.Flag.Int("masterPort", 9333, "master server http listen port") - masterMetaFolder = cmdServer.Flag.String("mdir", "", "data directory to store meta data, default to same as -dir specified") - masterVolumeSizeLimitMB = cmdServer.Flag.Uint("volumeSizeLimitMB", 30*1000, "Master stops directing writes to oversized volumes.") - masterConfFile = cmdServer.Flag.String("conf", "/etc/weedfs/weedfs.conf", "xml configuration file") - masterDefaultReplicaPlacement = cmdServer.Flag.String("defaultReplicaPlacement", "000", "Default replication type if not specified.") - volumePort = cmdServer.Flag.Int("port", 8080, "volume server http listen port") - volumePublicUrl = cmdServer.Flag.String("publicUrl", "", "Publicly accessible :") + serverPeers = cmdServer.Flag.String("master.peers", "", "other master nodes in comma separated ip:masterPort list") + masterPort = cmdServer.Flag.Int("master.port", 9333, "master server http listen port") + masterMetaFolder = cmdServer.Flag.String("master.dir", "", "data directory to store meta data, default to same as -dir specified") + masterVolumeSizeLimitMB = cmdServer.Flag.Uint("master.volumeSizeLimitMB", 30*1000, "Master stops directing writes to oversized volumes.") + masterConfFile = cmdServer.Flag.String("master.conf", "/etc/weedfs/weedfs.conf", "xml configuration file") + masterDefaultReplicaPlacement = cmdServer.Flag.String("master.defaultReplicaPlacement", "000", "Default replication type if not specified.") + volumePort = cmdServer.Flag.Int("volume.port", 8080, "volume server http listen port") volumeDataFolders = cmdServer.Flag.String("dir", os.TempDir(), "directories to store data files. dir[,dir]...") - volumeMaxDataVolumeCounts = cmdServer.Flag.String("max", "7", "maximum numbers of volumes, count[,count]...") + volumeMaxDataVolumeCounts = cmdServer.Flag.String("volume.max", "7", "maximum numbers of volumes, count[,count]...") volumePulse = cmdServer.Flag.Int("pulseSeconds", 5, "number of seconds between heartbeats") isStartingFiler = cmdServer.Flag.Bool("filer", false, "whether to start filer") @@ -68,7 +72,15 @@ func init() { func runServer(cmd *Command, args []string) bool { - *filer.master = *serverIp + ":" + strconv.Itoa(*masterPort) + if *serverPublicIp == "" { + if *serverIp == "" { + *serverPublicIp = "localhost" + } else { + *serverPublicIp = *serverIp + } + } + + *filer.master = *serverPublicIp + ":" + strconv.Itoa(*masterPort) if *filer.defaultReplicaPlacement == "" { *filer.defaultReplicaPlacement = *masterDefaultReplicaPlacement @@ -112,9 +124,6 @@ func runServer(cmd *Command, args []string) bool { glog.Fatalf("Check Mapping Meta Folder (-filer.dir=\"%s\") Writable: %s", *filer.dir, err) } - if *volumePublicUrl == "" { - *volumePublicUrl = *serverIp + ":" + strconv.Itoa(*volumePort) - } if *serverWhiteListOption != "" { serverWhiteList = strings.Split(*serverWhiteListOption, ",") } @@ -152,11 +161,8 @@ func runServer(cmd *Command, args []string) bool { *masterVolumeSizeLimitMB, *volumePulse, *masterConfFile, *masterDefaultReplicaPlacement, *garbageThreshold, serverWhiteList, ) - glog.V(0).Infoln("Start Weed Master", util.VERSION, "at port", *serverIp+":"+strconv.Itoa(*masterPort)) - masterListener, e := util.NewListener( - *serverIp+":"+strconv.Itoa(*masterPort), - time.Duration(*serverTimeout)*time.Second, - ) + glog.V(0).Infoln("Start Weed Master", util.VERSION, "at", *serverIp+":"+strconv.Itoa(*masterPort)) + masterListener, e := util.NewListener(*serverIp+":"+strconv.Itoa(*masterPort), time.Duration(*serverTimeout)*time.Second) if e != nil { glog.Fatalf(e.Error()) } @@ -164,7 +170,7 @@ func runServer(cmd *Command, args []string) bool { go func() { raftWaitForMaster.Wait() time.Sleep(100 * time.Millisecond) - myAddress := *serverIp + ":" + strconv.Itoa(*masterPort) + myAddress := *serverPublicIp + ":" + strconv.Itoa(*masterPort) var peers []string if *serverPeers != "" { peers = strings.Split(*serverPeers, ",") @@ -183,11 +189,11 @@ func runServer(cmd *Command, args []string) bool { volumeWait.Wait() time.Sleep(100 * time.Millisecond) r := http.NewServeMux() - weed_server.NewVolumeServer(r, *serverIp, *volumePort, *volumePublicUrl, folders, maxCounts, + weed_server.NewVolumeServer(r, *serverIp, *volumePort, *serverPublicIp, folders, maxCounts, *serverIp+":"+strconv.Itoa(*masterPort), *volumePulse, *serverDataCenter, *serverRack, serverWhiteList, ) - glog.V(0).Infoln("Start Weed volume server", util.VERSION, "at http://"+*serverIp+":"+strconv.Itoa(*volumePort)) + glog.V(0).Infoln("Start Weed volume server", util.VERSION, "at", *serverIp+":"+strconv.Itoa(*volumePort)) volumeListener, e := util.NewListener( *serverIp+":"+strconv.Itoa(*volumePort), time.Duration(*serverTimeout)*time.Second, diff --git a/go/weed/volume.go b/go/weed/volume.go index a43a396b2..43cff9ccf 100644 --- a/go/weed/volume.go +++ b/go/weed/volume.go @@ -28,8 +28,8 @@ var ( vport = cmdVolume.Flag.Int("port", 8080, "http listen port") volumeFolders = cmdVolume.Flag.String("dir", os.TempDir(), "directories to store data files. dir[,dir]...") maxVolumeCounts = cmdVolume.Flag.String("max", "7", "maximum numbers of volumes, count[,count]...") - ip = cmdVolume.Flag.String("ip", "localhost", "ip or server name") - publicUrl = cmdVolume.Flag.String("publicUrl", "", "Publicly accessible :") + ip = cmdVolume.Flag.String("ip", "", "ip or server name") + publicIp = cmdVolume.Flag.String("publicIp", "", "Publicly accessible ") masterNode = cmdVolume.Flag.String("mserver", "localhost:9333", "master server location") vpulse = cmdVolume.Flag.Int("pulseSeconds", 5, "number of seconds between heartbeats, must be smaller than or equal to the master's setting") vTimeout = cmdVolume.Flag.Int("idleTimeout", 10, "connection idle seconds") @@ -65,8 +65,12 @@ func runVolume(cmd *Command, args []string) bool { } } - if *publicUrl == "" { - *publicUrl = *ip + ":" + strconv.Itoa(*vport) + if *publicIp == "" { + if *ip == "" { + *publicIp = "localhost" + } else { + *publicIp = *ip + } } if *volumeWhiteListOption != "" { volumeWhiteList = strings.Split(*volumeWhiteListOption, ",") @@ -74,15 +78,15 @@ func runVolume(cmd *Command, args []string) bool { r := http.NewServeMux() - weed_server.NewVolumeServer(r, *ip, *vport, *publicUrl, folders, maxCounts, + weed_server.NewVolumeServer(r, *ip, *vport, *publicIp, folders, maxCounts, *masterNode, *vpulse, *dataCenter, *rack, volumeWhiteList, ) - glog.V(0).Infoln("Start Weed volume server", util.VERSION, "at http://"+*ip+":"+strconv.Itoa(*vport)) - listener, e := util.NewListener( - *ip+":"+strconv.Itoa(*vport), - time.Duration(*vTimeout)*time.Second, - ) + listeningAddress := *ip + ":" + strconv.Itoa(*vport) + + glog.V(0).Infoln("Start Weed volume server", util.VERSION, "at", listeningAddress) + + listener, e := util.NewListener(listeningAddress, time.Duration(*vTimeout)*time.Second) if e != nil { glog.Fatalf(e.Error()) } diff --git a/go/weed/weed_server/volume_server.go b/go/weed/weed_server/volume_server.go index 1db0f9581..01473b91a 100644 --- a/go/weed/weed_server/volume_server.go +++ b/go/weed/weed_server/volume_server.go @@ -5,6 +5,7 @@ import ( "code.google.com/p/weed-fs/go/storage" "math/rand" "net/http" + "strconv" "time" ) @@ -17,10 +18,11 @@ type VolumeServer struct { store *storage.Store } -func NewVolumeServer(r *http.ServeMux, ip string, port int, publicUrl string, folders []string, maxCounts []int, +func NewVolumeServer(r *http.ServeMux, ip string, port int, publicIp string, folders []string, maxCounts []int, masterNode string, pulseSeconds int, dataCenter string, rack string, whiteList []string) *VolumeServer { + publicUrl := publicIp + ":" + strconv.Itoa(port) vs := &VolumeServer{ masterNode: masterNode, pulseSeconds: pulseSeconds,