2020-12-23 08:56:49 +00:00
|
|
|
package auditor
|
|
|
|
|
|
|
|
import (
|
2021-11-10 07:08:33 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/netmap"
|
2022-05-31 17:00:41 +00:00
|
|
|
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
2022-02-25 09:20:49 +00:00
|
|
|
"github.com/nspcc-dev/tzhash/tz"
|
2020-12-23 08:56:49 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
2020-12-23 13:45:53 +00:00
|
|
|
const (
|
|
|
|
hashRangeNumber = 4
|
2022-02-25 09:20:49 +00:00
|
|
|
minGamePayloadSize = hashRangeNumber * tz.Size
|
2020-12-23 13:45:53 +00:00
|
|
|
)
|
|
|
|
|
2020-12-23 08:56:49 +00:00
|
|
|
func (c *Context) executePoP() {
|
|
|
|
c.buildCoverage()
|
|
|
|
|
|
|
|
c.report.SetPlacementCounters(
|
|
|
|
c.counters.hit,
|
|
|
|
c.counters.miss,
|
|
|
|
c.counters.fail,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Context) buildCoverage() {
|
2022-06-08 23:18:26 +00:00
|
|
|
policy := c.task.ContainerStructure().PlacementPolicy()
|
2020-12-23 08:56:49 +00:00
|
|
|
|
|
|
|
// select random member from another storage group
|
|
|
|
// and process all placement vectors
|
2022-06-08 23:18:26 +00:00
|
|
|
c.iterateSGMembersPlacementRand(func(id oid.ID, ind int, nodes []netmap.NodeInfo) bool {
|
|
|
|
c.processObjectPlacement(id, nodes, policy.ReplicaNumberByIndex(ind))
|
2020-12-23 08:56:49 +00:00
|
|
|
return c.containerCovered()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Context) containerCovered() bool {
|
|
|
|
// number of container nodes can be calculated once
|
|
|
|
return c.cnrNodesNum <= len(c.pairedNodes)
|
|
|
|
}
|
|
|
|
|
2022-06-08 23:18:26 +00:00
|
|
|
func (c *Context) processObjectPlacement(id oid.ID, nodes []netmap.NodeInfo, replicas uint32) {
|
2020-12-23 08:56:49 +00:00
|
|
|
var (
|
|
|
|
ok uint32
|
|
|
|
optimal bool
|
|
|
|
|
|
|
|
unpairedCandidate1, unpairedCandidate2 = -1, -1
|
|
|
|
|
|
|
|
pairedCandidate = -1
|
|
|
|
)
|
|
|
|
|
2022-05-19 18:26:27 +00:00
|
|
|
var getHeaderPrm GetHeaderPrm
|
|
|
|
getHeaderPrm.Context = c.task.AuditContext()
|
|
|
|
getHeaderPrm.OID = id
|
|
|
|
getHeaderPrm.CID = c.task.ContainerID()
|
|
|
|
getHeaderPrm.NodeIsRelay = false
|
|
|
|
|
2020-12-23 16:53:11 +00:00
|
|
|
for i := 0; ok < replicas && i < len(nodes); i++ {
|
2022-05-19 18:26:27 +00:00
|
|
|
getHeaderPrm.Node = nodes[i]
|
|
|
|
|
2020-12-23 08:56:49 +00:00
|
|
|
// try to get object header from node
|
2022-05-19 18:26:27 +00:00
|
|
|
hdr, err := c.cnrCom.GetHeader(getHeaderPrm)
|
2020-12-23 08:56:49 +00:00
|
|
|
if err != nil {
|
|
|
|
c.log.Debug("could not get object header from candidate",
|
|
|
|
zap.Stringer("id", id),
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2020-12-23 13:45:53 +00:00
|
|
|
c.updateHeadResponses(hdr)
|
|
|
|
|
2020-12-23 08:56:49 +00:00
|
|
|
// increment success counter
|
|
|
|
ok++
|
|
|
|
|
|
|
|
// update optimal flag
|
|
|
|
optimal = ok == replicas && uint32(i) < replicas
|
|
|
|
|
2020-12-23 13:45:53 +00:00
|
|
|
// exclude small objects from coverage
|
|
|
|
if c.objectSize(id) < minGamePayloadSize {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2020-12-23 08:56:49 +00:00
|
|
|
// update potential candidates to be paired
|
|
|
|
if _, ok := c.pairedNodes[nodes[i].Hash()]; !ok {
|
|
|
|
if unpairedCandidate1 < 0 {
|
|
|
|
unpairedCandidate1 = i
|
|
|
|
} else if unpairedCandidate2 < 0 {
|
|
|
|
unpairedCandidate2 = i
|
|
|
|
}
|
|
|
|
} else if pairedCandidate < 0 {
|
|
|
|
pairedCandidate = i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if optimal {
|
|
|
|
c.counters.hit++
|
|
|
|
} else if ok == replicas {
|
|
|
|
c.counters.miss++
|
|
|
|
} else {
|
|
|
|
c.counters.fail++
|
|
|
|
}
|
|
|
|
|
|
|
|
if unpairedCandidate1 >= 0 {
|
|
|
|
if unpairedCandidate2 >= 0 {
|
2022-06-08 23:18:26 +00:00
|
|
|
c.composePair(id, nodes[unpairedCandidate1], nodes[unpairedCandidate2])
|
2020-12-23 08:56:49 +00:00
|
|
|
} else if pairedCandidate >= 0 {
|
2022-06-08 23:18:26 +00:00
|
|
|
c.composePair(id, nodes[unpairedCandidate1], nodes[pairedCandidate])
|
2020-12-23 08:56:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-08 23:18:26 +00:00
|
|
|
func (c *Context) composePair(id oid.ID, n1, n2 netmap.NodeInfo) {
|
2020-12-23 08:56:49 +00:00
|
|
|
c.pairs = append(c.pairs, gamePair{
|
|
|
|
n1: n1,
|
|
|
|
n2: n2,
|
|
|
|
id: id,
|
|
|
|
})
|
|
|
|
|
2020-12-23 16:53:11 +00:00
|
|
|
c.pairedNodes[n1.Hash()] = &pairMemberInfo{
|
2020-12-23 08:56:49 +00:00
|
|
|
node: n1,
|
|
|
|
}
|
2020-12-23 16:53:11 +00:00
|
|
|
c.pairedNodes[n2.Hash()] = &pairMemberInfo{
|
2020-12-23 08:56:49 +00:00
|
|
|
node: n2,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-08 23:18:26 +00:00
|
|
|
func (c *Context) iterateSGMembersPlacementRand(f func(oid.ID, int, []netmap.NodeInfo) bool) {
|
2020-12-23 08:56:49 +00:00
|
|
|
// iterate over storage groups members for all storage groups (one by one)
|
|
|
|
// with randomly shuffled members
|
2022-05-31 17:00:41 +00:00
|
|
|
c.iterateSGMembersRand(func(id oid.ID) bool {
|
2020-12-23 08:56:49 +00:00
|
|
|
// build placement vector for the current object
|
|
|
|
nn, err := c.buildPlacement(id)
|
|
|
|
if err != nil {
|
|
|
|
c.log.Debug("could not build placement for object",
|
|
|
|
zap.Stringer("id", id),
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, nodes := range nn {
|
|
|
|
if f(id, i, nodes) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
func (c *Context) iterateSGMembersRand(f func(oid.ID) bool) {
|
|
|
|
c.iterateSGInfo(func(members []oid.ID) bool {
|
2020-12-23 08:56:49 +00:00
|
|
|
ln := len(members)
|
|
|
|
|
|
|
|
processed := make(map[uint64]struct{}, ln-1)
|
|
|
|
|
|
|
|
for len(processed) < ln {
|
|
|
|
ind := nextRandUint64(uint64(ln), processed)
|
|
|
|
processed[ind] = struct{}{}
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
if f(members[ind]) {
|
2020-12-23 08:56:49 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
func (c *Context) iterateSGInfo(f func([]oid.ID) bool) {
|
2020-12-24 11:26:07 +00:00
|
|
|
c.sgMembersMtx.RLock()
|
|
|
|
defer c.sgMembersMtx.RUnlock()
|
|
|
|
|
2020-12-23 08:56:49 +00:00
|
|
|
// we can add randomization like for SG members,
|
|
|
|
// but list of storage groups is already expected
|
|
|
|
// to be shuffled since it is a Search response
|
|
|
|
// with unpredictable order
|
2022-03-15 11:39:53 +00:00
|
|
|
for i := range c.sgMembersCache {
|
|
|
|
if f(c.sgMembersCache[i]) {
|
2020-12-23 08:56:49 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|