org.apache.hadoop.hbase.Cell - java examples

Here are the examples of the java api org.apache.hadoop.hbase.Cell taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

155 Examples 7

19 View Complete Implementation : HFileWriterImpl.java
Copyright Apache License 2.0
Author : apache
private String getLexicalErrorMessage(Cell cell) {
    StringBuilder sb = new StringBuilder();
    sb.append("Added a key not lexically larger than previous. Current cell = ");
    sb.append(cell);
    sb.append(", lastCell = ");
    sb.append(lastCell);
    // file context includes HFile path and optionally table and CF of file being written
    sb.append("fileContext=");
    sb.append(hFileContext);
    return sb.toString();
}

19 View Complete Implementation : CompactionScanQueryMatcher.java
Copyright Apache License 2.0
Author : apache
protected final void trackDelete(Cell cell) {
    // If keepDeletedCells is true, then we only remove cells by versions or TTL during
    // compaction, so we do not need to track delete here.
    // If keepDeletedCells is TTL and the delete marker is expired, then we can make sure that the
    // minVerions is larger than 0(otherwise we will just return at preCheck). So here we still
    // need to track the delete marker to see if it masks some cells.
    if (keepDeletedCells == KeepDeletedCells.FALSE || (keepDeletedCells == KeepDeletedCells.TTL && cell.getTimestamp() < oldestUnexpiredTS)) {
        deletes.add(cell);
    }
}

19 View Complete Implementation : AbstractMemStore.java
Copyright Apache License 2.0
Author : apache
/**
 * If the segment has a memory allocator the cell is being cloned to this space, and returned;
 * Otherwise the given cell is returned
 *
 * When a cell's size is too big (bigger than maxAlloc), it is not allocated on MSLAB.
 * Since the process of flattening to CellChunkMap replacedumes that all cells are allocated on MSLAB,
 * during this process, the input parameter forceCloneOfBigCell is set to 'true'
 * and the cell is copied into MSLAB.
 *
 * @param cell the cell to clone
 * @param forceCloneOfBigCell true only during the process of flattening to CellChunkMap.
 * @return either the given cell or its clone
 */
private Cell maybeCloneWithAllocator(MutableSegment currentActive, Cell cell, boolean forceCloneOfBigCell) {
    return currentActive.maybeCloneWithAllocator(cell, forceCloneOfBigCell);
}

19 View Complete Implementation : Filter.java
Copyright Apache License 2.0
Author : apache
/**
 * Filters a row based on the row key. If this returns true, the entire row will be excluded. If
 * false, each KeyValue in the row will be preplaceded to {@link #filterCell(Cell)} below.
 * If {@link #filterAllRemaining()} returns true, then {@link #filterRowKey(Cell)} should
 * also return true.
 *
 * Concrete implementers can signal a failure condition in their code by throwing an
 * {@link IOException}.
 *
 * @param firstRowCell The first cell coming in the new row
 * @return true, remove entire row, false, include the row (maybe).
 * @throws IOException in case an I/O or an filter specific failure needs to be signaled.
 */
abstract public boolean filterRowKey(Cell firstRowCell) throws IOException;

19 View Complete Implementation : TestMemStoreLAB.java
Copyright Apache License 2.0
Author : apache
private Thread getChunkQueueTestThread(final MemStoreLABImpl mslab, String threadName, Cell cellToCopyInto) {
    Thread thread = new Thread() {

        volatile boolean stopped = false;

        @Override
        public void run() {
            while (!stopped) {
                // keep triggering chunk retirement
                mslab.copyCellInto(cellToCopyInto);
            }
        }

        @Override
        public void interrupt() {
            this.stopped = true;
        }
    };
    thread.setName(threadName);
    thread.setDaemon(true);
    return thread;
}

19 View Complete Implementation : Result.java
Copyright Apache License 2.0
Author : apache
/**
 * Checks if the specified column contains an empty value (a zero-length byte array).
 *
 * @param family family name
 * @param foffset family offset
 * @param flength family length
 * @param qualifier column qualifier
 * @param qoffset qualifier offset
 * @param qlength qualifier length
 *
 * @return whether or not a latest value exists and is empty
 */
public boolean containsEmptyColumn(byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength) {
    Cell kv = getColumnLatestCell(family, foffset, flength, qualifier, qoffset, qlength);
    return (kv != null) && (kv.getValueLength() == 0);
}

19 View Complete Implementation : CellChunkImmutableSegment.java
Copyright Apache License 2.0
Author : apache
private Cell copyCellIntoMSLAB(Cell cell, MemStoreSizing memstoreSizing) {
    // Take care for a special case when a cell is copied from on-heap to (probably off-heap) MSLAB.
    // The cell allocated as an on-heap JVM object (byte array) occupies slightly different
    // amount of memory, than when the cell serialized and allocated on the MSLAB.
    // Here, we update the heap size of the new segment only for the difference between object and
    // serialized size. This is a decrease of the size as serialized cell is a bit smaller.
    // The actual size of the cell is not added yet, and will be added (only in compaction)
    // in initializeCellSet#updateMetaInfo().
    long oldHeapSize = heapSizeChange(cell, true);
    long oldOffHeapSize = offHeapSizeChange(cell, true);
    long oldCellSize = getCellLength(cell);
    cell = maybeCloneWithAllocator(cell, true);
    long newHeapSize = heapSizeChange(cell, true);
    long newOffHeapSize = offHeapSizeChange(cell, true);
    long newCellSize = getCellLength(cell);
    long heapOverhead = newHeapSize - oldHeapSize;
    long offHeapOverhead = newOffHeapSize - oldOffHeapSize;
    incMemStoreSize(newCellSize - oldCellSize, heapOverhead, offHeapOverhead, 0);
    if (memstoreSizing != null) {
        memstoreSizing.incMemStoreSize(newCellSize - oldCellSize, heapOverhead, offHeapOverhead, 0);
    }
    return cell;
}

