|
@@ -98,31 +98,27 @@ func SetNode(app cfacade.IApplication) (string, int32) {
|
|
|
if lNode > 0 {
|
|
|
m, err := mdb.RDB.HGetAll(context.Background(), constant.ServerLoadHKey).Result()
|
|
|
if err != nil {
|
|
|
- nodeId = list[key].GetNodeId()
|
|
|
+ mhayaLogger.Warnf("[SetNode] Load too high. err=%v", err)
|
|
|
}
|
|
|
- if len(m) == 0 {
|
|
|
- nodeId = list[key].GetNodeId()
|
|
|
- } else {
|
|
|
- var maps = make(map[string]int, 10)
|
|
|
- for _, v := range list {
|
|
|
- if d, ok := m[v.GetNodeId()]; ok {
|
|
|
- p, ok := mhayaString.ToInt(d)
|
|
|
- if !ok {
|
|
|
- nodeId = list[key].GetNodeId()
|
|
|
- }
|
|
|
- maps[v.GetNodeId()] = p
|
|
|
- } else {
|
|
|
- maps[v.GetNodeId()] = 0
|
|
|
+ var maps = make(map[string]int, 10)
|
|
|
+ for _, v := range list {
|
|
|
+ if d, ok := m[v.GetNodeId()]; ok {
|
|
|
+ p, ok := mhayaString.ToInt(d)
|
|
|
+ if !ok {
|
|
|
+ nodeId = list[key].GetNodeId()
|
|
|
}
|
|
|
+ maps[v.GetNodeId()] = p
|
|
|
+ } else {
|
|
|
+ maps[v.GetNodeId()] = 0
|
|
|
}
|
|
|
- wwr := NewWeightedRoundRobin(maps)
|
|
|
- info := wwr.Pick()
|
|
|
- if info == nil {
|
|
|
- mhayaLogger.Warnf("[SetNode] Load too high. data=%v", maps)
|
|
|
- return "", code.Error
|
|
|
- }
|
|
|
- nodeId = info.NodeId
|
|
|
}
|
|
|
+ wwr := NewWeightedRoundRobin(maps)
|
|
|
+ info := wwr.Pick()
|
|
|
+ if info == nil {
|
|
|
+ mhayaLogger.Warnf("[SetNode] Load too high. data=%v", maps)
|
|
|
+ return "", code.Error
|
|
|
+ }
|
|
|
+ nodeId = info.NodeId
|
|
|
}
|
|
|
return nodeId, code.OK
|
|
|
}
|