fix: transfer get stra
This commit is contained in:
parent
b88b9b670f
commit
428ce391f9
|
@ -248,24 +248,35 @@ func getIndexFromRemote(instances []*model.Instance) error {
|
||||||
filepath := fmt.Sprintf("db.tar.gz")
|
filepath := fmt.Sprintf("db.tar.gz")
|
||||||
var err error
|
var err error
|
||||||
// Get the data
|
// Get the data
|
||||||
|
|
||||||
perm := rand.Perm(len(instances))
|
perm := rand.Perm(len(instances))
|
||||||
for i := range perm {
|
for i := range perm {
|
||||||
url := fmt.Sprintf("http://%s:%s/api/index/idxfile", instances[perm[i]].Identity, instances[perm[i]].HTTPPort)
|
url := fmt.Sprintf("http://%s:%s/api/index/idxfile", instances[perm[i]].Identity, instances[perm[i]].HTTPPort)
|
||||||
resp, err := http.Get(url)
|
resp, e := http.Get(url)
|
||||||
if err != nil {
|
if e != nil {
|
||||||
return err
|
err = fmt.Errorf("get index from:%s err:%v", url, e)
|
||||||
|
logger.Warning(err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
// Create the file
|
// Create the file
|
||||||
out, err := os.Create(filepath)
|
out, e := os.Create(filepath)
|
||||||
if err != nil {
|
if e != nil {
|
||||||
return err
|
err = fmt.Errorf("create file:%s err:%v", filepath, e)
|
||||||
|
logger.Warning(err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
defer out.Close()
|
defer out.Close()
|
||||||
// Write the body to file
|
// Write the body to file
|
||||||
_, err = io.Copy(out, resp.Body)
|
_, err = io.Copy(out, resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
logger.Warning(err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
compress.UnTarGz(filepath, ".")
|
compress.UnTarGz(filepath, ".")
|
||||||
|
@ -273,9 +284,7 @@ func getIndexFromRemote(instances []*model.Instance) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
//清空db目录
|
//清空db目录
|
||||||
if err = os.Remove(filepath); err != nil {
|
err = os.Remove(filepath)
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,11 @@ func getStrategy() {
|
||||||
logger.Warningf("get strategy from remote failed, error:%v", stras.Err)
|
logger.Warningf("get strategy from remote failed, error:%v", stras.Err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if len(stras.Data) > 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("get stra err:", err)
|
logger.Error("get stra err:", err)
|
||||||
stats.Counter.Set("stra.err", 1)
|
stats.Counter.Set("stra.err", 1)
|
||||||
|
|
|
@ -48,6 +48,7 @@ func pullRRD(node string, addr string, concurrent int) {
|
||||||
time.Sleep(10 * time.Millisecond)
|
time.Sleep(10 * time.Millisecond)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
stats.Counter.Set("pull.rrd", count)
|
||||||
|
|
||||||
filenames := make([]dataobj.RRDFile, count)
|
filenames := make([]dataobj.RRDFile, count)
|
||||||
for i := 0; i < count; i++ {
|
for i := 0; i < count; i++ {
|
||||||
|
@ -78,11 +79,13 @@ func pullRRD(node string, addr string, concurrent int) {
|
||||||
paths := strings.Split(f.Filename, "/")
|
paths := strings.Split(f.Filename, "/")
|
||||||
if len(paths) != 2 {
|
if len(paths) != 2 {
|
||||||
logger.Errorf("write rrd file err %v filename:%s", err, f.Filename)
|
logger.Errorf("write rrd file err %v filename:%s", err, f.Filename)
|
||||||
|
stats.Counter.Set("pull.rrd.err", count)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
file.EnsureDir(rrdtool.Config.Storage + "/" + paths[0])
|
file.EnsureDir(rrdtool.Config.Storage + "/" + paths[0])
|
||||||
err = utils.WriteFile(filePath, f.Body, 0644)
|
err = utils.WriteFile(filePath, f.Body, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
stats.Counter.Set("pull.rrd.err", count)
|
||||||
logger.Errorf("write rrd file err %v filename:%s", err, f.Filename)
|
logger.Errorf("write rrd file err %v filename:%s", err, f.Filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue