From f470022594b7a8d7f35a56ef13fcf2ba29e61e9b Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Tue, 1 Dec 2020 13:54:29 +0300 Subject: [PATCH] [#222] Update Select method in storage engine Signed-off-by: Alex Vanin --- pkg/local_object_storage/engine/select.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/local_object_storage/engine/select.go b/pkg/local_object_storage/engine/select.go index 0272a637c..50f1cb5b3 100644 --- a/pkg/local_object_storage/engine/select.go +++ b/pkg/local_object_storage/engine/select.go @@ -35,11 +35,12 @@ func (r *SelectRes) AddressList() []*object.Address { // Returns any error encountered that did not allow to completely select the objects. func (e *StorageEngine) Select(prm *SelectPrm) (*SelectRes, error) { addrList := make([]*object.Address, 0) + uniqueMap := make(map[string]struct{}) shPrm := new(shard.SelectPrm). WithFilters(prm.filters) - e.iterateOverSortedShards(nil, func(_ int, sh *shard.Shard) (stop bool) { + e.iterateOverUnsortedShards(func(sh *shard.Shard) (stop bool) { res, err := sh.Select(shPrm) if err != nil { // TODO: smth wrong with shard, need to be processed @@ -48,7 +49,12 @@ func (e *StorageEngine) Select(prm *SelectPrm) (*SelectRes, error) { zap.String("error", err.Error()), ) } else { - addrList = append(addrList, res.AddressList()...) + for _, addr := range res.AddressList() { // save only unique values + if _, ok := uniqueMap[addr.String()]; !ok { + uniqueMap[addr.String()] = struct{}{} + addrList = append(addrList, addr) + } + } } return false