when using wildcard notation delete all indices might kick in even though its disabled
This commit is contained in:
parent
c33ca2921d
commit
2dd82675fb
|
@ -33,6 +33,7 @@ import org.elasticsearch.cluster.block.ClusterBlockLevel;
|
|||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaDataDeleteIndexService;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.regex.Regex;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.index.percolator.PercolatorService;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
|
@ -84,10 +85,27 @@ public class TransportDeleteIndexAction extends TransportMasterNodeOperationActi
|
|||
|
||||
@Override
|
||||
protected void doExecute(DeleteIndexRequest request, ActionListener<DeleteIndexResponse> listener) {
|
||||
if (disableDeleteAllIndices && (request.indices() == null || request.indices().length == 0 || (request.indices().length == 1 && request.indices()[0].equals("_all")))) {
|
||||
throw new ElasticSearchIllegalArgumentException("deleting all indices is disabled");
|
||||
ClusterState state = clusterService.state();
|
||||
String[] indicesOrAliases = request.indices();
|
||||
request.indices(state.metaData().concreteIndices(request.indices()));
|
||||
if (disableDeleteAllIndices) {
|
||||
// simple check on the original indices with "all" default parameter
|
||||
if (indicesOrAliases == null || indicesOrAliases.length == 0 || (indicesOrAliases.length == 1 && indicesOrAliases[0].equals("_all"))) {
|
||||
throw new ElasticSearchIllegalArgumentException("deleting all indices is disabled");
|
||||
}
|
||||
// if we end up matching on all indices, check, if its a wildcard parameter, or a "-something" structure
|
||||
if (request.indices().length == state.metaData().concreteAllIndices().length && indicesOrAliases.length > 0) {
|
||||
boolean hasRegex = false;
|
||||
for (String indexOrAlias : indicesOrAliases) {
|
||||
if (Regex.isSimpleMatchPattern(indexOrAlias)) {
|
||||
hasRegex = true;
|
||||
}
|
||||
}
|
||||
if (indicesOrAliases.length > 0 && (hasRegex || indicesOrAliases[0].charAt(0) == '-')) {
|
||||
throw new ElasticSearchIllegalArgumentException("deleting all indices is disabled");
|
||||
}
|
||||
}
|
||||
}
|
||||
request.indices(clusterService.state().metaData().concreteIndices(request.indices()));
|
||||
super.doExecute(request, listener);
|
||||
}
|
||||
|
||||
|
|
|
@ -135,6 +135,7 @@ public class MetaData implements Iterable<IndexMetaData> {
|
|||
private final transient int totalNumberOfShards;
|
||||
|
||||
private final String[] allIndices;
|
||||
private final ImmutableSet<String> allIndicesSet;
|
||||
private final String[] allOpenIndices;
|
||||
|
||||
private final ImmutableMap<String, ImmutableMap<String, AliasMetaData>> aliases;
|
||||
|
@ -166,6 +167,7 @@ public class MetaData implements Iterable<IndexMetaData> {
|
|||
allIndicesLst.add(indexMetaData.index());
|
||||
}
|
||||
allIndices = allIndicesLst.toArray(new String[allIndicesLst.size()]);
|
||||
allIndicesSet = ImmutableSet.copyOf(allIndices);
|
||||
|
||||
List<String> allOpenIndices = Lists.newArrayList();
|
||||
for (IndexMetaData indexMetaData : indices.values()) {
|
||||
|
@ -294,6 +296,10 @@ public class MetaData implements Iterable<IndexMetaData> {
|
|||
return allIndices;
|
||||
}
|
||||
|
||||
public ImmutableSet<String> concreteAllIndicesAsSet() {
|
||||
return allIndicesSet;
|
||||
}
|
||||
|
||||
public String[] getConcreteAllIndices() {
|
||||
return concreteAllIndices();
|
||||
}
|
||||
|
@ -508,7 +514,7 @@ public class MetaData implements Iterable<IndexMetaData> {
|
|||
if (aliasesOrIndices == null || aliasesOrIndices.length == 0) {
|
||||
return allOnlyOpen ? concreteAllOpenIndices() : concreteAllIndices();
|
||||
}
|
||||
aliasesOrIndices = convertFromWildcards(aliasesOrIndices, allOnlyOpen, false);
|
||||
aliasesOrIndices = convertFromWildcards(aliasesOrIndices, allOnlyOpen, ignoreMissing);
|
||||
// optimize for single element index (common case)
|
||||
if (aliasesOrIndices.length == 1) {
|
||||
String aliasOrIndex = aliasesOrIndices[0];
|
||||
|
@ -602,6 +608,9 @@ public class MetaData implements Iterable<IndexMetaData> {
|
|||
aliasOrIndex = aliasOrIndex.substring(1);
|
||||
}
|
||||
if (!Regex.isSimpleMatchPattern(aliasOrIndex)) {
|
||||
if (!ignoreMissing && !aliasAndIndexToIndexMap.containsKey(aliasOrIndex)) {
|
||||
throw new IndexMissingException(new Index(aliasOrIndex));
|
||||
}
|
||||
if (result != null) {
|
||||
if (add) {
|
||||
result.add(aliasOrIndex);
|
||||
|
|
Loading…
Reference in New Issue