-
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 6b609f5
Showing
5 changed files
with
53 additions
and
8 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,47 @@ | ||
package ydb | ||
|
||
import ( | ||
"context" | ||
|
||
"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" | ||
"google.golang.org/grpc" | ||
) | ||
|
||
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