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