forked from TrueCloudLab/frostfs-node
[#969] policer: Make error skip thread-safe
Introduces in afd2ba9a66
.
Refs #914
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
bugfix/namespace_require
parent
a6c9a337cd
commit
6010dfdf3d
|
@ -3,6 +3,7 @@ package policer
|
|||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
||||
|
@ -35,9 +36,7 @@ func (p *Policer) shardPolicyWorker(ctx context.Context) {
|
|||
p.log.Warn(logs.PolicerFailureAtObjectSelectForReplication, zap.Error(err))
|
||||
}
|
||||
|
||||
// contains all errors logged in this iteration for each container
|
||||
cnrErrSkip := make(map[cid.ID][]error)
|
||||
|
||||
skipMap := newSkipMap()
|
||||
for i := range addrs {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
|
@ -59,12 +58,10 @@ func (p *Policer) shardPolicyWorker(ctx context.Context) {
|
|||
|
||||
if p.objsInWork.add(addr.Address) {
|
||||
err := p.processObject(ctx, addr)
|
||||
if err != nil && !skipLog(cnrErrSkip[addr.Address.Container()], err) {
|
||||
if err != nil && !skipMap.addSeenError(addr.Address.Container(), err) {
|
||||
p.log.Error(logs.PolicerUnableToProcessObj,
|
||||
zap.Stringer("object", addr.Address),
|
||||
zap.String("error", err.Error()))
|
||||
|
||||
cnrErrSkip[addr.Address.Container()] = append(cnrErrSkip[addr.Address.Container()], err)
|
||||
}
|
||||
p.cache.Add(addr.Address, time.Now())
|
||||
p.objsInWork.remove(addr.Address)
|
||||
|
@ -79,11 +76,28 @@ func (p *Policer) shardPolicyWorker(ctx context.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
func skipLog(errs []error, err error) bool {
|
||||
for _, e := range errs {
|
||||
type errMap struct {
|
||||
sync.Mutex
|
||||
skipMap map[cid.ID][]error
|
||||
}
|
||||
|
||||
func newSkipMap() *errMap {
|
||||
return &errMap{
|
||||
skipMap: make(map[cid.ID][]error),
|
||||
}
|
||||
}
|
||||
|
||||
// addSeenError marks err as seen error for the container.
|
||||
// Returns true is the error has already been added.
|
||||
func (m *errMap) addSeenError(cnr cid.ID, err error) bool {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
|
||||
for _, e := range m.skipMap[cnr] {
|
||||
if errors.Is(err, e) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
m.skipMap[cnr] = append(m.skipMap[cnr], err)
|
||||
return false
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue