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.
This commit is contained in:
parent
fa4844c3f4
commit
ef0e3db0de
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -412,10 +412,12 @@ public class IndicesService extends AbstractLifecycleComponent<IndicesService>
|
|||
}
|
||||
|
||||
/**
|
||||
* 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<Closeable> closeables = new ArrayList<>();
|
||||
try {
|
||||
IndicesFieldDataCache indicesFieldDataCache = new IndicesFieldDataCache(settings, new IndexFieldDataCache.Listener() {});
|
||||
|
@ -431,7 +433,9 @@ public class IndicesService extends AbstractLifecycleComponent<IndicesService>
|
|||
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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue