2022-05-16 16:31:50 +00:00
|
|
|
package control
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control"
|
2024-02-06 14:34:32 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/tree"
|
2023-03-07 13:38:26 +00:00
|
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
2024-02-06 14:34:32 +00:00
|
|
|
netmapSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap"
|
2022-05-16 16:31:50 +00:00
|
|
|
"google.golang.org/grpc/codes"
|
|
|
|
"google.golang.org/grpc/status"
|
|
|
|
)
|
|
|
|
|
|
|
|
// TreeService represents a tree service instance.
|
|
|
|
type TreeService interface {
|
2024-02-06 14:34:32 +00:00
|
|
|
SynchronizeTree(ctx context.Context, cnr cid.ID, treeID string) error
|
|
|
|
ReplicateTreeOp(ctx context.Context, n netmapSDK.NodeInfo, req *tree.ApplyRequest) error
|
2022-05-16 16:31:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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())
|
|
|
|
}
|
|
|
|
|
2024-02-06 14:34:32 +00:00
|
|
|
err = s.treeService.SynchronizeTree(ctx, cnr, b.GetTreeId())
|
2022-05-16 16:31:50 +00:00
|
|
|
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
|
|
|
|
}
|