You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by mb...@apache.org on 2015/05/29 19:32:38 UTC

[1/5] hbase git commit: HBASE-13779 Calling table.exists() before table.get() end up with an empty Result

Repository: hbase
Updated Branches:
  refs/heads/0.98 fb9f47ec9 -> 8907e8f90
  refs/heads/branch-1 93e475e5b -> 5b67c7a0d
  refs/heads/branch-1.0 1c5068282 -> d1f761eec
  refs/heads/branch-1.1 e61e4f1b4 -> 1085e955d
  refs/heads/master f35b6c6b7 -> 18fef4690


HBASE-13779 Calling table.exists() before table.get() end up with an empty Result


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

Branch: refs/heads/master
Commit: 18fef46901c946b28c008cc1b22471d80e57df88
Parents: f35b6c6
Author: Matteo Bertozzi <ma...@cloudera.com>
Authored: Fri May 29 16:39:03 2015 +0100
Committer: Matteo Bertozzi <ma...@cloudera.com>
Committed: Fri May 29 16:39:03 2015 +0100

----------------------------------------------------------------------
 .../org/apache/hadoop/hbase/client/Get.java     | 13 +++-
 .../org/apache/hadoop/hbase/client/HTable.java  | 28 ++++++--
 .../org/apache/hadoop/hbase/client/Scan.java    |  1 +
 .../hbase/client/TestFromClientSide3.java       | 70 ++++++++++++++++++--
 4 files changed, 98 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/18fef469/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Get.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Get.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Get.java
index 3fa145c..272b7a6 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Get.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Get.java
@@ -107,7 +107,18 @@ public class Get extends Query
     this.tr = get.getTimeRange();
     this.checkExistenceOnly = get.isCheckExistenceOnly();
     this.closestRowBefore = get.isClosestRowBefore();
-    this.familyMap = get.getFamilyMap();
+    Map<byte[], NavigableSet<byte[]>> fams = get.getFamilyMap();
+    for (Map.Entry<byte[],NavigableSet<byte[]>> entry : fams.entrySet()) {
+      byte [] fam = entry.getKey();
+      NavigableSet<byte[]> cols = entry.getValue();
+      if (cols != null && cols.size() > 0) {
+        for (byte[] col : cols) {
+          addColumn(fam, col);
+        }
+      } else {
+        addFamily(fam);
+      }
+    }
     for (Map.Entry<String, byte[]> attr : get.getAttributesMap().entrySet()) {
       setAttribute(attr.getKey(), attr.getValue());
     }

http://git-wip-us.apache.org/repos/asf/hbase/blob/18fef469/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java
----------------------------------------------------------------------
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 6ba0b87..59fce15 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
@@ -71,6 +71,7 @@ import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.GetTableDescripto
 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.GetTableDescriptorsResponse;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.Pair;
+import org.apache.hadoop.hbase.util.ReflectionUtils;
 import org.apache.hadoop.hbase.util.Threads;
 
 import com.google.common.annotations.VisibleForTesting;
