Skip to content

Commit 887e5e5

Browse files
committed
[disk] SizedLRU.Reserve should return a non-nil error if unable to reserve the required space
Relates to buchgr#649
1 parent c5bf6e1 commit 887e5e5

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

cache/disk/lru.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,15 +215,19 @@ func (c *SizedLRU) Reserve(size int64) (bool, error) {
215215
return true, nil
216216
}
217217

218-
if size < 0 || size > c.maxSize {
219-
return false, nil
218+
if size < 0 {
219+
return false, fmt.Errorf("Invalid negative blob size: %d", size)
220+
}
221+
222+
if size > c.maxSize {
223+
return false, fmt.Errorf("Unable to reserve space for blob (size: %d) larger than cache size %d", size, c.maxSize)
220224
}
221225

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

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

0 commit comments

Comments
 (0)