Skip to content

Commit 3b878aa

Browse files
authored
Merge pull request #1735 from ydb-platform/post-fix-balancer
refactoring of internal/balancer logic: delete unnesesary call meta context, renamed internal funcs for better understanding of balancer internals
2 parents f8b47a0 + 0c5f485 commit 3b878aa

File tree

1 file changed

+7
-19
lines changed

1 file changed

+7
-19
lines changed

internal/balancer/balancer.go

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ func (b *Balancer) clusterDiscovery(ctx context.Context) (err error) {
7979
)
8080
}
8181

82-
// conn is a singleton with auto reconnect logic
83-
func (b *Balancer) conn(ctx context.Context) (*grpc.ClientConn, error) {
82+
// discoveryConn returns connection to database endpoint for discovery call
83+
func (b *Balancer) discoveryConn(ctx context.Context) (*grpc.ClientConn, error) {
8484
if cc := b.cc.Load(); cc != nil {
8585
if cc.GetState() == connectivity.Ready {
8686
return cc, nil
@@ -91,18 +91,6 @@ func (b *Balancer) conn(ctx context.Context) (*grpc.ClientConn, error) {
9191
}
9292
}
9393

94-
ctx, traceID, err := meta.TraceID(ctx)
95-
if err != nil {
96-
return nil, xerrors.WithStackTrace(err)
97-
}
98-
99-
ctx, err = b.driverConfig.Meta().Context(ctx)
100-
if err != nil {
101-
return nil, xerrors.WithStackTrace(
102-
fmt.Errorf("failed to enrich context with meta, traceID %q: %w", traceID, err),
103-
)
104-
}
105-
10694
if dialTimeout := b.driverConfig.DialTimeout(); dialTimeout > 0 {
10795
var cancel context.CancelFunc
10896
ctx, cancel = xcontext.WithTimeout(ctx, dialTimeout)
@@ -121,7 +109,7 @@ func (b *Balancer) conn(ctx context.Context) (*grpc.ClientConn, error) {
121109
)
122110
if err != nil {
123111
return nil, xerrors.WithStackTrace(
124-
fmt.Errorf("failed to dial %q, traceID %q: %w", b.driverConfig.Endpoint(), traceID, err),
112+
fmt.Errorf("failed to dial %q: %w", b.driverConfig.Endpoint(), err),
125113
)
126114
}
127115

@@ -143,7 +131,7 @@ func (b *Balancer) clusterDiscoveryAttemptWithDial(ctx context.Context) (finalEr
143131
onDone(finalErr)
144132
}()
145133

146-
cc, err := b.conn(ctx)
134+
cc, err := b.discoveryConn(ctx)
147135
if err != nil {
148136
return xerrors.WithStackTrace(err)
149137
}
@@ -377,7 +365,7 @@ func (b *Balancer) NewStream(
377365
}
378366

379367
func (b *Balancer) wrapCall(ctx context.Context, f func(ctx context.Context, cc conn.Conn) error) (err error) {
380-
cc, err := b.getConn(ctx)
368+
cc, err := b.nextConn(ctx)
381369
if err != nil {
382370
return xerrors.WithStackTrace(err)
383371
}
@@ -415,14 +403,14 @@ func (b *Balancer) connections() *connectionsState {
415403
return b.connectionsState.Load()
416404
}
417405

418-
func (b *Balancer) getConn(ctx context.Context) (c conn.Conn, err error) {
406+
func (b *Balancer) nextConn(ctx context.Context) (c conn.Conn, err error) {
419407
if b.closed.Load() {
420408
return nil, xerrors.WithStackTrace(errBalancerClosed)
421409
}
422410

423411
onDone := trace.DriverOnBalancerChooseEndpoint(
424412
b.driverConfig.Trace(), &ctx,
425-
stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/v3/internal/balancer.(*Balancer).getConn"),
413+
stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/v3/internal/balancer.(*Balancer).nextConn"),
426414
)
427415
defer func() {
428416
if err == nil {

0 commit comments

Comments
 (0)