From 6813f406655c9843afcb414d90a2cb80c88768cc Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Tue, 24 Nov 2020 16:40:50 +0300 Subject: [PATCH] [#211] blobstor: Refactor GetBig parameters and result Signed-off-by: Leonard Lyubich --- pkg/local_object_storage/blobstor/get_big.go | 24 +++----------- pkg/local_object_storage/blobstor/util.go | 33 ++++++++++++++++++++ pkg/local_object_storage/shard/get.go | 10 +++--- 3 files changed, 44 insertions(+), 23 deletions(-) create mode 100644 pkg/local_object_storage/blobstor/util.go diff --git a/pkg/local_object_storage/blobstor/get_big.go b/pkg/local_object_storage/blobstor/get_big.go index 91dc254c..1e5512b4 100644 --- a/pkg/local_object_storage/blobstor/get_big.go +++ b/pkg/local_object_storage/blobstor/get_big.go @@ -11,33 +11,17 @@ import ( // GetBigPrm groups the parameters of GetBig operation. type GetBigPrm struct { - addr *objectSDK.Address + address } // GetBigRes groups resulting values of GetBig operation. type GetBigRes struct { - obj *object.Object + roObject } // ErrObjectNotFound is returns on read operations requested on a missing object. var ErrObjectNotFound = errors.New("object not found") -// WithAddress is a GetBig option to set the address of the requested object. -// -// Option is required. -func (p *GetBigPrm) WithAddress(addr *objectSDK.Address) *GetBigPrm { - if p != nil { - p.addr = addr - } - - return p -} - -// Object returns the requested object. -func (r *GetBigRes) Object() *object.Object { - return r.obj -} - // GetBig reads the object from shallow dir of BLOB storage by address. // // Returns any error encountered that @@ -68,7 +52,9 @@ func (b *BlobStor) GetBig(prm *GetBigPrm) (*GetBigRes, error) { } return &GetBigRes{ - obj: obj, + roObject: roObject{ + obj: obj, + }, }, nil } diff --git a/pkg/local_object_storage/blobstor/util.go b/pkg/local_object_storage/blobstor/util.go new file mode 100644 index 00000000..507973a2 --- /dev/null +++ b/pkg/local_object_storage/blobstor/util.go @@ -0,0 +1,33 @@ +package blobstor + +import ( + objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" + "github.com/nspcc-dev/neofs-node/pkg/core/object" +) + +type address struct { + addr *objectSDK.Address +} + +// SetAddress sets the address of the requested object. +func (a *address) SetAddress(addr *objectSDK.Address) { + a.addr = addr +} + +type roObject struct { + obj *object.Object +} + +// Object returns the object. +func (o roObject) Object() *object.Object { + return o.obj +} + +type rwObject struct { + roObject +} + +// SetObject sets the object. +func (o *rwObject) SetObject(obj *object.Object) { + o.obj = obj +} diff --git a/pkg/local_object_storage/shard/get.go b/pkg/local_object_storage/shard/get.go index fe72d43d..d30c3826 100644 --- a/pkg/local_object_storage/shard/get.go +++ b/pkg/local_object_storage/shard/get.go @@ -77,10 +77,12 @@ func (s *Shard) Get(prm *GetPrm) (*GetRes, error) { if prm.ln < 0 { // try to read from WriteCache // TODO: implement - res, err := s.blobStor.GetBig( - new(blobstor.GetBigPrm). - WithAddress(prm.addr), - ) + + // form GetBig parameters + getBigPrm := new(blobstor.GetBigPrm) + getBigPrm.SetAddress(prm.addr) + + res, err := s.blobStor.GetBig(getBigPrm) if err != nil { if errors.Is(err, blobstor.ErrObjectNotFound) { err = ErrObjectNotFound