forked from TrueCloudLab/frostfs-node
[#401] control: Serve DropObjects RPC
Re-compile protobuf definition of Control service. Implement required messages on DropObjects RPC request and response messages. Implement `DropObjects` method on Control service server of the node. Use `StorageEngine.Delete` method as a deleted object handler on server. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
f2337baedc
commit
aa24702ebe
6 changed files with 624 additions and 79 deletions
61
pkg/services/control/server/gc.go
Normal file
61
pkg/services/control/server/gc.go
Normal file
|
@ -0,0 +1,61 @@
|
|||
package control
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/services/control"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
// DeletedObjectHandler is a handler of objects to be removed.
|
||||
type DeletedObjectHandler func([]*object.Address) error
|
||||
|
||||
// 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(_ 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([]*object.Address, 0, len(binAddrList))
|
||||
|
||||
for i := range binAddrList {
|
||||
a := object.NewAddress()
|
||||
|
||||
err := a.Unmarshal(binAddrList[i])
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.InvalidArgument,
|
||||
fmt.Sprintf("invalid binary object address: %v", err),
|
||||
)
|
||||
}
|
||||
|
||||
addrList = append(addrList, a)
|
||||
}
|
||||
|
||||
err := s.delObjHandler(addrList)
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
|
@ -47,6 +47,8 @@ type cfg struct {
|
|||
netMapSrc netmap.Source
|
||||
|
||||
nodeState NodeState
|
||||
|
||||
delObjHandler DeletedObjectHandler
|
||||
}
|
||||
|
||||
func defaultCfg() *cfg {
|
||||
|
@ -103,3 +105,11 @@ func WithNodeState(state NodeState) Option {
|
|||
c.nodeState = state
|
||||
}
|
||||
}
|
||||
|
||||
// WithDeletedObjectHandler returns option to function
|
||||
// which is called on the objects being deleted.
|
||||
func WithDeletedObjectHandler(h DeletedObjectHandler) Option {
|
||||
return func(c *cfg) {
|
||||
c.delObjHandler = h
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue