Skip to content

Commit a6dad70

Browse files
authored
HBASE-27750: Update the list of prefetched Hfiles upon block eviction (#5140)
Signed-off-by: Wellington Chevreuil <wchevreuil@apache.org>
1 parent 735fb43 commit a6dad70

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ protected void startWriterThreads() {
379379
void startBucketCachePersisterThread() {
380380
BucketCachePersister cachePersister =
381381
new BucketCachePersister(this, bucketcachePersistInterval);
382+
cachePersister.setDaemon(true);
382383
cachePersister.start();
383384
}
384385

@@ -610,6 +611,9 @@ void blockEvicted(BlockCacheKey cacheKey, BucketEntry bucketEntry, boolean decre
610611
cacheStats.evicted(bucketEntry.getCachedTime(), cacheKey.isPrimary());
611612
}
612613
if (ioEngine.isPersistent()) {
614+
if (prefetchedFileListPath != null) {
615+
PrefetchExecutor.removePrefetchedFileWhileEvict(cacheKey.getHfileName());
616+
}
613617
setCacheInconsistent(true);
614618
}
615619
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public void testPrefetchPersistence() throws Exception {
108108
table.put(put1);
109109
TEST_UTIL.flush(tableName);
110110
} finally {
111-
Thread.sleep(1500);
111+
Thread.sleep(2000);
112112
}
113113

114114
// Default interval for cache persistence is 1000ms. So after 1000ms, both the persistence files

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.apache.hadoop.hbase.io.hfile.HFileBlock;
3939
import org.apache.hadoop.hbase.io.hfile.HFileContext;
4040
import org.apache.hadoop.hbase.io.hfile.HFileContextBuilder;
41+
import org.apache.hadoop.hbase.io.hfile.PrefetchExecutor;
4142
import org.apache.hadoop.hbase.io.hfile.RandomKeyValueUtil;
4243
import org.apache.hadoop.hbase.regionserver.StoreFileWriter;
4344
import org.apache.hadoop.hbase.testclassification.IOTests;
@@ -119,21 +120,36 @@ public void testPrefetchPersistenceCrash() throws Exception {
119120

120121
@Test
121122
public void testPrefetchPersistenceCrashNegative() throws Exception {
122-
long bucketCachePersistInterval = 3000;
123+
long bucketCachePersistInterval = Long.MAX_VALUE;
123124
Configuration conf = setupBucketCacheConfig(bucketCachePersistInterval);
124125
BucketCache bucketCache = setupBucketCache(conf);
125126
CacheConfig cacheConf = new CacheConfig(conf, bucketCache);
126127
FileSystem fs = HFileSystem.get(conf);
127128
// Load Cache
128129
Path storeFile = writeStoreFile("TestPrefetch2", conf, cacheConf, fs);
129-
Path storeFile2 = writeStoreFile("TestPrefetch3", conf, cacheConf, fs);
130130
readStoreFile(storeFile, 0, fs, cacheConf, conf, bucketCache);
131-
readStoreFile(storeFile2, 0, fs, cacheConf, conf, bucketCache);
132131
assertFalse(new File(testDir + "/prefetch.persistence").exists());
133132
assertFalse(new File(testDir + "/bucket.persistence").exists());
134133
cleanupBucketCache(bucketCache);
135134
}
136135

136+
@Test
137+
public void testPrefetchListUponBlockEviction() throws Exception {
138+
Configuration conf = setupBucketCacheConfig(200);
139+
BucketCache bucketCache1 = setupBucketCache(conf);
140+
CacheConfig cacheConf = new CacheConfig(conf, bucketCache1);
141+
FileSystem fs = HFileSystem.get(conf);
142+
// Load Blocks in cache
143+
Path storeFile = writeStoreFile("TestPrefetch3", conf, cacheConf, fs);
144+
readStoreFile(storeFile, 0, fs, cacheConf, conf, bucketCache1);
145+
Thread.sleep(500);
146+
// Evict Blocks from cache
147+
BlockCacheKey bucketCacheKey = bucketCache1.backingMap.entrySet().iterator().next().getKey();
148+
assertTrue(PrefetchExecutor.isFilePrefetched(storeFile.getName()));
149+
bucketCache1.evictBlock(bucketCacheKey);
150+
assertFalse(PrefetchExecutor.isFilePrefetched(storeFile.getName()));
151+
}
152+
137153
public void readStoreFile(Path storeFilePath, long offset, FileSystem fs, CacheConfig cacheConf,
138154
Configuration conf, BucketCache bucketCache) throws Exception {
139155
// Open the file

0 commit comments

Comments
 (0)