use of org.apache.hadoop.hbase.client.Append in project hbase by apache.
the class TestPostIncrementAndAppendBeforeWAL method testChangeCellWithNotExistColumnFamily.
@Test
public void testChangeCellWithNotExistColumnFamily() throws Exception {
TableName tableName = TableName.valueOf(name.getMethodName());
createTableWithCoprocessor(tableName, ChangeCellWithNotExistColumnFamilyObserver.class.getName());
try (Table table = connection.getTable(tableName)) {
try {
Increment increment = new Increment(ROW).addColumn(CF1_BYTES, CQ1, 1);
table.increment(increment);
fail("should throw NoSuchColumnFamilyException");
} catch (Exception e) {
assertTrue(e instanceof NoSuchColumnFamilyException);
}
try {
Append append = new Append(ROW).addColumn(CF1_BYTES, CQ2, VALUE);
table.append(append);
fail("should throw NoSuchColumnFamilyException");
} catch (Exception e) {
assertTrue(e instanceof NoSuchColumnFamilyException);
}
}
}
use of org.apache.hadoop.hbase.client.Append in project hbase by apache.
the class TestRegionObserverInterface method testAppendHook.
@Test
public void testAppendHook() throws IOException {
final TableName tableName = TableName.valueOf(TEST_TABLE.getNameAsString() + "." + name.getMethodName());
Table table = util.createTable(tableName, new byte[][] { A, B, C });
try {
Append app = new Append(Bytes.toBytes(0));
app.addColumn(A, A, A);
verifyMethodResult(SimpleRegionObserver.class, new String[] { "hadPreAppend", "hadPostAppend", "hadPreAppendAfterRowLock", "hadPreBatchMutate", "hadPostBatchMutate", "hadPostBatchMutateIndispensably" }, tableName, new Boolean[] { false, false, false, false, false, false });
table.append(app);
verifyMethodResult(SimpleRegionObserver.class, new String[] { "hadPreAppend", "hadPostAppend", "hadPreAppendAfterRowLock", "hadPreBatchMutate", "hadPostBatchMutate", "hadPostBatchMutateIndispensably" }, tableName, new Boolean[] { true, true, true, true, true, true });
} finally {
util.deleteTable(tableName);
table.close();
}
}
use of org.apache.hadoop.hbase.client.Append in project hbase by apache.
the class TestHRegion method testCheckAndRowMutations.
@Test
public void testCheckAndRowMutations() throws Throwable {
final byte[] row = Bytes.toBytes("row");
final byte[] q1 = Bytes.toBytes("q1");
final byte[] q2 = Bytes.toBytes("q2");
final byte[] q3 = Bytes.toBytes("q3");
final byte[] q4 = Bytes.toBytes("q4");
final String v1 = "v1";
region = initHRegion(tableName, method, CONF, fam1);
// Initial values
region.batchMutate(new Mutation[] { new Put(row).addColumn(fam1, q2, Bytes.toBytes("toBeDeleted")), new Put(row).addColumn(fam1, q3, Bytes.toBytes(5L)), new Put(row).addColumn(fam1, q4, Bytes.toBytes("a")) });
// Do CheckAndRowMutations
CheckAndMutate checkAndMutate = CheckAndMutate.newBuilder(row).ifNotExists(fam1, q1).build(new RowMutations(row).add(Arrays.asList(new Put(row).addColumn(fam1, q1, Bytes.toBytes(v1)), new Delete(row).addColumns(fam1, q2), new Increment(row).addColumn(fam1, q3, 1), new Append(row).addColumn(fam1, q4, Bytes.toBytes("b")))));
CheckAndMutateResult result = region.checkAndMutate(checkAndMutate);
assertTrue(result.isSuccess());
assertEquals(6L, Bytes.toLong(result.getResult().getValue(fam1, q3)));
assertEquals("ab", Bytes.toString(result.getResult().getValue(fam1, q4)));
// Verify the value
Result r = region.get(new Get(row));
assertEquals(v1, Bytes.toString(r.getValue(fam1, q1)));
assertNull(r.getValue(fam1, q2));
assertEquals(6L, Bytes.toLong(r.getValue(fam1, q3)));
assertEquals("ab", Bytes.toString(r.getValue(fam1, q4)));
// Do CheckAndRowMutations again
checkAndMutate = CheckAndMutate.newBuilder(row).ifNotExists(fam1, q1).build(new RowMutations(row).add(Arrays.asList(new Delete(row).addColumns(fam1, q1), new Put(row).addColumn(fam1, q2, Bytes.toBytes(v1)), new Increment(row).addColumn(fam1, q3, 1), new Append(row).addColumn(fam1, q4, Bytes.toBytes("b")))));
result = region.checkAndMutate(checkAndMutate);
assertFalse(result.isSuccess());
assertNull(result.getResult());
// Verify the value
r = region.get(new Get(row));
assertEquals(v1, Bytes.toString(r.getValue(fam1, q1)));
assertNull(r.getValue(fam1, q2));
assertEquals(6L, Bytes.toLong(r.getValue(fam1, q3)));
assertEquals("ab", Bytes.toString(r.getValue(fam1, q4)));
}
use of org.apache.hadoop.hbase.client.Append in project hbase by apache.
the class TestSpaceQuotaBasicFunctioning method testNoInsertsWithAppend.
@Test
public void testNoInsertsWithAppend() throws Exception {
Append a = new Append(Bytes.toBytes("to_reject"));
a.addColumn(Bytes.toBytes(SpaceQuotaHelperForTests.F1), Bytes.toBytes("to"), Bytes.toBytes("reject"));
helper.writeUntilViolationAndVerifyViolation(SpaceViolationPolicy.NO_INSERTS, a);
}
use of org.apache.hadoop.hbase.client.Append in project hbase by apache.
the class RSRpcServices method append.
/**
* Execute an append mutation.
*
* @param region
* @param m
* @param cellScanner
* @return result to return to client if default operation should be
* bypassed as indicated by RegionObserver, null otherwise
* @throws IOException
*/
private Result append(final Region region, final OperationQuota quota, final MutationProto mutation, final CellScanner cellScanner, long nonceGroup) throws IOException {
long before = EnvironmentEdgeManager.currentTime();
Append append = ProtobufUtil.toAppend(mutation, cellScanner);
quota.addMutation(append);
Result r = null;
if (region.getCoprocessorHost() != null) {
r = region.getCoprocessorHost().preAppend(append);
}
if (r == null) {
boolean canProceed = startNonceOperation(mutation, nonceGroup);
boolean success = false;
try {
long nonce = mutation.hasNonce() ? mutation.getNonce() : HConstants.NO_NONCE;
if (canProceed) {
r = region.append(append, nonceGroup, nonce);
} else {
// convert duplicate append to get
List<Cell> results = region.get(ProtobufUtil.toGet(mutation, cellScanner), false, nonceGroup, nonce);
r = Result.create(results);
}
success = true;
} finally {
if (canProceed) {
endNonceOperation(mutation, nonceGroup, success);
}
}
if (region.getCoprocessorHost() != null) {
region.getCoprocessorHost().postAppend(append, r);
}
}
if (regionServer.metricsRegionServer != null) {
regionServer.metricsRegionServer.updateAppend(EnvironmentEdgeManager.currentTime() - before);
}
return r;
}
Aggregations