Skip to content

Commit 76d506d

Browse files
jpountzareek
authored andcommitted
Internal: Upgrade Guava to 18.0.
17.0 and earlier versions were affected by the following bug https://code.google.com/p/guava-libraries/issues/detail?id=1761 which caused caches that are configured with weights that are greater than 32GB to actually be unbounded. This is now fixed. Relates to #6268 Close #7593
1 parent 6a2fb21 commit 76d506d

File tree

6 files changed

+4
-130
lines changed

6 files changed

+4
-130
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@
191191
<dependency>
192192
<groupId>com.google.guava</groupId>
193193
<artifactId>guava</artifactId>
194-
<version>17.0</version>
194+
<version>18.0</version>
195195
<scope>compile</scope>
196196
</dependency>
197197

src/main/java/org/elasticsearch/common/unit/ByteSizeValue.java

-8
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,6 @@
3434
*
3535
*/
3636
public class ByteSizeValue implements Serializable, Streamable {
37-
/**
38-
* Largest size possible for Guava caches to prevent overflow. Guava's
39-
* caches use integers to track weight per segment and we always 16 segments
40-
* so caches of 32GB would always overflow that integer and they'd never be
41-
* evicted by size. We set this to 31.9GB leaving 100MB of headroom to
42-
* prevent overflow.
43-
*/
44-
public static final ByteSizeValue MAX_GUAVA_CACHE_SIZE = new ByteSizeValue(32 * ByteSizeUnit.C3 - 100 * ByteSizeUnit.C2);
4537

4638
private long size;
4739

src/main/java/org/elasticsearch/indices/cache/filter/IndicesFilterCache.java

+1-10
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,7 @@ private void buildCache() {
119119
}
120120

121121
private void computeSizeInBytes() {
122-
long sizeInBytes = MemorySizeValue.parseBytesSizeValueOrHeapRatio(size).bytes();
123-
if (sizeInBytes > ByteSizeValue.MAX_GUAVA_CACHE_SIZE.bytes()) {
124-
logger.warn("reducing requested filter cache size of [{}] to the maximum allowed size of [{}]", new ByteSizeValue(sizeInBytes),
125-
ByteSizeValue.MAX_GUAVA_CACHE_SIZE);
126-
sizeInBytes = ByteSizeValue.MAX_GUAVA_CACHE_SIZE.bytes();
127-
// Even though it feels wrong for size and sizeInBytes to get out of
128-
// sync we don't update size here because it might cause the cache
129-
// to be rebuilt every time new settings are applied.
130-
}
131-
this.sizeInBytes = sizeInBytes;
122+
this.sizeInBytes = MemorySizeValue.parseBytesSizeValueOrHeapRatio(size).bytes();
132123
}
133124

134125
public void addReaderKeyToClean(Object readerKey) {

src/main/java/org/elasticsearch/indices/cache/query/IndicesQueryCache.java

-8
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import org.elasticsearch.common.io.stream.StreamInput;
3939
import org.elasticsearch.common.io.stream.StreamOutput;
4040
import org.elasticsearch.common.settings.Settings;
41-
import org.elasticsearch.common.unit.ByteSizeValue;
4241
import org.elasticsearch.common.unit.MemorySizeValue;
4342
import org.elasticsearch.common.unit.TimeValue;
4443
import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
@@ -118,13 +117,6 @@ public IndicesQueryCache(Settings settings, ClusterService clusterService, Threa
118117

119118
private void buildCache() {
120119
long sizeInBytes = MemorySizeValue.parseBytesSizeValueOrHeapRatio(size).bytes();
121-
if (sizeInBytes > ByteSizeValue.MAX_GUAVA_CACHE_SIZE.bytes()) {
122-
logger.warn("reducing requested query cache size of [{}] to the maximum allowed size of [{}]", new ByteSizeValue(sizeInBytes), ByteSizeValue.MAX_GUAVA_CACHE_SIZE);
123-
sizeInBytes = ByteSizeValue.MAX_GUAVA_CACHE_SIZE.bytes();
124-
// Even though it feels wrong for size and sizeInBytes to get out of
125-
// sync we don't update size here because it might cause the cache
126-
// to be rebuilt every time new settings are applied.
127-
}
128120

129121
CacheBuilder<Key, BytesReference> cacheBuilder = CacheBuilder.newBuilder()
130122
.maximumWeight(sizeInBytes).weigher(new QueryCacheWeigher()).removalListener(this);

src/main/java/org/elasticsearch/indices/fielddata/cache/IndicesFieldDataCache.java

+2-8
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,8 @@ public IndicesFieldDataCache(Settings settings, IndicesFieldDataCacheListener in
6565
super(settings);
6666
this.threadPool = threadPool;
6767
this.indicesFieldDataCacheListener = indicesFieldDataCacheListener;
68-
String size = componentSettings.get("size", "-1");
69-
long sizeInBytes = componentSettings.getAsMemory("size", "-1").bytes();
70-
if (sizeInBytes > ByteSizeValue.MAX_GUAVA_CACHE_SIZE.bytes()) {
71-
logger.warn("reducing requested field data cache size of [{}] to the maximum allowed size of [{}]", new ByteSizeValue(sizeInBytes),
72-
ByteSizeValue.MAX_GUAVA_CACHE_SIZE);
73-
sizeInBytes = ByteSizeValue.MAX_GUAVA_CACHE_SIZE.bytes();
74-
size = ByteSizeValue.MAX_GUAVA_CACHE_SIZE.toString();
75-
}
68+
final String size = componentSettings.get("size", "-1");
69+
final long sizeInBytes = componentSettings.getAsMemory("size", "-1").bytes();
7670
final TimeValue expire = componentSettings.getAsTime("expire", null);
7771
CacheBuilder<Key, Accountable> cacheBuilder = CacheBuilder.newBuilder()
7872
.removalListener(this);

src/test/java/org/elasticsearch/common/util/GuavaCacheOverflowTest.java

-95
This file was deleted.

0 commit comments

Comments
 (0)