hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From inigo...@apache.org
Subject [hadoop] branch trunk updated: when evictableMmapped or evictable size is zero, do not throw NoSuchElementException
Date Tue, 25 Jun 2019 00:45:07 GMT
This is an automated email from the ASF dual-hosted git repository.

inigoiri pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/hadoop.git


The following commit(s) were added to refs/heads/trunk by this push:
     new daa1e14  when evictableMmapped or evictable size is zero, do not throw NoSuchElementException
     new 38a560c  Merge pull request #977 from leosunli/trunk
daa1e14 is described below

commit daa1e147454c3f14704aca904aaae168b47f3de0
Author: sunlisheng <sunlisheng@xiaomi.com>
AuthorDate: Mon Jun 17 19:32:41 2019 +0800

    when evictableMmapped or evictable size is zero, do not throw NoSuchElementException
    
    Signed-off-by: sunlisheng <sunlisheng@xiaomi.com>
---
 .../hdfs/shortcircuit/ShortCircuitCache.java       | 40 ++++++----------------
 1 file changed, 11 insertions(+), 29 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 c2f0350..d91dd7d 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
@@ -109,13 +109,8 @@ public class ShortCircuitCache implements Closeable {
         int numDemoted = demoteOldEvictableMmaped(curMs);
         int numPurged = 0;
         Long evictionTimeNs;
-        while (true) {
-          Object eldestKey;
-          try {
-            eldestKey = evictable.firstKey();
-          } catch (NoSuchElementException e) {
-            break;
-          }
+        while (!evictable.isEmpty()) {
+          Object eldestKey = evictable.firstKey();
           evictionTimeNs = (Long)eldestKey;
           long evictionTimeMs =
               TimeUnit.MILLISECONDS.convert(evictionTimeNs, TimeUnit.NANOSECONDS);
@@ -493,13 +488,8 @@ public class ShortCircuitCache implements Closeable {
     boolean needMoreSpace = false;
     Long evictionTimeNs;
 
-    while (true) {
-      Object eldestKey;
-      try {
-        eldestKey = evictableMmapped.firstKey();
-      } catch (NoSuchElementException e) {
-        break;
-      }
+    while (!evictableMmapped.isEmpty()) {
+      Object eldestKey = evictableMmapped.firstKey();
       evictionTimeNs = (Long)eldestKey;
       long evictionTimeMs =
           TimeUnit.MILLISECONDS.convert(evictionTimeNs, TimeUnit.NANOSECONDS);
@@ -533,23 +523,15 @@ public class ShortCircuitCache implements Closeable {
     long now = Time.monotonicNow();
     demoteOldEvictableMmaped(now);
 
-    while (true) {
-      long evictableSize = evictable.size();
-      long evictableMmappedSize = evictableMmapped.size();
-      if (evictableSize + evictableMmappedSize <= maxTotalSize) {
-        return;
-      }
+    while (evictable.size() + evictableMmapped.size() > maxTotalSize) {
       ShortCircuitReplica replica;
-      try {
-        if (evictableSize == 0) {
-          replica = (ShortCircuitReplica)evictableMmapped.get(evictableMmapped
-              .firstKey());
-        } else {
-          replica = (ShortCircuitReplica)evictable.get(evictable.firstKey());
-        }
-      } catch (NoSuchElementException e) {
-        break;
+      if (evictable.isEmpty()) {
+        replica = (ShortCircuitReplica) evictableMmapped
+            .get(evictableMmapped.firstKey());
+      } else {
+        replica = (ShortCircuitReplica) evictable.get(evictable.firstKey());
       }
+
       if (LOG.isTraceEnabled()) {
         LOG.trace(this + ": trimEvictionMaps is purging " + replica +
             StringUtils.getStackTrace(Thread.currentThread()));


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org


Mime
View raw message