Search in sources :

Example 1 with ExtendedCellBuilder

use of org.apache.hadoop.hbase.ExtendedCellBuilder in project hbase by apache.

the class TestProtobufUtil method getCellWithTags.

private Cell getCellWithTags() {
    Tag tag = new ArrayBackedTag(TAG_TYPE, TAG_STR);
    ExtendedCellBuilder cellBuilder = ExtendedCellBuilderFactory.create(CellBuilderType.DEEP_COPY);
    cellBuilder.setRow(Bytes.toBytes("row1"));
    cellBuilder.setFamily(Bytes.toBytes("f1"));
    cellBuilder.setQualifier(Bytes.toBytes("q1"));
    cellBuilder.setValue(Bytes.toBytes("value1"));
    cellBuilder.setType(Cell.Type.Delete);
    cellBuilder.setTags(Collections.singletonList(tag));
    return cellBuilder.build();
}
Also used : ExtendedCellBuilder(org.apache.hadoop.hbase.ExtendedCellBuilder) ArrayBackedTag(org.apache.hadoop.hbase.ArrayBackedTag) Tag(org.apache.hadoop.hbase.Tag) ArrayBackedTag(org.apache.hadoop.hbase.ArrayBackedTag)

Example 2 with ExtendedCellBuilder

use of org.apache.hadoop.hbase.ExtendedCellBuilder in project hbase by apache.

the class ProtobufUtil method toResult.

/**
 * Convert a protocol buffer Result to a client Result
 *
 * @param proto the protocol buffer Result to convert
 * @param decodeTags whether to decode tags into converted client Result
 *                   When @decodeTags is set to true, it will decode all the tags from the
 *                   response. These tags may contain some sensitive data like acl permissions,
 *                   etc. Only the tools like Export, Import which needs to take backup needs to
 *                   set it to true so that cell tags are persisted in backup.
 *                   Refer to HBASE-25246 for more context.
 * @return the converted client Result
 */
public static Result toResult(final ClientProtos.Result proto, boolean decodeTags) {
    if (proto.hasExists()) {
        if (proto.getStale()) {
            return proto.getExists() ? EMPTY_RESULT_EXISTS_TRUE_STALE : EMPTY_RESULT_EXISTS_FALSE_STALE;
        }
        return proto.getExists() ? EMPTY_RESULT_EXISTS_TRUE : EMPTY_RESULT_EXISTS_FALSE;
    }
    List<CellProtos.Cell> values = proto.getCellList();
    if (values.isEmpty()) {
        return proto.getStale() ? EMPTY_RESULT_STALE : EMPTY_RESULT;
    }
    List<Cell> cells = new ArrayList<>(values.size());
    ExtendedCellBuilder builder = ExtendedCellBuilderFactory.create(CellBuilderType.SHALLOW_COPY);
    for (CellProtos.Cell c : values) {
        cells.add(toCell(builder, c, decodeTags));
    }
    return Result.create(cells, null, proto.getStale(), proto.getPartial());
}
Also used : ExtendedCellBuilder(org.apache.hadoop.hbase.ExtendedCellBuilder) ArrayList(java.util.ArrayList) CellProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.CellProtos) Cell(org.apache.hadoop.hbase.Cell) ByteBufferExtendedCell(org.apache.hadoop.hbase.ByteBufferExtendedCell)

Example 3 with ExtendedCellBuilder

use of org.apache.hadoop.hbase.ExtendedCellBuilder in project hbase by apache.

the class ThriftUtilities method resultFromThrift.

public static Result resultFromThrift(TResult in) {
    if (in == null) {
        return null;
    }
    if (!in.isSetColumnValues() || in.getColumnValues().isEmpty()) {
        return in.isStale() ? EMPTY_RESULT_STALE : EMPTY_RESULT;
    }
    List<Cell> cells = new ArrayList<>(in.getColumnValues().size());
    ExtendedCellBuilder builder = ExtendedCellBuilderFactory.create(CellBuilderType.SHALLOW_COPY);
    for (TColumnValue columnValue : in.getColumnValues()) {
        cells.add(toCell(builder, in.getRow(), columnValue));
    }
    return Result.create(cells, null, in.isStale(), in.isPartial());
}
Also used : ExtendedCellBuilder(org.apache.hadoop.hbase.ExtendedCellBuilder) ArrayList(java.util.ArrayList) TColumnValue(org.apache.hadoop.hbase.thrift2.generated.TColumnValue) Cell(org.apache.hadoop.hbase.Cell)

Example 4 with ExtendedCellBuilder

use of org.apache.hadoop.hbase.ExtendedCellBuilder in project hbase by apache.

the class DefaultVisibilityLabelServiceImpl method setAuths.

