forked from TrueCloudLab/frostfs-node
[#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()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,31 +8,12 @@ import (
|
|||
|
||||
// Task represents group of Replicator task parameters.
|
||||
type Task struct {
|
||||
quantity uint32
|
||||
|
||||
addr oid.Address
|
||||
|
||||
obj *objectSDK.Object
|
||||
|
||||
nodes []netmap.NodeInfo
|
||||
}
|
||||
|
||||
// SetCopiesNumber sets number of copies to replicate.
|
||||
func (t *Task) SetCopiesNumber(v uint32) {
|
||||
t.quantity = v
|
||||
}
|
||||
|
||||
// SetObjectAddress sets address of local object.
|
||||
func (t *Task) SetObjectAddress(v oid.Address) {
|
||||
t.addr = v
|
||||
}
|
||||
|
||||
// SetObject sets object to avoid fetching it from the local storage.
|
||||
func (t *Task) SetObject(obj *objectSDK.Object) {
|
||||
t.obj = obj
|
||||
}
|
||||
|
||||
// SetNodes sets a list of potential object holders.
|
||||
func (t *Task) SetNodes(v []netmap.NodeInfo) {
|
||||
t.nodes = v
|
||||
// NumCopies is the number of copies to replicate.
|
||||
NumCopies uint32
|
||||
// Addr is the address of the local object.
|
||||
Addr oid.Address
|
||||
// Obj is the object to avoid fetching it from the local storage.
|
||||
Obj *objectSDK.Object
|
||||
// Nodes is a list of potential object holders.
|
||||
Nodes []netmap.NodeInfo
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue