From ef0e3db0de6928ddca70d18e929223980f283fe1 Mon Sep 17 00:00:00 2001 From: Jim Ferenczi Date: Tue, 28 Jun 2016 12:16:17 +0200 Subject: [PATCH] Validates new dynamic settings from the current state Thanks to https://github.com/elastic/elasticsearch/pull/19088 the settings are now validated against dynamic updaters on the master. Though only the new settings are applied to the IndexService created for the validation. Because of this we cannot check the transition from one value to another in a dynamic updaters. This change creates the IndexService from the current settings and validates that the new dynamic settings can replace the current settings. This change also removes the validation of dynamic settings when an index is opened. The validation should have occurred when the settings have been updated. --- .../cluster/metadata/MetaDataIndexStateService.java | 2 +- .../metadata/MetaDataUpdateSettingsService.java | 10 +++++++--- .../main/java/org/elasticsearch/gateway/Gateway.java | 2 +- .../org/elasticsearch/indices/IndicesService.java | 12 ++++++++---- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexStateService.java b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexStateService.java index e6e7084e4d9..53a0ede809a 100644 --- a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexStateService.java +++ b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexStateService.java @@ -172,7 +172,7 @@ public class MetaDataIndexStateService extends AbstractComponent { // We need to check that this index can be upgraded to the current version indexMetaData = metaDataIndexUpgradeService.upgradeIndexMetaData(indexMetaData); try { - indicesService.verifyIndexMetadata(nodeServiceProvider, indexMetaData); + indicesService.verifyIndexMetadata(nodeServiceProvider, indexMetaData, indexMetaData); } catch (Exception e) { throw new ElasticsearchException("Failed to verify index " + indexMetaData.getIndex(), e); } diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataUpdateSettingsService.java b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataUpdateSettingsService.java index 54f6ad0705a..8bf7b5edd94 100644 --- a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataUpdateSettingsService.java +++ b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataUpdateSettingsService.java @@ -275,13 +275,17 @@ public class MetaDataUpdateSettingsService extends AbstractComponent implements updatedState = ClusterState.builder(updatedState).routingResult(routingResult).build(); try { for (Index index : openIndices) { - indicesService.verifyIndexMetadata(nodeServiceProvider, updatedState.getMetaData().getIndexSafe(index)); + final IndexMetaData currentMetaData = currentState.getMetaData().getIndexSafe(index); + final IndexMetaData updatedMetaData = updatedState.metaData().getIndexSafe(index); + indicesService.verifyIndexMetadata(nodeServiceProvider, currentMetaData, updatedMetaData); } for (Index index : closeIndices) { - indicesService.verifyIndexMetadata(nodeServiceProvider, updatedState.getMetaData().getIndexSafe(index)); + final IndexMetaData currentMetaData = currentState.getMetaData().getIndexSafe(index); + final IndexMetaData updatedMetaData = updatedState.metaData().getIndexSafe(index); + indicesService.verifyIndexMetadata(nodeServiceProvider, currentMetaData, updatedMetaData); } } catch (IOException ex) { - ExceptionsHelper.convertToElastic(ex); + throw ExceptionsHelper.convertToElastic(ex); } return updatedState; } diff --git a/core/src/main/java/org/elasticsearch/gateway/Gateway.java b/core/src/main/java/org/elasticsearch/gateway/Gateway.java index af86633e235..d83a738aedf 100644 --- a/core/src/main/java/org/elasticsearch/gateway/Gateway.java +++ b/core/src/main/java/org/elasticsearch/gateway/Gateway.java @@ -141,7 +141,7 @@ public class Gateway extends AbstractComponent implements ClusterStateListener { try { if (electedIndexMetaData.getState() == IndexMetaData.State.OPEN) { // verify that we can actually create this index - if not we recover it as closed with lots of warn logs - indicesService.verifyIndexMetadata(nodeServicesProvider, electedIndexMetaData); + indicesService.verifyIndexMetadata(nodeServicesProvider, electedIndexMetaData, electedIndexMetaData); } } catch (Exception e) { logger.warn("recovering index {} failed - recovering as closed", e, electedIndexMetaData.getIndex()); diff --git a/core/src/main/java/org/elasticsearch/indices/IndicesService.java b/core/src/main/java/org/elasticsearch/indices/IndicesService.java index 89cfad98c4f..b8b9b827e4b 100644 --- a/core/src/main/java/org/elasticsearch/indices/IndicesService.java +++ b/core/src/main/java/org/elasticsearch/indices/IndicesService.java @@ -412,10 +412,12 @@ public class IndicesService extends AbstractLifecycleComponent } /** - * This method verifies that the given {@link IndexMetaData} holds sane values to create an {@link IndexService}. This method will throw an - * exception if the creation fails. The created {@link IndexService} will not be registered and will be closed immediately. + * This method verifies that the given {@code metaData} holds sane values to create an {@link IndexService}. + * This method tries to update the meta data of the created {@link IndexService} if the given {@code metaDataUpdate} is different from the given {@code metaData}. + * This method will throw an exception if the creation or the update fails. + * The created {@link IndexService} will not be registered and will be closed immediately. */ - public synchronized void verifyIndexMetadata(final NodeServicesProvider nodeServicesProvider, IndexMetaData metaData) throws IOException { + public synchronized void verifyIndexMetadata(final NodeServicesProvider nodeServicesProvider, IndexMetaData metaData, IndexMetaData metaDataUpdate) throws IOException { final List closeables = new ArrayList<>(); try { IndicesFieldDataCache indicesFieldDataCache = new IndicesFieldDataCache(settings, new IndexFieldDataCache.Listener() {}); @@ -431,7 +433,9 @@ public class IndicesService extends AbstractLifecycleComponent service.mapperService().merge(typeMapping.value.type(), typeMapping.value.source(), MapperService.MergeReason.MAPPING_RECOVERY, true); } - service.getIndexSettings().getScopedSettings().validateUpdate(metaData.getSettings()); + if (metaData.equals(metaDataUpdate) == false) { + service.updateMetaData(metaDataUpdate); + } } finally { IOUtils.close(closeables); }