2020-12-23 09:54:34 +00:00
|
|
|
package auditor
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2020-12-24 11:26:07 +00:00
|
|
|
"sync"
|
2020-12-23 09:54:34 +00:00
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object_manager/placement"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/rand"
|
|
|
|
containerSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap"
|
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
|
|
|
storagegroupSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/storagegroup"
|
|
|
|
"git.frostfs.info/TrueCloudLab/tzhash/tz"
|
2020-12-23 09:54:34 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (c *Context) executePoR() {
|
2020-12-24 11:26:07 +00:00
|
|
|
wg := new(sync.WaitGroup)
|
|
|
|
sgs := c.task.StorageGroupList()
|
|
|
|
|
2022-07-01 18:45:18 +00:00
|
|
|
for _, sg := range sgs {
|
2020-12-24 11:26:07 +00:00
|
|
|
wg.Add(1)
|
|
|
|
|
|
|
|
if err := c.porWorkerPool.Submit(func() {
|
2022-07-01 18:45:18 +00:00
|
|
|
c.checkStorageGroupPoR(sg.ID(), sg.StorageGroup())
|
2020-12-24 11:26:07 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-03-20 07:01:27 +00:00
|
|
|
// nolint: funlen
|
2022-05-19 19:40:22 +00:00
|
|
|
func (c *Context) checkStorageGroupPoR(sgID oid.ID, sg storagegroupSDK.StorageGroup) {
|
|
|
|
members := sg.Members()
|
|
|
|
c.updateSGInfo(sgID, 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
|
|
|
)
|
|
|
|
|
2022-05-19 18:26:27 +00:00
|
|
|
var getHeaderPrm GetHeaderPrm
|
|
|
|
getHeaderPrm.CID = c.task.ContainerID()
|
|
|
|
getHeaderPrm.NodeIsRelay = true
|
|
|
|
|
2022-04-29 17:59:14 +00:00
|
|
|
homomorphicHashingEnabled := !containerSDK.IsHomomorphicHashingDisabled(c.task.ContainerStructure())
|
|
|
|
|
2020-12-23 09:54:34 +00:00
|
|
|
for i := range members {
|
2022-05-31 17:00:41 +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",
|
2022-05-19 19:40:22 +00:00
|
|
|
zap.Stringer("sg", sgID),
|
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]
|
|
|
|
})
|
|
|
|
|
2022-05-19 18:26:27 +00:00
|
|
|
getHeaderPrm.OID = members[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-05-19 18:26:27 +00:00
|
|
|
getHeaderPrm.Node = flat[j]
|
|
|
|
|
2023-04-06 06:45:10 +00:00
|
|
|
hdr, err := c.cnrCom.GetHeader(c.task.AuditContext(), getHeaderPrm)
|
2020-12-23 09:54:34 +00:00
|
|
|
if err != nil {
|
|
|
|
c.log.Debug("can't head object",
|
2022-10-11 12:49:34 +00:00
|
|
|
zap.String("remote_node", netmap.StringifyPublicKey(flat[j])),
|
2022-05-31 17:00:41 +00:00
|
|
|
zap.Stringer("oid", members[i]),
|
|
|
|
)
|
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)
|
|
|
|
|
2022-04-29 17:59:14 +00:00
|
|
|
if homomorphicHashingEnabled {
|
|
|
|
cs, _ := hdr.PayloadHomomorphicHash()
|
|
|
|
if len(tzHash) == 0 {
|
|
|
|
tzHash = cs.Value()
|
|
|
|
} else {
|
|
|
|
tzHash, err = tz.Concat([][]byte{
|
|
|
|
tzHash,
|
|
|
|
cs.Value(),
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
c.log.Debug("can't concatenate tz hash",
|
|
|
|
zap.String("oid", members[i].String()),
|
|
|
|
zap.String("error", err.Error()))
|
|
|
|
|
|
|
|
break
|
|
|
|
}
|
2020-12-23 09:54:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
totalSize += hdr.PayloadSize()
|
|
|
|
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-24 11:26:07 +00:00
|
|
|
c.porRequests.Add(accRequests)
|
|
|
|
c.porRetries.Add(accRetries)
|
|
|
|
|
2022-05-19 19:40:22 +00:00
|
|
|
sizeCheck := sg.ValidationDataSize() == totalSize
|
|
|
|
cs, _ := sg.ValidationDataHash()
|
2022-04-29 17:59:14 +00:00
|
|
|
tzCheck := !homomorphicHashingEnabled || bytes.Equal(tzHash, cs.Value())
|
2020-12-23 09:54:34 +00:00
|
|
|
|
|
|
|
if sizeCheck && tzCheck {
|
2022-05-19 19:40:22 +00:00
|
|
|
c.report.PassedPoR(sgID) // write report
|
2020-12-23 09:54:34 +00:00
|
|
|
} else {
|
|
|
|
if !sizeCheck {
|
|
|
|
c.log.Debug("storage group size check failed",
|
2022-05-19 19:40:22 +00:00
|
|
|
zap.Uint64("expected", sg.ValidationDataSize()),
|
2020-12-23 09:54:34 +00:00
|
|
|
zap.Uint64("got", totalSize))
|
|
|
|
}
|
|
|
|
|
|
|
|
if !tzCheck {
|
|
|
|
c.log.Debug("storage group tz hash check failed")
|
|
|
|
}
|
|
|
|
|
2022-05-19 19:40:22 +00:00
|
|
|
c.report.FailedPoR(sgID) // write report
|
2020-12-23 09:54:34 +00:00
|
|
|
}
|
|
|
|
}
|