mochengqian commented on code in PR #966:
URL: https://github.com/apache/dubbo-go-pixiu/pull/966#discussion_r3644323913
##########
pkg/filter/llm/proxy/filter.go:
##########
@@ -500,13 +510,20 @@ func (s *cooldownStore) markFailure(clusterName string,
endpoint *model.Endpoint
defer s.mu.Unlock()
key := newCooldownKey(clusterName, endpoint)
s.sweepExpiredIfNeededLocked(time.Now(), key)
- if _, ok := s.lastFailureByEndpoint[key]; !ok {
- s.evictOldestIfFullLocked(key)
+ ttl := endpointCooldownInterval(endpoint)
+ if element, ok := s.lastFailureByEndpoint[key]; ok {
+ entry := element.Value.(*cooldownEntry)
+ entry.lastFailure = lastFailure
+ entry.ttl = ttl
+ s.recencyOrder.MoveToBack(element)
+ return
}
- s.lastFailureByEndpoint[key] = cooldownEntry{
+ s.evictOldestIfFullLocked()
+ s.lastFailureByEndpoint[key] = s.recencyOrder.PushBack(&cooldownEntry{
Review Comment:
好的,已在 b08b9b56 中修复。
根本原因正如你所指出的:`time.Now()` 在锁外采样,并发写入时较新的时间戳可能先
`PushBack`,导致链表顺序与时间戳顺序错位,容量满时淘汰的是链表头(实际上是较新的失败记录),使仍在 cooldown 内的 endpoint
提前恢复可选。
修复方案:在 `cooldownStore` 中注入 `nowFn func() time.Time`(默认 `time.Now`),并在持有
`s.mu` 后调用 `s.nowFn()` 采样 `lastFailure`,保证时间戳记录与 `PushBack`
顺序在同一临界区内完成,彻底消除乱序可能。`markFailure` 签名同步去掉了 `lastFailure time.Time`
参数,调用方不再在锁外传入时间戳。测试通过 `store.nowFn` 注入受控时钟,覆盖原有所有场景。
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]