From 3a37eda41070dc201c1d5d2f8a0d299f9d1a1955 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Thu, 3 Dec 2020 13:01:09 +0300 Subject: [PATCH] [#230] engine: Stop on first SplitInfoError in Get method Signed-off-by: Alex Vanin --- pkg/local_object_storage/engine/get.go | 17 ++++++++--------- pkg/local_object_storage/engine/head.go | 10 +++------- pkg/local_object_storage/engine/range.go | 10 +++------- 3 files changed, 14 insertions(+), 23 deletions(-) diff --git a/pkg/local_object_storage/engine/get.go b/pkg/local_object_storage/engine/get.go index 8bc69edeb..3b37a4a27 100644 --- a/pkg/local_object_storage/engine/get.go +++ b/pkg/local_object_storage/engine/get.go @@ -43,9 +43,10 @@ func (r *GetRes) Object() *object.Object { // Returns ErrNotFound if requested object is missing in local storage. func (e *StorageEngine) Get(prm *GetPrm) (*GetRes, error) { var ( - obj *object.Object + obj *object.Object + siErr *objectSDK.SplitInfoError - alreadyRemoved = false + outError = object.ErrNotFound ) shPrm := new(shard.GetPrm). @@ -57,8 +58,10 @@ func (e *StorageEngine) Get(prm *GetPrm) (*GetRes, error) { switch { case errors.Is(err, object.ErrNotFound): return false // ignore, go to next shard - case errors.Is(err, object.ErrAlreadyRemoved): - alreadyRemoved = true + case + errors.Is(err, object.ErrAlreadyRemoved), + errors.As(err, &siErr): + outError = err return true // stop, return it back default: @@ -79,11 +82,7 @@ func (e *StorageEngine) Get(prm *GetPrm) (*GetRes, error) { }) if obj == nil { - if alreadyRemoved { - return nil, object.ErrAlreadyRemoved - } - - return nil, object.ErrNotFound + return nil, outError } return &GetRes{ diff --git a/pkg/local_object_storage/engine/head.go b/pkg/local_object_storage/engine/head.go index e1b688218..1723df5e8 100644 --- a/pkg/local_object_storage/engine/head.go +++ b/pkg/local_object_storage/engine/head.go @@ -46,7 +46,7 @@ func (e *StorageEngine) Head(prm *HeadPrm) (*HeadRes, error) { var ( head *object.Object - alreadyRemoved = false + outError = object.ErrNotFound ) shPrm := new(shard.HeadPrm). @@ -59,7 +59,7 @@ func (e *StorageEngine) Head(prm *HeadPrm) (*HeadRes, error) { case errors.Is(err, object.ErrNotFound): return false // ignore, go to next shard case errors.Is(err, object.ErrAlreadyRemoved): - alreadyRemoved = true + outError = err return true // stop, return it back default: @@ -80,11 +80,7 @@ func (e *StorageEngine) Head(prm *HeadPrm) (*HeadRes, error) { }) if head == nil { - if alreadyRemoved { - return nil, object.ErrAlreadyRemoved - } - - return nil, object.ErrNotFound + return nil, outError } return &HeadRes{ diff --git a/pkg/local_object_storage/engine/range.go b/pkg/local_object_storage/engine/range.go index 1afb8b25d..f7ccdb67e 100644 --- a/pkg/local_object_storage/engine/range.go +++ b/pkg/local_object_storage/engine/range.go @@ -61,7 +61,7 @@ func (e *StorageEngine) GetRange(prm *RngPrm) (*RngRes, error) { var ( obj *object.Object - alreadyRemoved = false + outError = object.ErrNotFound ) shPrm := new(shard.RngPrm). @@ -75,7 +75,7 @@ func (e *StorageEngine) GetRange(prm *RngPrm) (*RngRes, error) { case errors.Is(err, object.ErrNotFound): return false // ignore, go to next shard case errors.Is(err, object.ErrAlreadyRemoved): - alreadyRemoved = true + outError = err return true // stop, return it back default: @@ -96,11 +96,7 @@ func (e *StorageEngine) GetRange(prm *RngPrm) (*RngRes, error) { }) if obj == nil { - if alreadyRemoved { - return nil, object.ErrAlreadyRemoved - } - - return nil, object.ErrNotFound + return nil, outError } return &RngRes{