Apache9 commented on code in PR #8165:
URL: https://github.com/apache/hbase/pull/8165#discussion_r3165214372


##########
hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileBlockHeaderCorruption.java:
##########
@@ -453,39 +468,25 @@ public Object readFully() throws IOException {
    */
   public static class HFileBlockChannelPositionIterator implements Closeable {
 
-    private final HFileTestRule hFileTestRule;
+    private final Path hfsPath;
     private final HFile.Reader reader;
     private final HFileBlock.BlockIterator iter;
     private HFileBlockChannelPosition current = null;
 
-    public HFileBlockChannelPositionIterator(HFileTestRule hFileTestRule) 
throws IOException {
-      Configuration conf = hFileTestRule.getConfiguration();
-      HFileSystem hfs = hFileTestRule.getHFileSystem();
-      Path hfsPath = hFileTestRule.getPath();
-
-      HFile.Reader reader = null;
-      HFileBlock.BlockIterator iter = null;
-      try {
-        reader = HFile.createReader(hfs, hfsPath, CacheConfig.DISABLED, true, 
conf);
-        HFileBlock.FSReader fsreader = reader.getUncachedBlockReader();
-        // The read block offset cannot out of the range:0,loadOnOpenDataOffset
-        iter = fsreader.blockRange(0, 
reader.getTrailer().getLoadOnOpenDataOffset());
-      } catch (IOException e) {
-        if (reader != null) {
-          closeQuietly(reader::close);
-        }
-        throw e;
-      }
-
-      this.hFileTestRule = hFileTestRule;
-      this.reader = reader;
-      this.iter = iter;
+    public HFileBlockChannelPositionIterator(HFileSystem hfs, Path hfsPath) 
throws IOException {
+      this.hfsPath = hfsPath;
+      this.reader = HFile.createReader(hfs, hfsPath, CacheConfig.DISABLED, 
true, hfs.getConf());
+      HFileBlock.FSReader fsreader = reader.getUncachedBlockReader();
+      // The read block offset cannot out of the range:0,loadOnOpenDataOffset
+      this.iter = fsreader.blockRange(0, 
reader.getTrailer().getLoadOnOpenDataOffset());
     }
 
     public boolean hasNext() throws IOException {
       HFileBlock next = iter.nextBlock();
-      SeekableByteChannel channel = hFileTestRule.getRWChannel();
       if (next != null) {
+        java.nio.file.Path p = 
FileSystems.getDefault().getPath(hfsPath.toString());
+        SeekableByteChannel channel = Files.newByteChannel(p, 
StandardOpenOption.READ,
+          StandardOpenOption.WRITE, StandardOpenOption.DSYNC);
         current = new HFileBlockChannelPosition(channel, next.getOffset());

Review Comment:
   Just copied the old code.



##########
hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileBlockHeaderCorruption.java:
##########
@@ -453,39 +468,25 @@ public Object readFully() throws IOException {
    */
   public static class HFileBlockChannelPositionIterator implements Closeable {
 
-    private final HFileTestRule hFileTestRule;
+    private final Path hfsPath;
     private final HFile.Reader reader;
     private final HFileBlock.BlockIterator iter;
     private HFileBlockChannelPosition current = null;
 
-    public HFileBlockChannelPositionIterator(HFileTestRule hFileTestRule) 
throws IOException {
-      Configuration conf = hFileTestRule.getConfiguration();
-      HFileSystem hfs = hFileTestRule.getHFileSystem();
-      Path hfsPath = hFileTestRule.getPath();
-
-      HFile.Reader reader = null;
-      HFileBlock.BlockIterator iter = null;
-      try {
-        reader = HFile.createReader(hfs, hfsPath, CacheConfig.DISABLED, true, 
conf);
-        HFileBlock.FSReader fsreader = reader.getUncachedBlockReader();
-        // The read block offset cannot out of the range:0,loadOnOpenDataOffset
-        iter = fsreader.blockRange(0, 
reader.getTrailer().getLoadOnOpenDataOffset());
-      } catch (IOException e) {
-        if (reader != null) {
-          closeQuietly(reader::close);
-        }
-        throw e;
-      }
-
-      this.hFileTestRule = hFileTestRule;
-      this.reader = reader;
-      this.iter = iter;
+    public HFileBlockChannelPositionIterator(HFileSystem hfs, Path hfsPath) 
throws IOException {
+      this.hfsPath = hfsPath;
+      this.reader = HFile.createReader(hfs, hfsPath, CacheConfig.DISABLED, 
true, hfs.getConf());
+      HFileBlock.FSReader fsreader = reader.getUncachedBlockReader();
+      // The read block offset cannot out of the range:0,loadOnOpenDataOffset
+      this.iter = fsreader.blockRange(0, 
reader.getTrailer().getLoadOnOpenDataOffset());
     }
 
     public boolean hasNext() throws IOException {
       HFileBlock next = iter.nextBlock();
-      SeekableByteChannel channel = hFileTestRule.getRWChannel();
       if (next != null) {
+        java.nio.file.Path p = 
FileSystems.getDefault().getPath(hfsPath.toString());
+        SeekableByteChannel channel = Files.newByteChannel(p, 
StandardOpenOption.READ,
+          StandardOpenOption.WRITE, StandardOpenOption.DSYNC);

Review Comment:
   Just copied the old code.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to