Search in sources :

Example 36 with Cell

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

the class ProtobufStreamingUtil method createModelFromResults.

private CellSetModel createModelFromResults(Result[] results) {
    CellSetModel cellSetModel = new CellSetModel();
    for (Result rs : results) {
        byte[] rowKey = rs.getRow();
        RowModel rModel = new RowModel(rowKey);
        List<Cell> kvs = rs.listCells();
        for (Cell kv : kvs) {
            rModel.addCell(new CellModel(CellUtil.cloneFamily(kv), CellUtil.cloneQualifier(kv), kv.getTimestamp(), CellUtil.cloneValue(kv)));
        }
        cellSetModel.addRow(rModel);
    }
    return cellSetModel;
}
Also used : CellSetModel(org.apache.hadoop.hbase.rest.model.CellSetModel) RowModel(org.apache.hadoop.hbase.rest.model.RowModel) CellModel(org.apache.hadoop.hbase.rest.model.CellModel) Cell(org.apache.hadoop.hbase.Cell) Result(org.apache.hadoop.hbase.client.Result)

Example 37 with Cell

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

the class AbstractMemStore method add.

@Override
public void add(Cell cell, MemstoreSize memstoreSize) {
    Cell toAdd = maybeCloneWithAllocator(cell);
    boolean mslabUsed = (toAdd != cell);
    // 3. When cells are from Append/Increment operation.
    if (!mslabUsed) {
        toAdd = deepCopyIfNeeded(toAdd);
    }
    internalAdd(toAdd, mslabUsed, memstoreSize);
}
Also used : ExtendedCell(org.apache.hadoop.hbase.ExtendedCell) Cell(org.apache.hadoop.hbase.Cell)

Example 38 with Cell

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

the class DefaultVisibilityLabelServiceImpl method extractLabelsAndAuths.

protected Pair<Map<String, Integer>, Map<String, List<Integer>>> extractLabelsAndAuths(List<List<Cell>> labelDetails) {
    Map<String, Integer> labels = new HashMap<>();
    Map<String, List<Integer>> userAuths = new HashMap<>();
    for (List<Cell> cells : labelDetails) {
        for (Cell cell : cells) {
            if (CellUtil.matchingQualifier(cell, LABEL_QUALIFIER)) {
                labels.put(Bytes.toString(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()), CellUtil.getRowAsInt(cell));
            } else {
                // These are user cells who has authorization for this label
                String user = Bytes.toString(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength());
                List<Integer> auths = userAuths.get(user);
                if (auths == null) {
                    auths = new ArrayList<>();
                    userAuths.put(user, auths);
                }
                auths.add(CellUtil.getRowAsInt(cell));
            }
        }
    }
    return new Pair<>(labels, userAuths);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) Cell(org.apache.hadoop.hbase.Cell) Pair(org.apache.hadoop.hbase.util.Pair)

Example 39 with Cell

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

the class VisibilityController method prePrepareTimeStampForDeleteVersion.