19 View Complete Implementation : Put.java
Copyright Apache License 2.0
Author : apache
/**
 * Add the specified KeyValue to this Put operation.  Operation replacedumes that
 * the preplaceded KeyValue is immutable and its backing array will not be modified
 * for the duration of this Put.
 * @param cell individual cell
 * @return this
 * @throws java.io.IOException e
 */
public Put add(Cell cell) throws IOException {
    super.add(cell);
    return this;
}

19 View Complete Implementation : Result.java
Copyright Apache License 2.0
Author : apache
/**
 * Get total size of raw cells
 * @param result
 * @return Total size.
 */
public static long getTotalSizeOfCells(Result result) {
    long size = 0;
    if (result.isEmpty()) {
        return size;
    }
    for (Cell c : result.rawCells()) {
        size += c.heapSize();
    }
    return size;
}

19 View Complete Implementation : Result.java
Copyright Apache License 2.0
Author : apache
/**
 * Checks for existence of a value for the specified column (empty or not).
 *
 * @param family family name
 * @param qualifier column qualifier
 *
 * @return true if at least one value exists in the result, false if not
 */
public boolean containsColumn(byte[] family, byte[] qualifier) {
    Cell kv = getColumnLatestCell(family, qualifier);
    return kv != null;
}

19 View Complete Implementation : CellFlatMap.java
Copyright Apache License 2.0
Author : apache
/**
 * Binary search for a given key in between given boundaries of the array.
 * Positive returned numbers mean the index.
 * Negative returned numbers means the key not found.
 *
 * The absolute value of the output is the
 * possible insert index for the searched key
 *
 * In twos-complement, (-1 * insertion point)-1 is the bitwise not of the insert point.
 *
 * @param needle The key to look for in all of the entries
 * @return Same return value as Arrays.binarySearch.
 */
private int find(Cell needle) {
    int begin = minCellIdx;
    int end = maxCellIdx - 1;
    while (begin <= end) {
        int mid = begin + ((end - begin) >> 1);
        Cell midCell = getCell(mid);
        int compareRes = comparator.compare(midCell, needle);
        if (compareRes == 0) {
            // 0 means equals. We found the key
            return mid;
        }
        // Key not found. Check the comparison results; reverse the meaning of
        // the comparison in case the order is descending (using XOR)
        if ((compareRes < 0) ^ descending) {
            // midCell is less than needle so we need to look at farther up
            begin = mid + 1;
        } else {
            // midCell is greater than needle so we need to look down
            end = mid - 1;
        }
    }
    return (-1 * begin) - 1;
}

19 View Complete Implementation : Import.java
Copyright Apache License 2.0
Author : apache
/**
 * Attempt to filter out the keyvalue
 * @param c {@link Cell} on which to apply the filter
 * @return <tt>null</tt> if the key should not be written, otherwise returns the original
 *         {@link Cell}
 */
public static Cell filterKv(Filter filter, Cell c) throws IOException {
    // apply the filter and skip this kv if the filter doesn't apply
    if (filter != null) {
        Filter.ReturnCode code = filter.filterCell(c);
        if (LOG.isTraceEnabled()) {
            LOG.trace("Filter returned:" + code + " for the cell:" + c);
        }
        // if its not an accept type, then skip this kv
        if (!(code.equals(Filter.ReturnCode.INCLUDE) || code.equals(Filter.ReturnCode.INCLUDE_AND_NEXT_COL))) {
            return null;
        }
    }
    return c;
}

19 View Complete Implementation : StoreScanner.java
Copyright Apache License 2.0
Author : apache
/**
 * Seek the specified scanners with the given key
 * @param scanners
 * @param seekKey
 * @param isLazy true if using lazy seek
 * @param isParallelSeek true if using parallel seek
 * @throws IOException
 */
protected void seekScanners(List<? extends KeyValueScanner> scanners, Cell seekKey, boolean isLazy, boolean isParallelSeek) throws IOException {
    // Seek all scanners to the start of the Row (or if the exact matching row
    // key does not exist, then to the start of the next matching Row).
    // Always check bloom filter to optimize the top row seek for delete
    // family marker.
    if (isLazy) {
        for (KeyValueScanner scanner : scanners) {
            scanner.requestSeek(seekKey, false, true);
        }
    } else {
        if (!isParallelSeek) {
            long totalScannersSoughtBytes = 0;
            for (KeyValueScanner scanner : scanners) {
                if (matcher.isUserScan() && totalScannersSoughtBytes >= maxRowSize) {
                    throw new RowTooBigException("Max row size allowed: " + maxRowSize + ", but row is bigger than that");
                }
                scanner.seek(seekKey);
                Cell c = scanner.peek();
                if (c != null) {
                    totalScannersSoughtBytes += PrivateCellUtil.estimatedSerializedSizeOf(c);
                }
            }
        } else {
            parallelSeek(scanners, seekKey);
        }
    }
}

