Search in sources :

Example 6 with Append

use of org.apache.hadoop.hbase.client.Append in project hbase by apache.

the class TestProtobufUtil method testAppendNoTimestamp.

/**
 * Older clients may not send along a timestamp in the MutationProto. Check that we
 * default correctly.
 */
@Test
public void testAppendNoTimestamp() throws IOException {
    MutationProto mutation = getAppendMutation(null);
    Append append = ProtobufUtil.toAppend(mutation, null);
    assertEquals(HConstants.LATEST_TIMESTAMP, append.getTimestamp());
    append.getFamilyCellMap().values().forEach(cells -> cells.forEach(cell -> assertEquals(HConstants.LATEST_TIMESTAMP, cell.getTimestamp())));
}
Also used : Any(org.apache.hbase.thirdparty.com.google.protobuf.Any) Increment(org.apache.hadoop.hbase.client.Increment) TimeRange(org.apache.hadoop.hbase.io.TimeRange) Column(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.Column) ByteBuffer(java.nio.ByteBuffer) ArrayBackedTag(org.apache.hadoop.hbase.ArrayBackedTag) HConstants(org.apache.hadoop.hbase.HConstants) Delete(org.apache.hadoop.hbase.client.Delete) CellComparatorImpl(org.apache.hadoop.hbase.CellComparatorImpl) Tag(org.apache.hadoop.hbase.Tag) DeleteType(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutationProto.DeleteType) ColumnValue(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutationProto.ColumnValue) LockServiceProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.LockServiceProtos) ClassRule(org.junit.ClassRule) ByteBufferKeyValue(org.apache.hadoop.hbase.ByteBufferKeyValue) ExtendedCellBuilderFactory(org.apache.hadoop.hbase.ExtendedCellBuilderFactory) Cell(org.apache.hadoop.hbase.Cell) KeyValue(org.apache.hadoop.hbase.KeyValue) Bytes(org.apache.hadoop.hbase.util.Bytes) NameBytesPair(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.NameBytesPair) Append(org.apache.hadoop.hbase.client.Append) ExtendedCellBuilder(org.apache.hadoop.hbase.ExtendedCellBuilder) CellBuilderType(org.apache.hadoop.hbase.CellBuilderType) Assert.assertNotNull(org.junit.Assert.assertNotNull) Put(org.apache.hadoop.hbase.client.Put) ClientProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos) ProcedureProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.ProcedureProtos) Get(org.apache.hadoop.hbase.client.Get) Assert.assertTrue(org.junit.Assert.assertTrue) HBaseClassTestRule(org.apache.hadoop.hbase.HBaseClassTestRule) IOException(java.io.IOException) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) CellProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.CellProtos) Lists(org.apache.hbase.thirdparty.com.google.common.collect.Lists) List(java.util.List) BytesValue(org.apache.hbase.thirdparty.com.google.protobuf.BytesValue) PrivateCellUtil(org.apache.hadoop.hbase.PrivateCellUtil) SmallTests(org.apache.hadoop.hbase.testclassification.SmallTests) MutationProto(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutationProto) ByteString(org.apache.hbase.thirdparty.com.google.protobuf.ByteString) MutationType(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutationProto.MutationType) Collections(java.util.Collections) QualifierValue(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutationProto.ColumnValue.QualifierValue) Assert.assertEquals(org.junit.Assert.assertEquals) Append(org.apache.hadoop.hbase.client.Append) MutationProto(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutationProto) Test(org.junit.Test)

Example 7 with Append

use of org.apache.hadoop.hbase.client.Append in project hbase by apache.

the class RSRpcServices method append.

/**
 * Execute an append mutation.
 *
 * @return result to return to client if default operation should be
 * bypassed as indicated by RegionObserver, null otherwise
 */
private Result append(final HRegion region, final OperationQuota quota, final MutationProto mutation, final CellScanner cellScanner, long nonceGroup, ActivePolicyEnforcement spaceQuota) throws IOException {
    long before = EnvironmentEdgeManager.currentTime();
    Append append = ProtobufUtil.toAppend(mutation, cellScanner);
    checkCellSizeLimit(region, append);
    spaceQuota.getPolicyEnforcement(region).check(append);
    quota.addMutation(append);
    long nonce = mutation.hasNonce() ? mutation.getNonce() : HConstants.NO_NONCE;
    Result r = region.append(append, nonceGroup, nonce);
    if (server.getMetrics() != null) {
        server.getMetrics().updateAppend(region.getTableDescriptor().getTableName(), EnvironmentEdgeManager.currentTime() - before);
    }
    return r == null ? Result.EMPTY_RESULT : r;
}
Also used : Append(org.apache.hadoop.hbase.client.Append) RegionActionResult(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.RegionActionResult) Result(org.apache.hadoop.hbase.client.Result) CheckAndMutateResult(org.apache.hadoop.hbase.client.CheckAndMutateResult)

Example 8 with Append

