Skip to content

LocalCache weight eviction does not work when maxSegmentWeight is >= int.MAX_VALUE #1761

@gissuebot

Description

@gissuebot

Original issue created by DanGLow on 2014-05-22 at 05:18 PM


Hi,

This bug was originally discovered here: elastic/elasticsearch#6268, but I have traced it down into an issue with an overflowing int and long comparison in LocalCache.java eviction logic. The following is the eviction code at https://github.com/google/guava/blob/master/guava/src/com/google/common/cache/LocalCache.java#L2665

@GuardedBy("Segment.this")
void evictEntries() {
  if (!map.evictsBySize()) {
    return;
  }

  drainRecencyQueue();
  while (totalWeight > maxSegmentWeight) {
    ReferenceEntry<K, V> e = getNextEvictable();
    if (!removeEntry(e, e.getHash(), RemovalCause.SIZE)) {
      throw new AssertionError();
    }
  }
}

'totalWeight' is defined as an int, while 'maxSegmentWeight' is a long. If 'maxSegmentWeight' is set to any value int.MAX_VALUE or greater, then this check

  while (totalWeight > maxSegmentWeight) {

will never be true, since 'totalWeight' will overflow, and the eviction code will never run.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions