This repository was archived by the owner on Feb 26, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -152,6 +152,8 @@ func open(dsn string) (*clickhouse, error) {
152152 connOpenStrategy = connOpenRandom
153153 case "in_order" :
154154 connOpenStrategy = connOpenInOrder
155+ case "time_random" :
156+ connOpenStrategy = connOpenTimeRandom
155157 }
156158
157159 settings , err := makeQuerySettings (query )
Original file line number Diff line number Diff line change @@ -17,13 +17,16 @@ func (s openStrategy) String() string {
1717 switch s {
1818 case connOpenInOrder :
1919 return "in_order"
20+ case connOpenTimeRandom :
21+ return "time_random"
2022 }
2123 return "random"
2224}
2325
2426const (
2527 connOpenRandom openStrategy = iota + 1
2628 connOpenInOrder
29+ connOpenTimeRandom
2730)
2831
2932type connOptions struct {
@@ -55,13 +58,21 @@ func dial(options connOptions) (*connect, error) {
5558 }
5659 tlsConfig .InsecureSkipVerify = options .skipVerify
5760 }
61+ checkedHosts := make (map [int ]struct {}, len (options .hosts ))
5862 for i := range options .hosts {
5963 var num int
6064 switch options .openStrategy {
6165 case connOpenInOrder :
6266 num = i
6367 case connOpenRandom :
6468 num = (ident + i ) % len (options .hosts )
69+ case connOpenTimeRandom :
70+ // select host based on milliseconds
71+ num = int ((time .Now ().UnixNano ()/ 1000 )% 1000 ) % len (options .hosts )
72+ for _ , ok := checkedHosts [num ]; ok ; _ , ok = checkedHosts [num ] {
73+ num = int (time .Now ().UnixNano ()) % len (options .hosts )
74+ }
75+ checkedHosts [num ] = struct {}{}
6576 }
6677 switch {
6778 case options .secure :
You can’t perform that action at this time.
0 commit comments