improve index and shard creation failure messages
This commit is contained in:
parent
b0caf0d761
commit
d92dc36213
|
@ -106,7 +106,12 @@ public class MetaDataIndexAliasesService extends AbstractComponent {
|
||||||
indexService = indicesService.indexService(indexMetaData.index());
|
indexService = indicesService.indexService(indexMetaData.index());
|
||||||
if (indexService == null) {
|
if (indexService == null) {
|
||||||
// temporarily create the index so we have can parse the filter
|
// temporarily create the index so we have can parse the filter
|
||||||
indexService = indicesService.createIndex(indexMetaData.index(), indexMetaData.settings(), currentState.nodes().localNode().id());
|
try {
|
||||||
|
indexService = indicesService.createIndex(indexMetaData.index(), indexMetaData.settings(), currentState.nodes().localNode().id());
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.warn("[{}] failed to temporary create in order to apply alias action", e, indexMetaData.index());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
indicesToClose.add(indexMetaData.index());
|
indicesToClose.add(indexMetaData.index());
|
||||||
}
|
}
|
||||||
indices.put(indexMetaData.index(), indexService);
|
indices.put(indexMetaData.index(), indexService);
|
||||||
|
|
|
@ -22,6 +22,7 @@ package org.elasticsearch.common.inject;
|
||||||
import org.elasticsearch.common.collect.Sets;
|
import org.elasticsearch.common.collect.Sets;
|
||||||
import org.elasticsearch.common.inject.matcher.Matcher;
|
import org.elasticsearch.common.inject.matcher.Matcher;
|
||||||
import org.elasticsearch.common.inject.name.Names;
|
import org.elasticsearch.common.inject.name.Names;
|
||||||
|
import org.elasticsearch.common.inject.spi.Message;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -33,6 +34,19 @@ import java.util.Set;
|
||||||
*/
|
*/
|
||||||
public class Injectors {
|
public class Injectors {
|
||||||
|
|
||||||
|
public static Throwable getFirstErrorFailure(CreationException e) {
|
||||||
|
if (e.getErrorMessages().isEmpty()) {
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
// return the first message that has root cause, probably an actual error
|
||||||
|
for (Message message : e.getErrorMessages()) {
|
||||||
|
if (message.getCause() != null) {
|
||||||
|
return message.getCause();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an instance of the given type with the {@link org.elasticsearch.common.inject.name.Named}
|
* Returns an instance of the given type with the {@link org.elasticsearch.common.inject.name.Named}
|
||||||
* annotation value.
|
* annotation value.
|
||||||
|
|
|
@ -19,9 +19,6 @@ package org.elasticsearch.common.inject;
|
||||||
import org.elasticsearch.common.inject.internal.Errors;
|
import org.elasticsearch.common.inject.internal.Errors;
|
||||||
import org.elasticsearch.common.inject.spi.Message;
|
import org.elasticsearch.common.inject.spi.Message;
|
||||||
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles {@link Binder#addError} commands.
|
* Handles {@link Binder#addError} commands.
|
||||||
*
|
*
|
||||||
|
@ -30,19 +27,20 @@ import java.util.logging.Logger;
|
||||||
*/
|
*/
|
||||||
class MessageProcessor extends AbstractProcessor {
|
class MessageProcessor extends AbstractProcessor {
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(Guice.class.getName());
|
//private static final Logger logger = Logger.getLogger(Guice.class.getName());
|
||||||
|
|
||||||
MessageProcessor(Errors errors) {
|
MessageProcessor(Errors errors) {
|
||||||
super(errors);
|
super(errors);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public Boolean visit(Message message) {
|
@Override public Boolean visit(Message message) {
|
||||||
if (message.getCause() != null) {
|
// ES_GUICE: don't log failures using jdk logging
|
||||||
String rootMessage = getRootMessage(message.getCause());
|
// if (message.getCause() != null) {
|
||||||
logger.log(Level.INFO,
|
// String rootMessage = getRootMessage(message.getCause());
|
||||||
"An exception was caught and reported. Message: " + rootMessage,
|
// logger.log(Level.INFO,
|
||||||
message.getCause());
|
// "An exception was caught and reported. Message: " + rootMessage,
|
||||||
}
|
// message.getCause());
|
||||||
|
// }
|
||||||
|
|
||||||
errors.addMessage(message);
|
errors.addMessage(message);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -231,9 +231,12 @@ public class AnalysisModule extends AbstractModule {
|
||||||
if (tokenFilterSettings.get("type") != null) {
|
if (tokenFilterSettings.get("type") != null) {
|
||||||
type = tokenFiltersBindings.tokenFilters.get(tokenFilterSettings.get("type"));
|
type = tokenFiltersBindings.tokenFilters.get(tokenFilterSettings.get("type"));
|
||||||
}
|
}
|
||||||
|
if (type == null) {
|
||||||
|
throw new ElasticSearchIllegalArgumentException("failed to find token filter type for [" + tokenFilterName + "]", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
throw new ElasticSearchIllegalArgumentException("Token Filter [" + tokenFilterName + "] must have a type associated with it");
|
throw new ElasticSearchIllegalArgumentException("token filter [" + tokenFilterName + "] must have a type associated with it");
|
||||||
}
|
}
|
||||||
tokenFilterBinder.addBinding(tokenFilterName).toProvider(FactoryProvider.newFactory(TokenFilterFactoryFactory.class, type)).in(Scopes.SINGLETON);
|
tokenFilterBinder.addBinding(tokenFilterName).toProvider(FactoryProvider.newFactory(TokenFilterFactoryFactory.class, type)).in(Scopes.SINGLETON);
|
||||||
}
|
}
|
||||||
|
@ -268,17 +271,21 @@ public class AnalysisModule extends AbstractModule {
|
||||||
String tokenizerName = entry.getKey();
|
String tokenizerName = entry.getKey();
|
||||||
Settings tokenizerSettings = entry.getValue();
|
Settings tokenizerSettings = entry.getValue();
|
||||||
|
|
||||||
Class<? extends TokenizerFactory> type = tokenizerSettings.getAsClass("type", null, "org.elasticsearch.index.analysis.", "TokenizerFactory");
|
try {
|
||||||
if (type == null) {
|
Class<? extends TokenizerFactory> type = tokenizerSettings.getAsClass("type", null, "org.elasticsearch.index.analysis.", "TokenizerFactory");
|
||||||
throw new ElasticSearchIllegalArgumentException("Tokenizer [" + tokenizerName + "] must have a type associated with it");
|
if (type == null) {
|
||||||
}
|
throw new ElasticSearchIllegalArgumentException("Tokenizer [" + tokenizerName + "] must have a type associated with it");
|
||||||
|
}
|
||||||
|
|
||||||
// if it requires settings, and it has none, then don't register it
|
// if it requires settings, and it has none, then don't register it
|
||||||
if (tokenizerSettings.getAsMap().isEmpty() && type.getAnnotation(AnalysisSettingsRequired.class) != null) {
|
if (tokenizerSettings.getAsMap().isEmpty() && type.getAnnotation(AnalysisSettingsRequired.class) != null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
tokenizerBinder.addBinding(tokenizerName).toProvider(FactoryProvider.newFactory(TokenizerFactoryFactory.class, type)).in(Scopes.SINGLETON);
|
tokenizerBinder.addBinding(tokenizerName).toProvider(FactoryProvider.newFactory(TokenizerFactoryFactory.class, type)).in(Scopes.SINGLETON);
|
||||||
|
} catch (NoClassSettingsException e) {
|
||||||
|
throw new ElasticSearchIllegalArgumentException("failed to find tokenizer type for [" + tokenizerName + "]", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AnalysisBinderProcessor.TokenizersBindings tokenizersBindings = new AnalysisBinderProcessor.TokenizersBindings(tokenizerBinder, tokenizersSettings, indicesAnalysisService);
|
AnalysisBinderProcessor.TokenizersBindings tokenizersBindings = new AnalysisBinderProcessor.TokenizersBindings(tokenizerBinder, tokenizersSettings, indicesAnalysisService);
|
||||||
|
@ -295,18 +302,22 @@ public class AnalysisModule extends AbstractModule {
|
||||||
for (Map.Entry<String, Settings> entry : analyzersSettings.entrySet()) {
|
for (Map.Entry<String, Settings> entry : analyzersSettings.entrySet()) {
|
||||||
String analyzerName = entry.getKey();
|
String analyzerName = entry.getKey();
|
||||||
Settings analyzerSettings = entry.getValue();
|
Settings analyzerSettings = entry.getValue();
|
||||||
Class<? extends AnalyzerProvider> type = analyzerSettings.getAsClass("type", null, "org.elasticsearch.index.analysis.", "AnalyzerProvider");
|
try {
|
||||||
if (type == null) {
|
Class<? extends AnalyzerProvider> type = analyzerSettings.getAsClass("type", null, "org.elasticsearch.index.analysis.", "AnalyzerProvider");
|
||||||
// no specific type, check if it has a tokenizer associated with it
|
if (type == null) {
|
||||||
String tokenizerName = analyzerSettings.get("tokenizer");
|
// no specific type, check if it has a tokenizer associated with it
|
||||||
if (tokenizerName != null) {
|
String tokenizerName = analyzerSettings.get("tokenizer");
|
||||||
// we have a tokenizer, use the CustomAnalyzer
|
if (tokenizerName != null) {
|
||||||
type = CustomAnalyzerProvider.class;
|
// we have a tokenizer, use the CustomAnalyzer
|
||||||
} else {
|
type = CustomAnalyzerProvider.class;
|
||||||
throw new ElasticSearchIllegalArgumentException("Analyzer [" + analyzerName + "] must have a type associated with it or a tokenizer");
|
} else {
|
||||||
|
throw new ElasticSearchIllegalArgumentException("analyzer [" + analyzerName + "] must have a type associated with it or a tokenizer");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
analyzerBinder.addBinding(analyzerName).toProvider(FactoryProvider.newFactory(AnalyzerProviderFactory.class, type)).in(Scopes.SINGLETON);
|
||||||
|
} catch (NoClassSettingsException e) {
|
||||||
|
throw new ElasticSearchIllegalArgumentException("failed to find analyzer type for [" + analyzerName + "]", e);
|
||||||
}
|
}
|
||||||
analyzerBinder.addBinding(analyzerName).toProvider(FactoryProvider.newFactory(AnalyzerProviderFactory.class, type)).in(Scopes.SINGLETON);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AnalysisBinderProcessor.AnalyzersBindings analyzersBindings = new AnalysisBinderProcessor.AnalyzersBindings(analyzerBinder, analyzersSettings, indicesAnalysisService);
|
AnalysisBinderProcessor.AnalyzersBindings analyzersBindings = new AnalysisBinderProcessor.AnalyzersBindings(analyzerBinder, analyzersSettings, indicesAnalysisService);
|
||||||
|
|
|
@ -26,6 +26,7 @@ import org.elasticsearch.common.Nullable;
|
||||||
import org.elasticsearch.common.collect.ImmutableMap;
|
import org.elasticsearch.common.collect.ImmutableMap;
|
||||||
import org.elasticsearch.common.collect.ImmutableSet;
|
import org.elasticsearch.common.collect.ImmutableSet;
|
||||||
import org.elasticsearch.common.collect.UnmodifiableIterator;
|
import org.elasticsearch.common.collect.UnmodifiableIterator;
|
||||||
|
import org.elasticsearch.common.inject.CreationException;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.inject.Injector;
|
import org.elasticsearch.common.inject.Injector;
|
||||||
import org.elasticsearch.common.inject.Injectors;
|
import org.elasticsearch.common.inject.Injectors;
|
||||||
|
@ -56,6 +57,7 @@ import org.elasticsearch.index.merge.scheduler.MergeSchedulerModule;
|
||||||
import org.elasticsearch.index.percolator.PercolatorService;
|
import org.elasticsearch.index.percolator.PercolatorService;
|
||||||
import org.elasticsearch.index.query.IndexQueryParserService;
|
import org.elasticsearch.index.query.IndexQueryParserService;
|
||||||
import org.elasticsearch.index.settings.IndexSettings;
|
import org.elasticsearch.index.settings.IndexSettings;
|
||||||
|
import org.elasticsearch.index.shard.IndexShardCreationException;
|
||||||
import org.elasticsearch.index.shard.IndexShardManagement;
|
import org.elasticsearch.index.shard.IndexShardManagement;
|
||||||
import org.elasticsearch.index.shard.IndexShardModule;
|
import org.elasticsearch.index.shard.IndexShardModule;
|
||||||
import org.elasticsearch.index.shard.ShardId;
|
import org.elasticsearch.index.shard.ShardId;
|
||||||
|
@ -285,7 +287,12 @@ public class InternalIndexService extends AbstractIndexComponent implements Inde
|
||||||
modules.add(new EngineModule(indexSettings));
|
modules.add(new EngineModule(indexSettings));
|
||||||
modules.add(new IndexShardGatewayModule(injector.getInstance(IndexGateway.class)));
|
modules.add(new IndexShardGatewayModule(injector.getInstance(IndexGateway.class)));
|
||||||
|
|
||||||
Injector shardInjector = modules.createChildInjector(injector);
|
Injector shardInjector;
|
||||||
|
try {
|
||||||
|
shardInjector = modules.createChildInjector(injector);
|
||||||
|
} catch (CreationException e) {
|
||||||
|
throw new IndexShardCreationException(shardId, Injectors.getFirstErrorFailure(e));
|
||||||
|
}
|
||||||
|
|
||||||
shardsInjectors = newMapBuilder(shardsInjectors).put(shardId.id(), shardInjector).immutableMap();
|
shardsInjectors = newMapBuilder(shardsInjectors).put(shardId.id(), shardInjector).immutableMap();
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
/*
|
||||||
|
* Licensed to Elastic Search and Shay Banon under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. Elastic Search licenses this
|
||||||
|
* file to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.elasticsearch.index.shard;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
public class IndexShardCreationException extends IndexShardException {
|
||||||
|
|
||||||
|
public IndexShardCreationException(ShardId shardId, Throwable cause) {
|
||||||
|
super(shardId, "failed to create shard", cause);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
/*
|
||||||
|
* Licensed to Elastic Search and Shay Banon under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. Elastic Search licenses this
|
||||||
|
* file to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.elasticsearch.indices;
|
||||||
|
|
||||||
|
import org.elasticsearch.index.Index;
|
||||||
|
import org.elasticsearch.index.IndexException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
public class IndexCreationException extends IndexException {
|
||||||
|
|
||||||
|
public IndexCreationException(Index index, Throwable cause) {
|
||||||
|
super(index, "failed to create index", cause);
|
||||||
|
}
|
||||||
|
}
|
|
@ -26,6 +26,7 @@ import org.elasticsearch.common.collect.ImmutableMap;
|
||||||
import org.elasticsearch.common.collect.ImmutableSet;
|
import org.elasticsearch.common.collect.ImmutableSet;
|
||||||
import org.elasticsearch.common.collect.UnmodifiableIterator;
|
import org.elasticsearch.common.collect.UnmodifiableIterator;
|
||||||
import org.elasticsearch.common.component.AbstractLifecycleComponent;
|
import org.elasticsearch.common.component.AbstractLifecycleComponent;
|
||||||
|
import org.elasticsearch.common.inject.CreationException;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.inject.Injector;
|
import org.elasticsearch.common.inject.Injector;
|
||||||
import org.elasticsearch.common.inject.Injectors;
|
import org.elasticsearch.common.inject.Injectors;
|
||||||
|
@ -265,7 +266,12 @@ public class InternalIndicesService extends AbstractLifecycleComponent<IndicesSe
|
||||||
modules.add(new IndexModule());
|
modules.add(new IndexModule());
|
||||||
modules.add(new PercolatorModule());
|
modules.add(new PercolatorModule());
|
||||||
|
|
||||||
Injector indexInjector = modules.createChildInjector(injector);
|
Injector indexInjector;
|
||||||
|
try {
|
||||||
|
indexInjector = modules.createChildInjector(injector);
|
||||||
|
} catch (CreationException e) {
|
||||||
|
throw new IndexCreationException(index, Injectors.getFirstErrorFailure(e));
|
||||||
|
}
|
||||||
|
|
||||||
indicesInjectors.put(index.name(), indexInjector);
|
indicesInjectors.put(index.name(), indexInjector);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue