|
|
@@ -19,14 +19,12 @@
|
|
|
|
|
|
package org.elasticsearch.indices.fielddata.cache;
|
|
|
|
|
|
-import java.util.Collections;
|
|
|
-
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
import org.apache.logging.log4j.Logger;
|
|
|
import org.apache.lucene.index.DirectoryReader;
|
|
|
import org.apache.lucene.index.IndexReader;
|
|
|
-import org.apache.lucene.index.LeafReaderContext;
|
|
|
import org.apache.lucene.index.IndexReader.CacheKey;
|
|
|
+import org.apache.lucene.index.LeafReaderContext;
|
|
|
import org.apache.lucene.util.Accountable;
|
|
|
import org.elasticsearch.common.Nullable;
|
|
|
import org.elasticsearch.common.cache.Cache;
|
|
|
@@ -46,8 +44,8 @@ import org.elasticsearch.index.fielddata.IndexFieldDataCache;
|
|
|
import org.elasticsearch.index.shard.ShardId;
|
|
|
import org.elasticsearch.index.shard.ShardUtils;
|
|
|
|
|
|
-import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
import java.util.function.ToLongBiFunction;
|
|
|
|
|
|
@@ -130,6 +128,7 @@ public class IndicesFieldDataCache implements RemovalListener<IndicesFieldDataCa
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
public <FD extends AtomicFieldData, IFD extends IndexFieldData<FD>> FD load(final LeafReaderContext context,
|
|
|
final IFD indexFieldData) throws Exception {
|
|
|
final ShardId shardId = ShardUtils.extractShardId(context.reader());
|
|
|
@@ -138,7 +137,6 @@ public class IndicesFieldDataCache implements RemovalListener<IndicesFieldDataCa
|
|
|
throw new IllegalArgumentException("Reader " + context.reader() + " does not support caching");
|
|
|
}
|
|
|
final Key key = new Key(this, cacheHelper.getKey(), shardId);
|
|
|
- //noinspection unchecked
|
|
|
final Accountable accountable = cache.computeIfAbsent(key, k -> {
|
|
|
cacheHelper.addClosedListener(IndexFieldCache.this);
|
|
|
Collections.addAll(k.listeners, this.listeners);
|
|
|
@@ -157,6 +155,7 @@ public class IndicesFieldDataCache implements RemovalListener<IndicesFieldDataCa
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
public <FD extends AtomicFieldData, IFD extends IndexFieldData.Global<FD>> IFD load(final DirectoryReader indexReader,
|
|
|
final IFD indexFieldData) throws Exception {
|
|
|
final ShardId shardId = ShardUtils.extractShardId(indexReader);
|
|
|
@@ -165,7 +164,6 @@ public class IndicesFieldDataCache implements RemovalListener<IndicesFieldDataCa
|
|
|
throw new IllegalArgumentException("Reader " + indexReader + " does not support caching");
|
|
|
}
|
|
|
final Key key = new Key(this, cacheHelper.getKey(), shardId);
|
|
|
- //noinspection unchecked
|
|
|
final Accountable accountable = cache.computeIfAbsent(key, k -> {
|
|
|
ElasticsearchDirectoryReader.addReaderCloseListener(indexReader, IndexFieldCache.this);
|
|
|
Collections.addAll(k.listeners, this.listeners);
|
|
|
@@ -184,7 +182,7 @@ public class IndicesFieldDataCache implements RemovalListener<IndicesFieldDataCa
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void onClose(CacheKey key) throws IOException {
|
|
|
+ public void onClose(CacheKey key) {
|
|
|
cache.invalidate(new Key(this, key, null));
|
|
|
// don't call cache.cleanUp here as it would have bad performance implications
|
|
|
}
|