From 1bed03995b84c5f1bde243c2e951a041d8bc21e7 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 1 Feb 2021 15:11:25 +0300 Subject: [PATCH] [#328] container/load: Implement Iterator on local storage engine Implement wrapper over StorageEngine on app-side that iterates over the values returned by ListContainers+ContainerSize method pair. Component will be used as the source of local metrics. Signed-off-by: Leonard Lyubich --- cmd/neofs-node/container.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/cmd/neofs-node/container.go b/cmd/neofs-node/container.go index cbaa94248..6dd9b79da 100644 --- a/cmd/neofs-node/container.go +++ b/cmd/neofs-node/container.go @@ -10,6 +10,7 @@ import ( containerGRPC "github.com/nspcc-dev/neofs-api-go/v2/container/grpc" containerCore "github.com/nspcc-dev/neofs-node/pkg/core/container" netmapCore "github.com/nspcc-dev/neofs-node/pkg/core/netmap" + "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine" "github.com/nspcc-dev/neofs-node/pkg/morph/client" "github.com/nspcc-dev/neofs-node/pkg/morph/client/container" "github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper" @@ -151,3 +152,36 @@ func (l *loadPlacementBuilder) buildPlacement(epoch uint64, cid *containerSDK.ID return cnrNodes, nm, nil } + +type localStorageLoad struct { + log *logger.Logger + + engine *engine.StorageEngine +} + +func (d *localStorageLoad) Iterate(f loadcontroller.UsedSpaceFilter, h loadcontroller.UsedSpaceHandler) error { + idList := engine.ListContainers(d.engine) + + for i := range idList { + sz := engine.ContainerSize(d.engine, idList[i]) + + d.log.Debug("container size in storage engine calculated successfully", + zap.Uint64("size", sz), + zap.Stringer("cid", idList[i]), + ) + + a := containerSDK.NewAnnouncement() + a.SetContainerID(idList[i]) + a.SetUsedSpace(sz) + + if f != nil && !f(*a) { + continue + } + + if err := h(*a); err != nil { + return err + } + } + + return nil +}