Skip to content

Commit daa1e14

Browse files
author
sunlisheng
committed
when evictableMmapped or evictable size is zero, do not throw NoSuchElementException
Signed-off-by: sunlisheng <sunlisheng@xiaomi.com>
1 parent d996479 commit daa1e14

File tree

1 file changed

+11
-29
lines changed
  • hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/shortcircuit

1 file changed

+11
-29
lines changed

hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/shortcircuit/ShortCircuitCache.java

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,8 @@ public void run() {
109109
int numDemoted = demoteOldEvictableMmaped(curMs);
110110
int numPurged = 0;
111111
Long evictionTimeNs;
112-
while (true) {
113-
Object eldestKey;
114-
try {
115-
eldestKey = evictable.firstKey();
116-
} catch (NoSuchElementException e) {
117-
break;
118-
}
112+
while (!evictable.isEmpty()) {
113+
Object eldestKey = evictable.firstKey();
119114
evictionTimeNs = (Long)eldestKey;
120115
long evictionTimeMs =
121116
TimeUnit.MILLISECONDS.convert(evictionTimeNs, TimeUnit.NANOSECONDS);
@@ -493,13 +488,8 @@ private int demoteOldEvictableMmaped(long now) {
493488
boolean needMoreSpace = false;
494489
Long evictionTimeNs;
495490

496-
while (true) {
497-
Object eldestKey;
498-
try {
499-
eldestKey = evictableMmapped.firstKey();
500-
} catch (NoSuchElementException e) {
501-
break;
502-
}
491+
while (!evictableMmapped.isEmpty()) {
492+
Object eldestKey = evictableMmapped.firstKey();
503493
evictionTimeNs = (Long)eldestKey;
504494
long evictionTimeMs =
505495
TimeUnit.MILLISECONDS.convert(evictionTimeNs, TimeUnit.NANOSECONDS);
@@ -533,23 +523,15 @@ private void trimEvictionMaps() {
533523
long now = Time.monotonicNow();
534524
demoteOldEvictableMmaped(now);
535525

536-
while (true) {
537-
long evictableSize = evictable.size();
538-
long evictableMmappedSize = evictableMmapped.size();
539-
if (evictableSize + evictableMmappedSize <= maxTotalSize) {
540-
return;
541-
}
526+
while (evictable.size() + evictableMmapped.size() > maxTotalSize) {
542527
ShortCircuitReplica replica;
543-
try {
544-
if (evictableSize == 0) {
545-
replica = (ShortCircuitReplica)evictableMmapped.get(evictableMmapped
546-
.firstKey());
547-
} else {
548-
replica = (ShortCircuitReplica)evictable.get(evictable.firstKey());
549-
}
550-
} catch (NoSuchElementException e) {
551-
break;
528+
if (evictable.isEmpty()) {
529+
replica = (ShortCircuitReplica) evictableMmapped
530+
.get(evictableMmapped.firstKey());
531+
} else {
532+
replica = (ShortCircuitReplica) evictable.get(evictable.firstKey());
552533
}
534+
553535
if (LOG.isTraceEnabled()) {
554536
LOG.trace(this + ": trimEvictionMaps is purging " + replica +
555537
StringUtils.getStackTrace(Thread.currentThread()));

0 commit comments

Comments
 (0)