@@ -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