From 646ab22e3a5aabf0f2a53c5a8e6f47ea1932ead5 Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Wed, 24 Jul 2013 19:12:07 +0200 Subject: [PATCH] only process an internal refresh mapping once we only need to process a refresh on an index/type tuple once even if there are several pending, optimize to not do it several times --- .../cluster/metadata/MetaDataMappingService.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java b/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java index e456ec42e47..1efac00a684 100644 --- a/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java +++ b/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java @@ -26,6 +26,7 @@ import org.elasticsearch.cluster.*; import org.elasticsearch.cluster.action.index.NodeMappingCreatedAction; import org.elasticsearch.cluster.routing.IndexRoutingTable; import org.elasticsearch.common.Priority; +import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.compress.CompressedString; import org.elasticsearch.common.inject.Inject; @@ -113,6 +114,8 @@ public class MetaDataMappingService extends AbstractComponent { } Set indicesToRemove = Sets.newHashSet(); + // keep track of what we already refreshed, no need to refresh it again... + Set> processedRefreshes = Sets.newHashSet(); try { boolean dirty = false; MetaData.Builder mdBuilder = newMetaDataBuilder().metaData(currentState.metaData()); @@ -141,11 +144,16 @@ public class MetaDataMappingService extends AbstractComponent { IndexMetaData.Builder indexMetaDataBuilder = newIndexMetaDataBuilder(indexMetaData); List updatedTypes = Lists.newArrayList(); for (String type : refreshTask.types) { + Tuple processedRefresh = Tuple.tuple(index, type); + if (processedRefreshes.contains(processedRefresh)) { + continue; + } DocumentMapper mapper = indexService.mapperService().documentMapper(type); if (!mapper.mappingSource().equals(indexMetaData.mappings().get(type).source())) { updatedTypes.add(type); indexMetaDataBuilder.putMapping(new MappingMetaData(mapper)); } + processedRefreshes.add(processedRefresh); } if (updatedTypes.isEmpty()) { @@ -184,6 +192,7 @@ public class MetaDataMappingService extends AbstractComponent { } DocumentMapper updatedMapper = indexService.mapperService().merge(type, mappingSource.string(), false); + processedRefreshes.add(Tuple.tuple(index, type)); // if we end up with the same mapping as the original once, ignore if (indexMetaData.mappings().containsKey(type) && indexMetaData.mapping(type).source().equals(updatedMapper.mappingSource())) {