Merge pull request #977 from leosunli/trunk

HDFS-14541. When evictableMmapped or evictable size is zero, do not throw NoSuchElementException.
This commit is contained in:
Inigo Goiri 2019-06-24 17:44:54 -07:00 committed by GitHub
commit 38a560c6f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 29 deletions

View File

@ -109,13 +109,8 @@ public class ShortCircuitCache implements Closeable {
int numDemoted = demoteOldEvictableMmaped(curMs); int numDemoted = demoteOldEvictableMmaped(curMs);
int numPurged = 0; int numPurged = 0;
Long evictionTimeNs; Long evictionTimeNs;
while (true) { while (!evictable.isEmpty()) {
Object eldestKey; Object eldestKey = evictable.firstKey();
try {
eldestKey = evictable.firstKey();
} catch (NoSuchElementException e) {
break;
}
evictionTimeNs = (Long)eldestKey; evictionTimeNs = (Long)eldestKey;
long evictionTimeMs = long evictionTimeMs =
TimeUnit.MILLISECONDS.convert(evictionTimeNs, TimeUnit.NANOSECONDS); TimeUnit.MILLISECONDS.convert(evictionTimeNs, TimeUnit.NANOSECONDS);
@ -493,13 +488,8 @@ public class ShortCircuitCache implements Closeable {
boolean needMoreSpace = false; boolean needMoreSpace = false;
Long evictionTimeNs; Long evictionTimeNs;
while (true) { while (!evictableMmapped.isEmpty()) {
Object eldestKey; Object eldestKey = evictableMmapped.firstKey();
try {
eldestKey = evictableMmapped.firstKey();
} catch (NoSuchElementException e) {
break;
}
evictionTimeNs = (Long)eldestKey; evictionTimeNs = (Long)eldestKey;
long evictionTimeMs = long evictionTimeMs =
TimeUnit.MILLISECONDS.convert(evictionTimeNs, TimeUnit.NANOSECONDS); TimeUnit.MILLISECONDS.convert(evictionTimeNs, TimeUnit.NANOSECONDS);
@ -533,23 +523,15 @@ public class ShortCircuitCache implements Closeable {
long now = Time.monotonicNow(); long now = Time.monotonicNow();
demoteOldEvictableMmaped(now); demoteOldEvictableMmaped(now);
while (true) { while (evictable.size() + evictableMmapped.size() > maxTotalSize) {
long evictableSize = evictable.size();
long evictableMmappedSize = evictableMmapped.size();
if (evictableSize + evictableMmappedSize <= maxTotalSize) {
return;
}
ShortCircuitReplica replica; ShortCircuitReplica replica;
try { if (evictable.isEmpty()) {
if (evictableSize == 0) { replica = (ShortCircuitReplica) evictableMmapped
replica = (ShortCircuitReplica)evictableMmapped.get(evictableMmapped .get(evictableMmapped.firstKey());
.firstKey()); } else {
} else { replica = (ShortCircuitReplica) evictable.get(evictable.firstKey());
replica = (ShortCircuitReplica)evictable.get(evictable.firstKey());
}
} catch (NoSuchElementException e) {
break;
} }
if (LOG.isTraceEnabled()) { if (LOG.isTraceEnabled()) {
LOG.trace(this + ": trimEvictionMaps is purging " + replica + LOG.trace(this + ": trimEvictionMaps is purging " + replica +
StringUtils.getStackTrace(Thread.currentThread())); StringUtils.getStackTrace(Thread.currentThread()));