Skip to content

Commit

Permalink
重新测试最快线路时清空之前的缓存记录。
Browse files Browse the repository at this point in the history
  • Loading branch information
GameXG authored and GameXG committed Nov 21, 2015
1 parent c316216 commit 078d548
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
10 changes: 5 additions & 5 deletions errconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ type ErrConnDomain struct {
// 异常连接 相关服务
type ErrConnService struct {
lru *lru.Cache // key domainAddr value *ErrConnDomain
rwm sync.RWMutex
m sync.Mutex
}

func NewErrConnService() *ErrConnService {
Expand All @@ -86,8 +86,8 @@ func (ec*ErrConnService)set(domain *ErrConnDomain) {

// 增加异常记录
func (ec*ErrConnService)AddErrLog(dialName, domainAddr, ipAddr string, errType ErrConnType) {
ec.rwm.Lock()
defer ec.rwm.Unlock()
ec.m.Lock()
defer ec.m.Unlock()

d := ec.get(domainAddr)
if d == nil {
Expand All @@ -107,8 +107,8 @@ func (ec*ErrConnService)AddErrLog(dialName, domainAddr, ipAddr string, errType E
// 如果启用了全球解析,那么需要挂掉很多ip。
// 返回值: true 表示安全 false 表示不建议使用
func (ec*ErrConnService)Check(dialName, domainAddr, ipAddr string) bool {
ec.rwm.Lock()
defer ec.rwm.Unlock()
ec.m.Lock()
defer ec.m.Unlock()

d := ec.get(domainAddr)
if d == nil {
Expand Down
9 changes: 9 additions & 0 deletions upstream_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,12 @@ func (c*upStreamConnCache)GetOptimal(domainAddr string) (upStreamConnCacheAddrIt
}
return upStreamConnCacheAddrItem{}, fmt.Errorf("全部连接有异常。")
}

// 删除某个域的缓存记录
// 在每次进行全部连接重试时将会清空旧的缓存内容。
func (c*upStreamConnCache)Del(domainAddr string) {
c.rwm.Lock()
defer c.rwm.Unlock()

c.domains.Remove(domainAddr)
}
1 change: 1 addition & 0 deletions upstream_tcpping.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func (su*tcppingUpStream)DialTimeout(network, address string, timeout time.Durat
}

// 缓存未命中时同时使用多个线路尝试连接。
su.connCache.Del(address)

resChan := make(chan dialTimeoutRes, 1)
connChan := make(chan netchan.ConnRes, 10)
Expand Down

0 comments on commit 078d548

Please sign in to comment.