hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject hbase git commit: HBASE-13299 Add setReturnResults() to Increment, like Append has
Date Tue, 07 Apr 2015 18:47:33 GMT
Repository: hbase
Updated Branches:
  refs/heads/master 57f9c8212 -> 4d5a11e08


HBASE-13299 Add setReturnResults() to Increment, like Append has

Signed-off-by: stack <stack@apache.org>


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

Branch: refs/heads/master
Commit: 4d5a11e082e3b18100bb533626b51ebefb62fc7e
Parents: 57f9c82
Author: Ashish Singhi <ashish.singhi@huawei.com>
Authored: Fri Mar 20 21:43:20 2015 +0530
Committer: stack <stack@apache.org>
Committed: Tue Apr 7 11:46:56 2015 -0700

----------------------------------------------------------------------
 .../apache/hadoop/hbase/client/Increment.java   | 20 +++++++++++++++++
 .../hadoop/hbase/regionserver/HRegion.java      |  3 +--
 .../hbase/regionserver/wal/TestDurability.java  | 23 ++++++++++++++++++++
 3 files changed, 44 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/4d5a11e0/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Increment.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Increment.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Increment.java
index b6e6a52..d37cf82 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Increment.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Increment.java
@@ -53,6 +53,8 @@ import org.apache.hadoop.hbase.util.ClassSize;
 public class Increment extends Mutation implements Comparable<Row> {
   private static final long HEAP_OVERHEAD =  ClassSize.REFERENCE + ClassSize.TIMERANGE;
 
+  private static final String RETURN_RESULTS = "_rr_";
+
   private TimeRange tr = new TimeRange();
 
   /**
@@ -161,6 +163,24 @@ public class Increment extends Mutation implements Comparable<Row>
{
     tr = new TimeRange(minStamp, maxStamp);
     return this;
   }
+  
+  /**
+   * @param returnResults True (default) if the increment operation should return the results.
A
+   *          client that is not interested in the result can save network bandwidth setting
this
+   *          to false.
+   */
+  public Increment setReturnResults(boolean returnResults) {
+    setAttribute(RETURN_RESULTS, Bytes.toBytes(returnResults));
+    return this;
+  }
+
+  /**
+   * @return current value for returnResults
+   */
+  public boolean isReturnResults() {
+    byte[] v = getAttribute(RETURN_RESULTS);
+    return v == null ? true : Bytes.toBoolean(v);
+  }
 
   /**
    * Method for retrieving the number of families to increment from

http://git-wip-us.apache.org/repos/asf/hbase/blob/4d5a11e0/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
index b8e3e52..4a8e7cc 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
@@ -7097,8 +7097,7 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver,
Regi
       // Request a cache flush.  Do it outside update lock.
       requestFlush();
     }
-
-    return Result.create(allKVs);
+    return increment.isReturnResults() ? Result.create(allKVs) : null;
   }
 
   //

http://git-wip-us.apache.org/repos/asf/hbase/blob/4d5a11e0/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestDurability.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestDurability.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestDurability.java
index 10e7e3d..94aa106 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestDurability.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestDurability.java
@@ -19,6 +19,7 @@
 package org.apache.hadoop.hbase.regionserver.wal;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
 
 import java.io.IOException;
 
@@ -192,6 +193,28 @@ public class TestDurability {
     assertEquals(3, Bytes.toLong(res.getValue(FAMILY, col3)));
     verifyWALCount(wals, wal, 2);
   }
+  
+  /*
+   * Test when returnResults set to false in increment it should not return the result instead
it
+   * resturn null.
+   */
+  @Test
+  public void testIncrementWithReturnResultsSetToFalse() throws Exception {
+    byte[] row1 = Bytes.toBytes("row1");
+    byte[] col1 = Bytes.toBytes("col1");
+
+    // Setting up region
+    final WALFactory wals = new WALFactory(CONF, null, "testIncrementWithReturnResultsSetToFalse");
+    byte[] tableName = Bytes.toBytes("testIncrementWithReturnResultsSetToFalse");
+    final WAL wal = wals.getWAL(tableName);
+    HRegion region = createHRegion(tableName, "increment", wal, Durability.USE_DEFAULT);
+
+    Increment inc1 = new Increment(row1);
+    inc1.setReturnResults(false);
+    inc1.addColumn(FAMILY, col1, 1);
+    Result res = region.increment(inc1);
+    assertNull(res);
+  }
 
   private Put newPut(Durability durability) {
     Put p = new Put(ROW);


Mime
View raw message