Revert "Reduce synchronization on field data cache"

This reverts commit 2e863572f4.

Relates #27365
This commit is contained in:
Jason Tedor 2017-11-14 05:57:51 -05:00
parent dd51c231ac
commit be399965e3
1 changed files with 12 additions and 17 deletions

View File

@ -114,24 +114,19 @@ public class IndexFieldDataService extends AbstractIndexComponent implements Clo
final String fieldName = fieldType.name();
IndexFieldData.Builder builder = fieldType.fielddataBuilder(fullyQualifiedIndexName);
IndexFieldDataCache cache = fieldDataCaches.get(fieldName);
if (cache == null) {
//for perf reason, only synchronize when cache is null
synchronized (this) {
cache = fieldDataCaches.get(fieldName);
//double checked locking to make sure it is thread safe
//especially when other threads calling clear() or clearField()
if (cache == null) {
String cacheType = indexSettings.getValue(INDEX_FIELDDATA_CACHE_KEY);
if (FIELDDATA_CACHE_VALUE_NODE.equals(cacheType)) {
cache = indicesFieldDataCache.buildIndexFieldDataCache(listener, index(), fieldName);
} else if ("none".equals(cacheType)){
cache = new IndexFieldDataCache.None();
} else {
throw new IllegalArgumentException("cache type not supported [" + cacheType + "] for field [" + fieldName + "]");
}
fieldDataCaches.put(fieldName, cache);
IndexFieldDataCache cache;
synchronized (this) {
cache = fieldDataCaches.get(fieldName);
if (cache == null) {
String cacheType = indexSettings.getValue(INDEX_FIELDDATA_CACHE_KEY);
if (FIELDDATA_CACHE_VALUE_NODE.equals(cacheType)) {
cache = indicesFieldDataCache.buildIndexFieldDataCache(listener, index(), fieldName);
} else if ("none".equals(cacheType)){
cache = new IndexFieldDataCache.None();
} else {
throw new IllegalArgumentException("cache type not supported [" + cacheType + "] for field [" + fieldName + "]");
}
fieldDataCaches.put(fieldName, cache);
}
}