Skip to content

Commit c11c70a

Browse files
committed
Fix node selection for round-robin rotation.
1 parent eeca1c9 commit c11c70a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/main/java/org/typesense/api/ApiCall.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ boolean isDueForHealthCheck(Node node) {
5858
return Duration.between(node.lastAccessTimestamp, LocalDateTime.now()).getSeconds() > configuration.healthCheckInterval.getSeconds();
5959
}
6060

61-
//Loops in a round-robin fashion to check for a healthy node and returns it
61+
// Loops in a round-robin fashion to check for a healthy node and returns it
6262
Node getNode() {
6363
if (configuration.nearestNode != null) {
6464
if (isDueForHealthCheck((configuration.nearestNode)) || configuration.nearestNode.isHealthy) {
@@ -70,14 +70,14 @@ Node getNode() {
7070
Node testNode;
7171

7272
while (i < configuration.nodes.size()) {
73+
nodeIndex = (nodeIndex + 1) % configuration.nodes.size();
7374
testNode = configuration.nodes.get(nodeIndex);
7475

7576
if (testNode.isHealthy || isDueForHealthCheck((testNode))) {
7677
return testNode;
7778
}
7879

7980
i += 1;
80-
nodeIndex = (nodeIndex + 1) % configuration.nodes.size();
8181
}
8282

8383
return configuration.nodes.get(nodeIndex);

0 commit comments

Comments
 (0)