Skip to content

Commit

Permalink
Tidy this logic up slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
joegallo committed Nov 18, 2024
1 parent 8dd227c commit 6d217d7
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -580,14 +580,16 @@ private void addIndexLifecyclePoliciesIfMissing(ClusterState state) {
logger.trace("running in data stream lifecycle only mode. skipping the installation of ILM policies.");
return;
}
IndexLifecycleMetadata metadata = state.metadata().custom(IndexLifecycleMetadata.TYPE);
final IndexLifecycleMetadata metadata = state.metadata().custom(IndexLifecycleMetadata.TYPE);
final Map<String, LifecyclePolicy> policies = metadata != null ? metadata.getPolicies() : Map.of();

for (LifecyclePolicy policy : getLifecyclePolicies()) {
final AtomicBoolean creationCheck = policyCreationsInProgress.computeIfAbsent(
policy.getName(),
key -> new AtomicBoolean(false)
);
if (creationCheck.compareAndSet(false, true)) {
final LifecyclePolicy currentPolicy = metadata != null ? metadata.getPolicies().get(policy.getName()) : null;
final LifecyclePolicy currentPolicy = policies.get(policy.getName());
if (Objects.isNull(currentPolicy)) {
logger.debug("adding lifecycle policy [{}] for [{}], because it doesn't exist", policy.getName(), getOrigin());
putPolicy(policy, creationCheck);
Expand Down

0 comments on commit 6d217d7

Please sign in to comment.