Skip to content

Commit 25487fe

Browse files
authored
Merge pull request #75 from ydb-platform/multiple-databases
v3.7.0: Scripting, connection TTL, replacement of database/token, PreferLocations, refactoring
2 parents dcfb6d2 + a69f16f commit 25487fe

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+2992
-2012
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
## 3.7.0
2+
* Replaced `Option` to `CustomOption` on `Connection` interface methods
3+
* Implements `WithCustom[Token,Database]` options for redefine database and token
4+
* Removed experimental `balancer.PreferEndpoints[WithFallback][RegEx]` balancers
5+
* Supported connections `TTL` with `Option` `WithConnectionTTL`
6+
* Remove unnecessary `WithFastDial` option (lazy connections are always fast inserts into cluster)
7+
* Added `Scripting` service client with API methods `Execute()`, `StreamExecute()` and `Explain()`
8+
* Added `String()` method to `table.types.Type` interface
9+
* Added `With[Custom]UserAgent()` `Option` and `CustomOption` constructors
10+
* Refactored `log.Logger` interface and internal implementation
11+
* Added `retry.RetryableError()` for returns user-defined error which must be retryed
12+
* Renamed internal type `internal.errors.OperationCompleted` to `internal.errors.OperationStatus`
13+
* Added `String()` method to `table.KeyRange` and `table.Value` types
14+
115
## 3.6.2
216
* Refactored table retry helpers
317
* Added new `PreferLocations[WithFallback][RegEx]` balancers

balancer/balancer.go

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
package balancer
2+
3+
import (
4+
"strings"
5+
6+
"github.com/ydb-platform/ydb-go-sdk/v3/internal/balancer/ibalancer"
7+
"github.com/ydb-platform/ydb-go-sdk/v3/internal/balancer/multi"
8+
"github.com/ydb-platform/ydb-go-sdk/v3/internal/balancer/rr"
9+
"github.com/ydb-platform/ydb-go-sdk/v3/internal/balancer/single"
10+
"github.com/ydb-platform/ydb-go-sdk/v3/internal/conn"
11+
)
12+
13+
func RoundRobin() ibalancer.Balancer {
14+
return rr.RoundRobin()
15+
}
16+
17+
func RandomChoice() ibalancer.Balancer {
18+
return rr.RandomChoice()
19+
}
20+
21+
func SingleConn() ibalancer.Balancer {
22+
return single.Balancer()
23+
}
24+
25+
// PreferLocalDC creates balancer which use endpoints only in location such as initial endpoint location
26+
// Balancer "balancer" defines balancing algorithm between endpoints selected with filter by location
27+
func PreferLocalDC(balancer ibalancer.Balancer) ibalancer.Balancer {
28+
return multi.Balancer(
29+
multi.WithBalancer(
30+
balancer,
31+
func(cc conn.Conn) bool {
32+
return cc.Endpoint().LocalDC()
33+
},
34+
),
35+
)
36+
}
37+
38+
// PreferLocalDCWithFallBack creates balancer which use endpoints only in location such as initial endpoint location
39+
// Balancer "balancer" defines balancing algorithm between endpoints selected with filter by location
40+
// If filter returned zero endpoints from all discovery endpoints list - used all endpoint instead
41+
func PreferLocalDCWithFallBack(balancer ibalancer.Balancer) ibalancer.Balancer {
42+
return multi.Balancer(
43+
multi.WithBalancer(
44+
balancer,
45+
func(cc conn.Conn) bool {
46+
return cc.Endpoint().LocalDC()
47+
},
48+
),
49+
multi.WithBalancer(
50+
balancer.(ibalancer.Creator).Create(),
51+
func(cc conn.Conn) bool {
52+
return !cc.Endpoint().LocalDC()
53+
},
54+
),
55+
)
56+
}
57+
58+
// PreferLocations creates balancer which use endpoints only in selected locations (such as "MAN", "VLA", etc.)
59+
// Balancer "balancer" defines balancing algorithm between endpoints selected with filter by location
60+
func PreferLocations(balancer ibalancer.Balancer, locations ...string) ibalancer.Balancer {
61+
if len(locations) == 0 {
62+
panic("empty list of locations")
63+
}
64+
for i := range locations {
65+
locations[i] = strings.ToUpper(locations[i])
66+
}
67+
return multi.Balancer(
68+
multi.WithBalancer(balancer, func(cc conn.Conn) bool {
69+
location := strings.ToUpper(cc.Endpoint().Location())
70+
for _, l := range locations {
71+
if location == l {
72+
return true
73+
}
74+
}
75+
return false
76+
}),
77+
)
78+
}
79+
80+
// PreferLocationsWithFallback creates balancer which use endpoints only in selected locations
81+
// Balancer "balancer" defines balancing algorithm between endpoints selected with filter by location
82+
// If filter returned zero endpoints from all discovery endpoints list - used all endpoint instead
83+
func PreferLocationsWithFallback(balancer ibalancer.Balancer, locations ...string) ibalancer.Balancer {
84+
if len(locations) == 0 {
85+
panic("empty list of locations")
86+
}
87+
for i := range locations {
88+
locations[i] = strings.ToUpper(locations[i])
89+
}
90+
return multi.Balancer(
91+
multi.WithBalancer(balancer, func(cc conn.Conn) bool {
92+
location := strings.ToUpper(cc.Endpoint().Location())
93+
for _, l := range locations {
94+
if location == l {
95+
return true
96+
}
97+
}
98+
return false
99+
}),
100+
multi.WithBalancer(balancer.(ibalancer.Creator).Create(), func(cc conn.Conn) bool {
101+
location := strings.ToUpper(cc.Endpoint().Location())
102+
for _, l := range locations {
103+
if location == l {
104+
return false
105+
}
106+
}
107+
return true
108+
}),
109+
)
110+
}
111+
112+
func Default() ibalancer.Balancer {
113+
return PreferLocalDCWithFallBack(RandomChoice())
114+
}

config/balancer/balancer.go

Lines changed: 0 additions & 171 deletions
This file was deleted.

0 commit comments

Comments
 (0)