@Override
public void prePrepareTimeStampForDeleteVersion(ObserverContext<RegionCoprocessorEnvironment> ctx, Mutation delete, Cell cell, byte[] byteNow, Get get) throws IOException {
    // Nothing to do if we are not filtering by visibility
    if (!authorizationEnabled) {
        return;
    }
    CellVisibility cellVisibility = null;
    try {
        cellVisibility = delete.getCellVisibility();
    } catch (DeserializationException de) {
        throw new IOException("Invalid cell visibility specified " + delete, de);
    }
    // The check for checkForReservedVisibilityTagPresence happens in preBatchMutate happens.
    // It happens for every mutation and that would be enough.
    List<Tag> visibilityTags = new ArrayList<>();
    if (cellVisibility != null) {
        String labelsExp = cellVisibility.getExpression();
        try {
            visibilityTags = this.visibilityLabelService.createVisibilityExpTags(labelsExp, false, false);
        } catch (InvalidLabelException e) {
            throw new IOException("Invalid cell visibility specified " + labelsExp, e);
        }
    }
    get.setFilter(new DeleteVersionVisibilityExpressionFilter(visibilityTags, VisibilityConstants.SORTED_ORDINAL_SERIALIZATION_FORMAT));
    List<Cell> result = ctx.getEnvironment().getRegion().get(get, false);
    if (result.size() < get.getMaxVersions()) {
        // Nothing to delete
        CellUtil.updateLatestStamp(cell, byteNow, 0);
        return;
    }
    if (result.size() > get.getMaxVersions()) {
        throw new RuntimeException("Unexpected size: " + result.size() + ". Results more than the max versions obtained.");
    }
    Cell getCell = result.get(get.getMaxVersions() - 1);
    CellUtil.setTimestamp(cell, getCell.getTimestamp());
    // We are bypassing here because in the HRegion.updateDeleteLatestVersionTimeStamp we would
    // update with the current timestamp after again doing a get. As the hook as already determined
    // the needed timestamp we need to bypass here.
    // TODO : See if HRegion.updateDeleteLatestVersionTimeStamp() could be
    // called only if the hook is not called.
    ctx.bypass();
}
Also used : ArrayList(java.util.ArrayList) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException) Tag(org.apache.hadoop.hbase.Tag) ByteString(com.google.protobuf.ByteString) Cell(org.apache.hadoop.hbase.Cell) DeserializationException(org.apache.hadoop.hbase.exceptions.DeserializationException)

Example 40 with Cell

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

the class VisibilityController method postMutationBeforeWAL.

@Override
public Cell postMutationBeforeWAL(ObserverContext<RegionCoprocessorEnvironment> ctx, MutationType opType, Mutation mutation, Cell oldCell, Cell newCell) throws IOException {
    List<Tag> tags = Lists.newArrayList();
    CellVisibility cellVisibility = null;
    try {
        cellVisibility = mutation.getCellVisibility();
    } catch (DeserializationException e) {
        throw new IOException(e);
    }
    if (cellVisibility == null) {
        return newCell;
    }
    // Prepend new visibility tags to a new list of tags for the cell
    // Don't check user auths for labels with Mutations when the user is super user
    boolean authCheck = authorizationEnabled && checkAuths && !(isSystemOrSuperUser());
    tags.addAll(this.visibilityLabelService.createVisibilityExpTags(cellVisibility.getExpression(), true, authCheck));
    // Carry forward all other tags
    Iterator<Tag> tagsItr = CellUtil.tagsIterator(newCell);
    while (tagsItr.hasNext()) {
        Tag tag = tagsItr.next();
        if (tag.getType() != TagType.VISIBILITY_TAG_TYPE && tag.getType() != TagType.VISIBILITY_EXP_SERIALIZATION_FORMAT_TAG_TYPE) {
            tags.add(tag);
        }
    }
    Cell rewriteCell = CellUtil.createCell(newCell, tags);
    return rewriteCell;
}
Also used : Tag(org.apache.hadoop.hbase.Tag) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException) Cell(org.apache.hadoop.hbase.Cell) DeserializationException(org.apache.hadoop.hbase.exceptions.DeserializationException)

Aggregations

Cell (org.apache.hadoop.hbase.Cell)862 Test (org.junit.Test)326 ArrayList (java.util.ArrayList)323 Scan (org.apache.hadoop.hbase.client.Scan)258 KeyValue (org.apache.hadoop.hbase.KeyValue)220 Result (org.apache.hadoop.hbase.client.Result)203 Put (org.apache.hadoop.hbase.client.Put)159 IOException (java.io.IOException)123 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)106 Get (org.apache.hadoop.hbase.client.Get)85 Table (org.apache.hadoop.hbase.client.Table)85 List (java.util.List)80 TableName (org.apache.hadoop.hbase.TableName)77 Delete (org.apache.hadoop.hbase.client.Delete)75 CellScanner (org.apache.hadoop.hbase.CellScanner)69 Configuration (org.apache.hadoop.conf.Configuration)62 InterruptedIOException (java.io.InterruptedIOException)48 Map (java.util.Map)45 Path (org.apache.hadoop.fs.Path)45 RegionScanner (org.apache.hadoop.hbase.regionserver.RegionScanner)45