forked from TrueCloudLab/frostfs-node
[#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 <leonard@nspcc.ru>
This commit is contained in:
parent
910017b72f
commit
1bed03995b
1 changed files with 34 additions and 0 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue