2021-01-29 00:04:36 +00:00
|
|
|
package placementrouter
|
|
|
|
|
|
|
|
import (
|
2021-10-05 11:53:18 +00:00
|
|
|
"bytes"
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
|
|
|
|
2021-01-29 00:04:36 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
|
|
|
loadroute "github.com/nspcc-dev/neofs-node/pkg/services/container/announcement/load/route"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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 {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("could not build placement %s: %w", a.ContainerID(), err)
|
2021-01-29 00:04:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
res := make([]loadroute.ServerInfo, 0, len(placement))
|
|
|
|
|
|
|
|
for i := range placement {
|
|
|
|
if len(placement[i]) == 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2021-10-05 11:53:18 +00:00
|
|
|
target := placement[i][0]
|
|
|
|
|
|
|
|
if len(passed) == 1 && bytes.Equal(passed[0].PublicKey(), target.PublicKey()) {
|
|
|
|
// add nil element so the announcement will be saved in local memory
|
|
|
|
res = append(res, nil)
|
|
|
|
} else {
|
|
|
|
// add element with remote node to send announcement to
|
|
|
|
res = append(res, target)
|
|
|
|
}
|
2021-01-29 00:04:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
}
|