19 View Complete Implementation : AbstractMemStore.java
Copyright Apache License 2.0
Author : apache
private void doAdd(MutableSegment currentActive, Cell cell, MemStoreSizing memstoreSizing) {
    Cell toAdd = maybeCloneWithAllocator(currentActive, cell, false);
    boolean mslabUsed = (toAdd != cell);
    // This cell data is backed by the same byte[] where we read request in RPC(See
    // HBASE-15180). By default MSLAB is ON and we might have copied cell to MSLAB area. If
    // not we must do below deep copy. Or else we will keep referring to the bigger chunk of
    // memory and prevent it from getting GCed.
    // Copy to MSLAB would not have happened if
    // 1. MSLAB is turned OFF. See "hbase.hregion.memstore.mslab.enabled"
    // 2. When the size of the cell is bigger than the max size supported by MSLAB. See
    // "hbase.hregion.memstore.mslab.max.allocation". This defaults to 256 KB
    // 3. When cells are from Append/Increment operation.
    if (!mslabUsed) {
        toAdd = deepCopyIfNeeded(toAdd);
    }
    internalAdd(currentActive, toAdd, mslabUsed, memstoreSizing);
}

19 View Complete Implementation : CodecPerformance.java
Copyright Apache License 2.0
Author : apache
public static void main(String[] args) throws IOException {
    // How many Cells to encode/decode on each cycle.
    final int count = 100000;
    // How many times to do an operation; repeat gives hotspot chance to warm up.
    final int cycles = 30;
    Cell[] cells = getCells(count);
    int size = getRoughSize(cells);
    // Multiply by 2 to ensure we don't have to grow buffer
    int initialBufferSize = 2 * size;
    // Test KeyValue codec.
    doCodec(new KeyValueCodec(), cells, cycles, count, initialBufferSize);
    doCodec(new CellCodec(), cells, cycles, count, initialBufferSize);
    doCodec(new MessageCodec(), cells, cycles, count, initialBufferSize);
}

19 View Complete Implementation : ConnectionUtils.java
Copyright Apache License 2.0
Author : apache
// validate for well-formedness
static void validatePut(Put put, int maxKeyValueSize) throws IllegalArgumentException {
    if (put.isEmpty()) {
        throw new IllegalArgumentException("No columns to insert");
    }
    if (maxKeyValueSize > 0) {
        for (List<Cell> list : put.getFamilyCellMap().values()) {
            for (Cell cell : list) {
                if (cell.getSerializedSize() > maxKeyValueSize) {
                    throw new IllegalArgumentException("KeyValue size too large");
                }
            }
        }
    }
}

19 View Complete Implementation : Filter.java
Copyright Apache License 2.0
Author : apache
/**
 * Give the filter a chance to transform the preplaceded KeyValue. If the Cell is changed a new
 * Cell object must be returned.
 *
 * @see org.apache.hadoop.hbase.KeyValue#shallowCopy()
 *      The transformed KeyValue is what is eventually returned to the client. Most filters will
 *      return the preplaceded KeyValue unchanged.
 * @see org.apache.hadoop.hbase.filter.KeyOnlyFilter#transformCell(Cell) for an example of a
 *      transformation.
 *
 *      Concrete implementers can signal a failure condition in their code by throwing an
 *      {@link IOException}.
 *
 * @param v the KeyValue in question
 * @return the changed KeyValue
 * @throws IOException in case an I/O or an filter specific failure needs to be signaled.
 */
abstract public Cell transformCell(final Cell v) throws IOException;

19 View Complete Implementation : Increment.java
Copyright Apache License 2.0
Author : apache
/**
 * Add the specified KeyValue to this operation.
 * @param cell individual Cell
 * @return this
 * @throws java.io.IOException e
 */
public Increment add(Cell cell) throws IOException {
    super.add(cell);
    return this;
}

19 View Complete Implementation : Mutation.java
Copyright Apache License 2.0
Author : apache
Mutation add(Cell cell) throws IOException {
    // Checking that the row of the kv is the same as the mutation
    // TODO: It is fraught with risk if user preplaced the wrong row.
    // Throwing the IllegalArgumentException is more suitable I'd say.
    if (!CellUtil.matchingRows(cell, this.row)) {
        throw new WrongRowIOException("The row in " + cell.toString() + " doesn't match the original one " + Bytes.toStringBinary(this.row));
    }
    byte[] family;
    if (cell instanceof IndividualBytesFieldCell) {
        family = cell.getFamilyArray();
    } else {
        family = CellUtil.cloneFamily(cell);
    }
    if (family == null || family.length == 0) {
        throw new IllegalArgumentException("Family cannot be null");
    }
    if (cell instanceof ExtendedCell) {
        getCellList(family).add(cell);
    } else {
        getCellList(family).add(new CellWrapper(cell));
    }
    return this;
}

19 View Complete Implementation : NewVersionBehaviorTracker.java
Copyright Apache License 2.0
Author : apache
/**
 * Reset the map if it is different with the last Cell.
 * Save the cq array/offset/length for next Cell.
 *
 * @return If this put has duplicate ts with last cell, return the mvcc of last cell.
 * Else return MAX_VALUE.
 */
