Skip to content

Commit

Permalink
[#1460] engine: Do not use pointers as the results
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
  • Loading branch information
carpawell committed Jun 6, 2022
1 parent 7b6363f commit 08bf8a6
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 49 deletions.
14 changes: 6 additions & 8 deletions pkg/local_object_storage/engine/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (r ListContainersRes) Containers() []cid.ID {
// ContainerSize returns the sum of estimation container sizes among all shards.
//
// Returns an error if executions are blocked (see BlockExecution).
func (e *StorageEngine) ContainerSize(prm ContainerSizePrm) (res *ContainerSizeRes, err error) {
func (e *StorageEngine) ContainerSize(prm ContainerSizePrm) (res ContainerSizeRes, err error) {
err = e.execIfNotBlocked(func() error {
res, err = e.containerSize(prm)
return err
Expand All @@ -65,13 +65,11 @@ func ContainerSize(e *StorageEngine, id cid.ID) (uint64, error) {
return res.Size(), nil
}

func (e *StorageEngine) containerSize(prm ContainerSizePrm) (*ContainerSizeRes, error) {
func (e *StorageEngine) containerSize(prm ContainerSizePrm) (res ContainerSizeRes, err error) {
if e.metrics != nil {
defer elapsed(e.metrics.AddEstimateContainerSizeDuration)()
}

res := new(ContainerSizeRes)

e.iterateOverUnsortedShards(func(sh hashedShard) (stop bool) {
size, err := shard.ContainerSize(sh.Shard, prm.cnr)
if err != nil {
Expand All @@ -86,13 +84,13 @@ func (e *StorageEngine) containerSize(prm ContainerSizePrm) (*ContainerSizeRes,
return false
})

return res, nil
return
}

// ListContainers returns a unique container IDs presented in the engine objects.
//
// Returns an error if executions are blocked (see BlockExecution).
func (e *StorageEngine) ListContainers(_ ListContainersPrm) (res *ListContainersRes, err error) {
func (e *StorageEngine) ListContainers(_ ListContainersPrm) (res ListContainersRes, err error) {
err = e.execIfNotBlocked(func() error {
res, err = e.listContainers()
return err
Expand All @@ -113,7 +111,7 @@ func ListContainers(e *StorageEngine) ([]cid.ID, error) {
return res.Containers(), nil
}

func (e *StorageEngine) listContainers() (*ListContainersRes, error) {
func (e *StorageEngine) listContainers() (ListContainersRes, error) {
if e.metrics != nil {
defer elapsed(e.metrics.AddListContainersDuration)()
}
Expand Down Expand Up @@ -142,7 +140,7 @@ func (e *StorageEngine) listContainers() (*ListContainersRes, error) {
result = append(result, v)
}

return &ListContainersRes{
return ListContainersRes{
containers: result,
}, nil
}
8 changes: 4 additions & 4 deletions pkg/local_object_storage/engine/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (p *DeletePrm) WithAddresses(addr ...oid.Address) {
//
// Returns apistatus.ObjectLocked if at least one object is locked.
// In this case no object from the list is marked to be deleted.
func (e *StorageEngine) Delete(prm DeletePrm) (res *DeleteRes, err error) {
func (e *StorageEngine) Delete(prm DeletePrm) (res DeleteRes, err error) {
err = e.execIfNotBlocked(func() error {
res, err = e.delete(prm)
return err
Expand All @@ -40,7 +40,7 @@ func (e *StorageEngine) Delete(prm DeletePrm) (res *DeleteRes, err error) {
return
}

func (e *StorageEngine) delete(prm DeletePrm) (*DeleteRes, error) {
func (e *StorageEngine) delete(prm DeletePrm) (DeleteRes, error) {
if e.metrics != nil {
defer elapsed(e.metrics.AddDeleteDuration)()
}
Expand Down Expand Up @@ -80,8 +80,8 @@ func (e *StorageEngine) delete(prm DeletePrm) (*DeleteRes, error) {
}

if locked.is {
return nil, locked.err
return DeleteRes{}, locked.err
}

return nil, nil
return DeleteRes{}, nil
}
12 changes: 6 additions & 6 deletions pkg/local_object_storage/engine/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (r GetRes) Object() *objectSDK.Object {
// Returns an error of type apistatus.ObjectAlreadyRemoved if the object has been marked as removed.
//
// Returns an error if executions are blocked (see BlockExecution).
func (e *StorageEngine) Get(prm GetPrm) (res *GetRes, err error) {
func (e *StorageEngine) Get(prm GetPrm) (res GetRes, err error) {
err = e.execIfNotBlocked(func() error {
res, err = e.get(prm)
return err
Expand All @@ -53,7 +53,7 @@ func (e *StorageEngine) Get(prm GetPrm) (res *GetRes, err error) {
return
}

func (e *StorageEngine) get(prm GetPrm) (*GetRes, error) {
func (e *StorageEngine) get(prm GetPrm) (GetRes, error) {
if e.metrics != nil {
defer elapsed(e.metrics.AddGetDuration)()
}
Expand Down Expand Up @@ -118,12 +118,12 @@ func (e *StorageEngine) get(prm GetPrm) (*GetRes, error) {
})

if outSI != nil {
return nil, objectSDK.NewSplitInfoError(outSI)
return GetRes{}, objectSDK.NewSplitInfoError(outSI)
}

if obj == nil {
if shardWithMeta.Shard == nil || !shard.IsErrNotFound(outError) {
return nil, outError
return GetRes{}, outError
}

// If the object is not found but is present in metabase,
Expand All @@ -137,13 +137,13 @@ func (e *StorageEngine) get(prm GetPrm) (*GetRes, error) {
return err == nil
})
if obj == nil {
return nil, outError
return GetRes{}, outError
}
e.reportShardError(shardWithMeta, "meta info was present, but object is missing",
metaError, zap.Stringer("address", prm.addr))
}

return &GetRes{
return GetRes{
obj: obj,
}, nil
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/local_object_storage/engine/head.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (r HeadRes) Header() *objectSDK.Object {
// Returns an error of type apistatus.ObjectAlreadyRemoved if the requested object was inhumed.
//
// Returns an error if executions are blocked (see BlockExecution).
func (e *StorageEngine) Head(prm HeadPrm) (res *HeadRes, err error) {
func (e *StorageEngine) Head(prm HeadPrm) (res HeadRes, err error) {
err = e.execIfNotBlocked(func() error {
res, err = e.head(prm)
return err
Expand All @@ -64,7 +64,7 @@ func (e *StorageEngine) Head(prm HeadPrm) (res *HeadRes, err error) {
return
}

func (e *StorageEngine) head(prm HeadPrm) (*HeadRes, error) {
func (e *StorageEngine) head(prm HeadPrm) (HeadRes, error) {
if e.metrics != nil {
defer elapsed(e.metrics.AddHeadDuration)()
}
Expand Down Expand Up @@ -123,14 +123,14 @@ func (e *StorageEngine) head(prm HeadPrm) (*HeadRes, error) {
})

if outSI != nil {
return nil, objectSDK.NewSplitInfoError(outSI)
return HeadRes{}, objectSDK.NewSplitInfoError(outSI)
}

if head == nil {
return nil, outError
return HeadRes{}, outError
}

return &HeadRes{
return HeadRes{
head: head,
}, nil
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/local_object_storage/engine/inhume.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var errInhumeFailure = errors.New("inhume operation failed")
// if at least one object is locked.
//
// Returns an error if executions are blocked (see BlockExecution).
func (e *StorageEngine) Inhume(prm InhumePrm) (res *InhumeRes, err error) {
func (e *StorageEngine) Inhume(prm InhumePrm) (res InhumeRes, err error) {
err = e.execIfNotBlocked(func() error {
res, err = e.inhume(prm)
return err
Expand All @@ -60,7 +60,7 @@ func (e *StorageEngine) Inhume(prm InhumePrm) (res *InhumeRes, err error) {
return
}

func (e *StorageEngine) inhume(prm InhumePrm) (*InhumeRes, error) {
func (e *StorageEngine) inhume(prm InhumePrm) (InhumeRes, error) {
if e.metrics != nil {
defer elapsed(e.metrics.AddInhumeDuration)()
}
Expand All @@ -76,18 +76,18 @@ func (e *StorageEngine) inhume(prm InhumePrm) (*InhumeRes, error) {

switch e.inhumeAddr(prm.addrs[i], shPrm, true) {
case 1:
return nil, apistatus.ObjectLocked{}
return InhumeRes{}, apistatus.ObjectLocked{}
case 0:
switch e.inhumeAddr(prm.addrs[i], shPrm, false) {
case 1:
return nil, apistatus.ObjectLocked{}
return InhumeRes{}, apistatus.ObjectLocked{}
case 0:
return nil, errInhumeFailure
return InhumeRes{}, errInhumeFailure
}
}
}

return new(InhumeRes), nil
return InhumeRes{}, nil
}

// Returns:
Expand Down
8 changes: 4 additions & 4 deletions pkg/local_object_storage/engine/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (l ListWithCursorRes) Cursor() *Cursor {
//
// Returns ErrEndOfListing if there are no more objects to return or count
// parameter set to zero.
func (e *StorageEngine) ListWithCursor(prm ListWithCursorPrm) (*ListWithCursorRes, error) {
func (e *StorageEngine) ListWithCursor(prm ListWithCursorPrm) (ListWithCursorRes, error) {
result := make([]oid.Address, 0, prm.count)

// 1. Get available shards and sort them.
Expand All @@ -71,7 +71,7 @@ func (e *StorageEngine) ListWithCursor(prm ListWithCursorPrm) (*ListWithCursorRe
e.mtx.RUnlock()

if len(shardIDs) == 0 {
return nil, ErrEndOfListing
return ListWithCursorRes{}, ErrEndOfListing
}

sort.Slice(shardIDs, func(i, j int) bool {
Expand Down Expand Up @@ -119,10 +119,10 @@ func (e *StorageEngine) ListWithCursor(prm ListWithCursorPrm) (*ListWithCursorRe
}

if len(result) == 0 {
return nil, ErrEndOfListing
return ListWithCursorRes{}, ErrEndOfListing
}

return &ListWithCursorRes{
return ListWithCursorRes{
addrList: result,
cursor: cursor,
}, nil
Expand Down
8 changes: 4 additions & 4 deletions pkg/local_object_storage/engine/put.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (p *PutPrm) WithObject(obj *objectSDK.Object) {
// Returns an error if executions are blocked (see BlockExecution).
//
// Returns an error of type apistatus.ObjectAlreadyRemoved if the object has been marked as removed.
func (e *StorageEngine) Put(prm PutPrm) (res *PutRes, err error) {
func (e *StorageEngine) Put(prm PutPrm) (res PutRes, err error) {
err = e.execIfNotBlocked(func() error {
res, err = e.put(prm)
return err
Expand All @@ -45,7 +45,7 @@ func (e *StorageEngine) Put(prm PutPrm) (res *PutRes, err error) {
return
}

func (e *StorageEngine) put(prm PutPrm) (*PutRes, error) {
func (e *StorageEngine) put(prm PutPrm) (PutRes, error) {
if e.metrics != nil {
defer elapsed(e.metrics.AddPutDuration)()
}
Expand All @@ -56,7 +56,7 @@ func (e *StorageEngine) put(prm PutPrm) (*PutRes, error) {
// much slower on fast machines for 4 shards.
_, err := e.exists(addr)
if err != nil {
return nil, err
return PutRes{}, err
}

var existPrm shard.ExistsPrm
Expand Down Expand Up @@ -125,7 +125,7 @@ func (e *StorageEngine) put(prm PutPrm) (*PutRes, error) {
err = errPutShard
}

return nil, err
return PutRes{}, err
}

// Put writes provided object to local storage.
Expand Down
12 changes: 6 additions & 6 deletions pkg/local_object_storage/engine/range.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (r RngRes) Object() *objectSDK.Object {
// Returns ErrRangeOutOfBounds if the requested object range is out of bounds.
//
// Returns an error if executions are blocked (see BlockExecution).
func (e *StorageEngine) GetRange(prm RngPrm) (res *RngRes, err error) {
func (e *StorageEngine) GetRange(prm RngPrm) (res RngRes, err error) {
err = e.execIfNotBlocked(func() error {
res, err = e.getRange(prm)
return err
Expand All @@ -69,7 +69,7 @@ func (e *StorageEngine) GetRange(prm RngPrm) (res *RngRes, err error) {
return
}

func (e *StorageEngine) getRange(prm RngPrm) (*RngRes, error) {
func (e *StorageEngine) getRange(prm RngPrm) (RngRes, error) {
if e.metrics != nil {
defer elapsed(e.metrics.AddRangeDuration)()
}
Expand Down Expand Up @@ -137,12 +137,12 @@ func (e *StorageEngine) getRange(prm RngPrm) (*RngRes, error) {
})

if outSI != nil {
return nil, objectSDK.NewSplitInfoError(outSI)
return RngRes{}, objectSDK.NewSplitInfoError(outSI)
}

if obj == nil {
if shardWithMeta.Shard == nil || !shard.IsErrNotFound(outError) {
return nil, outError
return RngRes{}, outError
}

// If the object is not found but is present in metabase,
Expand All @@ -160,15 +160,15 @@ func (e *StorageEngine) getRange(prm RngPrm) (*RngRes, error) {
return err == nil
})
if obj == nil {
return nil, outError
return RngRes{}, outError
}
e.reportShardError(shardWithMeta, "meta info was present, but object is missing",
metaError,
zap.Stringer("address", prm.addr),
)
}

return &RngRes{
return RngRes{
obj: obj,
}, nil
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/local_object_storage/engine/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (r SelectRes) AddressList() []oid.Address {
// Returns any error encountered that did not allow to completely select the objects.
//
// Returns an error if executions are blocked (see BlockExecution).
func (e *StorageEngine) Select(prm SelectPrm) (res *SelectRes, err error) {
func (e *StorageEngine) Select(prm SelectPrm) (res SelectRes, err error) {
err = e.execIfNotBlocked(func() error {
res, err = e._select(prm)
return err
Expand All @@ -51,7 +51,7 @@ func (e *StorageEngine) Select(prm SelectPrm) (res *SelectRes, err error) {
return
}

func (e *StorageEngine) _select(prm SelectPrm) (*SelectRes, error) {
func (e *StorageEngine) _select(prm SelectPrm) (SelectRes, error) {
if e.metrics != nil {
defer elapsed(e.metrics.AddSearchDuration)()
}
Expand Down Expand Up @@ -82,7 +82,7 @@ func (e *StorageEngine) _select(prm SelectPrm) (*SelectRes, error) {
return false
})

return &SelectRes{
return SelectRes{
addrList: addrList,
}, outError
}
Expand All @@ -91,7 +91,7 @@ func (e *StorageEngine) _select(prm SelectPrm) (*SelectRes, error) {
// If limit is zero, then returns all available object addresses.
//
// Returns an error if executions are blocked (see BlockExecution).
func (e *StorageEngine) List(limit uint64) (res *SelectRes, err error) {
func (e *StorageEngine) List(limit uint64) (res SelectRes, err error) {
err = e.execIfNotBlocked(func() error {
res, err = e.list(limit)
return err
Expand All @@ -100,7 +100,7 @@ func (e *StorageEngine) List(limit uint64) (res *SelectRes, err error) {
return
}

func (e *StorageEngine) list(limit uint64) (*SelectRes, error) {
func (e *StorageEngine) list(limit uint64) (SelectRes, error) {
if e.metrics != nil {
defer elapsed(e.metrics.AddListObjectsDuration)()
}
Expand Down Expand Up @@ -131,7 +131,7 @@ func (e *StorageEngine) list(limit uint64) (*SelectRes, error) {
return false
})

return &SelectRes{
return SelectRes{
addrList: addrList,
}, nil
}
Expand Down

0 comments on commit 08bf8a6

Please sign in to comment.