Skip to content

Commit 3d1dd2b

Browse files
committed
Sort null ranked nodes before nodes that have a rank
1 parent dcae338 commit 3d1dd2b

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

core/src/main/java/org/elasticsearch/cluster/routing/IndexShardRoutingTable.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -407,11 +407,21 @@ public int compare(ShardRouting s1, ShardRouting s2) {
407407
}
408408
Double shard1rank = nodeRanks.get(s1.currentNodeId());
409409
Double shard2rank = nodeRanks.get(s2.currentNodeId());
410-
if (shard1rank != null && shard2rank != null) {
411-
return shard1rank.compareTo(shard2rank);
410+
if (shard1rank != null) {
411+
if (shard2rank != null) {
412+
return shard1rank.compareTo(shard2rank);
413+
} else {
414+
// place non-nulls after null values
415+
return 1;
416+
}
412417
} else {
413-
// One or both of the nodes don't have stats, treat them as equal
414-
return 0;
418+
if (shard2rank != null) {
419+
// place nulls before non-null values
420+
return -1;
421+
} else {
422+
// Both nodes do not have stats, they are equal
423+
return 0;
424+
}
415425
}
416426
}
417427
}

0 commit comments

Comments
 (0)