Skip to content

Commit

Permalink
feat: random idx of replicas when init cluster connection
Browse files Browse the repository at this point in the history
  • Loading branch information
YenchangChan committed Jun 7, 2024
1 parent 756c312 commit bff611b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pool/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"context"
"crypto/tls"
"fmt"
"math/rand"
"sync"
"time"

Expand Down Expand Up @@ -181,7 +182,10 @@ func InitClusterConn(chCfg *config.ClickHouseConfig) (err error) {
sc.opts.ConnMaxLifetime = time.Minute * 10
}
sc.protocol = proto
if _, _, err = sc.NextGoodReplica(0); err != nil {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
idx := r.Intn(numReplicas)
sc.nextRep = idx
if _, _, err = sc.NextGoodReplica(idx); err != nil {
return
}
clusterConn = append(clusterConn, sc)
Expand Down

0 comments on commit bff611b

Please sign in to comment.