Java Code Examples for org.apache.hadoop.hbase.regionserver.MiniBatchOperationInProgress#getOperationStatus()

The following examples show how to use org.apache.hadoop.hbase.regionserver.MiniBatchOperationInProgress#getOperationStatus() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IndexRegionObserver.java    From phoenix with Apache License 2.0 6 votes vote down vote up
private Collection<? extends Mutation> groupMutations(MiniBatchOperationInProgress<Mutation> miniBatchOp,
                                                      BatchMutateContext context) throws IOException {
    context.multiMutationMap = new HashMap<>();
    for (int i = 0; i < miniBatchOp.size(); i++) {
        Mutation m = miniBatchOp.getOperation(i);
        // skip this mutation if we aren't enabling indexing
        // unfortunately, we really should ask if the raw mutation (rather than the combined mutation)
        // should be indexed, which means we need to expose another method on the builder. Such is the
        // way optimization go though.
        if (miniBatchOp.getOperationStatus(i) != IGNORE && this.builder.isEnabled(m)) {
            ImmutableBytesPtr row = new ImmutableBytesPtr(m.getRow());
            MultiMutation stored = context.multiMutationMap.get(row);
            if (stored == null) {
                // we haven't seen this row before, so add it
                stored = new MultiMutation(row);
                context.multiMutationMap.put(row, stored);
            }
            stored.addAll(m);
        }
    }
    return context.multiMutationMap.values();
}
 
Example 2
Source File: IndexRegionObserver.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private void populateRowsToLock(MiniBatchOperationInProgress<Mutation> miniBatchOp, BatchMutateContext context) {
    for (int i = 0; i < miniBatchOp.size(); i++) {
        if (miniBatchOp.getOperationStatus(i) == IGNORE) {
            continue;
        }
        Mutation m = miniBatchOp.getOperation(i);
        if (this.builder.isEnabled(m)) {
            ImmutableBytesPtr row = new ImmutableBytesPtr(m.getRow());
            if (!context.rowsToLock.contains(row)) {
                context.rowsToLock.add(row);
            }
        }
    }
}
 
Example 3
Source File: IndexRegionObserver.java    From phoenix with Apache License 2.0 5 votes vote down vote up
/**
 * This method applies the pending put mutations on the the next row states.
 * Before this method is called, the next row states is set to current row states.
 */
private void applyPendingPutMutations(MiniBatchOperationInProgress<Mutation> miniBatchOp,
                                      BatchMutateContext context, long now) throws IOException {
    for (Integer i = 0; i < miniBatchOp.size(); i++) {
        if (miniBatchOp.getOperationStatus(i) == IGNORE) {
            continue;
        }
        Mutation m = miniBatchOp.getOperation(i);
        // skip this mutation if we aren't enabling indexing
        if (!this.builder.isEnabled(m)) {
            continue;
        }
        // Unless we're replaying edits to rebuild the index, we update the time stamp
        // of the data table to prevent overlapping time stamps (which prevents index
        // inconsistencies as this case isn't handled correctly currently).
        setTimestamp(m, now);
        if (m instanceof Put) {
            ImmutableBytesPtr rowKeyPtr = new ImmutableBytesPtr(m.getRow());
            Pair<Put, Put> dataRowState = context.dataRowStates.get(rowKeyPtr);
            if (dataRowState == null) {
                dataRowState = new Pair<Put, Put>(null, null);
                context.dataRowStates.put(rowKeyPtr, dataRowState);
            }
            Put nextDataRowState = dataRowState.getSecond();
            dataRowState.setSecond((nextDataRowState != null) ? applyNew((Put) m, nextDataRowState) : new Put((Put) m));
        }
    }
}
 
Example 4
Source File: IndexRegionObserver.java    From phoenix with Apache License 2.0 4 votes vote down vote up
/**
 * This method applies pending delete mutations on the next row states
 */
private void applyPendingDeleteMutations(MiniBatchOperationInProgress<Mutation> miniBatchOp,
                                         BatchMutateContext context) throws IOException {
    for (int i = 0; i < miniBatchOp.size(); i++) {
        if (miniBatchOp.getOperationStatus(i) == IGNORE) {
            continue;
        }
        Mutation m = miniBatchOp.getOperation(i);
        if (!this.builder.isEnabled(m)) {
            continue;
        }
        if (!(m instanceof Delete)) {
            continue;
        }
        ImmutableBytesPtr rowKeyPtr = new ImmutableBytesPtr(m.getRow());
        Pair<Put, Put> dataRowState = context.dataRowStates.get(rowKeyPtr);
        if (dataRowState == null) {
            dataRowState = new Pair<Put, Put>(null, null);
            context.dataRowStates.put(rowKeyPtr, dataRowState);
        }
        Put nextDataRowState = dataRowState.getSecond();
        if (nextDataRowState == null) {
            if (dataRowState.getFirst() == null) {
                // This is a delete row mutation on a non-existing row. There is no need to apply this mutation
                // on the data table
                miniBatchOp.setOperationStatus(i, NOWRITE);
            }
            continue;
        }
        for (List<Cell> cells : m.getFamilyCellMap().values()) {
            for (Cell cell : cells) {
                switch (KeyValue.Type.codeToType(cell.getTypeByte())) {
                    case DeleteFamily:
                    case DeleteFamilyVersion:
                        nextDataRowState.getFamilyCellMap().remove(CellUtil.cloneFamily(cell));
                        break;
                    case DeleteColumn:
                    case Delete:
                        removeColumn(nextDataRowState, cell);
                }
            }
        }
        if (nextDataRowState != null && nextDataRowState.getFamilyCellMap().size() == 0) {
            dataRowState.setSecond(null);
        }
    }
}