diff --git a/hbase-external-blockcache/src/main/java/org/apache/hadoop/hbase/io/hfile/MemcachedBlockCache.java b/hbase-external-blockcache/src/main/java/org/apache/hadoop/hbase/io/hfile/MemcachedBlockCache.java index ba6ae1e..489cf62 100644 --- a/hbase-external-blockcache/src/main/java/org/apache/hadoop/hbase/io/hfile/MemcachedBlockCache.java +++ b/hbase-external-blockcache/src/main/java/org/apache/hadoop/hbase/io/hfile/MemcachedBlockCache.java @@ -54,14 +54,14 @@ import org.slf4j.LoggerFactory; */ @InterfaceAudience.Private public class MemcachedBlockCache implements BlockCache { - private static final Logger LOG = LoggerFactory.getLogger(MemcachedBlockCache.class.getName()); + private static final Logger LOG = LoggerFactory.getLogger(MemcachedBlockCache.class); // Some memcache versions won't take more than 1024 * 1024. So set the limit below // that just in case this client is used with those versions. public static final int MAX_SIZE = 1020 * 1024; // Config key for what memcached servers to use. - // They should be specified in a comma sperated list with ports. + // They should be specified in a comma separated list with ports. // like: // // host1:11211,host3:8080,host4:11211 @@ -98,10 +98,10 @@ public class MemcachedBlockCache implements BlockCache { // If this config is a pool of memecached servers they will all be used according to the // default hashing scheme defined by the memcache client. Spy Memecache client in this // case. - String serverListString = c.get(MEMCACHED_CONFIG_KEY,"localhost:11211"); + String serverListString = c.get(MEMCACHED_CONFIG_KEY, "localhost:11211"); String[] servers = serverListString.split(","); List serverAddresses = new ArrayList<>(servers.length); - for (String s:servers) { + for (String s : servers) { serverAddresses.add(Addressing.createInetSocketAddressFromHostAndPortStr(s)); } @@ -118,10 +118,7 @@ public class MemcachedBlockCache implements BlockCache { if (buf instanceof HFileBlock) { client.add(cacheKey.toString(), MAX_SIZE, (HFileBlock) buf, tc); } else { - if (LOG.isDebugEnabled()) { - LOG.debug("MemcachedBlockCache can not cache Cacheable's of type " - + buf.getClass().toString()); - } + LOG.debug("MemcachedBlockCache can not cache Cacheable's of type {}", buf.getClass()); } } @@ -134,25 +131,18 @@ public class MemcachedBlockCache implements BlockCache { try (TraceScope traceScope = TraceUtil.createTrace("MemcachedBlockCache.getBlock")) { result = client.get(cacheKey.toString(), tc); } catch (Exception e) { - // Catch a pretty broad set of exceptions to limit any changes in the memecache client + // Catch a pretty broad set of exceptions to limit any changes in the memcached client // and how it handles failures from leaking into the read path. - if (LOG.isDebugEnabled()) { - LOG.debug("Exception pulling from memcached [ " - + cacheKey.toString() - + " ]. Treating as a miss.", e); - } - result = null; - } finally { - // Update stats if this request doesn't have it turned off 100% of the time - if (updateCacheMetrics) { - if (result == null) { - cacheStats.miss(caching, cacheKey.isPrimary(), cacheKey.getBlockType()); - } else { - cacheStats.hit(caching, cacheKey.isPrimary(), cacheKey.getBlockType()); - } + LOG.debug("Exception pulling from memcached [{}]. Treating as a miss.", cacheKey, e); + } + // Update stats if this request does not have it turned off 100% of the time + if (updateCacheMetrics) { + if (result == null) { + cacheStats.miss(caching, cacheKey.isPrimary(), cacheKey.getBlockType()); + } else { + cacheStats.hit(caching, cacheKey.isPrimary(), cacheKey.getBlockType()); } } - return result; } @@ -162,12 +152,10 @@ public class MemcachedBlockCache implements BlockCache { cacheStats.evict(); return client.delete(cacheKey.toString()).get(); } catch (InterruptedException e) { - LOG.warn("Error deleting " + cacheKey.toString(), e); + LOG.warn("Error deleting {}", cacheKey, e); Thread.currentThread().interrupt(); } catch (ExecutionException e) { - if (LOG.isDebugEnabled()) { - LOG.debug("Error deleting " + cacheKey.toString(), e); - } + LOG.debug("Error deleting {}", cacheKey, e); } return false; } @@ -235,7 +223,7 @@ public class MemcachedBlockCache implements BlockCache { @Override public CachedBlock next() { - throw new NoSuchElementException("MemcachedBlockCache can't iterate over blocks."); + throw new NoSuchElementException("MemcachedBlockCache cannot iterate over blocks"); } @Override