Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove pool unused fields #2438

Merged
merged 1 commit into from
Feb 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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