Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c29d80f015 | |||
| 3ba01a7dcd |
+33
-2
@@ -643,13 +643,25 @@ func handlerMultiKeyUpdate(channel *Channel, usingKey string, status int, reason
|
|||||||
if len(keys) == 0 {
|
if len(keys) == 0 {
|
||||||
channel.Status = status
|
channel.Status = status
|
||||||
} else {
|
} else {
|
||||||
var keyIndex int
|
keyIndex := -1
|
||||||
for i, key := range keys {
|
for i, key := range keys {
|
||||||
if key == usingKey {
|
if key == usingKey {
|
||||||
keyIndex = i
|
keyIndex = i
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if keyIndex < 0 {
|
||||||
|
if usingKey != "" {
|
||||||
|
common.SysLog(fmt.Sprintf("failed to update multi-key status: channel_id=%d, using key not found", channel.Id))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
channel.Status = status
|
||||||
|
info := channel.GetOtherInfo()
|
||||||
|
info["status_reason"] = reason
|
||||||
|
info["status_time"] = common.GetTimestamp()
|
||||||
|
channel.SetOtherInfo(info)
|
||||||
|
return
|
||||||
|
}
|
||||||
if channel.ChannelInfo.MultiKeyStatusList == nil {
|
if channel.ChannelInfo.MultiKeyStatusList == nil {
|
||||||
channel.ChannelInfo.MultiKeyStatusList = make(map[int]int)
|
channel.ChannelInfo.MultiKeyStatusList = make(map[int]int)
|
||||||
}
|
}
|
||||||
@@ -666,16 +678,31 @@ func handlerMultiKeyUpdate(channel *Channel, usingKey string, status int, reason
|
|||||||
channel.ChannelInfo.MultiKeyDisabledReason[keyIndex] = reason
|
channel.ChannelInfo.MultiKeyDisabledReason[keyIndex] = reason
|
||||||
channel.ChannelInfo.MultiKeyDisabledTime[keyIndex] = common.GetTimestamp()
|
channel.ChannelInfo.MultiKeyDisabledTime[keyIndex] = common.GetTimestamp()
|
||||||
}
|
}
|
||||||
if len(channel.ChannelInfo.MultiKeyStatusList) >= channel.ChannelInfo.MultiKeySize {
|
if !hasEnabledMultiKey(keys, channel.ChannelInfo.MultiKeyStatusList) {
|
||||||
channel.Status = common.ChannelStatusAutoDisabled
|
channel.Status = common.ChannelStatusAutoDisabled
|
||||||
info := channel.GetOtherInfo()
|
info := channel.GetOtherInfo()
|
||||||
info["status_reason"] = "All keys are disabled"
|
info["status_reason"] = "All keys are disabled"
|
||||||
info["status_time"] = common.GetTimestamp()
|
info["status_time"] = common.GetTimestamp()
|
||||||
channel.SetOtherInfo(info)
|
channel.SetOtherInfo(info)
|
||||||
|
} else if status == common.ChannelStatusEnabled {
|
||||||
|
channel.Status = common.ChannelStatusEnabled
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func hasEnabledMultiKey(keys []string, statusList map[int]int) bool {
|
||||||
|
for i := range keys {
|
||||||
|
if statusList == nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
status, ok := statusList[i]
|
||||||
|
if !ok || status == common.ChannelStatusEnabled {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func UpdateChannelStatus(channelId int, usingKey string, status int, reason string) bool {
|
func UpdateChannelStatus(channelId int, usingKey string, status int, reason string) bool {
|
||||||
if common.MemoryCacheEnabled {
|
if common.MemoryCacheEnabled {
|
||||||
channelStatusLock.Lock()
|
channelStatusLock.Lock()
|
||||||
@@ -687,11 +714,15 @@ func UpdateChannelStatus(channelId int, usingKey string, status int, reason stri
|
|||||||
}
|
}
|
||||||
if channelCache.ChannelInfo.IsMultiKey {
|
if channelCache.ChannelInfo.IsMultiKey {
|
||||||
// Use per-channel lock to prevent concurrent map read/write with GetNextEnabledKey
|
// Use per-channel lock to prevent concurrent map read/write with GetNextEnabledKey
|
||||||
|
beforeStatus := channelCache.Status
|
||||||
pollingLock := GetChannelPollingLock(channelId)
|
pollingLock := GetChannelPollingLock(channelId)
|
||||||
pollingLock.Lock()
|
pollingLock.Lock()
|
||||||
// 如果是多Key模式,更新缓存中的状态
|
// 如果是多Key模式,更新缓存中的状态
|
||||||
handlerMultiKeyUpdate(channelCache, usingKey, status, reason)
|
handlerMultiKeyUpdate(channelCache, usingKey, status, reason)
|
||||||
pollingLock.Unlock()
|
pollingLock.Unlock()
|
||||||
|
if beforeStatus != channelCache.Status {
|
||||||
|
CacheUpdateChannelStatus(channelId, channelCache.Status)
|
||||||
|
}
|
||||||
//CacheUpdateChannel(channelCache)
|
//CacheUpdateChannel(channelCache)
|
||||||
//return true
|
//return true
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user