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"
|
2021-12-27 16:32:25 +00:00
|
|
|
"google.golang.org/grpc/codes"
|
|
|
|
"google.golang.org/grpc/status"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s *Server) SetShardMode(_ context.Context, req *control.SetShardModeRequest) (*control.SetShardModeResponse, error) {
|
|
|
|
// 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))
|
|
|
|
}
|
|
|
|
|
2022-10-10 18:14:12 +00:00
|
|
|
for _, shardID := range s.getShardIDList(req.Body.GetShard_ID()) {
|
2022-10-20 10:22:10 +00:00
|
|
|
err = s.s.SetShardMode(shardID, m, req.Body.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
|
|
|
|
err = SignMessage(s.key, resp)
|
|
|
|
if err != nil {
|
|
|
|
return nil, status.Error(codes.Internal, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp, nil
|
|
|
|
}
|