From b0c7b7851aab8e7ddfd474952eb94b632c0aa1e9 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Mon, 23 May 2022 17:15:16 +0300 Subject: [PATCH] [#1418] blobstor: Do not use pointers as parameters Signed-off-by: Pavel Karpy --- pkg/local_object_storage/blobovnicza/get.go | 2 +- .../blobstor/blobovnicza.go | 18 +++++++++++------- pkg/local_object_storage/shard/put.go | 1 - 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/pkg/local_object_storage/blobovnicza/get.go b/pkg/local_object_storage/blobovnicza/get.go index 406f98a8..66cc41f7 100644 --- a/pkg/local_object_storage/blobovnicza/get.go +++ b/pkg/local_object_storage/blobovnicza/get.go @@ -24,7 +24,7 @@ func (p *GetPrm) SetAddress(addr oid.Address) { } // Object returns binary representation of the requested object. -func (p *GetRes) Object() []byte { +func (p GetRes) Object() []byte { return p.obj } diff --git a/pkg/local_object_storage/blobstor/blobovnicza.go b/pkg/local_object_storage/blobstor/blobovnicza.go index d02e715a..91a7fdd9 100644 --- a/pkg/local_object_storage/blobstor/blobovnicza.go +++ b/pkg/local_object_storage/blobstor/blobovnicza.go @@ -212,7 +212,7 @@ func (b *blobovniczas) get(prm GetSmallPrm) (res *GetSmallRes, err error) { if prm.blobovniczaID != nil { blz, err := b.openBlobovnicza(prm.blobovniczaID.String()) if err != nil { - return nil, err + return res, err } return b.getObject(blz, bPrm) @@ -245,7 +245,7 @@ func (b *blobovniczas) get(prm GetSmallPrm) (res *GetSmallRes, err error) { // not found in any blobovnicza var errNotFound apistatus.ObjectNotFound - return nil, errNotFound + return res, errNotFound } return @@ -262,13 +262,14 @@ func (b *blobovniczas) delete(prm DeleteSmallPrm) (res *DeleteSmallRes, err erro if prm.blobovniczaID != nil { blz, err := b.openBlobovnicza(prm.blobovniczaID.String()) if err != nil { - return nil, err + return res, err } return b.deleteObject(blz, bPrm, prm) } activeCache := make(map[string]struct{}) + objectFound := false err = b.iterateSortedLeaves(&prm.addr, func(p string) (bool, error) { dirPath := filepath.Dir(p) @@ -289,14 +290,14 @@ func (b *blobovniczas) delete(prm DeleteSmallPrm) (res *DeleteSmallRes, err erro activeCache[dirPath] = struct{}{} if err == nil { - res = new(DeleteSmallRes) + objectFound = true } // abort iterator if found, otherwise process all blobovniczas return err == nil, nil }) - if err == nil && res == nil { + if err == nil && !objectFound { // not found in any blobovnicza var errNotFound apistatus.ObjectNotFound @@ -321,6 +322,7 @@ func (b *blobovniczas) getRange(prm GetRangeSmallPrm) (res *GetRangeSmallRes, er } activeCache := make(map[string]struct{}) + objectFound := false err = b.iterateSortedLeaves(&prm.addr, func(p string) (bool, error) { dirPath := filepath.Dir(p) @@ -343,11 +345,13 @@ func (b *blobovniczas) getRange(prm GetRangeSmallPrm) (res *GetRangeSmallRes, er activeCache[dirPath] = struct{}{} + objectFound = err == nil + // abort iterator if found, otherwise process all blobovniczas return err == nil, nil }) - if err == nil && res == nil { + if err == nil && !objectFound { // not found in any blobovnicza var errNotFound apistatus.ObjectNotFound @@ -566,7 +570,7 @@ func (b *blobovniczas) deleteObject(blz *blobovnicza.Blobovnicza, prm blobovnicz zap.Stringer("blobovnicza ID", dp.blobovniczaID), ) - return new(DeleteSmallRes), nil + return nil, nil } // reads object from blobovnicza and returns GetSmallRes. diff --git a/pkg/local_object_storage/shard/put.go b/pkg/local_object_storage/shard/put.go index 36dc7a3a..a89b5e03 100644 --- a/pkg/local_object_storage/shard/put.go +++ b/pkg/local_object_storage/shard/put.go @@ -55,7 +55,6 @@ func (s *Shard) Put(prm PutPrm) (*PutRes, error) { res *blobstor.PutRes ) - // res == nil if there is no writeCache or writeCache.Put has been failed if res, err = s.blobStor.Put(putPrm); err != nil { return nil, fmt.Errorf("could not put object to BLOB storage: %w", err) }