Skip to content

Commit fca922c

Browse files
authored
Merge pull request #1530 from ydb-platform/use_common_balancer_in_shared_drivers
allow to use common balancer in child drivers
2 parents 89f4332 + 8b810e4 commit fca922c

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

CHANGELOG.md

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

driver.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -415,10 +415,11 @@ 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...)
420-
if err != nil {
421-
return xerrors.WithStackTrace(err)
418+
if d.balancer == nil {
419+
d.balancer, err = balancer.New(ctx, d.config, d.pool, d.discoveryOptions...)
420+
if err != nil {
421+
return xerrors.WithStackTrace(err)
422+
}
422423
}
423424

424425
d.table = xsync.OnceValue(func() (*internalTable.Client, error) {

options.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,15 @@ func WithPanicCallback(panicCallback func(e interface{})) Option {
599599
}
600600
}
601601

602+
// WithSharedBalancer sets balancer from parent driver to child driver
603+
func WithSharedBalancer(parent *Driver) Option {
604+
return func(ctx context.Context, c *Driver) error {
605+
c.balancer = parent.balancer
606+
607+
return nil
608+
}
609+
}
610+
602611
// WithTraceTable appends trace.Table into table traces
603612
func WithTraceTable(t trace.Table, opts ...trace.TableComposeOption) Option { //nolint:gocritic
604613
return func(ctx context.Context, c *Driver) error {

0 commit comments

Comments
 (0)