Skip to content

Commit 6bb6adb

Browse files
authored
Reuse collected cluster state in EnrichPolicyRunner (#48488) (#49100)
The cluster state is obtained twice in the EnrichPolicyRunner when updating the final alias. There is a possibility for the state to be slightly different between those two calls. This PR just has the function get the cluster state once and reuse it for the life of the function call.
1 parent 6ce0442 commit 6bb6adb

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPolicyRunner.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest;
3030
import org.elasticsearch.action.support.master.AcknowledgedResponse;
3131
import org.elasticsearch.client.Client;
32+
import org.elasticsearch.cluster.ClusterState;
3233
import org.elasticsearch.cluster.metadata.AliasMetaData;
3334
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
3435
import org.elasticsearch.cluster.metadata.MappingMetaData;
@@ -498,10 +499,9 @@ private void updateEnrichPolicyAlias(final String destinationIndexName) {
498499
String enrichIndexBase = EnrichPolicy.getBaseName(policyName);
499500
logger.debug("Policy [{}]: Promoting new enrich index [{}] to alias [{}]", policyName, destinationIndexName, enrichIndexBase);
500501
GetAliasesRequest aliasRequest = new GetAliasesRequest(enrichIndexBase);
501-
String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterService.state(), aliasRequest);
502-
ImmutableOpenMap<String, List<AliasMetaData>> aliases = clusterService.state()
503-
.metaData()
504-
.findAliases(aliasRequest, concreteIndices);
502+
ClusterState clusterState = clusterService.state();
503+
String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterState, aliasRequest);
504+
ImmutableOpenMap<String, List<AliasMetaData>> aliases = clusterState.metaData().findAliases(aliasRequest, concreteIndices);
505505
IndicesAliasesRequest aliasToggleRequest = new IndicesAliasesRequest();
506506
String[] indices = aliases.keys().toArray(String.class);
507507
if (indices.length > 0) {

0 commit comments

Comments
 (0)