Skip to content

Commit

Permalink
feat: rename EnableReplicaInfoAZ to EnableReplicaAZInfo
Browse files Browse the repository at this point in the history
Signed-off-by: Rueian <[email protected]>
  • Loading branch information
rueian committed Jan 18, 2025
1 parent f14b451 commit 3927502
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
19 changes: 7 additions & 12 deletions cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,21 +260,16 @@ func (c *clusterClient) _refresh() (err error) {
if len(g.nodes) > 1 {
n := len(g.nodes) - 1

if c.opt.EnableReplicaInfoAZ {
if c.opt.EnableReplicaAZInfo {
var wg sync.WaitGroup
for i := 0; i < n; i += 4 { // batch AZ() for every 4 connections
for j := i; j < i+4 && j < n; j++ {
replica := g.nodes[j+1]
rConn := conns[replica.Addr].conn

for i := 1; i <= n; i += 4 { // batch AZ() for every 4 connections
for j := i; j <= i+4 && j <= n; j++ {
wg.Add(1)
go func(j int, rConn conn) {
defer wg.Done()

g.nodes[j+1].AZ = rConn.AZ()
}(j, rConn)
go func(wg *sync.WaitGroup, conn conn, info *ReplicaInfo) {
info.AZ = conn.AZ()
wg.Done()
}(&wg, conns[g.nodes[j].Addr].conn, &g.nodes[j])
}

wg.Wait()
}
}
Expand Down
2 changes: 1 addition & 1 deletion cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1478,7 +1478,7 @@ func TestClusterClientInit(t *testing.T) {
}
return -1
},
EnableReplicaInfoAZ: true,
EnableReplicaAZInfo: true,
},
func(dst string, opt *ClientOption) conn {
switch {
Expand Down
4 changes: 2 additions & 2 deletions rueidis.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,9 @@ type ClientOption struct {
// NOTE: This function must be used with SendToReplicas function.
ReplicaSelector func(slot uint16, replicas []ReplicaInfo) int

// EnableReplicaInfoAZ enables the client to load the replica node's availability zone.
// EnableReplicaAZInfo enables the client to load the replica node's availability zone.
// If true, the client will set the `AZ` field in `ReplicaInfo`.
EnableReplicaInfoAZ bool
EnableReplicaAZInfo bool
}

// SentinelOption contains MasterSet,
Expand Down

0 comments on commit 3927502

Please sign in to comment.