|
| 1 | +package ydb |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + |
| 6 | + "google.golang.org/grpc" |
| 7 | + |
| 8 | + "github.com/ydb-platform/ydb-go-sdk/v3/internal/balancer" |
| 9 | + "github.com/ydb-platform/ydb-go-sdk/v3/internal/meta" |
| 10 | + "github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors" |
| 11 | +) |
| 12 | + |
| 13 | +type balancerWithMeta struct { |
| 14 | + balancer *balancer.Balancer |
| 15 | + meta *meta.Meta |
| 16 | +} |
| 17 | + |
| 18 | +func newBalancerWithMeta(b *balancer.Balancer, m *meta.Meta) *balancerWithMeta { |
| 19 | + return &balancerWithMeta{balancer: b, meta: m} |
| 20 | +} |
| 21 | + |
| 22 | +func (b *balancerWithMeta) Invoke(ctx context.Context, method string, args any, reply any, |
| 23 | + opts ...grpc.CallOption, |
| 24 | +) error { |
| 25 | + metaCtx, err := b.meta.Context(ctx) |
| 26 | + if err != nil { |
| 27 | + return xerrors.WithStackTrace(err) |
| 28 | + } |
| 29 | + |
| 30 | + return b.balancer.Invoke(metaCtx, method, args, reply, opts...) |
| 31 | +} |
| 32 | + |
| 33 | +func (b *balancerWithMeta) NewStream(ctx context.Context, desc *grpc.StreamDesc, method string, |
| 34 | + opts ...grpc.CallOption, |
| 35 | +) (grpc.ClientStream, error) { |
| 36 | + metaCtx, err := b.meta.Context(ctx) |
| 37 | + if err != nil { |
| 38 | + return nil, xerrors.WithStackTrace(err) |
| 39 | + } |
| 40 | + |
| 41 | + return b.balancer.NewStream(metaCtx, desc, method, opts...) |
| 42 | +} |
| 43 | + |
| 44 | +func (b *balancerWithMeta) Close(ctx context.Context) error { |
| 45 | + return b.balancer.Close(ctx) |
| 46 | +} |
0 commit comments