protected long prepare(Cell cell) {
    boolean matchCq = PrivateCellUtil.matchingQualifier(cell, lastCqArray, lastCqOffset, lastCqLength);
    if (!matchCq) {
        // The last cell is family-level delete and this is not, or the cq is changed,
        // we should construct delColMap as a deep copy of delFamMap.
        delColMap.clear();
        for (Map.Entry<Long, DeleteVersionsNode> e : delFamMap.entrySet()) {
            delColMap.put(e.getKey(), e.getValue().getDeepCopy());
        }
        countCurrentCol = 0;
    }
    if (matchCq && !PrivateCellUtil.isDelete(lastCqType) && lastCqType == cell.getTypeByte() && lastCqTs == cell.getTimestamp()) {
        // Put with duplicate timestamp, ignore.
        return lastCqMvcc;
    }
    lastCqArray = cell.getQualifierArray();
    lastCqOffset = cell.getQualifierOffset();
    lastCqLength = cell.getQualifierLength();
    lastCqTs = cell.getTimestamp();
    lastCqMvcc = cell.getSequenceId();
    lastCqType = cell.getTypeByte();
    return Long.MAX_VALUE;
}

19 View Complete Implementation : TestMemstoreLABWithoutPool.java
Copyright Apache License 2.0
Author : apache
private Thread getChunkQueueTestThread(final MemStoreLABImpl mslab, String threadName, Cell cellToCopyInto) {
    Thread thread = new Thread() {

        volatile boolean stopped = false;

        @Override
        public void run() {
            while (!stopped) {
                // keep triggering chunk retirement
                mslab.copyCellInto(cellToCopyInto);
            }
        }

        @Override
        public void interrupt() {
            this.stopped = true;
        }
    };
    thread.setName(threadName);
    thread.setDaemon(true);
    return thread;
}

19 View Complete Implementation : RemoteHTable.java
Copyright Apache License 2.0
Author : apache
protected CellSetModel buildModelFromPut(Put put) {
    RowModel row = new RowModel(put.getRow());
    long ts = put.getTimestamp();
    for (List<Cell> cells : put.getFamilyCellMap().values()) {
        for (Cell cell : cells) {
            row.addCell(new CellModel(CellUtil.cloneFamily(cell), CellUtil.cloneQualifier(cell), ts != HConstants.LATEST_TIMESTAMP ? ts : cell.getTimestamp(), CellUtil.cloneValue(cell)));
        }
    }
    CellSetModel model = new CellSetModel();
    model.addRow(row);
    return model;
}

19 View Complete Implementation : Result.java
Copyright Apache License 2.0
Author : apache
/**
 * The Cell for the most recent timestamp for a given column.
 *
 * @param family family name
 * @param foffset family offset
 * @param flength family length
 * @param qualifier column qualifier
 * @param qoffset qualifier offset
 * @param qlength qualifier length
 *
 * @return the Cell for the column, or null if no value exists in the row or none have been
 * selected in the query (Get/Scan)
 */
public Cell getColumnLatestCell(byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength) {
    // side effect possibly.
    Cell[] kvs = rawCells();
    if (kvs == null || kvs.length == 0) {
        return null;
    }
    int pos = binarySearch(kvs, family, foffset, flength, qualifier, qoffset, qlength);
    if (pos == -1) {
        return null;
    }
    if (PrivateCellUtil.matchingColumn(kvs[pos], family, foffset, flength, qualifier, qoffset, qlength)) {
        return kvs[pos];
    }
    return null;
}

19 View Complete Implementation : StoreScanner.java
Copyright Apache License 2.0
Author : apache
private void seekOrSkipToNextRow(Cell cell) throws IOException {
    // If it is a Get Scan, then we know that we are done with this row; there are no more
    // rows beyond the current one: don't try to optimize.
    if (!get) {
        if (trySkipToNextRow(cell)) {
            return;
        }
    }
    seekToNextRow(cell);
}

19 View Complete Implementation : MobUtils.java
Copyright Apache License 2.0
Author : apache
/**
 * Creates a mob reference KeyValue.
 * The value of the mob reference KeyValue is mobCellValueSize + mobFileName.
 * @param cell The original Cell.
 * @param fileName The mob file name where the mob reference KeyValue is written.
 * @param tableNameTag The tag of the current table name. It's very important in
 *                        cloning the snapshot.
 * @return The mob reference KeyValue.
 */
public static Cell createMobRefCell(Cell cell, byte[] fileName, Tag tableNameTag) {
    // Append the tags to the KeyValue.
    // The key is same, the value is the filename of the mob file
    List<Tag> tags = new ArrayList<>();
    // Add the ref tag as the 1st one.
    tags.add(MobConstants.MOB_REF_TAG);
    // Add the tag of the source table name, this table is where this mob file is flushed
    // from.
    // It's very useful in cloning the snapshot. When reading from the cloning table, we need to
    // find the original mob files by this table name. For details please see cloning
    // snapshot for mob files.
    tags.add(tableNameTag);
    return createMobRefCell(cell, fileName, TagUtil.fromList(tags));
}

19 View Complete Implementation : MobUtils.java
Copyright Apache License 2.0
Author : apache
/**
 * Indicates whether the current mob ref cell has a valid value.
 * A mob ref cell has a mob reference tag.
 * The value of a mob ref cell consists of two parts, real mob value length and mob file name.
 * The real mob value length takes 4 bytes.
 * The remaining part is the mob file name.
 * @param cell The mob ref cell.
 * @return True if the cell has a valid value.
 */
