Skip to content

Commit

Permalink
feat: remove pool unused fields (#2438)
Browse files Browse the repository at this point in the history
Signed-off-by: monkey92t <golang@88.com>
  • Loading branch information
monkey92t committed Feb 12, 2023
1 parent 2bed945 commit 08b4cc5
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions internal/pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ type Pooler interface {
}

type Options struct {
Dialer func(context.Context) (net.Conn, error)
OnClose func(*Conn) error
Dialer func(context.Context) (net.Conn, error)

PoolFIFO bool
PoolSize int
Expand Down Expand Up @@ -87,8 +86,7 @@ type ConnPool struct {

stats Stats

_closed uint32 // atomic
closedCh chan struct{}
_closed uint32 // atomic
}

var _ Pooler = (*ConnPool)(nil)
Expand All @@ -100,7 +98,6 @@ func NewConnPool(opt *Options) *ConnPool {
queue: make(chan struct{}, opt.PoolSize),
conns: make([]*Conn, 0, opt.PoolSize),
idleConns: make([]*Conn, 0, opt.PoolSize),
closedCh: make(chan struct{}),
}

p.connsMu.Lock()
Expand Down Expand Up @@ -376,7 +373,7 @@ func (p *ConnPool) Put(ctx context.Context, cn *Conn) {
}
}

func (p *ConnPool) Remove(ctx context.Context, cn *Conn, reason error) {
func (p *ConnPool) Remove(_ context.Context, cn *Conn, reason error) {
p.removeConnWithLock(cn)
p.freeTurn()
_ = p.closeConn(cn)
Expand Down Expand Up @@ -407,9 +404,6 @@ func (p *ConnPool) removeConn(cn *Conn) {
}

func (p *ConnPool) closeConn(cn *Conn) error {
if p.cfg.OnClose != nil {
_ = p.cfg.OnClose(cn)
}
return cn.Close()
}

Expand Down Expand Up @@ -464,7 +458,6 @@ func (p *ConnPool) Close() error {
if !atomic.CompareAndSwapUint32(&p._closed, 0, 1) {
return ErrClosed
}
close(p.closedCh)

var firstErr error
p.connsMu.Lock()
Expand All @@ -489,7 +482,6 @@ func (p *ConnPool) isHealthyConn(cn *Conn) bool {
return false
}
if p.cfg.ConnMaxIdleTime > 0 && now.Sub(cn.UsedAt()) >= p.cfg.ConnMaxIdleTime {
atomic.AddUint32(&p.stats.IdleConns, 1)
return false
}

Expand Down

0 comments on commit 08b4cc5

Please sign in to comment.