Skip to content

Commit 630aac2

Browse files
authored
Reuse collected cluster state in EnrichPolicyRunner (#48488)
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 d4e82d4 commit 630aac2

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;
@@ -494,10 +495,9 @@ private void updateEnrichPolicyAlias(final String destinationIndexName) {
494495
String enrichIndexBase = EnrichPolicy.getBaseName(policyName);
495496
logger.debug("Policy [{}]: Promoting new enrich index [{}] to alias [{}]", policyName, destinationIndexName, enrichIndexBase);
496497
GetAliasesRequest aliasRequest = new GetAliasesRequest(enrichIndexBase);
497-
String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterService.state(), aliasRequest);
498-
ImmutableOpenMap<String, List<AliasMetaData>> aliases = clusterService.state()
499-
.metaData()
500-
.findAliases(aliasRequest, concreteIndices);
498+
ClusterState clusterState = clusterService.state();
499+
String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterState, aliasRequest);
500+
ImmutableOpenMap<String, List<AliasMetaData>> aliases = clusterState.metaData().findAliases(aliasRequest, concreteIndices);
501501
IndicesAliasesRequest aliasToggleRequest = new IndicesAliasesRequest();
502502
String[] indices = aliases.keys().toArray(String.class);
503503
if (indices.length > 0) {

0 commit comments

Comments
 (0)