org.opensearch.search.backpressure.trackers.NodeDuressTracker Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of opensearch Show documentation
Show all versions of opensearch Show documentation
OpenSearch subproject :server
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/
package org.opensearch.search.backpressure.trackers;
import org.opensearch.common.util.Streak;
import java.util.function.BooleanSupplier;
/**
* NodeDuressTracker is used to check if the node is in duress.
*
* @opensearch.internal
*/
public class NodeDuressTracker {
/**
* Tracks the number of consecutive breaches.
*/
private final Streak breaches = new Streak();
/**
* Predicate that returns true when the node is in duress.
*/
private final BooleanSupplier isNodeInDuress;
public NodeDuressTracker(BooleanSupplier isNodeInDuress) {
this.isNodeInDuress = isNodeInDuress;
}
/**
* Evaluates the predicate and returns the number of consecutive breaches.
*/
public int check() {
return breaches.record(isNodeInDuress.getAsBoolean());
}
}