From f09710bbb8e56d066f9d7a2e70a41ed82d5aa781 Mon Sep 17 00:00:00 2001 From: Ayush Saxena Date: Wed, 12 Feb 2020 20:22:51 +0530 Subject: [PATCH] HDFS-15161. When evictableMmapped or evictable size is zero, do not throw NoSuchElementException in ShortCircuitCache#close(). Contributed by Lisheng Sun --- .../hdfs/shortcircuit/ShortCircuitCache.java | 23 +++++-------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/shortcircuit/ShortCircuitCache.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/shortcircuit/ShortCircuitCache.java index d3eb3ac0da..d4d898c892 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/shortcircuit/ShortCircuitCache.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/shortcircuit/ShortCircuitCache.java @@ -26,7 +26,6 @@ import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; -import java.util.NoSuchElementException; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; @@ -865,23 +864,13 @@ public void close() { // Close and join cacheCleaner thread. IOUtilsClient.cleanupWithLogger(LOG, cacheCleaner); // Purge all replicas. - while (true) { - Object eldestKey; - try { - eldestKey = evictable.firstKey(); - } catch (NoSuchElementException e) { - break; - } - purge((ShortCircuitReplica)evictable.get(eldestKey)); + while (!evictable.isEmpty()) { + Object eldestKey = evictable.firstKey(); + purge((ShortCircuitReplica) evictable.get(eldestKey)); } - while (true) { - Object eldestKey; - try { - eldestKey = evictableMmapped.firstKey(); - } catch (NoSuchElementException e) { - break; - } - purge((ShortCircuitReplica)evictableMmapped.get(eldestKey)); + while (!evictableMmapped.isEmpty()) { + Object eldestKey = evictableMmapped.firstKey(); + purge((ShortCircuitReplica) evictableMmapped.get(eldestKey)); } } finally { lock.unlock();