Skip to content

Commit

Permalink
perf: use only when replica exist
Browse files Browse the repository at this point in the history
  • Loading branch information
proost committed Jan 15, 2025
1 parent 96d3291 commit 69b4018
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,26 +207,15 @@ func (c *clusterClient) _refresh() (err error) {

groups := result.parse(c.opt.TLSConfig != nil)
conns := make(map[string]connrole, len(groups))
for primary, g := range groups {
primaryConn := c.connFn(primary, c.opt)
conns[primary] = connrole{conn: primaryConn}
if len(g.nodes) > 0 {
g.nodes[0].AZ = primaryConn.AZ()
}

for master, g := range groups {
conns[master] = connrole{conn: c.connFn(master, c.opt)}
if c.rOpt != nil {
for i, nodeInfo := range g.nodes[1:] {
replicaConn := c.connFn(nodeInfo.Addr, c.rOpt)
conns[nodeInfo.Addr] = connrole{conn: replicaConn}

g.nodes[i+1].AZ = replicaConn.AZ()
for _, nodeInfo := range g.nodes[1:] {
conns[nodeInfo.Addr] = connrole{conn: c.connFn(nodeInfo.Addr, c.rOpt)}
}
} else {
for i, nodeInfo := range g.nodes[1:] {
replicaConn := c.connFn(nodeInfo.Addr, c.opt)
conns[nodeInfo.Addr] = connrole{conn: replicaConn}

g.nodes[i+1].AZ = replicaConn.AZ()
for _, nodeInfo := range g.nodes[1:] {
conns[nodeInfo.Addr] = connrole{conn: c.connFn(nodeInfo.Addr, c.opt)}
}
}
}
Expand Down Expand Up @@ -270,6 +259,10 @@ func (c *clusterClient) _refresh() (err error) {
}
if len(g.nodes) > 1 {
n := len(g.nodes) - 1
for i, replica := range g.nodes[1:] {
rConn := conns[replica.Addr].conn
g.nodes[i+1].AZ = rConn.AZ()
}
for _, slot := range g.slots {
for i := slot[0]; i <= slot[1] && i >= 0 && i < 16384; i++ {
pslots[i] = conns[master].conn
Expand Down

0 comments on commit 69b4018

Please sign in to comment.