Java Code Examples for org.apache.hadoop.hbase.client.Delete#addFamilyVersion()

The following examples show how to use org.apache.hadoop.hbase.client.Delete#addFamilyVersion() . 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: TestVisibilityLabelsWithDeletes.java    From hbase with Apache License 2.0 6 votes vote down vote up
private static Delete addDeleteMark(Delete d, DeleteMark mark, long now) {
  switch (mark) {
    case ROW:
      break;
    case FAMILY:
      d.addFamily(fam);
      break;
    case FAMILY_VERSION:
      d.addFamilyVersion(fam, now);
      break;
    case COLUMN:
      d.addColumns(fam, qual);
      break;
    case CELL:
      d.addColumn(fam, qual);
      break;
    default:
      break;
  }
  return d;
}
 
Example 2
Source File: IndexMaintainer.java    From phoenix with Apache License 2.0 6 votes vote down vote up
public Delete buildRowDeleteMutation(byte[] indexRowKey, DeleteType deleteType, long ts) {
    byte[] emptyCF = emptyKeyValueCFPtr.copyBytesIfNecessary();
    Delete delete = new Delete(indexRowKey);

    for (ColumnReference ref : getCoveredColumns()) {
        ColumnReference indexColumn = coveredColumnsMap.get(ref);
        // If table delete was single version, then index delete should be as well
        if (deleteType == DeleteType.SINGLE_VERSION) {
            delete.addFamilyVersion(indexColumn.getFamily(), ts);
        } else {
            delete.addFamily(indexColumn.getFamily(), ts);
        }
    }
    if (deleteType == DeleteType.SINGLE_VERSION) {
        delete.addFamilyVersion(emptyCF, ts);
    } else {
        delete.addFamily(emptyCF, ts);
    }
    delete.setDurability(!indexWALDisabled ? Durability.USE_DEFAULT : Durability.SKIP_WAL);
    return delete;
}
 
Example 3
Source File: VisibilityLabelsWithDeletesTestBase.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testVisibilityLabelsWithDeleteFamilyVersion() throws Exception {
  setAuths();
  final TableName tableName = TableName.valueOf(testName.getMethodName());
  long[] ts = new long[] { 123L, 125L };
  try (
    Table table = createTableAndWriteDataWithLabels(ts, CONFIDENTIAL + "|" + TOPSECRET, SECRET)) {
    PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
      @Override
      public Void run() throws Exception {
        try (Connection connection = ConnectionFactory.createConnection(conf);
          Table table = connection.getTable(tableName)) {
          Delete d = new Delete(row1);
          d.setCellVisibility(new CellVisibility(TOPSECRET + "|" + CONFIDENTIAL));
          d.addFamilyVersion(fam, 123L);
          table.delete(d);
        } catch (Throwable t) {
          throw new IOException(t);
        }
        return null;
      }
    };
    SUPERUSER.runAs(actiona);

    TEST_UTIL.getAdmin().flush(tableName);
    Scan s = new Scan();
    s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL));
    ResultScanner scanner = table.getScanner(s);
    Result[] next = scanner.next(3);
    assertTrue(next.length == 1);
    CellScanner cellScanner = next[0].cellScanner();
    cellScanner.advance();
    Cell current = cellScanner.current();
    assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(),
      row2, 0, row2.length));
  }
}
 
Example 4
Source File: TransactionAwareHTable.java    From phoenix-tephra with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean doRollback() throws Exception {
  try {
    // pre-size arraylist of deletes
    int size = 0;
    for (Set<ActionChange> cs : changeSets.values()) {
      size += cs.size();
    }
    List<Delete> rollbackDeletes = new ArrayList<>(size);
    for (Map.Entry<Long, Set<ActionChange>> entry : changeSets.entrySet()) {
      long transactionTimestamp = entry.getKey();
      for (ActionChange change : entry.getValue()) {
        byte[] row = change.getRow();
        byte[] family = change.getFamily();
        byte[] qualifier = change.getQualifier();
        Delete rollbackDelete = new Delete(row);
        makeRollbackOperation(rollbackDelete);
        switch (conflictLevel) {
        case ROW:
        case NONE:
          // issue family delete for the tx write pointer
          rollbackDelete.addFamilyVersion(change.getFamily(), transactionTimestamp);
          break;
        case COLUMN:
          if (family != null && qualifier == null) {
            rollbackDelete.addFamilyVersion(family, transactionTimestamp);
          } else if (family != null && qualifier != null) {
            rollbackDelete.addColumn(family, qualifier, transactionTimestamp);
          }
          break;
        default:
          throw new IllegalStateException("Unknown conflict detection level: " + conflictLevel);
        }
        rollbackDeletes.add(rollbackDelete);
      }
    }
    hTable.delete(rollbackDeletes);
    return true;
  } finally {
    tx = null;
    changeSets.clear();
  }
}