2020-12-23 09:54:34 +00:00
|
|
|
package auditor
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2021-06-23 12:27:00 +00:00
|
|
|
"encoding/hex"
|
2020-12-24 11:26:07 +00:00
|
|
|
"sync"
|
2020-12-23 09:54:34 +00:00
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/object_manager/placement"
|
2020-12-23 14:57:50 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/util/rand"
|
2022-01-26 12:11:13 +00:00
|
|
|
oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
2020-12-23 09:54:34 +00:00
|
|
|
"github.com/nspcc-dev/tzhash/tz"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (c *Context) executePoR() {
|
2020-12-24 11:26:07 +00:00
|
|
|
wg := new(sync.WaitGroup)
|
|
|
|
sgs := c.task.StorageGroupList()
|
|
|
|
|
|
|
|
for i := range sgs {
|
|
|
|
wg.Add(1)
|
|
|
|
|
|
|
|
sg := sgs[i]
|
|
|
|
|
|
|
|
if err := c.porWorkerPool.Submit(func() {
|
|
|
|
c.checkStorageGroupPoR(i, sg)
|
|
|
|
wg.Done()
|
|
|
|
}); err != nil {
|
|
|
|
wg.Done()
|
|
|
|
}
|
2020-12-23 09:54:34 +00:00
|
|
|
}
|
2020-12-24 11:26:07 +00:00
|
|
|
|
|
|
|
wg.Wait()
|
2021-10-19 13:34:34 +00:00
|
|
|
c.porWorkerPool.Release()
|
2020-12-24 11:26:07 +00:00
|
|
|
|
|
|
|
c.report.SetPoRCounters(c.porRequests.Load(), c.porRetries.Load())
|
2020-12-23 09:54:34 +00:00
|
|
|
}
|
|
|
|
|
2022-01-26 12:11:13 +00:00
|
|
|
func (c *Context) checkStorageGroupPoR(ind int, sg *oidSDK.ID) {
|
2020-12-23 09:54:34 +00:00
|
|
|
storageGroup, err := c.cnrCom.GetSG(c.task, sg) // get storage group
|
|
|
|
if err != nil {
|
|
|
|
c.log.Warn("can't get storage group",
|
|
|
|
zap.Stringer("sgid", sg),
|
|
|
|
zap.String("error", err.Error()))
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
members := storageGroup.Members()
|
2020-12-24 11:26:07 +00:00
|
|
|
c.updateSGInfo(ind, members)
|
2020-12-23 09:54:34 +00:00
|
|
|
|
|
|
|
var (
|
|
|
|
tzHash []byte
|
|
|
|
totalSize uint64
|
2020-12-24 11:26:07 +00:00
|
|
|
|
|
|
|
accRequests, accRetries uint32
|
2020-12-23 09:54:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
for i := range members {
|
2022-03-15 11:39:53 +00:00
|
|
|
objectPlacement, err := c.buildPlacement(&members[i])
|
2020-12-23 09:54:34 +00:00
|
|
|
if err != nil {
|
|
|
|
c.log.Info("can't build placement for storage group member",
|
|
|
|
zap.Stringer("sg", sg),
|
2022-03-16 12:18:56 +00:00
|
|
|
zap.String("member_id", members[i].String()),
|
2020-12-23 09:54:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2020-12-23 14:57:50 +00:00
|
|
|
flat := placement.FlattenNodes(objectPlacement)
|
|
|
|
|
2022-01-11 14:07:59 +00:00
|
|
|
rand.Shuffle(len(flat), func(i, j int) {
|
2020-12-23 14:57:50 +00:00
|
|
|
flat[i], flat[j] = flat[j], flat[i]
|
|
|
|
})
|
|
|
|
|
2020-12-25 07:45:59 +00:00
|
|
|
for j := range flat {
|
2020-12-24 11:26:07 +00:00
|
|
|
accRequests++
|
2020-12-25 07:45:59 +00:00
|
|
|
if j > 0 { // in best case audit get object header on first iteration
|
2020-12-24 11:26:07 +00:00
|
|
|
accRetries++
|
2020-12-24 10:22:14 +00:00
|
|
|
}
|
|
|
|
|
2022-03-15 11:39:53 +00:00
|
|
|
hdr, err := c.cnrCom.GetHeader(c.task, &flat[j], &members[i], true)
|
2020-12-23 09:54:34 +00:00
|
|
|
if err != nil {
|
|
|
|
c.log.Debug("can't head object",
|
2021-06-23 12:27:00 +00:00
|
|
|
zap.String("remote_node", hex.EncodeToString(flat[j].PublicKey())),
|
2022-03-16 12:18:56 +00:00
|
|
|
zap.String("oid", members[i].String()))
|
2020-12-23 09:54:34 +00:00
|
|
|
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2020-12-23 13:39:51 +00:00
|
|
|
// update cache for PoR and PDP audit checks
|
|
|
|
c.updateHeadResponses(hdr)
|
|
|
|
|
2020-12-23 09:54:34 +00:00
|
|
|
if len(tzHash) == 0 {
|
|
|
|
tzHash = hdr.PayloadHomomorphicHash().Sum()
|
|
|
|
} else {
|
|
|
|
tzHash, err = tz.Concat([][]byte{
|
|
|
|
tzHash,
|
|
|
|
hdr.PayloadHomomorphicHash().Sum(),
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
c.log.Debug("can't concatenate tz hash",
|
2022-03-16 12:18:56 +00:00
|
|
|
zap.String("oid", members[i].String()),
|
2020-12-23 09:54:34 +00:00
|
|
|
zap.String("error", err.Error()))
|
|
|
|
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
totalSize += hdr.PayloadSize()
|
|
|
|
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-24 11:26:07 +00:00
|
|
|
c.porRequests.Add(accRequests)
|
|
|
|
c.porRetries.Add(accRetries)
|
|
|
|
|
2020-12-23 09:54:34 +00:00
|
|
|
sizeCheck := storageGroup.ValidationDataSize() == totalSize
|
|
|
|
tzCheck := bytes.Equal(tzHash, storageGroup.ValidationDataHash().Sum())
|
|
|
|
|
|
|
|
if sizeCheck && tzCheck {
|
|
|
|
c.report.PassedPoR(sg) // write report
|
|
|
|
} else {
|
|
|
|
if !sizeCheck {
|
|
|
|
c.log.Debug("storage group size check failed",
|
|
|
|
zap.Uint64("expected", storageGroup.ValidationDataSize()),
|
|
|
|
zap.Uint64("got", totalSize))
|
|
|
|
}
|
|
|
|
|
|
|
|
if !tzCheck {
|
|
|
|
c.log.Debug("storage group tz hash check failed")
|
|
|
|
}
|
|
|
|
|
|
|
|
c.report.FailedPoR(sg) // write report
|
|
|
|
}
|
|
|
|
}
|