2020-12-18 09:27:19 +00:00
|
|
|
package audit
|
|
|
|
|
|
|
|
import (
|
2020-12-22 00:28:42 +00:00
|
|
|
"context"
|
2021-03-13 15:22:21 +00:00
|
|
|
"crypto/ecdsa"
|
2021-05-18 08:12:51 +00:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
2020-12-23 15:07:10 +00:00
|
|
|
"time"
|
2020-12-22 00:28:42 +00:00
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/storagegroup"
|
|
|
|
cntClient "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client/container"
|
|
|
|
nmClient "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client/netmap"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/event"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/audit"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
2020-12-18 09:27:19 +00:00
|
|
|
"github.com/panjf2000/ants/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
|
|
|
// Indexer is a callback interface for inner ring global state.
|
|
|
|
Indexer interface {
|
2021-03-23 14:14:28 +00:00
|
|
|
InnerRingIndex() int
|
2021-02-21 06:28:53 +00:00
|
|
|
InnerRingSize() int
|
2020-12-18 09:27:19 +00:00
|
|
|
}
|
|
|
|
|
2020-12-22 00:28:42 +00:00
|
|
|
TaskManager interface {
|
|
|
|
PushTask(*audit.Task) error
|
2020-12-22 12:34:38 +00:00
|
|
|
|
|
|
|
// Must skip all tasks planned for execution and
|
|
|
|
// return their number.
|
|
|
|
Reset() int
|
2020-12-22 00:28:42 +00:00
|
|
|
}
|
|
|
|
|
2022-05-19 19:40:22 +00:00
|
|
|
// EpochSource is an interface that provides actual
|
|
|
|
// epoch information.
|
|
|
|
EpochSource interface {
|
|
|
|
// EpochCounter must return current epoch number.
|
|
|
|
EpochCounter() uint64
|
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// Processor of events related to data audit.
|
2020-12-18 09:27:19 +00:00
|
|
|
Processor struct {
|
2022-09-28 07:41:01 +00:00
|
|
|
log *logger.Logger
|
2021-05-31 11:50:11 +00:00
|
|
|
pool *ants.Pool
|
|
|
|
irList Indexer
|
2022-07-01 18:16:28 +00:00
|
|
|
sgSrc storagegroup.SGSource
|
2022-05-19 19:40:22 +00:00
|
|
|
epochSrc EpochSource
|
2021-05-31 11:50:11 +00:00
|
|
|
searchTimeout time.Duration
|
2020-12-21 08:40:30 +00:00
|
|
|
|
2022-01-31 13:34:01 +00:00
|
|
|
containerClient *cntClient.Client
|
2022-01-31 11:58:55 +00:00
|
|
|
netmapClient *nmClient.Client
|
2020-12-22 00:28:42 +00:00
|
|
|
|
|
|
|
taskManager TaskManager
|
|
|
|
reporter audit.Reporter
|
|
|
|
prevAuditCanceler context.CancelFunc
|
2020-12-18 09:27:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Params of the processor constructor.
|
|
|
|
Params struct {
|
2022-09-28 07:41:01 +00:00
|
|
|
Log *logger.Logger
|
2022-01-31 11:58:55 +00:00
|
|
|
NetmapClient *nmClient.Client
|
2022-01-31 13:34:01 +00:00
|
|
|
ContainerClient *cntClient.Client
|
2021-05-31 11:50:11 +00:00
|
|
|
IRList Indexer
|
2022-07-01 18:16:28 +00:00
|
|
|
SGSource storagegroup.SGSource
|
2021-05-31 11:50:11 +00:00
|
|
|
RPCSearchTimeout time.Duration
|
|
|
|
TaskManager TaskManager
|
|
|
|
Reporter audit.Reporter
|
|
|
|
Key *ecdsa.PrivateKey
|
2022-05-19 19:40:22 +00:00
|
|
|
EpochSource EpochSource
|
2020-12-18 09:27:19 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2020-12-22 00:28:42 +00:00
|
|
|
type epochAuditReporter struct {
|
|
|
|
epoch uint64
|
|
|
|
|
|
|
|
rep audit.Reporter
|
|
|
|
}
|
|
|
|
|
2021-06-23 13:29:46 +00:00
|
|
|
// ProcessorPoolSize limits pool size for audit Processor. Processor manages
|
2022-04-21 11:28:05 +00:00
|
|
|
// audit tasks and fills queue for the next epoch. This process must not be interrupted
|
|
|
|
// by a new audit epoch, so we limit the pool size for the processor to one.
|
2020-12-18 09:27:19 +00:00
|
|
|
const ProcessorPoolSize = 1
|
|
|
|
|
|
|
|
// New creates audit processor instance.
|
|
|
|
func New(p *Params) (*Processor, error) {
|
|
|
|
switch {
|
|
|
|
case p.Log == nil:
|
|
|
|
return nil, errors.New("ir/audit: logger is not set")
|
|
|
|
case p.IRList == nil:
|
|
|
|
return nil, errors.New("ir/audit: global state is not set")
|
2021-10-27 12:12:05 +00:00
|
|
|
case p.SGSource == nil:
|
|
|
|
return nil, errors.New("ir/audit: SG source is not set")
|
2020-12-23 15:07:10 +00:00
|
|
|
case p.TaskManager == nil:
|
|
|
|
return nil, errors.New("ir/audit: audit task manager is not set")
|
|
|
|
case p.Reporter == nil:
|
|
|
|
return nil, errors.New("ir/audit: audit result reporter is not set")
|
2021-03-13 15:22:21 +00:00
|
|
|
case p.Key == nil:
|
|
|
|
return nil, errors.New("ir/audit: signing key is not set")
|
2022-05-19 19:40:22 +00:00
|
|
|
case p.EpochSource == nil:
|
|
|
|
return nil, errors.New("ir/audit: epoch source is not set")
|
2020-12-18 09:27:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pool, err := ants.NewPool(ProcessorPoolSize, ants.WithNonblocking(true))
|
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("ir/audit: can't create worker pool: %w", err)
|
2020-12-18 09:27:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &Processor{
|
|
|
|
log: p.Log,
|
|
|
|
pool: pool,
|
2021-05-31 11:50:11 +00:00
|
|
|
containerClient: p.ContainerClient,
|
2020-12-18 09:27:19 +00:00
|
|
|
irList: p.IRList,
|
2021-10-27 12:12:05 +00:00
|
|
|
sgSrc: p.SGSource,
|
2022-05-19 19:40:22 +00:00
|
|
|
epochSrc: p.EpochSource,
|
2020-12-23 15:07:10 +00:00
|
|
|
searchTimeout: p.RPCSearchTimeout,
|
2021-05-31 11:50:11 +00:00
|
|
|
netmapClient: p.NetmapClient,
|
2020-12-22 00:28:42 +00:00
|
|
|
taskManager: p.TaskManager,
|
|
|
|
reporter: p.Reporter,
|
|
|
|
prevAuditCanceler: func() {},
|
2020-12-18 09:27:19 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-08-12 15:24:17 +00:00
|
|
|
// ListenerNotificationParsers for the 'event.Listener' event producer.
|
|
|
|
func (ap *Processor) ListenerNotificationParsers() []event.NotificationParserInfo {
|
2020-12-18 09:27:19 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-08-12 15:24:17 +00:00
|
|
|
// ListenerNotificationHandlers for the 'event.Listener' event producer.
|
|
|
|
func (ap *Processor) ListenerNotificationHandlers() []event.NotificationHandlerInfo {
|
2020-12-18 09:27:19 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// TimersHandlers for the 'Timers' event producer.
|
2021-08-12 15:24:17 +00:00
|
|
|
func (ap *Processor) TimersHandlers() []event.NotificationHandlerInfo {
|
2020-12-18 09:27:19 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// StartAuditHandler for the internal event producer.
|
|
|
|
func (ap *Processor) StartAuditHandler() event.Handler {
|
|
|
|
return ap.handleNewAuditRound
|
|
|
|
}
|
2020-12-22 00:28:42 +00:00
|
|
|
|
|
|
|
func (r *epochAuditReporter) WriteReport(rep *audit.Report) error {
|
|
|
|
res := rep.Result()
|
2022-05-11 10:26:22 +00:00
|
|
|
res.ForEpoch(r.epoch)
|
2020-12-22 00:28:42 +00:00
|
|
|
|
|
|
|
return r.rep.WriteReport(rep)
|
|
|
|
}
|