From 24e9e3f3bf398c183347a82eefa387dd491bbe90 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Tue, 18 Oct 2022 15:49:40 +0300 Subject: [PATCH] [#1902] engine, shard: Implement `TreeList` method Signed-off-by: Pavel Karpy --- pkg/local_object_storage/engine/tree.go | 22 +++++++++++++++++++-- pkg/local_object_storage/pilorama/forest.go | 2 +- pkg/local_object_storage/shard/tree.go | 6 ++++-- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/pkg/local_object_storage/engine/tree.go b/pkg/local_object_storage/engine/tree.go index a62809d225..90fd508869 100644 --- a/pkg/local_object_storage/engine/tree.go +++ b/pkg/local_object_storage/engine/tree.go @@ -183,6 +183,24 @@ func (e *StorageEngine) TreeDrop(cid cidSDK.ID, treeID string) error { // TreeList implements the pilorama.Forest interface. func (e *StorageEngine) TreeList(cid cidSDK.ID) ([]string, error) { - //TODO implement me - panic("implement me") + var ids []string + var err error + + for _, sh := range e.sortShardsByWeight(cid) { + ids, err = sh.TreeList(cid) + if err != nil { + if errors.Is(err, shard.ErrPiloramaDisabled) || errors.Is(err, shard.ErrReadOnlyMode) { + return nil, err + } + + e.reportShardError(sh, "can't perform `TreeList`", err, + zap.Stringer("cid", cid)) + + continue + } + + return ids, nil + } + + return ids, err } diff --git a/pkg/local_object_storage/pilorama/forest.go b/pkg/local_object_storage/pilorama/forest.go index 79aaae91ac..e4d4f5f24c 100644 --- a/pkg/local_object_storage/pilorama/forest.go +++ b/pkg/local_object_storage/pilorama/forest.go @@ -193,7 +193,7 @@ func (f *memoryForest) TreeDrop(cid cidSDK.ID, treeID string) error { return nil } -// TreeGetTrees implements the pilorama.Forest interface. +// TreeList implements the pilorama.Forest interface. func (f *memoryForest) TreeList(cid cidSDK.ID) ([]string, error) { var res []string cidStr := cid.EncodeToString() diff --git a/pkg/local_object_storage/shard/tree.go b/pkg/local_object_storage/shard/tree.go index b57a1a314f..9a8c4f2d83 100644 --- a/pkg/local_object_storage/shard/tree.go +++ b/pkg/local_object_storage/shard/tree.go @@ -87,6 +87,8 @@ func (s *Shard) TreeDrop(cid cidSDK.ID, treeID string) error { // TreeList implements the pilorama.Forest interface. func (s *Shard) TreeList(cid cidSDK.ID) ([]string, error) { - //TODO implement me - panic("implement me") + if s.pilorama == nil { + return nil, ErrPiloramaDisabled + } + return s.pilorama.TreeList(cid) }