You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ap...@apache.org on 2019/04/26 21:25:19 UTC

[hbase] branch branch-1.4 updated: HBASE-22310 checkAndMutate used an incorrect row to check the condition (Adonis Ling)

This is an automated email from the ASF dual-hosted git repository.

apurtell pushed a commit to branch branch-1.4
in repository https://gitbox.apache.org/repos/asf/hbase.git


The following commit(s) were added to refs/heads/branch-1.4 by this push:
     new dfbf9cc  HBASE-22310 checkAndMutate used an incorrect row to check the condition (Adonis Ling)
dfbf9cc is described below

commit dfbf9cc0f21d21d6f0c969b286c647332088bcaa
Author: Andrew Purtell <ap...@apache.org>
AuthorDate: Fri Apr 26 12:39:34 2019 -0700

    HBASE-22310 checkAndMutate used an incorrect row to check the condition (Adonis Ling)
---
 .../org/apache/hadoop/hbase/client/HTable.java     |  4 +-
 .../hadoop/hbase/client/TestCheckAndMutate.java    | 45 ++++++++++++++++++++--
 2 files changed, 43 insertions(+), 6 deletions(-)

diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java
index 5fb9e63..91a8f92 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java
@@ -1366,7 +1366,7 @@ public class HTable implements HTableInterface, RegionLocator {
     throws IOException {
     final RetryingTimeTracker tracker = new RetryingTimeTracker().start();
     PayloadCarryingServerCallable<MultiResponse> callable =
-      new PayloadCarryingServerCallable<MultiResponse>(connection, getName(), rm.getRow(),
+      new PayloadCarryingServerCallable<MultiResponse>(connection, getName(), row,
         rpcControllerFactory) {
         @Override
         public MultiResponse call(int callTimeout) throws IOException {
@@ -1391,7 +1391,7 @@ public class HTable implements HTableInterface, RegionLocator {
                 throw (IOException)ex;
               }
               throw new IOException("Failed to checkAndMutate row: "+
-                                    Bytes.toStringBinary(rm.getRow()), ex);
+                Bytes.toStringBinary(row), ex);
             }
             return ResponseConverter.getResults(request, response, controller.cellScanner());
           } catch (ServiceException se) {
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestCheckAndMutate.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestCheckAndMutate.java
index 591474f..aff92b2 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestCheckAndMutate.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestCheckAndMutate.java
@@ -18,20 +18,22 @@
  */
 package org.apache.hadoop.hbase.client;
 
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
 import org.apache.hadoop.hbase.HBaseTestingUtility;
-import org.apache.hadoop.hbase.testclassification.MediumTests;
 import org.apache.hadoop.hbase.TableName;
 import org.apache.hadoop.hbase.filter.CompareFilter;
 import org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException;
+import org.apache.hadoop.hbase.testclassification.MediumTests;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
 @Category(MediumTests.class)
 public class TestCheckAndMutate {
   private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
@@ -119,4 +121,39 @@ public class TestCheckAndMutate {
       table.close();
     }
   }
+
+  @Test
+  public void testCheckRowAndMutateDifferentRow() throws IOException {
+    TableName tableName = TableName.valueOf("TestCheckRowAndMutateDifferentRow");
+    byte[] family = Bytes.toBytes("f");
+    TEST_UTIL.createTable(tableName, family);
+    try (Table table = TEST_UTIL.getConnection().getTable(tableName)) {
+      byte[] row1 = Bytes.toBytes("row1");
+      byte[] qualifier = Bytes.toBytes("q1");
+      byte[] value1 = Bytes.toBytes("value1");
+
+      Put put = new Put(row1);
+      put.addColumn(family, qualifier, value1);
+      table.put(put);
+
+      Result result = table.get(new Get(row1));
+      assertArrayEquals("the value of column q in row1 should be value1",
+          value1, result.getValue(family, qualifier));
+
+      byte[] row2 = Bytes.toBytes("row2");
+      byte[] value2 = Bytes.toBytes("value2");
+      RowMutations mutations = new RowMutations(row2);
+      put = new Put(row2);
+      put.addColumn(family, qualifier, value2);
+      mutations.add(put);
+
+      // check row1 and put row2
+      assertTrue(table.checkAndMutate(row1, family, qualifier,
+          CompareFilter.CompareOp.GREATER, value2, mutations));
+
+      result = table.get(new Get(row2));
+      assertArrayEquals("the value of column q in row2 should be value2",
+          value2, result.getValue(family, qualifier));
+    }
+  }
 }