frostfs-node/pkg/services/container/announcement/load/route/placement/calls.go
Leonard Lyubich 21133aee2f [#328] container/load: Implement route builder based on placement
Implement route Builder interface on wrapper over the container placement
builder, Component implies exactly one transfer to each of the most weight
nodes of the container (according to some weighing algorithm).
Implementation is planned for use when transferring local estimates of
storage nodes.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-02-02 15:45:04 +03:00

36 lines
1 KiB
Go

package placementrouter
import (
"github.com/nspcc-dev/neofs-api-go/pkg/container"
loadroute "github.com/nspcc-dev/neofs-node/pkg/services/container/announcement/load/route"
"github.com/pkg/errors"
)
// NextStage composes container nodes for the container and epoch from a,
// and returns the list of nodes with maximum weight (one from each vector).
//
// If passed route has more than one point, then endpoint of the route is reached.
//
// The traversed route is not checked, it is assumed to be correct.
func (b *Builder) NextStage(a container.UsedSpaceAnnouncement, passed []loadroute.ServerInfo) ([]loadroute.ServerInfo, error) {
if len(passed) > 1 {
return nil, nil
}
placement, err := b.placementBuilder.BuildPlacement(a.Epoch(), a.ContainerID())
if err != nil {
return nil, errors.Wrapf(err, "could not build placement %s", a.ContainerID())
}
res := make([]loadroute.ServerInfo, 0, len(placement))
for i := range placement {
if len(placement[i]) == 0 {
continue
}
res = append(res, placement[i][0])
}
return res, nil
}