[#1442] services/tree: Fix log message for failed Apply

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-05-27 14:16:12 +03:00 committed by fyrchik
parent 01d2e06a9b
commit 3caa982283

View file

@ -4,18 +4,15 @@ import (
"bytes" "bytes"
"context" "context"
"crypto/sha256" "crypto/sha256"
"encoding/base64" "encoding/hex"
"fmt" "fmt"
"time" "time"
clientcore "github.com/nspcc-dev/neofs-node/pkg/core/client"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/pilorama" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/pilorama"
"github.com/nspcc-dev/neofs-node/pkg/network"
"github.com/nspcc-dev/neofs-node/pkg/services/object_manager/placement" "github.com/nspcc-dev/neofs-node/pkg/services/object_manager/placement"
cidSDK "github.com/nspcc-dev/neofs-sdk-go/container/id" cidSDK "github.com/nspcc-dev/neofs-sdk-go/container/id"
netmapSDK "github.com/nspcc-dev/neofs-sdk-go/netmap" netmapSDK "github.com/nspcc-dev/neofs-sdk-go/netmap"
"go.uber.org/zap" "go.uber.org/zap"
"google.golang.org/grpc"
) )
type movePair struct { type movePair struct {
@ -62,24 +59,23 @@ func (s *Service) replicate(ctx context.Context, op movePair) error {
return fmt.Errorf("can't get container nodes: %w", err) return fmt.Errorf("can't get container nodes: %w", err)
} }
var node clientcore.NodeInfo
for _, n := range nodes { for _, n := range nodes {
if bytes.Equal(n.PublicKey(), s.rawPub) { if bytes.Equal(n.PublicKey(), s.rawPub) {
continue continue
} }
var lastErr error var lastErr error
var lastAddr string
n.IterateNetworkEndpoints(func(addr string) bool { n.IterateNetworkEndpoints(func(addr string) bool {
cc, err := grpc.DialContext(ctx, addr) lastAddr = addr
c, err := dialTreeService(ctx, addr)
if err != nil { if err != nil {
lastErr = err lastErr = err
return false return false
} }
// TODO cache clients
c := NewTreeServiceClient(cc)
_, lastErr = c.Apply(ctx, req) _, lastErr = c.Apply(ctx, req)
return lastErr == nil return lastErr == nil
}) })
@ -87,8 +83,8 @@ func (s *Service) replicate(ctx context.Context, op movePair) error {
if lastErr != nil { if lastErr != nil {
s.log.Warn("failed to sent update to the node", s.log.Warn("failed to sent update to the node",
zap.String("last_error", lastErr.Error()), zap.String("last_error", lastErr.Error()),
zap.String("address", network.StringifyGroup(node.AddressGroup())), zap.String("address", lastAddr),
zap.String("key", base64.StdEncoding.EncodeToString(node.PublicKey()))) zap.String("key", hex.EncodeToString(n.PublicKey())))
} }
} }
return nil return nil