[transfer] fix and trigger generates event twice bug (#266)
* [transfer] fix and trigger generates event twice bug * [monapi] stra excl all leaf nodes under exclNid
This commit is contained in:
parent
16a39410b8
commit
7abec2ccb8
|
@ -232,10 +232,15 @@ func GetLeafNids(nid int64, exclNid []int64) ([]int64, error) {
|
|||
return ids, nil
|
||||
}
|
||||
|
||||
exclLeafIds, err := GetExclLeafIds(exclNid)
|
||||
if err != nil {
|
||||
return leafIds, err
|
||||
}
|
||||
|
||||
for _, id := range ids {
|
||||
idsMap[id] = true
|
||||
}
|
||||
for _, id := range exclNid {
|
||||
for _, id := range exclLeafIds {
|
||||
delete(idsMap, id)
|
||||
}
|
||||
|
||||
|
@ -256,3 +261,19 @@ func removeDuplicateElement(addrs []string) []string {
|
|||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// GetExclLeafIds 获取排除节点下的叶子节点
|
||||
func GetExclLeafIds(exclNid []int64) (leafIds []int64, err error) {
|
||||
for _, nid := range exclNid {
|
||||
node, err := model.NodeGet("id", nid)
|
||||
if err != nil {
|
||||
return leafIds, err
|
||||
}
|
||||
ids, err := node.LeafIds()
|
||||
if err != nil {
|
||||
return leafIds, err
|
||||
}
|
||||
leafIds = append(leafIds, ids...)
|
||||
}
|
||||
return leafIds, nil
|
||||
}
|
||||
|
|
|
@ -76,23 +76,21 @@ func getStrategy() {
|
|||
continue
|
||||
}
|
||||
|
||||
for _, exp := range stra.Exprs {
|
||||
metric := exp.Metric
|
||||
for _, endpoint := range stra.Endpoints {
|
||||
key := str.PK(metric, endpoint) //TODO get straMap key, 此处需要优化
|
||||
k1 := key[0:2] //为了加快查找,增加一层 map,key 为计算出来的 hash 的前 2 位
|
||||
metric := stra.Exprs[0].Metric
|
||||
for _, endpoint := range stra.Endpoints {
|
||||
key := str.PK(metric, endpoint) //TODO get straMap key, 此处需要优化
|
||||
k1 := key[0:2] //为了加快查找,增加一层 map,key 为计算出来的 hash 的前 2 位
|
||||
|
||||
if _, exists := straMap[k1]; !exists {
|
||||
straMap[k1] = make(map[string][]*model.Stra)
|
||||
}
|
||||
if _, exists := straMap[k1]; !exists {
|
||||
straMap[k1] = make(map[string][]*model.Stra)
|
||||
}
|
||||
|
||||
if _, exists := straMap[k1][key]; !exists {
|
||||
straMap[k1][key] = []*model.Stra{stra}
|
||||
stats.Counter.Set("stra.key", 1)
|
||||
if _, exists := straMap[k1][key]; !exists {
|
||||
straMap[k1][key] = []*model.Stra{stra}
|
||||
stats.Counter.Set("stra.key", 1)
|
||||
|
||||
} else {
|
||||
straMap[k1][key] = append(straMap[k1][key], stra)
|
||||
}
|
||||
} else {
|
||||
straMap[k1][key] = append(straMap[k1][key], stra)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue