Skip to content

Commit d1866bc

Browse files
jhungundwchevreuil
authored andcommitted
HBASE-28804: Implement asynchronous retrieval of bucket-cache data from persistence (#6182) (#6219)
The cherry-pick of HBASE-29727 into branch-2.6 accidently brought most of HBASE-28804 into branch-2, this is to backport the remaining original change in HBASE-28804. Signed-off-by: Wellington Chevreuil <wchevreuil@apache.org> Change-Id: I816141ccebf91191aaa4cb6afa04343b64663eb0
1 parent c8f512a commit d1866bc

File tree

2 files changed

+35
-27
lines changed

2 files changed

+35
-27
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFilePreadReader.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ public class HFilePreadReader extends HFileReaderImpl {
3737
public HFilePreadReader(ReaderContext context, HFileInfo fileInfo, CacheConfig cacheConf,
3838
Configuration conf) throws IOException {
3939
super(context, fileInfo, cacheConf, conf);
40+
cacheConf.getBlockCache()
41+
.ifPresent(cache -> cache.waitForCacheInitialization(WAIT_TIME_FOR_CACHE_INITIALIZATION));
42+
4043
// Initialize HFileInfo object with metadata for caching decisions
4144
fileInfo.initMetaAndIndex(this);
4245
// master hosted regions, like the master procedures store wouldn't have a block cache

hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestVerifyBucketCacheFile.java

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ public void testRetrieveFromFile() throws Exception {
108108
bucketCache = new BucketCache("file:" + testDir + "/bucket.cache", capacitySize,
109109
constructedBlockSize, constructedBlockSizes, writeThreads, writerQLen,
110110
testDir + "/bucket.persistence", DEFAULT_ERROR_TOLERATION_DURATION, conf);
111-
assertTrue(bucketCache.waitForCacheInitialization(10000));long usedSize = bucketCache.getAllocator().getUsedSize();
111+
assertTrue(bucketCache.waitForCacheInitialization(10000));
112+
long usedSize = bucketCache.getAllocator().getUsedSize();
112113
assertEquals(0, usedSize);
113114
CacheTestUtils.HFileBlockPair[] blocks =
114115
CacheTestUtils.generateHFileBlocks(constructedBlockSize, 1);
@@ -125,30 +126,30 @@ public void testRetrieveFromFile() throws Exception {
125126
constructedBlockSize, constructedBlockSizes, writeThreads, writerQLen,
126127
testDir + "/bucket.persistence", DEFAULT_ERROR_TOLERATION_DURATION, conf);
127128
waitPersistentCacheValidation(conf, bucketCache);
128-
assertTrue(bucketCache.waitForCacheInitialization(10000));
129+
assertTrue(bucketCache.waitForCacheInitialization(10000));
129130
assertEquals(usedSize, bucketCache.getAllocator().getUsedSize());
130131
// persist cache to file
131132
bucketCache.shutdown();
132133

133-
// 2.delete bucket cache file
134-
final java.nio.file.Path cacheFile =
135-
FileSystems.getDefault().getPath(testDir.toString(), "bucket.cache");
136-
assertTrue(Files.deleteIfExists(cacheFile));
137-
// can't restore cache from file
138-
bucketCache =
139-
new BucketCache("file:" + testDir + "/bucket.cache", capacitySize, constructedBlockSize,
140-
constructedBlockSizes, writeThreads, writerQLen, testDir + "/bucket.persistence");
141-
assertTrue(bucketCache.waitForCacheInitialization(10000));
142-
assertEquals(0, bucketCache.getAllocator().getUsedSize());
143-
assertEquals(0, bucketCache.backingMap.size());
144-
// Add blocks
145-
for (CacheTestUtils.HFileBlockPair block : blocks) {
146-
cacheAndWaitUntilFlushedToBucket(bucketCache, block.getBlockName(), block.getBlock());
147-
}
148-
usedSize = bucketCache.getAllocator().getUsedSize();
149-
assertNotEquals(0, usedSize);
150-
// persist cache to file
151-
bucketCache.shutdown();
134+
// 2.delete bucket cache file
135+
final java.nio.file.Path cacheFile =
136+
FileSystems.getDefault().getPath(testDir.toString(), "bucket.cache");
137+
assertTrue(Files.deleteIfExists(cacheFile));
138+
// can't restore cache from file
139+
bucketCache =
140+
new BucketCache("file:" + testDir + "/bucket.cache", capacitySize, constructedBlockSize,
141+
constructedBlockSizes, writeThreads, writerQLen, testDir + "/bucket.persistence");
142+
assertTrue(bucketCache.waitForCacheInitialization(10000));
143+
assertEquals(0, bucketCache.getAllocator().getUsedSize());
144+
assertEquals(0, bucketCache.backingMap.size());
145+
// Add blocks
146+
for (CacheTestUtils.HFileBlockPair block : blocks) {
147+
cacheAndWaitUntilFlushedToBucket(bucketCache, block.getBlockName(), block.getBlock());
148+
}
149+
usedSize = bucketCache.getAllocator().getUsedSize();
150+
assertNotEquals(0, usedSize);
151+
// persist cache to file
152+
bucketCache.shutdown();
152153

153154
// 3.delete backingMap persistence file
154155
final java.nio.file.Path mapFile =
@@ -186,7 +187,8 @@ public void testRetrieveFromFileAfterDelete() throws Exception {
186187
bucketCache = new BucketCache("file:" + testDir + "/bucket.cache", capacitySize,
187188
constructedBlockSize, constructedBlockSizes, writeThreads, writerQLen, mapFileName,
188189
DEFAULT_ERROR_TOLERATION_DURATION, conf);
189-
assertTrue(bucketCache.waitForCacheInitialization(10000)); long usedSize = bucketCache.getAllocator().getUsedSize();
190+
assertTrue(bucketCache.waitForCacheInitialization(10000));
191+
long usedSize = bucketCache.getAllocator().getUsedSize();
190192
assertEquals(0, usedSize);
191193
CacheTestUtils.HFileBlockPair[] blocks =
192194
CacheTestUtils.generateHFileBlocks(constructedBlockSize, 1);
@@ -238,7 +240,8 @@ public void testModifiedBucketCacheFileData() throws Exception {
238240
bucketCache = new BucketCache("file:" + testDir + "/bucket.cache", capacitySize,
239241
constructedBlockSize, constructedBlockSizes, writeThreads, writerQLen,
240242
testDir + "/bucket.persistence", DEFAULT_ERROR_TOLERATION_DURATION, conf);
241-
assertTrue(bucketCache.waitForCacheInitialization(10000));long usedSize = bucketCache.getAllocator().getUsedSize();
243+
assertTrue(bucketCache.waitForCacheInitialization(10000));
244+
long usedSize = bucketCache.getAllocator().getUsedSize();
242245
assertEquals(0, usedSize);
243246

244247
CacheTestUtils.HFileBlockPair[] blocks =
@@ -300,7 +303,8 @@ public void testModifiedBucketCacheFileTime() throws Exception {
300303
bucketCache = new BucketCache("file:" + testDir + "/bucket.cache", capacitySize,
301304
constructedBlockSize, constructedBlockSizes, writeThreads, writerQLen,
302305
testDir + "/bucket.persistence", DEFAULT_ERROR_TOLERATION_DURATION, conf);
303-
assertTrue(bucketCache.waitForCacheInitialization(10000));long usedSize = bucketCache.getAllocator().getUsedSize();
306+
assertTrue(bucketCache.waitForCacheInitialization(10000));
307+
long usedSize = bucketCache.getAllocator().getUsedSize();
304308
assertEquals(0, usedSize);
305309

306310
Pair<String, Long> myPair = new Pair<>();
@@ -327,7 +331,8 @@ public void testModifiedBucketCacheFileTime() throws Exception {
327331
constructedBlockSize, constructedBlockSizes, writeThreads, writerQLen,
328332
testDir + "/bucket.persistence", DEFAULT_ERROR_TOLERATION_DURATION, conf);
329333
waitPersistentCacheValidation(conf, bucketCache);
330-
assertTrue(bucketCache.waitForCacheInitialization(10000));assertEquals(usedSize, bucketCache.getAllocator().getUsedSize());
334+
assertTrue(bucketCache.waitForCacheInitialization(10000));
335+
assertEquals(usedSize, bucketCache.getAllocator().getUsedSize());
331336
assertEquals(blockCount, bucketCache.backingMap.size());
332337
} finally {
333338
if (bucketCache != null) {
@@ -360,7 +365,7 @@ public void testBucketCacheRecovery() throws Exception {
360365
bucketCache = new BucketCache("file:" + testDir + "/bucket.cache", capacitySize,
361366
constructedBlockSize, constructedBlockSizes, writeThreads, writerQLen, mapFileName,
362367
DEFAULT_ERROR_TOLERATION_DURATION, conf);
363-
assertTrue(bucketCache.waitForCacheInitialization(10000));
368+
assertTrue(bucketCache.waitForCacheInitialization(10000));
364369

365370
CacheTestUtils.HFileBlockPair[] blocks =
366371
CacheTestUtils.generateHFileBlocks(constructedBlockSize, 4);
@@ -428,7 +433,7 @@ private void testChunkedBackingMapRecovery(int chunkSize, int numBlocks) throws
428433
bucketCache = new BucketCache("file:" + testDir + "/bucket.cache", capacitySize,
429434
constructedBlockSize, constructedBlockSizes, writeThreads, writerQLen, mapFileName,
430435
DEFAULT_ERROR_TOLERATION_DURATION, conf);
431-
assertTrue(bucketCache.waitForCacheInitialization(10000));
436+
assertTrue(bucketCache.waitForCacheInitialization(10000));
432437

433438
CacheTestUtils.HFileBlockPair[] blocks =
434439
CacheTestUtils.generateHFileBlocks(constructedBlockSize, numBlocks);

0 commit comments

Comments
 (0)