Skip to content

Commit

Permalink
Fix checking if tablets should be used in scyllaConnPicker Pick
Browse files Browse the repository at this point in the history
Previously the check was always based on p.conns[0], but there
is a posibility that it is nil and it should be checked.
The check should be based on not nil connection
This commit introduces searching for first not nil connection
and checking tablet-awareness based on this connection.
  • Loading branch information
sylwiaszunejko committed Feb 2, 2024
1 parent 9dd9a7f commit a39ad55
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions scylla.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,24 +370,33 @@ func (p *scyllaConnPicker) Pick(t token, keyspace string, table string) *Conn {

idx := -1

p.conns[0].mu.Lock()
if p.conns[0].tabletsRoutingV1 {
tablets := p.conns[0].session.getTablets()

// Search for tablets with Keyspace and Table from the Query
l, r := findTablets(tablets, keyspace, table)

if l != -1 {
tablet := findTabletForToken(tablets, mmt, l, r)
for _, conn := range p.conns {
if conn == nil {
continue
}

for _, replica := range tablet.replicas {
if replica.hostId.String() == p.hostId {
idx = replica.shardId
conn.mu.Lock()
if conn.tabletsRoutingV1 {
tablets := conn.session.getTablets()

// Search for tablets with Keyspace and Table from the Query
l, r := findTablets(tablets, keyspace, table)

if l != -1 {
tablet := findTabletForToken(tablets, mmt, l, r)

for _, replica := range tablet.replicas {
if replica.hostId.String() == p.hostId {
idx = replica.shardId
}
}
}
}
conn.mu.Unlock()

break
}
p.conns[0].mu.Unlock()

if idx == -1 {
idx = p.shardOf(mmt)
}
Expand Down

0 comments on commit a39ad55

Please sign in to comment.