@@ -3,31 +3,31 @@ package balancers
3
3
import (
4
4
"strings"
5
5
6
+ balancerConfig "github.com/ydb-platform/ydb-go-sdk/v3/internal/balancer/config"
6
7
"github.com/ydb-platform/ydb-go-sdk/v3/internal/conn"
7
- routerconfig "github.com/ydb-platform/ydb-go-sdk/v3/internal/router/config"
8
8
)
9
9
10
10
// Deprecated: RoundRobin is RandomChoice now
11
- func RoundRobin () * routerconfig .Config {
12
- return & routerconfig .Config {}
11
+ func RoundRobin () * balancerConfig .Config {
12
+ return & balancerConfig .Config {}
13
13
}
14
14
15
- func RandomChoice () * routerconfig .Config {
16
- return & routerconfig .Config {}
15
+ func RandomChoice () * balancerConfig .Config {
16
+ return & balancerConfig .Config {}
17
17
}
18
18
19
- func SingleConn () * routerconfig .Config {
20
- return & routerconfig .Config {
19
+ func SingleConn () * balancerConfig .Config {
20
+ return & balancerConfig .Config {
21
21
SingleConn : true ,
22
22
}
23
23
}
24
24
25
25
// PreferLocalDC creates balancer which use endpoints only in location such as initial endpoint location
26
26
// Balancer "balancer" defines balancing algorithm between endpoints selected with filter by location
27
27
// PreferLocalDC balancer try to autodetect local DC from client side.
28
- func PreferLocalDC (balancer * routerconfig .Config ) * routerconfig .Config {
29
- balancer .IsPreferConn = func (routerInfo routerconfig .Info , c conn.Conn ) bool {
30
- return c .Endpoint ().Location () == routerInfo .SelfLocation
28
+ func PreferLocalDC (balancer * balancerConfig .Config ) * balancerConfig .Config {
29
+ balancer .IsPreferConn = func (info balancerConfig .Info , c conn.Conn ) bool {
30
+ return c .Endpoint ().Location () == info .SelfLocation
31
31
}
32
32
balancer .DetectlocalDC = true
33
33
return balancer
@@ -36,22 +36,22 @@ func PreferLocalDC(balancer *routerconfig.Config) *routerconfig.Config {
36
36
// PreferLocalDCWithFallBack creates balancer which use endpoints only in location such as initial endpoint location
37
37
// Balancer "balancer" defines balancing algorithm between endpoints selected with filter by location
38
38
// If filter returned zero endpoints from all discovery endpoints list - used all endpoint instead
39
- func PreferLocalDCWithFallBack (balancer * routerconfig .Config ) * routerconfig .Config {
39
+ func PreferLocalDCWithFallBack (balancer * balancerConfig .Config ) * balancerConfig .Config {
40
40
balancer = PreferLocalDC (balancer )
41
41
balancer .AllowFalback = true
42
42
return balancer
43
43
}
44
44
45
45
// PreferLocations creates balancer which use endpoints only in selected locations (such as "ABC", "DEF", etc.)
46
46
// Balancer "balancer" defines balancing algorithm between endpoints selected with filter by location
47
- func PreferLocations (balancer * routerconfig .Config , locations ... string ) * routerconfig .Config {
47
+ func PreferLocations (balancer * balancerConfig .Config , locations ... string ) * balancerConfig .Config {
48
48
if len (locations ) == 0 {
49
49
panic ("empty list of locations" )
50
50
}
51
51
for i := range locations {
52
52
locations [i ] = strings .ToUpper (locations [i ])
53
53
}
54
- balancer .IsPreferConn = func (_ routerconfig .Info , c conn.Conn ) bool {
54
+ balancer .IsPreferConn = func (_ balancerConfig .Info , c conn.Conn ) bool {
55
55
location := strings .ToUpper (c .Endpoint ().Location ())
56
56
for _ , l := range locations {
57
57
if location == l {
@@ -66,7 +66,7 @@ func PreferLocations(balancer *routerconfig.Config, locations ...string) *router
66
66
// PreferLocationsWithFallback creates balancer which use endpoints only in selected locations
67
67
// Balancer "balancer" defines balancing algorithm between endpoints selected with filter by location
68
68
// If filter returned zero endpoints from all discovery endpoints list - used all endpoint instead
69
- func PreferLocationsWithFallback (balancer * routerconfig .Config , locations ... string ) * routerconfig .Config {
69
+ func PreferLocationsWithFallback (balancer * balancerConfig .Config , locations ... string ) * balancerConfig .Config {
70
70
balancer = PreferLocations (balancer , locations ... )
71
71
balancer .AllowFalback = true
72
72
return balancer
@@ -84,8 +84,8 @@ type Endpoint interface {
84
84
85
85
// Prefer creates balancer which use endpoints by filter
86
86
// Balancer "balancer" defines balancing algorithm between endpoints selected with filter
87
- func Prefer (balancer * routerconfig .Config , filter func (endpoint Endpoint ) bool ) * routerconfig .Config {
88
- balancer .IsPreferConn = func (_ routerconfig .Info , c conn.Conn ) bool {
87
+ func Prefer (balancer * balancerConfig .Config , filter func (endpoint Endpoint ) bool ) * balancerConfig .Config {
88
+ balancer .IsPreferConn = func (_ balancerConfig .Info , c conn.Conn ) bool {
89
89
return filter (c .Endpoint ())
90
90
}
91
91
return balancer
@@ -94,13 +94,13 @@ func Prefer(balancer *routerconfig.Config, filter func(endpoint Endpoint) bool)
94
94
// PreferWithFallback creates balancer which use endpoints by filter
95
95
// Balancer "balancer" defines balancing algorithm between endpoints selected with filter
96
96
// If filter returned zero endpoints from all discovery endpoints list - used all endpoint instead
97
- func PreferWithFallback (balancer * routerconfig .Config , filter func (endpoint Endpoint ) bool ) * routerconfig .Config {
97
+ func PreferWithFallback (balancer * balancerConfig .Config , filter func (endpoint Endpoint ) bool ) * balancerConfig .Config {
98
98
balancer = Prefer (balancer , filter )
99
99
balancer .AllowFalback = true
100
100
return balancer
101
101
}
102
102
103
103
// Default balancer used by default
104
- func Default () * routerconfig .Config {
104
+ func Default () * balancerConfig .Config {
105
105
return RandomChoice ()
106
106
}
0 commit comments