forked from TrueCloudLab/frostfs-node
[#212] reputationsvc: Resolve containedctx linter
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>fix/118-unit_test
parent
e2f13d03d7
commit
469e8a6e59
|
@ -1,8 +1,6 @@
|
|||
package eigentrustctrl
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/reputation/eigentrust"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
@ -12,10 +10,7 @@ type ContinuePrm struct {
|
|||
Epoch uint64
|
||||
}
|
||||
|
||||
// nolint: containedctx
|
||||
type iterContext struct {
|
||||
context.Context
|
||||
|
||||
eigentrust.EpochIteration
|
||||
|
||||
iterationNumber uint32
|
||||
|
@ -26,12 +21,6 @@ func (x iterContext) Last() bool {
|
|||
return x.last
|
||||
}
|
||||
|
||||
type iterContextCancel struct {
|
||||
iterContext
|
||||
|
||||
cancel context.CancelFunc
|
||||
}
|
||||
|
||||
// Continue moves the global reputation calculator to the next iteration.
|
||||
func (c *Controller) Continue(prm ContinuePrm) {
|
||||
c.mtx.Lock()
|
||||
|
@ -39,10 +28,9 @@ func (c *Controller) Continue(prm ContinuePrm) {
|
|||
{
|
||||
iterCtx, ok := c.mCtx[prm.Epoch]
|
||||
if !ok {
|
||||
iterCtx = new(iterContextCancel)
|
||||
iterCtx = new(iterContext)
|
||||
c.mCtx[prm.Epoch] = iterCtx
|
||||
|
||||
iterCtx.Context, iterCtx.cancel = context.WithCancel(context.Background())
|
||||
iterCtx.EpochIteration.SetEpoch(prm.Epoch)
|
||||
|
||||
iterations, err := c.prm.IterationsProvider.EigenTrustIterations()
|
||||
|
@ -53,14 +41,12 @@ func (c *Controller) Continue(prm ContinuePrm) {
|
|||
} else {
|
||||
iterCtx.iterationNumber = uint32(iterations)
|
||||
}
|
||||
} else {
|
||||
iterCtx.cancel()
|
||||
}
|
||||
|
||||
iterCtx.last = iterCtx.I() == iterCtx.iterationNumber-1
|
||||
|
||||
err := c.prm.WorkerPool.Submit(func() {
|
||||
c.prm.DaughtersTrustCalculator.Calculate(iterCtx.iterContext)
|
||||
c.prm.DaughtersTrustCalculator.Calculate(iterCtx)
|
||||
|
||||
// iteration++
|
||||
iterCtx.Increment()
|
||||
|
|
|
@ -47,7 +47,7 @@ type Controller struct {
|
|||
opts *options
|
||||
|
||||
mtx sync.Mutex
|
||||
mCtx map[uint64]*iterContextCancel
|
||||
mCtx map[uint64]*iterContext
|
||||
}
|
||||
|
||||
const invalidPrmValFmt = "invalid parameter %s (%T):%v"
|
||||
|
@ -81,6 +81,6 @@ func New(prm Prm, opts ...Option) *Controller {
|
|||
return &Controller{
|
||||
prm: prm,
|
||||
opts: o,
|
||||
mCtx: make(map[uint64]*iterContextCancel),
|
||||
mCtx: make(map[uint64]*iterContext),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,8 @@
|
|||
package eigentrustctrl
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
// IterationContext is a context of the i-th
|
||||
// stage of iterative EigenTrust algorithm.
|
||||
type IterationContext interface {
|
||||
context.Context
|
||||
|
||||
// Must return epoch number to select the values
|
||||
// for global trust calculation.
|
||||
Epoch() uint64
|
||||
|
|
Loading…
Reference in New Issue