You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hbase.apache.org by GitBox <gi...@apache.org> on 2020/12/01 05:10:50 UTC

[GitHub] [hbase] sunhelly commented on a change in pull request #2699: HBASE-25287 Forgetting to unbuffer streams results in many CLOSE_WAIT…

sunhelly commented on a change in pull request #2699:
URL: https://github.com/apache/hbase/pull/2699#discussion_r533076760



##########
File path: hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileInfo.java
##########
@@ -359,24 +360,32 @@ public void initMetaAndIndex(HFile.Reader reader) throws IOException {
     // 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());
-    reader.setDataBlockIndexReader(dataIndexReader);
-    // Meta index.
-    this.metaIndexReader = new HFileBlockIndex.ByteArrayKeyBlockIndexReader(1);
-    metaIndexReader.readRootIndex(blockIter.nextBlockWithBlockType(BlockType.ROOT_INDEX),
+    try {
+      // 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());
+      reader.setDataBlockIndexReader(dataIndexReader);
+      // Meta index.
+      this.metaIndexReader = new HFileBlockIndex.ByteArrayKeyBlockIndexReader(1);
+      metaIndexReader.readRootIndex(blockIter.nextBlockWithBlockType(BlockType.ROOT_INDEX),
         trailer.getMetaIndexCount());
-    reader.setMetaBlockIndexReader(metaIndexReader);
-    loadMetaInfo(blockIter, hfileContext);
-    reader.setDataBlockEncoder(HFileDataBlockEncoderImpl.createFromFileInfo(this));
-    // Load-On-Open info
-    HFileBlock b;
-    while ((b = blockIter.nextBlock()) != null) {
-      loadOnOpenBlocks.add(b);
+      reader.setMetaBlockIndexReader(metaIndexReader);
+      loadMetaInfo(blockIter, hfileContext);
+      reader.setDataBlockEncoder(HFileDataBlockEncoderImpl.createFromFileInfo(this));
+      // Load-On-Open info
+      HFileBlock b;
+      while ((b = blockIter.nextBlock()) != null) {
+        loadOnOpenBlocks.add(b);
+      }
+    } catch (Throwable t) {
+      IOUtils.closeQuietly(context.getInputStreamWrapper());
+      throw new CorruptHFileException("Problem reading data index and meta index from file "
+        + context.getFilePath(), t);
+    } finally {
+      context.getInputStreamWrapper().unbuffer();

Review comment:
       I think it might be better to call `context.getInputStreamWrapper().unbuffer()` before `catch` sentences.
   And because `DFSInputStream.close()` uses the same logic as `unbuffer()` to close the `blockReader` by `closeCurrentBlockReaders()`, so it need not to call `unbuffer` before `IOUtils.closeQuietly()`.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org