diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java index b3eb2fd7f9..a46a2ce15c 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java @@ -678,7 +678,15 @@ private Consumer> createSecondaryNodeSorter() { Consumer> secondarySort = null; if (readConsiderStorageType) { Comparator comp = - Comparator.comparing(DatanodeInfoWithStorage::getStorageType); + Comparator.comparing(DatanodeInfoWithStorage::getStorageType, (s1, s2) -> { + if (s1 == null) { + return (s2 == null) ? 0 : -1; + } else if (s2 == null) { + return 1; + } else { + return s2.compareTo(s1); + } + }); secondarySort = list -> Collections.sort(list, comp); } if (readConsiderLoad) {