diff --git a/CHANGELOG.md b/CHANGELOG.md index 87971af03..574e398e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +* Added option `ydb.WithSharedBalancer(*Driver)` for child drivers + ## v3.89.0 * Fixed send optional arguments to the server with `ydb.ParamsBuilder` diff --git a/driver.go b/driver.go index 49920cf2a..b168f87ae 100644 --- a/driver.go +++ b/driver.go @@ -415,10 +415,11 @@ func (d *Driver) connect(ctx context.Context) (err error) { if d.pool == nil { d.pool = conn.NewPool(ctx, d.config) } - - d.balancer, err = balancer.New(ctx, d.config, d.pool, d.discoveryOptions...) - if err != nil { - return xerrors.WithStackTrace(err) + if d.balancer == nil { + d.balancer, err = balancer.New(ctx, d.config, d.pool, d.discoveryOptions...) + if err != nil { + return xerrors.WithStackTrace(err) + } } d.table = xsync.OnceValue(func() (*internalTable.Client, error) { diff --git a/options.go b/options.go index b2983d366..7dfdfc3dd 100644 --- a/options.go +++ b/options.go @@ -599,6 +599,15 @@ func WithPanicCallback(panicCallback func(e interface{})) Option { } } +// WithSharedBalancer sets balancer from parent driver to child driver +func WithSharedBalancer(parent *Driver) Option { + return func(ctx context.Context, c *Driver) error { + c.balancer = parent.balancer + + return nil + } +} + // WithTraceTable appends trace.Table into table traces func WithTraceTable(t trace.Table, opts ...trace.TableComposeOption) Option { //nolint:gocritic return func(ctx context.Context, c *Driver) error {