public static boolean hasValidMobRefCellValue(Cell cell) {
    return cell.getValueLength() > Bytes.SIZEOF_INT;
}

19 View Complete Implementation : Result.java
Copyright Apache License 2.0
Author : apache
/**
 * Does a deep comparison of two Results, down to the byte arrays.
 * @param res1 first result to compare
 * @param res2 second result to compare
 * @throws Exception Every difference is throwing an exception
 */
public static void compareResults(Result res1, Result res2) throws Exception {
    if (res2 == null) {
        throw new Exception("There wasn't enough rows, we stopped at " + Bytes.toStringBinary(res1.getRow()));
    }
    if (res1.size() != res2.size()) {
        throw new Exception("This row doesn't have the same number of KVs: " + res1.toString() + " compared to " + res2.toString());
    }
    Cell[] ourKVs = res1.rawCells();
    Cell[] replicatedKVs = res2.rawCells();
    for (int i = 0; i < res1.size(); i++) {
        if (!ourKVs[i].equals(replicatedKVs[i]) || !CellUtil.matchingValue(ourKVs[i], replicatedKVs[i])) {
            throw new Exception("This result was different: " + res1.toString() + " compared to " + res2.toString());
        }
    }
}

19 View Complete Implementation : RowIndexEncoderV1.java
Copyright Apache License 2.0
Author : apache
protected boolean checkRow(final Cell cell) throws IOException {
    boolean isDuplicateRow = false;
    if (cell == null) {
        throw new IOException("Key cannot be null or empty");
    }
    if (lastCell != null) {
        int keyComp = this.context.getHFileContext().getCellComparator().compareRows(lastCell, cell);
        if (keyComp > 0) {
            throw new IOException("Added a key not lexically larger than" + " previous. Current cell = " + cell + ", lastCell = " + lastCell);
        } else if (keyComp == 0) {
            isDuplicateRow = true;
        }
    }
    return isDuplicateRow;
}

19 View Complete Implementation : Result.java
Copyright Apache License 2.0
Author : apache
/**
 * The Cell for the most recent timestamp for a given column.
 *
 * @param family
 * @param qualifier
 *
 * @return the Cell for the column, or null if no value exists in the row or none have been
 * selected in the query (Get/Scan)
 */
public Cell getColumnLatestCell(byte[] family, byte[] qualifier) {
    // side effect possibly.
    Cell[] kvs = rawCells();
    if (kvs == null || kvs.length == 0) {
        return null;
    }
    int pos = binarySearch(kvs, family, qualifier);
    if (pos == -1) {
        return null;
    }
    if (CellUtil.matchingColumn(kvs[pos], family, qualifier)) {
        return kvs[pos];
    }
    return null;
}

19 View Complete Implementation : StoreFileWriter.java
Copyright Apache License 2.0
Author : apache
/**
 * Record the earlest Put timestamp.
 *
 * If the timeRangeTracker is not set,
 * update TimeRangeTracker to include the timestamp of this key
 */
public void trackTimestamps(final Cell cell) {
    if (KeyValue.Type.Put.getCode() == cell.getTypeByte()) {
        earliestPutTs = Math.min(earliestPutTs, cell.getTimestamp());
    }
    timeRangeTracker.includeTimestamp(cell);
}

19 View Complete Implementation : Filter.java
Copyright Apache License 2.0
Author : apache
/**
 * If the filter returns the match code SEEK_NEXT_USING_HINT, then it should also tell which is
 * the next key it must seek to. After receiving the match code SEEK_NEXT_USING_HINT, the
 * QueryMatcher would call this function to find out which key it must next seek to.
 *
 * Concrete implementers can signal a failure condition in their code by throwing an
 * {@link IOException}.
 *
 * @return KeyValue which must be next seeked. return null if the filter is not sure which key to
 *         seek to next.
 * @throws IOException in case an I/O or an filter specific failure needs to be signaled.
 */
abstract public Cell getNextCellHint(final Cell currentCell) throws IOException;

19 View Complete Implementation : StripeStoreFileManager.java
Copyright Apache License 2.0
Author : apache
/**
 * See {@link StoreFileManager#getCandidateFilesForRowKeyBefore(KeyValue)} and
 * {@link StoreFileManager#updateCandidateFilesForRowKeyBefore(Iterator, KeyValue, Cell)}
 * for details on this methods.
 */
@Override
public Iterator<HStoreFile> updateCandidateFilesForRowKeyBefore(Iterator<HStoreFile> candidateFiles, final KeyValue targetKey, final Cell candidate) {
    KeyBeforeConcatenatedLists.Iterator original = (KeyBeforeConcatenatedLists.Iterator) candidateFiles;
    replacedert original != null;
    ArrayList<List<HStoreFile>> components = original.getComponents();
    for (int firstIrrelevant = 0; firstIrrelevant < components.size(); ++firstIrrelevant) {
        HStoreFile sf = components.get(firstIrrelevant).get(0);
        byte[] endKey = endOf(sf);
        // Entries are ordered as such: L0, then stripes in reverse order. We never remove
        // level 0; we remove the stripe, and all subsequent ones, as soon as we find the
        // first one that cannot possibly have better candidates.
        if (!isInvalid(endKey) && !isOpen(endKey) && (nonOpenRowCompare(targetKey, endKey) >= 0)) {
            original.removeComponents(firstIrrelevant);
            break;
        }
    }
    return original;
}

