Skip to content

Commit bcc438a

Browse files
committed
Revert "Reduce synchronization on field data cache"
This reverts commit bda9257. Relates #27365
1 parent 855d98b commit bcc438a

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

core/src/main/java/org/elasticsearch/index/fielddata/IndexFieldDataService.java

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -110,24 +110,19 @@ public <IFD extends IndexFieldData<?>> IFD getForField(MappedFieldType fieldType
110110
final String fieldName = fieldType.name();
111111
IndexFieldData.Builder builder = fieldType.fielddataBuilder();
112112

113-
IndexFieldDataCache cache = fieldDataCaches.get(fieldName);
114-
if (cache == null) {
115-
//for perf reason, only synchronize when cache is null
116-
synchronized (this) {
117-
cache = fieldDataCaches.get(fieldName);
118-
//double checked locking to make sure it is thread safe
119-
//especially when other threads calling clear() or clearField()
120-
if (cache == null) {
121-
String cacheType = indexSettings.getValue(INDEX_FIELDDATA_CACHE_KEY);
122-
if (FIELDDATA_CACHE_VALUE_NODE.equals(cacheType)) {
123-
cache = indicesFieldDataCache.buildIndexFieldDataCache(listener, index(), fieldName);
124-
} else if ("none".equals(cacheType)){
125-
cache = new IndexFieldDataCache.None();
126-
} else {
127-
throw new IllegalArgumentException("cache type not supported [" + cacheType + "] for field [" + fieldName + "]");
128-
}
129-
fieldDataCaches.put(fieldName, cache);
113+
IndexFieldDataCache cache;
114+
synchronized (this) {
115+
cache = fieldDataCaches.get(fieldName);
116+
if (cache == null) {
117+
String cacheType = indexSettings.getValue(INDEX_FIELDDATA_CACHE_KEY);
118+
if (FIELDDATA_CACHE_VALUE_NODE.equals(cacheType)) {
119+
cache = indicesFieldDataCache.buildIndexFieldDataCache(listener, index(), fieldName);
120+
} else if ("none".equals(cacheType)){
121+
cache = new IndexFieldDataCache.None();
122+
} else {
123+
throw new IllegalArgumentException("cache type not supported [" + cacheType + "] for field [" + fieldName + "]");
130124
}
125+
fieldDataCaches.put(fieldName, cache);
131126
}
132127
}
133128

0 commit comments

Comments
 (0)