[#92] Refactor policer and add some unit tests #485

Merged
fyrchik merged 3 commits from ale64bit/frostfs-node:fix/policer-refactor-test into master 2023-07-03 07:05:33 +00:00
2 changed files with 8 additions and 7 deletions
Showing only changes of commit e7f3a9fc19 - Show all commits

View file

@ -29,10 +29,12 @@ func (oiw *objectsInWork) remove(addr oid.Address) {
oiw.Unlock()
}
func (oiw *objectsInWork) add(addr oid.Address) {
func (oiw *objectsInWork) add(addr oid.Address) bool {
oiw.Lock()
_, exists := oiw.objs[addr]
oiw.objs[addr] = struct{}{}
oiw.Unlock()
return !exists
}
// Policer represents the utility that verifies

View file

@ -51,12 +51,11 @@ func (p *Policer) shardPolicyWorker(ctx context.Context) {
return
}
p.objsInWork.add(addr.Address)
p.processObject(ctx, addr)
p.cache.Add(addr.Address, time.Now())
p.objsInWork.remove(addr.Address)
if p.objsInWork.add(addr.Address) {
p.processObject(ctx, addr)
p.cache.Add(addr.Address, time.Now())
p.objsInWork.remove(addr.Address)
}
})
if err != nil {
p.log.Warn(logs.PolicerPoolSubmission, zap.Error(err))