Skip to content

Commit 5d43b53

Browse files
stuBirdFlymiyuan-ljr
authored andcommitted
hbase support batchCallBack (oceanbase#86)
1 parent 676ec51 commit 5d43b53

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

src/main/java/com/alipay/oceanbase/hbase/OHTable.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,18 @@ private String getTargetTableName(List<? extends Row> actions) {
519519
@Override
520520
public <R> void batchCallback(List<? extends Row> actions, Object[] results,
521521
Batch.Callback<R> callback) throws IOException,
522-
InterruptedException {
523-
throw new FeatureNotSupportedException("not supported yet'");
522+
InterruptedException {
523+
try {
524+
batch(actions, results);
525+
} finally {
526+
if (results != null) {
527+
for (int i = 0; i < results.length; i++) {
528+
if (!(results[i] instanceof ObTableException)) {
529+
callback.update(null, actions.get(i).getRow(), (R) results[i]);
530+
}
531+
}
532+
}
533+
}
524534
}
525535

526536
public static int compareByteArray(byte[] bt1, byte[] bt2) {

src/test/java/com/alipay/oceanbase/hbase/OHTableMultiColumnFamilyTest.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717

1818
package com.alipay.oceanbase.hbase;
1919

20+
import com.alipay.oceanbase.rpc.mutation.result.MutationResult;
2021
import org.apache.hadoop.hbase.Cell;
2122
import org.apache.hadoop.hbase.CellUtil;
22-
import org.apache.hadoop.hbase.KeyValue;
2323
import org.apache.hadoop.hbase.client.*;
24+
import org.apache.hadoop.hbase.client.coprocessor.Batch;
2425
import org.apache.hadoop.hbase.filter.PrefixFilter;
2526
import org.junit.*;
2627
import org.junit.rules.ExpectedException;
@@ -152,6 +153,32 @@ public void testMultiColumnFamilyBatch() throws Exception {
152153
result = hTable.get(get);
153154
keyValues = result.rawCells();
154155
assertEquals(6, keyValues.length);
156+
157+
batchLsit.clear();
158+
final long[] updateCounter = new long[] { 0L };
159+
delete = new Delete(toBytes("Key5"));
160+
delete.deleteColumns(family1, family1_column2);
161+
delete.deleteColumns(family2, family2_column1);
162+
delete.deleteFamily(family3);
163+
batchLsit.add(delete);
164+
for (int i = 0; i < rows; ++i) {
165+
Put put = new Put(toBytes("Key" + i));
166+
put.add(family1, family1_column1, family1_value);
167+
put.add(family1, family1_column2, family1_value);
168+
put.add(family1, family1_column3, family1_value);
169+
put.add(family2, family2_column1, family2_value);
170+
put.add(family2, family2_column2, family2_value);
171+
put.add(family3, family3_column1, family3_value);
172+
batchLsit.add(put);
173+
}
174+
hTable.batchCallback(batchLsit, new Batch.Callback<MutationResult>() {
175+
@Override
176+
public void update(byte[] region, byte[] row, MutationResult result) {
177+
updateCounter[0]++;
178+
}
179+
});
180+
assertEquals(11, updateCounter[0]);
181+
155182
}
156183

157184
@Test

0 commit comments

Comments
 (0)