You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hbase.apache.org by "virajjasani (via GitHub)" <gi...@apache.org> on 2023/04/15 04:20:25 UTC
[GitHub] [hbase] virajjasani commented on a diff in pull request #5181: HBASE-27796 Improve MemcachedBlockCache
virajjasani commented on code in PR #5181:
URL: https://github.com/apache/hbase/pull/5181#discussion_r1167370213
##########
hbase-external-blockcache/pom.xml:
##########
@@ -51,7 +51,63 @@
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
+ <artifactId>jcl-over-slf4j</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>jul-to-slf4j</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-slf4j-impl</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-1.2-api</artifactId>
+ <scope>test</scope>
+ </dependency>
Review Comment:
All these `log4j*` dependencies are required for `jmemcached-core`?
##########
hbase-external-blockcache/src/main/java/org/apache/hadoop/hbase/io/hfile/MemcachedBlockCache.java:
##########
@@ -67,10 +78,20 @@ public class MemcachedBlockCache implements BlockCache {
public static final String MEMCACHED_OPTIMIZE_KEY = "hbase.cache.memcached.spy.optimze";
public static final long MEMCACHED_DEFAULT_TIMEOUT = 500;
public static final boolean MEMCACHED_OPTIMIZE_DEFAULT = false;
+ public static final int STAT_THREAD_PERIOD = 60 * 5;
private final MemcachedClient client;
private final HFileBlockTranscoder tc = new HFileBlockTranscoder();
private final CacheStats cacheStats = new CacheStats("MemcachedBlockCache");
+ private final AtomicLong cachedCount = new AtomicLong();
+ private final AtomicLong notCachedCount = new AtomicLong();
+ private final AtomicLong cacheErrorCount = new AtomicLong();
+ private final AtomicLong timeoutCount = new AtomicLong();
+
+ /** Statistics thread schedule pool (for heavy debugging, could remove) */
+ private transient final ScheduledExecutorService scheduleThreadPool =
+ Executors.newScheduledThreadPool(1, new ThreadFactoryBuilder()
+ .setNameFormat("MemcachedBlockCacheStatsExecutor").setDaemon(true).build());
Review Comment:
Since it is meant for debugging, shall we initialize the thread pool with only some configuration (default off)?
##########
hbase-external-blockcache/src/test/java/org/apache/hadoop/hbase/io/hfile/TestMemcachedBlockCache.java:
##########
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.io.hfile;
+
+import static org.junit.Assert.assertEquals;
+
+import com.thimbleware.jmemcached.CacheElement;
+import com.thimbleware.jmemcached.CacheImpl;
+import com.thimbleware.jmemcached.Key;
+import com.thimbleware.jmemcached.LocalCacheElement;
+import com.thimbleware.jmemcached.MemCacheDaemon;
+import com.thimbleware.jmemcached.storage.hash.ConcurrentLinkedHashMap;
+import com.thimbleware.jmemcached.storage.hash.ConcurrentLinkedHashMap.EvictionPolicy;
+import java.net.InetSocketAddress;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.HBaseTestingUtil;
+import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.Waiter;
+import org.apache.hadoop.hbase.io.hfile.CacheTestUtils.HFileBlockPair;
+import org.apache.hadoop.hbase.testclassification.IOTests;
+import org.apache.hadoop.hbase.testclassification.LargeTests;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category({ IOTests.class, LargeTests.class })
+public class TestMemcachedBlockCache {
+
+ @ClassRule
+ public static final HBaseClassTestRule CLASS_RULE =
+ HBaseClassTestRule.forClass(TestMemcachedBlockCache.class);
+
+ static MemCacheDaemon<? extends CacheElement> MEMCACHED;
+ static MemcachedBlockCache CACHE;
+
+ @Before
+ public void before() throws Exception {
+ MEMCACHED.getCache().flush_all();
+ assertEquals("Memcache is not empty", MEMCACHED.getCache().getCurrentItems(), 0);
+ }
+
+ @BeforeClass
+ public static void setup() throws Exception {
+ int port = HBaseTestingUtil.randomFreePort();
+ MEMCACHED = createDaemon(port);
+ Configuration conf = new Configuration();
+ conf.set("hbase.cache.memcached.servers", "localhost:" + port);
+ CACHE = new MemcachedBlockCache(conf);
+ }
+
+ @AfterClass
+ public static void tearDown() throws Exception {
+ if (MEMCACHED != null) {
+ MEMCACHED.stop();
+ }
+ }
+
+ @Test
+ public void testCache() throws Exception {
+ final int NUM_BLOCKS = 10;
+ HFileBlockPair[] blocks =
+ CacheTestUtils.generateHFileBlocks(HConstants.DEFAULT_BLOCKSIZE, NUM_BLOCKS);
+ for (int i = 0; i < NUM_BLOCKS; i++) {
+ CACHE.cacheBlock(blocks[i].getBlockName(), blocks[i].getBlock());
+ }
+ Waiter.waitFor(new Configuration(), 10000,
+ () -> MEMCACHED.getCache().getCurrentItems() == NUM_BLOCKS);
+ }
+
+ @Test
+ public void testEviction() throws Exception {
+ final int NUM_BLOCKS = 10;
+ HFileBlockPair[] blocks =
+ CacheTestUtils.generateHFileBlocks(HConstants.DEFAULT_BLOCKSIZE, NUM_BLOCKS);
+ for (int i = 0; i < NUM_BLOCKS; i++) {
+ CACHE.cacheBlock(blocks[i].getBlockName(), blocks[i].getBlock());
+ }
+ Waiter.waitFor(new Configuration(), 10000,
+ () -> MEMCACHED.getCache().getCurrentItems() == NUM_BLOCKS);
+ for (int i = 0; i < NUM_BLOCKS; i++) {
+ CACHE.evictBlock(blocks[i].getBlockName());
+ }
+ Waiter.waitFor(new Configuration(), 10000, () -> MEMCACHED.getCache().getCurrentItems() == 0);
+ }
+
+ private static MemCacheDaemon<? extends CacheElement> createDaemon(int port) {
Review Comment:
Looks like we didn't have tests so far that runs memcached locally?
##########
hbase-external-blockcache/src/main/java/org/apache/hadoop/hbase/io/hfile/MemcachedBlockCache.java:
##########
@@ -139,17 +165,24 @@ public Cacheable getBlock(BlockCacheKey cacheKey, boolean caching, boolean repea
try (Scope traceScope = span.makeCurrent()) {
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 memcache 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);
+ if (
+ (e instanceof OperationTimeoutException) || ((e instanceof RuntimeException)
+ && (e.getCause() instanceof OperationTimeoutException))
+ ) {
+ timeoutCount.incrementAndGet();
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Timeout getting key " + cacheKey.toString(), e);
+ }
+ } else {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Exception getting key " + cacheKey.toString(), e);
+ }
}
Review Comment:
We need to increment `cacheErrorCount` correct?
--
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: issues-unsubscribe@hbase.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org