Implement review feedback

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
Arve Knudsen 2023-10-30 13:59:43 +01:00
parent 6c0910a289
commit 25e2c05a47

View file

@ -94,7 +94,7 @@ func (c *PostingsForMatchersCache) PostingsForMatchers(ctx context.Context, ix I
span.RecordError(err) span.RecordError(err)
return p, err return p, err
} }
c.expire(ctx) c.expire()
p, err := c.postingsForMatchersPromise(ctx, ix, ms)(ctx) p, err := c.postingsForMatchersPromise(ctx, ix, ms)(ctx)
span.RecordError(err) span.RecordError(err)
return p, err return p, err
@ -190,20 +190,13 @@ type postingsForMatchersCachedCall struct {
sizeBytes int64 sizeBytes int64
} }
func (c *PostingsForMatchersCache) expire(ctx context.Context) { func (c *PostingsForMatchersCache) expire() {
_, span := otel.Tracer("").Start(ctx, "PostingsForMatchersCache.expire", trace.WithAttributes(
attribute.Stringer("ttl", c.ttl),
))
defer span.End()
if c.ttl <= 0 { if c.ttl <= 0 {
span.AddEvent("ttl < 0 - doing nothing")
return return
} }
c.cachedMtx.RLock() c.cachedMtx.RLock()
if !c.shouldEvictHead() { if !c.shouldEvictHead() {
span.AddEvent("should not evict head")
c.cachedMtx.RUnlock() c.cachedMtx.RUnlock()
return return
} }
@ -212,7 +205,6 @@ func (c *PostingsForMatchersCache) expire(ctx context.Context) {
c.cachedMtx.Lock() c.cachedMtx.Lock()
defer c.cachedMtx.Unlock() defer c.cachedMtx.Unlock()
span.AddEvent("evicting head(s)")
for c.shouldEvictHead() { for c.shouldEvictHead() {
c.evictHead() c.evictHead()
} }
@ -246,8 +238,7 @@ func (c *PostingsForMatchersCache) evictHead() {
// created has to be called when returning from the PostingsForMatchers call that creates the promise. // created has to be called when returning from the PostingsForMatchers call that creates the promise.
// the ts provided should be the call time. // the ts provided should be the call time.
func (c *PostingsForMatchersCache) created(ctx context.Context, key string, ts time.Time, sizeBytes int64) { func (c *PostingsForMatchersCache) created(ctx context.Context, key string, ts time.Time, sizeBytes int64) {
_, span := otel.Tracer("").Start(ctx, "PostingsForMatchersCache.created") span := trace.SpanFromContext(ctx)
defer span.End()
if c.ttl <= 0 { if c.ttl <= 0 {
span.AddEvent("deleting cached promise since c.ttl <= 0", trace.WithAttributes( span.AddEvent("deleting cached promise since c.ttl <= 0", trace.WithAttributes(