use of org.apache.hadoop.hbase.client.Append in project hbase by apache.

the class ProtobufUtil method toAppend.

/**
 * Convert a protocol buffer Mutate to an Append
 * @param cellScanner
 * @param proto the protocol buffer Mutate to convert
 * @return the converted client Append
 * @throws IOException
 */
public static Append toAppend(final MutationProto proto, final CellScanner cellScanner) throws IOException {
    MutationType type = proto.getMutateType();
    assert type == MutationType.APPEND : type.name();
    Append append = toDelta((Bytes row) -> new Append(row.get(), row.getOffset(), row.getLength()), Append::add, proto, cellScanner);
    if (proto.hasTimeRange()) {
        TimeRange timeRange = toTimeRange(proto.getTimeRange());
        append.setTimeRange(timeRange.getMin(), timeRange.getMax());
    }
    return append;
}
Also used : Bytes(org.apache.hadoop.hbase.util.Bytes) TimeRange(org.apache.hadoop.hbase.io.TimeRange) MutationType(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutationProto.MutationType) Append(org.apache.hadoop.hbase.client.Append)

Example 9 with Append

use of org.apache.hadoop.hbase.client.Append in project hbase by apache.

the class ProtobufUtil method toCheckAndMutate.

public static CheckAndMutate toCheckAndMutate(ClientProtos.Condition condition, List<Mutation> mutations) throws IOException {
    assert mutations.size() > 0;
    byte[] row = condition.getRow().toByteArray();
    CheckAndMutate.Builder builder = CheckAndMutate.newBuilder(row);
    Filter filter = condition.hasFilter() ? ProtobufUtil.toFilter(condition.getFilter()) : null;
    if (filter != null) {
        builder.ifMatches(filter);
    } else {
        builder.ifMatches(condition.getFamily().toByteArray(), condition.getQualifier().toByteArray(), CompareOperator.valueOf(condition.getCompareType().name()), ProtobufUtil.toComparator(condition.getComparator()).getValue());
    }
    TimeRange timeRange = condition.hasTimeRange() ? ProtobufUtil.toTimeRange(condition.getTimeRange()) : TimeRange.allTime();
    builder.timeRange(timeRange);
    try {
        if (mutations.size() == 1) {
            Mutation m = mutations.get(0);
            if (m instanceof Put) {
                return builder.build((Put) m);
            } else if (m instanceof Delete) {
                return builder.build((Delete) m);
            } else if (m instanceof Increment) {
                return builder.build((Increment) m);
            } else if (m instanceof Append) {
                return builder.build((Append) m);
            } else {
                throw new DoNotRetryIOException("Unsupported mutate type: " + m.getClass().getSimpleName().toUpperCase());
            }
        } else {
            return builder.build(new RowMutations(mutations.get(0).getRow()).add(mutations));
        }
    } catch (IllegalArgumentException e) {
        throw new DoNotRetryIOException(e.getMessage());
    }
}
Also used : Delete(org.apache.hadoop.hbase.client.Delete) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) CheckAndMutate(org.apache.hadoop.hbase.client.CheckAndMutate) Put(org.apache.hadoop.hbase.client.Put) RowMutations(org.apache.hadoop.hbase.client.RowMutations) TimeRange(org.apache.hadoop.hbase.io.TimeRange) Append(org.apache.hadoop.hbase.client.Append) Filter(org.apache.hadoop.hbase.filter.Filter) Increment(org.apache.hadoop.hbase.client.Increment) Mutation(org.apache.hadoop.hbase.client.Mutation)

Example 10 with Append

use of org.apache.hadoop.hbase.client.Append in project hbase by apache.

the class RequestConverter method buildNoDataRegionAction.

/**
 * @return whether or not the rowMutations has a Increment or Append
 */
private static boolean buildNoDataRegionAction(final RowMutations rowMutations, final List<CellScannable> cells, long nonce, final RegionAction.Builder regionActionBuilder, final ClientProtos.Action.Builder actionBuilder, final MutationProto.Builder mutationBuilder) throws IOException {
    boolean ret = false;
    for (Mutation mutation : rowMutations.getMutations()) {
        mutationBuilder.clear();
        MutationProto mp;
        if (mutation instanceof Increment || mutation instanceof Append) {
            mp = ProtobufUtil.toMutationNoData(getMutationType(mutation), mutation, mutationBuilder, nonce);
            ret = true;
        } else {
            mp = ProtobufUtil.toMutationNoData(getMutationType(mutation), mutation, mutationBuilder);
        }
        cells.add(mutation);
        actionBuilder.clear();
        regionActionBuilder.addAction(actionBuilder.setMutation(mp).build());
    }
    return ret;
}
Also used : Append(org.apache.hadoop.hbase.client.Append) Increment(org.apache.hadoop.hbase.client.Increment) Mutation(org.apache.hadoop.hbase.client.Mutation) MutationProto(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutationProto)

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