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"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
netmapcore "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/netmap"
|
|
|
|
loadroute "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/container/announcement/load/route"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container"
|
2021-01-29 00:04:36 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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.
|
2022-06-28 07:01:05 +00:00
|
|
|
func (b *Builder) NextStage(a container.SizeEstimation, passed []loadroute.ServerInfo) ([]loadroute.ServerInfo, error) {
|
2021-01-29 00:04:36 +00:00
|
|
|
if len(passed) > 1 {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2022-06-28 07:01:05 +00:00
|
|
|
cnr := a.Container()
|
2022-05-12 16:37:46 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
placement, err := b.placementBuilder.BuildPlacement(a.Epoch(), cnr)
|
2021-01-29 00:04:36 +00:00
|
|
|
if err != nil {
|
2022-05-12 16:37:46 +00:00
|
|
|
return nil, fmt.Errorf("could not build placement %s: %w", cnr, 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
|
|
|
|
}
|
|
|
|
|
2022-06-08 23:18:26 +00:00
|
|
|
if len(passed) == 1 && bytes.Equal(passed[0].PublicKey(), placement[i][0].PublicKey()) {
|
2021-10-05 11:53:18 +00:00
|
|
|
// 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
|
2022-06-08 23:18:26 +00:00
|
|
|
res = append(res, netmapcore.Node(placement[i][0]))
|
2021-10-05 11:53:18 +00:00
|
|
|
}
|
2021-01-29 00:04:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
}
|