Skip to content

Commit 1ba6f3f

Browse files
author
wenbang
committed
HBASE-25001 Backport HBASE-16283 to branch-1
1 parent e5c0a94 commit 1ba6f3f

File tree

5 files changed

+57
-5
lines changed

5 files changed

+57
-5
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8021,7 +8021,7 @@ public Result append(Append mutate, long nonceGroup, long nonce) throws IOExcept
80218021
this.metricsRegion.updateAppend();
80228022
}
80238023
if (isFlushSize(this.addAndGetGlobalMemstoreSize(size))) requestFlush();
8024-
return mutate.isReturnResults() ? Result.create(allKVs) : null;
8024+
return mutate.isReturnResults() ? Result.create(allKVs) : Result.EMPTY_RESULT;
80258025
}
80268026

80278027
private void preWALAppend(WALKey walKey, WALEdit walEdits) throws IOException {
@@ -8261,7 +8261,7 @@ private Result doIncrement(Increment increment, long nonceGroup, long nonce) thr
82618261

82628262
// Request a cache flush. Do it outside update lock.
82638263
if (isFlushSize(this.addAndGetGlobalMemstoreSize(accumulatedResultSize))) requestFlush();
8264-
return increment.isReturnResults() ? Result.create(allKVs) : null;
8264+
return increment.isReturnResults() ? Result.create(allKVs) : Result.EMPTY_RESULT;
82658265
}
82668266

82678267
/**

hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4763,6 +4763,30 @@ public void testRowMutation() throws Exception {
47634763
}
47644764
}
47654765

4766+
@Test
4767+
public void testBatchAppendWithReturnResultFalse() throws Exception {
4768+
LOG.info("Starting testBatchAppendWithReturnResultFalse");
4769+
final TableName TABLENAME = TableName.valueOf("testBatchAppend");
4770+
Table table = TEST_UTIL.createTable(TABLENAME, FAMILY);
4771+
Append append1 = new Append(Bytes.toBytes("row1"));
4772+
append1.setReturnResults(false);
4773+
append1.add(FAMILY, Bytes.toBytes("f1"), Bytes.toBytes("value1"));
4774+
Append append2 = new Append(Bytes.toBytes("row1"));
4775+
append2.setReturnResults(false);
4776+
append2.add(FAMILY, Bytes.toBytes("f1"), Bytes.toBytes("value2"));
4777+
List<Append> appends = new ArrayList<>();
4778+
appends.add(append1);
4779+
appends.add(append2);
4780+
Object[] results = new Object[2];
4781+
table.batch(appends, results);
4782+
assertTrue(results.length == 2);
4783+
for(Object r : results) {
4784+
Result result = (Result)r;
4785+
assertTrue(result.isEmpty());
4786+
}
4787+
table.close();
4788+
}
4789+
47664790
@Test
47674791
public void testAppend() throws Exception {
47684792
LOG.info("Starting testAppend");
@@ -4778,7 +4802,7 @@ public void testAppend() throws Exception {
47784802
a.add(FAMILY, QUALIFIERS[0], v1);
47794803
a.add(FAMILY, QUALIFIERS[1], v2);
47804804
a.setReturnResults(false);
4781-
assertNullResult(t.append(a));
4805+
assertEmptyResult(t.append(a));
47824806

47834807
a = new Append(ROW);
47844808
a.add(FAMILY, QUALIFIERS[0], v2);

hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestIncrementsFromClientSide.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@
1919
package org.apache.hadoop.hbase.client;
2020

2121
import static org.junit.Assert.assertEquals;
22+
import static org.junit.Assert.assertTrue;
2223
import static org.junit.Assert.assertNotNull;
2324
import static org.junit.Assert.fail;
2425

2526
import java.io.IOException;
2627
import java.util.Arrays;
28+
import java.util.ArrayList;
2729
import java.util.Collection;
2830
import java.util.HashMap;
31+
import java.util.List;
2932
import java.util.Map;
3033

3134
import org.apache.commons.logging.Log;
@@ -187,6 +190,30 @@ public void testIncrementingInvalidValue() throws Exception {
187190
}
188191
}
189192

193+
@Test
194+
public void testBatchIncrementsWithReturnResultFalse() throws Exception {
195+
LOG.info("Starting testBatchIncrementsWithReturnResultFalse");
196+
final TableName TABLENAME = TableName.valueOf("testBatchAppend");
197+
Table table = TEST_UTIL.createTable(TABLENAME, FAMILY);
198+
Increment inc1 = new Increment(Bytes.toBytes("row2"));
199+
inc1.setReturnResults(false);
200+
inc1.addColumn(FAMILY, Bytes.toBytes("f1"), 1);
201+
Increment inc2 = new Increment(Bytes.toBytes("row2"));
202+
inc2.setReturnResults(false);
203+
inc2.addColumn(FAMILY, Bytes.toBytes("f1"), 1);
204+
List<Increment> incs = new ArrayList<>();
205+
incs.add(inc1);
206+
incs.add(inc2);
207+
Object[] results = new Object[2];
208+
table.batch(incs, results);
209+
assertTrue(results.length == 2);
210+
for(Object r : results) {
211+
Result result = (Result)r;
212+
assertTrue(result.isEmpty());
213+
}
214+
table.close();
215+
}
216+
190217
@Test
191218
public void testIncrementInvalidArguments() throws Exception {
192219
LOG.info("Starting " + this.name.getMethodName());

hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestAtomicOperation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public void testAppend() throws IOException {
131131
a.setReturnResults(false);
132132
a.add(fam1, qual1, Bytes.toBytes(v1));
133133
a.add(fam1, qual2, Bytes.toBytes(v2));
134-
assertNull(region.append(a, HConstants.NO_NONCE, HConstants.NO_NONCE));
134+
assertTrue(region.append(a, HConstants.NO_NONCE, HConstants.NO_NONCE).isEmpty());
135135
a = new Append(row);
136136
a.add(fam1, qual1, Bytes.toBytes(v2));
137137
a.add(fam1, qual2, Bytes.toBytes(v1));

hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestDurability.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import static org.junit.Assert.assertEquals;
2222
import static org.junit.Assert.assertNull;
23+
import static org.junit.Assert.assertTrue;
2324

2425
import java.io.IOException;
2526

@@ -220,7 +221,7 @@ public void testIncrementWithReturnResultsSetToFalse() throws Exception {
220221
inc1.setReturnResults(false);
221222
inc1.addColumn(FAMILY, col1, 1);
222223
Result res = region.increment(inc1);
223-
assertNull(res);
224+
assertTrue(res.isEmpty());
224225
}
225226

226227
private Put newPut(Durability durability) {

0 commit comments

Comments
 (0)