19 View Complete Implementation : AbstractMemStore.java
Copyright Apache License 2.0
Author : apache
private void doUpsert(MutableSegment currentActive, Cell cell, long readpoint, MemStoreSizing memstoreSizing) {
    // Add the Cell to the MemStore
    // Use the internalAdd method here since we (a) already have a lock
    // and (b) cannot safely use the MSLAB here without potentially
    // hitting OOME - see TestMemStore.testUpsertMSLAB for a
    // test that triggers the pathological case if we don't avoid MSLAB
    // here.
    // This cell data is backed by the same byte[] where we read request in RPC(See
    // HBASE-15180). We must do below deep copy. Or else we will keep referring to the bigger
    // chunk of memory and prevent it from getting GCed.
    cell = deepCopyIfNeeded(cell);
    boolean sizeAddedPreOperation = sizeAddedPreOperation();
    currentActive.upsert(cell, readpoint, memstoreSizing, sizeAddedPreOperation);
    setOldestEditTimeToNow();
}

19 View Complete Implementation : HFileWriterImpl.java
Copyright Apache License 2.0
Author : apache
/**
 * Checks that the given Cell's key does not violate the key order.
 *
 * @param cell Cell whose key to check.
 * @return true if the key is duplicate
 * @throws IOException if the key or the key order is wrong
 */
protected boolean checkKey(final Cell cell) throws IOException {
    boolean isDuplicateKey = false;
    if (cell == null) {
        throw new IOException("Key cannot be null or empty");
    }
    if (lastCell != null) {
        int keyComp = PrivateCellUtil.compareKeyIgnoresMvcc(this.hFileContext.getCellComparator(), lastCell, cell);
        if (keyComp > 0) {
            String message = getLexicalErrorMessage(cell);
            throw new IOException(message);
        } else if (keyComp == 0) {
            isDuplicateKey = true;
        }
    }
    return isDuplicateKey;
}

19 View Complete Implementation : TestDefaultMemStore.java
Copyright Apache License 2.0
Author : apache
@Test
public void testPutSameKey() {
    byte[] bytes = Bytes.toBytes(getName());
    KeyValue kv = new KeyValue(bytes, bytes, bytes, bytes);
    this.memstore.add(kv, null);
    byte[] other = Bytes.toBytes("somethingelse");
    KeyValue samekey = new KeyValue(bytes, bytes, bytes, other);
    this.memstore.add(samekey, null);
    Cell found = this.memstore.getActive().first();
    replacedertEquals(1, this.memstore.getActive().getCellsCount());
    replacedertTrue(Bytes.toString(found.getValueArray()), CellUtil.matchingValue(samekey, found));
}

19 View Complete Implementation : MobUtils.java
Copyright Apache License 2.0
Author : apache
/**
 * Gets the mob value length from the mob ref cell.
 * A mob ref cell has a mob reference tag.
 * The value of a mob ref cell consists of two parts, real mob value length and mob file name.
 * The real mob value length takes 4 bytes.
 * The remaining part is the mob file name.
 * @param cell The mob ref cell.
 * @return The real mob value length.
 */
public static int getMobValueLength(Cell cell) {
    return PrivateCellUtil.getValueAsInt(cell);
}

19 View Complete Implementation : AbstractMemStore.java
Copyright Apache License 2.0
Author : apache
/*
   * Internal version of add() that doesn't clone Cells with the
   * allocator, and doesn't take the lock.
   *
   * Callers should ensure they already have the read lock taken
   * @param toAdd the cell to add
   * @param mslabUsed whether using MSLAB
   * @param memstoreSizing object to acreplacedulate changed size
   */
private void internalAdd(MutableSegment currentActive, final Cell toAdd, final boolean mslabUsed, MemStoreSizing memstoreSizing) {
    boolean sizeAddedPreOperation = sizeAddedPreOperation();
    currentActive.add(toAdd, mslabUsed, memstoreSizing, sizeAddedPreOperation);
    setOldestEditTimeToNow();
}

19 View Complete Implementation : Import.java
Copyright Apache License 2.0
Author : apache
// helper: create a new KeyValue based on CF rename map
private static Cell convertKv(Cell kv, Map<byte[], byte[]> cfRenameMap) {
    if (cfRenameMap != null) {
        // If there's a rename mapping for this CF, create a new KeyValue
        byte[] newCfName = cfRenameMap.get(CellUtil.cloneFamily(kv));
        if (newCfName != null) {
            kv = new // row buffer
            KeyValue(// row buffer
            kv.getRowArray(), // row offset
            kv.getRowOffset(), // row length
            kv.getRowLength(), // CF buffer
            newCfName, // CF offset
            0, // CF length
            newCfName.length, // qualifier buffer
            kv.getQualifierArray(), // qualifier offset
            kv.getQualifierOffset(), // qualifier length
            kv.getQualifierLength(), // timestamp
            kv.getTimestamp(), // KV Type
            KeyValue.Type.codeToType(kv.getTypeByte()), // value buffer
            kv.getValueArray(), // value offset
            kv.getValueOffset(), // value length
            kv.getValueLength());
        }
    }
    return kv;
}

19 View Complete Implementation : Result.java
Copyright Apache License 2.0
Author : apache
/**
 * Checks if the specified column contains a non-empty value (not a zero-length byte array).
 *
 * @param family family name
 * @param foffset family offset
 * @param flength family length
 * @param qualifier column qualifier
 * @param qoffset qualifier offset
 * @param qlength qualifier length
 *
 * @return whether or not a latest value exists and is not empty
 */
public boolean containsNonEmptyColumn(byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength) {
    Cell kv = getColumnLatestCell(family, foffset, flength, qualifier, qoffset, qlength);
    return (kv != null) && (kv.getValueLength() > 0);
}

19 View Complete Implementation : AbstractMemStore.java
Copyright Apache License 2.0
Author : apache
/*
   * Inserts the specified Cell into MemStore and deletes any existing
   * versions of the same row/family/qualifier as the specified Cell.
   * <p>
   * First, the specified Cell is inserted into the Memstore.
   * <p>
   * If there are any existing Cell in this MemStore with the same row,
   * family, and qualifier, they are removed.
   * <p>
   * Callers must hold the read lock.
   *
   * @param cell the cell to be updated
   * @param readpoint readpoint below which we can safely remove duplicate KVs
   * @param memstoreSizing object to acreplacedulate changed size
   */
private void upsert(Cell cell, long readpoint, MemStoreSizing memstoreSizing) {
    doAddOrUpsert(cell, readpoint, memstoreSizing, false);
}

19 View Complete Implementation : TestDefaultMemStore.java
Copyright Apache License 2.0
Author : apache
private void isExpectedRowWithoutTimestamps(final int rowIndex, List<Cell> kvs) {
    int i = 0;
    for (Cell kv : kvs) {
        byte[] expectedColname = makeQualifier(rowIndex, i++);
        replacedertTrue("Column name", CellUtil.matchingQualifier(kv, expectedColname));
        // Value is column name as bytes.  Usually result is
        // 100 bytes in size at least. This is the default size
        // for BytesWriteable.  For comparison, convert bytes to
        // String and trim to remove trailing null bytes.
        replacedertTrue("Content", CellUtil.matchingValue(kv, expectedColname));
    }
}

19 View Complete Implementation : CellFlatMap.java
Copyright Apache License 2.0
Author : apache
/**
 * Get the index of the given anchor key for creating subsequent set.
 * It doesn't matter whether the given key exists in the set or not.
 * taking into consideration whether
 * the key should be inclusive or exclusive.
 */
private int getValidIndex(Cell key, boolean inclusive, boolean tail) {
    final int index = find(key);
    // get the valid (positive) insertion point from the output of the find() method
    int insertionPoint = index < 0 ? ~index : index;
    // correct the insertion point in case the given anchor key DOES EXIST in the set
    if (index >= 0) {
        if (descending && !(tail ^ inclusive)) {
            // for the descending case
            // if anchor for head set (tail=false) AND anchor is not inclusive -> move the insertion pt
            // if anchor for tail set (tail=true) AND the keys is inclusive -> move the insertion point
            // because the end index of a set is the index of the cell after the maximal cell
            insertionPoint += 1;
        } else if (!descending && (tail ^ inclusive)) {
            // for the ascending case
            // if anchor for head set (tail=false) AND anchor is inclusive -> move the insertion point
            // because the end index of a set is the index of the cell after the maximal cell
            // if anchor for tail set (tail=true) AND the keys is not inclusive -> move the insertion pt
            insertionPoint += 1;
        }
    }
    // insert the insertion point into the valid range,
    // as we may enlarge it too much in the above correction
    return Math.min(Math.max(insertionPoint, minCellIdx), maxCellIdx);
}

19 View Complete Implementation : StoreFileScanner.java
Copyright Apache License 2.0
Author : apache
protected boolean skipKVsNewerThanReadpoint() throws IOException {
    // We want to ignore all key-values that are newer than our current
    // readPoint
    Cell startKV = cur;
    while (enforceMVCC && cur != null && (cur.getSequenceId() > readPt)) {
        boolean hasNext = hfs.next();
        setCurrentCell(hfs.getCell());
        if (hasNext && this.stopSkippingKVsIfNextRow && getComparator().compareRows(cur, startKV) > 0) {
            return false;
        }
    }
    if (cur == null) {
        return false;
    }
    return true;
}

19 View Complete Implementation : HMobStore.java
Copyright Apache License 2.0
Author : apache
/**
 * Reads the cell from the mob file, and the read point does not count. This is used for
 * DefaultMobStoreCompactor where we can read empty value for the missing cell.
 * @param reference The cell found in the HBase, its value is a path to a mob file.
 * @param cacheBlocks Whether the scanner should cache blocks.
 * @return The cell found in the mob file.
 * @throws IOException
 */
public MobCell resolve(Cell reference, boolean cacheBlocks) throws IOException {
    return resolve(reference, cacheBlocks, -1, true);
}

19 View Complete Implementation : Segment.java
Copyright Apache License 2.0
Author : apache
/**
 * If the segment has a memory allocator the cell is being cloned to this space, and returned;
 * otherwise the given cell is returned
 *
 * When a cell's size is too big (bigger than maxAlloc), it is not allocated on MSLAB.
 * Since the process of flattening to CellChunkMap replacedumes that all cells
 * are allocated on MSLAB, during this process, the input parameter
 * forceCloneOfBigCell is set to 'true' and the cell is copied into MSLAB.
 *
 * @return either the given cell or its clone
 */
public Cell maybeCloneWithAllocator(Cell cell, boolean forceCloneOfBigCell) {
    if (this.memStoreLAB == null) {
        return cell;
    }
    Cell cellFromMslab;
    if (forceCloneOfBigCell) {
        cellFromMslab = this.memStoreLAB.forceCopyOfBigCellInto(cell);
    } else {
        cellFromMslab = this.memStoreLAB.copyCellInto(cell);
    }
    return (cellFromMslab != null) ? cellFromMslab : cell;
}

19 View Complete Implementation : ConnectionUtils.java
Copyright Apache License 2.0
Author : apache
static Result filterCells(Result result, Cell keepCellsAfter) {
    if (keepCellsAfter == null) {
        // do not need to filter
        return result;
    }
    // not the same row
    if (!PrivateCellUtil.matchingRows(keepCellsAfter, result.getRow(), 0, result.getRow().length)) {
        return result;
    }
    Cell[] rawCells = result.rawCells();
    int index = Arrays.binarySearch(rawCells, keepCellsAfter, CellComparator.getInstance()::compareWithoutRow);
    if (index < 0) {
        index = -index - 1;
    } else {
        index++;
    }
    if (index == 0) {
        return result;
    }
    if (index == rawCells.length) {
        return null;
    }
    return Result.create(Arrays.copyOfRange(rawCells, index, rawCells.length), null, result.isStale(), result.mayHaveMoreCellsInRow());
}

19 View Complete Implementation : BloomFilterChunk.java
Copyright Apache License 2.0
Author : apache
public void add(Cell cell) {
    /*
     * For faster hashing, use combinatorial generation
     * http://www.eecs.harvard.edu/~kirsch/pubs/bbbf/esa06.pdf
     */
    int hash1;
    int hash2;
    HashKey<Cell> hashKey;
    if (this.bloomType == BloomType.ROWCOL) {
        hashKey = new RowColBloomHashKey(cell);
        hash1 = this.hash.hash(hashKey, 0);
        hash2 = this.hash.hash(hashKey, hash1);
    } else {
        hashKey = new RowBloomHashKey(cell);
        hash1 = this.hash.hash(hashKey, 0);
        hash2 = this.hash.hash(hashKey, hash1);
    }
    setHashLoc(hash1, hash2);
}

19 View Complete Implementation : RowResource.java
Copyright Apache License 2.0
Author : apache
@GET
@Produces({ MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF, MIMETYPE_PROTOBUF_IETF })
public Response get(@Context final UriInfo uriInfo) {
    if (LOG.isTraceEnabled()) {
        LOG.trace("GET " + uriInfo.getAbsolutePath());
    }
    servlet.getMetrics().incrementRequests(1);
    MultivaluedMap<String, String> params = uriInfo.getQueryParameters();
    try {
        ResultGenerator generator = ResultGenerator.fromRowSpec(tableResource.getName(), rowspec, null, !params.containsKey(NOCACHE_PARAM_NAME));
        if (!generator.hasNext()) {
            servlet.getMetrics().incrementFailedGetRequests(1);
            return Response.status(Response.Status.NOT_FOUND).type(MIMETYPE_TEXT).enreplacedy("Not found" + CRLF).build();
        }
        int count = 0;
        CellSetModel model = new CellSetModel();
        Cell value = generator.next();
        byte[] rowKey = CellUtil.cloneRow(value);
        RowModel rowModel = new RowModel(rowKey);
        do {
            if (!Bytes.equals(CellUtil.cloneRow(value), rowKey)) {
                model.addRow(rowModel);
                rowKey = CellUtil.cloneRow(value);
                rowModel = new RowModel(rowKey);
            }
            rowModel.addCell(new CellModel(CellUtil.cloneFamily(value), CellUtil.cloneQualifier(value), value.getTimestamp(), CellUtil.cloneValue(value)));
            if (++count > rowspec.getMaxValues()) {
                break;
            }
            value = generator.next();
        } while (value != null);
        model.addRow(rowModel);
        servlet.getMetrics().incrementSucessfulGetRequests(1);
        return Response.ok(model).build();
    } catch (Exception e) {
        servlet.getMetrics().incrementFailedPutRequests(1);
        return processException(e);
    }
}

19 View Complete Implementation : TestCompactingMemStore.java
Copyright Apache License 2.0
Author : apache
private void isExpectedRowWithoutTimestamps(final int rowIndex, List<Cell> kvs) {
    int i = 0;
    for (Cell kv : kvs) {
        byte[] expectedColname = makeQualifier(rowIndex, i++);
        replacedertTrue("Column name", CellUtil.matchingQualifier(kv, expectedColname));
        // Value is column name as bytes.  Usually result is
        // 100 bytes in size at least. This is the default size
        // for BytesWriteable.  For comparison, convert bytes to
        // String and trim to remove trailing null bytes.
        replacedertTrue("Content", CellUtil.matchingValue(kv, expectedColname));
    }
}

19 View Complete Implementation : BloomContext.java
Copyright Apache License 2.0
Author : apache
/**
 * Bloom information from the cell is retrieved
 * @param cell
 * @throws IOException
 */
public void writeBloom(Cell cell) throws IOException {
    // only add to the bloom filter on a new, unique key
    if (isNewKey(cell)) {
        sanityCheck(cell);
        bloomFilterWriter.append(cell);
    }
}