@Override
public OperationStatus[] setAuths(byte[] user, List<byte[]> authLabels) throws IOException {
    assert labelsRegion != null;
    OperationStatus[] finalOpStatus = new OperationStatus[authLabels.size()];
    List<Mutation> puts = new ArrayList<>(authLabels.size());
    int i = 0;
    ExtendedCellBuilder builder = ExtendedCellBuilderFactory.create(CellBuilderType.SHALLOW_COPY);
    for (byte[] auth : authLabels) {
        String authStr = Bytes.toString(auth);
        int labelOrdinal = this.labelsCache.getLabelOrdinal(authStr);
        if (labelOrdinal == 0) {
            // This label is not yet added. 1st this should be added to the system
            finalOpStatus[i] = new OperationStatus(OperationStatusCode.FAILURE, new InvalidLabelException("Label '" + authStr + "' doesn't exists"));
        } else {
            byte[] row = Bytes.toBytes(labelOrdinal);
            Put p = new Put(row);
            p.add(builder.clear().setRow(row).setFamily(LABELS_TABLE_FAMILY).setQualifier(user).setTimestamp(p.getTimestamp()).setType(Cell.Type.Put).setValue(DUMMY_VALUE).setTags(TagUtil.fromList(Arrays.asList(LABELS_TABLE_TAGS))).build());
            puts.add(p);
        }
        i++;
    }
    if (mutateLabelsRegion(puts, finalOpStatus)) {
        updateZk(false);
    }
    return finalOpStatus;
}
Also used : ExtendedCellBuilder(org.apache.hadoop.hbase.ExtendedCellBuilder) OperationStatus(org.apache.hadoop.hbase.regionserver.OperationStatus) ArrayList(java.util.ArrayList) Mutation(org.apache.hadoop.hbase.client.Mutation) Put(org.apache.hadoop.hbase.client.Put)

Example 5 with ExtendedCellBuilder

use of org.apache.hadoop.hbase.ExtendedCellBuilder in project hbase by apache.

the class DefaultVisibilityLabelServiceImpl method addLabels.

@Override
public OperationStatus[] addLabels(List<byte[]> labels) throws IOException {
    assert labelsRegion != null;
    OperationStatus[] finalOpStatus = new OperationStatus[labels.size()];
    List<Mutation> puts = new ArrayList<>(labels.size());
    int i = 0;
    ExtendedCellBuilder builder = ExtendedCellBuilderFactory.create(CellBuilderType.SHALLOW_COPY);
    for (byte[] label : labels) {
        String labelStr = Bytes.toString(label);
        if (this.labelsCache.getLabelOrdinal(labelStr) > 0) {
            finalOpStatus[i] = new OperationStatus(OperationStatusCode.FAILURE, new LabelAlreadyExistsException("Label '" + labelStr + "' already exists"));
        } else {
            byte[] row = Bytes.toBytes(ordinalCounter.get());
            Put p = new Put(row);
            p.add(builder.clear().setRow(row).setFamily(LABELS_TABLE_FAMILY).setQualifier(LABEL_QUALIFIER).setTimestamp(p.getTimestamp()).setType(Type.Put).setValue(label).setTags(TagUtil.fromList(Arrays.asList(LABELS_TABLE_TAGS))).build());
            if (LOG.isDebugEnabled()) {
                LOG.debug("Adding the label " + labelStr);
            }
            puts.add(p);
            ordinalCounter.incrementAndGet();
        }
        i++;
    }
    if (mutateLabelsRegion(puts, finalOpStatus)) {
        updateZk(true);
    }
    return finalOpStatus;
}
Also used : ExtendedCellBuilder(org.apache.hadoop.hbase.ExtendedCellBuilder) OperationStatus(org.apache.hadoop.hbase.regionserver.OperationStatus) ArrayList(java.util.ArrayList) Mutation(org.apache.hadoop.hbase.client.Mutation) Put(org.apache.hadoop.hbase.client.Put)

Aggregations

ExtendedCellBuilder (org.apache.hadoop.hbase.ExtendedCellBuilder)7 ArrayList (java.util.ArrayList)5 Cell (org.apache.hadoop.hbase.Cell)4 ByteBufferExtendedCell (org.apache.hadoop.hbase.ByteBufferExtendedCell)3 Put (org.apache.hadoop.hbase.client.Put)3 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)2 Mutation (org.apache.hadoop.hbase.client.Mutation)2 OperationStatus (org.apache.hadoop.hbase.regionserver.OperationStatus)2 CellProtos (org.apache.hadoop.hbase.shaded.protobuf.generated.CellProtos)2 IOException (java.io.IOException)1 ArrayBackedTag (org.apache.hadoop.hbase.ArrayBackedTag)1 HBaseIOException (org.apache.hadoop.hbase.HBaseIOException)1 Tag (org.apache.hadoop.hbase.Tag)1 ColumnValue (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutationProto.ColumnValue)1 QualifierValue (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutationProto.ColumnValue.QualifierValue)1 MutationType (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutationProto.MutationType)1 NameBytesPair (org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.NameBytesPair)1 TColumnValue (org.apache.hadoop.hbase.thrift2.generated.TColumnValue)1