frostfs-node/pkg/services/reputation/eigentrust/controller/calls.go
Dmitrii Stepanov 7ebbfa3358 [#212] reputationsvc: Resolve linters and rename
Resolved containedctx linters.
Renamed context structs and interfaces to more understandble names.

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
2023-04-07 15:35:57 +00:00

72 lines
1.6 KiB
Go

package eigentrustctrl
import (
"context"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/reputation/eigentrust"
"go.uber.org/zap"
)
// ContinuePrm groups the required parameters of Continue operation.
type ContinuePrm struct {
Epoch uint64
}
type iterContext struct {
eigentrust.EpochIteration
iterationNumber uint32
last bool
}
func (x iterContext) Last() bool {
return x.last
}
// Continue moves the global reputation calculator to the next iteration.
func (c *Controller) Continue(ctx context.Context, prm ContinuePrm) {
c.mtx.Lock()
{
iterCtx, ok := c.mCtx[prm.Epoch]
if !ok {
iterCtx = new(iterContext)
c.mCtx[prm.Epoch] = iterCtx
iterCtx.EpochIteration.SetEpoch(prm.Epoch)
iterations, err := c.prm.IterationsProvider.EigenTrustIterations()
if err != nil {
c.opts.log.Error("could not get EigenTrust iteration number",
zap.Error(err),
)
} else {
iterCtx.iterationNumber = uint32(iterations)
}
}
iterCtx.last = iterCtx.I() == iterCtx.iterationNumber-1
err := c.prm.WorkerPool.Submit(func() {
c.prm.DaughtersTrustCalculator.Calculate(ctx, iterCtx)
// iteration++
iterCtx.Increment()
})
if err != nil {
c.opts.log.Debug("iteration submit failure",
zap.String("error", err.Error()),
)
}
if iterCtx.last {
// will only live while the application is alive.
// 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)
}
}
c.mtx.Unlock()
}