Search in sources :

Example 1 with MutationType

use of org.apache.hadoop.hbase.coprocessor.RegionObserver.MutationType in project hbase by apache.

the class HRegion method reckonDeltasByStore.

/**
   * Reckon the Cells to apply to WAL, memstore, and to return to the Client in passed
   * column family/Store.
   *
   * Does Get of current value and then adds passed in deltas for this Store returning the result.
   *
   * @param op Whether Increment or Append
   * @param mutation The encompassing Mutation object
   * @param deltas Changes to apply to this Store; either increment amount or data to append
   * @param results In here we accumulate all the Cells we are to return to the client; this List
   *  can be larger than what we return in case where delta is zero; i.e. don't write
   *  out new values, just return current value. If null, client doesn't want results returned.
   * @return Resulting Cells after <code>deltas</code> have been applied to current
   *  values. Side effect is our filling out of the <code>results</code> List.
   */
private List<Cell> reckonDeltasByStore(final Store store, final Operation op, final Mutation mutation, final Durability effectiveDurability, final long now, final List<Cell> deltas, final List<Cell> results) throws IOException {
    byte[] columnFamily = store.getFamily().getName();
    List<Cell> toApply = new ArrayList<>(deltas.size());
    // Get previous values for all columns in this family.
    List<Cell> currentValues = get(mutation, store, deltas, null, /*Default IsolationLevel*/
    op == Operation.INCREMENT ? ((Increment) mutation).getTimeRange() : null);
    // Iterate the input columns and update existing values if they were found, otherwise
    // add new column initialized to the delta amount
    int currentValuesIndex = 0;
    for (int i = 0; i < deltas.size(); i++) {
        Cell delta = deltas.get(i);
        Cell currentValue = null;
        boolean firstWrite = false;
        if (currentValuesIndex < currentValues.size() && CellUtil.matchingQualifier(currentValues.get(currentValuesIndex), delta)) {
            currentValue = currentValues.get(currentValuesIndex);
            if (i < (deltas.size() - 1) && !CellUtil.matchingQualifier(delta, deltas.get(i + 1))) {
                currentValuesIndex++;
            }
        } else {
            firstWrite = true;
        }
        // Switch on whether this an increment or an append building the new Cell to apply.
        Cell newCell = null;
        MutationType mutationType = null;
        boolean apply = true;
        switch(op) {
            case INCREMENT:
                mutationType = MutationType.INCREMENT;
                // If delta amount to apply is 0, don't write WAL or MemStore.
                long deltaAmount = getLongValue(delta);
                apply = deltaAmount != 0;
                newCell = reckonIncrement(delta, deltaAmount, currentValue, columnFamily, now, (Increment) mutation);
                break;
            case APPEND:
                mutationType = MutationType.APPEND;
                // Always apply Append. TODO: Does empty delta value mean reset Cell? It seems to.
                newCell = reckonAppend(delta, currentValue, now, (Append) mutation);
                break;
            default:
                throw new UnsupportedOperationException(op.toString());
        }
        // Give coprocessors a chance to update the new cell
        if (coprocessorHost != null) {
            newCell = coprocessorHost.postMutationBeforeWAL(mutationType, mutation, currentValue, newCell);
        }
        // If apply, we need to update memstore/WAL with new value; add it toApply.
        if (apply || firstWrite) {
            toApply.add(newCell);
        }
        // Add to results to get returned to the Client. If null, cilent does not want results.
        if (results != null) {
            results.add(newCell);
        }
    }
    return toApply;
}
Also used : MutationType(org.apache.hadoop.hbase.coprocessor.RegionObserver.MutationType) Append(org.apache.hadoop.hbase.client.Append) Increment(org.apache.hadoop.hbase.client.Increment) ArrayList(java.util.ArrayList) Cell(org.apache.hadoop.hbase.Cell)

Aggregations

ArrayList (java.util.ArrayList)1 Cell (org.apache.hadoop.hbase.Cell)1 Append (org.apache.hadoop.hbase.client.Append)1 Increment (org.apache.hadoop.hbase.client.Increment)1 MutationType (org.apache.hadoop.hbase.coprocessor.RegionObserver.MutationType)1