From 83e561d19f8aa2f3733db0ed159dc3f19f4b5272 Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Wed, 1 Feb 2012 21:17:07 +0200 Subject: [PATCH] only update new versioned index or new indices when a new cluster state is received --- .../elasticsearch/discovery/zen/ZenDiscovery.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java b/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java index d1f1c72d47f..4faa8f6b004 100644 --- a/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java +++ b/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java @@ -24,6 +24,7 @@ import org.elasticsearch.ElasticSearchException; import org.elasticsearch.ElasticSearchIllegalStateException; import org.elasticsearch.cluster.*; import org.elasticsearch.cluster.block.ClusterBlocks; +import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeService; @@ -492,6 +493,18 @@ public class ZenDiscovery extends AbstractLifecycleComponent implemen // same for metadata if (newState.metaData().version() == currentState.metaData().version()) { builder.metaData(currentState.metaData()); + } else { + // if its not the same version, only copy over new indices or ones that changed the version + MetaData.Builder metaDataBuilder = MetaData.builder().metaData(newState.metaData()).removeAllIndices(); + for (IndexMetaData indexMetaData : newState.metaData()) { + IndexMetaData currentIndexMetaData = currentState.metaData().index(indexMetaData.index()); + if (currentIndexMetaData == null || currentIndexMetaData.version() != indexMetaData.version()) { + metaDataBuilder.put(indexMetaData, false); + } else { + metaDataBuilder.put(currentIndexMetaData, false); + } + } + builder.metaData(metaDataBuilder); } return builder.build();