Skip to content

Commit

Permalink
Remove sleep when waiting for node closure
Browse files Browse the repository at this point in the history
For each node in the cluster we were removing and then sleeping for
250ms.  There is an API that we can wait on to be sure the node has
closed or at least take action if the closure wasn't successful.

For the usage, which is cleaning up all nodes, switching to a best
effort mode that could wait the same 250ms or return faster.

Signed-off-by: Peter Nied <[email protected]>
  • Loading branch information
peternied committed Mar 30, 2022
1 parent ebdaaaa commit 7075ed5
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -247,18 +248,18 @@ public final void stopCluster() throws Exception {

private void closeAllNodes() throws Exception {
//close non master nodes
opensearchNodes.stream().filter(n->!n.isMasterEligible()).forEach(node->closeNode(node));
opensearchNodes.stream().filter(n->!n.isMasterEligible()).forEach(ClusterHelper::closeNode);

//close master nodes
opensearchNodes.stream().filter(n->n.isMasterEligible()).forEach(node->closeNode(node));
opensearchNodes.stream().filter(n->n.isMasterEligible()).forEach(ClusterHelper::closeNode);
opensearchNodes.clear();
clusterState = ClusterState.STOPPED;
}

private static void closeNode(Node node) {
try {
node.close();
Thread.sleep(250);
node.awaitClose(250, TimeUnit.MILLISECONDS);
} catch (Throwable e) {
//ignore
}
Expand Down

0 comments on commit 7075ed5

Please sign in to comment.