[#741] treesvc: Refactor tree sync
All checks were successful
DCO action / DCO (pull_request) Successful in 1m22s
Build / Build Components (1.21) (pull_request) Successful in 3m51s
Vulncheck / Vulncheck (pull_request) Successful in 3m30s
Build / Build Components (1.20) (pull_request) Successful in 4m12s
Tests and linters / Staticcheck (pull_request) Successful in 4m47s
Tests and linters / Lint (pull_request) Successful in 5m45s
Tests and linters / Tests (1.20) (pull_request) Successful in 6m25s
Tests and linters / Tests (1.21) (pull_request) Successful in 8m9s
Tests and linters / Tests with -race (pull_request) Successful in 8m40s
All checks were successful
DCO action / DCO (pull_request) Successful in 1m22s
Build / Build Components (1.21) (pull_request) Successful in 3m51s
Vulncheck / Vulncheck (pull_request) Successful in 3m30s
Build / Build Components (1.20) (pull_request) Successful in 4m12s
Tests and linters / Staticcheck (pull_request) Successful in 4m47s
Tests and linters / Lint (pull_request) Successful in 5m45s
Tests and linters / Tests (1.20) (pull_request) Successful in 6m25s
Tests and linters / Tests (1.21) (pull_request) Successful in 8m9s
Tests and linters / Tests with -race (pull_request) Successful in 8m40s
Fix linter issues. Add error logging. Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
1c735efedd
commit
b20298007e
2 changed files with 22 additions and 15 deletions
|
@ -65,6 +65,8 @@ const (
|
||||||
TreeSynchronizeTree = "synchronize tree"
|
TreeSynchronizeTree = "synchronize tree"
|
||||||
TreeFailedToRunTreeSynchronizationOverAllNodes = "failed to run tree synchronization over all nodes"
|
TreeFailedToRunTreeSynchronizationOverAllNodes = "failed to run tree synchronization over all nodes"
|
||||||
TreeFailedToRunTreeSynchronizationForSpecificNode = "failed to run tree synchronization for specific node"
|
TreeFailedToRunTreeSynchronizationForSpecificNode = "failed to run tree synchronization for specific node"
|
||||||
|
TreeFailedToParseAddressForTreeSynchronization = "failed to parse address for tree synchronization"
|
||||||
|
TreeFailedToConnectForTreeSynchronization = "failed to connect for tree synchronization"
|
||||||
TreeSyncingTrees = "syncing trees..."
|
TreeSyncingTrees = "syncing trees..."
|
||||||
TreeCouldNotFetchContainers = "could not fetch containers"
|
TreeCouldNotFetchContainers = "could not fetch containers"
|
||||||
TreeTreesHaveBeenSynchronized = "trees have been synchronized"
|
TreeTreesHaveBeenSynchronized = "trees have been synchronized"
|
||||||
|
|
|
@ -217,8 +217,10 @@ func (s *Service) applyOperationStream(ctx context.Context, cid cid.ID, treeID s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) startStream(ctx context.Context, cid cid.ID, treeID string,
|
func (s *Service) startStream(ctx context.Context, cid cid.ID, treeID string,
|
||||||
height uint64, treeClient TreeServiceClient, opsCh chan<- *pilorama.Move,
|
height uint64, cc *grpc.ClientConn, opsCh chan<- *pilorama.Move,
|
||||||
) error {
|
) error {
|
||||||
|
treeClient := NewTreeServiceClient(cc)
|
||||||
|
|
||||||
rawCID := make([]byte, sha256.Size)
|
rawCID := make([]byte, sha256.Size)
|
||||||
cid.Encode(rawCID)
|
cid.Encode(rawCID)
|
||||||
|
|
||||||
|
@ -296,29 +298,19 @@ func (s *Service) synchronizeTree(ctx context.Context, cid cid.ID, from uint64,
|
||||||
n.IterateNetworkEndpoints(func(addr string) bool {
|
n.IterateNetworkEndpoints(func(addr string) bool {
|
||||||
var a network.Address
|
var a network.Address
|
||||||
if err := a.FromString(addr); err != nil {
|
if err := a.FromString(addr); err != nil {
|
||||||
|
s.log.Warn(logs.TreeFailedToParseAddressForTreeSynchronization, zap.Error(err), zap.String("address", addr))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
cc, err := grpc.DialContext(egCtx, a.URIAddr(),
|
cc, err := s.dialCtx(egCtx, a)
|
||||||
grpc.WithChainUnaryInterceptor(
|
|
||||||
metrics.NewUnaryClientInterceptor(),
|
|
||||||
tracing_grpc.NewUnaryClientInteceptor(),
|
|
||||||
),
|
|
||||||
grpc.WithChainStreamInterceptor(
|
|
||||||
metrics.NewStreamClientInterceptor(),
|
|
||||||
tracing_grpc.NewStreamClientInterceptor(),
|
|
||||||
),
|
|
||||||
grpc.WithTransportCredentials(insecure.NewCredentials()))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Failed to connect, try the next address.
|
s.log.Warn(logs.TreeFailedToConnectForTreeSynchronization, zap.Error(err), zap.String("address", addr))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
defer cc.Close()
|
defer cc.Close()
|
||||||
|
|
||||||
treeClient := NewTreeServiceClient(cc)
|
err = s.startStream(egCtx, cid, treeID, from, cc, nodeOperationStreams[i])
|
||||||
err = s.startStream(egCtx, cid, treeID, from, treeClient, nodeOperationStreams[i])
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Error with the response, try the next node.
|
|
||||||
s.log.Warn(logs.TreeFailedToRunTreeSynchronizationForSpecificNode, zap.Error(err), zap.String("address", addr))
|
s.log.Warn(logs.TreeFailedToRunTreeSynchronizationForSpecificNode, zap.Error(err), zap.String("address", addr))
|
||||||
}
|
}
|
||||||
nodeSynced = err == nil
|
nodeSynced = err == nil
|
||||||
|
@ -348,6 +340,19 @@ func (s *Service) synchronizeTree(ctx context.Context, cid cid.ID, from uint64,
|
||||||
return from
|
return from
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (*Service) dialCtx(egCtx context.Context, a network.Address) (*grpc.ClientConn, error) {
|
||||||
|
return grpc.DialContext(egCtx, a.URIAddr(),
|
||||||
|
grpc.WithChainUnaryInterceptor(
|
||||||
|
metrics.NewUnaryClientInterceptor(),
|
||||||
|
tracing_grpc.NewUnaryClientInteceptor(),
|
||||||
|
),
|
||||||
|
grpc.WithChainStreamInterceptor(
|
||||||
|
metrics.NewStreamClientInterceptor(),
|
||||||
|
tracing_grpc.NewStreamClientInterceptor(),
|
||||||
|
),
|
||||||
|
grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||||
|
}
|
||||||
|
|
||||||
// ErrAlreadySyncing is returned when a service synchronization has already
|
// ErrAlreadySyncing is returned when a service synchronization has already
|
||||||
// been started.
|
// been started.
|
||||||
var ErrAlreadySyncing = errors.New("service is being synchronized")
|
var ErrAlreadySyncing = errors.New("service is being synchronized")
|
||||||
|
|
Loading…
Reference in a new issue