[#92] Refactor policer and add some unit tests
Signed-off-by: Alejandro Lopez <a.lopez@yadro.com>
This commit is contained in:
parent
0c5b025788
commit
f9730f090d
13 changed files with 640 additions and 310 deletions
|
@ -24,16 +24,16 @@ func (p *Replicator) HandleTask(ctx context.Context, task Task, res TaskResult)
|
|||
defer p.metrics.DecInFlightRequest()
|
||||
defer func() {
|
||||
p.log.Debug(logs.ReplicatorFinishWork,
|
||||
zap.Uint32("amount of unfinished replicas", task.quantity),
|
||||
zap.Uint32("amount of unfinished replicas", task.NumCopies),
|
||||
)
|
||||
}()
|
||||
|
||||
if task.obj == nil {
|
||||
if task.Obj == nil {
|
||||
var err error
|
||||
task.obj, err = engine.Get(ctx, p.localStorage, task.addr)
|
||||
task.Obj, err = engine.Get(ctx, p.localStorage, task.Addr)
|
||||
if err != nil {
|
||||
p.log.Error(logs.ReplicatorCouldNotGetObjectFromLocalStorage,
|
||||
zap.Stringer("object", task.addr),
|
||||
zap.Stringer("object", task.Addr),
|
||||
zap.Error(err))
|
||||
|
||||
return
|
||||
|
@ -41,9 +41,9 @@ func (p *Replicator) HandleTask(ctx context.Context, task Task, res TaskResult)
|
|||
}
|
||||
|
||||
prm := new(putsvc.RemotePutPrm).
|
||||
WithObject(task.obj)
|
||||
WithObject(task.Obj)
|
||||
|
||||
for i := 0; task.quantity > 0 && i < len(task.nodes); i++ {
|
||||
for i := 0; task.NumCopies > 0 && i < len(task.Nodes); i++ {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
|
@ -51,13 +51,13 @@ func (p *Replicator) HandleTask(ctx context.Context, task Task, res TaskResult)
|
|||
}
|
||||
|
||||
log := p.log.With(
|
||||
zap.String("node", netmap.StringifyPublicKey(task.nodes[i])),
|
||||
zap.Stringer("object", task.addr),
|
||||
zap.String("node", netmap.StringifyPublicKey(task.Nodes[i])),
|
||||
zap.Stringer("object", task.Addr),
|
||||
)
|
||||
|
||||
callCtx, cancel := context.WithTimeout(ctx, p.putTimeout)
|
||||
|
||||
err := p.remoteSender.PutObject(callCtx, prm.WithNodeInfo(task.nodes[i]))
|
||||
err := p.remoteSender.PutObject(callCtx, prm.WithNodeInfo(task.Nodes[i]))
|
||||
|
||||
cancel()
|
||||
|
||||
|
@ -68,12 +68,12 @@ func (p *Replicator) HandleTask(ctx context.Context, task Task, res TaskResult)
|
|||
} else {
|
||||
log.Debug(logs.ReplicatorObjectSuccessfullyReplicated)
|
||||
|
||||
task.quantity--
|
||||
task.NumCopies--
|
||||
|
||||
res.SubmitSuccessfulReplication(task.nodes[i])
|
||||
res.SubmitSuccessfulReplication(task.Nodes[i])
|
||||
|
||||
p.metrics.IncProcessedObjects()
|
||||
p.metrics.AddPayloadSize(int64(task.obj.PayloadSize()))
|
||||
p.metrics.AddPayloadSize(int64(task.Obj.PayloadSize()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue