[#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 9ca20ad80f
commit 724346a704
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 "git.frostfs.info/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

@ -51,7 +51,6 @@ type epochSource interface {
func (c *cfg) initDefault() {
c.log = &logger.Logger{Logger: zap.L()}
c.localStorage = new(storageEngineWrapper)
c.clientCache = new(clientCacheWrapper)
}
@ -79,7 +78,7 @@ func WithLogger(l *logger.Logger) Option {
// instance.
func WithLocalStorageEngine(e *engine.StorageEngine) Option {
return func(c *cfg) {
c.localStorage.(*storageEngineWrapper).engine = e
c.localStorage = (*storageEngineWrapper)(e)
}
}

View file

@ -28,9 +28,7 @@ type clientWrapper struct {
client coreclient.MultiAddressClient
}
type storageEngineWrapper struct {
engine *engine.StorageEngine
}
type storageEngineWrapper engine.StorageEngine
type partWriter struct {
ObjectWriter
@ -192,13 +190,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
}
@ -209,7 +208,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
}
@ -219,7 +218,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
}