Skip to content

Commit 7d2b5ac

Browse files
author
Roman Golov
committed
USe common balancer in child drivers
1 parent 89f4332 commit 7d2b5ac

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
* Use common balancer for child drivers
2+
13
## v3.89.0
24
* Fixed send optional arguments to the server with `ydb.ParamsBuilder`
35

driver.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,9 @@ func (d *Driver) connect(ctx context.Context) (err error) {
415415
if d.pool == nil {
416416
d.pool = conn.NewPool(ctx, d.config)
417417
}
418-
419-
d.balancer, err = balancer.New(ctx, d.config, d.pool, d.discoveryOptions...)
418+
if d.balancer == nil {
419+
d.balancer, err = balancer.New(ctx, d.config, d.pool, d.discoveryOptions...)
420+
}
420421
if err != nil {
421422
return xerrors.WithStackTrace(err)
422423
}

options.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"github.com/ydb-platform/ydb-go-sdk/v3/config"
1313
"github.com/ydb-platform/ydb-go-sdk/v3/credentials"
14+
"github.com/ydb-platform/ydb-go-sdk/v3/internal/balancer"
1415
balancerConfig "github.com/ydb-platform/ydb-go-sdk/v3/internal/balancer/config"
1516
"github.com/ydb-platform/ydb-go-sdk/v3/internal/certificates"
1617
"github.com/ydb-platform/ydb-go-sdk/v3/internal/conn"
@@ -804,3 +805,11 @@ func withConnPool(pool *conn.Pool) Option {
804805
return pool.Take(ctx)
805806
}
806807
}
808+
809+
func withSharedBalancer(balancer *balancer.Balancer) Option {
810+
return func(ctx context.Context, c *Driver) error {
811+
c.balancer = balancer
812+
813+
return nil
814+
}
815+
}

with.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,14 @@ func (d *Driver) with(ctx context.Context, opts ...Option) (*Driver, uint64, err
1919
append(
2020
append(
2121
d.opts,
22-
WithBalancer(
23-
d.config.Balancer(),
24-
),
2522
withOnClose(func(child *Driver) {
2623
d.childrenMtx.Lock()
2724
defer d.childrenMtx.Unlock()
2825

2926
delete(d.children, id)
3027
}),
3128
withConnPool(d.pool),
29+
withSharedBalancer(d.balancer),
3230
),
3331
opts...,
3432
)...,

0 commit comments

Comments
 (0)