[#6] services/object: Simplify storage wrappers

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2022-12-30 14:29:29 +03:00
parent 8b50b042c4
commit 7318b70ba7
5 changed files with 12 additions and 18 deletions

View file

@ -46,7 +46,7 @@ type headerSource struct {
}
func (c *cfg) initDefault() {
c.storage = new(localStorage)
c.storage = (*localStorage)(nil)
}
func NewMessageHeaderSource(opts ...Option) (eaclSDK.TypedHeaderSource, error) {

View file

@ -8,14 +8,12 @@ import (
oid "github.com/TrueCloudLab/frostfs-sdk-go/object/id"
)
type localStorage struct {
ls *engine.StorageEngine
}
type localStorage engine.StorageEngine
func (s *localStorage) Head(addr oid.Address) (*objectSDK.Object, error) {
if s.ls == nil {
if s == nil {
return nil, io.ErrUnexpectedEOF
}
return engine.Head(s.ls, addr)
return engine.Head((*engine.StorageEngine)(s), addr)
}

View file

@ -14,9 +14,7 @@ func WithObjectStorage(v ObjectStorage) Option {
func WithLocalObjectStorage(v *engine.StorageEngine) Option {
return func(c *cfg) {
c.storage = &localStorage{
ls: v,
}
c.storage = (*localStorage)(v)
}
}

View file

@ -53,7 +53,6 @@ type epochSource interface {
func (c *cfg) initDefault() {
c.log = &logger.Logger{Logger: zap.L()}
c.localStorage = new(storageEngineWrapper)
c.assembly = true
c.clientCache = new(clientCacheWrapper)
}
@ -89,7 +88,7 @@ func WithoutAssembly() Option {
// instance.
func WithLocalStorageEngine(e *engine.StorageEngine) Option {
return func(c *cfg) {
c.localStorage.(*storageEngineWrapper).engine = e
c.localStorage = (*storageEngineWrapper)(e)
}
}

View file

@ -27,9 +27,7 @@ type clientWrapper struct {
client coreclient.MultiAddressClient
}
type storageEngineWrapper struct {
engine *engine.StorageEngine
}
type storageEngineWrapper engine.StorageEngine
type partWriter struct {
ObjectWriter
@ -190,13 +188,14 @@ func (c *clientWrapper) get(exec *execCtx, key *ecdsa.PrivateKey) (*object.Objec
return res.Object(), nil
}
func (e *storageEngineWrapper) get(exec *execCtx) (*object.Object, error) {
func (w *storageEngineWrapper) get(exec *execCtx) (*object.Object, error) {
e := (*engine.StorageEngine)(w)
if exec.headOnly {
var headPrm engine.HeadPrm
headPrm.WithAddress(exec.prm.addr)
headPrm.WithRaw(exec.prm.raw)
r, err := e.engine.Head(headPrm)
r, err := e.Head(headPrm)
if err != nil {
return nil, err
}
@ -207,7 +206,7 @@ func (e *storageEngineWrapper) get(exec *execCtx) (*object.Object, error) {
getRange.WithAddress(exec.prm.addr)
getRange.WithPayloadRange(rng)
r, err := e.engine.GetRange(getRange)
r, err := e.GetRange(getRange)
if err != nil {
return nil, err
}
@ -217,7 +216,7 @@ func (e *storageEngineWrapper) get(exec *execCtx) (*object.Object, error) {
var getPrm engine.GetPrm
getPrm.WithAddress(exec.prm.addr)
r, err := e.engine.Get(getPrm)
r, err := e.Get(getPrm)
if err != nil {
return nil, err
}