Skip to content

Commit dbfb516

Browse files
authored
HBASE-28217 PrefetchExecutor should not run for files from CFs that have disabled BLOCKCACHE (#5535)
Signed-off-by: Peter Somogyi <[email protected]>
1 parent 6f8b288 commit dbfb516

File tree

3 files changed

+56
-3
lines changed

3 files changed

+56
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ public boolean shouldCacheCompressed(BlockCategory category) {
343343

344344
/** Returns true if blocks should be prefetched into the cache on open, false if not */
345345
public boolean shouldPrefetchOnOpen() {
346-
return this.prefetchOnOpen;
346+
return this.prefetchOnOpen && this.cacheDataOnRead;
347347
}
348348

349349
/** Returns true if blocks should be cached while writing during compaction, false if not */

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,9 @@ public static boolean isCompleted(Path path) {
129129

130130
private PrefetchExecutor() {
131131
}
132+
133+
/* Visible for testing only */
134+
static ScheduledExecutorService getExecutorPool() {
135+
return prefetchExecutorPool;
136+
}
132137
}

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

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import static org.hamcrest.Matchers.hasItem;
2727
import static org.hamcrest.Matchers.hasItems;
2828
import static org.hamcrest.Matchers.not;
29+
import static org.junit.Assert.assertEquals;
2930
import static org.junit.Assert.assertFalse;
3031
import static org.junit.Assert.assertTrue;
3132
import static org.junit.Assert.fail;
@@ -35,6 +36,7 @@
3536
import java.io.IOException;
3637
import java.util.List;
3738
import java.util.Random;
39+
import java.util.concurrent.ScheduledThreadPoolExecutor;
3840
import java.util.concurrent.ThreadLocalRandom;
3941
import java.util.concurrent.TimeUnit;
4042
import java.util.function.BiConsumer;
@@ -120,6 +122,40 @@ public void testPrefetchSetInHCDWorks() {
120122
assertTrue(cc.shouldPrefetchOnOpen());
121123
}
122124

125+
@Test
126+
public void testPrefetchBlockCacheDisabled() throws Exception {
127+
ScheduledThreadPoolExecutor poolExecutor =
128+
(ScheduledThreadPoolExecutor) PrefetchExecutor.getExecutorPool();
129+
long totalCompletedBefore = poolExecutor.getCompletedTaskCount();
130+
long queueBefore = poolExecutor.getQueue().size();
131+
ColumnFamilyDescriptor columnFamilyDescriptor =
132+
ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("f")).setPrefetchBlocksOnOpen(true)
133+
.setBlockCacheEnabled(false).build();
134+
HFileContext meta = new HFileContextBuilder().withBlockSize(DATA_BLOCK_SIZE).build();
135+
CacheConfig cacheConfig =
136+
new CacheConfig(conf, columnFamilyDescriptor, blockCache, ByteBuffAllocator.HEAP);
137+
Path storeFile = writeStoreFile("testPrefetchBlockCacheDisabled", meta, cacheConfig);
138+
readStoreFile(storeFile, (r, o) -> {
139+
HFileBlock block = null;
140+
try {
141+
block = r.readBlock(o, -1, false, true, false, true, null, null);
142+
} catch (IOException e) {
143+
fail(e.getMessage());
144+
}
145+
return block;
146+
}, (key, block) -> {
147+
boolean isCached = blockCache.getBlock(key, true, false, true) != null;
148+
if (
149+
block.getBlockType() == BlockType.DATA || block.getBlockType() == BlockType.ROOT_INDEX
150+
|| block.getBlockType() == BlockType.INTERMEDIATE_INDEX
151+
) {
152+
assertFalse(isCached);
153+
}
154+
}, cacheConfig);
155+
assertEquals(totalCompletedBefore + queueBefore,
156+
poolExecutor.getCompletedTaskCount() + poolExecutor.getQueue().size());
157+
}
158+
123159
@Test
124160
public void testPrefetch() throws Exception {
125161
TraceUtil.trace(() -> {
@@ -212,8 +248,15 @@ private void readStoreFileCacheOnly(Path storeFilePath) throws Exception {
212248
private void readStoreFile(Path storeFilePath,
213249
BiFunction<HFile.Reader, Long, HFileBlock> readFunction,
214250
BiConsumer<BlockCacheKey, HFileBlock> validationFunction) throws Exception {
251+
readStoreFile(storeFilePath, readFunction, validationFunction, cacheConf);
252+
}
253+
254+
private void readStoreFile(Path storeFilePath,
255+
BiFunction<HFile.Reader, Long, HFileBlock> readFunction,
256+
BiConsumer<BlockCacheKey, HFileBlock> validationFunction, CacheConfig cacheConfig)
257+
throws Exception {
215258
// Open the file
216-
HFile.Reader reader = HFile.createReader(fs, storeFilePath, cacheConf, true, conf);
259+
HFile.Reader reader = HFile.createReader(fs, storeFilePath, cacheConfig, true, conf);
217260

218261
while (!reader.prefetchComplete()) {
219262
// Sleep for a bit
@@ -350,8 +393,13 @@ private Path writeStoreFile(String fname) throws IOException {
350393
}
351394

352395
private Path writeStoreFile(String fname, HFileContext context) throws IOException {
396+
return writeStoreFile(fname, context, cacheConf);
397+
}
398+
399+
private Path writeStoreFile(String fname, HFileContext context, CacheConfig cacheConfig)
400+
throws IOException {
353401
Path storeFileParentDir = new Path(TEST_UTIL.getDataTestDir(), fname);
354-
StoreFileWriter sfw = new StoreFileWriter.Builder(conf, cacheConf, fs)
402+
StoreFileWriter sfw = new StoreFileWriter.Builder(conf, cacheConfig, fs)
355403
.withOutputDir(storeFileParentDir).withFileContext(context).build();
356404
Random rand = ThreadLocalRandom.current();
357405
final int rowLen = 32;

0 commit comments

Comments
 (0)