@@ -613,6 +614,7 @@ public class HTable implements HTableInterface {
     if (scan.getBatch() > 0 && scan.isSmall()) {
       throw new IllegalArgumentException("Small scan should not be used with batching");
     }
+
     if (scan.getCaching() <= 0) {
       scan.setCaching(scannerCaching);
     }
@@ -682,18 +684,28 @@ public class HTable implements HTableInterface {
    */
   @Override
   public Result get(final Get get) throws IOException {
-    if (get.getConsistency() == null){
-      get.setConsistency(defaultConsistency);
+    return get(get, false);
+  }
+
+  private Result get(Get get, final boolean checkExistenceOnly) throws IOException {
+    // if we are changing settings to the get, clone it.
+    if (get.isCheckExistenceOnly() != checkExistenceOnly || get.getConsistency() == null) {
+      get = ReflectionUtils.newInstance(get.getClass(), get);
+      get.setCheckExistenceOnly(checkExistenceOnly);
+      if (get.getConsistency() == null){
+        get.setConsistency(defaultConsistency);
+      }
     }
 
     if (get.getConsistency() == Consistency.STRONG) {
       // Good old call.
+      final Get getReq = get;
       RegionServerCallable<Result> callable = new RegionServerCallable<Result>(this.connection,
           getName(), get.getRow()) {
         @Override
         public Result call(int callTimeout) throws IOException {
           ClientProtos.GetRequest request =
-              RequestConverter.buildGetRequest(getLocation().getRegionInfo().getRegionName(), get);
+            RequestConverter.buildGetRequest(getLocation().getRegionInfo().getRegionName(), getReq);
           PayloadCarryingRpcController controller = rpcControllerFactory.newController();
           controller.setPriority(tableName);
           controller.setCallTimeout(callTimeout);
@@ -1189,8 +1201,7 @@ public class HTable implements HTableInterface {
    */
   @Override
   public boolean exists(final Get get) throws IOException {
-    get.setCheckExistenceOnly(true);
-    Result r = get(get);
+    Result r = get(get, true);
     assert r.getExists() != null;
     return r.getExists();
   }
@@ -1203,13 +1214,16 @@ public class HTable implements HTableInterface {
     if (gets.isEmpty()) return new boolean[]{};
     if (gets.size() == 1) return new boolean[]{exists(gets.get(0))};
 
+    ArrayList<Get> exists = new ArrayList<Get>(gets.size());
     for (Get g: gets){
-      g.setCheckExistenceOnly(true);
+      Get ge = new Get(g);
+      ge.setCheckExistenceOnly(true);
+      exists.add(ge);
     }
 
     Object[] r1;
     try {
-      r1 = batch(gets);
+      r1 = batch(exists);
     } catch (InterruptedException e) {
       throw (InterruptedIOException)new InterruptedIOException().initCause(e);
     }

http://git-wip-us.apache.org/repos/asf/hbase/blob/18fef469/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Scan.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Scan.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Scan.java
index 0b51150..a2e4449 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Scan.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Scan.java
@@ -235,6 +235,7 @@ public class Scan extends Query {
     loadColumnFamiliesOnDemand = scan.getLoadColumnFamiliesOnDemandValue();
     consistency = scan.getConsistency();
     reversed = scan.isReversed();
+    asyncPrefetch = scan.isAsyncPrefetch();
     small = scan.isSmall();
     TimeRange ctr = scan.getTimeRange();
     tr = new TimeRange(ctr.getMin(), ctr.getMax());

http://git-wip-us.apache.org/repos/asf/hbase/blob/18fef469/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java
index 52f4c89..1e7fbc7 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java
@@ -97,7 +97,10 @@ public class TestFromClientSide3 {
    */
   @After
   public void tearDown() throws Exception {
-    // Nothing to do.
+    for (HTableDescriptor htd: TEST_UTIL.getHBaseAdmin().listTables()) {
+      LOG.info("Tear down, remove table=" + htd.getTableName());
+      TEST_UTIL.deleteTable(htd.getTableName());
+    }
   }
 
   private void randomCFPuts(Table table, byte[] row, byte[] family, int nPuts)
@@ -277,20 +280,20 @@ public class TestFromClientSide3 {
       // create an empty Put
       Put put1 = new Put(ROW);
       actions.add(put1);
-      
+
       Put put2 = new Put(ANOTHERROW);
       put2.add(FAMILY, QUALIFIER, VALUE);
       actions.add(put2);
-      
+
       table.batch(actions, results);
       fail("Empty Put should have failed the batch call");
     } catch (IllegalArgumentException iae) {
-      
+
     } finally {
       table.close();
     }
   }
-  
+
   @Test
   public void testHTableExistsMethodSingleRegionSingleGet() throws Exception {
 
@@ -334,6 +337,61 @@ public class TestFromClientSide3 {
   }
 
   @Test
+  public void testHTableExistsBeforeGet() throws Exception {
+    Table table = TEST_UTIL.createTable(
+      Bytes.toBytes("testHTableExistsBeforeGet"), new byte[][] { FAMILY });
+    try {
+      Put put = new Put(ROW);
+      put.add(FAMILY, QUALIFIER, VALUE);
+      table.put(put);
+
+      Get get = new Get(ROW);
+
+      boolean exist = table.exists(get);
+      assertEquals(true, exist);
+
+      Result result = table.get(get);
+      assertEquals(false, result.isEmpty());
+      assertTrue(Bytes.equals(VALUE, result.getValue(FAMILY, QUALIFIER)));
+    } finally {
+      table.close();
+    }
+  }
+
+  @Test
+  public void testHTableExistsAllBeforeGet() throws Exception {
+    final byte[] ROW2 = Bytes.add(ROW, Bytes.toBytes("2"));
+    Table table = TEST_UTIL.createTable(
+      Bytes.toBytes("testHTableExistsAllBeforeGet"), new byte[][] { FAMILY });
+    try {
+      Put put = new Put(ROW);
+      put.add(FAMILY, QUALIFIER, VALUE);
+      table.put(put);
+      put = new Put(ROW2);
+      put.add(FAMILY, QUALIFIER, VALUE);
+      table.put(put);
+
+      Get get = new Get(ROW);
+      Get get2 = new Get(ROW2);
+      ArrayList<Get> getList = new ArrayList(2);
+      getList.add(get);
+      getList.add(get2);
+
+      boolean[] exists = table.existsAll(getList);
+      assertEquals(true, exists[0]);
+      assertEquals(true, exists[1]);
+
+      Result[] result = table.get(getList);
+      assertEquals(false, result[0].isEmpty());
+      assertTrue(Bytes.equals(VALUE, result[0].getValue(FAMILY, QUALIFIER)));
+      assertEquals(false, result[1].isEmpty());
+      assertTrue(Bytes.equals(VALUE, result[1].getValue(FAMILY, QUALIFIER)));
+    } finally {
+      table.close();
+    }
+  }
+
+  @Test
   public void testHTableExistsMethodMultipleRegionsSingleGet() throws Exception {
 
     Table table = TEST_UTIL.createTable(
@@ -356,7 +414,7 @@ public class TestFromClientSide3 {
   @Test
   public void testHTableExistsMethodMultipleRegionsMultipleGets() throws Exception {
     HTable table = TEST_UTIL.createTable(
-      TableName.valueOf("testHTableExistsMethodMultipleRegionsMultipleGets"), 
+      TableName.valueOf("testHTableExistsMethodMultipleRegionsMultipleGets"),
       new byte[][] { FAMILY }, 1, new byte[] { 0x00 }, new byte[] { (byte) 0xff }, 255);
     Put put = new Put(ROW);
     put.add(FAMILY, QUALIFIER, VALUE);


[4/5] hbase git commit: HBASE-13779 Calling table.exists() before table.get() end up with an empty Result

Posted by mb...@apache.org.
HBASE-13779 Calling table.exists() before table.get() end up with an empty Result


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

Branch: refs/heads/branch-1.0
Commit: d1f761eeca33610768fd58ced66e7417ffc6055e
Parents: 1c50682
Author: Matteo Bertozzi <ma...@cloudera.com>
Authored: Fri May 29 16:39:03 2015 +0100
Committer: Matteo Bertozzi <ma...@cloudera.com>
Committed: Fri May 29 17:48:28 2015 +0100

----------------------------------------------------------------------
 .../org/apache/hadoop/hbase/client/Get.java     | 13 +++-
 .../org/apache/hadoop/hbase/client/HTable.java  | 28 ++++++--
 .../hbase/client/TestFromClientSide3.java       | 70 ++++++++++++++++++--
 3 files changed, 97 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/d1f761ee/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Get.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Get.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Get.java
index eb3553b..32e3114 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Get.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Get.java
@@ -107,7 +107,18 @@ public class Get extends Query
     this.tr = get.getTimeRange();
     this.checkExistenceOnly = get.isCheckExistenceOnly();
     this.closestRowBefore = get.isClosestRowBefore();
-    this.familyMap = get.getFamilyMap();
+    Map<byte[], NavigableSet<byte[]>> fams = get.getFamilyMap();
+    for (Map.Entry<byte[],NavigableSet<byte[]>> entry : fams.entrySet()) {
+      byte [] fam = entry.getKey();
+      NavigableSet<byte[]> cols = entry.getValue();
+      if (cols != null && cols.size() > 0) {
+        for (byte[] col : cols) {
+          addColumn(fam, col);
+        }
+      } else {
+        addFamily(fam);
+      }
+    }
     for (Map.Entry<String, byte[]> attr : get.getAttributesMap().entrySet()) {
       setAttribute(attr.getKey(), attr.getValue());
     }

http://git-wip-us.apache.org/repos/asf/hbase/blob/d1f761ee/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java
----------------------------------------------------------------------
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 13827d6..689e827 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
@@ -74,6 +74,7 @@ import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.GetTableDescripto
 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.GetTableDescriptorsResponse;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.Pair;
+import org.apache.hadoop.hbase.util.ReflectionUtils;
 import org.apache.hadoop.hbase.util.Threads;
 
 import com.google.common.annotations.VisibleForTesting;
@@ -800,6 +801,7 @@ public class HTable implements HTableInterface, RegionLocator {
     if (scan.getBatch() > 0 && scan.isSmall()) {
       throw new IllegalArgumentException("Small scan should not be used with batching");
     }
+
     if (scan.getCaching() <= 0) {
       scan.setCaching(getScannerCaching());
     }
@@ -858,18 +860,28 @@ public class HTable implements HTableInterface, RegionLocator {
    */
   @Override
   public Result get(final Get get) throws IOException {
-    if (get.getConsistency() == null){
-      get.setConsistency(defaultConsistency);
+    return get(get, false);
+  }
+
+  private Result get(Get get, final boolean checkExistenceOnly) throws IOException {
+    // if we are changing settings to the get, clone it.
+    if (get.isCheckExistenceOnly() != checkExistenceOnly || get.getConsistency() == null) {
+      get = ReflectionUtils.newInstance(get.getClass(), get);
+      get.setCheckExistenceOnly(checkExistenceOnly);
+      if (get.getConsistency() == null){
+        get.setConsistency(defaultConsistency);
+      }
     }
 
     if (get.getConsistency() == Consistency.STRONG) {
       // Good old call.
+      final Get getReq = get;
       RegionServerCallable<Result> callable = new RegionServerCallable<Result>(this.connection,
           getName(), get.getRow()) {
         @Override
         public Result call(int callTimeout) throws IOException {
           ClientProtos.GetRequest request =
-              RequestConverter.buildGetRequest(getLocation().getRegionInfo().getRegionName(), get);
+            RequestConverter.buildGetRequest(getLocation().getRegionInfo().getRegionName(), getReq);
           PayloadCarryingRpcController controller = rpcControllerFactory.newController();
           controller.setPriority(tableName);
           controller.setCallTimeout(callTimeout);
@@ -1377,8 +1389,7 @@ public class HTable implements HTableInterface, RegionLocator {
    */
   @Override
   public boolean exists(final Get get) throws IOException {
-    get.setCheckExistenceOnly(true);
-    Result r = get(get);
+    Result r = get(get, true);
     assert r.getExists() != null;
     return r.getExists();
   }
@@ -1391,13 +1402,16 @@ public class HTable implements HTableInterface, RegionLocator {
     if (gets.isEmpty()) return new boolean[]{};
     if (gets.size() == 1) return new boolean[]{exists(gets.get(0))};
 
+    ArrayList<Get> exists = new ArrayList<Get>(gets.size());
     for (Get g: gets){
-      g.setCheckExistenceOnly(true);
+      Get ge = new Get(g);
+      ge.setCheckExistenceOnly(true);
+      exists.add(ge);
     }
 
     Object[] r1;
     try {
-      r1 = batch(gets);
+      r1 = batch(exists);
     } catch (InterruptedException e) {
       throw (InterruptedIOException)new InterruptedIOException().initCause(e);
     }

http://git-wip-us.apache.org/repos/asf/hbase/blob/d1f761ee/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java
index e2bd999..4afe3e7 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java
@@ -96,7 +96,10 @@ public class TestFromClientSide3 {
    */
   @After
   public void tearDown() throws Exception {
-    // Nothing to do.
+    for (HTableDescriptor htd: TEST_UTIL.getHBaseAdmin().listTables()) {
+      LOG.info("Tear down, remove table=" + htd.getTableName());
+      TEST_UTIL.deleteTable(htd.getTableName());
+    }
   }
 
   private void randomCFPuts(Table table, byte[] row, byte[] family, int nPuts)
@@ -276,20 +279,20 @@ public class TestFromClientSide3 {
       // create an empty Put
       Put put1 = new Put(ROW);
       actions.add(put1);
-      
+
       Put put2 = new Put(ANOTHERROW);
       put2.add(FAMILY, QUALIFIER, VALUE);
       actions.add(put2);
-      
+
       table.batch(actions, results);
       fail("Empty Put should have failed the batch call");
     } catch (IllegalArgumentException iae) {
-      
+
     } finally {
       table.close();
     }
   }
-  
+
   @Test
   public void testHTableExistsMethodSingleRegionSingleGet() throws Exception {
 
@@ -333,6 +336,61 @@ public class TestFromClientSide3 {
   }
 
   @Test
+  public void testHTableExistsBeforeGet() throws Exception {
+    Table table = TEST_UTIL.createTable(
+      Bytes.toBytes("testHTableExistsBeforeGet"), new byte[][] { FAMILY });
+    try {
+      Put put = new Put(ROW);
+      put.add(FAMILY, QUALIFIER, VALUE);
+      table.put(put);
+
+      Get get = new Get(ROW);
+
+      boolean exist = table.exists(get);
+      assertEquals(true, exist);
+
+      Result result = table.get(get);
+      assertEquals(false, result.isEmpty());
+      assertTrue(Bytes.equals(VALUE, result.getValue(FAMILY, QUALIFIER)));
+    } finally {
+      table.close();
+    }
+  }
+
+  @Test
+  public void testHTableExistsAllBeforeGet() throws Exception {
+    final byte[] ROW2 = Bytes.add(ROW, Bytes.toBytes("2"));
+    Table table = TEST_UTIL.createTable(
+      Bytes.toBytes("testHTableExistsAllBeforeGet"), new byte[][] { FAMILY });
+    try {
+      Put put = new Put(ROW);
+      put.add(FAMILY, QUALIFIER, VALUE);
+      table.put(put);
+      put = new Put(ROW2);
+      put.add(FAMILY, QUALIFIER, VALUE);
+      table.put(put);
+
+      Get get = new Get(ROW);
+      Get get2 = new Get(ROW2);
+      ArrayList<Get> getList = new ArrayList(2);
+      getList.add(get);
+      getList.add(get2);
+
+      boolean[] exists = table.existsAll(getList);
+      assertEquals(true, exists[0]);
+      assertEquals(true, exists[1]);
+
+      Result[] result = table.get(getList);
+      assertEquals(false, result[0].isEmpty());
+      assertTrue(Bytes.equals(VALUE, result[0].getValue(FAMILY, QUALIFIER)));
+      assertEquals(false, result[1].isEmpty());
+      assertTrue(Bytes.equals(VALUE, result[1].getValue(FAMILY, QUALIFIER)));
+    } finally {
+      table.close();
+    }
+  }
+
+  @Test
   public void testHTableExistsMethodMultipleRegionsSingleGet() throws Exception {
 
     Table table = TEST_UTIL.createTable(
@@ -355,7 +413,7 @@ public class TestFromClientSide3 {
   @Test
   public void testHTableExistsMethodMultipleRegionsMultipleGets() throws Exception {
     HTable table = TEST_UTIL.createTable(
-      TableName.valueOf("testHTableExistsMethodMultipleRegionsMultipleGets"), 
+      TableName.valueOf("testHTableExistsMethodMultipleRegionsMultipleGets"),
       new byte[][] { FAMILY }, 1, new byte[] { 0x00 }, new byte[] { (byte) 0xff }, 255);
     Put put = new Put(ROW);
     put.add(FAMILY, QUALIFIER, VALUE);


[3/5] hbase git commit: HBASE-13779 Calling table.exists() before table.get() end up with an empty Result

Posted by mb...@apache.org.
HBASE-13779 Calling table.exists() before table.get() end up with an empty Result


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

Branch: refs/heads/branch-1.1
Commit: 1085e955d34b3962094ce71db82afd71f86a59cc
Parents: e61e4f1
Author: Matteo Bertozzi <ma...@cloudera.com>
Authored: Fri May 29 16:39:03 2015 +0100
Committer: Matteo Bertozzi <ma...@cloudera.com>
Committed: Fri May 29 16:57:06 2015 +0100

----------------------------------------------------------------------
 .../org/apache/hadoop/hbase/client/Get.java     | 13 +++-
 .../org/apache/hadoop/hbase/client/HTable.java  | 28 ++++++--
 .../hbase/client/TestFromClientSide3.java       | 70 ++++++++++++++++++--
 3 files changed, 97 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/1085e955/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Get.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Get.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Get.java
index eb3553b..32e3114 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Get.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Get.java
@@ -107,7 +107,18 @@ public class Get extends Query
     this.tr = get.getTimeRange();
     this.checkExistenceOnly = get.isCheckExistenceOnly();
     this.closestRowBefore = get.isClosestRowBefore();
-    this.familyMap = get.getFamilyMap();
+    Map<byte[], NavigableSet<byte[]>> fams = get.getFamilyMap();
+    for (Map.Entry<byte[],NavigableSet<byte[]>> entry : fams.entrySet()) {
+      byte [] fam = entry.getKey();
+      NavigableSet<byte[]> cols = entry.getValue();
+      if (cols != null && cols.size() > 0) {
+        for (byte[] col : cols) {
+          addColumn(fam, col);
+        }
+      } else {
+        addFamily(fam);
+      }
+    }
     for (Map.Entry<String, byte[]> attr : get.getAttributesMap().entrySet()) {
       setAttribute(attr.getKey(), attr.getValue());
     }

http://git-wip-us.apache.org/repos/asf/hbase/blob/1085e955/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java
----------------------------------------------------------------------
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 f82e554..c59be3c 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
@@ -70,6 +70,7 @@ import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.GetTableDescripto
 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.GetTableDescriptorsResponse;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.Pair;
+import org.apache.hadoop.hbase.util.ReflectionUtils;
 import org.apache.hadoop.hbase.util.Threads;
 
 import com.google.common.annotations.VisibleForTesting;
@@ -782,6 +783,7 @@ public class HTable implements HTableInterface, RegionLocator {
     if (scan.getBatch() > 0 && scan.isSmall()) {
       throw new IllegalArgumentException("Small scan should not be used with batching");
     }
+
     if (scan.getCaching() <= 0) {
       scan.setCaching(getScannerCaching());
     }
@@ -840,18 +842,28 @@ public class HTable implements HTableInterface, RegionLocator {
    */
   @Override
   public Result get(final Get get) throws IOException {
-    if (get.getConsistency() == null){
-      get.setConsistency(defaultConsistency);
+    return get(get, false);
+  }
+
+  private Result get(Get get, final boolean checkExistenceOnly) throws IOException {
+    // if we are changing settings to the get, clone it.
+    if (get.isCheckExistenceOnly() != checkExistenceOnly || get.getConsistency() == null) {
+      get = ReflectionUtils.newInstance(get.getClass(), get);
+      get.setCheckExistenceOnly(checkExistenceOnly);
+      if (get.getConsistency() == null){
+        get.setConsistency(defaultConsistency);
+      }
     }
 
     if (get.getConsistency() == Consistency.STRONG) {
       // Good old call.
+      final Get getReq = get;
       RegionServerCallable<Result> callable = new RegionServerCallable<Result>(this.connection,
           getName(), get.getRow()) {
         @Override
         public Result call(int callTimeout) throws IOException {
           ClientProtos.GetRequest request =
-              RequestConverter.buildGetRequest(getLocation().getRegionInfo().getRegionName(), get);
+            RequestConverter.buildGetRequest(getLocation().getRegionInfo().getRegionName(), getReq);
           PayloadCarryingRpcController controller = rpcControllerFactory.newController();
           controller.setPriority(tableName);
           controller.setCallTimeout(callTimeout);
@@ -1362,8 +1374,7 @@ public class HTable implements HTableInterface, RegionLocator {
    */
   @Override
   public boolean exists(final Get get) throws IOException {
-    get.setCheckExistenceOnly(true);
-    Result r = get(get);
+    Result r = get(get, true);
     assert r.getExists() != null;
     return r.getExists();
   }
@@ -1376,13 +1387,16 @@ public class HTable implements HTableInterface, RegionLocator {
     if (gets.isEmpty()) return new boolean[]{};
     if (gets.size() == 1) return new boolean[]{exists(gets.get(0))};
 
+    ArrayList<Get> exists = new ArrayList<Get>(gets.size());
     for (Get g: gets){
-      g.setCheckExistenceOnly(true);
+      Get ge = new Get(g);
+      ge.setCheckExistenceOnly(true);
+      exists.add(ge);
     }
 
     Object[] r1;
     try {
-      r1 = batch(gets);
+      r1 = batch(exists);
     } catch (InterruptedException e) {
       throw (InterruptedIOException)new InterruptedIOException().initCause(e);
     }

http://git-wip-us.apache.org/repos/asf/hbase/blob/1085e955/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java
index e2bd999..4afe3e7 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java
@@ -96,7 +96,10 @@ public class TestFromClientSide3 {
    */
   @After
   public void tearDown() throws Exception {
-    // Nothing to do.
+    for (HTableDescriptor htd: TEST_UTIL.getHBaseAdmin().listTables()) {
+      LOG.info("Tear down, remove table=" + htd.getTableName());
+      TEST_UTIL.deleteTable(htd.getTableName());
+    }
   }
 
   private void randomCFPuts(Table table, byte[] row, byte[] family, int nPuts)
@@ -276,20 +279,20 @@ public class TestFromClientSide3 {
       // create an empty Put
       Put put1 = new Put(ROW);
       actions.add(put1);
-      
+
       Put put2 = new Put(ANOTHERROW);
       put2.add(FAMILY, QUALIFIER, VALUE);
       actions.add(put2);
-      
+
       table.batch(actions, results);
       fail("Empty Put should have failed the batch call");
     } catch (IllegalArgumentException iae) {
-      
+
     } finally {
       table.close();
     }
   }
-  
+
   @Test
   public void testHTableExistsMethodSingleRegionSingleGet() throws Exception {
 
@@ -333,6 +336,61 @@ public class TestFromClientSide3 {
   }
 
   @Test
+  public void testHTableExistsBeforeGet() throws Exception {
+    Table table = TEST_UTIL.createTable(
+      Bytes.toBytes("testHTableExistsBeforeGet"), new byte[][] { FAMILY });
+    try {
+      Put put = new Put(ROW);
+      put.add(FAMILY, QUALIFIER, VALUE);
+      table.put(put);
+
+      Get get = new Get(ROW);
+
+      boolean exist = table.exists(get);
+      assertEquals(true, exist);
+
+      Result result = table.get(get);
+      assertEquals(false, result.isEmpty());
+      assertTrue(Bytes.equals(VALUE, result.getValue(FAMILY, QUALIFIER)));
+    } finally {
+      table.close();
+    }
+  }
+
+  @Test
+  public void testHTableExistsAllBeforeGet() throws Exception {
+    final byte[] ROW2 = Bytes.add(ROW, Bytes.toBytes("2"));
+    Table table = TEST_UTIL.createTable(
+      Bytes.toBytes("testHTableExistsAllBeforeGet"), new byte[][] { FAMILY });
+    try {
+      Put put = new Put(ROW);
+      put.add(FAMILY, QUALIFIER, VALUE);
+      table.put(put);
+      put = new Put(ROW2);
+      put.add(FAMILY, QUALIFIER, VALUE);
+      table.put(put);
+
+      Get get = new Get(ROW);
+      Get get2 = new Get(ROW2);
+      ArrayList<Get> getList = new ArrayList(2);
+      getList.add(get);
+      getList.add(get2);
+
+      boolean[] exists = table.existsAll(getList);
+      assertEquals(true, exists[0]);
+      assertEquals(true, exists[1]);
+
+      Result[] result = table.get(getList);
+      assertEquals(false, result[0].isEmpty());
+      assertTrue(Bytes.equals(VALUE, result[0].getValue(FAMILY, QUALIFIER)));
+      assertEquals(false, result[1].isEmpty());
+      assertTrue(Bytes.equals(VALUE, result[1].getValue(FAMILY, QUALIFIER)));
+    } finally {
+      table.close();
+    }
+  }
+
+  @Test
   public void testHTableExistsMethodMultipleRegionsSingleGet() throws Exception {
 
     Table table = TEST_UTIL.createTable(
@@ -355,7 +413,7 @@ public class TestFromClientSide3 {
   @Test
   public void testHTableExistsMethodMultipleRegionsMultipleGets() throws Exception {
     HTable table = TEST_UTIL.createTable(
-      TableName.valueOf("testHTableExistsMethodMultipleRegionsMultipleGets"), 
+      TableName.valueOf("testHTableExistsMethodMultipleRegionsMultipleGets"),
       new byte[][] { FAMILY }, 1, new byte[] { 0x00 }, new byte[] { (byte) 0xff }, 255);
     Put put = new Put(ROW);
     put.add(FAMILY, QUALIFIER, VALUE);


[5/5] hbase git commit: HBASE-13779 Calling table.exists() before table.get() end up with an empty Result

Posted by mb...@apache.org.
HBASE-13779 Calling table.exists() before table.get() end up with an empty Result


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

Branch: refs/heads/0.98
Commit: 8907e8f90610b38bd0d74c6c0849054719d60d0d
Parents: fb9f47e
Author: Matteo Bertozzi <ma...@cloudera.com>
Authored: Fri May 29 18:26:18 2015 +0100
Committer: Matteo Bertozzi <ma...@cloudera.com>
Committed: Fri May 29 18:26:18 2015 +0100

----------------------------------------------------------------------
 .../org/apache/hadoop/hbase/client/Get.java     | 19 ++++--
 .../org/apache/hadoop/hbase/client/HTable.java  | 28 ++++++--
 .../hbase/client/TestFromClientSide3.java       | 68 ++++++++++++++++++--
 3 files changed, 99 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/8907e8f9/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Get.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Get.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Get.java
index 1d75847..0abc09d 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Get.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Get.java
@@ -105,7 +105,18 @@ public class Get extends Query
     this.tr = get.getTimeRange();
     this.checkExistenceOnly = get.isCheckExistenceOnly();
     this.closestRowBefore = get.isClosestRowBefore();
-    this.familyMap = get.getFamilyMap();
+    Map<byte[], NavigableSet<byte[]>> fams = get.getFamilyMap();
+    for (Map.Entry<byte[],NavigableSet<byte[]>> entry : fams.entrySet()) {
+      byte [] fam = entry.getKey();
+      NavigableSet<byte[]> cols = entry.getValue();
+      if (cols != null && cols.size() > 0) {
+        for (byte[] col : cols) {
+          addColumn(fam, col);
+        }
+      } else {
+        addFamily(fam);
+      }
+    }
     for (Map.Entry<String, byte[]> attr : get.getAttributesMap().entrySet()) {
       setAttribute(attr.getKey(), attr.getValue());
     }
@@ -370,7 +381,7 @@ public class Get extends Query
   public Map<String, Object> toMap(int maxCols) {
     // we start with the fingerprint map and build on top of it.
     Map<String, Object> map = getFingerprint();
-    // replace the fingerprint's simple list of families with a 
+    // replace the fingerprint's simple list of families with a
     // map from column families to lists of qualifiers and kv details
     Map<String, List<String>> columns = new HashMap<String, List<String>>();
     map.put("families", columns);
@@ -403,8 +414,8 @@ public class Get extends Query
           }
           familyList.add(Bytes.toStringBinary(column));
         }
-      }   
-    }   
+      }
+    }
     map.put("totalColumns", colCount);
     if (this.filter != null) {
       map.put("filter", this.filter.toString());

http://git-wip-us.apache.org/repos/asf/hbase/blob/8907e8f9/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java
----------------------------------------------------------------------
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 7f641fb..a6d1d55 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
@@ -72,6 +72,7 @@ import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.RegionAction;
 import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.CompareType;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.Pair;
+import org.apache.hadoop.hbase.util.ReflectionUtils;
 import org.apache.hadoop.hbase.util.Threads;
 
 import com.google.protobuf.Descriptors;
@@ -221,7 +222,7 @@ public class HTable implements HTableInterface {
     this.pool = getDefaultExecutor(this.configuration);
     this.finishSetup();
   }
-   
+
   public static ThreadPoolExecutor getDefaultExecutor(Configuration conf) {
     int maxThreads = conf.getInt("hbase.htable.threads.max", Integer.MAX_VALUE);
     if (maxThreads == 0) {
@@ -808,16 +809,27 @@ public class HTable implements HTableInterface {
    */
   @Override
   public Result get(final Get get) throws IOException {
+    return get(get, false);
+  }
+
+  private Result get(Get get, final boolean checkExistenceOnly) throws IOException {
+    // if we are changing settings to the get, clone it.
+    if (get.isCheckExistenceOnly() != checkExistenceOnly) {
+      get = ReflectionUtils.newInstance(get.getClass(), get);
+      get.setCheckExistenceOnly(checkExistenceOnly);
+    }
+
     // have to instanatiate this and set the priority here since in protobuf util we don't pass in
     // the tablename... an unfortunate side-effect of public interfaces :-/ In 0.99+ we put all the
     // logic back into HTable
     final PayloadCarryingRpcController controller = rpcControllerFactory.newController();
     controller.setPriority(tableName);
+    final Get getReq = get;
     RegionServerCallable<Result> callable =
         new RegionServerCallable<Result>(this.connection, getName(), get.getRow()) {
           public Result call() throws IOException {
-            return ProtobufUtil.get(getStub(), getLocation().getRegionInfo().getRegionName(), get,
-              controller);
+            return ProtobufUtil.get(getStub(), getLocation().getRegionInfo().getRegionName(),
+              getReq, controller);
           }
         };
     return rpcCallerFactory.<Result> newCaller().callWithRetries(callable, this.operationTimeout);
@@ -1294,8 +1306,7 @@ public class HTable implements HTableInterface {
    */
   @Override
   public boolean exists(final Get get) throws IOException {
-    get.setCheckExistenceOnly(true);
-    Result r = get(get);
+    Result r = get(get, true);
     assert r.getExists() != null;
     return r.getExists();
   }
@@ -1308,13 +1319,16 @@ public class HTable implements HTableInterface {
     if (gets.isEmpty()) return new Boolean[]{};
     if (gets.size() == 1) return new Boolean[]{exists(gets.get(0))};
 
+    ArrayList<Get> exists = new ArrayList<Get>(gets.size());
     for (Get g: gets){
-      g.setCheckExistenceOnly(true);
+      Get ge = new Get(g);
+      ge.setCheckExistenceOnly(true);
+      exists.add(ge);
     }
 
     Object[] r1;
     try {
-      r1 = batch(gets);
+      r1 = batch(exists);
     } catch (InterruptedException e) {
       throw (InterruptedIOException)new InterruptedIOException().initCause(e);
     }

http://git-wip-us.apache.org/repos/asf/hbase/blob/8907e8f9/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java
index 900b40a..b06ea04 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java
@@ -96,7 +96,10 @@ public class TestFromClientSide3 {
    */
   @After
   public void tearDown() throws Exception {
-    // Nothing to do.
+    for (HTableDescriptor htd: TEST_UTIL.getHBaseAdmin().listTables()) {
+      LOG.info("Tear down, remove table=" + htd.getTableName());
+      TEST_UTIL.deleteTable(htd.getTableName());
+    }
   }
 
   private void randomCFPuts(HTable table, byte[] row, byte[] family, int nPuts)
@@ -278,20 +281,20 @@ public class TestFromClientSide3 {
       // create an empty Put
       Put put1 = new Put(ROW);
       actions.add(put1);
-      
+
       Put put2 = new Put(ANOTHERROW);
       put2.add(FAMILY, QUALIFIER, VALUE);
       actions.add(put2);
-      
+
       table.batch(actions, results);
       fail("Empty Put should have failed the batch call");
     } catch (IllegalArgumentException iae) {
-      
+
     } finally {
       table.close();
     }
   }
-  
+
   @Test
   public void testHTableExistsMethodSingleRegionSingleGet() throws Exception {
 
@@ -434,6 +437,61 @@ public class TestFromClientSide3 {
   }
 
   @Test
+  public void testHTableExistsBeforeGet() throws Exception {
+    HTable table = TEST_UTIL.createTable(
+      Bytes.toBytes("testHTableExistsBeforeGet"), new byte[][] { FAMILY });
+    try {
+      Put put = new Put(ROW);
+      put.add(FAMILY, QUALIFIER, VALUE);
+      table.put(put);
+
+      Get get = new Get(ROW);
+
+      boolean exist = table.exists(get);
+      assertEquals(true, exist);
+
+      Result result = table.get(get);
+      assertEquals(false, result.isEmpty());
+      assertTrue(Bytes.equals(VALUE, result.getValue(FAMILY, QUALIFIER)));
+    } finally {
+      table.close();
+    }
+  }
+
+  @Test
+  public void testHTableExistsAllBeforeGet() throws Exception {
+    final byte[] ROW2 = Bytes.add(ROW, Bytes.toBytes("2"));
+    HTable table = TEST_UTIL.createTable(
+      Bytes.toBytes("testHTableExistsAllBeforeGet"), new byte[][] { FAMILY });
+    try {
+      Put put = new Put(ROW);
+      put.add(FAMILY, QUALIFIER, VALUE);
+      table.put(put);
+      put = new Put(ROW2);
+      put.add(FAMILY, QUALIFIER, VALUE);
+      table.put(put);
+
+      Get get = new Get(ROW);
+      Get get2 = new Get(ROW2);
+      ArrayList<Get> getList = new ArrayList(2);
+      getList.add(get);
+      getList.add(get2);
+
+      Boolean[] exists = table.exists(getList);
+      assertEquals(true, exists[0]);
+      assertEquals(true, exists[1]);
+
+      Result[] result = table.get(getList);
+      assertEquals(false, result[0].isEmpty());
+      assertTrue(Bytes.equals(VALUE, result[0].getValue(FAMILY, QUALIFIER)));
+      assertEquals(false, result[1].isEmpty());
+      assertTrue(Bytes.equals(VALUE, result[1].getValue(FAMILY, QUALIFIER)));
+    } finally {
+      table.close();
+    }
+  }
+
+  @Test
   public void testLeaseRenewal() throws Exception {
     HTable table = TEST_UTIL.createTable(
       Bytes.toBytes("testLeaseRenewal"), FAMILY);


[2/5] hbase git commit: HBASE-13779 Calling table.exists() before table.get() end up with an empty Result

Posted by mb...@apache.org.
HBASE-13779 Calling table.exists() before table.get() end up with an empty Result


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

Branch: refs/heads/branch-1
Commit: 5b67c7a0da32a21a38195353582e7851b5e11b51
Parents: 93e475e
Author: Matteo Bertozzi <ma...@cloudera.com>
Authored: Fri May 29 16:39:03 2015 +0100
Committer: Matteo Bertozzi <ma...@cloudera.com>
Committed: Fri May 29 16:44:39 2015 +0100

----------------------------------------------------------------------
 .../org/apache/hadoop/hbase/client/Get.java     | 13 +++-
 .../org/apache/hadoop/hbase/client/HTable.java  | 28 ++++++--
 .../hbase/client/TestFromClientSide3.java       | 70 ++++++++++++++++++--
 3 files changed, 97 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/5b67c7a0/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Get.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Get.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Get.java
index eb3553b..32e3114 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Get.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Get.java
@@ -107,7 +107,18 @@ public class Get extends Query
     this.tr = get.getTimeRange();
     this.checkExistenceOnly = get.isCheckExistenceOnly();
     this.closestRowBefore = get.isClosestRowBefore();
-    this.familyMap = get.getFamilyMap();
+    Map<byte[], NavigableSet<byte[]>> fams = get.getFamilyMap();
+    for (Map.Entry<byte[],NavigableSet<byte[]>> entry : fams.entrySet()) {
+      byte [] fam = entry.getKey();
+      NavigableSet<byte[]> cols = entry.getValue();
+      if (cols != null && cols.size() > 0) {
+        for (byte[] col : cols) {
+          addColumn(fam, col);
+        }
+      } else {
+        addFamily(fam);
+      }
+    }
     for (Map.Entry<String, byte[]> attr : get.getAttributesMap().entrySet()) {
       setAttribute(attr.getKey(), attr.getValue());
     }

http://git-wip-us.apache.org/repos/asf/hbase/blob/5b67c7a0/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java
----------------------------------------------------------------------
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 f82e554..c59be3c 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
@@ -70,6 +70,7 @@ import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.GetTableDescripto
 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.GetTableDescriptorsResponse;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.Pair;
+import org.apache.hadoop.hbase.util.ReflectionUtils;
 import org.apache.hadoop.hbase.util.Threads;
 
 import com.google.common.annotations.VisibleForTesting;
@@ -782,6 +783,7 @@ public class HTable implements HTableInterface, RegionLocator {
     if (scan.getBatch() > 0 && scan.isSmall()) {
       throw new IllegalArgumentException("Small scan should not be used with batching");
     }
+
     if (scan.getCaching() <= 0) {
       scan.setCaching(getScannerCaching());
     }
@@ -840,18 +842,28 @@ public class HTable implements HTableInterface, RegionLocator {
    */
   @Override
   public Result get(final Get get) throws IOException {
-    if (get.getConsistency() == null){
-      get.setConsistency(defaultConsistency);
+    return get(get, false);
+  }
+
+  private Result get(Get get, final boolean checkExistenceOnly) throws IOException {
+    // if we are changing settings to the get, clone it.
+    if (get.isCheckExistenceOnly() != checkExistenceOnly || get.getConsistency() == null) {
+      get = ReflectionUtils.newInstance(get.getClass(), get);
+      get.setCheckExistenceOnly(checkExistenceOnly);
+      if (get.getConsistency() == null){
+        get.setConsistency(defaultConsistency);
+      }
     }
 
     if (get.getConsistency() == Consistency.STRONG) {
       // Good old call.
+      final Get getReq = get;
       RegionServerCallable<Result> callable = new RegionServerCallable<Result>(this.connection,
           getName(), get.getRow()) {
         @Override
         public Result call(int callTimeout) throws IOException {
           ClientProtos.GetRequest request =
-              RequestConverter.buildGetRequest(getLocation().getRegionInfo().getRegionName(), get);
+            RequestConverter.buildGetRequest(getLocation().getRegionInfo().getRegionName(), getReq);
           PayloadCarryingRpcController controller = rpcControllerFactory.newController();
           controller.setPriority(tableName);
           controller.setCallTimeout(callTimeout);
@@ -1362,8 +1374,7 @@ public class HTable implements HTableInterface, RegionLocator {
    */
   @Override
   public boolean exists(final Get get) throws IOException {
-    get.setCheckExistenceOnly(true);
-    Result r = get(get);
+    Result r = get(get, true);
     assert r.getExists() != null;
     return r.getExists();
   }
@@ -1376,13 +1387,16 @@ public class HTable implements HTableInterface, RegionLocator {
     if (gets.isEmpty()) return new boolean[]{};
     if (gets.size() == 1) return new boolean[]{exists(gets.get(0))};
 
+    ArrayList<Get> exists = new ArrayList<Get>(gets.size());
     for (Get g: gets){
-      g.setCheckExistenceOnly(true);
+      Get ge = new Get(g);
+      ge.setCheckExistenceOnly(true);
+      exists.add(ge);
     }
 
     Object[] r1;
     try {
-      r1 = batch(gets);
+      r1 = batch(exists);
     } catch (InterruptedException e) {
       throw (InterruptedIOException)new InterruptedIOException().initCause(e);
     }

http://git-wip-us.apache.org/repos/asf/hbase/blob/5b67c7a0/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java
index 975103f..bb2784d 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java
@@ -96,7 +96,10 @@ public class TestFromClientSide3 {
    */
   @After
   public void tearDown() throws Exception {
-    // Nothing to do.
+    for (HTableDescriptor htd: TEST_UTIL.getHBaseAdmin().listTables()) {
+      LOG.info("Tear down, remove table=" + htd.getTableName());
+      TEST_UTIL.deleteTable(htd.getTableName());
+    }
   }
 
   private void randomCFPuts(Table table, byte[] row, byte[] family, int nPuts)
@@ -276,20 +279,20 @@ public class TestFromClientSide3 {
       // create an empty Put
       Put put1 = new Put(ROW);
       actions.add(put1);
-      
+
       Put put2 = new Put(ANOTHERROW);
       put2.add(FAMILY, QUALIFIER, VALUE);
       actions.add(put2);
-      
+
       table.batch(actions, results);
       fail("Empty Put should have failed the batch call");
     } catch (IllegalArgumentException iae) {
-      
+
     } finally {
       table.close();
     }
   }
-  
+
   @Test
   public void testHTableExistsMethodSingleRegionSingleGet() throws Exception {
 
@@ -333,6 +336,61 @@ public class TestFromClientSide3 {
   }
 
   @Test
+  public void testHTableExistsBeforeGet() throws Exception {
+    Table table = TEST_UTIL.createTable(
+      Bytes.toBytes("testHTableExistsBeforeGet"), new byte[][] { FAMILY });
+    try {
+      Put put = new Put(ROW);
+      put.add(FAMILY, QUALIFIER, VALUE);
+      table.put(put);
+
+      Get get = new Get(ROW);
+
+      boolean exist = table.exists(get);
+      assertEquals(true, exist);
+
+      Result result = table.get(get);
+      assertEquals(false, result.isEmpty());
+      assertTrue(Bytes.equals(VALUE, result.getValue(FAMILY, QUALIFIER)));
+    } finally {
+      table.close();
+    }
+  }
+
+  @Test
+  public void testHTableExistsAllBeforeGet() throws Exception {
+    final byte[] ROW2 = Bytes.add(ROW, Bytes.toBytes("2"));
+    Table table = TEST_UTIL.createTable(
+      Bytes.toBytes("testHTableExistsAllBeforeGet"), new byte[][] { FAMILY });
+    try {
+      Put put = new Put(ROW);
+      put.add(FAMILY, QUALIFIER, VALUE);
+      table.put(put);
+      put = new Put(ROW2);
+      put.add(FAMILY, QUALIFIER, VALUE);
+      table.put(put);
+
+      Get get = new Get(ROW);
+      Get get2 = new Get(ROW2);
+      ArrayList<Get> getList = new ArrayList(2);
+      getList.add(get);
+      getList.add(get2);
+
+      boolean[] exists = table.existsAll(getList);
+      assertEquals(true, exists[0]);
+      assertEquals(true, exists[1]);
+
+      Result[] result = table.get(getList);
+      assertEquals(false, result[0].isEmpty());
+      assertTrue(Bytes.equals(VALUE, result[0].getValue(FAMILY, QUALIFIER)));
+      assertEquals(false, result[1].isEmpty());
+      assertTrue(Bytes.equals(VALUE, result[1].getValue(FAMILY, QUALIFIER)));
+    } finally {
+      table.close();
+    }
+  }
+
+  @Test
   public void testHTableExistsMethodMultipleRegionsSingleGet() throws Exception {
 
     Table table = TEST_UTIL.createTable(
@@ -355,7 +413,7 @@ public class TestFromClientSide3 {
   @Test
   public void testHTableExistsMethodMultipleRegionsMultipleGets() throws Exception {
     HTable table = TEST_UTIL.createTable(
-      TableName.valueOf("testHTableExistsMethodMultipleRegionsMultipleGets"), 
+      TableName.valueOf("testHTableExistsMethodMultipleRegionsMultipleGets"),
       new byte[][] { FAMILY }, 1, new byte[] { 0x00 }, new byte[] { (byte) 0xff }, 255);
     Put put = new Put(ROW);
     put.add(FAMILY, QUALIFIER, VALUE);