2021-12-27 16:32:25 +00:00
|
|
|
package control
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode"
|
|
|
|
"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"
|
2021-12-27 16:32:25 +00:00
|
|
|
"google.golang.org/grpc/codes"
|
|
|
|
"google.golang.org/grpc/status"
|
|
|
|
)
|
|
|
|
|
2024-10-21 08:56:38 +00:00
|
|
|
func (s *Server) SetShardMode(ctx context.Context, req *control.SetShardModeRequest) (*control.SetShardModeResponse, error) {
|
2021-12-27 16:32:25 +00:00
|
|
|
// verify request
|
|
|
|
err := s.isValidRequest(req)
|
|
|
|
if err != nil {
|
|
|
|
return nil, status.Error(codes.PermissionDenied, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
2022-06-28 14:05:08 +00:00
|
|
|
m mode.Mode
|
2021-12-27 16:32:25 +00:00
|
|
|
|
2022-10-10 17:54:14 +00:00
|
|
|
requestedMode = req.GetBody().GetMode()
|
2021-12-27 16:32:25 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
switch requestedMode {
|
|
|
|
case control.ShardMode_READ_WRITE:
|
2022-06-28 14:05:08 +00:00
|
|
|
m = mode.ReadWrite
|
2021-12-27 16:32:25 +00:00
|
|
|
case control.ShardMode_READ_ONLY:
|
2022-06-28 14:05:08 +00:00
|
|
|
m = mode.ReadOnly
|
2022-03-17 11:55:25 +00:00
|
|
|
case control.ShardMode_DEGRADED:
|
2022-06-28 14:05:08 +00:00
|
|
|
m = mode.Degraded
|
2022-07-18 11:44:29 +00:00
|
|
|
case control.ShardMode_DEGRADED_READ_ONLY:
|
2022-10-10 08:59:15 +00:00
|
|
|
m = mode.DegradedReadOnly
|
2021-12-27 16:32:25 +00:00
|
|
|
default:
|
|
|
|
return nil, status.Error(codes.Internal, fmt.Sprintf("unknown shard mode: %s", requestedMode))
|
|
|
|
}
|
|
|
|
|
2023-12-11 10:18:34 +00:00
|
|
|
for _, shardID := range s.getShardIDList(req.GetBody().GetShard_ID()) {
|
2024-10-21 08:56:38 +00:00
|
|
|
err = s.s.SetShardMode(ctx, shardID, m, req.GetBody().GetResetErrorCounter())
|
2022-10-10 17:54:14 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, status.Error(codes.Internal, err.Error())
|
|
|
|
}
|
2021-12-27 16:32:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// create and fill response
|
|
|
|
resp := new(control.SetShardModeResponse)
|
|
|
|
|
|
|
|
body := new(control.SetShardModeResponse_Body)
|
|
|
|
resp.SetBody(body)
|
|
|
|
|
|
|
|
// sign the response
|
2024-05-16 09:11:57 +00:00
|
|
|
err = ctrlmessage.Sign(s.key, resp)
|
2021-12-27 16:32:25 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, status.Error(codes.Internal, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp, nil
|
|
|
|
}
|