comnetwork commented on a change in pull request #3680:
URL: https://github.com/apache/hbase/pull/3680#discussion_r708808296
##########
File path:
hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketCache.java
##########
@@ -577,43 +598,84 @@ void blockEvicted(BlockCacheKey cacheKey, BucketEntry
bucketEntry, boolean decre
*/
@Override
public boolean evictBlock(BlockCacheKey cacheKey) {
+ return doEvictBlock(cacheKey, null);
+ }
+
+ /**
+ * Evict the {@link BlockCacheKey} and {@link BucketEntry} from {@link
BucketCache#backingMap} and
+ * {@link BucketCache#ramCache}. <br/>
+ * NOTE:When Evict from {@link BucketCache#backingMap},only the matched
{@link BlockCacheKey} and
+ * {@link BucketEntry} could be removed.
+ * @param cacheKey
+ * @param bucketEntry
+ * @return
+ */
+ private boolean doEvictBlock(BlockCacheKey cacheKey, BucketEntry
bucketEntry) {
if (!cacheEnabled) {
return false;
}
- boolean existed = removeFromRamCache(cacheKey);
- BucketEntry be = backingMap.get(cacheKey);
- if (be == null) {
- if (existed) {
+ boolean existedInRamCache = removeFromRamCache(cacheKey);
+ if (bucketEntry == null) {
+ bucketEntry = backingMap.get(cacheKey);
+ }
+ final BucketEntry bucketEntryToUse = bucketEntry;
+
+ if (bucketEntryToUse == null) {
+ if (existedInRamCache) {
cacheStats.evicted(0, cacheKey.isPrimary());
}
- return existed;
+ return existedInRamCache;
} else {
- return be.withWriteLock(offsetLock, be::markAsEvicted);
+ return bucketEntryToUse.withWriteLock(offsetLock, () -> {
+ if (backingMap.remove(cacheKey, bucketEntryToUse)) {
+ blockEvicted(cacheKey, bucketEntryToUse, !existedInRamCache);
+ return true;
+ }
+ return false;
+ });
}
}
- private Recycler createRecycler(BlockCacheKey cacheKey) {
+ /**
+ * Create the {@link Recycler} for {@link BucketEntry#refCnt}.
+ * @param bucketEntry
+ * @return
+ */
+ protected Recycler createRecycler(final BucketEntry bucketEntry) {
return () -> {
- if (!cacheEnabled) {
- return;
- }
- boolean existed = removeFromRamCache(cacheKey);
- BucketEntry be = backingMap.get(cacheKey);
- if (be == null && existed) {
- cacheStats.evicted(0, cacheKey.isPrimary());
- } else if (be != null) {
- be.withWriteLock(offsetLock, () -> {
- if (backingMap.remove(cacheKey, be)) {
- blockEvicted(cacheKey, be, !existed);
- cacheStats.evicted(be.getCachedTime(), cacheKey.isPrimary());
- }
- return null;
- });
- }
+ freeBucketEntry(bucketEntry);
+ return;
};
}
- private boolean removeFromRamCache(BlockCacheKey cacheKey) {
+ /**
+ * NOTE: This method is only for test.
+ * @param blockCacheKey
Review comment:
Fix it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]