Apache9 commented on a change in pull request #3680:
URL: https://github.com/apache/hbase/pull/3680#discussion_r708274079
##########
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:
Ditto. And also no empty return.
##########
File path:
hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketCache.java
##########
@@ -550,13 +555,29 @@ public Cacheable getBlock(BlockCacheKey key, boolean
caching, boolean repeat,
return null;
}
+ /**
+ * This method is invoked after the bucketEntry is removed from {@link
BucketCache#backingMap}
+ * @param cacheKey
Review comment:
Remove empty param
##########
File path:
hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketCache.java
##########
@@ -550,13 +555,29 @@ public Cacheable getBlock(BlockCacheKey key, boolean
caching, boolean repeat,
return null;
}
+ /**
+ * This method is invoked after the bucketEntry is removed from {@link
BucketCache#backingMap}
+ * @param cacheKey
+ * @param bucketEntry
+ * @param decrementBlockNumber
+ */
void blockEvicted(BlockCacheKey cacheKey, BucketEntry bucketEntry, boolean
decrementBlockNumber) {
- bucketAllocator.freeBlock(bucketEntry.offset());
- realCacheSize.add(-1 * bucketEntry.getLength());
+ bucketEntry.markAsEvicted();
blocksByHFile.remove(cacheKey);
if (decrementBlockNumber) {
this.blockNumber.decrement();
}
+ cacheStats.evicted(bucketEntry.getCachedTime(), cacheKey.isPrimary());
+ }
+
+ /**
+ * Free the {{@link BucketEntry} actually,which could only be invoked when
the
+ * {@link BucketEntry#refCnt} becoming 0.
+ * @param bucketEntry
Review comment:
Ditto.
--
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]