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

Signed-off-by: stack <stack@apache.org>
This commit is contained in:
Ashish Singhi 2015-03-20 21:43:20 +05:30 committed by stack
parent 57f9c82128
commit 4d5a11e082
3 changed files with 44 additions and 2 deletions

View File

@ -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

View File

@ -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;
}
//

View File

@ -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);