forked from TrueCloudLab/frostfs-node
[#5] policer: Use generic LRU client
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
55b403e0ee
commit
8f61cc1dcc
2 changed files with 4 additions and 4 deletions
|
@ -12,7 +12,7 @@ import (
|
||||||
"github.com/TrueCloudLab/frostfs-node/pkg/services/replicator"
|
"github.com/TrueCloudLab/frostfs-node/pkg/services/replicator"
|
||||||
"github.com/TrueCloudLab/frostfs-node/pkg/util/logger"
|
"github.com/TrueCloudLab/frostfs-node/pkg/util/logger"
|
||||||
oid "github.com/TrueCloudLab/frostfs-sdk-go/object/id"
|
oid "github.com/TrueCloudLab/frostfs-sdk-go/object/id"
|
||||||
lru "github.com/hashicorp/golang-lru"
|
lru "github.com/hashicorp/golang-lru/v2"
|
||||||
"github.com/panjf2000/ants/v2"
|
"github.com/panjf2000/ants/v2"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
@ -53,7 +53,7 @@ func (oiw *objectsInWork) add(addr oid.Address) {
|
||||||
type Policer struct {
|
type Policer struct {
|
||||||
*cfg
|
*cfg
|
||||||
|
|
||||||
cache *lru.Cache
|
cache *lru.Cache[oid.Address, time.Time]
|
||||||
|
|
||||||
objsInWork *objectsInWork
|
objsInWork *objectsInWork
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ func New(opts ...Option) *Policer {
|
||||||
|
|
||||||
c.log = &logger.Logger{Logger: c.log.With(zap.String("component", "Object Policer"))}
|
c.log = &logger.Logger{Logger: c.log.With(zap.String("component", "Object Policer"))}
|
||||||
|
|
||||||
cache, err := lru.New(int(c.cacheSize))
|
cache, err := lru.New[oid.Address, time.Time](int(c.cacheSize))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ func (p *Policer) shardPolicyWorker(ctx context.Context) {
|
||||||
|
|
||||||
err = p.taskPool.Submit(func() {
|
err = p.taskPool.Submit(func() {
|
||||||
v, ok := p.cache.Get(addr.Address)
|
v, ok := p.cache.Get(addr.Address)
|
||||||
if ok && time.Since(v.(time.Time)) < p.evictDuration {
|
if ok && time.Since(v) < p.evictDuration {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue