-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1536 from ydb-platform/add-metadate-middleware
Added balancer with metadata customization
- Loading branch information
Showing
5 changed files
with
52 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,46 @@ | ||
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) 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