Skip to content

Commit

Permalink
Remove the getConcreteIndexAndAliasMetadatas() method from IndexAbstr…
Browse files Browse the repository at this point in the history
…action.Alias class.

This change is part of series of changes to clean up the usage `IndexAbstraction.Alias` in the codebase,
so that it is no longer needed to cast to `IndexAbstraction.Alias` and just use the methods on the `IndexAbstraction`
interface. This should help adding data stream aliases, so that `IndexAbstraction` instances of type `ALIAS` can
also be data stream aliases.

Relates to elastic#66163
  • Loading branch information
martijnvg committed Dec 10, 2020
1 parent 616098e commit 1f21e48
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ public List<IndexMetadata> getIndices() {
return referenceIndexMetadatas;
}


@Nullable
public IndexMetadata getWriteIndex() {
return writeIndex.get();
Expand All @@ -224,30 +223,6 @@ public boolean isSystem() {
return referenceIndexMetadatas.stream().allMatch(IndexMetadata::isSystem);
}

/**
* Returns the unique alias metadata per concrete index.
* <p>
* (note that although alias can point to the same concrete indices, each alias reference may have its own routing
* and filters)
*/
public Iterable<Tuple<String, AliasMetadata>> getConcreteIndexAndAliasMetadatas() {
return () -> new Iterator<>() {

int index = 0;

@Override
public boolean hasNext() {
return index < referenceIndexMetadatas.size();
}

@Override
public Tuple<String, AliasMetadata> next() {
IndexMetadata indexMetadata = referenceIndexMetadatas.get(index++);
return new Tuple<>(indexMetadata.getIndex().getName(), indexMetadata.getAliases().get(aliasName));
}
};
}

public AliasMetadata getFirstAliasMetadata() {
return referenceIndexMetadatas.get(0).getAliases().get(aliasName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.regex.Regex;
import org.elasticsearch.common.time.DateFormatter;
Expand Down Expand Up @@ -563,10 +562,9 @@ public Map<String, Set<String>> resolveSearchRouting(ClusterState state, @Nullab
for (String expression : resolvedExpressions) {
IndexAbstraction indexAbstraction = state.metadata().getIndicesLookup().get(expression);
if (indexAbstraction != null && indexAbstraction.getType() == IndexAbstraction.Type.ALIAS) {
IndexAbstraction.Alias alias = (IndexAbstraction.Alias) indexAbstraction;
for (Tuple<String, AliasMetadata> item : alias.getConcreteIndexAndAliasMetadatas()) {
String concreteIndex = item.v1();
AliasMetadata aliasMetadata = item.v2();
for (IndexMetadata index : indexAbstraction.getIndices()) {
String concreteIndex = index.getIndex().getName();
AliasMetadata aliasMetadata = index.getAliases().get(indexAbstraction.getName());
if (!norouting.contains(concreteIndex)) {
if (!aliasMetadata.searchRoutingValues().isEmpty()) {
// Routing alias
Expand Down

0 comments on commit 1f21e48

Please sign in to comment.