only check if settings need to change or mappings need to be checked if the index metadata has actually changed

This commit is contained in:
Shay Banon 2012-02-03 14:20:42 +02:00
parent 68f838a488
commit e06de6b24c
2 changed files with 27 additions and 0 deletions

View File

@ -21,6 +21,8 @@ package org.elasticsearch.cluster;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.node.DiscoveryNodes;
import java.util.List; import java.util.List;
@ -122,6 +124,20 @@ public class ClusterChangedEvent {
return state.metaData() != previousState.metaData(); return state.metaData() != previousState.metaData();
} }
public boolean indexMetaDataChanged(IndexMetaData current) {
MetaData previousMetaData = previousState.metaData();
if (previousMetaData == null) {
return true;
}
IndexMetaData previousIndexMetaData = previousMetaData.index(current.index());
// no need to check on version, since disco modules will make sure to use the
// same instance if its a version match
if (previousIndexMetaData == current) {
return false;
}
return false;
}
public boolean blocksChanged() { public boolean blocksChanged() {
return state.blocks() != previousState.blocks(); return state.blocks() != previousState.blocks();
} }

View File

@ -304,11 +304,18 @@ public class IndicesClusterStateService extends AbstractLifecycleComponent<Indic
} }
private void applySettings(ClusterChangedEvent event) { private void applySettings(ClusterChangedEvent event) {
if (!event.metaDataChanged()) {
return;
}
for (IndexMetaData indexMetaData : event.state().metaData()) { for (IndexMetaData indexMetaData : event.state().metaData()) {
if (!indicesService.hasIndex(indexMetaData.index())) { if (!indicesService.hasIndex(indexMetaData.index())) {
// we only create / update here // we only create / update here
continue; continue;
} }
// if the index meta data didn't change, no need check for refreshed settings
if (!event.indexMetaDataChanged(indexMetaData)) {
continue;
}
String index = indexMetaData.index(); String index = indexMetaData.index();
IndexService indexService = indicesService.indexServiceSafe(index); IndexService indexService = indicesService.indexServiceSafe(index);
IndexSettingsService indexSettingsService = indexService.injector().getInstance(IndexSettingsService.class); IndexSettingsService indexSettingsService = indexService.injector().getInstance(IndexSettingsService.class);
@ -324,6 +331,10 @@ public class IndicesClusterStateService extends AbstractLifecycleComponent<Indic
// we only create / update here // we only create / update here
continue; continue;
} }
// if the index meta data didn't change, no need check for refreshed settings
if (!event.indexMetaDataChanged(indexMetaData)) {
continue;
}
List<String> typesToRefresh = null; List<String> typesToRefresh = null;
String index = indexMetaData.index(); String index = indexMetaData.index();
IndexService indexService = indicesService.indexServiceSafe(index); IndexService indexService = indicesService.indexServiceSafe(index);