Skip to content

Commit

Permalink
Merge pull request apache#739 from skyao/improve/map-access-concurreny
Browse files Browse the repository at this point in the history
Imp: Improve map access concurrency
  • Loading branch information
zouyx committed Sep 22, 2020
1 parent 6b7d698 commit a17b0af
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions protocol/rpc_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ func (rpc *RPCStatus) GetSuccessiveRequestFailureCount() int32 {

// GetURLStatus get URL RPC status.
func GetURLStatus(url common.URL) *RPCStatus {
rpcStatus, _ := serviceStatistic.LoadOrStore(url.Key(), &RPCStatus{})
rpcStatus, found := serviceStatistic.Load(url.Key())
if !found {
rpcStatus, _ = serviceStatistic.LoadOrStore(url.Key(), &RPCStatus{})
}
return rpcStatus.(*RPCStatus)
}

Expand All @@ -107,15 +110,13 @@ func GetMethodStatus(url common.URL, methodName string) *RPCStatus {
identifier := url.Key()
methodMap, found := methodStatistics.Load(identifier)
if !found {
methodMap = &sync.Map{}
methodStatistics.Store(identifier, methodMap)
methodMap, _ = methodStatistics.LoadOrStore(identifier, &sync.Map{})
}

methodActive := methodMap.(*sync.Map)
rpcStatus, found := methodActive.Load(methodName)
if !found {
rpcStatus = &RPCStatus{}
methodActive.Store(methodName, rpcStatus)
rpcStatus, _ = methodActive.LoadOrStore(methodName, &RPCStatus{})
}

status := rpcStatus.(*RPCStatus)
Expand Down

0 comments on commit a17b0af

Please sign in to comment.