virajjasani commented on a change in pull request #673: HBASE-23093 : Avoid
Optional Anti-Pattern where possible
URL: https://github.com/apache/hbase/pull/673#discussion_r332423948
##########
File path:
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerWrapperImpl.java
##########
@@ -275,7 +276,7 @@ public int getFlushQueueSize() {
@Override
public long getBlockCacheCount() {
- return this.blockCache.map(BlockCache::getBlockCount).orElse(0L);
+ return this.blockCache != null ? this.blockCache.getBlockCount() : 0L;
Review comment:
Valid and agree with this. Although one thing to notice is initBlockCache()
is called only once during initialization and not multiple times. Whereas all
these getters can be called multiple times and hence, those many isPresent()
checks followed by Optional.ofNullable() calls.
Rather we can just do unwrap once during init() and then have simple null
check and no Optional.ofNullable() during every get call. Thought?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services