2023-12-27 11:37:22 +00:00
|
|
|
package control
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/engine"
|
|
|
|
"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-12-27 11:37:22 +00:00
|
|
|
"google.golang.org/grpc/codes"
|
|
|
|
"google.golang.org/grpc/status"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s *Server) SealWriteCache(ctx context.Context, req *control.SealWriteCacheRequest) (*control.SealWriteCacheResponse, error) {
|
|
|
|
err := s.isValidRequest(req)
|
|
|
|
if err != nil {
|
|
|
|
return nil, status.Error(codes.PermissionDenied, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
prm := engine.SealWriteCachePrm{
|
|
|
|
ShardIDs: s.getShardIDList(req.GetBody().GetShard_ID()),
|
|
|
|
IgnoreErrors: req.GetBody().GetIgnoreErrors(),
|
2024-07-31 13:30:07 +00:00
|
|
|
Async: req.GetBody().GetAsync(),
|
2024-08-06 10:20:33 +00:00
|
|
|
RestoreMode: req.GetBody().GetRestoreMode(),
|
2024-08-06 12:45:53 +00:00
|
|
|
Shrink: req.GetBody().GetShrink(),
|
2023-12-27 11:37:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
res, err := s.s.SealWriteCache(ctx, prm)
|
|
|
|
if err != nil {
|
|
|
|
return nil, status.Error(codes.Internal, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
resp := &control.SealWriteCacheResponse{Body: &control.SealWriteCacheResponse_Body{}}
|
|
|
|
for _, r := range res.ShardResults {
|
|
|
|
if r.Success {
|
|
|
|
resp.Body.Results = append(resp.GetBody().GetResults(), &control.SealWriteCacheResponse_Body_Status{
|
|
|
|
Shard_ID: *r.ShardID,
|
|
|
|
Success: true,
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
resp.Body.Results = append(resp.GetBody().GetResults(), &control.SealWriteCacheResponse_Body_Status{
|
|
|
|
Shard_ID: *r.ShardID,
|
|
|
|
Error: r.ErrorMsg,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-16 09:11:57 +00:00
|
|
|
err = ctrlmessage.Sign(s.key, resp)
|
2023-12-27 11:37:22 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
}
|