Alexander Chuprov
b078fe5ba1
All checks were successful
DCO action / DCO (pull_request) Successful in 6m11s
Build / Build Components (1.22) (pull_request) Successful in 7m50s
Build / Build Components (1.21) (pull_request) Successful in 8m3s
Tests and linters / Lint (pull_request) Successful in 9m45s
Tests and linters / gopls check (pull_request) Successful in 12m40s
Vulncheck / Vulncheck (pull_request) Successful in 12m35s
Tests and linters / Staticcheck (pull_request) Successful in 15m34s
Pre-commit hooks / Pre-commit (pull_request) Successful in 19m38s
Tests and linters / Tests with -race (pull_request) Successful in 21m40s
Tests and linters / Tests (1.22) (pull_request) Successful in 3m21s
Tests and linters / Tests (1.21) (pull_request) Successful in 3m36s
Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
60 lines
1.5 KiB
Go
60 lines
1.5 KiB
Go
package control
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control/server/ctrlmessage"
|
|
"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 (
|
|
m mode.Mode
|
|
|
|
requestedMode = req.GetBody().GetMode()
|
|
)
|
|
|
|
switch requestedMode {
|
|
case control.ShardMode_READ_WRITE:
|
|
m = mode.ReadWrite
|
|
case control.ShardMode_READ_ONLY:
|
|
m = mode.ReadOnly
|
|
case control.ShardMode_DEGRADED:
|
|
m = mode.Degraded
|
|
case control.ShardMode_DEGRADED_READ_ONLY:
|
|
m = mode.DegradedReadOnly
|
|
default:
|
|
return nil, status.Error(codes.Internal, fmt.Sprintf("unknown shard mode: %s", requestedMode))
|
|
}
|
|
|
|
for _, shardID := range s.getShardIDList(req.GetBody().GetShard_ID()) {
|
|
err = s.s.SetShardMode(shardID, m, req.GetBody().GetResetErrorCounter())
|
|
if err != nil {
|
|
return nil, status.Error(codes.Internal, err.Error())
|
|
}
|
|
}
|
|
|
|
// create and fill response
|
|
resp := new(control.SetShardModeResponse)
|
|
|
|
body := new(control.SetShardModeResponse_Body)
|
|
resp.SetBody(body)
|
|
|
|
// sign the response
|
|
err = ctrlmessage.Sign(s.key, resp)
|
|
if err != nil {
|
|
return nil, status.Error(codes.Internal, err.Error())
|
|
}
|
|
|
|
return resp, nil
|
|
}
|