diff --git a/pkg/local_object_storage/engine/select.go b/pkg/local_object_storage/engine/select.go index 50f1cb5b..3801ff05 100644 --- a/pkg/local_object_storage/engine/select.go +++ b/pkg/local_object_storage/engine/select.go @@ -65,6 +65,44 @@ func (e *StorageEngine) Select(prm *SelectPrm) (*SelectRes, error) { }, nil } +// List returns `limit` available physically storage object addresses in engine. +// If limit is zero, then returns all available object addresses. +func (e *StorageEngine) List(limit uint64) (*SelectRes, error) { + addrList := make([]*object.Address, limit) + uniqueMap := make(map[string]struct{}) + ln := uint64(0) + + // consider iterating over shuffled shards + e.iterateOverUnsortedShards(func(sh *shard.Shard) (stop bool) { + res, err := sh.List() // consider limit result of shard iterator + if err != nil { + // TODO: smth wrong with shard, need to be processed + e.log.Warn("could not select objects from shard", + zap.Stringer("shard", sh.ID()), + zap.String("error", err.Error()), + ) + } else { + for _, addr := range res.AddressList() { // save only unique values + if _, ok := uniqueMap[addr.String()]; !ok { + uniqueMap[addr.String()] = struct{}{} + addrList = append(addrList, addr) + + ln++ + if limit > 0 && ln >= limit { + return true + } + } + } + } + + return false + }) + + return &SelectRes{ + addrList: addrList, + }, nil +} + // Select selects objects from local storage using provided filters. func Select(storage *StorageEngine, fs object.SearchFilters) ([]*object.Address, error) { res, err := storage.Select(new(SelectPrm). @@ -77,7 +115,13 @@ func Select(storage *StorageEngine, fs object.SearchFilters) ([]*object.Address, return res.AddressList(), nil } -// SelectAll selects all objects from local storage. -func SelectAll(storage *StorageEngine) ([]*object.Address, error) { - return Select(storage, object.SearchFilters{}) +// List returns `limit` available physically storage object addresses in +// engine. If limit is zero, then returns all available object addresses. +func List(storage *StorageEngine, limit uint64) ([]*object.Address, error) { + res, err := storage.List(limit) + if err != nil { + return nil, err + } + + return res.AddressList(), nil }