Skip to content

Commit

Permalink
Reuse ensureAliasOrIndexExists
Browse files Browse the repository at this point in the history
  • Loading branch information
albertzaharovits committed Nov 9, 2022
1 parent d1f11d4 commit 6b2dc8e
Showing 1 changed file with 24 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -349,31 +349,16 @@ Index[] concreteIndices(Context context, String... indexExpressions) {
final Set<Index> concreteIndices = Sets.newLinkedHashSetWithExpectedSize(expressions.size());
final SortedMap<String, IndexAbstraction> indicesLookup = context.state.metadata().getIndicesLookup();
for (String expression : expressions) {
if (options.ignoreUnavailable() == false) {
ensureAliasOrIndexExists(context, expression);
}
IndexAbstraction indexAbstraction = indicesLookup.get(expression);
if (indexAbstraction == null) {
if (options.ignoreUnavailable() == false) {
assert options.expandWildcardExpressions() == false;
throw notFoundException(expression);
} else {
continue;
}
continue;
} else if (indexAbstraction.getType() == Type.ALIAS && context.getOptions().ignoreAliases()) {
if (options.ignoreUnavailable() == false) {
assert options.expandWildcardExpressions() == false;
throw aliasesNotSupportedException(expression);
} else {
continue;
}
continue;
} else if (indexAbstraction.isDataStreamRelated() && context.includeDataStreams() == false) {
if (options.ignoreUnavailable() == false) {
assert options.expandWildcardExpressions() == false;
IndexNotFoundException infe = notFoundException(indexExpressions);
// Allows callers to handle IndexNotFoundException differently based on whether data streams were excluded.
infe.addMetadata(EXCLUDED_DATA_STREAMS_KEY, "true");
throw infe;
} else {
continue;
}
continue;
}

if (indexAbstraction.getType() == Type.ALIAS && context.isResolveToWriteIndex()) {
Expand Down Expand Up @@ -489,6 +474,24 @@ private static IndexNotFoundException notFoundException(String... indexExpressio
return infe;
}

@Nullable
private static void ensureAliasOrIndexExists(Context context, String expression) {
IndexAbstraction indexAbstraction = context.getState().getMetadata().getIndicesLookup().get(expression);
if (indexAbstraction == null) {
throw notFoundException(expression);
}
// treat aliases as unavailable indices when ignoreAliases is set to true (e.g. delete index and update aliases api)
if (indexAbstraction.getType() == Type.ALIAS && context.getOptions().ignoreAliases()) {
throw aliasesNotSupportedException(expression);
}
if (indexAbstraction.isDataStreamRelated() && context.includeDataStreams() == false) {
IndexNotFoundException infe = notFoundException(expression);
// Allows callers to handle IndexNotFoundException differently based on whether data streams were excluded.
infe.addMetadata(EXCLUDED_DATA_STREAMS_KEY, "true");
throw infe;
}
}

private static boolean shouldTrackConcreteIndex(Context context, IndicesOptions options, Index index) {
if (context.systemIndexAccessLevel == SystemIndexAccessLevel.BACKWARDS_COMPATIBLE_ONLY
&& context.netNewSystemIndexPredicate.test(index.getName())) {
Expand Down Expand Up @@ -1260,22 +1263,6 @@ private static String validateAliasOrIndex(String expression) {
return expression;
}

@Nullable
private static void ensureAliasOrIndexExists(Context context, String expression) {
final IndicesOptions options = context.getOptions();
IndexAbstraction indexAbstraction = context.getState().getMetadata().getIndicesLookup().get(expression);
if (indexAbstraction == null) {
throw notFoundException(expression);
}
// treat aliases as unavailable indices when ignoreAliases is set to true (e.g. delete index and update aliases api)
if (indexAbstraction.getType() == Type.ALIAS && options.ignoreAliases()) {
throw aliasesNotSupportedException(expression);
}
if (indexAbstraction.isDataStreamRelated() && context.includeDataStreams() == false) {
throw notFoundException(expression);
}
}

private static IndexMetadata.State excludeState(IndicesOptions options) {
final IndexMetadata.State excludeState;
if (options.expandWildcardsOpen() && options.expandWildcardsClosed()) {
Expand Down

0 comments on commit 6b2dc8e

Please sign in to comment.