Skip to content

Commit 2a17df5

Browse files
authored
Only resolve project once in FieldCaps (elastic#123664)
`TransportFieldCapabilitiesAction.doExecuteForked` would resolve the project twice: - Once implicitly when resolving indices from cluster state - Another time to resolve index blocks This changes this method to resolve `ProjectState` once and use that instance for both index resolution and block checking
1 parent 9a37fbf commit 2a17df5

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

server/src/main/java/org/elasticsearch/action/fieldcaps/TransportFieldCapabilitiesAction.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.elasticsearch.action.support.HandledTransportAction;
2424
import org.elasticsearch.action.support.RefCountingRunnable;
2525
import org.elasticsearch.client.internal.RemoteClusterClient;
26-
import org.elasticsearch.cluster.ClusterState;
2726
import org.elasticsearch.cluster.ProjectState;
2827
import org.elasticsearch.cluster.block.ClusterBlockLevel;
2928
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
@@ -150,7 +149,7 @@ private void doExecuteForked(
150149
final CancellableTask fieldCapTask = (CancellableTask) task;
151150
// retrieve the initial timestamp in case the action is a cross cluster search
152151
long nowInMillis = request.nowInMillis() == null ? System.currentTimeMillis() : request.nowInMillis();
153-
final ClusterState clusterState = clusterService.state();
152+
final ProjectState projectState = projectResolver.getProjectState(clusterService.state());
154153
final Map<String, OriginalIndices> remoteClusterIndices = transportService.getRemoteClusterService()
155154
.groupIndices(request.indicesOptions(), request.indices());
156155
final OriginalIndices localIndices = remoteClusterIndices.remove(RemoteClusterAware.LOCAL_CLUSTER_GROUP_KEY);
@@ -159,15 +158,15 @@ private void doExecuteForked(
159158
// in the case we have one or more remote indices but no local we don't expand to all local indices and just do remote indices
160159
concreteIndices = Strings.EMPTY_ARRAY;
161160
} else {
162-
concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterState, localIndices);
161+
concreteIndices = indexNameExpressionResolver.concreteIndexNames(projectState.metadata(), localIndices);
163162
}
164163

165164
if (concreteIndices.length == 0 && remoteClusterIndices.isEmpty()) {
166165
listener.onResponse(new FieldCapabilitiesResponse(new String[0], Collections.emptyMap()));
167166
return;
168167
}
169168

170-
checkIndexBlocks(projectResolver.getProjectState(clusterState), concreteIndices);
169+
checkIndexBlocks(projectState, concreteIndices);
171170
final FailureCollector indexFailures = new FailureCollector();
172171
final Map<String, FieldCapabilitiesIndexResponse> indexResponses = Collections.synchronizedMap(new HashMap<>());
173172
// This map is used to share the index response for indices which have the same index mapping hash to reduce the memory usage.

0 commit comments

Comments
 (0)