Skip to content

Commit

Permalink
Merge pull request #1530 from ydb-platform/use_common_balancer_in_sha…
Browse files Browse the repository at this point in the history
…red_drivers

allow to use common balancer in child drivers
  • Loading branch information
asmyasnikov authored Oct 25, 2024
2 parents 89f4332 + 8b810e4 commit fca922c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`

Expand Down
9 changes: 5 additions & 4 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 9 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit fca922c

Please sign in to comment.