hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject svn commit: r1436587 - in /hbase/trunk/hbase-server/src: main/java/org/apache/hadoop/hbase/client/Scan.java main/java/org/apache/hadoop/hbase/regionserver/HRegion.java test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java
Date Mon, 21 Jan 2013 20:11:43 GMT
Author: stack
Date: Mon Jan 21 20:11:42 2013
New Revision: 1436587

URL: http://svn.apache.org/viewvc?rev=1436587&view=rev
Log:
HBASE-3170 RegionServer confused about empty row keys

Modified:
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/Scan.java
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/Scan.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/Scan.java?rev=1436587&r1=1436586&r2=1436587&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/Scan.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/Scan.java Mon Jan
21 20:11:42 2013
@@ -92,6 +92,7 @@ public class Scan extends OperationWithA
 
   private int storeLimit = -1;
   private int storeOffset = 0;
+  private boolean getScan;
 
   // If application wants to collect scan metrics, it needs to
   // call scan.setAttribute(SCAN_ATTRIBUTES_ENABLE, Bytes.toBytes(Boolean.TRUE))
@@ -141,6 +142,8 @@ public class Scan extends OperationWithA
   public Scan(byte [] startRow, byte [] stopRow) {
     this.startRow = startRow;
     this.stopRow = stopRow;
+    //if the startRow and stopRow both are empty, it is not a Get
+    this.getScan = isStartRowAndEqualsStopRow();
   }
 
   /**
@@ -159,6 +162,7 @@ public class Scan extends OperationWithA
     caching = scan.getCaching();
     maxResultSize = scan.getMaxResultSize();
     cacheBlocks = scan.getCacheBlocks();
+    getScan = scan.isGetScan();
     filter = scan.getFilter(); // clone?
     loadColumnFamiliesOnDemand = scan.getLoadColumnFamiliesOnDemandValue();
     TimeRange ctr = scan.getTimeRange();
@@ -194,13 +198,17 @@ public class Scan extends OperationWithA
     this.storeOffset = get.getRowOffsetPerColumnFamily();
     this.tr = get.getTimeRange();
     this.familyMap = get.getFamilyMap();
+    this.getScan = true;
   }
 
   public boolean isGetScan() {
-    return this.startRow != null && this.startRow.length > 0 &&
-      Bytes.equals(this.startRow, this.stopRow);
+    return this.getScan || isStartRowAndEqualsStopRow();
   }
 
+  private boolean isStartRowAndEqualsStopRow() {
+    return this.startRow != null && this.startRow.length > 0 &&
+        Bytes.equals(this.startRow, this.stopRow);
+  }
   /**
    * Get all columns from the specified family.
    * <p>

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java?rev=1436587&r1=1436586&r2=1436587&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
(original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
Mon Jan 21 20:11:42 2013
@@ -3406,7 +3406,7 @@ public class HRegion implements HeapSize
       }
 
       this.batch = scan.getBatch();
-      if (Bytes.equals(scan.getStopRow(), HConstants.EMPTY_END_ROW)) {
+      if (Bytes.equals(scan.getStopRow(), HConstants.EMPTY_END_ROW) && !scan.isGetScan())
{
         this.stopRow = null;
       } else {
         this.stopRow = scan.getStopRow();

Modified: hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java?rev=1436587&r1=1436586&r2=1436587&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java
(original)
+++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java
Mon Jan 21 20:11:42 2013
@@ -22,6 +22,7 @@ package org.apache.hadoop.hbase.client;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
+import java.util.Arrays;
 import java.util.List;
 import java.util.Random;
 
@@ -51,6 +52,9 @@ public class TestFromClientSide3 {
   private static byte[] FAMILY = Bytes.toBytes("testFamily");
   private static Random random = new Random();
   private static int SLAVES = 3;
+  private final static byte[] COL_QUAL = Bytes.toBytes("f1");
+  private final static byte[] VAL_BYTES = Bytes.toBytes("v1");
+  private final static byte[] ROW_BYTES = Bytes.toBytes("r1");
 
   /**
    * @throws java.lang.Exception
@@ -256,4 +260,34 @@ public class TestFromClientSide3 {
         "hbase.hstore.compaction.min"));
   }
 
+  @Test
+  public void testGetEmptyRow() throws Exception {
+    //Create a table and put in 1 row
+    HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
+    HTableDescriptor desc = new HTableDescriptor(Bytes.toBytes("test"));
+    desc.addFamily(new HColumnDescriptor(FAMILY));
+    admin.createTable(desc);
+    HTable table = new HTable(TEST_UTIL.getConfiguration(), "test");
+
+    Put put = new Put(ROW_BYTES);
+    put.add(FAMILY, COL_QUAL, VAL_BYTES);
+    table.put(put);
+    table.flushCommits();
+
+    //Try getting the row with an empty row key and make sure the other base cases work as
well
+    Result res = table.get(new Get(new byte[0]));
+    assertTrue(res.isEmpty() == true);
+    res = table.get(new Get(Bytes.toBytes("r1-not-exist")));
+    assertTrue(res.isEmpty() == true);
+    res = table.get(new Get(ROW_BYTES));
+    assertTrue(Arrays.equals(res.getValue(FAMILY, COL_QUAL), VAL_BYTES));
+
+    //Now actually put in a row with an empty row key    
+    put = new Put(new byte[0]);
+    put.add(FAMILY, COL_QUAL, VAL_BYTES);
+    table.put(put);
+    table.flushCommits();
+    res = table.get(new Get(new byte[0]));
+    assertTrue(Arrays.equals(res.getValue(FAMILY, COL_QUAL), VAL_BYTES));
+  }
 }



Mime
View raw message