hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From liang...@apache.org
Subject hbase git commit: HBASE-12767 Fix a StoreFileScanner NPE in reverse scan flow
Date Tue, 30 Dec 2014 04:32:40 GMT
Repository: hbase
Updated Branches:
  refs/heads/0.98 46f6ae85c -> 3197a631d


HBASE-12767 Fix a StoreFileScanner NPE in reverse scan flow


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

Branch: refs/heads/0.98
Commit: 3197a631dbdf8cee7ba8fe1ea4864ac55fde5a43
Parents: 46f6ae8
Author: xieliang <xieliang@xiaomi.com>
Authored: Tue Dec 30 11:52:33 2014 +0800
Committer: xieliang <xieliang@xiaomi.com>
Committed: Tue Dec 30 12:32:06 2014 +0800

----------------------------------------------------------------------
 .../hadoop/hbase/io/HalfStoreFileReader.java    |  12 ++-
 .../hadoop/hbase/regionserver/TestHRegion.java  | 102 +++++++++++++++++++
 2 files changed, 112 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/3197a631/hbase-server/src/main/java/org/apache/hadoop/hbase/io/HalfStoreFileReader.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/HalfStoreFileReader.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/HalfStoreFileReader.java
index cf94c33..5ce6c74 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/HalfStoreFileReader.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/HalfStoreFileReader.java
@@ -186,10 +186,18 @@ public class HalfStoreFileReader extends StoreFile.Reader {
           // The equals sign isn't strictly necessary just here to be consistent with seekTo
           if (getComparator().compareFlatKey(key, offset, length, splitkey, 0,
               splitkey.length) >= 0) {
-            return this.delegate.seekBefore(splitkey, 0, splitkey.length);
+            boolean ret = this.delegate.seekBefore(splitkey, 0, splitkey.length);
+            if (ret) {
+              atEnd = false;
+            }
+            return ret;
           }
         }
-        return this.delegate.seekBefore(key, offset, length);
+        boolean ret = this.delegate.seekBefore(key, offset, length);
+        if (ret) {
+          atEnd = false;
+        }
+        return ret;
       }
 
       public boolean seekTo() throws IOException {

http://git-wip-us.apache.org/repos/asf/hbase/blob/3197a631/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java
index 946fa0b..1ee9d06 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java
@@ -4511,6 +4511,7 @@ public class TestHRegion {
         Bytes.toString(CellUtil.cloneValue(kv)));
   }
 
+  @Test (timeout=60000)
   public void testReverseScanner_FromMemStore_SingleCF_Normal()
       throws IOException {
     byte[] rowC = Bytes.toBytes("rowC");
@@ -4566,6 +4567,7 @@ public class TestHRegion {
     }
   }
 
+  @Test (timeout=60000)
   public void testReverseScanner_FromMemStore_SingleCF_LargerKey()
       throws IOException {
     byte[] rowC = Bytes.toBytes("rowC");
@@ -4622,6 +4624,7 @@ public class TestHRegion {
     }
   }
 
+  @Test (timeout=60000)
   public void testReverseScanner_FromMemStore_SingleCF_FullScan()
       throws IOException {
     byte[] rowC = Bytes.toBytes("rowC");
@@ -4675,6 +4678,7 @@ public class TestHRegion {
     }
   }
 
+  @Test (timeout=60000)
   public void testReverseScanner_moreRowsMayExistAfter() throws IOException {
     // case for "INCLUDE_AND_SEEK_NEXT_ROW & SEEK_NEXT_ROW" endless loop
     byte[] rowA = Bytes.toBytes("rowA");
@@ -4752,6 +4756,7 @@ public class TestHRegion {
     }
   }
 
+  @Test (timeout=60000)
   public void testReverseScanner_smaller_blocksize() throws IOException {
     // case to ensure no conflict with HFile index optimization
     byte[] rowA = Bytes.toBytes("rowA");
@@ -4831,6 +4836,7 @@ public class TestHRegion {
     }
   }
 
+  @Test (timeout=60000)
   public void testReverseScanner_FromMemStoreAndHFiles_MultiCFs1()
       throws IOException {
     byte[] row0 = Bytes.toBytes("row0"); // 1 kv
@@ -4991,6 +4997,7 @@ public class TestHRegion {
     }
   }
 
+  @Test (timeout=60000)
   public void testReverseScanner_FromMemStoreAndHFiles_MultiCFs2()
       throws IOException {
     byte[] row1 = Bytes.toBytes("row1");
@@ -5064,6 +5071,101 @@ public class TestHRegion {
     }
   }
 
+  @Test (timeout=60000)
+  public void testSplitRegionWithReverseScan() throws IOException {
+    byte [] tableName = Bytes.toBytes("testSplitRegionWithReverseScan");
+    byte [] qualifier = Bytes.toBytes("qualifier");
+    Configuration hc = initSplit();
+    int numRows = 3;
+    byte [][] families = {fam1};
+
+    //Setting up region
+    String method = this.getName();
+    this.region = initHRegion(tableName, method, hc, families);
+
+    //Put data in region
+    int startRow = 100;
+    putData(startRow, numRows, qualifier, families);
+    int splitRow = startRow + numRows;
+    putData(splitRow, numRows, qualifier, families);
+    int endRow = splitRow + numRows;
+    region.flushcache();
+
+    HRegion [] regions = null;
+    try {
+      regions = splitRegion(region, Bytes.toBytes("" + splitRow));
+      //Opening the regions returned.
+      for (int i = 0; i < regions.length; i++) {
+        regions[i] = HRegion.openHRegion(regions[i], null);
+      }
+      //Verifying that the region has been split
+      assertEquals(2, regions.length);
+
+      //Verifying that all data is still there and that data is in the right
+      //place
+      verifyData(regions[0], startRow, numRows, qualifier, families);
+      verifyData(regions[1], splitRow, numRows, qualifier, families);
+
+      //fire the reverse scan1:  top range, and larger than the last row
+      Scan scan = new Scan(Bytes.toBytes(String.valueOf(startRow + 10 * numRows)));
+      scan.setReversed(true);
+      InternalScanner scanner = regions[1].getScanner(scan);
+      List<Cell> currRow = new ArrayList<Cell>();
+      boolean more = false;
+      int verify = startRow + 2 * numRows - 1;
+      do {
+        more = scanner.next(currRow);
+        assertEquals(Bytes.toString(currRow.get(0).getRow()), verify + "");
+        verify--;
+        currRow.clear();
+      } while(more);
+      assertEquals(verify, startRow + numRows - 1);
+      scanner.close();
+      //fire the reverse scan2:  top range, and equals to the last row
+      scan = new Scan(Bytes.toBytes(String.valueOf(startRow + 2 * numRows - 1)));
+      scan.setReversed(true);
+      scanner = regions[1].getScanner(scan);
+      verify = startRow + 2 * numRows - 1;
+      do {
+        more = scanner.next(currRow);
+        assertEquals(Bytes.toString(currRow.get(0).getRow()), verify + "");
+        verify--;
+        currRow.clear();
+      } while(more);
+      assertEquals(verify, startRow + numRows - 1);
+      scanner.close();
+      //fire the reverse scan3:  bottom range, and larger than the last row
+      scan = new Scan(Bytes.toBytes(String.valueOf(startRow + numRows)));
+      scan.setReversed(true);
+      scanner = regions[0].getScanner(scan);
+      verify = startRow + numRows - 1;
+      do {
+        more = scanner.next(currRow);
+        assertEquals(Bytes.toString(currRow.get(0).getRow()), verify + "");
+        verify--;
+        currRow.clear();
+      } while(more);
+      assertEquals(verify, 99);
+      scanner.close();
+      //fire the reverse scan4:  bottom range, and equals to the last row
+      scan = new Scan(Bytes.toBytes(String.valueOf(startRow + numRows - 1)));
+      scan.setReversed(true);
+      scanner = regions[0].getScanner(scan);
+      verify = startRow + numRows - 1;
+      do {
+        more = scanner.next(currRow);
+        assertEquals(Bytes.toString(currRow.get(0).getRow()), verify + "");
+        verify--;
+        currRow.clear();
+      } while(more);
+      assertEquals(verify, startRow - 1);
+      scanner.close();
+    } finally {
+      HRegion.closeHRegion(this.region);
+      this.region = null;
+    }
+  }
+
   @Test
   public void testWriteRequestsCounter() throws IOException {
     byte[] fam = Bytes.toBytes("info");


Mime
View raw message