Skip to content

Commit

Permalink
Check caches in blobExist in the correct order. (#311)
Browse files Browse the repository at this point in the history
  • Loading branch information
fische authored May 16, 2024
1 parent 859e78f commit b6ffca3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Version 11.10.4
--------------
* Check caches in the correct order.

Version 11.10.3
--------------
* Stop reserving rate limiter once past limit.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
11.10.3
11.10.4
30 changes: 16 additions & 14 deletions elan/rpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,21 @@ func (s *server) FindMissingBlobs(ctx context.Context, req *pb.FindMissingBlobsR
}

// blobExists returns true if this blob exists in the underlying storage.
func (s *server) blobExists(ctx context.Context, prefix string, digest *pb.Digest, compressed, redisRequest bool) bool {
func (s *server) blobExists(ctx context.Context, prefix string, digest *pb.Digest, compressed, redisRequest bool) (exists bool) {
key := s.compressedKey(prefix, digest, compressed)
if s.knownBlobCache != nil {
if _, present := s.knownBlobCache.Get(key); present {
knownBlobCacheHits.Inc()
return true
}
knownBlobCacheMisses.Inc()
}
defer func() {
if exists {
s.markKnownBlob(key)
}
}()

if redisRequest && s.readRedis != nil && prefix == CASPrefix && digest.SizeBytes < s.redisMaxSize {
exists, err := s.readRedis.Exists(ctx, digest.Hash).Result()
if err != nil && err != redis.Nil {
Expand All @@ -333,21 +347,9 @@ func (s *server) blobExists(ctx context.Context, prefix string, digest *pb.Diges
}
}

key := s.compressedKey(prefix, digest, compressed)
if s.knownBlobCache != nil {
if _, present := s.knownBlobCache.Get(key); present {
knownBlobCacheHits.Inc()
return true
}
knownBlobCacheMisses.Inc()
}
// N.B. if the blob is not known in the cache we still have to check, since something
// else could have written it when we weren't looking.
if !s.blobExistsUncached(ctx, key) {
return false
}
s.markKnownBlob(key)
return true
return s.blobExistsUncached(ctx, key)
}

func (s *server) blobExistsUncached(ctx context.Context, key string) bool {
Expand Down

0 comments on commit b6ffca3

Please sign in to comment.