HBASE-13134 mutateRow and checkAndMutate apis don't throw region level exceptions (Francis Liu)
This commit is contained in:
parent
10f3b77748
commit
c64686e2e1
|
@ -1048,7 +1048,15 @@ public class HTable implements HTableInterface {
|
||||||
regionMutationBuilder.setAtomic(true);
|
regionMutationBuilder.setAtomic(true);
|
||||||
MultiRequest request =
|
MultiRequest request =
|
||||||
MultiRequest.newBuilder().addRegionAction(regionMutationBuilder.build()).build();
|
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) {
|
} catch (ServiceException se) {
|
||||||
throw ProtobufUtil.getRemoteException(se);
|
throw ProtobufUtil.getRemoteException(se);
|
||||||
}
|
}
|
||||||
|
@ -1327,6 +1335,15 @@ public class HTable implements HTableInterface {
|
||||||
getLocation().getRegionInfo().getRegionName(), row, family, qualifier,
|
getLocation().getRegionInfo().getRegionName(), row, family, qualifier,
|
||||||
new BinaryComparator(value), compareType, rm);
|
new BinaryComparator(value), compareType, rm);
|
||||||
ClientProtos.MultiResponse response = 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 checkAndMutate row: "+
|
||||||
|
Bytes.toStringBinary(rm.getRow()), ex);
|
||||||
|
}
|
||||||
return Boolean.valueOf(response.getProcessed());
|
return Boolean.valueOf(response.getProcessed());
|
||||||
} catch (ServiceException se) {
|
} catch (ServiceException se) {
|
||||||
throw ProtobufUtil.getRemoteException(se);
|
throw ProtobufUtil.getRemoteException(se);
|
||||||
|
|
|
@ -22,6 +22,7 @@ import org.apache.hadoop.hbase.HBaseTestingUtility;
|
||||||
import org.apache.hadoop.hbase.testclassification.MediumTests;
|
import org.apache.hadoop.hbase.testclassification.MediumTests;
|
||||||
import org.apache.hadoop.hbase.TableName;
|
import org.apache.hadoop.hbase.TableName;
|
||||||
import org.apache.hadoop.hbase.filter.CompareFilter;
|
import org.apache.hadoop.hbase.filter.CompareFilter;
|
||||||
|
import org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException;
|
||||||
import org.apache.hadoop.hbase.util.Bytes;
|
import org.apache.hadoop.hbase.util.Bytes;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
@ -29,6 +30,7 @@ import org.junit.Test;
|
||||||
import org.junit.experimental.categories.Category;
|
import org.junit.experimental.categories.Category;
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
@Category(MediumTests.class)
|
@Category(MediumTests.class)
|
||||||
public class TestCheckAndMutate {
|
public class TestCheckAndMutate {
|
||||||
|
@ -96,8 +98,20 @@ public class TestCheckAndMutate {
|
||||||
Bytes.toString(result.getValue(family, Bytes.toBytes("B"))).equals("b"));
|
Bytes.toString(result.getValue(family, Bytes.toBytes("B"))).equals("b"));
|
||||||
assertTrue("Column C should not exist",
|
assertTrue("Column C should not exist",
|
||||||
result.getValue(family, Bytes.toBytes("C")) == null);
|
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 {
|
} finally {
|
||||||
table.close();
|
table.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4432,6 +4432,17 @@ public class TestFromClientSide {
|
||||||
r = t.get(g);
|
r = t.get(g);
|
||||||
assertEquals(0, Bytes.compareTo(VALUE, r.getValue(FAMILY, QUALIFIERS[1])));
|
assertEquals(0, Bytes.compareTo(VALUE, r.getValue(FAMILY, QUALIFIERS[1])));
|
||||||
assertNull(r.getValue(FAMILY, QUALIFIERS[0]));
|
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
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue