From 0e3140c54c7f461a6b54ebac6d315542cc5e4ea9 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Mon, 6 Jun 2016 23:50:27 -0700 Subject: [PATCH] a little refactoring --- weed/server/filer_server.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/weed/server/filer_server.go b/weed/server/filer_server.go index 767db3aea..dfdf25333 100644 --- a/weed/server/filer_server.go +++ b/weed/server/filer_server.go @@ -120,20 +120,14 @@ func (fs *FilerServer) setMasterNode(masterNode string) { } func (fs *FilerServer) detectHealthyMaster(masterNode string) (master string, e error) { - statUrl := "http://" + masterNode + "/stats" - glog.V(4).Infof("Connecting to %s ...", statUrl) - _, e = util.Get(statUrl) - if e != nil { + if e = checkMaster(masterNode); e != nil { fs.masterNodes.Reset() for i := 0; i <= 3; i++ { master, e = fs.masterNodes.FindMaster() if e != nil { continue } else { - statUrl := "http://" + master + "/stats" - glog.V(4).Infof("Connecting to %s ...", statUrl) - _, e = util.Get(statUrl) - if e == nil { + if e = checkMaster(masterNode); e == nil { break } } @@ -143,3 +137,10 @@ func (fs *FilerServer) detectHealthyMaster(masterNode string) (master string, e } return } + +func checkMaster(masterNode string) error { + statUrl := "http://" + masterNode + "/stats" + glog.V(4).Infof("Connecting to %s ...", statUrl) + _, e := util.Get(statUrl) + return e +}