All checks were successful
DCO action / DCO (pull_request) Successful in 31s
Tests and linters / Run gofumpt (pull_request) Successful in 29s
Vulncheck / Vulncheck (pull_request) Successful in 54s
Build / Build Components (pull_request) Successful in 1m29s
Pre-commit hooks / Pre-commit (pull_request) Successful in 1m28s
Tests and linters / gopls check (pull_request) Successful in 2m15s
Tests and linters / Lint (pull_request) Successful in 2m41s
Tests and linters / Staticcheck (pull_request) Successful in 2m49s
Tests and linters / Tests (pull_request) Successful in 3m52s
Tests and linters / Tests with -race (pull_request) Successful in 5m1s
Vulncheck / Vulncheck (push) Successful in 1m5s
Pre-commit hooks / Pre-commit (push) Successful in 1m19s
Build / Build Components (push) Successful in 1m36s
Tests and linters / gopls check (push) Successful in 2m16s
Tests and linters / Run gofumpt (push) Successful in 2m32s
Tests and linters / Staticcheck (push) Successful in 2m49s
Tests and linters / Lint (push) Successful in 3m10s
Tests and linters / Tests (push) Successful in 3m12s
Tests and linters / Tests with -race (push) Successful in 4m15s
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
66 lines
1.8 KiB
Go
66 lines
1.8 KiB
Go
package control
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/engine"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control/server/ctrlmessage"
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
|
"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.
|
|
func (s *Server) DropObjects(ctx context.Context, req *control.DropObjectsRequest) (*control.DropObjectsResponse, error) {
|
|
// verify request
|
|
if err := s.isValidRequest(req); err != nil {
|
|
return nil, status.Error(codes.PermissionDenied, err.Error())
|
|
}
|
|
|
|
binAddrList := req.GetBody().GetAddressList()
|
|
addrList := make([]oid.Address, len(binAddrList))
|
|
|
|
for i := range binAddrList {
|
|
err := addrList[i].DecodeString(string(binAddrList[i]))
|
|
if err != nil {
|
|
return nil, status.Error(codes.InvalidArgument,
|
|
fmt.Sprintf("invalid binary object address: %v", err),
|
|
)
|
|
}
|
|
}
|
|
|
|
var firstErr error
|
|
for i := range addrList {
|
|
var prm engine.DeletePrm
|
|
prm.WithForceRemoval()
|
|
prm.WithAddress(addrList[i])
|
|
|
|
if err := s.s.Delete(ctx, prm); err != nil && firstErr == nil {
|
|
firstErr = err
|
|
}
|
|
}
|
|
|
|
if firstErr != nil {
|
|
return nil, status.Error(codes.Internal, firstErr.Error())
|
|
}
|
|
|
|
// create and fill response
|
|
resp := new(control.DropObjectsResponse)
|
|
|
|
body := new(control.DropObjectsResponse_Body)
|
|
resp.SetBody(body)
|
|
|
|
// sign the response
|
|
if err := ctrlmessage.Sign(s.key, resp); err != nil {
|
|
return nil, status.Error(codes.Internal, err.Error())
|
|
}
|
|
|
|
return resp, nil
|
|
}
|