forked from TrueCloudLab/frostfs-node
[#1318] service: Add tombstone checker service
The service fetches tombstones from the network via object service, every request is handled in the following order: 1. checks local LRU cache; 2. checks local storage engine; 3. tries to find object in the placement nodes. Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
2583f608e8
commit
e4cfeec449
3 changed files with 261 additions and 0 deletions
84
pkg/services/object_manager/tombstone/source/source.go
Normal file
84
pkg/services/object_manager/tombstone/source/source.go
Normal file
|
@ -0,0 +1,84 @@
|
|||
package tsourse
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
getsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/get"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/services/object/util"
|
||||
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
||||
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
||||
)
|
||||
|
||||
// Source represents wrapper over the object service that
|
||||
// allows checking if a tombstone is available in NeoFS
|
||||
// network.
|
||||
//
|
||||
// Must be created via NewSource function. `var` and `Source{}`
|
||||
// declarations leads to undefined behaviour and may lead
|
||||
// to panics.
|
||||
type Source struct {
|
||||
s *getsvc.Service
|
||||
}
|
||||
|
||||
// TombstoneSourcePrm groups required parameters for Source creation.
|
||||
type TombstoneSourcePrm struct {
|
||||
s *getsvc.Service
|
||||
}
|
||||
|
||||
// SetGetService sets object service.
|
||||
func (s *TombstoneSourcePrm) SetGetService(v *getsvc.Service) {
|
||||
s.s = v
|
||||
}
|
||||
|
||||
// NewSource creates, initialize and returns local tombstone Source.
|
||||
// The returned structure is ready to use.
|
||||
//
|
||||
// Panics if any of the provided options does not allow
|
||||
// constructing a valid tombstone local Source.
|
||||
func NewSource(p TombstoneSourcePrm) Source {
|
||||
if p.s == nil {
|
||||
panic("Tombstone source: nil object service")
|
||||
}
|
||||
|
||||
return Source{s: p.s}
|
||||
}
|
||||
|
||||
type headerWriter struct {
|
||||
o *objectSDK.Object
|
||||
}
|
||||
|
||||
func (h *headerWriter) WriteHeader(o *objectSDK.Object) error {
|
||||
h.o = o
|
||||
return nil
|
||||
}
|
||||
|
||||
// Tombstone checks if the engine stores tombstone.
|
||||
// Returns nil, nil if the tombstone has been removed
|
||||
// or marked for removal.
|
||||
func (s Source) Tombstone(ctx context.Context, a *addressSDK.Address, _ uint64) (*object.Object, error) {
|
||||
var hr headerWriter
|
||||
|
||||
var headPrm getsvc.HeadPrm
|
||||
headPrm.WithAddress(a)
|
||||
headPrm.SetHeaderWriter(&hr)
|
||||
headPrm.SetCommonParameters(&util.CommonPrm{}) //default values are ok for that operation
|
||||
|
||||
err := s.s.Head(ctx, headPrm)
|
||||
switch {
|
||||
case errors.As(err, new(apistatus.ObjectNotFound)) || errors.As(err, new(apistatus.ObjectAlreadyRemoved)):
|
||||
return nil, nil
|
||||
case err != nil:
|
||||
return nil, fmt.Errorf("could not get tombstone from the source: %w", err)
|
||||
default:
|
||||
}
|
||||
|
||||
if hr.o.Type() != objectSDK.TypeTombstone {
|
||||
return nil, fmt.Errorf("returned %s object is not a tombstone", a)
|
||||
}
|
||||
|
||||
return hr.o, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue