diff --git a/pkg/local_object_storage/shard/delete.go b/pkg/local_object_storage/shard/delete.go new file mode 100644 index 00000000..c1a81af6 --- /dev/null +++ b/pkg/local_object_storage/shard/delete.go @@ -0,0 +1,37 @@ +package shard + +import ( + objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" +) + +// DeletePrm groups the parameters of Delete operation. +type DeletePrm struct { + addr *objectSDK.Address +} + +// DeleteRes groups resulting values of Delete operation. +type DeleteRes struct{} + +// WithAddress is a Delete option to set the address of the object to delete. +// +// Option is required. +func (p *DeletePrm) WithAddress(addr *objectSDK.Address) *DeletePrm { + if p != nil { + p.addr = addr + } + + return p +} + +// Delete marks object to delete from shard. +// +// Returns any error encountered that did not allow to completely +// mark the object to delete. +func (s *Shard) Delete(prm *DeletePrm) (*DeleteRes, error) { + s.mtx.Lock() + defer s.mtx.Unlock() + + // FIXME: implement me + + return nil, nil +} diff --git a/pkg/local_object_storage/shard/exists.go b/pkg/local_object_storage/shard/exists.go new file mode 100644 index 00000000..02d93b72 --- /dev/null +++ b/pkg/local_object_storage/shard/exists.go @@ -0,0 +1,43 @@ +package shard + +import ( + "github.com/nspcc-dev/neofs-api-go/pkg/object" +) + +// ExistsPrm groups the parameters of Exists operation. +type ExistsPrm struct { + addr *object.Address +} + +// ExistsRes groups resulting values of Exists operation. +type ExistsRes struct { + ex bool +} + +// WithAddress is an Exists option to set object checked for existence. +func (p *ExistsPrm) WithAddress(addr *object.Address) *ExistsPrm { + if p != nil { + p.addr = addr + } + + return p +} + +// Exists returns the fact that the object is in the shard. +func (p *ExistsRes) Exists() bool { + return p.ex +} + +// Exists checks if object is presented in shard. +// +// Returns any error encountered that does not allow to +// unambiguously determine the presence of an object. +func (s *Shard) Exists(prm *ExistsPrm) (*ExistsRes, error) { + s.mtx.RLock() + defer s.mtx.RUnlock() + + // FIXME: implement me + return &ExistsRes{ + ex: false, + }, nil +} diff --git a/pkg/local_object_storage/shard/get.go b/pkg/local_object_storage/shard/get.go new file mode 100644 index 00000000..feacf1cf --- /dev/null +++ b/pkg/local_object_storage/shard/get.go @@ -0,0 +1,79 @@ +package shard + +import ( + "errors" + + objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" + "github.com/nspcc-dev/neofs-node/pkg/core/object" +) + +// GetPrm groups the parameters of Get operation. +type GetPrm struct { + ln int64 // negative value for full range + + off uint64 + + addr *objectSDK.Address +} + +// GetRes groups resulting values of Get operation. +type GetRes struct { + obj *object.Object +} + +// ErrObjectNotFound is returns on read operations requested on a missing object. +var ErrObjectNotFound = errors.New("object not found") + +// WithAddress is a Get option to set the address of the requested object. +// +// Option is required. +func (p *GetPrm) WithAddress(addr *objectSDK.Address) *GetPrm { + if p != nil { + p.addr = addr + } + + return p +} + +// WithFullRange is a Get option to receive full object payload. +func (p *GetPrm) WithFullRange() *GetPrm { + if p != nil { + p.ln = -1 + } + + return p +} + +// WithRange is a Get option to set range of requested payload data. +// +// Calling with negative length is equivalent +// to getting the full payload range. +func (p *GetPrm) WithRange(off uint64, ln int64) *GetPrm { + if p != nil { + p.off, p.ln = off, ln + } + + return p +} + +// Object returns the requested object part. +// +// Instance payload contains the requested range of the original object. +func (r *GetRes) Object() *object.Object { + return r.obj +} + +// Get reads part of an object from shard. +// +// Returns any error encountered that +// did not allow to completely read the object part. +// +// Returns ErrObjectNotFound if requested object is missing in shard. +func (s *Shard) Get(prm *GetPrm) (*GetRes, error) { + s.mtx.RLock() + defer s.mtx.RUnlock() + + // FIXME: implement me + + return nil, nil +} diff --git a/pkg/local_object_storage/shard/id.go b/pkg/local_object_storage/shard/id.go new file mode 100644 index 00000000..01e5e93a --- /dev/null +++ b/pkg/local_object_storage/shard/id.go @@ -0,0 +1,21 @@ +package shard + +// ID represents Shard identifier. +// +// Each shard should have the unique ID within +// a single instance of local storage. +type ID []byte + +// NewIDFromBytes constructs ID from byte slice. +func NewIDFromBytes(v []byte) *ID { + return (*ID)(&v) +} + +func (id ID) String() string { + return string(id) +} + +// ID returns Shard identifier. +func (s *Shard) ID() *ID { + return s.id +} diff --git a/pkg/local_object_storage/shard/put.go b/pkg/local_object_storage/shard/put.go new file mode 100644 index 00000000..0c726c86 --- /dev/null +++ b/pkg/local_object_storage/shard/put.go @@ -0,0 +1,35 @@ +package shard + +import ( + "github.com/nspcc-dev/neofs-node/pkg/core/object" +) + +// PutPrm groups the parameters of Put operation. +type PutPrm struct { + obj *object.Object +} + +// PutRes groups resulting values of Put operation. +type PutRes struct{} + +// WithObject is a Put option to set object to save. +func (p *PutPrm) WithObject(obj *object.Object) *PutPrm { + if p != nil { + p.obj = obj + } + + return p +} + +// Put saves the object in shard. +// +// Returns any error encountered that +// did not allow to completely save the object. +func (s *Shard) Put(prm *PutPrm) (*PutRes, error) { + s.mtx.Lock() + defer s.mtx.Unlock() + + // FIXME: implement me + + return nil, nil +} diff --git a/pkg/local_object_storage/shard/select.go b/pkg/local_object_storage/shard/select.go new file mode 100644 index 00000000..be17180a --- /dev/null +++ b/pkg/local_object_storage/shard/select.go @@ -0,0 +1,42 @@ +package shard + +import ( + objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" +) + +// SelectPrm groups the parameters of Select operation. +type SelectPrm struct { + filters objectSDK.SearchFilters +} + +// SelectRes groups resulting values of Select operation. +type SelectRes struct { + addrList []*objectSDK.Address +} + +// WithFilters is a Select option to set the object filters. +func (p *SelectPrm) WithFilters(fs objectSDK.SearchFilters) *SelectPrm { + if p != nil { + p.filters = fs + } + + return p +} + +// AddressList returns list of addresses of the selected objects. +func (r *SelectRes) AddressList() []*objectSDK.Address { + return r.addrList +} + +// Select selects the objects from shard that match select parameters. +// +// Returns any error encountered that +// did not allow to completely select the objects. +func (s *Shard) Select(prm *SelectPrm) (*SelectRes, error) { + s.mtx.RLock() + defer s.mtx.RUnlock() + + // FIXME: implement me + + return nil, nil +} diff --git a/pkg/local_object_storage/shard/shard.go b/pkg/local_object_storage/shard/shard.go new file mode 100644 index 00000000..94eb7f08 --- /dev/null +++ b/pkg/local_object_storage/shard/shard.go @@ -0,0 +1,46 @@ +package shard + +import ( + "sync" +) + +// Shard represents single shard of NeoFS Local Storage Engine. +type Shard struct { + *cfg + + mtx *sync.RWMutex + + weight WeightValues +} + +// Option represents Shard's constructor option. +type Option func(*cfg) + +type cfg struct { + id *ID +} + +func defaultCfg() *cfg { + return new(cfg) +} + +// New creates, initializes and returns new Shard instance. +func New(opts ...Option) *Shard { + c := defaultCfg() + + for i := range opts { + opts[i](c) + } + + return &Shard{ + cfg: c, + mtx: new(sync.RWMutex), + } +} + +// WithID returns option to set shard identifier. +func WithID(id *ID) Option { + return func(c *cfg) { + c.id = id + } +} diff --git a/pkg/local_object_storage/shard/weight.go b/pkg/local_object_storage/shard/weight.go new file mode 100644 index 00000000..90bb8402 --- /dev/null +++ b/pkg/local_object_storage/shard/weight.go @@ -0,0 +1,12 @@ +package shard + +// WeightValues groups values of Shard weight parameters. +type WeightValues struct { + // Amount of free disk space. Measured in kilobytes. + FreeSpace uint64 +} + +// WeightValues returns current weight values of the Shard. +func (s *Shard) WeightValues() WeightValues { + return s.weight +}