mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-10-15 03:04:54 +08:00
1. volume server auto detect clustered master nodes
2. remove operation package dependency on storage
This commit is contained in:
@@ -28,8 +28,9 @@ var cmdMaster = &Command{
|
||||
|
||||
var (
|
||||
mport = cmdMaster.Flag.Int("port", 9333, "http listen port")
|
||||
mip = cmdMaster.Flag.String("ip", "localhost", "http listen port")
|
||||
masterIp = cmdMaster.Flag.String("ip", "", "master ip address")
|
||||
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", 32*1000, "Default Volume Size in MegaBytes")
|
||||
mpulse = cmdMaster.Flag.Int("pulseSeconds", 5, "number of seconds between heartbeats")
|
||||
confFile = cmdMaster.Flag.String("conf", "/etc/weedfs/weedfs.conf", "xml configuration file")
|
||||
@@ -55,16 +56,28 @@ func runMaster(cmd *Command, args []string) bool {
|
||||
}
|
||||
|
||||
r := mux.NewRouter()
|
||||
weed_server.NewMasterServer(r, VERSION, *mport, *metaFolder,
|
||||
ms := weed_server.NewMasterServer(r, VERSION, *mport, *metaFolder,
|
||||
*volumeSizeLimitMB, *mpulse, *confFile, *defaultRepType, *garbageThreshold, masterWhiteList,
|
||||
)
|
||||
|
||||
glog.V(0).Infoln("Start Weed Master", VERSION, "at port", *mip+":"+strconv.Itoa(*mport))
|
||||
glog.V(0).Infoln("Start Weed Master", VERSION, "at port", *masterIp+":"+strconv.Itoa(*mport))
|
||||
|
||||
srv := &http.Server{
|
||||
Addr: *mip + ":" + strconv.Itoa(*mport),
|
||||
Addr: *masterIp + ":" + strconv.Itoa(*mport),
|
||||
Handler: r,
|
||||
ReadTimeout: time.Duration(*mReadTimeout) * time.Second,
|
||||
}
|
||||
|
||||
go func() {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
var peers []string
|
||||
if *masterPeers != "" {
|
||||
peers = strings.Split(*masterPeers, ",")
|
||||
}
|
||||
raftServer := weed_server.NewRaftServer(r, VERSION, peers, *masterIp+":"+strconv.Itoa(*mport), *metaFolder)
|
||||
ms.SetRaftServer(raftServer)
|
||||
}()
|
||||
|
||||
e := srv.ListenAndServe()
|
||||
if e != nil {
|
||||
glog.Fatalf("Fail to start:%s", e)
|
||||
|
@@ -43,7 +43,7 @@ func NewVolumeServer(r *http.ServeMux, version string, ip string, port int, publ
|
||||
|
||||
go func() {
|
||||
connected := true
|
||||
vs.store.SetMaster(vs.masterNode)
|
||||
vs.store.SetBootstrapMaster(vs.masterNode)
|
||||
vs.store.SetDataCenter(vs.dataCenter)
|
||||
vs.store.SetRack(vs.rack)
|
||||
for {
|
||||
@@ -58,7 +58,11 @@ func NewVolumeServer(r *http.ServeMux, version string, ip string, port int, publ
|
||||
connected = false
|
||||
}
|
||||
}
|
||||
time.Sleep(time.Duration(float32(vs.pulseSeconds*1e3)*(1+rand.Float32())) * time.Millisecond)
|
||||
if connected {
|
||||
time.Sleep(time.Duration(float32(vs.pulseSeconds*1e3)*(1+rand.Float32())) * time.Millisecond)
|
||||
} else {
|
||||
time.Sleep(time.Duration(float32(vs.pulseSeconds*1e3)* 0.25) * time.Millisecond)
|
||||
}
|
||||
}
|
||||
}()
|
||||
glog.V(0).Infoln("store joined at", vs.masterNode)
|
||||
|
@@ -102,7 +102,7 @@ func (vs *VolumeServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request,
|
||||
|
||||
glog.V(2).Infoln("volume", volumeId, "reading", n)
|
||||
if !vs.store.HasVolume(volumeId) {
|
||||
lookupResult, err := operation.Lookup(vs.masterNode, volumeId)
|
||||
lookupResult, err := operation.Lookup(vs.masterNode, volumeId.String())
|
||||
glog.V(2).Infoln("volume", volumeId, "found on", lookupResult, "error", err)
|
||||
if err == nil && len(lookupResult.Locations) > 0 {
|
||||
http.Redirect(w, r, "http://"+lookupResult.Locations[0].PublicUrl+r.URL.Path, http.StatusMovedPermanently)
|
||||
|
Reference in New Issue
Block a user