diff --git a/core/src/main/java/org/elasticsearch/common/cache/Cache.java b/core/src/main/java/org/elasticsearch/common/cache/Cache.java index 004f5388557..d39b609e7ea 100644 --- a/core/src/main/java/org/elasticsearch/common/cache/Cache.java +++ b/core/src/main/java/org/elasticsearch/common/cache/Cache.java @@ -504,37 +504,37 @@ public class Cache { * @return the current cache statistics */ public CacheStats stats() { - int hits = 0; - int misses = 0; - int evictions = 0; + long hits = 0; + long misses = 0; + long evictions = 0; for (int i = 0; i < segments.length; i++) { - hits += segments[i].segmentStats.hits.intValue(); - misses += segments[i].segmentStats.misses.intValue(); - evictions += segments[i].segmentStats.evictions.intValue(); + hits += segments[i].segmentStats.hits.longValue(); + misses += segments[i].segmentStats.misses.longValue(); + evictions += segments[i].segmentStats.evictions.longValue(); } return new CacheStats(hits, misses, evictions); } public static class CacheStats { - private int hits; - private int misses; - private int evictions; + private long hits; + private long misses; + private long evictions; - public CacheStats(int hits, int misses, int evictions) { + public CacheStats(long hits, long misses, long evictions) { this.hits = hits; this.misses = misses; this.evictions = evictions; } - public int getHits() { + public long getHits() { return hits; } - public int getMisses() { + public long getMisses() { return misses; } - public int getEvictions() { + public long getEvictions() { return evictions; } } diff --git a/core/src/test/java/org/elasticsearch/common/cache/CacheTests.java b/core/src/test/java/org/elasticsearch/common/cache/CacheTests.java index 5f8c44660a2..d1481a5ad5b 100644 --- a/core/src/test/java/org/elasticsearch/common/cache/CacheTests.java +++ b/core/src/test/java/org/elasticsearch/common/cache/CacheTests.java @@ -25,7 +25,6 @@ import org.junit.Before; import java.util.*; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; -import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicReferenceArray; @@ -43,7 +42,7 @@ public class CacheTests extends ESTestCase { // cache some entries, then randomly lookup keys that do not exist, then check the stats public void testCacheStats() { - AtomicInteger evictions = new AtomicInteger(); + AtomicLong evictions = new AtomicLong(); Set keys = new HashSet<>(); Cache cache = CacheBuilder.builder() @@ -59,9 +58,9 @@ public class CacheTests extends ESTestCase { keys.add(i); cache.put(i, Integer.toString(i)); } - int hits = 0; - int misses = 0; - int missingKey = 0; + long hits = 0; + long misses = 0; + Integer missingKey = 0; for (Integer key : keys) { --missingKey; if (rarely()) { @@ -74,7 +73,7 @@ public class CacheTests extends ESTestCase { } assertEquals(hits, cache.stats().getHits()); assertEquals(misses, cache.stats().getMisses()); - assertEquals((int) Math.ceil(numberOfEntries / 2.0), evictions.get()); + assertEquals((long) Math.ceil(numberOfEntries / 2.0), evictions.get()); assertEquals(evictions.get(), cache.stats().getEvictions()); } @@ -84,7 +83,7 @@ public class CacheTests extends ESTestCase { // for each batch public void testCacheEvictions() { int maximumWeight = randomIntBetween(1, numberOfEntries); - AtomicInteger evictions = new AtomicInteger(); + AtomicLong evictions = new AtomicLong(); List evictedKeys = new ArrayList<>(); Cache cache = CacheBuilder.builder() @@ -145,7 +144,7 @@ public class CacheTests extends ESTestCase { public void testWeigher() { int maximumWeight = 2 * numberOfEntries; int weight = randomIntBetween(2, 10); - AtomicInteger evictions = new AtomicInteger(); + AtomicLong evictions = new AtomicLong(); Cache cache = CacheBuilder.builder() .setMaximumWeight(maximumWeight)