Skip to content

Commit

Permalink
Don't use Allow, because that consumes tokens (#272)
Browse files Browse the repository at this point in the history
* Don't use Allow, because that consumes tokens

* Check for tokens existing

* Version + changelog

---------

Co-authored-by: Alexander Garbett <[email protected]>
  • Loading branch information
Garbett1 and Alexander Garbett authored Nov 10, 2023
1 parent 9988e47 commit 71d337e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Version 11.6.2
--------------
* Error token bucket was mistakenly consuming with `Allow()`. Refactored to make token bucket behaviour correct.

Version 11.6.1
--------------
* Randomly offset retentionTime and expiryTime for each job so the
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
11.6.1
11.6.2
4 changes: 2 additions & 2 deletions mettle/worker/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (r *redisClient) ReadBlob(dg *pb.Digest) ([]byte, error) {
ctx, cancel := context.WithTimeout(context.Background(), r.timeout)
defer cancel()

if r.limiter.Allow() {
if r.limiter.Tokens() >= 1.0 {
cmd := r.readRedis.Get(ctx, dg.Hash)
if err := cmd.Err(); err == nil {
blob, _ := cmd.Bytes()
Expand Down Expand Up @@ -226,7 +226,7 @@ func (r *redisClient) readBlobs(keys []string, metrics bool) [][]byte {
if len(keys) == 0 {
return nil
}
if !r.limiter.Allow() {
if r.limiter.Tokens() < 1.0 {
// Bail out immediately if Redis has exceeded error limit
return nil
}
Expand Down

0 comments on commit 71d337e

Please sign in to comment.