@@ -114,24 +114,19 @@ public <IFD extends IndexFieldData<?>> IFD getForField(MappedFieldType fieldType
114114 final String fieldName = fieldType .name ();
115115 IndexFieldData .Builder builder = fieldType .fielddataBuilder (fullyQualifiedIndexName );
116116
117- IndexFieldDataCache cache = fieldDataCaches .get (fieldName );
118- if (cache == null ) {
119- //for perf reason, only synchronize when cache is null
120- synchronized (this ) {
121- cache = fieldDataCaches .get (fieldName );
122- //double checked locking to make sure it is thread safe
123- //especially when other threads calling clear() or clearField()
124- if (cache == null ) {
125- String cacheType = indexSettings .getValue (INDEX_FIELDDATA_CACHE_KEY );
126- if (FIELDDATA_CACHE_VALUE_NODE .equals (cacheType )) {
127- cache = indicesFieldDataCache .buildIndexFieldDataCache (listener , index (), fieldName );
128- } else if ("none" .equals (cacheType )){
129- cache = new IndexFieldDataCache .None ();
130- } else {
131- throw new IllegalArgumentException ("cache type not supported [" + cacheType + "] for field [" + fieldName + "]" );
132- }
133- fieldDataCaches .put (fieldName , cache );
117+ IndexFieldDataCache cache ;
118+ synchronized (this ) {
119+ cache = fieldDataCaches .get (fieldName );
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 + "]" );
134128 }
129+ fieldDataCaches .put (fieldName , cache );
135130 }
136131 }
137132
0 commit comments