Skip to content

Commit

Permalink
Deduplicate concrete indices after indices resolution
Browse files Browse the repository at this point in the history
This commit fixes a regression introduced with elastic#12058. This causes failures with the delete index api when providing the same index name multiple times in the request, or aliases/wildcard expressions that end up pointing to the same concrete index. The bug was revealed after merging elastic#11258 as we delete indices in batch rather than one by one. The master node will expect too many acknowledgements based on the number of indices that it's trying to delete, hence the request will never be acknowledged by all nodes.

Closes elastic#14316
  • Loading branch information
javanna committed Oct 27, 2015
1 parent 1373892 commit 4f3a378
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Expand Up @@ -72,7 +72,7 @@ public String[] concreteIndices(ClusterState state, IndicesRequest request) {
}

/**
* Translates the provided index expression into actual concrete indices.
* Translates the provided index expression into actual concrete indices, properly deduplicated.
*
* @param state the cluster state containing all the data to resolve to expressions to concrete indices
* @param options defines how the aliases or indices need to be resolved to concrete indices
Expand All @@ -90,7 +90,7 @@ public String[] concreteIndices(ClusterState state, IndicesOptions options, Stri
}

/**
* Translates the provided index expression into actual concrete indices.
* Translates the provided index expression into actual concrete indices, properly deduplicated.
*
* @param state the cluster state containing all the data to resolve to expressions to concrete indices
* @param options defines how the aliases or indices need to be resolved to concrete indices
Expand Down Expand Up @@ -137,7 +137,7 @@ String[] concreteIndices(Context context, String... indexExpressions) {
}
}

List<String> concreteIndices = new ArrayList<>(expressions.size());
final Set<String> concreteIndices = new HashSet<>(expressions.size());
for (String expression : expressions) {
AliasOrIndex aliasOrIndex = metaData.getAliasAndIndexLookup().get(expression);
if (aliasOrIndex == null) {
Expand Down
Expand Up @@ -868,6 +868,19 @@ public void testIndexOptions_failClosedIndicesAndAliases() {
assertThat(results, arrayContainingInAnyOrder("foo1-closed", "foo2-closed", "foo3"));
}

public void testDedupConcreteIndices() {
MetaData.Builder mdBuilder = MetaData.builder()
.put(indexBuilder("index1").putAlias(AliasMetaData.builder("alias1")));
ClusterState state = ClusterState.builder(new ClusterName("_name")).metaData(mdBuilder).build();
IndicesOptions[] indicesOptions = new IndicesOptions[]{ IndicesOptions.strictExpandOpen(), IndicesOptions.strictExpand(),
IndicesOptions.lenientExpandOpen(), IndicesOptions.strictExpandOpenAndForbidClosed()};
for (IndicesOptions options : indicesOptions) {
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, options);
String[] results = indexNameExpressionResolver.concreteIndices(context, "index1", "index1", "alias1");
assertThat(results, equalTo(new String[]{"index1"}));
}
}

private MetaData metaDataBuilder(String... indices) {
MetaData.Builder mdBuilder = MetaData.builder();
for (String concreteIndex : indices) {
Expand Down

0 comments on commit 4f3a378

Please sign in to comment.