Skip to content

Commit

Permalink
[disk] SizedLRU.Reserve should return a non-nil error if unable to re…
Browse files Browse the repository at this point in the history
…serve the required space

Relates to buchgr#649
  • Loading branch information
mostynb committed Mar 11, 2023
1 parent c5bf6e1 commit 887e5e5
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions cache/disk/lru.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,19 @@ func (c *SizedLRU) Reserve(size int64) (bool, error) {
return true, nil
}

if size < 0 || size > c.maxSize {
return false, nil
if size < 0 {
return false, fmt.Errorf("Invalid negative blob size: %d", size)
}

if size > c.maxSize {
return false, fmt.Errorf("Unable to reserve space for blob (size: %d) larger than cache size %d", size, c.maxSize)
}

if sumLargerThan(size, c.reservedSize, c.maxSize) {
// If size + c.reservedSize is larger than c.maxSize
// then we cannot evict enough items to make enough
// space.
return false, nil
return false, fmt.Errorf("INTERNAL ERROR: unable to reserve enough space for blob with size %d (undersized cache?)", size)
}

// Evict elements until we are able to reserve enough space.
Expand Down

0 comments on commit 887e5e5

Please sign in to comment.