vaijosh commented on code in PR #7995:
URL: https://github.com/apache/hbase/pull/7995#discussion_r3007309262
##########
hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFile.java:
##########
@@ -202,6 +207,53 @@ public void testReaderWithLRUBlockCache() throws Exception
{
lru.shutdown();
}
+ @Test
+ public void testWriterCacheOnWriteSkipDoesNotLeak() throws Exception {
+ int bufCount = 32;
+ int blockSize = 4 * 1024;
+ ByteBuffAllocator alloc = initAllocator(true, blockSize, bufCount, 0);
+ fillByteBuffAllocator(alloc, bufCount);
+ ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.PARANOID);
+ Configuration myConf = HBaseConfiguration.create(conf);
+ myConf.setBoolean(CacheConfig.CACHE_BLOCKS_ON_WRITE_KEY, true);
+ myConf.setBoolean(CacheConfig.CACHE_INDEX_BLOCKS_ON_WRITE_KEY, false);
+ myConf.setBoolean(CacheConfig.CACHE_BLOOM_BLOCKS_ON_WRITE_KEY, false);
+ final AtomicInteger counter = new AtomicInteger();
+ RefCnt.detector.setLeakListener(new ResourceLeakDetector.LeakListener() {
+ @Override
+ public void onLeak(String s, String s1) {
+ counter.incrementAndGet();
+ }
+ });
+ BlockCache cache = Mockito.mock(BlockCache.class);
+ Mockito.when(cache.shouldCacheBlock(Mockito.any(), Mockito.anyLong(),
Mockito.any()))
+ .thenReturn(Optional.of(false));
+ Path hfilePath = new Path(TEST_UTIL.getDataTestDir(),
"testWriterCacheOnWriteSkipDoesNotLeak");
+ HFileContext context = new
HFileContextBuilder().withBlockSize(blockSize).build();
+
+ try {
+ Writer writer = new HFile.WriterFactory(myConf, new CacheConfig(myConf,
null, cache, alloc))
+ .withPath(fs, hfilePath).withFileContext(context).create();
+ try {
+ writer.append(new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("cf"),
Bytes.toBytes("q"),
+ HConstants.LATEST_TIMESTAMP, Bytes.toBytes("value")));
+ } finally {
+ writer.close();
+ }
+
+ Mockito.verify(cache).shouldCacheBlock(Mockito.any(), Mockito.anyLong(),
Mockito.any());
+ Mockito.verify(cache, Mockito.never()).cacheBlock(Mockito.any(),
Mockito.any(),
+ Mockito.anyBoolean(), Mockito.anyBoolean());
+ System.gc();
+ Thread.sleep(1000);
Review Comment:
@dParikesit
I think the 1-second assumption might bite us on slower systems and make the
test flaky.
What if we wrap this in a loop instead? We could retry up to 15 times with a
small delay—that way it succeeds as soon as it's ready rather than relying on
luck.
--
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]