HBASE-13134 mutateRow and checkAndMutate apis don't throw region level exceptions (Francis Liu)

This commit is contained in:
tedyu 2015-03-01 20:22:07 -08:00
parent 70ecf18817
commit 4980bfe642
3 changed files with 43 additions and 1 deletions

View File

@ -1038,7 +1038,15 @@ public class HTable implements HTableInterface {
regionMutationBuilder.setAtomic(true);
MultiRequest request =
MultiRequest.newBuilder().addRegionAction(regionMutationBuilder.build()).build();
getStub().multi(controller, request);
ClientProtos.MultiResponse response = getStub().multi(controller, request);
ClientProtos.RegionActionResult res = response.getRegionActionResultList().get(0);
if (res.hasException()) {
Throwable ex = ProtobufUtil.toException(res.getException());
if(ex instanceof IOException) {
throw (IOException)ex;
}
throw new IOException("Failed to mutate row: "+Bytes.toStringBinary(rm.getRow()), ex);
}
} catch (ServiceException se) {
throw ProtobufUtil.getRemoteException(se);
}
@ -1317,6 +1325,15 @@ public class HTable implements HTableInterface {
getLocation().getRegionInfo().getRegionName(), row, family, qualifier,
new BinaryComparator(value), compareType, rm);
ClientProtos.MultiResponse response = getStub().multi(controller, request);
ClientProtos.RegionActionResult res = response.getRegionActionResultList().get(0);
if (res.hasException()) {
Throwable ex = ProtobufUtil.toException(res.getException());
if(ex instanceof IOException) {
throw (IOException)ex;
}
throw new IOException("Failed to checkAndMutate row: "+
Bytes.toStringBinary(rm.getRow()), ex);
}
return Boolean.valueOf(response.getProcessed());
} catch (ServiceException se) {
throw ProtobufUtil.getRemoteException(se);

View File

@ -21,6 +21,7 @@ package org.apache.hadoop.hbase.client;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.filter.CompareFilter;
import org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.AfterClass;
@ -29,6 +30,7 @@ import org.junit.Test;
import org.junit.experimental.categories.Category;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@Category(MediumTests.class)
public class TestCheckAndMutate {
@ -96,6 +98,18 @@ public class TestCheckAndMutate {
Bytes.toString(result.getValue(family, Bytes.toBytes("B"))).equals("b"));
assertTrue("Column C should not exist",
result.getValue(family, Bytes.toBytes("C")) == null);
//Test that we get a region level exception
try {
Put p = new Put(rowKey);
p.add(new byte[]{'b', 'o', 'g', 'u', 's'}, new byte[]{'A'}, new byte[0]);
rm = new RowMutations(rowKey);
rm.add(p);
table.checkAndMutate(rowKey, family, Bytes.toBytes("A"), CompareFilter.CompareOp.EQUAL,
Bytes.toBytes("a"), rm);
fail("Expected NoSuchColumnFamilyException");
} catch(NoSuchColumnFamilyException e) {
}
} finally {
table.close();
}

View File

@ -4432,6 +4432,17 @@ public class TestFromClientSide {
r = t.get(g);
assertEquals(0, Bytes.compareTo(VALUE, r.getValue(FAMILY, QUALIFIERS[1])));
assertNull(r.getValue(FAMILY, QUALIFIERS[0]));
//Test that we get a region level exception
try {
arm = new RowMutations(ROW);
p = new Put(ROW);
p.add(new byte[]{'b', 'o', 'g', 'u', 's'}, QUALIFIERS[0], VALUE);
arm.add(p);
t.mutateRow(arm);
fail("Expected NoSuchColumnFamilyException");
} catch(NoSuchColumnFamilyException e) {
}
}
@Test