From ca876bdf6f8dc2e90e3d7510359b0ddda08b762b Mon Sep 17 00:00:00 2001 From: Andrey Pleskach Date: Mon, 22 Jan 2024 14:20:10 +0100 Subject: [PATCH] Add check that cluster has block on index creation Signed-off-by: Andrey Pleskach --- .../security/configuration/ConfigurationRepository.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/opensearch/security/configuration/ConfigurationRepository.java b/src/main/java/org/opensearch/security/configuration/ConfigurationRepository.java index dfbeb16cb3..183dda79d2 100644 --- a/src/main/java/org/opensearch/security/configuration/ConfigurationRepository.java +++ b/src/main/java/org/opensearch/security/configuration/ConfigurationRepository.java @@ -61,6 +61,7 @@ import org.opensearch.cluster.health.ClusterHealthStatus; import org.opensearch.cluster.metadata.IndexMetadata; import org.opensearch.cluster.metadata.MappingMetadata; +import org.opensearch.cluster.metadata.Metadata; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.settings.Settings; import org.opensearch.common.util.concurrent.ThreadContext; @@ -126,10 +127,12 @@ private ConfigurationRepository( private void initalizeClusterConfiguration(final boolean installDefaultConfig) { try { LOGGER.info("Background init thread started. Install default config?: " + installDefaultConfig); - // wait for the cluster here until it will finish managed node election - while (clusterService.state().blocks().hasGlobalBlockWithStatus(RestStatus.SERVICE_UNAVAILABLE)) { + // wait for the cluster here until it will finish managed node election or skip index creation since + // cluster blocks index creation + while (clusterService.state().blocks().hasGlobalBlockWithStatus(RestStatus.SERVICE_UNAVAILABLE) + || clusterService.state().blocks().hasGlobalBlockWithId(Metadata.CLUSTER_CREATE_INDEX_BLOCK.id())) { LOGGER.info("Wait for cluster to be available ..."); - TimeUnit.SECONDS.sleep(1); + TimeUnit.SECONDS.sleep(5); } if (installDefaultConfig) {