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 2019/10/02 12:12:28 UTC

[GitHub] [hbase] chenxu14 commented on a change in pull request #581: HBASE-22888 Share some stuffs with the initial reader when new stream reader created

chenxu14 commented on a change in pull request #581: HBASE-22888 Share some stuffs with the initial reader when new stream reader created
URL: https://github.com/apache/hbase/pull/581#discussion_r330513774
 
 

 ##########
 File path: hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFilePreadReader.java
 ##########
 @@ -0,0 +1,213 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.io.hfile;
+
+import java.io.IOException;
+import java.security.Key;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hbase.io.crypto.Cipher;
+import org.apache.hadoop.hbase.io.crypto.Encryption;
+import org.apache.hadoop.hbase.io.hfile.HFile.FileInfo;
+import org.apache.hadoop.hbase.io.hfile.HFile.Reader;
+import org.apache.hadoop.hbase.security.EncryptionUtil;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.yetus.audience.InterfaceAudience;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Implementation of {@link HFile.Reader} to deal with pread.
+ */
+@InterfaceAudience.Private
+public class HFilePreadReader extends HFileReaderImpl {
+  private static final Logger LOG = LoggerFactory.getLogger(HFileReaderImpl.class);
+
+  /**
+   * The iterator will track all blocks in load-on-open section, since we use the
+   * {@link org.apache.hadoop.hbase.io.ByteBuffAllocator} to manage the ByteBuffers in block now,
+   * so we must ensure that deallocate all ByteBuffers in the end.
+   */
+  private final HFileBlock.BlockIterator blockIter;
+
+  public HFilePreadReader(ReaderContext context, FixedFileTrailer trailer,
+      CacheConfig cacheConf, Configuration conf) throws IOException {
+    super(context, cacheConf, conf);
+    this.trailer = trailer;
+    this.compressAlgo = trailer.getCompressionCodec();
+    // Comparator class name is stored in the trailer in version 2.
+    this.comparator = trailer.createComparator();
+    checkFileVersion();
+    this.hfileContext = createHFileContext(context, trailer, conf);
+    this.fsBlockReader = new HFileBlock.FSReaderImpl(context, hfileContext,
+        cacheConf.getByteBuffAllocator());
+    // Initialize an block iterator, and parse load-on-open blocks in the following.
+    this.blockIter = fsBlockReader.blockRange(trailer.getLoadOnOpenDataOffset(),
+      fileSize - trailer.getTrailerSize());
+
+    dataBlockIndexReader = new HFileBlockIndex.CellBasedKeyBlockIndexReader(comparator,
+        trailer.getNumDataIndexLevels());
+    metaBlockIndexReader = new HFileBlockIndex.ByteArrayKeyBlockIndexReader(1);
+    // Data index. We also read statistics about the block index written after
+    // the root level.
+    dataBlockIndexReader.readMultiLevelIndexRoot(
+        blockIter.nextBlockWithBlockType(BlockType.ROOT_INDEX),
+        trailer.getDataIndexCount());
+    // Meta index.
+    metaBlockIndexReader.readRootIndex(
+        blockIter.nextBlockWithBlockType(BlockType.ROOT_INDEX),
+        trailer.getMetaIndexCount());
+    loadFileInfo();
 
 Review comment:
   Move the code to HFileInfo

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


With regards,
Apache Git Services