forked from TrueCloudLab/frostfs-node
[#1447] services/tree: Move relaying code to a separate function
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
29708b78d7
commit
bc8d79ddf9
2 changed files with 20 additions and 60 deletions
|
@ -12,10 +12,24 @@ import (
|
|||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"go.uber.org/zap"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
var errNoSuitableNode = errors.New("no node was found to execute the request")
|
||||
|
||||
func relayUnary[Req any, Resp any](ctx context.Context, s *Service, ns []netmapSDK.NodeInfo, req *Req, callback func(TreeServiceClient, context.Context, *Req, ...grpc.CallOption) (*Resp, error)) (*Resp, error) {
|
||||
var resp *Resp
|
||||
var outErr error
|
||||
err := s.forEachNode(ctx, ns, func(c TreeServiceClient) bool {
|
||||
resp, outErr = callback(c, ctx, req)
|
||||
return true
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp, outErr
|
||||
}
|
||||
|
||||
// forEachNode executes callback for each node in the container until true is returned.
|
||||
// Returns errNoSuitableNode if there was no successful attempt to dial any node.
|
||||
func (s *Service) forEachNode(ctx context.Context, cntNodes []netmapSDK.NodeInfo, f func(c TreeServiceClient) bool) error {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue