PHOENIX-4839 IndexHalfStoreFileReaderGenerator throws NullPointerException 
(Aman Poonia)


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/b437712b
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/b437712b
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/b437712b

Branch: refs/heads/4.14-cdh5.12
Commit: b437712b3cfe5541e14ae8e319b63bb6d986b564
Parents: b902048
Author: Lars Hofhansl <la...@apache.org>
Authored: Fri Sep 14 20:40:06 2018 +0100
Committer: Pedro Boado <pbo...@apache.org>
Committed: Wed Oct 17 20:31:32 2018 +0100

----------------------------------------------------------------------
 .../regionserver/IndexHalfStoreFileReader.java  | 48 ++++++++++++++++----
 .../IndexHalfStoreFileReaderGenerator.java      | 12 ++---
 2 files changed, 43 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/b437712b/phoenix-core/src/main/java/org/apache/hadoop/hbase/regionserver/IndexHalfStoreFileReader.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/hadoop/hbase/regionserver/IndexHalfStoreFileReader.java
 
b/phoenix-core/src/main/java/org/apache/hadoop/hbase/regionserver/IndexHalfStoreFileReader.java
index 8bd0d72..273a1b0 100644
--- 
a/phoenix-core/src/main/java/org/apache/hadoop/hbase/regionserver/IndexHalfStoreFileReader.java
+++ 
b/phoenix-core/src/main/java/org/apache/hadoop/hbase/regionserver/IndexHalfStoreFileReader.java
@@ -17,6 +17,8 @@
  */
 package org.apache.hadoop.hbase.regionserver;
 
+import static 
org.apache.phoenix.coprocessor.BaseScannerRegionObserver.SCAN_START_ROW_SUFFIX;
+
 import java.io.IOException;
 import java.util.Map;
 
@@ -26,10 +28,12 @@ import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.hbase.CellUtil;
 import org.apache.hadoop.hbase.HRegionInfo;
 import org.apache.hadoop.hbase.KeyValue;
+import org.apache.hadoop.hbase.client.Scan;
 import org.apache.hadoop.hbase.io.FSDataInputStreamWrapper;
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.hadoop.hbase.io.Reference;
 import org.apache.hadoop.hbase.io.hfile.CacheConfig;
+import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.phoenix.index.IndexMaintainer;
 
 /**
@@ -56,8 +60,9 @@ public class IndexHalfStoreFileReader extends 
StoreFile.Reader {
     private final Map<ImmutableBytesWritable, IndexMaintainer> 
indexMaintainers;
     private final byte[][] viewConstants;
     private final int offset;
-    private final HRegionInfo regionInfo;
+    private final HRegionInfo childRegionInfo;
     private final byte[] regionStartKeyInHFile;
+    private final HRegionInfo currentRegion;
 
     /**
      * @param fs
@@ -69,17 +74,19 @@ public class IndexHalfStoreFileReader extends 
StoreFile.Reader {
      * @param conf
      * @param indexMaintainers
      * @param viewConstants
-     * @param regionInfo
+     * @param childRegionInfo
      * @param regionStartKeyInHFile
      * @param splitKey
+     * @param currentRegion
      * @throws IOException
      */
     public IndexHalfStoreFileReader(final FileSystem fs, final Path p, final 
CacheConfig cacheConf,
             final FSDataInputStreamWrapper in, long size, final Reference r,
             final Configuration conf,
             final Map<ImmutableBytesWritable, IndexMaintainer> 
indexMaintainers,
-            final byte[][] viewConstants, final HRegionInfo regionInfo,
-            byte[] regionStartKeyInHFile, byte[] splitKey) throws IOException {
+            final byte[][] viewConstants, final HRegionInfo childRegionInfo,
+            byte[] regionStartKeyInHFile, byte[] splitKey, HRegionInfo 
currentRegion)
+            throws IOException {
         super(fs, p, in, size, cacheConf, conf);
         this.splitkey = splitKey == null ? r.getSplitKey() : splitKey;
         // Is it top or bottom half?
@@ -87,9 +94,10 @@ public class IndexHalfStoreFileReader extends 
StoreFile.Reader {
         this.splitRow = 
CellUtil.cloneRow(KeyValue.createKeyValueFromKey(splitkey));
         this.indexMaintainers = indexMaintainers;
         this.viewConstants = viewConstants;
-        this.regionInfo = regionInfo;
+        this.childRegionInfo = childRegionInfo;
         this.regionStartKeyInHFile = regionStartKeyInHFile;
         this.offset = regionStartKeyInHFile.length;
+        this.currentRegion = currentRegion;
     }
 
     public int getOffset() {
@@ -105,7 +113,7 @@ public class IndexHalfStoreFileReader extends 
StoreFile.Reader {
     }
 
     public HRegionInfo getRegionInfo() {
-        return regionInfo;
+        return childRegionInfo;
     }
 
     public byte[] getRegionStartKeyInHFile() {
@@ -125,8 +133,30 @@ public class IndexHalfStoreFileReader extends 
StoreFile.Reader {
     }
 
     @Override
-    public StoreFileScanner getStoreFileScanner(boolean cacheBlocks, boolean 
pread, boolean isCompaction, long readPt) {
-        return new LocalIndexStoreFileScanner(this, getScanner(cacheBlocks, 
pread, isCompaction), true,
-                getHFileReader().hasMVCCInfo(), readPt);
+    public StoreFileScanner getStoreFileScanner(boolean cacheBlocks, boolean 
pread,
+                                                boolean isCompaction, long 
readPt) {
+        return new LocalIndexStoreFileScanner(this, getScanner(cacheBlocks, 
pread, isCompaction),
+                true, getHFileReader().hasMVCCInfo(), readPt);
+    }
+
+    @Override
+    public boolean passesKeyRangeFilter(Scan scan) {
+        if (scan.getAttribute(SCAN_START_ROW_SUFFIX) == null) {
+            // Scan from compaction.
+            return true;
+        }
+        byte[] startKey = currentRegion.getStartKey();
+        byte[] endKey = currentRegion.getEndKey();
+        // If the region start key is not the prefix of the scan start row 
then we can return empty
+        // scanners. This is possible during merge where one of the child 
region scan should not return any
+        // results as we go through merged region.
+        int prefixLength =
+                scan.getStartRow().length - 
scan.getAttribute(SCAN_START_ROW_SUFFIX).length;
+        if (Bytes.compareTo(scan.getStartRow(), 0, prefixLength,
+                (startKey.length == 0 ? new byte[endKey.length] : startKey), 0,
+                (startKey.length == 0 ? endKey.length : startKey.length)) != 
0) {
+            return false;
+        }
+        return true;
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b437712b/phoenix-core/src/main/java/org/apache/hadoop/hbase/regionserver/IndexHalfStoreFileReaderGenerator.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/hadoop/hbase/regionserver/IndexHalfStoreFileReaderGenerator.java
 
b/phoenix-core/src/main/java/org/apache/hadoop/hbase/regionserver/IndexHalfStoreFileReaderGenerator.java
index ab65456..4981e8c 100644
--- 
a/phoenix-core/src/main/java/org/apache/hadoop/hbase/regionserver/IndexHalfStoreFileReaderGenerator.java
+++ 
b/phoenix-core/src/main/java/org/apache/hadoop/hbase/regionserver/IndexHalfStoreFileReaderGenerator.java
@@ -162,11 +162,11 @@ public class IndexHalfStoreFileReaderGenerator extends 
BaseRegionObserver {
                             indexMaintainer);
                     }
                 }
-                if(indexMaintainers.isEmpty()) return reader;
+                if (indexMaintainers.isEmpty()) return reader;
                 byte[][] viewConstants = getViewConstants(dataTable);
-                return new IndexHalfStoreFileReader(fs, p, cacheConf, in, 
size, r, ctx
-                        .getEnvironment().getConfiguration(), 
indexMaintainers, viewConstants,
-                        childRegion, regionStartKeyInHFile, splitKey);
+                return new IndexHalfStoreFileReader(fs, p, cacheConf, in, 
size, r,
+                        ctx.getEnvironment().getConfiguration(), 
indexMaintainers, viewConstants,
+                        childRegion, regionStartKeyInHFile, splitKey, 
region.getRegionInfo());
             } catch (ClassNotFoundException e) {
                 throw new IOException(e);
             } catch (SQLException e) {
@@ -247,10 +247,6 @@ public class IndexHalfStoreFileReaderGenerator extends 
BaseRegionObserver {
     /**
      * @param env
      * @param store Local Index store
-     * @param scan
-     * @param scanType
-     * @param earliestPutTs
-     * @param request
      * @return StoreScanner for new Local Index data for a passed store and 
Null if repair is not possible
      * @throws IOException
      */

Reply via email to