forked from TrueCloudLab/frostfs-node
[#947] tree: Add method to list all trees
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
80b581d499
commit
8e2a0611f4
5 changed files with 234 additions and 0 deletions
|
@ -63,6 +63,9 @@ type ForestStorage interface {
|
|||
SetMode(m mode.Mode) error
|
||||
SetParentID(id string)
|
||||
Forest
|
||||
|
||||
// TreeListTrees returns all pairs "containerID:treeID".
|
||||
TreeListTrees(ctx context.Context, prm TreeListTreesPrm) (*TreeListTreesResult, error)
|
||||
}
|
||||
|
||||
const (
|
||||
|
@ -85,3 +88,44 @@ var ErrInvalidCIDDescriptor = logicerr.New("cid descriptor is invalid")
|
|||
func (d CIDDescriptor) checkValid() bool {
|
||||
return 0 <= d.Position && d.Position < d.Size
|
||||
}
|
||||
|
||||
var treeListTreesBatchSizeDefault = 1000
|
||||
|
||||
type ContainerIDTreeID struct {
|
||||
CID cidSDK.ID
|
||||
TreeID string
|
||||
}
|
||||
|
||||
type TreeListTreesPrm struct {
|
||||
NextPageToken []byte
|
||||
// BatchSize is batch size to list trees. If not lower or equals zero, than treeListTreesBatchSizeDefault is used.
|
||||
BatchSize int
|
||||
}
|
||||
|
||||
type TreeListTreesResult struct {
|
||||
NextPageToken []byte
|
||||
Items []ContainerIDTreeID
|
||||
}
|
||||
|
||||
func TreeListAll(ctx context.Context, f ForestStorage) ([]ContainerIDTreeID, error) {
|
||||
return treeListAll(ctx, f, treeListTreesBatchSizeDefault)
|
||||
}
|
||||
|
||||
func treeListAll(ctx context.Context, f ForestStorage, batchSize int) ([]ContainerIDTreeID, error) {
|
||||
var prm TreeListTreesPrm
|
||||
var result []ContainerIDTreeID
|
||||
first := true
|
||||
|
||||
for len(prm.NextPageToken) > 0 || first {
|
||||
first = false
|
||||
|
||||
res, err := f.TreeListTrees(ctx, prm)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
prm.NextPageToken = res.NextPageToken
|
||||
result = append(result, res.Items...)
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue