Skip to content

Commit a1b9255

Browse files
authored
Merge pull request #145 from ydb-platform/prefer
v3.11.12: balancers.Prefer + balancers.PreferWithFallback + trace.ClusterInsert…
2 parents dd3e376 + 81b1ed2 commit a1b9255

File tree

18 files changed

+169
-81
lines changed

18 files changed

+169
-81
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ jobs:
5757
YDB_SSL_ROOT_CERTIFICATES_FILE: /tmp/ydb_certs/ca.pem
5858
YDB_ANONYMOUS_CREDENTIALS: 1
5959
YDB_SHUTDOWN_URLS: http://localhost:8765/actors/kqp_proxy?force_shutdown=all
60+
HIDE_APPLICATION_OUTPUT: 1
6061
runs-on: ${{ matrix.os }}
6162
steps:
6263
- name: Install Go

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 3.11.12
2+
* Added `trace.ClusterInsertDoneInfo.Inserted` boolean flag for notify about success of insert endpoint into balancer
3+
* Added `trace.ClusterRemoveDoneInfo.Removed` boolean flag for notify about success of remove endpoint from balancer
4+
15
## 3.11.11
26
* Reverted usage of `math/rand` (instead `crypto/rand`)
37

internal/balancer/balancer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type Balancer interface {
2525
Update(Element, info.Info)
2626

2727
// Remove removes previously inserted connection.
28-
Remove(Element)
28+
Remove(Element) bool
2929

3030
// Contains returns true if Balancer contains requested element.
3131
Contains(Element) bool

internal/balancer/multi/multi.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,25 @@ func (m *multi) Next() conn.Conn {
6565
}
6666

6767
func (m *multi) Insert(conn conn.Conn) balancer.Element {
68-
n := len(m.filter)
69-
h := multiHandle{
70-
elements: make([]balancer.Element, n),
71-
}
68+
var (
69+
n = len(m.filter)
70+
h = multiHandle{
71+
elements: make([]balancer.Element, n),
72+
}
73+
inserted = false
74+
)
75+
7276
for i, f := range m.filter {
7377
if f(conn) {
7478
x := m.balancer[i].Insert(conn)
7579
h.elements[i] = x
80+
inserted = true
7681
}
7782
}
78-
return h
83+
if inserted {
84+
return h
85+
}
86+
return nil
7987
}
8088

8189
func (m *multi) Update(x balancer.Element, info info.Info) {
@@ -86,10 +94,13 @@ func (m *multi) Update(x balancer.Element, info info.Info) {
8694
}
8795
}
8896

89-
func (m *multi) Remove(x balancer.Element) {
97+
func (m *multi) Remove(x balancer.Element) (removed bool) {
9098
for i, x := range x.(multiHandle).elements {
9199
if x != nil {
92-
m.balancer[i].Remove(x)
100+
if m.balancer[i].Remove(x) {
101+
removed = true
102+
}
93103
}
94104
}
105+
return removed
95106
}

internal/balancer/rr/rr.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,12 @@ func (r *roundRobin) Update(el balancer.Element, info info.Info) {
103103
r.belt = r.distribute()
104104
}
105105

106-
func (r *roundRobin) Remove(x balancer.Element) {
106+
func (r *roundRobin) Remove(x balancer.Element) bool {
107107
el := x.(*list.Element)
108108
r.conns.Remove(el)
109109
r.inspectMinMax(el.Info)
110110
r.belt = r.distribute()
111+
return true
111112
}
112113

113114
func (r *roundRobin) Contains(x balancer.Element) bool {

internal/balancer/single/single.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ func (b *single) Insert(conn conn.Conn) balancer.Element {
3030
return conn
3131
}
3232

33-
func (b *single) Remove(x balancer.Element) {
33+
func (b *single) Remove(x balancer.Element) bool {
3434
if b.conn != x.(conn.Conn) {
3535
panic("ydb: single Conn Balancer: Remove() unknown Conn")
3636
}
3737
b.conn = nil
38+
return true
3839
}
3940

4041
func (b *single) Update(balancer.Element, info.Info) {}

internal/balancer/stub/stub.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type stubBalancer struct {
1313
OnNext func() conn.Conn
1414
OnInsert func(conn.Conn) balancer.Element
1515
OnUpdate func(balancer.Element, info.Info)
16-
OnRemove func(balancer.Element)
16+
OnRemove func(balancer.Element) bool
1717
OnPessimize func(context.Context, balancer.Element) error
1818
OnContains func(balancer.Element) bool
1919
}
@@ -34,9 +34,10 @@ func Balancer() (*list.List, balancer.Balancer) {
3434
OnInsert: func(conn conn.Conn) balancer.Element {
3535
return cs.Insert(conn)
3636
},
37-
OnRemove: func(x balancer.Element) {
37+
OnRemove: func(x balancer.Element) bool {
3838
e := x.(*list.Element)
3939
cs.Remove(e)
40+
return true
4041
},
4142
OnUpdate: func(x balancer.Element, info info.Info) {
4243
e := x.(*list.Element)
@@ -74,10 +75,11 @@ func (s stubBalancer) Update(el balancer.Element, i info.Info) {
7475
}
7576
}
7677

77-
func (s stubBalancer) Remove(el balancer.Element) {
78+
func (s stubBalancer) Remove(el balancer.Element) bool {
7879
if f := s.OnRemove; f != nil {
79-
f(el)
80+
return f(el)
8081
}
82+
return true
8183
}
8284

8385
func (s stubBalancer) Pessimize(ctx context.Context, el balancer.Element) error {

internal/cluster/cluster.go

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,12 @@ func (c *cluster) Get(ctx context.Context, opts ...crudOption) (cc conn.Conn, er
236236

237237
// Insert inserts new connection into the cluster.
238238
func (c *cluster) Insert(ctx context.Context, e endpoint.Endpoint, opts ...crudOption) (cc conn.Conn) {
239-
onDone := trace.DriverOnClusterInsert(c.config.Trace(), &ctx, e.Copy())
239+
var (
240+
onDone = trace.DriverOnClusterInsert(c.config.Trace(), &ctx, e.Copy())
241+
inserted = false
242+
)
240243
defer func() {
241-
if cc != nil {
242-
onDone(cc.GetState())
243-
} else {
244-
onDone(conn.Unknown)
245-
}
244+
onDone(inserted, cc.GetState())
246245
}()
247246

248247
options := parseOptions(opts...)
@@ -266,7 +265,7 @@ func (c *cluster) Insert(ctx context.Context, e endpoint.Endpoint, opts ...crudO
266265

267266
entry := entry.Entry{Conn: cc}
268267

269-
entry.InsertInto(c.balancer)
268+
inserted = entry.InsertInto(c.balancer)
270269

271270
c.index[e.Address()] = entry
272271

@@ -325,13 +324,12 @@ func (c *cluster) Update(ctx context.Context, e endpoint.Endpoint, opts ...crudO
325324

326325
// Remove removes and closes previously inserted connection.
327326
func (c *cluster) Remove(ctx context.Context, e endpoint.Endpoint, opts ...crudOption) (cc conn.Conn) {
328-
onDone := trace.DriverOnClusterRemove(c.config.Trace(), &ctx, e.Copy())
327+
var (
328+
onDone = trace.DriverOnClusterRemove(c.config.Trace(), &ctx, e.Copy())
329+
removed = false
330+
)
329331
defer func() {
330-
if cc != nil {
331-
onDone(cc.GetState())
332-
} else {
333-
onDone(conn.Unknown)
334-
}
332+
onDone(cc.GetState(), removed)
335333
}()
336334

337335
options := parseOptions(opts...)
@@ -352,7 +350,8 @@ func (c *cluster) Remove(ctx context.Context, e endpoint.Endpoint, opts ...crudO
352350
panic("ydb: can't remove not-existing endpoint")
353351
}
354352

355-
entry.RemoveFrom(c.balancer)
353+
removed = entry.RemoveFrom(c.balancer)
354+
356355
delete(c.index, e.Address())
357356
delete(c.endpoints, e.NodeID())
358357

internal/cluster/entry/entry.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,22 @@ type Entry struct {
1111
Handle balancer.Element
1212
}
1313

14-
func (c *Entry) InsertInto(b balancer.Balancer) {
14+
func (c *Entry) InsertInto(b balancer.Balancer) bool {
1515
if c.Handle != nil {
1616
panic("ydb: Handle already exists")
1717
}
1818
if c.Conn == nil {
1919
panic("ydb: can't insert nil Conn into balancer")
2020
}
2121
c.Handle = b.Insert(c.Conn)
22-
if c.Handle == nil {
23-
panic("ydb: balancer has returned nil Handle")
24-
}
22+
return c.Handle != nil
2523
}
2624

27-
func (c *Entry) RemoveFrom(b balancer.Balancer) {
25+
func (c *Entry) RemoveFrom(b balancer.Balancer) bool {
2826
if c.Handle == nil {
29-
panic("ydb: no Handle to remove from balancer")
27+
return false
3028
}
3129
b.Remove(c.Handle)
3230
c.Handle = nil
31+
return true
3332
}

internal/meta/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package meta
22

33
const (
4-
Version = "ydb-go-sdk/3.11.11"
4+
Version = "ydb-go-sdk/3.11.12"
55
)

0 commit comments

Comments
 (0)