Skip to content

Commit

Permalink
Revert two commits
Browse files Browse the repository at this point in the history
  • Loading branch information
terence-yoo committed Jan 11, 2023
1 parent 9c22e81 commit 377c5e1
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ public HDFSBlocksDistribution getHDFSBlockDistribution() {
* Opens reader on this store file. Called by Constructor.
* @see #closeStoreFile(boolean)
*/
private void open(boolean warmup) throws IOException {
private void open() throws IOException {
fileInfo.initHDFSBlocksDistribution();
long readahead = fileInfo.isNoReadahead() ? 0L : -1L;
ReaderContext context = fileInfo.createReaderContext(false, readahead, ReaderType.PREAD);
Expand Down Expand Up @@ -499,25 +499,17 @@ private void open(boolean warmup) throws IOException {
firstKey = initialReader.getFirstKey();
lastKey = initialReader.getLastKey();
comparator = initialReader.getComparator();

if (warmup) {
closeStoreFile(cacheConf == null || cacheConf.shouldEvictOnClose());
}
}

/**
* Initialize the reader used for pread.
*/
public void initReader() throws IOException {
initReader(false);
}

public void initReader(boolean warmup) throws IOException {
if (initialReader == null) {
synchronized (this) {
if (initialReader == null) {
try {
open(warmup);
open();
} catch (Exception e) {
try {
boolean evictOnClose = cacheConf != null ? cacheConf.shouldEvictOnClose() : true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,10 @@ public HStoreFile createStoreFileAndReader(Path p) throws IOException {
}

public HStoreFile createStoreFileAndReader(StoreFileInfo info) throws IOException {
return createStoreFileAndReader(info, false);
}

public HStoreFile createStoreFileAndReader(StoreFileInfo info, boolean warmup)
throws IOException {
info.setRegionCoprocessorHost(coprocessorHost);
HStoreFile storeFile = new HStoreFile(info, ctx.getFamily().getBloomFilterType(),
ctx.getCacheConf(), bloomFilterMetrics);
storeFile.initReader(warmup);
storeFile.initReader();
return storeFile;
}

Expand Down Expand Up @@ -268,7 +263,7 @@ private List<HStoreFile> openStoreFiles(Collection<StoreFileInfo> files, boolean
// our store's CompoundConfiguration here.
storeFileInfo.setConf(conf);
// open each store file in parallel
completionService.submit(() -> createStoreFileAndReader(storeFileInfo, warmup));
completionService.submit(() -> createStoreFileAndReader(storeFileInfo));
totalValidStoreFile++;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1279,32 +1279,4 @@ private void testDataBlockSizeWithCompressionRatePredicator(int expectedBlockCou
assertEquals(expectedBlockCount, blockCount);
}

@Test
public void testInitReaderForWarmup() throws Exception {
final RegionInfo hri =
RegionInfoBuilder.newBuilder(TableName.valueOf("testInitReaderForWarmup")).build();
HRegionFileSystem regionFs = HRegionFileSystem.createRegionOnFileSystem(conf, fs,
new Path(testDir, hri.getTable().getNameAsString()), hri);
HFileContext meta = new HFileContextBuilder().withBlockSize(8 * 1024).build();

// Make a store file and write data to it.
StoreFileWriter writer = new StoreFileWriter.Builder(conf, cacheConf, this.fs)
.withFilePath(regionFs.createTempName()).withFileContext(meta).build();
writeStoreFile(writer);
Path hsfPath = regionFs.commitStoreFile(TEST_FAMILY, writer.getPath());
writer.close();

HStoreFile file =
Mockito.spy(new HStoreFile(this.fs, hsfPath, conf, cacheConf, BloomType.NONE, true));

// after warmup the file reader should be closed and null to avoid file descriptor leakage
file.initReader(true);
assertNull(file.getReader());
Mockito.verify(file, Mockito.times(1)).closeStoreFile(Mockito.anyBoolean());

// not for warmup
file.initReader();
assertNotNull(file.getReader());
Mockito.verify(file, Mockito.times(1)).closeStoreFile(Mockito.anyBoolean());
}
}

0 comments on commit 377c5e1

Please sign in to comment.