Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check caches in blobExist in the correct order. #311

Merged
merged 1 commit into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading