HBASE-22447 Check refCount before free block in BucketCache
This commit is contained in:
parent
5b24d4e1bc
commit
81dc712779
|
@ -554,37 +554,6 @@ public class BucketCache implements BlockCache, HeapSize {
|
||||||
return evictBlock(cacheKey, true);
|
return evictBlock(cacheKey, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// does not check for the ref count. Just tries to evict it if found in the
|
|
||||||
// bucket map
|
|
||||||
private boolean forceEvict(BlockCacheKey cacheKey) {
|
|
||||||
if (!cacheEnabled) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
RAMQueueEntry removedBlock = checkRamCache(cacheKey);
|
|
||||||
BucketEntry bucketEntry = backingMap.get(cacheKey);
|
|
||||||
if (bucketEntry == null) {
|
|
||||||
if (removedBlock != null) {
|
|
||||||
cacheStats.evicted(0, cacheKey.isPrimary());
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ReentrantReadWriteLock lock = offsetLock.getLock(bucketEntry.offset());
|
|
||||||
try {
|
|
||||||
lock.writeLock().lock();
|
|
||||||
if (backingMap.remove(cacheKey, bucketEntry)) {
|
|
||||||
blockEvicted(cacheKey, bucketEntry, removedBlock == null);
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
lock.writeLock().unlock();
|
|
||||||
}
|
|
||||||
cacheStats.evicted(bucketEntry.getCachedTime(), cacheKey.isPrimary());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private RAMQueueEntry checkRamCache(BlockCacheKey cacheKey) {
|
private RAMQueueEntry checkRamCache(BlockCacheKey cacheKey) {
|
||||||
RAMQueueEntry removedBlock = ramCache.remove(cacheKey);
|
RAMQueueEntry removedBlock = ramCache.remove(cacheKey);
|
||||||
if (removedBlock != null) {
|
if (removedBlock != null) {
|
||||||
|
@ -1046,8 +1015,15 @@ public class BucketCache implements BlockCache, HeapSize {
|
||||||
ReentrantReadWriteLock lock = offsetLock.getLock(bucketEntries[i].offset());
|
ReentrantReadWriteLock lock = offsetLock.getLock(bucketEntries[i].offset());
|
||||||
try {
|
try {
|
||||||
lock.writeLock().lock();
|
lock.writeLock().lock();
|
||||||
if (backingMap.remove(key, bucketEntries[i])) {
|
int refCount = bucketEntries[i].getRefCount();
|
||||||
blockEvicted(key, bucketEntries[i], false);
|
if (refCount == 0) {
|
||||||
|
if (backingMap.remove(key, bucketEntries[i])) {
|
||||||
|
blockEvicted(key, bucketEntries[i], false);
|
||||||
|
} else {
|
||||||
|
bucketEntries[i].markForEvict();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
bucketEntries[i].markForEvict();
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
lock.writeLock().unlock();
|
lock.writeLock().unlock();
|
||||||
|
@ -1666,7 +1642,7 @@ public class BucketCache implements BlockCache, HeapSize {
|
||||||
if (bucketEntry != null) {
|
if (bucketEntry != null) {
|
||||||
int refCount = bucketEntry.decrementRefCountAndGet();
|
int refCount = bucketEntry.decrementRefCountAndGet();
|
||||||
if (refCount == 0 && bucketEntry.isMarkedForEvict()) {
|
if (refCount == 0 && bucketEntry.isMarkedForEvict()) {
|
||||||
forceEvict(cacheKey);
|
evictBlock(cacheKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue