[#1243] node/object: Hide engine behind interface

Do not use engine as explicit dependency in the put service. This allows
wrapping storage engine.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2022-03-15 22:40:31 +03:00 committed by Alex Vanin
parent a4a29f3442
commit 16543a1904
2 changed files with 12 additions and 6 deletions

View file

@ -3,13 +3,20 @@ package putsvc
import (
"fmt"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine"
"github.com/nspcc-dev/neofs-node/pkg/services/object_manager/transformer"
"github.com/nspcc-dev/neofs-sdk-go/object"
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
)
// ObjectStorage is an object storage interface.
type ObjectStorage interface {
// Put must save passed object
// and return any appeared error.
Put(o *objectSDK.Object) error
}
type localTarget struct {
storage *engine.StorageEngine
storage ObjectStorage
obj *object.Object
@ -31,7 +38,7 @@ func (t *localTarget) Write(p []byte) (n int, err error) {
}
func (t *localTarget) Close() (*transformer.AccessIdentifiers, error) {
if err := engine.Put(t.storage, t.obj); err != nil {
if err := t.storage.Put(t.obj); err != nil {
return nil, fmt.Errorf("(%T) could not put object to local storage: %w", t, err)
}

View file

@ -7,7 +7,6 @@ import (
"github.com/nspcc-dev/neofs-node/pkg/core/container"
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
"github.com/nspcc-dev/neofs-node/pkg/core/object"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine"
objutil "github.com/nspcc-dev/neofs-node/pkg/services/object/util"
"github.com/nspcc-dev/neofs-node/pkg/util"
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
@ -37,7 +36,7 @@ type cfg struct {
maxSizeSrc MaxSizeSource
localStore *engine.StorageEngine
localStore ObjectStorage
cnrSrc container.Source
@ -99,7 +98,7 @@ func WithMaxSizeSource(v MaxSizeSource) Option {
}
}
func WithLocalStorage(v *engine.StorageEngine) Option {
func WithObjectStorage(v ObjectStorage) Option {
return func(c *cfg) {
c.localStore = v
}