2023-05-02 15:40:54 +00:00
|
|
|
package control
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-05-04 10:58:26 +00:00
|
|
|
"errors"
|
2023-05-02 15:40:54 +00:00
|
|
|
|
2023-05-04 10:58:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/engine"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util/logicerr"
|
2023-05-02 15:40:54 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control"
|
2024-05-16 09:11:57 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control/server/ctrlmessage"
|
2023-05-04 10:58:26 +00:00
|
|
|
"google.golang.org/grpc/codes"
|
|
|
|
"google.golang.org/grpc/status"
|
2023-05-02 15:40:54 +00:00
|
|
|
)
|
|
|
|
|
2023-05-04 10:58:26 +00:00
|
|
|
func (s *Server) StartShardEvacuation(ctx context.Context, req *control.StartShardEvacuationRequest) (*control.StartShardEvacuationResponse, error) {
|
|
|
|
err := s.isValidRequest(req)
|
|
|
|
if err != nil {
|
|
|
|
return nil, status.Error(codes.PermissionDenied, err.Error())
|
|
|
|
}
|
|
|
|
|
2024-02-05 13:33:09 +00:00
|
|
|
if req.GetBody().GetScope() == uint32(control.StartShardEvacuationRequest_Body_NONE) {
|
|
|
|
return nil, status.Error(codes.InvalidArgument, "no evacuation scope")
|
|
|
|
}
|
|
|
|
|
2024-02-05 12:42:30 +00:00
|
|
|
prm := engine.EvacuateShardPrm{
|
2024-02-05 14:48:43 +00:00
|
|
|
ShardID: s.getShardIDList(req.GetBody().GetShard_ID()),
|
|
|
|
IgnoreErrors: req.GetBody().GetIgnoreErrors(),
|
2024-02-06 14:34:32 +00:00
|
|
|
ObjectsHandler: s.replicateObject,
|
|
|
|
TreeHandler: s.replicateTree,
|
2024-02-05 14:48:43 +00:00
|
|
|
Async: true,
|
|
|
|
Scope: engine.EvacuateScope(req.GetBody().GetScope()),
|
2024-02-05 12:42:30 +00:00
|
|
|
}
|
2023-05-04 10:58:26 +00:00
|
|
|
|
|
|
|
_, err = s.s.Evacuate(ctx, prm)
|
|
|
|
if err != nil {
|
|
|
|
var logicalErr logicerr.Logical
|
|
|
|
if errors.As(err, &logicalErr) {
|
|
|
|
return nil, status.Error(codes.Aborted, err.Error())
|
|
|
|
}
|
|
|
|
return nil, status.Error(codes.Internal, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
resp := &control.StartShardEvacuationResponse{
|
|
|
|
Body: &control.StartShardEvacuationResponse_Body{},
|
|
|
|
}
|
|
|
|
|
2024-05-16 09:11:57 +00:00
|
|
|
err = ctrlmessage.Sign(s.key, resp)
|
2023-05-04 10:58:26 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, status.Error(codes.Internal, err.Error())
|
|
|
|
}
|
|
|
|
return resp, nil
|
2023-05-02 15:40:54 +00:00
|
|
|
}
|
|
|
|
|
2023-05-04 10:58:26 +00:00
|
|
|
func (s *Server) GetShardEvacuationStatus(ctx context.Context, req *control.GetShardEvacuationStatusRequest) (*control.GetShardEvacuationStatusResponse, error) {
|
|
|
|
err := s.isValidRequest(req)
|
|
|
|
if err != nil {
|
|
|
|
return nil, status.Error(codes.PermissionDenied, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
state, err := s.s.GetEvacuationState(ctx)
|
|
|
|
if err != nil {
|
|
|
|
var logicalErr logicerr.Logical
|
|
|
|
if errors.As(err, &logicalErr) {
|
|
|
|
return nil, status.Error(codes.Aborted, err.Error())
|
|
|
|
}
|
|
|
|
return nil, status.Error(codes.Internal, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := stateToResponse(state)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-05-16 09:11:57 +00:00
|
|
|
err = ctrlmessage.Sign(s.key, resp)
|
2023-05-04 10:58:26 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, status.Error(codes.Internal, err.Error())
|
|
|
|
}
|
|
|
|
return resp, nil
|
2023-05-02 15:40:54 +00:00
|
|
|
}
|
|
|
|
|
2023-05-04 10:58:26 +00:00
|
|
|
func (s *Server) StopShardEvacuation(ctx context.Context, req *control.StopShardEvacuationRequest) (*control.StopShardEvacuationResponse, error) {
|
|
|
|
err := s.isValidRequest(req)
|
|
|
|
if err != nil {
|
|
|
|
return nil, status.Error(codes.PermissionDenied, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
err = s.s.EnqueRunningEvacuationStop(ctx)
|
|
|
|
if err != nil {
|
|
|
|
var logicalErr logicerr.Logical
|
|
|
|
if errors.As(err, &logicalErr) {
|
|
|
|
return nil, status.Error(codes.Aborted, err.Error())
|
|
|
|
}
|
|
|
|
return nil, status.Error(codes.Internal, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
resp := &control.StopShardEvacuationResponse{
|
|
|
|
Body: &control.StopShardEvacuationResponse_Body{},
|
|
|
|
}
|
|
|
|
|
2024-05-16 09:11:57 +00:00
|
|
|
err = ctrlmessage.Sign(s.key, resp)
|
2023-05-04 10:58:26 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, status.Error(codes.Internal, err.Error())
|
|
|
|
}
|
|
|
|
return resp, nil
|
2023-05-02 15:40:54 +00:00
|
|
|
}
|
2024-03-12 15:57:38 +00:00
|
|
|
|
|
|
|
func (s *Server) ResetShardEvacuationStatus(ctx context.Context, req *control.ResetShardEvacuationStatusRequest) (*control.ResetShardEvacuationStatusResponse, error) {
|
|
|
|
err := s.isValidRequest(req)
|
|
|
|
if err != nil {
|
|
|
|
return nil, status.Error(codes.PermissionDenied, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
err = s.s.ResetEvacuationStatus(ctx)
|
|
|
|
if err != nil {
|
|
|
|
var logicalErr logicerr.Logical
|
|
|
|
if errors.As(err, &logicalErr) {
|
|
|
|
return nil, status.Error(codes.Aborted, err.Error())
|
|
|
|
}
|
|
|
|
return nil, status.Error(codes.Internal, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
resp := &control.ResetShardEvacuationStatusResponse{
|
|
|
|
Body: &control.ResetShardEvacuationStatusResponse_Body{},
|
|
|
|
}
|
|
|
|
|
2024-05-16 09:11:57 +00:00
|
|
|
err = ctrlmessage.Sign(s.key, resp)
|
2024-03-12 15:57:38 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, status.Error(codes.Internal, err.Error())
|
|
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
}
|