improve concurrency when loading field data

This commit is contained in:
kimchy 2010-08-02 18:20:49 +03:00
parent 7719dcd790
commit 4e6087ee2d
5 changed files with 6 additions and 13 deletions

View File

@ -26,7 +26,7 @@ import org.elasticsearch.index.field.data.FieldData;
import java.io.IOException; import java.io.IOException;
/** /**
* @author kimchy (Shay Banon) * @author kimchy (shay.banon)
*/ */
public interface FieldDataCache extends CloseableComponent { public interface FieldDataCache extends CloseableComponent {

View File

@ -32,7 +32,7 @@ import org.elasticsearch.index.settings.IndexSettings;
import java.io.IOException; import java.io.IOException;
/** /**
* @author kimchy (Shay Banon) * @author kimchy (shay.banon)
*/ */
public class NoneFieldDataCache extends AbstractIndexComponent implements FieldDataCache { public class NoneFieldDataCache extends AbstractIndexComponent implements FieldDataCache {

View File

@ -30,7 +30,7 @@ import org.elasticsearch.index.settings.IndexSettings;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
/** /**
* @author kimchy (Shay Banon) * @author kimchy (shay.banon)
*/ */
public class SoftFieldDataCache extends AbstractConcurrentMapFieldDataCache { public class SoftFieldDataCache extends AbstractConcurrentMapFieldDataCache {

View File

@ -33,7 +33,7 @@ import java.io.IOException;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
/** /**
* @author kimchy (Shay Banon) * @author kimchy (shay.banon)
*/ */
public abstract class AbstractConcurrentMapFieldDataCache extends AbstractIndexComponent implements FieldDataCache { public abstract class AbstractConcurrentMapFieldDataCache extends AbstractIndexComponent implements FieldDataCache {
@ -76,23 +76,16 @@ public abstract class AbstractConcurrentMapFieldDataCache extends AbstractIndexC
fieldDataCache = ConcurrentCollections.newConcurrentMap(); fieldDataCache = ConcurrentCollections.newConcurrentMap();
cache.put(reader.getFieldCacheKey(), fieldDataCache); cache.put(reader.getFieldCacheKey(), fieldDataCache);
} }
T fieldData = (T) fieldDataCache.get(fieldName);
if (fieldData == null) {
fieldData = FieldData.load(type, reader, fieldName);
fieldDataCache.put(fieldName, fieldData);
}
return fieldData;
} }
} }
T fieldData = (T) fieldDataCache.get(fieldName); T fieldData = (T) fieldDataCache.get(fieldName);
if (fieldData == null) { if (fieldData == null) {
synchronized (creationMutex) { synchronized (fieldDataCache) {
fieldData = (T) fieldDataCache.get(fieldName); fieldData = (T) fieldDataCache.get(fieldName);
if (fieldData == null) { if (fieldData == null) {
fieldData = FieldData.load(type, reader, fieldName); fieldData = FieldData.load(type, reader, fieldName);
fieldDataCache.put(fieldName, fieldData); fieldDataCache.put(fieldName, fieldData);
} }
return fieldData;
} }
} }
return fieldData; return fieldData;

View File

@ -30,7 +30,7 @@ import org.elasticsearch.index.settings.IndexSettings;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
/** /**
* @author kimchy (Shay Banon) * @author kimchy (shay.banon)
*/ */
public class WeakFieldDataCache extends AbstractConcurrentMapFieldDataCache { public class WeakFieldDataCache extends AbstractConcurrentMapFieldDataCache {