From dc5a481f1786dfc95a720f71027fb9332b6fa6e2 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Fri, 22 Jan 2021 14:36:16 +0300 Subject: [PATCH] [#337] shard: Get container size estimation from metabase Signed-off-by: Alex Vanin --- pkg/local_object_storage/shard/container.go | 46 +++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 pkg/local_object_storage/shard/container.go diff --git a/pkg/local_object_storage/shard/container.go b/pkg/local_object_storage/shard/container.go new file mode 100644 index 000000000..3ec4d51ae --- /dev/null +++ b/pkg/local_object_storage/shard/container.go @@ -0,0 +1,46 @@ +package shard + +import ( + "github.com/nspcc-dev/neofs-api-go/pkg/container" + "github.com/pkg/errors" +) + +type ContainerSizePrm struct { + cid *container.ID +} + +type ContainerSizeRes struct { + size uint64 +} + +func (p *ContainerSizePrm) WithContainerID(cid *container.ID) *ContainerSizePrm { + if p != nil { + p.cid = cid + } + + return p +} + +func (r *ContainerSizeRes) Size() uint64 { + return r.size +} + +func (s *Shard) ContainerSize(prm *ContainerSizePrm) (*ContainerSizeRes, error) { + size, err := s.metaBase.ContainerSize(prm.cid) + if err != nil { + return nil, errors.Wrap(err, "could not get container size") + } + + return &ContainerSizeRes{ + size: size, + }, nil +} + +func ContainerSize(s *Shard, cid *container.ID) (uint64, error) { + res, err := s.ContainerSize(&ContainerSizePrm{cid: cid}) + if err != nil { + return 0, err + } + + return res.Size(), nil +}