diff --git a/server/src/main/java/org/opensearch/cluster/service/ClusterApplierService.java b/server/src/main/java/org/opensearch/cluster/service/ClusterApplierService.java index 9ce2c719e9c..a016fc05086 100644 --- a/server/src/main/java/org/opensearch/cluster/service/ClusterApplierService.java +++ b/server/src/main/java/org/opensearch/cluster/service/ClusterApplierService.java @@ -204,6 +204,13 @@ public class ClusterApplierService extends AbstractLifecycleComponent implements return clusterState; } + /** + * Returns true if the appliedClusterState is not null + */ + public boolean isInitialClusterStateSet() { + return Objects.nonNull(this.state.get()); + } + /** * Adds a high priority applier of updated cluster states. */ diff --git a/server/src/main/java/org/opensearch/index/ShardIndexingPressureSettings.java b/server/src/main/java/org/opensearch/index/ShardIndexingPressureSettings.java index b5d76bf15e4..5b5b887b105 100644 --- a/server/src/main/java/org/opensearch/index/ShardIndexingPressureSettings.java +++ b/server/src/main/java/org/opensearch/index/ShardIndexingPressureSettings.java @@ -80,7 +80,7 @@ public final class ShardIndexingPressureSettings { public static boolean isShardIndexingPressureAttributeEnabled() { // Null check is required only for bwc tests which start node without initializing cluster service. // In actual run time, clusterService will never be null. - if (Objects.nonNull(clusterService)) { + if (Objects.nonNull(clusterService) && clusterService.getClusterApplierService().isInitialClusterStateSet()) { Iterator nodes = clusterService.state().getNodes().getNodes().valuesIt(); while (nodes.hasNext()) { if (Boolean.parseBoolean(nodes.next().getAttributes().get(SHARD_INDEXING_PRESSURE_ENABLED_ATTRIBUTE_KEY)) == false) {