[#1333] services/control: Allow to synchronize local trees
Do not check that a node indeed belongs to the container, because the synchronization will fail in this case anyway. Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
0dc1a4e336
commit
bfdd68dcb3
13 changed files with 836 additions and 180 deletions
48
pkg/services/control/server/syncronize_tree.go
Normal file
48
pkg/services/control/server/syncronize_tree.go
Normal file
|
@ -0,0 +1,48 @@
|
|||
package control
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/nspcc-dev/neofs-node/pkg/services/control"
|
||||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
// TreeService represents a tree service instance.
|
||||
type TreeService interface {
|
||||
Synchronize(ctx context.Context, cnr cid.ID, treeID string) error
|
||||
}
|
||||
|
||||
func (s *Server) SynchronizeTree(ctx context.Context, req *control.SynchronizeTreeRequest) (*control.SynchronizeTreeResponse, error) {
|
||||
err := s.isValidRequest(req)
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.PermissionDenied, err.Error())
|
||||
}
|
||||
|
||||
if s.treeService == nil {
|
||||
return nil, status.Error(codes.Internal, "tree service is disabled")
|
||||
}
|
||||
|
||||
b := req.GetBody()
|
||||
|
||||
var cnr cid.ID
|
||||
if err := cnr.Decode(b.GetContainerId()); err != nil {
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
|
||||
err = s.treeService.Synchronize(ctx, cnr, b.GetTreeId())
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
|
||||
resp := new(control.SynchronizeTreeResponse)
|
||||
resp.SetBody(new(control.SynchronizeTreeResponse_Body))
|
||||
|
||||
err = SignMessage(s.key, resp)
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue