forked from TrueCloudLab/frostfs-node
[#1210] reputation: Resolve race condition
Make all epoch independent in reputation process. Do not reset any timers related to reputation. Make it possible to finish iteration after the unexpected `NewEpoch` event. Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
77d847dbea
commit
c3db12d71b
6 changed files with 66 additions and 115 deletions
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/reputation/common"
|
||||
intermediatereputation "github.com/nspcc-dev/neofs-node/cmd/neofs-node/reputation/intermediate"
|
||||
localreputation "github.com/nspcc-dev/neofs-node/cmd/neofs-node/reputation/local"
|
||||
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/reputation/ticker"
|
||||
repClient "github.com/nspcc-dev/neofs-node/pkg/morph/client/reputation"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/event/netmap"
|
||||
|
@ -215,36 +216,40 @@ func initReputationService(c *cfg) {
|
|||
}
|
||||
|
||||
// initialize eigen trust block timer
|
||||
durationMeter := NewEigenTrustDuration(c.cfgNetmap.wrapper)
|
||||
|
||||
newEigenTrustIterTimer(c, durationMeter, func() {
|
||||
epoch, err := c.cfgNetmap.wrapper.Epoch()
|
||||
if err != nil {
|
||||
c.log.Debug(
|
||||
"could not get current epoch",
|
||||
zap.String("error", err.Error()),
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
eigenTrustController.Continue(
|
||||
eigentrustctrl.ContinuePrm{
|
||||
Epoch: epoch - 1,
|
||||
},
|
||||
)
|
||||
})
|
||||
newEigenTrustIterTimer(c)
|
||||
|
||||
addNewEpochAsyncNotificationHandler(
|
||||
c,
|
||||
func(e event.Event) {
|
||||
durationMeter.Update() // recalculate duration of one iteration round
|
||||
epoch := e.(netmap.NewEpoch).EpochNumber()
|
||||
|
||||
err := c.cfgMorph.eigenTrustTimer.Reset() // start iteration rounds again
|
||||
log := c.log.With(zap.Uint64("epoch", epoch))
|
||||
|
||||
duration, err := c.cfgNetmap.wrapper.EpochDuration()
|
||||
if err != nil {
|
||||
c.log.Warn("can't reset block timer to start eigen trust calculations again",
|
||||
zap.String("error", err.Error()))
|
||||
log.Debug("could not fetch epoch duration", zap.Error(err))
|
||||
return
|
||||
}
|
||||
|
||||
iterations, err := c.cfgNetmap.wrapper.EigenTrustIterations()
|
||||
if err != nil {
|
||||
log.Debug("could not fetch iteration number", zap.Error(err))
|
||||
return
|
||||
}
|
||||
|
||||
epochTimer, err := ticker.NewIterationsTicker(duration, iterations, func() {
|
||||
eigenTrustController.Continue(
|
||||
eigentrustctrl.ContinuePrm{
|
||||
Epoch: epoch - 1,
|
||||
},
|
||||
)
|
||||
})
|
||||
if err != nil {
|
||||
log.Debug("could not create fixed epoch timer", zap.Error(err))
|
||||
return
|
||||
}
|
||||
|
||||
c.cfgMorph.eigenTrustTicker.addEpochTimer(epoch, epochTimer)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue