Package org.apache.hadoop.hbase

Examples of org.apache.hadoop.hbase.KeyValue$MetaComparator


    }

    private KeyValue getNext(Iterator<KeyValue> it) {
      long readPoint = MultiVersionConsistencyControl.getThreadReadPoint();

      KeyValue v = null;
      try {
        while (it.hasNext()) {
          v = it.next();
          if (v.getMemstoreTS() <= readPoint) {
            return v;
          }
        }

        return null;
View Full Code Here


    public synchronized KeyValue next() {
      if (theNext == null) {
          return null;
      }

      final KeyValue ret = theNext;

      // Advance one of the iterators
      if (theNext == kvsetNextRow) {
        kvsetNextRow = getNext(kvsetIt);
      } else {
View Full Code Here

   * @return approximate size of the passed key and value.
   */
  long add(final KeyValue kv) {
    this.lock.readLock().lock();
    try {
      KeyValue toAdd = maybeCloneWithAllocator(kv);
      return internalAdd(toAdd);
    } finally {
      this.lock.readLock().unlock();
    }
  }
View Full Code Here

      // not to do anything with it.
      return kv;
    }
    assert alloc != null && alloc.getData() != null;
    System.arraycopy(kv.getBuffer(), kv.getOffset(), alloc.getData(), alloc.getOffset(), len);
    KeyValue newKv = new KeyValue(alloc.getData(), alloc.getOffset(), len);
    newKv.setMemstoreTS(kv.getMemstoreTS());
    return newKv;
  }
View Full Code Here

      // If the key is in the snapshot, delete it. We should not update
      // this.size, because that tracks the size of only the memstore and
      // not the snapshot. The flush of this snapshot to disk has not
      // yet started because Store.flush() waits for all rwcc transactions to
      // commit before starting the flush to disk.
      KeyValue found = this.snapshot.get(kv);
      if (found != null && found.getMemstoreTS() == kv.getMemstoreTS()) {
        this.snapshot.remove(kv);
      }
      // If the key is in the memstore, delete it. Update this.size.
      found = this.kvset.get(kv);
      if (found != null && found.getMemstoreTS() == kv.getMemstoreTS()) {
        this.kvset.remove(kv);
        long s = heapSizeChange(kv, true);
        this.size.addAndGet(-s);
      }
    } finally {
View Full Code Here

   */
  long delete(final KeyValue delete) {
    long s = 0;
    this.lock.readLock().lock();
    try {
      KeyValue toAdd = maybeCloneWithAllocator(delete);
      s += heapSizeChange(toAdd, this.kvset.add(toAdd));
      timeRangeTracker.includeTimestamp(toAdd);
    } finally {
      this.lock.readLock().unlock();
    }
View Full Code Here

   * @return Next row or null if none found.  If one found, will be a new
   * KeyValue -- can be destroyed by subsequent calls to this method.
   */
  private KeyValue getNextRow(final KeyValue key,
      final NavigableSet<KeyValue> set) {
    KeyValue result = null;
    SortedSet<KeyValue> tail = key == null? set: set.tailSet(key);
    // Iterate until we fall into the next row; i.e. move off current row
    for (KeyValue kv: tail) {
      if (comparator.compareRows(kv, key) <= 0)
        continue;
View Full Code Here

      final KeyValue firstOnRow, final GetClosestRowBeforeTracker state) {
    boolean foundCandidate = false;
    SortedSet<KeyValue> tail = set.tailSet(firstOnRow);
    if (tail.isEmpty()) return foundCandidate;
    for (Iterator<KeyValue> i = tail.iterator(); i.hasNext();) {
      KeyValue kv = i.next();
      // Did we go beyond the target row? If so break.
      if (state.isTooFar(kv, firstOnRow)) break;
      if (state.isExpired(kv)) {
        i.remove();
        continue;
View Full Code Here

   * @param set
   * @param state
   */
  private void getRowKeyBefore(NavigableSet<KeyValue> set,
      final GetClosestRowBeforeTracker state) {
    KeyValue firstOnRow = state.getTargetKey();
    for (Member p = memberOfPreviousRow(set, state, firstOnRow);
        p != null; p = memberOfPreviousRow(p.set, state, firstOnRow)) {
      // Make sure we don't fall out of our table.
      if (!state.isTargetTable(p.kv)) break;
      // Stop looking if we've exited the better candidate range.
      if (!state.isBetterCandidate(p.kv)) break;
      // Make into firstOnRow
      firstOnRow = new KeyValue(p.kv.getRow(), HConstants.LATEST_TIMESTAMP);
      // If we find something, break;
      if (walkForwardInSingleRow(p.set, firstOnRow, state)) break;
    }
  }
View Full Code Here

                                byte[] qualifier,
                                long newValue,
                                long now) {
   this.lock.readLock().lock();
    try {
      KeyValue firstKv = KeyValue.createFirstOnRow(
          row, family, qualifier);
      // Is there a KeyValue in 'snapshot' with the same TS? If so, upgrade the timestamp a bit.
      SortedSet<KeyValue> snSs = snapshot.tailSet(firstKv);
      if (!snSs.isEmpty()) {
        KeyValue snKv = snSs.first();
        // is there a matching KV in the snapshot?
        if (snKv.matchingRow(firstKv) && snKv.matchingQualifier(firstKv)) {
          if (snKv.getTimestamp() == now) {
            // poop,
            now += 1;
          }
        }
      }

      // logic here: the new ts MUST be at least 'now'. But it could be larger if necessary.
      // But the timestamp should also be max(now, mostRecentTsInMemstore)

      // so we cant add the new KV w/o knowing what's there already, but we also
      // want to take this chance to delete some kvs. So two loops (sad)

      SortedSet<KeyValue> ss = kvset.tailSet(firstKv);
      Iterator<KeyValue> it = ss.iterator();
      while ( it.hasNext() ) {
        KeyValue kv = it.next();

        // if this isnt the row we are interested in, then bail:
        if (!kv.matchingColumn(family,qualifier) || !kv.matchingRow(firstKv) ) {
          break; // rows dont match, bail.
        }

        // if the qualifier matches and it's a put, just RM it out of the kvset.
        if (kv.getType() == KeyValue.Type.Put.getCode() &&
            kv.getTimestamp() > now && firstKv.matchingQualifier(kv)) {
          now = kv.getTimestamp();
        }
      }

      // create or update (upsert) a new KeyValue with
      // 'now' and a 0 memstoreTS == immediately visible
      return upsert(Arrays.asList(
          new KeyValue(row, family, qualifier, now, Bytes.toBytes(newValue)))
      );
    } finally {
      this.lock.readLock().unlock();
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hbase.KeyValue$MetaComparator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.