[#1707] tree: Pass tracing context in forEachNode
All checks were successful
Vulncheck / Vulncheck (push) Successful in 1m7s
Pre-commit hooks / Pre-commit (push) Successful in 1m29s
Build / Build Components (push) Successful in 2m15s
Tests and linters / Run gofumpt (push) Successful in 3m24s
Tests and linters / Staticcheck (push) Successful in 4m3s
Tests and linters / Tests (push) Successful in 4m8s
Tests and linters / gopls check (push) Successful in 4m17s
Tests and linters / Lint (push) Successful in 4m28s
Tests and linters / Tests with -race (push) Successful in 5m28s
OCI image / Build container images (push) Successful in 4m34s
All checks were successful
Vulncheck / Vulncheck (push) Successful in 1m7s
Pre-commit hooks / Pre-commit (push) Successful in 1m29s
Build / Build Components (push) Successful in 2m15s
Tests and linters / Run gofumpt (push) Successful in 3m24s
Tests and linters / Staticcheck (push) Successful in 4m3s
Tests and linters / Tests (push) Successful in 4m8s
Tests and linters / gopls check (push) Successful in 4m17s
Tests and linters / Lint (push) Successful in 4m28s
Tests and linters / Tests with -race (push) Successful in 5m28s
OCI image / Build container images (push) Successful in 4m34s
Change-Id: I884dcd215bd3934f9b4ea43dcc77e38f9dadcf10 Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
6567ceaf13
commit
4bcb672630
3 changed files with 13 additions and 13 deletions
|
@ -19,8 +19,8 @@ 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)
|
||||
err := s.forEachNode(ctx, ns, func(fCtx context.Context, c TreeServiceClient) bool {
|
||||
resp, outErr = callback(c, fCtx, req)
|
||||
return true
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -31,7 +31,7 @@ func relayUnary[Req any, Resp any](ctx context.Context, s *Service, ns []netmapS
|
|||
|
||||
// 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 {
|
||||
func (s *Service) forEachNode(ctx context.Context, cntNodes []netmapSDK.NodeInfo, f func(context.Context, TreeServiceClient) bool) error {
|
||||
for _, n := range cntNodes {
|
||||
if bytes.Equal(n.PublicKey(), s.rawPub) {
|
||||
return nil
|
||||
|
@ -42,9 +42,9 @@ func (s *Service) forEachNode(ctx context.Context, cntNodes []netmapSDK.NodeInfo
|
|||
for _, n := range cntNodes {
|
||||
var stop bool
|
||||
for endpoint := range n.NetworkEndpoints() {
|
||||
stop = s.execOnClient(ctx, endpoint, func(c TreeServiceClient) bool {
|
||||
stop = s.execOnClient(ctx, endpoint, func(fCtx context.Context, c TreeServiceClient) bool {
|
||||
called = true
|
||||
return f(c)
|
||||
return f(fCtx, c)
|
||||
})
|
||||
if called {
|
||||
break
|
||||
|
@ -60,7 +60,7 @@ func (s *Service) forEachNode(ctx context.Context, cntNodes []netmapSDK.NodeInfo
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) execOnClient(ctx context.Context, endpoint string, f func(TreeServiceClient) bool) bool {
|
||||
func (s *Service) execOnClient(ctx context.Context, endpoint string, f func(context.Context, TreeServiceClient) bool) bool {
|
||||
ctx, span := tracing.StartSpanFromContext(ctx, "TreeService.IterateNetworkEndpoints",
|
||||
trace.WithAttributes(
|
||||
attribute.String("endpoint", endpoint),
|
||||
|
@ -73,5 +73,5 @@ func (s *Service) execOnClient(ctx context.Context, endpoint string, f func(Tree
|
|||
}
|
||||
|
||||
s.log.Debug(ctx, logs.TreeRedirectingTreeServiceQuery, zap.String("endpoint", endpoint))
|
||||
return f(c)
|
||||
return f(ctx, c)
|
||||
}
|
||||
|
|
|
@ -391,8 +391,8 @@ func (s *Service) GetSubTree(req *GetSubTreeRequest, srv TreeService_GetSubTreeS
|
|||
if pos < 0 {
|
||||
var cli TreeService_GetSubTreeClient
|
||||
var outErr error
|
||||
err = s.forEachNode(srv.Context(), ns, func(c TreeServiceClient) bool {
|
||||
cli, outErr = c.GetSubTree(srv.Context(), req)
|
||||
err = s.forEachNode(srv.Context(), ns, func(fCtx context.Context, c TreeServiceClient) bool {
|
||||
cli, outErr = c.GetSubTree(fCtx, req)
|
||||
return true
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -655,8 +655,8 @@ func (s *Service) GetOpLog(req *GetOpLogRequest, srv TreeService_GetOpLogServer)
|
|||
if pos < 0 {
|
||||
var cli TreeService_GetOpLogClient
|
||||
var outErr error
|
||||
err := s.forEachNode(srv.Context(), ns, func(c TreeServiceClient) bool {
|
||||
cli, outErr = c.GetOpLog(srv.Context(), req)
|
||||
err := s.forEachNode(srv.Context(), ns, func(fCtx context.Context, c TreeServiceClient) bool {
|
||||
cli, outErr = c.GetOpLog(fCtx, req)
|
||||
return true
|
||||
})
|
||||
if err != nil {
|
||||
|
|
|
@ -76,8 +76,8 @@ func (s *Service) synchronizeAllTrees(ctx context.Context, cid cid.ID) error {
|
|||
var treesToSync []string
|
||||
var outErr error
|
||||
|
||||
err = s.forEachNode(ctx, nodes, func(c TreeServiceClient) bool {
|
||||
resp, outErr = c.TreeList(ctx, req)
|
||||
err = s.forEachNode(ctx, nodes, func(fCtx context.Context, c TreeServiceClient) bool {
|
||||
resp, outErr = c.TreeList(fCtx, req)
|
||||
if outErr != nil {
|
||||
return false
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue