2021-04-10 12:02:51 +00:00
|
|
|
package eigentrustctrl
|
|
|
|
|
|
|
|
import (
|
2023-04-05 07:44:40 +00:00
|
|
|
"context"
|
|
|
|
|
2023-04-12 14:35:10 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/reputation/eigentrust"
|
2021-04-10 12:02:51 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ContinuePrm groups the required parameters of Continue operation.
|
|
|
|
type ContinuePrm struct {
|
2021-04-29 05:30:41 +00:00
|
|
|
Epoch uint64
|
2021-04-10 12:02:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type iterContext struct {
|
|
|
|
eigentrust.EpochIteration
|
|
|
|
|
2022-03-02 16:31:56 +00:00
|
|
|
iterationNumber uint32
|
|
|
|
last bool
|
2021-04-10 12:02:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (x iterContext) Last() bool {
|
|
|
|
return x.last
|
|
|
|
}
|
|
|
|
|
|
|
|
// Continue moves the global reputation calculator to the next iteration.
|
2023-04-05 07:44:40 +00:00
|
|
|
func (c *Controller) Continue(ctx context.Context, prm ContinuePrm) {
|
2021-04-10 12:02:51 +00:00
|
|
|
c.mtx.Lock()
|
|
|
|
|
|
|
|
{
|
2021-04-29 05:30:41 +00:00
|
|
|
iterCtx, ok := c.mCtx[prm.Epoch]
|
2021-04-10 12:02:51 +00:00
|
|
|
if !ok {
|
2023-04-04 14:47:00 +00:00
|
|
|
iterCtx = new(iterContext)
|
2021-04-29 05:30:41 +00:00
|
|
|
c.mCtx[prm.Epoch] = iterCtx
|
2021-04-10 12:02:51 +00:00
|
|
|
|
2021-04-29 05:30:41 +00:00
|
|
|
iterCtx.EpochIteration.SetEpoch(prm.Epoch)
|
2022-03-02 16:31:56 +00:00
|
|
|
|
|
|
|
iterations, err := c.prm.IterationsProvider.EigenTrustIterations()
|
|
|
|
if err != nil {
|
2023-04-12 14:35:10 +00:00
|
|
|
c.opts.log.Error(logs.ControllerCouldNotGetEigenTrustIterationNumber,
|
2022-03-02 16:31:56 +00:00
|
|
|
zap.Error(err),
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
iterCtx.iterationNumber = uint32(iterations)
|
|
|
|
}
|
2021-04-10 12:02:51 +00:00
|
|
|
}
|
|
|
|
|
2022-03-02 16:31:56 +00:00
|
|
|
iterCtx.last = iterCtx.I() == iterCtx.iterationNumber-1
|
2021-04-10 12:02:51 +00:00
|
|
|
|
|
|
|
err := c.prm.WorkerPool.Submit(func() {
|
2023-04-05 07:44:40 +00:00
|
|
|
c.prm.DaughtersTrustCalculator.Calculate(ctx, iterCtx)
|
2021-04-29 05:30:41 +00:00
|
|
|
|
|
|
|
// iteration++
|
|
|
|
iterCtx.Increment()
|
2021-04-10 12:02:51 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
2023-04-12 14:35:10 +00:00
|
|
|
c.opts.log.Debug(logs.ControllerIterationSubmitFailure,
|
2021-04-10 12:02:51 +00:00
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
if iterCtx.last {
|
|
|
|
// will only live while the application is alive.
|
2021-04-29 05:30:41 +00:00
|
|
|
// during normal operation of the system. Also, such information
|
|
|
|
// number as already processed, but in any case it grows up
|
|
|
|
// In this case and worker pool failure we can mark epoch
|
|
|
|
delete(c.mCtx, prm.Epoch)
|
2021-04-10 12:02:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
c.mtx.Unlock()
|
|
|
|
}
|