Search in sources :

Example 21 with Append

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);
        }
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) Table(org.apache.hadoop.hbase.client.Table) Append(org.apache.hadoop.hbase.client.Append) Increment(org.apache.hadoop.hbase.client.Increment) NoSuchColumnFamilyException(org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException) NoSuchColumnFamilyException(org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException) Test(org.junit.Test)

Example 22 with Append

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();
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) Table(org.apache.hadoop.hbase.client.Table) Append(org.apache.hadoop.hbase.client.Append) Test(org.junit.Test)

Example 23 with Append

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)));
}
Also used : Delete(org.apache.hadoop.hbase.client.Delete) Append(org.apache.hadoop.hbase.client.Append) CheckAndMutateResult(org.apache.hadoop.hbase.client.CheckAndMutateResult) Increment(org.apache.hadoop.hbase.client.Increment) Get(org.apache.hadoop.hbase.client.Get) CheckAndMutate(org.apache.hadoop.hbase.client.CheckAndMutate) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ByteString(org.apache.hbase.thirdparty.com.google.protobuf.ByteString) Put(org.apache.hadoop.hbase.client.Put) RowMutations(org.apache.hadoop.hbase.client.RowMutations) CheckAndMutateResult(org.apache.hadoop.hbase.client.CheckAndMutateResult) Result(org.apache.hadoop.hbase.client.Result) Test(org.junit.Test)

Example 24 with Append

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);
}
Also used : Append(org.apache.hadoop.hbase.client.Append) Test(org.junit.Test)

Example 25 with Append

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;
}
Also used : Append(org.apache.hadoop.hbase.client.Append) Cell(org.apache.hadoop.hbase.Cell) ByteBufferCell(org.apache.hadoop.hbase.ByteBufferCell) RegionActionResult(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.RegionActionResult) Result(org.apache.hadoop.hbase.client.Result)

Aggregations

Append (org.apache.hadoop.hbase.client.Append)62 Test (org.junit.Test)31 Result (org.apache.hadoop.hbase.client.Result)26 Increment (org.apache.hadoop.hbase.client.Increment)25 Put (org.apache.hadoop.hbase.client.Put)23 IOException (java.io.IOException)17 Get (org.apache.hadoop.hbase.client.Get)17 Delete (org.apache.hadoop.hbase.client.Delete)16 Table (org.apache.hadoop.hbase.client.Table)15 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)10 TableName (org.apache.hadoop.hbase.TableName)10 RowMutations (org.apache.hadoop.hbase.client.RowMutations)10 Cell (org.apache.hadoop.hbase.Cell)9 CheckAndMutateResult (org.apache.hadoop.hbase.client.CheckAndMutateResult)8 Mutation (org.apache.hadoop.hbase.client.Mutation)7 ArrayList (java.util.ArrayList)5 CheckAndMutate (org.apache.hadoop.hbase.client.CheckAndMutate)5 MutationProto (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutationProto)5 ByteString (org.apache.hbase.thirdparty.com.google.protobuf.ByteString)5 List (java.util.List)4