From 3dc17396bd90ee76bb6e35b965d80f7a454588b5 Mon Sep 17 00:00:00 2001 From: Armin Braun Date: Wed, 4 Sep 2024 09:20:31 +0200 Subject: [PATCH] Two speedups to IndexNameExpressionResolver Two obvious speedups to the IndexNameExpressionResolver where we can defer an expensive lookup from either the indices lookup or the thread context to if and when we actually need it. --- .../metadata/IndexNameExpressionResolver.java | 19 ++++++++----------- .../elasticsearch/indices/SystemIndices.java | 3 +-- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java index 459c6c6ec733e..b945fe7e510f6 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java @@ -567,17 +567,14 @@ private static boolean shouldTrackConcreteIndex(Context context, IndicesOptions // Exclude this one as it's a net-new system index, and we explicitly don't want those. return false; } - if (DataStream.isFailureStoreFeatureFlagEnabled()) { - IndexAbstraction indexAbstraction = context.getState().metadata().getIndicesLookup().get(index.getName()); - if (context.options.allowFailureIndices() == false) { - DataStream parentDataStream = indexAbstraction.getParentDataStream(); - if (parentDataStream != null && parentDataStream.isFailureStoreEnabled()) { - if (parentDataStream.isFailureStoreIndex(index.getName())) { - if (options.ignoreUnavailable()) { - return false; - } else { - throw new FailureIndexNotSupportedException(index); - } + if (DataStream.isFailureStoreFeatureFlagEnabled() && context.options.allowFailureIndices() == false) { + DataStream parentDataStream = context.getState().metadata().getIndicesLookup().get(index.getName()).getParentDataStream(); + if (parentDataStream != null && parentDataStream.isFailureStoreEnabled()) { + if (parentDataStream.isFailureStoreIndex(index.getName())) { + if (options.ignoreUnavailable()) { + return false; + } else { + throw new FailureIndexNotSupportedException(index); } } } diff --git a/server/src/main/java/org/elasticsearch/indices/SystemIndices.java b/server/src/main/java/org/elasticsearch/indices/SystemIndices.java index 3261ac83a7e67..bafbd57a607a5 100644 --- a/server/src/main/java/org/elasticsearch/indices/SystemIndices.java +++ b/server/src/main/java/org/elasticsearch/indices/SystemIndices.java @@ -562,11 +562,10 @@ public static SystemIndexAccessLevel getSystemIndexAccessLevel(ThreadContext thr // This method intentionally cannot return BACKWARDS_COMPATIBLE_ONLY - that access level should only be used manually // in known special cases. final String headerValue = threadContext.getHeader(SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY); - final String productHeaderValue = threadContext.getHeader(EXTERNAL_SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY); final boolean allowed = Booleans.parseBoolean(headerValue, true); if (allowed) { - if (productHeaderValue != null) { + if (threadContext.getHeader(EXTERNAL_SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY) != null) { return SystemIndexAccessLevel.RESTRICTED; } else { return SystemIndexAccessLevel.ALL;