Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow to use common balancer in child drivers #1530

Merged
merged 6 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* Use common balancer for child drivers
asmyasnikov marked this conversation as resolved.
Show resolved Hide resolved

## v3.89.0
* Fixed send optional arguments to the server with `ydb.ParamsBuilder`

Expand Down
5 changes: 3 additions & 2 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,9 @@ 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 d.balancer == nil {
d.balancer, err = balancer.New(ctx, d.config, d.pool, d.discoveryOptions...)
}
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

перенести проверку выше

return xerrors.WithStackTrace(err)
}
Expand Down
9 changes: 9 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

"github.com/ydb-platform/ydb-go-sdk/v3/config"
"github.com/ydb-platform/ydb-go-sdk/v3/credentials"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/balancer"

Check failure on line 14 in options.go

View workflow job for this annotation

GitHub Actions / unit (1.21.x, macOS)

"github.com/ydb-platform/ydb-go-sdk/v3/internal/balancer" imported and not used

Check failure on line 14 in options.go

View workflow job for this annotation

GitHub Actions / unit (1.21.x, macOS)

"github.com/ydb-platform/ydb-go-sdk/v3/internal/balancer" imported and not used

Check failure on line 14 in options.go

View workflow job for this annotation

GitHub Actions / unit (1.21.x, macOS)

"github.com/ydb-platform/ydb-go-sdk/v3/internal/balancer" imported and not used
balancerConfig "github.com/ydb-platform/ydb-go-sdk/v3/internal/balancer/config"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/certificates"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/conn"
Expand Down Expand Up @@ -804,3 +805,11 @@
return pool.Take(ctx)
}
}

func WithSharedBalancer(parent *Driver) Option {
return func(ctx context.Context, c *Driver) error {
c.balancer = parent.balancer

return nil
}
}
4 changes: 1 addition & 3 deletions with.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,14 @@ func (d *Driver) with(ctx context.Context, opts ...Option) (*Driver, uint64, err
append(
append(
d.opts,
WithBalancer(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

вернуть как было!

d.config.Balancer(),
),
withOnClose(func(child *Driver) {
d.childrenMtx.Lock()
defer d.childrenMtx.Unlock()

delete(d.children, id)
}),
withConnPool(d.pool),
WithSharedBalancer(d),
asmyasnikov marked this conversation as resolved.
Show resolved Hide resolved
),
opts...,
)...,
Expand Down
Loading