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

transport: pool: connection reopening improvement #248

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
17 changes: 12 additions & 5 deletions transport/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net"
"time"

"github.com/mmatczuk/scylla-go-driver/frame"
. "github.com/mmatczuk/scylla-go-driver/frame/response"

"go.uber.org/atomic"
Expand Down Expand Up @@ -121,10 +122,11 @@ func (p *ConnPool) closeAll() {
}

type PoolRefiller struct {
addr string
pool ConnPool
cfg ConnConfig
active int
addr string
pool ConnPool
cfg ConnConfig
active int
authFail []bool
}

func (r *PoolRefiller) init(host string) error {
Expand Down Expand Up @@ -167,6 +169,7 @@ func (r *PoolRefiller) init(host string) error {
conn.setOnClose(r.onConnClose)
r.pool.storeConn(conn)
r.active = 1
r.authFail = make([]bool, int(ss.NrShards))
if r.pool.connObs != nil {
r.pool.connObs.OnConnect(ConnectEvent{ConnEvent: conn.Event(), span: span})
}
Expand Down Expand Up @@ -216,7 +219,7 @@ func (r *PoolRefiller) fill() {
}

for i := 0; i < r.pool.nrShards; i++ {
if r.pool.loadConn(i) != nil {
if r.authFail[i] || r.pool.loadConn(i) != nil {
continue
}

Expand All @@ -225,6 +228,10 @@ func (r *PoolRefiller) fill() {
conn, err := OpenShardConn(r.addr, si, r.cfg)
span.stop()
if err != nil {
e, ok := err.(CodedError)
if ok && e.ErrorCode() == frame.ErrCodeCredentials {
r.authFail[i] = true
}
if r.pool.connObs != nil {
r.pool.connObs.OnConnect(ConnectEvent{ConnEvent: ConnEvent{Addr: r.addr, Shard: si.Shard}, span: span, Err: err})
}
Expand Down