fix concurrency rw

This commit is contained in:
liugq 2023-07-17 18:30:26 +08:00
parent 7b4b583837
commit f92b448333
2 changed files with 7 additions and 0 deletions

View File

@ -373,6 +373,9 @@ func GetLatestOnlineAgentIDs(agentIds []string, lastSeconds int) (map[string]str
}, },
}, },
} }
if len(agentIds) == 0 {
queryDSL["size"] = 2000
}
q.RawQuery = util.MustToJSONBytes(queryDSL) q.RawQuery = util.MustToJSONBytes(queryDSL)
err, result := orm.Search(event.Event{}, &q) err, result := orm.Search(event.Event{}, &q)
if err != nil { if err != nil {

View File

@ -109,7 +109,9 @@ func (sm *StateManager) checkAgentStatus() {
return return
} }
// status change to online // status change to online
sm.agentMutex.Lock()
sm.agentIds[agentID] = model.StatusOnline sm.agentIds[agentID] = model.StatusOnline
sm.agentMutex.Unlock()
log.Infof("status of agent [%s] changed to online", agentID) log.Infof("status of agent [%s] changed to online", agentID)
return return
}else{ }else{
@ -119,7 +121,9 @@ func (sm *StateManager) checkAgentStatus() {
} }
} }
// status change to offline // status change to offline
sm.agentMutex.Lock()
sm.agentIds[agentID] = model.StatusOffline sm.agentIds[agentID] = model.StatusOffline
sm.agentMutex.Unlock()
ag, err := sm.GetAgent(agentID) ag, err := sm.GetAgent(agentID)
if err != nil { if err != nil {
if err != elastic.ErrNotFound { if err != elastic.ErrNotFound {