-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added balancer with metadata customization
- Loading branch information
Roman Golov
committed
Nov 2, 2024
1 parent
17a901b
commit a789c3c
Showing
5 changed files
with
56 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package ydb | ||
|
||
import ( | ||
"context" | ||
|
||
"google.golang.org/grpc" | ||
|
||
"github.com/ydb-platform/ydb-go-sdk/v3/internal/balancer" | ||
"github.com/ydb-platform/ydb-go-sdk/v3/internal/meta" | ||
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors" | ||
) | ||
|
||
type balancerWithMeta struct { | ||
balancer *balancer.Balancer | ||
meta *meta.Meta | ||
} | ||
|
||
func newBalancerWithMeta(b *balancer.Balancer, m *meta.Meta) *balancerWithMeta { | ||
return &balancerWithMeta{balancer: b, meta: m} | ||
} | ||
|
||
func (b *balancerWithMeta) Balancer() *balancer.Balancer { | ||
return b.balancer | ||
} | ||
|
||
func (b *balancerWithMeta) Invoke(ctx context.Context, method string, args any, reply any, | ||
opts ...grpc.CallOption, | ||
) error { | ||
metaCtx, err := b.meta.Context(ctx) | ||
if err != nil { | ||
return xerrors.WithStackTrace(err) | ||
} | ||
|
||
return b.balancer.Invoke(metaCtx, method, args, reply, opts...) | ||
} | ||
|
||
func (b *balancerWithMeta) NewStream(ctx context.Context, desc *grpc.StreamDesc, method string, | ||
opts ...grpc.CallOption, | ||
) (grpc.ClientStream, error) { | ||
metaCtx, err := b.meta.Context(ctx) | ||
if err != nil { | ||
return nil, xerrors.WithStackTrace(err) | ||
} | ||
|
||
return b.balancer.NewStream(metaCtx, desc, method, opts...) | ||
} | ||
|
||
func (b *balancerWithMeta) Close(ctx context.Context) error { | ||
return b.balancer.Close(ctx) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters