From 4e6087ee2de4b6a4e66b8767cd7a3134a82356b1 Mon Sep 17 00:00:00 2001 From: kimchy Date: Mon, 2 Aug 2010 18:20:49 +0300 Subject: [PATCH] improve concurrency when loading field data --- .../index/cache/field/data/FieldDataCache.java | 2 +- .../cache/field/data/none/NoneFieldDataCache.java | 2 +- .../cache/field/data/soft/SoftFieldDataCache.java | 2 +- .../support/AbstractConcurrentMapFieldDataCache.java | 11 ++--------- .../cache/field/data/weak/WeakFieldDataCache.java | 2 +- 5 files changed, 6 insertions(+), 13 deletions(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/field/data/FieldDataCache.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/field/data/FieldDataCache.java index 15435996b42..f312bfa4cfa 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/field/data/FieldDataCache.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/field/data/FieldDataCache.java @@ -26,7 +26,7 @@ import org.elasticsearch.index.field.data.FieldData; import java.io.IOException; /** - * @author kimchy (Shay Banon) + * @author kimchy (shay.banon) */ public interface FieldDataCache extends CloseableComponent { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/field/data/none/NoneFieldDataCache.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/field/data/none/NoneFieldDataCache.java index 53265334fdf..8320cdc1261 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/field/data/none/NoneFieldDataCache.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/field/data/none/NoneFieldDataCache.java @@ -32,7 +32,7 @@ import org.elasticsearch.index.settings.IndexSettings; import java.io.IOException; /** - * @author kimchy (Shay Banon) + * @author kimchy (shay.banon) */ public class NoneFieldDataCache extends AbstractIndexComponent implements FieldDataCache { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/field/data/soft/SoftFieldDataCache.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/field/data/soft/SoftFieldDataCache.java index 9dd9767e494..4a2224e2a91 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/field/data/soft/SoftFieldDataCache.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/field/data/soft/SoftFieldDataCache.java @@ -30,7 +30,7 @@ import org.elasticsearch.index.settings.IndexSettings; import java.util.concurrent.ConcurrentMap; /** - * @author kimchy (Shay Banon) + * @author kimchy (shay.banon) */ public class SoftFieldDataCache extends AbstractConcurrentMapFieldDataCache { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/field/data/support/AbstractConcurrentMapFieldDataCache.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/field/data/support/AbstractConcurrentMapFieldDataCache.java index 79c9eee8fb4..b3eceef6e51 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/field/data/support/AbstractConcurrentMapFieldDataCache.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/field/data/support/AbstractConcurrentMapFieldDataCache.java @@ -33,7 +33,7 @@ import java.io.IOException; import java.util.concurrent.ConcurrentMap; /** - * @author kimchy (Shay Banon) + * @author kimchy (shay.banon) */ public abstract class AbstractConcurrentMapFieldDataCache extends AbstractIndexComponent implements FieldDataCache { @@ -76,23 +76,16 @@ public abstract class AbstractConcurrentMapFieldDataCache extends AbstractIndexC fieldDataCache = ConcurrentCollections.newConcurrentMap(); 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); if (fieldData == null) { - synchronized (creationMutex) { + synchronized (fieldDataCache) { fieldData = (T) fieldDataCache.get(fieldName); if (fieldData == null) { fieldData = FieldData.load(type, reader, fieldName); fieldDataCache.put(fieldName, fieldData); } - return fieldData; } } return fieldData; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/field/data/weak/WeakFieldDataCache.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/field/data/weak/WeakFieldDataCache.java index 3200549888f..55680dbd117 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/field/data/weak/WeakFieldDataCache.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/field/data/weak/WeakFieldDataCache.java @@ -30,7 +30,7 @@ import org.elasticsearch.index.settings.IndexSettings; import java.util.concurrent.ConcurrentMap; /** - * @author kimchy (Shay Banon) + * @author kimchy (shay.banon) */ public class WeakFieldDataCache extends AbstractConcurrentMapFieldDataCache {