2020-12-22 00:25:26 +00:00
|
|
|
package audit
|
|
|
|
|
|
|
|
import (
|
2020-12-24 11:22:55 +00:00
|
|
|
"sync"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/audit"
|
|
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
2020-12-22 00:25:26 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Report tracks the progress of auditing container data.
|
|
|
|
type Report struct {
|
2020-12-24 11:22:55 +00:00
|
|
|
mu sync.RWMutex
|
2022-05-11 10:26:22 +00:00
|
|
|
res audit.Result
|
2020-12-22 00:25:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Reporter is an interface of the entity that records
|
|
|
|
// the data audit report.
|
|
|
|
type Reporter interface {
|
|
|
|
WriteReport(r *Report) error
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewReport creates and returns blank Report instance.
|
2022-05-31 17:00:41 +00:00
|
|
|
func NewReport(cnr cid.ID) *Report {
|
2022-05-11 10:26:22 +00:00
|
|
|
var rep Report
|
2022-05-31 17:00:41 +00:00
|
|
|
rep.res.ForContainer(cnr)
|
2020-12-22 00:25:26 +00:00
|
|
|
|
2022-05-11 10:26:22 +00:00
|
|
|
return &rep
|
2020-12-22 00:25:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Result forms the structure of the data audit result.
|
|
|
|
func (r *Report) Result() *audit.Result {
|
2020-12-24 11:22:55 +00:00
|
|
|
r.mu.RLock()
|
|
|
|
defer r.mu.RUnlock()
|
|
|
|
|
2022-05-11 10:26:22 +00:00
|
|
|
return &r.res
|
2020-12-22 00:25:26 +00:00
|
|
|
}
|
2020-12-22 08:08:31 +00:00
|
|
|
|
|
|
|
// Complete completes audit report.
|
|
|
|
func (r *Report) Complete() {
|
2020-12-24 11:22:55 +00:00
|
|
|
r.mu.Lock()
|
|
|
|
defer r.mu.Unlock()
|
|
|
|
|
2022-05-11 10:26:22 +00:00
|
|
|
r.res.Complete()
|
2020-12-22 08:08:31 +00:00
|
|
|
}
|
2020-12-23 09:47:40 +00:00
|
|
|
|
|
|
|
// PassedPoR updates list of passed storage groups.
|
2022-05-31 17:00:41 +00:00
|
|
|
func (r *Report) PassedPoR(sg oid.ID) {
|
2020-12-24 11:22:55 +00:00
|
|
|
r.mu.Lock()
|
|
|
|
defer r.mu.Unlock()
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
r.res.SubmitPassedStorageGroup(sg)
|
2020-12-23 09:47:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// FailedPoR updates list of failed storage groups.
|
2022-05-31 17:00:41 +00:00
|
|
|
func (r *Report) FailedPoR(sg oid.ID) {
|
2020-12-24 11:22:55 +00:00
|
|
|
r.mu.Lock()
|
|
|
|
defer r.mu.Unlock()
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
r.res.SubmitFailedStorageGroup(sg)
|
2020-12-23 09:47:40 +00:00
|
|
|
}
|
2020-12-23 08:56:49 +00:00
|
|
|
|
|
|
|
// SetPlacementCounters sets counters of compliance with placement.
|
|
|
|
func (r *Report) SetPlacementCounters(hit, miss, fail uint32) {
|
2020-12-24 11:22:55 +00:00
|
|
|
r.mu.Lock()
|
|
|
|
defer r.mu.Unlock()
|
|
|
|
|
2022-05-11 10:26:22 +00:00
|
|
|
r.res.SetHits(hit)
|
|
|
|
r.res.SetMisses(miss)
|
|
|
|
r.res.SetFailures(fail)
|
2020-12-23 08:56:49 +00:00
|
|
|
}
|
2020-12-23 16:53:11 +00:00
|
|
|
|
|
|
|
// SetPDPResults sets lists of nodes according to their PDP results.
|
|
|
|
func (r *Report) SetPDPResults(passed, failed [][]byte) {
|
2020-12-24 11:22:55 +00:00
|
|
|
r.mu.Lock()
|
|
|
|
defer r.mu.Unlock()
|
|
|
|
|
2022-05-11 10:26:22 +00:00
|
|
|
r.res.SubmitPassedStorageNodes(passed)
|
|
|
|
r.res.SubmitFailedStorageNodes(failed)
|
2020-12-23 16:53:11 +00:00
|
|
|
}
|
2020-12-24 10:22:14 +00:00
|
|
|
|
|
|
|
// SetPoRCounters sets amounts of head requests and retries at PoR audit stage.
|
|
|
|
func (r *Report) SetPoRCounters(requests, retries uint32) {
|
2020-12-24 11:22:55 +00:00
|
|
|
r.mu.Lock()
|
|
|
|
defer r.mu.Unlock()
|
|
|
|
|
2022-05-11 10:26:22 +00:00
|
|
|
r.res.SetRequestsPoR(requests)
|
|
|
|
r.res.SetRetriesPoR(retries)
|
2020-12-24 10:22:14 +00:00
|
|
|
}
|