forked from TrueCloudLab/frostfs-node
Add Inner Ring code
This commit is contained in:
parent
dadfd90dcd
commit
b7b5079934
400 changed files with 11420 additions and 8690 deletions
61
pkg/core/object/storage/storage.go
Normal file
61
pkg/core/object/storage/storage.go
Normal file
|
@ -0,0 +1,61 @@
|
|||
package storage
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
||||
)
|
||||
|
||||
// Object represents the NeoFS Object.
|
||||
//
|
||||
// It is a type alias of
|
||||
// github.com/nspcc-dev/neofs-node/pkg/core/object.Object.
|
||||
type Object = object.Object
|
||||
|
||||
// Address represents the address of
|
||||
// NeoFS Object.
|
||||
//
|
||||
// It is a type alias of
|
||||
// github.com/nspcc-dev/neofs-node/pkg/core/object.Address.
|
||||
type Address = object.Address
|
||||
|
||||
// Storage is an interface that wraps
|
||||
// basic object storage methods.
|
||||
type Storage interface {
|
||||
// Put saves pointed object to the underlying storage.
|
||||
// It returns object address for reference and any error
|
||||
// encountered that caused the saving to interrupt.
|
||||
//
|
||||
// Put must return object.ErrNilObject on nil-pointer.
|
||||
//
|
||||
// Implementations must not modify the object through the pointer (even temporarily).
|
||||
// Implementations must not retain the object pointer.
|
||||
//
|
||||
// Object rewriting behavior is dictated by implementation.
|
||||
Put(*Object) (*Address, error)
|
||||
|
||||
// Get reads the object from the storage by address.
|
||||
// It returns the pointer to requested object and any error encountered.
|
||||
//
|
||||
// Get must return exactly one non-nil value.
|
||||
// Get must return ErrNotFound if the object is not in storage.
|
||||
//
|
||||
// Implementations must not retain the object pointer and modify
|
||||
// the object through it.
|
||||
Get(Address) (*Object, error)
|
||||
|
||||
// Delete removes the object from the storage.
|
||||
// It returns any error encountered that caused the deletion to interrupt.
|
||||
//
|
||||
// Delete must return nil if object was successfully deleted.
|
||||
//
|
||||
// Behavior when deleting a nonexistent object is dictated by implementation.
|
||||
Delete(Address) error
|
||||
}
|
||||
|
||||
// ErrNotFound is the error returned when object was not found in storage.
|
||||
var ErrNotFound = errors.New("object not found")
|
||||
|
||||
// ErrNilStorage is the error returned by functions that
|
||||
// expect a non-nil object storage implementation, but received nil.
|
||||
var ErrNilStorage = errors.New("object storage is nil")
|
88
pkg/core/object/storage/test/storage.go
Normal file
88
pkg/core/object/storage/test/storage.go
Normal file
|
@ -0,0 +1,88 @@
|
|||
package test
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/core/object/storage"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
type testStorage struct {
|
||||
*sync.RWMutex
|
||||
|
||||
items map[storage.Address]*storage.Object
|
||||
}
|
||||
|
||||
func (s *testStorage) Put(o *storage.Object) (*storage.Address, error) {
|
||||
if o == nil {
|
||||
return nil, object.ErrNilObject
|
||||
}
|
||||
|
||||
a := object.AddressFromObject(o)
|
||||
|
||||
s.Lock()
|
||||
s.items[*a] = o
|
||||
s.Unlock()
|
||||
|
||||
return a, nil
|
||||
}
|
||||
|
||||
func (s *testStorage) Get(a storage.Address) (*storage.Object, error) {
|
||||
s.RLock()
|
||||
o, ok := s.items[a]
|
||||
s.RUnlock()
|
||||
|
||||
if !ok {
|
||||
return nil, storage.ErrNotFound
|
||||
}
|
||||
|
||||
return o, nil
|
||||
}
|
||||
|
||||
func (s *testStorage) Delete(a storage.Address) error {
|
||||
s.Lock()
|
||||
delete(s.items, a)
|
||||
s.Unlock()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// New creates new container storage
|
||||
// that stores containers in go-builtin map.
|
||||
func New() storage.Storage {
|
||||
return &testStorage{
|
||||
RWMutex: new(sync.RWMutex),
|
||||
items: make(map[storage.Address]*storage.Object),
|
||||
}
|
||||
}
|
||||
|
||||
// Storage conducts testing of object
|
||||
// storage for interface specification.
|
||||
//
|
||||
// Storage must be empty.
|
||||
func Storage(t *testing.T, s storage.Storage) {
|
||||
_, err := s.Put(nil)
|
||||
require.True(t, errors.Is(err, object.ErrNilObject))
|
||||
|
||||
a := new(object.Address)
|
||||
_, err = s.Get(*a)
|
||||
require.True(t, errors.Is(err, storage.ErrNotFound))
|
||||
|
||||
o := new(object.Object)
|
||||
o.SetID(object.ID{1, 2, 3})
|
||||
|
||||
a, err = s.Put(o)
|
||||
require.NoError(t, err)
|
||||
|
||||
o2, err := s.Get(*a)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, o, o2)
|
||||
|
||||
require.NoError(t, s.Delete(*a))
|
||||
_, err = s.Get(*a)
|
||||
require.True(t, errors.Is(err, storage.ErrNotFound))
|
||||
}
|
11
pkg/core/object/storage/test/storage_test.go
Normal file
11
pkg/core/object/storage/test/storage_test.go
Normal file
|
@ -0,0 +1,11 @@
|
|||
package test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNewStorage(t *testing.T) {
|
||||
s := New()
|
||||
|
||||
Storage(t, s)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue