Package org.apache.hbase.index.covered.update

Examples of org.apache.hbase.index.covered.update.IndexUpdateManager


  }

  @Override
  public Collection<Pair<Mutation, byte[]>> getIndexUpdate(Mutation mutation) throws IOException {
    // build the index updates for each group
    IndexUpdateManager updateMap = new IndexUpdateManager();

    batchMutationAndAddUpdates(updateMap, mutation);

    if (LOG.isDebugEnabled()) {
      LOG.debug("Found index updates for Mutation: " + mutation + "\n" + updateMap);
    }

    return updateMap.toMap();
  }
View Full Code Here


  }

  @Override
  public Collection<Pair<Mutation, byte[]>> getIndexUpdate(Delete d) throws IOException {
    // stores all the return values
    IndexUpdateManager updateMap = new IndexUpdateManager();

    // We have to figure out which kind of delete it is, since we need to do different things if its
    // a general (row) delete, versus a delete of just a single column or family
    Map<byte[], List<KeyValue>> families = d.getFamilyMap();

    /*
     * Option 1: its a row delete marker, so we just need to delete the most recent state for each
     * group, as of the specified timestamp in the delete. This can happen if we have a single row
     * update and it is part of a batch mutation (prepare doesn't happen until later... maybe a
     * bug?). In a single delete, this delete gets all the column families appended, so the family
     * map won't be empty by the time it gets here.
     */
    if (families.size() == 0) {
      LocalTableState state = new LocalTableState(env, localTable, d);
      // get a consistent view of name
      long now = d.getTimeStamp();
      if (now == HConstants.LATEST_TIMESTAMP) {
        now = EnvironmentEdgeManager.currentTimeMillis();
        // update the delete's idea of 'now' to be consistent with the index
        d.setTimestamp(now);
      }
      // get deletes from the codec
      // we only need to get deletes and not add puts because this delete covers all columns
      addDeleteUpdatesToMap(updateMap, state, now);

      /*
       * Update the current state for all the kvs in the delete. Generally, we would just iterate
       * the family map, but since we go here, the family map is empty! Therefore, we need to fake a
       * bunch of family deletes (just like hos HRegion#prepareDelete works). This is just needed
       * for current version of HBase that has an issue where the batch update doesn't update the
       * deletes before calling the hook.
       */
      byte[] deleteRow = d.getRow();
      for (byte[] family : this.env.getRegion().getTableDesc().getFamiliesKeys()) {
        state.addPendingUpdates(new KeyValue(deleteRow, family, null, now,
            KeyValue.Type.DeleteFamily));
      }
    } else {
      // Option 2: Its actually a bunch single updates, which can have different timestamps.
      // Therefore, we need to do something similar to the put case and batch by timestamp
      batchMutationAndAddUpdates(updateMap, d);
    }

    if (LOG.isDebugEnabled()) {
      LOG.debug("Found index updates for Delete: " + d + "\n" + updateMap);
    }

    return updateMap.toMap();
  }
View Full Code Here

  @Override
  public Collection<Pair<Mutation, byte[]>> getIndexUpdateForFilteredRows(
      Collection<KeyValue> filtered) throws IOException {

    // stores all the return values
    IndexUpdateManager updateMap = new IndexUpdateManager();
    // batch the updates by row to make life easier and ordered
    Collection<Batch> batches = batchByRow(filtered);

    for (Batch batch : batches) {
      Put p = new Put(batch.getKvs().iterator().next().getRow());
      for (KeyValue kv : batch.getKvs()) {
        // we only need to cleanup Put entries
        byte type = kv.getType();
        Type t = KeyValue.Type.codeToType(type);
        if (!t.equals(Type.Put)) {
          continue;
        }

        // add the kv independently
        p.add(kv);
      }

      // do the usual thing as for deletes
      Collection<Batch> timeBatch = createTimestampBatchesFromMutation(p);
      LocalTableState state = new LocalTableState(env, localTable, p);
      for (Batch entry : timeBatch) {
        //just set the timestamp on the table - it already has all the future state
        state.setCurrentTimestamp(entry.getTimestamp());
        this.addDeleteUpdatesToMap(updateMap, state, entry.getTimestamp());
      }
    }
    return updateMap.toMap();
  }
View Full Code Here

  private static final String TABLE_NAME = "table";
  private static final byte[] table = Bytes.toBytes(TABLE_NAME);

  @Test
  public void testMutationComparator() throws Exception {
    IndexUpdateManager manager = new IndexUpdateManager();
    Comparator<Mutation> comparator = manager.COMPARATOR;
    Put p = new Put(row, 10);
    // lexigraphically earlier should sort earlier
    Put p1 = new Put(Bytes.toBytes("ro"), 10);
    assertTrue("lexigraphically later sorting first, should be earlier first.",
View Full Code Here

   * When making updates we need to cancel out {@link Delete} and {@link Put}s for the same row.
   * @throws Exception on failure
   */
  @Test
  public void testCancelingUpdates() throws Exception {
    IndexUpdateManager manager = new IndexUpdateManager();

    long ts1 = 10, ts2 = 11;
    // at different timestamps, so both should be retained
    Delete d = new Delete(row, ts1);
    Put p = new Put(row, ts2);
    manager.addIndexUpdate(table, d);
    manager.addIndexUpdate(table, p);
    List<Mutation> pending = new ArrayList<Mutation>();
    pending.add(p);
    pending.add(d);
    validate(manager, pending);

    // add a delete that should cancel out the put, leading to only one delete remaining
    Delete d2 = new Delete(row, ts2);
    manager.addIndexUpdate(table, d2);
    pending.add(d);
    validate(manager, pending);

    // double-deletes of the same row only retain the existing one, which was already canceled out
    // above
    Delete d3 = new Delete(row, ts2);
    manager.addIndexUpdate(table, d3);
    pending.add(d);
    validate(manager, pending);

    // if there is just a put and a delete at the same ts, no pending updates should be returned
    manager = new IndexUpdateManager();
    manager.addIndexUpdate(table, d2);
    manager.addIndexUpdate(table, p);
    validate(manager, Collections.<Mutation> emptyList());

    // different row insertions can be tricky too, if you don't get the base cases right
    manager = new IndexUpdateManager();
    manager.addIndexUpdate(table, p);
    // this row definitely sorts after the current row
    byte[] row1 = Bytes.toBytes("row1");
    Put p1 = new Put(row1, ts1);
    manager.addIndexUpdate(table, p1);
    // this delete should completely cover the given put and both should be removed
    Delete d4 = new Delete(row1, ts1);
    manager.addIndexUpdate(table, d4);
    pending.clear();
    pending.add(p);
    validate(manager, pending);
  }
View Full Code Here

TOP

Related Classes of org.apache.hbase.index.covered.update.IndexUpdateManager

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.