hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From te...@apache.org
Subject svn commit: r1553712 - in /hbase/branches/0.96/hbase-server/src: main/java/org/apache/hadoop/hbase/regionserver/HRegion.java test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java
Date Fri, 27 Dec 2013 18:17:41 GMT
Author: tedyu
Date: Fri Dec 27 18:17:41 2013
New Revision: 1553712

URL: http://svn.apache.org/r1553712
Log:
HBASE-7226 HRegion.checkAndMutate uses incorrect comparison result for <, <=, > and
>=


Modified:
    hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
    hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java

Modified: hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java?rev=1553712&r1=1553711&r2=1553712&view=diff
==============================================================================
--- hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
(original)
+++ hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
Fri Dec 27 18:17:41 2013
@@ -2409,10 +2409,10 @@ public class HRegion implements HeapSize
               kv.getValueOffset(), kv.getValueLength());
           switch (compareOp) {
           case LESS:
-            matches = compareResult <= 0;
+            matches = compareResult < 0;
             break;
           case LESS_OR_EQUAL:
-            matches = compareResult < 0;
+            matches = compareResult <= 0;
             break;
           case EQUAL:
             matches = compareResult == 0;
@@ -2421,10 +2421,10 @@ public class HRegion implements HeapSize
             matches = compareResult != 0;
             break;
           case GREATER_OR_EQUAL:
-            matches = compareResult > 0;
+            matches = compareResult >= 0;
             break;
           case GREATER:
-            matches = compareResult >= 0;
+            matches = compareResult > 0;
             break;
           default:
             throw new RuntimeException("Unknown Compare op " + compareOp.name());

Modified: hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java?rev=1553712&r1=1553711&r2=1553712&view=diff
==============================================================================
--- hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java
(original)
+++ hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java
Fri Dec 27 18:17:41 2013
@@ -1031,6 +1031,101 @@ public class TestHRegion {
   }
 
   @Test
+  public void testCheckAndMutate_WithNonEqualCompareOp() throws IOException {
+    byte[] row1 = Bytes.toBytes("row1");
+    byte[] fam1 = Bytes.toBytes("fam1");
+    byte[] qf1 = Bytes.toBytes("qualifier");
+    byte[] val1 = Bytes.toBytes("value1");
+    byte[] val2 = Bytes.toBytes("value2");
+    byte[] val3 = Bytes.toBytes("value3");
+    byte[] val4 = Bytes.toBytes("value4");
+
+    // Setting up region
+    String method = this.getName();
+    this.region = initHRegion(tableName, method, conf, fam1);
+    try {
+      // Putting val3 in key
+      Put put = new Put(row1);
+      put.add(fam1, qf1, val3);
+      region.put(put);
+
+      // Test CompareOp.LESS: original = val3, compare with val3, fail
+      boolean res = region.checkAndMutate(row1, fam1, qf1, CompareOp.LESS,
+          new BinaryComparator(val3), put, true);
+      assertEquals(false, res);
+
+      // Test CompareOp.LESS: original = val3, compare with val4, fail
+      res = region.checkAndMutate(row1, fam1, qf1, CompareOp.LESS,
+          new BinaryComparator(val4), put, true);
+      assertEquals(false, res);
+
+      // Test CompareOp.LESS: original = val3, compare with val2,
+      // succeed (now value = val2)
+      put = new Put(row1);
+      put.add(fam1, qf1, val2);
+      res = region.checkAndMutate(row1, fam1, qf1, CompareOp.LESS,
+          new BinaryComparator(val2), put, true);
+      assertEquals(true, res);
+
+      // Test CompareOp.LESS_OR_EQUAL: original = val2, compare with val3, fail
+      res = region.checkAndMutate(row1, fam1, qf1, CompareOp.LESS_OR_EQUAL,
+          new BinaryComparator(val3), put, true);
+      assertEquals(false, res);
+
+      // Test CompareOp.LESS_OR_EQUAL: original = val2, compare with val2,
+      // succeed (value still = val2)
+      res = region.checkAndMutate(row1, fam1, qf1, CompareOp.LESS_OR_EQUAL,
+          new BinaryComparator(val2), put, true);
+      assertEquals(true, res);
+
+      // Test CompareOp.LESS_OR_EQUAL: original = val2, compare with val1,
+      // succeed (now value = val3)
+      put = new Put(row1);
+      put.add(fam1, qf1, val3);
+      res = region.checkAndMutate(row1, fam1, qf1, CompareOp.LESS_OR_EQUAL,
+          new BinaryComparator(val1), put, true);
+      assertEquals(true, res);
+
+      // Test CompareOp.GREATER: original = val3, compare with val3, fail
+      res = region.checkAndMutate(row1, fam1, qf1, CompareOp.GREATER,
+          new BinaryComparator(val3), put, true);
+      assertEquals(false, res);
+
+      // Test CompareOp.GREATER: original = val3, compare with val2, fail
+      res = region.checkAndMutate(row1, fam1, qf1, CompareOp.GREATER,
+          new BinaryComparator(val2), put, true);
+      assertEquals(false, res);
+
+      // Test CompareOp.GREATER: original = val3, compare with val4,
+      // succeed (now value = val2)
+      put = new Put(row1);
+      put.add(fam1, qf1, val2);
+      res = region.checkAndMutate(row1, fam1, qf1, CompareOp.GREATER,
+          new BinaryComparator(val4), put, true);
+      assertEquals(true, res);
+
+      // Test CompareOp.GREATER_OR_EQUAL: original = val2, compare with val1, fail
+      res = region.checkAndMutate(row1, fam1, qf1, CompareOp.GREATER_OR_EQUAL,
+          new BinaryComparator(val1), put, true);
+      assertEquals(false, res);
+
+      // Test CompareOp.GREATER_OR_EQUAL: original = val2, compare with val2,
+      // succeed (value still = val2)
+      res = region.checkAndMutate(row1, fam1, qf1, CompareOp.GREATER_OR_EQUAL,
+          new BinaryComparator(val2), put, true);
+      assertEquals(true, res);
+
+      // Test CompareOp.GREATER_OR_EQUAL: original = val2, compare with val3, succeed
+      res = region.checkAndMutate(row1, fam1, qf1, CompareOp.GREATER_OR_EQUAL,
+          new BinaryComparator(val3), put, true);
+      assertEquals(true, res);
+    } finally {
+      HRegion.closeHRegion(this.region);
+      this.region = null;
+    }
+  }
+
+  @Test
   public void testCheckAndPut_ThatPutWasWritten() throws IOException {
     byte[] row1 = Bytes.toBytes("row1");
     byte[] fam1 = Bytes.toBytes("fam1");



Mime
View raw message