Commit 4bf8af55 authored by szh's avatar szh

deal node of wrong type

parent c1062ba7
...@@ -169,12 +169,58 @@ func BityuanJob(ticker *time.Ticker) { ...@@ -169,12 +169,58 @@ func BityuanJob(ticker *time.Ticker) {
} }
//升级6.4.0bityuan //升级6.4.0bityuan
//updateBityuan640() //updateBityuan640()
err := MakeSureNodeRunning()
if err != nil {
tlog.Error("bityuan job", "err", err)
}
} }
BityuanFlag.Lock.Unlock() BityuanFlag.Lock.Unlock()
} }
} }
} }
// MakeSureNodeRunning 针对node 异常情况做出对应处理策略
func MakeSureNodeRunning() error {
var pai pai_service.Pai
err := pai.SetPai()
if err != nil {
tlog.Error("MakeSureNodeRunning SetPai", "err", err)
return err
}
// peer list只有自己 节点应进行重启或升级
if pai.PeerLen == 1 {
util.AddValue(&JobID, 1)
JobChan <- MsgType{Name: "RESTART", JobID: JobID}
return nil
}
nowTime := time.Now().Unix()
// 节点高度一直不增长 可能是由于非正常启动矿机造成 进行回滚操作
if pai.LocalLastHeight > 0 {
if heightStr == "" {
heightStr = fmt.Sprintf("%d_%d", nowTime, pai.LocalLastHeight)
} else {
lastTime, lastHeight := getLastHeightFromCache()
tlog.Info("last ", "height", lastHeight)
//高度无变化且时间超过1小时 程序内部发送回滚信号
if lastHeight == pai.LocalLastHeight {
if (nowTime - lastTime) > 3600 {
tlog.Error("node stop sync rleady to rollback", "height", pai.LocalLastHeight)
util.AddValue(&JobID, 1)
JobChan <- MsgType{Name: "ROLLBACK", JobID: JobID}
return nil
}
} else if lastHeight < pai.LocalLastHeight { //高度增长则更新cache
heightStr = fmt.Sprintf("%d_%d", nowTime, pai.LocalLastHeight)
} else {
heightStr = fmt.Sprintf("%d_%d", nowTime, pai.LocalLastHeight)
}
}
}
//节点版本过低 导致的异常
return nil
}
func Copy(src, dst string) { func Copy(src, dst string) {
cp := exec.Command("cp", "-r", src, dst) cp := exec.Command("cp", "-r", src, dst)
cp.Start() cp.Start()
...@@ -711,27 +757,27 @@ func uploadInfo() error { ...@@ -711,27 +757,27 @@ func uploadInfo() error {
tlog.Error("SetPai", "err", err) tlog.Error("SetPai", "err", err)
return err return err
} }
nowTime := time.Now().Unix() // nowTime := time.Now().Unix()
if pai.LocalLastHeight > 0 { // if pai.LocalLastHeight > 0 {
if heightStr == "" { // if heightStr == "" {
heightStr = fmt.Sprintf("%d_%d", nowTime, pai.LocalLastHeight) // heightStr = fmt.Sprintf("%d_%d", nowTime, pai.LocalLastHeight)
} else { // } else {
lastTime, lastHeight := getLastHeightFromCache() // lastTime, lastHeight := getLastHeightFromCache()
tlog.Info("last ", "height", lastHeight) // tlog.Info("last ", "height", lastHeight)
//高度无变化且时间超过1小时 程序内部发送回滚信号 // //高度无变化且时间超过1小时 程序内部发送回滚信号
if lastHeight == pai.LocalLastHeight { // if lastHeight == pai.LocalLastHeight {
if (nowTime - lastTime) > 3600 { // if (nowTime - lastTime) > 3600 {
tlog.Error("node stop sync rleady to rollback", "height", pai.LocalLastHeight) // tlog.Error("node stop sync rleady to rollback", "height", pai.LocalLastHeight)
util.AddValue(&JobID, 1) // util.AddValue(&JobID, 1)
JobChan <- MsgType{Name: "ROLLBACK", JobID: JobID} // JobChan <- MsgType{Name: "ROLLBACK", JobID: JobID}
} // }
} else if lastHeight < pai.LocalLastHeight { //高度增长则更新cache // } else if lastHeight < pai.LocalLastHeight { //高度增长则更新cache
heightStr = fmt.Sprintf("%d_%d", nowTime, pai.LocalLastHeight) // heightStr = fmt.Sprintf("%d_%d", nowTime, pai.LocalLastHeight)
} else { // } else {
heightStr = fmt.Sprintf("%d_%d", nowTime, pai.LocalLastHeight) // heightStr = fmt.Sprintf("%d_%d", nowTime, pai.LocalLastHeight)
} // }
} // }
} // }
if pai.NetInfo == nil { if pai.NetInfo == nil {
net := &types.NodeNetInfo{} net := &types.NodeNetInfo{}
ips, err := GetRightIPs() ips, err := GetRightIPs()
......
...@@ -9,8 +9,6 @@ import ( ...@@ -9,8 +9,6 @@ import (
"chain33-pai/pkg/setting" "chain33-pai/pkg/setting"
"encoding/json" "encoding/json"
"errors" "errors"
log "github.com/33cn/chain33/common/log/log15"
"github.com/33cn/chain33/types"
"io" "io"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
...@@ -18,6 +16,9 @@ import ( ...@@ -18,6 +16,9 @@ import (
"os/exec" "os/exec"
"strconv" "strconv"
"strings" "strings"
log "github.com/33cn/chain33/common/log/log15"
"github.com/33cn/chain33/types"
) )
var ( var (
...@@ -46,6 +47,7 @@ type Pai struct { ...@@ -46,6 +47,7 @@ type Pai struct {
LocalLastHeight2 int64 `json:"local_last_height_2"` LocalLastHeight2 int64 `json:"local_last_height_2"`
ProLevel int64 `json:"pro_level"` ProLevel int64 `json:"pro_level"`
Temp int64 `json:"temp"` Temp int64 `json:"temp"`
PeerLen int64 `json:"peer_len"`
} }
type ReqUpdatePai struct { type ReqUpdatePai struct {
...@@ -123,7 +125,7 @@ func (p *Pai) GetDevstatus() error { ...@@ -123,7 +125,7 @@ func (p *Pai) GetDevstatus() error {
p.Err = err.Error() p.Err = err.Error()
return err return err
} }
p.PeerLen = int64(len(peerinfo.Peers))
for _, v := range peerinfo.Peers { for _, v := range peerinfo.Peers {
if p.LastHeight < v.Header.Height { if p.LastHeight < v.Header.Height {
p.LastHeight = v.Header.Height p.LastHeight = v.Header.Height
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment