Skip to content

Commit 97e90c6

Browse files
authored
Merge pull request #162 from ydb-platform/recursive
v3.14.5: minifixes from #160
2 parents 03e690e + c54ac4f commit 97e90c6

File tree

8 files changed

+41
-46
lines changed

8 files changed

+41
-46
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* Refactored `table.CreateSession` as retry operation with options
1010
* Moved log level from root of repository to package `log`
1111
* Added details and address to transport error
12+
* Fixed `recursive` param in `ratelimiter.ListResource`
1213

1314
## 3.14.4
1415
* Implemented auto-removing `conn.Conn` from `conn.Pool` with counting usages of `conn.Conn`

internal/balancer/multi/multi.go

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,8 @@ func WithBalancer(b balancer.Balancer, filter func(cc conn.Conn) bool) Option {
4444
type Option func(*multi)
4545

4646
func (m *multi) Contains(x balancer.Element) bool {
47-
for i, x := range x.(multiHandle).elements {
48-
if x == nil {
49-
continue
50-
}
51-
if m.balancer[i].Contains(x) {
47+
for i, h := range x.(multiHandle).elements {
48+
if h != nil && m.balancer[i].Contains(h) {
5249
return true
5350
}
5451
}
@@ -75,8 +72,7 @@ func (m *multi) Insert(conn conn.Conn) balancer.Element {
7572

7673
for i, f := range m.filter {
7774
if f(conn) {
78-
x := m.balancer[i].Insert(conn)
79-
h.elements[i] = x
75+
h.elements[i] = m.balancer[i].Insert(conn)
8076
inserted = true
8177
}
8278
}
@@ -87,17 +83,17 @@ func (m *multi) Insert(conn conn.Conn) balancer.Element {
8783
}
8884

8985
func (m *multi) Update(x balancer.Element, info info.Info) {
90-
for i, x := range x.(multiHandle).elements {
91-
if x != nil {
92-
m.balancer[i].Update(x, info)
86+
for i, h := range x.(multiHandle).elements {
87+
if h != nil {
88+
m.balancer[i].Update(h, info)
9389
}
9490
}
9591
}
9692

9793
func (m *multi) Remove(x balancer.Element) (removed bool) {
98-
for i, x := range x.(multiHandle).elements {
99-
if x != nil {
100-
if m.balancer[i].Remove(x) {
94+
for i, h := range x.(multiHandle).elements {
95+
if h != nil {
96+
if m.balancer[i].Remove(h) {
10197
removed = true
10298
}
10399
}

internal/cluster/cluster.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -437,15 +437,7 @@ func DiffEndpoints(curr, next []endpoint.Endpoint, eq, add, del func(i, j int))
437437
func(i, j int) int {
438438
return compareEndpoints(curr[i], next[j])
439439
},
440-
func(i, j int) {
441-
eq(i, j)
442-
},
443-
func(i, j int) {
444-
add(i, j)
445-
},
446-
func(i, j int) {
447-
del(i, j)
448-
},
440+
eq, add, del,
449441
)
450442
}
451443

internal/conn/conn.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,13 @@ func (c *conn) changeUsages(delta int32) int32 {
210210
func (c *conn) incUsages() {
211211
c.Lock()
212212
defer c.Unlock()
213+
c.lastUsage = time.Now()
213214
c.changeUsages(1)
214215
}
215216

216217
func (c *conn) decUsages() int32 {
217218
c.Lock()
218219
defer c.Unlock()
219-
c.lastUsage = time.Now()
220220
return c.changeUsages(-1)
221221
}
222222

internal/conn/pool.go

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,19 @@ func (p *pool) Get(ctx context.Context, endpoint endpoint.Endpoint) Conn {
6666
return cc
6767
}
6868

69-
cc = newConn(
70-
endpoint,
71-
p.config,
72-
withOnClose(func(c *conn) {
73-
p.mtx.Lock()
74-
defer p.mtx.Unlock()
75-
delete(p.conns, c.Endpoint().Address())
76-
}),
77-
)
69+
cc = newConn(endpoint, p.config, withOnClose(p.remove))
7870

7971
p.conns[address] = cc
8072

8173
return cc
8274
}
8375

76+
func (p *pool) remove(c *conn) {
77+
p.mtx.Lock()
78+
defer p.mtx.Unlock()
79+
delete(p.conns, c.Endpoint().Address())
80+
}
81+
8482
func (p *pool) Pessimize(ctx context.Context, cc Conn, cause error) {
8583
e := cc.Endpoint().Copy()
8684

@@ -101,7 +99,7 @@ func (p *pool) Pessimize(ctx context.Context, cc Conn, cause error) {
10199
)(cc.SetState(Banned))
102100
}
103101

104-
func (p *pool) Take(ctx context.Context) error {
102+
func (p *pool) Take(context.Context) error {
105103
atomic.AddInt64(&p.usages, 1)
106104
return nil
107105
}
@@ -134,21 +132,14 @@ func (p *pool) Release(ctx context.Context) error {
134132
return nil
135133
}
136134

137-
func (p *pool) connParker(ctx context.Context, interval time.Duration) {
135+
func (p *pool) connParker(ctx context.Context, ttl, interval time.Duration) {
138136
ticker := time.NewTicker(interval)
139-
ttl := p.config.ConnectionTTL()
140137
for {
141138
select {
142139
case <-p.done:
143140
return
144141
case <-ticker.C:
145-
p.mtx.RLock()
146-
conns := make([]*conn, 0, len(p.conns))
147-
for _, c := range p.conns {
148-
conns = append(conns, c)
149-
}
150-
p.mtx.RUnlock()
151-
for _, c := range conns {
142+
for _, c := range p.collectConns() {
152143
if time.Since(c.LastUsage()) > ttl {
153144
_ = c.park(ctx)
154145
}
@@ -157,6 +148,16 @@ func (p *pool) connParker(ctx context.Context, interval time.Duration) {
157148
}
158149
}
159150

151+
func (p *pool) collectConns() []*conn {
152+
p.mtx.RLock()
153+
defer p.mtx.RUnlock()
154+
conns := make([]*conn, 0, len(p.conns))
155+
for _, c := range p.conns {
156+
conns = append(conns, c)
157+
}
158+
return conns
159+
}
160+
160161
func NewPool(
161162
ctx context.Context,
162163
config Config,
@@ -169,7 +170,7 @@ func NewPool(
169170
done: make(chan struct{}),
170171
}
171172
if ttl := config.ConnectionTTL(); ttl > 0 {
172-
go p.connParker(ctx, ttl/2)
173+
go p.connParker(ctx, ttl, ttl/2)
173174
}
174175
return p
175176
}

internal/discovery/discovery.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ func New(
7575

7676
cluster.DiffEndpoints(curr, next,
7777
func(i, j int) {
78-
// Endpoints are equal, but we still need to update meta
79-
// data such that load factor and others.
78+
// Endpoints are equal, but we still need to update metadata (e.g., load factor).
8079
crudExplorer.Update(
8180
ctx,
8281
next[j],

internal/errors/transport.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,12 @@ func (t *TransportError) Error() string {
116116
}
117117
if len(t.details) > 0 {
118118
b.WriteString(", details: ")
119-
b.WriteString(fmt.Sprintf("%v", t.details))
119+
if len(t.details) > 0 {
120+
b.WriteString(", details:")
121+
for _, detail := range t.details {
122+
b.WriteString(fmt.Sprintf("\n- %v", detail))
123+
}
124+
}
120125
}
121126
return b.String()
122127
}

internal/ratelimiter/ratelimiter.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ func (c *client) ListResource(
120120
response, err = c.service.ListResources(ctx, &Ydb_RateLimiter.ListResourcesRequest{
121121
CoordinationNodePath: coordinationNodePath,
122122
ResourcePath: resourcePath,
123+
Recursive: recursive,
123124
OperationParams: operation.Params(
124125
c.config.OperationTimeout(),
125126
c.config.OperationCancelAfter(),

0 commit comments

Comments
 (0)