forked from TrueCloudLab/frostfs-node
[#212] reputationsvc: Resolve funlen linter
Resolve funlen linter for Calculator.iterateDaughter method. Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
7ebbfa3358
commit
c236b54a65
1 changed files with 60 additions and 53 deletions
|
@ -101,7 +101,6 @@ type iterDaughterPrm struct {
|
||||||
consumersIter TrustIterator
|
consumersIter TrustIterator
|
||||||
}
|
}
|
||||||
|
|
||||||
// nolint: funlen
|
|
||||||
func (c *Calculator) iterateDaughter(ctx context.Context, p iterDaughterPrm) {
|
func (c *Calculator) iterateDaughter(ctx context.Context, p iterDaughterPrm) {
|
||||||
initTrust, err := c.prm.InitialTrustSource.InitialTrust(p.id)
|
initTrust, err := c.prm.InitialTrustSource.InitialTrust(p.id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -157,69 +156,77 @@ func (c *Calculator) iterateDaughter(ctx context.Context, p iterDaughterPrm) {
|
||||||
intermediateTrust.SetI(p.ei.I())
|
intermediateTrust.SetI(p.ei.I())
|
||||||
|
|
||||||
if p.lastIter {
|
if p.lastIter {
|
||||||
finalWriter, err := c.prm.FinalResultTarget.InitIntermediateWriter(p.ei)
|
c.processLastIteration(p, intermediateTrust, sum)
|
||||||
if err != nil {
|
|
||||||
c.opts.log.Debug("init writer failure",
|
|
||||||
zap.String("error", err.Error()),
|
|
||||||
)
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
intermediateTrust.SetValue(sum)
|
|
||||||
|
|
||||||
err = finalWriter.WriteIntermediateTrust(intermediateTrust)
|
|
||||||
if err != nil {
|
|
||||||
c.opts.log.Debug("write final result failure",
|
|
||||||
zap.String("error", err.Error()),
|
|
||||||
)
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
intermediateWriter, err := c.prm.IntermediateValueTarget.InitWriter(p.ei)
|
c.processIntermediateIteration(ctx, p, daughterIter, sum)
|
||||||
if err != nil {
|
}
|
||||||
c.opts.log.Debug("init writer failure",
|
}
|
||||||
zap.String("error", err.Error()),
|
|
||||||
)
|
|
||||||
|
|
||||||
return
|
func (c *Calculator) processLastIteration(p iterDaughterPrm, intermediateTrust eigentrust.IterationTrust, sum reputation.TrustValue) {
|
||||||
|
finalWriter, err := c.prm.FinalResultTarget.InitIntermediateWriter(p.ei)
|
||||||
|
if err != nil {
|
||||||
|
c.opts.log.Debug("init writer failure",
|
||||||
|
zap.String("error", err.Error()),
|
||||||
|
)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
intermediateTrust.SetValue(sum)
|
||||||
|
|
||||||
|
err = finalWriter.WriteIntermediateTrust(intermediateTrust)
|
||||||
|
if err != nil {
|
||||||
|
c.opts.log.Debug("write final result failure",
|
||||||
|
zap.String("error", err.Error()),
|
||||||
|
)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Calculator) processIntermediateIteration(ctx context.Context, p iterDaughterPrm, daughterIter TrustIterator, sum reputation.TrustValue) {
|
||||||
|
intermediateWriter, err := c.prm.IntermediateValueTarget.InitWriter(p.ei)
|
||||||
|
if err != nil {
|
||||||
|
c.opts.log.Debug("init writer failure",
|
||||||
|
zap.String("error", err.Error()),
|
||||||
|
)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = daughterIter.Iterate(func(trust reputation.Trust) error {
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return ctx.Err()
|
||||||
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
err = daughterIter.Iterate(func(trust reputation.Trust) error {
|
val := trust.Value()
|
||||||
select {
|
val.Mul(sum)
|
||||||
case <-ctx.Done():
|
|
||||||
return ctx.Err()
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
|
|
||||||
val := trust.Value()
|
trust.SetValue(val)
|
||||||
val.Mul(sum)
|
|
||||||
|
|
||||||
trust.SetValue(val)
|
err := intermediateWriter.Write(ctx, trust)
|
||||||
|
|
||||||
err := intermediateWriter.Write(ctx, trust)
|
|
||||||
if err != nil {
|
|
||||||
c.opts.log.Debug("write value failure",
|
|
||||||
zap.String("error", err.Error()),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.opts.log.Debug("iterate daughter trusts failure",
|
c.opts.log.Debug("write value failure",
|
||||||
zap.String("error", err.Error()),
|
zap.String("error", err.Error()),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = intermediateWriter.Close(ctx)
|
return nil
|
||||||
if err != nil {
|
})
|
||||||
c.opts.log.Error(
|
if err != nil {
|
||||||
"could not close writer",
|
c.opts.log.Debug("iterate daughter trusts failure",
|
||||||
zap.String("error", err.Error()),
|
zap.String("error", err.Error()),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = intermediateWriter.Close(ctx)
|
||||||
|
if err != nil {
|
||||||
|
c.opts.log.Error(
|
||||||
|
"could not close writer",
|
||||||
|
zap.String("error", err.Error()),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue