Skip to content

Commit

Permalink
amending apparently flakey TestBucketCache.testNotifyFileCachingCompl…
Browse files Browse the repository at this point in the history
…etedSuccess

Change-Id: I84268b4deb2a91c20e082c2bbf1f354b852f521a
  • Loading branch information
wchevreuil committed Oct 4, 2024
1 parent 7c16de1 commit 1435331
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,7 @@ protected void cacheBlockWithWaitInternal(BlockCacheKey cacheKey, Cacheable cach
successfulAddition = bq.offer(re);
}
if (!successfulAddition) {
LOG.debug("Failed to insert block {} into the cache writers queue", cacheKey);
ramCache.remove(cacheKey);
cacheStats.failInsert();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.mockito.Mockito;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableMap;

Expand All @@ -82,6 +84,8 @@
@Category({ IOTests.class, LargeTests.class })
public class TestBucketCache {

private static final Logger LOG = LoggerFactory.getLogger(TestBucketCache.class);

@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestBucketCache.class);
Expand Down Expand Up @@ -911,8 +915,16 @@ public void testNotifyFileCachingCompletedSuccess() throws Exception {
try {
Path filePath =
new Path(HBASE_TESTING_UTILITY.getDataTestDir(), "testNotifyFileCachingCompletedSuccess");
bucketCache = testNotifyFileCachingCompleted(filePath, 10);
assertTrue(bucketCache.fullyCachedFiles.containsKey(filePath.getName()));
bucketCache = testNotifyFileCachingCompletedForTenBlocks(filePath, 10);
if (bucketCache.getStats().getFailedInserts() > 0) {
LOG.info("There were {} fail inserts, "
+ "will assert if total blocks in backingMap equals (10 - failInserts) "
+ "and file isn't listed as fully cached.", bucketCache.getStats().getFailedInserts());
assertEquals(10 - bucketCache.getStats().getFailedInserts(), bucketCache.backingMap.size());
assertFalse(bucketCache.fullyCachedFiles.containsKey(filePath.getName()));
} else {
assertTrue(bucketCache.fullyCachedFiles.containsKey(filePath.getName()));
}
} finally {
if (bucketCache != null) {
bucketCache.shutdown();
Expand All @@ -929,7 +941,7 @@ public void testNotifyFileCachingCompletedNotAllCached() throws Exception {
"testNotifyFileCachingCompletedNotAllCached");
// Deliberately passing more blocks than we have created to test that
// notifyFileCachingCompleted will not consider the file fully cached
bucketCache = testNotifyFileCachingCompleted(filePath, 12);
bucketCache = testNotifyFileCachingCompletedForTenBlocks(filePath, 12);
assertFalse(bucketCache.fullyCachedFiles.containsKey(filePath.getName()));
} finally {
if (bucketCache != null) {
Expand All @@ -939,8 +951,8 @@ public void testNotifyFileCachingCompletedNotAllCached() throws Exception {
}
}

private BucketCache testNotifyFileCachingCompleted(Path filePath, int totalBlocks)
throws Exception {
private BucketCache testNotifyFileCachingCompletedForTenBlocks(Path filePath,
int totalBlocksToCheck) throws Exception {
final Path dataTestDir = createAndGetTestDir();
String ioEngineName = "file:" + dataTestDir + "/bucketNoRecycler.cache";
BucketCache bucketCache = new BucketCache(ioEngineName, capacitySize, constructedBlockSize,
Expand All @@ -954,8 +966,8 @@ private BucketCache testNotifyFileCachingCompleted(Path filePath, int totalBlock
for (HFileBlockPair hfileBlockPair : hfileBlockPairs) {
bucketCache.cacheBlock(hfileBlockPair.getBlockName(), hfileBlockPair.getBlock(), false, true);
}
bucketCache.notifyFileCachingCompleted(filePath, totalBlocks, totalBlocks,
totalBlocks * constructedBlockSize);
bucketCache.notifyFileCachingCompleted(filePath, totalBlocksToCheck, totalBlocksToCheck,
totalBlocksToCheck * constructedBlockSize);
return bucketCache;
}
}

0 comments on commit 1435331

Please sign in to comment.