fix: transfer get stra

This commit is contained in:
710leo 2020-04-01 16:14:57 +08:00
parent b88b9b670f
commit 428ce391f9
3 changed files with 26 additions and 10 deletions

View File

@ -248,24 +248,35 @@ func getIndexFromRemote(instances []*model.Instance) error {
filepath := fmt.Sprintf("db.tar.gz")
var err error
// Get the data
perm := rand.Perm(len(instances))
for i := range perm {
url := fmt.Sprintf("http://%s:%s/api/index/idxfile", instances[perm[i]].Identity, instances[perm[i]].HTTPPort)
resp, err := http.Get(url)
if err != nil {
return err
resp, e := http.Get(url)
if e != nil {
err = fmt.Errorf("get index from:%s err:%v", url, e)
logger.Warning(err)
continue
}
defer resp.Body.Close()
// Create the file
out, err := os.Create(filepath)
if err != nil {
return err
out, e := os.Create(filepath)
if e != nil {
err = fmt.Errorf("create file:%s err:%v", filepath, e)
logger.Warning(err)
continue
}
defer out.Close()
// Write the body to file
_, err = io.Copy(out, resp.Body)
if err != nil {
logger.Warning(err)
continue
}
break
}
if err != nil {
return err
}
compress.UnTarGz(filepath, ".")
@ -273,9 +284,7 @@ func getIndexFromRemote(instances []*model.Instance) error {
return err
}
//清空db目录
if err = os.Remove(filepath); err != nil {
return err
}
err = os.Remove(filepath)
return err
}

View File

@ -53,7 +53,11 @@ func getStrategy() {
logger.Warningf("get strategy from remote failed, error:%v", stras.Err)
continue
}
if len(stras.Data) > 0 {
break
}
}
if err != nil {
logger.Error("get stra err:", err)
stats.Counter.Set("stra.err", 1)

View File

@ -48,6 +48,7 @@ func pullRRD(node string, addr string, concurrent int) {
time.Sleep(10 * time.Millisecond)
continue
}
stats.Counter.Set("pull.rrd", count)
filenames := make([]dataobj.RRDFile, count)
for i := 0; i < count; i++ {
@ -78,11 +79,13 @@ func pullRRD(node string, addr string, concurrent int) {
paths := strings.Split(f.Filename, "/")
if len(paths) != 2 {
logger.Errorf("write rrd file err %v filename:%s", err, f.Filename)
stats.Counter.Set("pull.rrd.err", count)
continue
}
file.EnsureDir(rrdtool.Config.Storage + "/" + paths[0])
err = utils.WriteFile(filePath, f.Body, 0644)
if err != nil {
stats.Counter.Set("pull.rrd.err", count)
logger.Errorf("write rrd file err %v filename:%s", err, f.Filename)
}