HBASE-25287 Forgetting to unbuffer streams results in many CLOSE_WAIT sockets when loading files (#2699)
Signed-off-by: Andrew Purtell <apurtell@apache.org> Signed-off-by: Duo Zhang <zhangduo@apache.org>
This commit is contained in:
parent
a9b8c10f80
commit
635c911532
|
@ -342,8 +342,8 @@ public class HFileInfo implements SortedMap<byte[], byte[]> {
|
|||
Path path = context.getFilePath();
|
||||
checkFileVersion(path);
|
||||
this.hfileContext = createHFileContext(path, trailer, conf);
|
||||
} catch (Throwable t) {
|
||||
context.getInputStreamWrapper().unbuffer();
|
||||
} catch (Throwable t) {
|
||||
IOUtils.closeQuietly(context.getInputStreamWrapper());
|
||||
throw new CorruptHFileException("Problem reading HFile Trailer from file "
|
||||
+ context.getFilePath(), t);
|
||||
|
@ -355,16 +355,17 @@ public class HFileInfo implements SortedMap<byte[], byte[]> {
|
|||
*/
|
||||
public void initMetaAndIndex(HFile.Reader reader) throws IOException {
|
||||
ReaderContext context = reader.getContext();
|
||||
try {
|
||||
HFileBlock.FSReader blockReader = reader.getUncachedBlockReader();
|
||||
// Initialize an block iterator, and parse load-on-open blocks in the following.
|
||||
blockIter = blockReader.blockRange(trailer.getLoadOnOpenDataOffset(),
|
||||
context.getFileSize() - trailer.getTrailerSize());
|
||||
// Data index. We also read statistics about the block index written after
|
||||
// the root level.
|
||||
this.dataIndexReader = new HFileBlockIndex
|
||||
.CellBasedKeyBlockIndexReader(trailer.createComparator(), trailer.getNumDataIndexLevels());
|
||||
dataIndexReader.readMultiLevelIndexRoot(blockIter.nextBlockWithBlockType(BlockType.ROOT_INDEX),
|
||||
trailer.getDataIndexCount());
|
||||
this.dataIndexReader =
|
||||
new HFileBlockIndex.CellBasedKeyBlockIndexReader(trailer.createComparator(), trailer.getNumDataIndexLevels());
|
||||
dataIndexReader
|
||||
.readMultiLevelIndexRoot(blockIter.nextBlockWithBlockType(BlockType.ROOT_INDEX), trailer.getDataIndexCount());
|
||||
reader.setDataBlockIndexReader(dataIndexReader);
|
||||
// Meta index.
|
||||
this.metaIndexReader = new HFileBlockIndex.ByteArrayKeyBlockIndexReader(1);
|
||||
|
@ -378,6 +379,13 @@ public class HFileInfo implements SortedMap<byte[], byte[]> {
|
|||
while ((b = blockIter.nextBlock()) != null) {
|
||||
loadOnOpenBlocks.add(b);
|
||||
}
|
||||
// close the block reader
|
||||
context.getInputStreamWrapper().unbuffer();
|
||||
} catch (Throwable t) {
|
||||
IOUtils.closeQuietly(context.getInputStreamWrapper());
|
||||
throw new CorruptHFileException("Problem reading data index and meta index from file "
|
||||
+ context.getFilePath(), t);
|
||||
}
|
||||
}
|
||||
|
||||
private HFileContext createHFileContext(Path path,
|
||||
|
|
Loading…
Reference in New Issue