2021-02-21 08:30:32 +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/engine"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control"
|
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
2021-02-21 08:30:32 +00:00
|
|
|
"google.golang.org/grpc/codes"
|
|
|
|
"google.golang.org/grpc/status"
|
|
|
|
)
|
|
|
|
|
|
|
|
// DropObjects marks objects to be removed from the local node.
|
|
|
|
//
|
|
|
|
// Objects are marked via garbage collector's callback.
|
|
|
|
//
|
|
|
|
// If some address is not a valid object address in a binary format, an error returns.
|
|
|
|
// If request is unsigned or signed by disallowed key, permission error returns.
|
2023-04-04 11:40:01 +00:00
|
|
|
func (s *Server) DropObjects(ctx context.Context, req *control.DropObjectsRequest) (*control.DropObjectsResponse, error) {
|
2021-02-21 08:30:32 +00:00
|
|
|
// verify request
|
|
|
|
if err := s.isValidRequest(req); err != nil {
|
|
|
|
return nil, status.Error(codes.PermissionDenied, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
binAddrList := req.GetBody().GetAddressList()
|
2022-05-31 17:00:41 +00:00
|
|
|
addrList := make([]oid.Address, len(binAddrList))
|
2021-02-21 08:30:32 +00:00
|
|
|
|
|
|
|
for i := range binAddrList {
|
2022-05-31 17:00:41 +00:00
|
|
|
err := addrList[i].DecodeString(string(binAddrList[i]))
|
2021-02-21 08:30:32 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, status.Error(codes.InvalidArgument,
|
|
|
|
fmt.Sprintf("invalid binary object address: %v", err),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-14 14:18:11 +00:00
|
|
|
var firstErr error
|
|
|
|
for i := range addrList {
|
|
|
|
var prm engine.DeletePrm
|
|
|
|
prm.WithForceRemoval()
|
|
|
|
prm.WithAddress(addrList[i])
|
2022-09-14 14:13:40 +00:00
|
|
|
|
2023-03-20 12:10:53 +00:00
|
|
|
//nolint: contextcheck
|
2023-04-04 11:40:01 +00:00
|
|
|
_, err := s.s.Delete(ctx, prm)
|
2022-09-14 14:18:11 +00:00
|
|
|
if err != nil && firstErr == nil {
|
|
|
|
firstErr = err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if firstErr != nil {
|
|
|
|
return nil, status.Error(codes.Internal, firstErr.Error())
|
2021-02-21 08:30:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// create and fill response
|
|
|
|
resp := new(control.DropObjectsResponse)
|
|
|
|
|
|
|
|
body := new(control.DropObjectsResponse_Body)
|
|
|
|
resp.SetBody(body)
|
|
|
|
|
|
|
|
// sign the response
|
|
|
|
if err := SignMessage(s.key, resp); err != nil {
|
|
|
|
return nil, status.Error(codes.Internal, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp, nil
|
|
|
|
}
|