Java Code Examples for org.apache.hadoop.hbase.client.Delete

The following are top voted examples for showing how to use org.apache.hadoop.hbase.client.Delete. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: ditb   File: OfflineMetaRebuildTestCore.java   Source Code and License 11 votes vote down vote up
protected void wipeOutMeta() throws IOException {
  // Mess it up by blowing up meta.
  Admin admin = TEST_UTIL.getHBaseAdmin();
  Scan s = new Scan();
  Table meta = new HTable(conf, TableName.META_TABLE_NAME);
  ResultScanner scanner = meta.getScanner(s);
  List<Delete> dels = new ArrayList<Delete>();
  for (Result r : scanner) {
    HRegionInfo info =
        HRegionInfo.getHRegionInfo(r);
    if(info != null && !info.getTable().getNamespaceAsString()
        .equals(NamespaceDescriptor.SYSTEM_NAMESPACE_NAME_STR)) {
      Delete d = new Delete(r.getRow());
      dels.add(d);
      admin.unassign(r.getRow(), true);
    }
  }
  meta.delete(dels);
  scanner.close();
  meta.close();
}
 
Example 2
Project: ditb   File: HBaseFsck.java   Source Code and License 8 votes vote down vote up
/**
 * Reset the split parent region info in meta table
 */
private void resetSplitParent(HbckInfo hi) throws IOException {
  RowMutations mutations = new RowMutations(hi.metaEntry.getRegionName());
  Delete d = new Delete(hi.metaEntry.getRegionName());
  d.deleteColumn(HConstants.CATALOG_FAMILY, HConstants.SPLITA_QUALIFIER);
  d.deleteColumn(HConstants.CATALOG_FAMILY, HConstants.SPLITB_QUALIFIER);
  mutations.add(d);

  HRegionInfo hri = new HRegionInfo(hi.metaEntry);
  hri.setOffline(false);
  hri.setSplit(false);
  Put p = MetaTableAccessor.makePutFromRegionInfo(hri);
  mutations.add(p);

  meta.mutateRow(mutations);
  LOG.info("Reset split parent " + hi.metaEntry.getRegionNameAsString() + " in META" );
}
 
Example 3
Project: aliyun-tablestore-hbase-client   File: TablestoreBufferedMutator.java   Source Code and License 7 votes vote down vote up
private void commitDeletes(final List<ODelete> deletes) throws IOException {
    boolean flushSuccessfully = false;
    try {
        this.adapter.deleteMultiple(tableName.getNameAsString(), deletes);
        flushSuccessfully = true;
    } finally {
        if (!flushSuccessfully && !clearBufferOnFail) {
            List<Delete> hDeletes = ElementConvertor.toHBaseDeletes(deletes, this.columnMapping);
            synchronized (writeBuffer) {
                for (Delete delete : hDeletes) {
                    writeBuffer.add(delete);
                    currentWriteBufferSize += delete.heapSize();
                }
            }
        }
    }
}
 
Example 4
Project: ditb   File: ThriftServerRunner.java   Source Code and License 7 votes vote down vote up
@Override
public void deleteAllTs(ByteBuffer tableName,
                        ByteBuffer row,
                        ByteBuffer column,
    long timestamp, Map<ByteBuffer, ByteBuffer> attributes) throws IOError {
  Table table = null;
  try {
    table = getTable(tableName);
    Delete delete  = new Delete(getBytes(row));
    addAttributes(delete, attributes);
    byte [][] famAndQf = KeyValue.parseColumn(getBytes(column));
    if (famAndQf.length == 1) {
      delete.deleteFamily(famAndQf[0], timestamp);
    } else {
      delete.deleteColumns(famAndQf[0], famAndQf[1], timestamp);
    }
    table.delete(delete);

  } catch (IOException e) {
    LOG.warn(e.getMessage(), e);
    throw new IOError(Throwables.getStackTraceAsString(e));
  } finally {
    closeTable(table);
  }
}
 
Example 5
Project: ditb   File: ThriftServerRunner.java   Source Code and License 7 votes vote down vote up
@Override
public void deleteAllRowTs(
    ByteBuffer tableName, ByteBuffer row, long timestamp,
    Map<ByteBuffer, ByteBuffer> attributes) throws IOError {
  Table table = null;
  try {
    table = getTable(tableName);
    Delete delete  = new Delete(getBytes(row), timestamp);
    addAttributes(delete, attributes);
    table.delete(delete);
  } catch (IOException e) {
    LOG.warn(e.getMessage(), e);
    throw new IOError(Throwables.getStackTraceAsString(e));
  } finally {
    closeTable(table);
  }
}
 
Example 6
Project: ditb   File: AccessControlLists.java   Source Code and License 7 votes vote down vote up
/**
 * Removes a previously granted permission from the stored access control
 * lists.  The {@link TablePermission} being removed must exactly match what
 * is stored -- no wildcard matching is attempted.  Ie, if user "bob" has
 * been granted "READ" access to the "data" table, but only to column family
 * plus qualifier "info:colA", then trying to call this method with only
 * user "bob" and the table name "data" (but without specifying the
 * column qualifier "info:colA") will have no effect.
 *
 * @param conf the configuration
 * @param userPerm the details of the permission to be revoked
 * @throws IOException if there is an error accessing the metadata table
 */
static void removeUserPermission(Configuration conf, UserPermission userPerm)
    throws IOException {
  Delete d = new Delete(userPermissionRowKey(userPerm));
  byte[] key = userPermissionKey(userPerm);

  if (LOG.isDebugEnabled()) {
    LOG.debug("Removing permission "+ userPerm.toString());
  }
  d.addColumns(ACL_LIST_FAMILY, key);
  // TODO: Pass in a Connection rather than create one each time.
  try (Connection connection = ConnectionFactory.createConnection(conf)) {
    try (Table table = connection.getTable(ACL_TABLE_NAME)) {
      table.delete(d);
    }
  }
}
 
Example 7
Project: ditb   File: MetaTableAccessor.java   Source Code and License 7 votes vote down vote up
/**
 * Deletes some replica columns corresponding to replicas for the passed rows
 * @param metaRows rows in hbase:meta
 * @param replicaIndexToDeleteFrom the replica ID we would start deleting from
 * @param numReplicasToRemove how many replicas to remove
 * @param connection connection we're using to access meta table
 * @throws IOException
 */
public static void removeRegionReplicasFromMeta(Set<byte[]> metaRows,
  int replicaIndexToDeleteFrom, int numReplicasToRemove, Connection connection)
    throws IOException {
  int absoluteIndex = replicaIndexToDeleteFrom + numReplicasToRemove;
  for (byte[] row : metaRows) {
    Delete deleteReplicaLocations = new Delete(row);
    for (int i = replicaIndexToDeleteFrom; i < absoluteIndex; i++) {
      deleteReplicaLocations.deleteColumns(HConstants.CATALOG_FAMILY,
        getServerColumn(i));
      deleteReplicaLocations.deleteColumns(HConstants.CATALOG_FAMILY,
        getSeqNumColumn(i));
      deleteReplicaLocations.deleteColumns(HConstants.CATALOG_FAMILY,
        getStartCodeColumn(i));
    }
    deleteFromMetaTable(connection, deleteReplicaLocations);
  }
}
 
Example 8
Project: ditb   File: HMerge.java   Source Code and License 7 votes vote down vote up
@Override
protected void updateMeta(final byte [] oldRegion1,
    final byte [] oldRegion2,
  HRegion newRegion)
throws IOException {
  byte[][] regionsToDelete = {oldRegion1, oldRegion2};
  for (int r = 0; r < regionsToDelete.length; r++) {
    if(Bytes.equals(regionsToDelete[r], latestRegion.getRegionName())) {
      latestRegion = null;
    }
    Delete delete = new Delete(regionsToDelete[r]);
    table.delete(delete);
    if(LOG.isDebugEnabled()) {
      LOG.debug("updated columns in row: " + Bytes.toStringBinary(regionsToDelete[r]));
    }
  }
  newRegion.getRegionInfo().setOffline(true);

  MetaTableAccessor.addRegionToMeta(table, newRegion.getRegionInfo());

  if(LOG.isDebugEnabled()) {
    LOG.debug("updated columns in row: "
        + Bytes.toStringBinary(newRegion.getRegionInfo().getRegionName()));
  }
}
 
Example 9
Project: ditb   File: MultiRowMutationProcessor.java   Source Code and License 7 votes vote down vote up
@Override
public void postProcess(HRegion region, WALEdit walEdit, boolean success) throws IOException {
  RegionCoprocessorHost coprocessorHost = region.getCoprocessorHost();
  if (coprocessorHost != null) {
    for (Mutation m : mutations) {
      if (m instanceof Put) {
        coprocessorHost.postPut((Put) m, walEdit, m.getDurability());
      } else if (m instanceof Delete) {
        coprocessorHost.postDelete((Delete) m, walEdit, m.getDurability());
      }
    }
    // At the end call the CP hook postBatchMutateIndispensably
    if (miniBatch != null) {
      // Directly calling this hook, with out calling pre/postBatchMutate() when Processor do a
      // read only process. Then no need to call this batch based CP hook also.
      coprocessorHost.postBatchMutateIndispensably(miniBatch, success);
    }
  }
}
 
Example 10
Project: ditb   File: TestMultiSlaveReplication.java   Source Code and License 7 votes vote down vote up
private void deleteAndWait(byte[] row, Table source, Table... targets)
throws Exception {
  Delete del = new Delete(row);
  source.delete(del);

  Get get = new Get(row);
  for (int i = 0; i < NB_RETRIES; i++) {
    if (i==NB_RETRIES-1) {
      fail("Waited too much time for del replication");
    }
    boolean removedFromAll = true;
    for (Table target : targets) {
      Result res = target.get(get);
      if (res.size() >= 1) {
        LOG.info("Row not deleted");
        removedFromAll = false;
        break;
      }
    }
    if (removedFromAll) {
      break;
    } else {
      Thread.sleep(SLEEP_TIME);
    }
  }
}
 
Example 11
Project: ditb   File: RequestConverter.java   Source Code and License 7 votes vote down vote up
/**
 * Create a protocol buffer MutateRequest for a conditioned delete
 *
 * @param regionName
 * @param row
 * @param family
 * @param qualifier
 * @param comparator
 * @param compareType
 * @param delete
 * @return a mutate request
 * @throws IOException
 */
public static MutateRequest buildMutateRequest(
    final byte[] regionName, final byte[] row, final byte[] family,
    final byte [] qualifier, final ByteArrayComparable comparator,
    final CompareType compareType, final Delete delete) throws IOException {
  MutateRequest.Builder builder = MutateRequest.newBuilder();
  RegionSpecifier region = buildRegionSpecifier(
    RegionSpecifierType.REGION_NAME, regionName);
  builder.setRegion(region);
  Condition condition = buildCondition(
    row, family, qualifier, comparator, compareType);
  builder.setMutation(ProtobufUtil.toMutation(MutationType.DELETE, delete,
    MutationProto.newBuilder()));
  builder.setCondition(condition);
  return builder.build();
}
 
Example 12
Project: ditb   File: TestCellACLWithMultipleVersions.java   Source Code and License 7 votes vote down vote up
private void verifyUserDeniedForDeleteMultipleVersions(final User user, final byte[] row,
    final byte[] q1, final byte[] q2) throws IOException, InterruptedException {
  user.runAs(new PrivilegedExceptionAction<Void>() {
    @Override
    public Void run() throws Exception {
      try (Connection connection = ConnectionFactory.createConnection(conf)) {
        try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
          Delete d = new Delete(row);
          d.addColumns(TEST_FAMILY1, q1);
          d.addColumns(TEST_FAMILY1, q2);
          t.delete(d);
          fail(user.getShortName() + " should not be allowed to delete the row");
        } catch (Exception e) {

        }
      }
      return null;
    }
  });
}
 
Example 13
Project: ditb   File: TestCellACLWithMultipleVersions.java   Source Code and License 7 votes vote down vote up
private void verifyUserDeniedForDeleteExactVersion(final User user, final byte[] row,
    final byte[] q1, final byte[] q2) throws IOException, InterruptedException {
  user.runAs(new PrivilegedExceptionAction<Void>() {
    @Override
    public Void run() throws Exception {
      try (Connection connection = ConnectionFactory.createConnection(conf)) {
        try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
          Delete d = new Delete(row, 127);
          d.addColumns(TEST_FAMILY1, q1);
          d.addColumns(TEST_FAMILY1, q2);
          d.addFamily(TEST_FAMILY2, 129);
          t.delete(d);
          fail(user.getShortName() + " can not do the delete");
        } catch (Exception e) {

        }
      }
      return null;
    }
  });
}
 
Example 14
Project: ditb   File: TestCellACLWithMultipleVersions.java   Source Code and License 7 votes vote down vote up
private void verifyUserAllowedforCheckAndDelete(final User user, final byte[] row,
    final byte[] q1, final byte[] value) throws IOException, InterruptedException {
  user.runAs(new PrivilegedExceptionAction<Void>() {
    @Override
    public Void run() throws Exception {
      try (Connection connection = ConnectionFactory.createConnection(conf)) {
        try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
          Delete d = new Delete(row);
          d.addColumn(TEST_FAMILY1, q1, 120);
          t.checkAndDelete(row, TEST_FAMILY1, q1, value, d);
        }
      }
      return null;
    }
  });
}
 
Example 15
Project: ditb   File: TestCellACLWithMultipleVersions.java   Source Code and License 7 votes vote down vote up
private void verifyUserDeniedForCheckAndDelete(final User user, final byte[] row,
    final byte[] value) throws IOException, InterruptedException {
  user.runAs(new PrivilegedExceptionAction<Void>() {
    @Override
    public Void run() throws Exception {
      try (Connection connection = ConnectionFactory.createConnection(conf)) {
        try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
          Delete d = new Delete(row);
          d.addColumns(TEST_FAMILY1, TEST_Q1);
          t.checkAndDelete(row, TEST_FAMILY1, TEST_Q1, value, d);
          fail(user.getShortName() + " should not be allowed to do checkAndDelete");
        } catch (Exception e) {
        }
      }
      return null;
    }
  });
}
 
Example 16
Project: ditb   File: RequestConverter.java   Source Code and License 6 votes vote down vote up
/**
 * Create a protocol buffer MultiRequest for row mutations that does not hold data.  Data/Cells
 * are carried outside of protobuf.  Return references to the Cells in <code>cells</code> param.
  * Does not propagate Action absolute position.  Does not set atomic action on the created
 * RegionAtomic.  Caller should do that if wanted.
 * @param regionName
 * @param rowMutations
 * @param cells Return in here a list of Cells as CellIterable.
 * @return a region mutation minus data
 * @throws IOException
 */
public static RegionAction.Builder buildNoDataRegionAction(final byte[] regionName,
    final RowMutations rowMutations, final List<CellScannable> cells,
    final RegionAction.Builder regionActionBuilder,
    final ClientProtos.Action.Builder actionBuilder,
    final MutationProto.Builder mutationBuilder)
throws IOException {
  for (Mutation mutation: rowMutations.getMutations()) {
    MutationType type = null;
    if (mutation instanceof Put) {
      type = MutationType.PUT;
    } else if (mutation instanceof Delete) {
      type = MutationType.DELETE;
    } else {
      throw new DoNotRetryIOException("RowMutations supports only put and delete, not " +
        mutation.getClass().getName());
    }
    mutationBuilder.clear();
    MutationProto mp = ProtobufUtil.toMutationNoData(type, mutation, mutationBuilder);
    cells.add(mutation);
    actionBuilder.clear();
    regionActionBuilder.addAction(actionBuilder.setMutation(mp).build());
  }
  return regionActionBuilder;
}
 
Example 17
Project: SparkDemo   File: MyClass.java   Source Code and License 6 votes vote down vote up
public static void deleteRow(String tablename, String rowkey) {
    try {
        HTable table = new HTable(configuration, tablename);
        List list = new ArrayList();
        Delete d1 = new Delete(rowkey.getBytes());
        list.add(d1);

        table.delete(list);
        System.out.println("删除行成功!");

    } catch (IOException e) {
        e.printStackTrace();
    }


}
 
Example 18
Project: stroom-stats   File: HBaseTable.java   Source Code and License 6 votes vote down vote up
boolean doCheckAndDelete(final byte[] row, final byte[] family, final byte[] qualifier, final byte[] value,
        final Delete delete) {
    boolean result;
    final Table tableInterface = getTable();
    try {
        result = doCheckAndDelete(tableInterface, row, family, qualifier, value, delete);
    } finally {
        closeTable(tableInterface);
    }
    return result;
}
 
Example 19
Project: ditb   File: TestMinorCompaction.java   Source Code and License 6 votes vote down vote up
@Test
public void testMinorCompactionWithDeleteColumn1() throws Exception {
  Delete dc = new Delete(secondRowBytes);
  /* delete all timestamps in the column */
  dc.deleteColumns(fam2, col2);
  testMinorCompactionWithDelete(dc);
}
 
Example 20
Project: stroom-stats   File: HBaseTable.java   Source Code and License 6 votes vote down vote up
/**
 * Gets a tableInterface, does the passed delete on this table and then
 * closes the tableInterface
 *
 * @param delete
 *            The HBase delete object
 */
public void doDelete(final Delete delete) {
    final Table tableInterface = getTable();
    try {
        doDelete(delete);
    } finally {
        closeTable(tableInterface);
    }
}
 
Example 21
Project: stroom-stats   File: HBaseTable.java   Source Code and License 6 votes vote down vote up
/**
 * Does the delete using the passed tableInterface but leaves it open
 *
 * @param tableInterface
 * @param delete
 */
public static void doDelete(final Table tableInterface, final Delete delete) {
    try {
        tableInterface.delete(delete);
    } catch (final Exception e) {
        closeTable(tableInterface);
        throw new HBaseException(e.getMessage(), e);
    }
}
 
Example 22
Project: QDrill   File: HBasePStore.java   Source Code and License 6 votes vote down vote up
private void delete(byte[] row) {
  try {
    Delete del = new Delete(row);
    table.delete(del);
  } catch (IOException e) {
    throw new DrillRuntimeException("Caught error while deleting row '" + Bytes.toStringBinary(row)
        + "' from for table:" + Bytes.toString(table.getTableName()), e);
  }
}
 
Example 23
Project: ditb   File: TestHRegion.java   Source Code and License 6 votes vote down vote up
@Test
public void testWriteRequestsCounter() throws IOException {
  byte[] fam = Bytes.toBytes("info");
  byte[][] families = { fam };
  this.region = initHRegion(tableName, method, CONF, families);

  Assert.assertEquals(0L, region.getWriteRequestsCount());

  Put put = new Put(row);
  put.add(fam, fam, fam);

  Assert.assertEquals(0L, region.getWriteRequestsCount());
  region.put(put);
  Assert.assertEquals(1L, region.getWriteRequestsCount());
  region.put(put);
  Assert.assertEquals(2L, region.getWriteRequestsCount());
  region.put(put);
  Assert.assertEquals(3L, region.getWriteRequestsCount());

  region.delete(new Delete(row));
  Assert.assertEquals(4L, region.getWriteRequestsCount());

  HRegion.closeHRegion(this.region);
  this.region = null;
}
 
Example 24
Project: ditb   File: TestMinorCompaction.java   Source Code and License 5 votes vote down vote up
@Test
public void testMinorCompactionWithDeleteVersion1() throws Exception {
  Delete deleteVersion = new Delete(secondRowBytes);
  deleteVersion.deleteColumns(fam2, col2, 2);
  /* compactionThreshold is 3. The table has 4 versions: 0, 1, 2, and 3.
   * We delete versions 0 ... 2. So, we still have one remaining.
   */
  testMinorCompactionWithDelete(deleteVersion, 1);
}
 
Example 25
Project: ignite-hbase   File: HBaseCacheStore.java   Source Code and License 5 votes vote down vote up
private Delete createDelete(Object key) {
  try {
    @SuppressWarnings("unchecked")
    Delete delete = new Delete(keySerializer.serialize((K) key));
    delete.addColumns(family(), QUALIFIER);
    return delete;
  } catch (ClassCastException | SerializationException e) {
    throw new CacheWriterException("Failed to create delete", e);
  }
}
 
Example 26
Project: ditb   File: MetaTableAccessor.java   Source Code and License 5 votes vote down vote up
/**
 * Deletes merge qualifiers for the specified merged region.
 * @param connection connection we're using
 * @param mergedRegion
 * @throws IOException
 */
public static void deleteMergeQualifiers(Connection connection,
                                         final HRegionInfo mergedRegion) throws IOException {
  Delete delete = new Delete(mergedRegion.getRegionName());
  delete.deleteColumns(HConstants.CATALOG_FAMILY, HConstants.MERGEA_QUALIFIER);
  delete.deleteColumns(HConstants.CATALOG_FAMILY, HConstants.MERGEB_QUALIFIER);
  deleteFromMetaTable(connection, delete);
  LOG.info("Deleted references in merged region "
    + mergedRegion.getRegionNameAsString() + ", qualifier="
    + Bytes.toStringBinary(HConstants.MERGEA_QUALIFIER) + " and qualifier="
    + Bytes.toStringBinary(HConstants.MERGEB_QUALIFIER));
}
 
Example 27
Project: ditb   File: ThriftUtilities.java   Source Code and License 5 votes vote down vote up
public static TDelete deleteFromHBase(Delete in) {
  TDelete out = new TDelete(ByteBuffer.wrap(in.getRow()));

  List<TColumn> columns = new ArrayList<TColumn>();
  long rowTimestamp = in.getTimeStamp();
  if (rowTimestamp != HConstants.LATEST_TIMESTAMP) {
    out.setTimestamp(rowTimestamp);
  }

  // Map<family, List<KeyValue>>
  for (Map.Entry<byte[], List<org.apache.hadoop.hbase.Cell>> familyEntry:
      in.getFamilyCellMap().entrySet()) {
    TColumn column = new TColumn(ByteBuffer.wrap(familyEntry.getKey()));
    for (org.apache.hadoop.hbase.Cell cell: familyEntry.getValue()) {
      byte[] family = CellUtil.cloneFamily(cell);
      byte[] qualifier = CellUtil.cloneQualifier(cell);
      long timestamp = cell.getTimestamp();
      if (family != null) {
        column.setFamily(family);
      }
      if (qualifier != null) {
        column.setQualifier(qualifier);
      }
      if (timestamp != HConstants.LATEST_TIMESTAMP) {
        column.setTimestamp(timestamp);
      }
    }
    columns.add(column);
  }
  out.setColumns(columns);

  return out;
}
 
Example 28
Project: ditb   File: SimpleRegionObserver.java   Source Code and License 5 votes vote down vote up
@Override
public boolean preCheckAndDelete(ObserverContext<RegionCoprocessorEnvironment> e, byte[] row,
    byte[] family, byte[] qualifier, CompareOp compareOp, ByteArrayComparable comparator,
    Delete delete, boolean result) throws IOException {
  ctPreCheckAndDelete.incrementAndGet();
  return true;
}
 
Example 29
Project: ditb   File: AccessControlLists.java   Source Code and License 5 votes vote down vote up
/**
 * Remove specified namespace from the acl table.
 */
static void removeNamespacePermissions(Configuration conf, String namespace)
    throws IOException{
  Delete d = new Delete(Bytes.toBytes(toNamespaceEntry(namespace)));

  if (LOG.isDebugEnabled()) {
    LOG.debug("Removing permissions of removed namespace "+ namespace);
  }

  try (Connection connection = ConnectionFactory.createConnection(conf)) {
    try (Table table = connection.getTable(ACL_TABLE_NAME)) {
      table.delete(d);
    }
  }
}
 
Example 30
Project: ditb   File: AccessController.java   Source Code and License 5 votes vote down vote up
@Override
public void preDelete(final ObserverContext<RegionCoprocessorEnvironment> c,
    final Delete delete, final WALEdit edit, final Durability durability)
    throws IOException {
  // An ACL on a delete is useless, we shouldn't allow it
  if (delete.getAttribute(AccessControlConstants.OP_ATTRIBUTE_ACL) != null) {
    throw new DoNotRetryIOException("ACL on delete has no effect: " + delete.toString());
  }
  // Require WRITE permissions on all cells covered by the delete. Unlike
  // for Puts we need to check all visible prior versions, because a major
  // compaction could remove them. If the user doesn't have permission to
  // overwrite any of the visible versions ('visible' defined as not covered
  // by a tombstone already) then we have to disallow this operation.
  RegionCoprocessorEnvironment env = c.getEnvironment();
  Map<byte[],? extends Collection<Cell>> families = delete.getFamilyCellMap();
  User user = getActiveUser();
  AuthResult authResult = permissionGranted(OpType.DELETE, user, env, families, Action.WRITE);
  logResult(authResult);
  if (!authResult.isAllowed()) {
    if (cellFeaturesEnabled && !compatibleEarlyTermination) {
      delete.setAttribute(CHECK_COVERING_PERM, TRUE);
    } else if (authorizationEnabled) {
      throw new AccessDeniedException("Insufficient permissions " +
        authResult.toContextString());
    }
  }
}
 
Example 31
Project: ditb   File: AccessController.java   Source Code and License 5 votes vote down vote up
@Override
public void postDelete(final ObserverContext<RegionCoprocessorEnvironment> c,
    final Delete delete, final WALEdit edit, final Durability durability)
    throws IOException {
  if (aclRegion) {
    updateACL(c.getEnvironment(), delete.getFamilyCellMap());
  }
}
 
Example 32
Project: ditb   File: AccessController.java   Source Code and License 5 votes vote down vote up
@Override
public boolean preCheckAndDeleteAfterRowLock(
    final ObserverContext<RegionCoprocessorEnvironment> c, final byte[] row, final byte[] family,
    final byte[] qualifier, final CompareFilter.CompareOp compareOp,
    final ByteArrayComparable comparator, final Delete delete, final boolean result)
    throws IOException {
  if (delete.getAttribute(CHECK_COVERING_PERM) != null) {
    // We had failure with table, cf and q perm checks and now giving a chance for cell
    // perm check
    TableName table = c.getEnvironment().getRegion().getRegionInfo().getTable();
    Map<byte[], ? extends Collection<byte[]>> families = makeFamilyMap(family, qualifier);
    AuthResult authResult = null;
    if (checkCoveringPermission(OpType.CHECK_AND_DELETE, c.getEnvironment(), row, families,
        HConstants.LATEST_TIMESTAMP, Action.READ)) {
      authResult = AuthResult.allow(OpType.CHECK_AND_DELETE.toString(), "Covering cell set",
          getActiveUser(), Action.READ, table, families);
    } else {
      authResult = AuthResult.deny(OpType.CHECK_AND_DELETE.toString(), "Covering cell set",
          getActiveUser(), Action.READ, table, families);
    }
    logResult(authResult);
    if (authorizationEnabled && !authResult.isAllowed()) {
      throw new AccessDeniedException("Insufficient permissions " + authResult.toContextString());
    }
  }
  return result;
}
 
Example 33
Project: ditb   File: TestRegionObserverBypass.java   Source Code and License 5 votes vote down vote up
private void checkRowAndDelete(Table t, byte[] row, int count) throws IOException {
  Get g = new Get(row);
  Result r = t.get(g);
  assertEquals(count, r.size());
  Delete d = new Delete(row);
  t.delete(d);
}
 
Example 34
Project: ditb   File: TestHRegion.java   Source Code and License 5 votes vote down vote up
@Test
public void testCheckAndMutate_WithWrongValue() throws IOException {
  byte[] row1 = Bytes.toBytes("row1");
  byte[] fam1 = Bytes.toBytes("fam1");
  byte[] qf1 = Bytes.toBytes("qualifier");
  byte[] val1 = Bytes.toBytes("value1");
  byte[] val2 = Bytes.toBytes("value2");

  // Setting up region
  String method = this.getName();
  this.region = initHRegion(tableName, method, CONF, fam1);
  try {
    // Putting data in key
    Put put = new Put(row1);
    put.add(fam1, qf1, val1);
    region.put(put);

    // checkAndPut with wrong value
    boolean res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, new BinaryComparator(
        val2), put, true);
    assertEquals(false, res);

    // checkAndDelete with wrong value
    Delete delete = new Delete(row1);
    delete.deleteFamily(fam1);
    res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, new BinaryComparator(val2),
        put, true);
    assertEquals(false, res);
  } finally {
    HRegion.closeHRegion(this.region);
    this.region = null;
  }
}
 
Example 35
Project: ditb   File: TableNamespaceManager.java   Source Code and License 5 votes vote down vote up
public synchronized void remove(String name) throws IOException {
  if (get(name) == null) {
    throw new NamespaceNotFoundException(name);
  }
  if (NamespaceDescriptor.RESERVED_NAMESPACES.contains(name)) {
    throw new ConstraintException("Reserved namespace "+name+" cannot be removed.");
  }
  int tableCount;
  try {
    tableCount = masterServices.listTableDescriptorsByNamespace(name).size();
  } catch (FileNotFoundException fnfe) {
    throw new NamespaceNotFoundException(name);
  }
  if (tableCount > 0) {
    throw new ConstraintException("Only empty namespaces can be removed. " +
        "Namespace "+name+" has "+tableCount+" tables");
  }
  Delete d = new Delete(Bytes.toBytes(name));
  getNamespaceTable().delete(d);
  //don't abort if cleanup isn't complete
  //it will be replaced on new namespace creation
  zkNamespaceManager.remove(name);
  FileSystem fs = masterServices.getMasterFileSystem().getFileSystem();
  for(FileStatus status :
          fs.listStatus(FSUtils.getNamespaceDir(
              masterServices.getMasterFileSystem().getRootDir(), name))) {
    if (!HConstants.HBASE_NON_TABLE_DIRS.contains(status.getPath().getName())) {
      throw new IOException("Namespace directory contains table dir: "+status.getPath());
    }
  }
  if (!fs.delete(FSUtils.getNamespaceDir(
      masterServices.getMasterFileSystem().getRootDir(), name), true)) {
    throw new IOException("Failed to remove namespace: "+name);
  }
  this.masterServices.getMasterQuotaManager().removeNamespaceQuota(name);
}
 
Example 36
Project: ditb   File: MutationSerialization.java   Source Code and License 5 votes vote down vote up
@Override
public void serialize(Mutation mutation) throws IOException {
  MutationType type;
  if (mutation instanceof Put) {
    type = MutationType.PUT;
  } else if (mutation instanceof Delete) {
    type = MutationType.DELETE;
  } else {
    throw new IllegalArgumentException("Only Put and Delete are supported");
  }
  ProtobufUtil.toMutation(type, mutation).writeDelimitedTo(out);
}
 
Example 37
Project: ditb   File: TestHeapSize.java   Source Code and License 5 votes vote down vote up
@Test
public void testMutations(){
  Class<?> cl;
  long expected;
  long actual;

  cl = TimeRange.class;
  actual = ClassSize.TIMERANGE;
  expected  = ClassSize.estimateBase(cl, false);
  if (expected != actual) {
    ClassSize.estimateBase(cl, true);
    assertEquals(expected, actual);
  }

  byte[] row = new byte[] { 0 };
  cl = Put.class;
  actual = new Put(row).MUTATION_OVERHEAD + ClassSize.align(ClassSize.ARRAY);
  expected = ClassSize.estimateBase(cl, false);
  //The actual TreeMap is not included in the above calculation
  expected += ClassSize.align(ClassSize.TREEMAP);
  if (expected != actual) {
    ClassSize.estimateBase(cl, true);
    assertEquals(expected, actual);
  }

  cl = Delete.class;
  actual = new Delete(row).MUTATION_OVERHEAD + ClassSize.align(ClassSize.ARRAY);
  expected  = ClassSize.estimateBase(cl, false);
  //The actual TreeMap is not included in the above calculation
  expected += ClassSize.align(ClassSize.TREEMAP);
  if (expected != actual) {
    ClassSize.estimateBase(cl, true);
    assertEquals(expected, actual);
  }
}
 
Example 38
Project: ditb   File: SimpleRegionObserver.java   Source Code and License 5 votes vote down vote up
@Override
public void postDelete(final ObserverContext<RegionCoprocessorEnvironment> c, 
    final Delete delete, final WALEdit edit,
    final Durability durability) throws IOException {
  Map<byte[], List<Cell>> familyMap  = delete.getFamilyCellMap();
  RegionCoprocessorEnvironment e = c.getEnvironment();
  assertNotNull(e);
  assertNotNull(e.getRegion());
  assertNotNull(familyMap);
  ctBeforeDelete.set(0);
  ctPostDeleted.incrementAndGet();
}
 
Example 39
Project: ditb   File: BaseRegionObserver.java   Source Code and License 5 votes vote down vote up
@Override
public boolean preCheckAndDelete(final ObserverContext<RegionCoprocessorEnvironment> e,
    final byte [] row, final byte [] family, final byte [] qualifier,
    final CompareOp compareOp, final ByteArrayComparable comparator,
    final Delete delete, final boolean result) throws IOException {
  return result;
}
 
Example 40
Project: ditb   File: BaseRegionObserver.java   Source Code and License 5 votes vote down vote up
@Override
public boolean preCheckAndDeleteAfterRowLock(
    final ObserverContext<RegionCoprocessorEnvironment> e,
    final byte[] row, final byte[] family, final byte[] qualifier, final CompareOp compareOp,
    final ByteArrayComparable comparator, final Delete delete,
    final boolean result) throws IOException {
  return result;
}
 
Example 41
Project: ditb   File: Merge.java   Source Code and License 5 votes vote down vote up
private void removeRegionFromMeta(HRegion meta, HRegionInfo regioninfo)
throws IOException {
  if (LOG.isDebugEnabled()) {
    LOG.debug("Removing region: " + regioninfo + " from " + meta);
  }

  Delete delete  = new Delete(regioninfo.getRegionName(),
      System.currentTimeMillis());
  meta.delete(delete);
}
 
Example 42
Project: ditb   File: SimpleIndexKeyGenerator.java   Source Code and License 5 votes vote down vote up
@Override
public byte[] createIndexRowKey(final IndexSpecification indexSpec, final Delete delete) {
  List<KeyValue> values = delete.getFamilyMap().get(indexSpec.getFamily());

  byte[] value = null;
  for (KeyValue kv : values) {
    if (Bytes.compareTo(kv.getFamily(), indexSpec.getFamily()) == 0
        && Bytes.compareTo(kv.getQualifier(), indexSpec.getQualifier()) == 0) {
      value = kv.getValue();
      break;
    }
  }
  return createIndexRowKey(delete.getRow(), value);
}
 
Example 43
Project: ditb   File: MetaTableAccessor.java   Source Code and License 5 votes vote down vote up
/**
 * Performs an atomic multi-Mutate operation against the given table.
 */
private static void multiMutate(Table table, byte[] row, Mutation... mutations)
    throws IOException {
  CoprocessorRpcChannel channel = table.coprocessorService(row);
  MultiRowMutationProtos.MutateRowsRequest.Builder mmrBuilder
    = MultiRowMutationProtos.MutateRowsRequest.newBuilder();
  for (Mutation mutation : mutations) {
    if (mutation instanceof Put) {
      mmrBuilder.addMutationRequest(ProtobufUtil.toMutation(
        ClientProtos.MutationProto.MutationType.PUT, mutation));
    } else if (mutation instanceof Delete) {
      mmrBuilder.addMutationRequest(ProtobufUtil.toMutation(
        ClientProtos.MutationProto.MutationType.DELETE, mutation));
    } else {
      throw new DoNotRetryIOException("multi in MetaEditor doesn't support "
        + mutation.getClass().getName());
    }
  }

  MultiRowMutationProtos.MultiRowMutationService.BlockingInterface service =
    MultiRowMutationProtos.MultiRowMutationService.newBlockingStub(channel);
  try {
    service.mutateRows(null, mmrBuilder.build());
  } catch (ServiceException ex) {
    ProtobufUtil.toIOException(ex);
  }
}
 
Example 44
Project: ditb   File: RegionCoprocessorHost.java   Source Code and License 5 votes vote down vote up
/**
 * @param delete The Delete object
 * @param edit The WALEdit object.
 * @param durability The durability used
 * @return true if default processing should be bypassed
 * @exception IOException Exception
 */
public boolean preDelete(final Delete delete, final WALEdit edit, final Durability durability)
    throws IOException {
  return execOperation(coprocessors.isEmpty() ? null : new RegionOperation() {
    @Override
    public void call(RegionObserver oserver, ObserverContext<RegionCoprocessorEnvironment> ctx)
        throws IOException {
      oserver.preDelete(ctx, delete, edit, durability);
    }
  });
}
 
Example 45
Project: ditb   File: RegionCoprocessorHost.java   Source Code and License 5 votes vote down vote up
/**
 * @param delete The Delete object
 * @param edit The WALEdit object.
 * @param durability The durability used
 * @exception IOException Exception
 */
public void postDelete(final Delete delete, final WALEdit edit, final Durability durability)
    throws IOException {
  execOperation(coprocessors.isEmpty() ? null : new RegionOperation() {
    @Override
    public void call(RegionObserver oserver, ObserverContext<RegionCoprocessorEnvironment> ctx)
        throws IOException {
      oserver.postDelete(ctx, delete, edit, durability);
    }
  });
}
 
Example 46
Project: ditb   File: RegionCoprocessorHost.java   Source Code and License 5 votes vote down vote up
/**
 * @param row row to check
 * @param family column family
 * @param qualifier column qualifier
 * @param compareOp the comparison operation
 * @param comparator the comparator
 * @param delete delete to commit if check succeeds
 * @return true or false to return to client if default processing should
 * be bypassed, or null otherwise
 * @throws IOException e
 */
public Boolean preCheckAndDelete(final byte [] row, final byte [] family,
    final byte [] qualifier, final CompareOp compareOp,
    final ByteArrayComparable comparator, final Delete delete)
    throws IOException {
  return execOperationWithResult(true, false,
      coprocessors.isEmpty() ? null : new RegionOperationWithResult<Boolean>() {
    @Override
    public void call(RegionObserver oserver, ObserverContext<RegionCoprocessorEnvironment> ctx)
        throws IOException {
      setResult(oserver.preCheckAndDelete(ctx, row, family,
          qualifier, compareOp, comparator, delete, getResult()));
    }
  });
}
 
Example 47
Project: ditb   File: RegionCoprocessorHost.java   Source Code and License 5 votes vote down vote up
/**
 * @param row row to check
 * @param family column family
 * @param qualifier column qualifier
 * @param compareOp the comparison operation
 * @param comparator the comparator
 * @param delete delete to commit if check succeeds
 * @return true or false to return to client if default processing should
 * be bypassed, or null otherwise
 * @throws IOException e
 */
public Boolean preCheckAndDeleteAfterRowLock(final byte[] row, final byte[] family,
    final byte[] qualifier, final CompareOp compareOp, final ByteArrayComparable comparator,
    final Delete delete) throws IOException {
  return execOperationWithResult(true, false,
      coprocessors.isEmpty() ? null : new RegionOperationWithResult<Boolean>() {
    @Override
    public void call(RegionObserver oserver, ObserverContext<RegionCoprocessorEnvironment> ctx)
        throws IOException {
      setResult(oserver.preCheckAndDeleteAfterRowLock(ctx, row,
            family, qualifier, compareOp, comparator, delete, getResult()));
    }
  });
}
 
Example 48
Project: ditb   File: MultiThreadedUpdater.java   Source Code and License 5 votes vote down vote up
public void mutate(Table table, Mutation m,
    long keyBase, byte[] row, byte[] cf, byte[] q, byte[] v) {
  long start = System.currentTimeMillis();
  try {
    m = dataGenerator.beforeMutate(keyBase, m);
    if (m instanceof Increment) {
      table.increment((Increment)m);
    } else if (m instanceof Append) {
      table.append((Append)m);
    } else if (m instanceof Put) {
      table.checkAndPut(row, cf, q, v, (Put)m);
    } else if (m instanceof Delete) {
      table.checkAndDelete(row, cf, q, v, (Delete)m);
    } else {
      throw new IllegalArgumentException(
        "unsupported mutation " + m.getClass().getSimpleName());
    }
    totalOpTimeMs.addAndGet(System.currentTimeMillis() - start);
  } catch (IOException e) {
    if (ignoreNonceConflicts && (e instanceof OperationConflictException)) {
      LOG.info("Detected nonce conflict, ignoring: " + e.getMessage());
      totalOpTimeMs.addAndGet(System.currentTimeMillis() - start);
      return;
    }
    failedKeySet.add(keyBase);
    String exceptionInfo;
    if (e instanceof RetriesExhaustedWithDetailsException) {
      RetriesExhaustedWithDetailsException aggEx = (RetriesExhaustedWithDetailsException) e;
      exceptionInfo = aggEx.getExhaustiveDescription();
    } else {
      exceptionInfo = StringUtils.stringifyException(e);
    }
    LOG.error("Failed to mutate: " + keyBase + " after " +
        (System.currentTimeMillis() - start) +
      "ms; region information: " + getRegionDebugInfoSafe(table, m.getRow()) + "; errors: "
        + exceptionInfo);
  }
}
 
Example 49
Project: ditb   File: PerformanceEvaluation.java   Source Code and License 5 votes vote down vote up
@Override
void testRow(final int i) throws IOException {
  byte [] bytes = format(i);
  // Put a known value so when we go to check it, it is there.
  Put put = new Put(bytes);
  put.addColumn(FAMILY_NAME, getQualifier(), bytes);
  this.table.put(put);
  Delete delete = new Delete(put.getRow());
  delete.addColumn(FAMILY_NAME, getQualifier());
  this.table.checkAndDelete(bytes, FAMILY_NAME, getQualifier(), CompareOp.EQUAL, bytes, delete);
}
 
Example 50
Project: ditb   File: TestPerTableCFReplication.java   Source Code and License 5 votes vote down vote up
private void deleteAndWaitWithFamily(byte[] row, byte[] fam,
    Table source, Table... targets)
  throws Exception {
  Delete del = new Delete(row);
  del.deleteFamily(fam);
  source.delete(del);

  Get get = new Get(row);
  get.addFamily(fam);
  for (int i = 0; i < NB_RETRIES; i++) {
    if (i==NB_RETRIES-1) {
      fail("Waited too much time for del replication");
    }
    boolean removedFromAll = true;
    for (Table target : targets) {
      Result res = target.get(get);
      if (res.size() >= 1) {
        LOG.info("Row not deleted");
        removedFromAll = false;
        break;
      }
    }
    if (removedFromAll) {
      break;
    } else {
      Thread.sleep(SLEEP_TIME);
    }
  }
}
 
Example 51
Project: ditb   File: TestVisibilityLabelsWithDeletes.java   Source Code and License 5 votes vote down vote up
@Test
public void testVisibilityLabelsWithDeleteColumns() throws Throwable {
  setAuths();
  final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());

  try (Table table = createTableAndWriteDataWithLabels(tableName,
      SECRET + "&" + 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 + "&" + SECRET));
          d.addColumns(fam, qual);
          table.delete(d);
        } catch (Throwable t) {
          throw new IOException(t);
        }
        return null;
      }
    };
    SUPERUSER.runAs(actiona);

    TEST_UTIL.getHBaseAdmin().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 52
Project: ditb   File: SimpleRegionObserver.java   Source Code and License 5 votes vote down vote up
@Override
public void preDelete(final ObserverContext<RegionCoprocessorEnvironment> c, 
    final Delete delete, final WALEdit edit,
    final Durability durability) throws IOException {
  Map<byte[], List<Cell>> familyMap  = delete.getFamilyCellMap();
  RegionCoprocessorEnvironment e = c.getEnvironment();
  assertNotNull(e);
  assertNotNull(e.getRegion());
  assertNotNull(familyMap);
  if (ctBeforeDelete.get() > 0) {
    ctPreDeleted.incrementAndGet();
  }
}
 
Example 53
Project: ditb   File: TestVisibilityLabelsWithDeletes.java   Source Code and License 5 votes vote down vote up
@Test
public void testVisibilityLabelsWithDeleteFamilyVersion() throws Exception {
  setAuths();
  final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
  long[] ts = new long[] { 123l, 125l };
  try (Table table = createTableAndWriteDataWithLabels(tableName, 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.deleteFamilyVersion(fam, 123l);
          table.delete(d);
        } catch (Throwable t) {
          throw new IOException(t);
        }
        return null;
      }
    };
    SUPERUSER.runAs(actiona);

    TEST_UTIL.getHBaseAdmin().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 54
Project: ditb   File: TestVisibilityLabelsWithDeletes.java   Source Code and License 5 votes vote down vote up
@Test
public void testVisibilityLabelsWithDeleteColumnExactVersion() throws Exception {
  setAuths();
  final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
  long[] ts = new long[] { 123l, 125l };
  try (Table table = createTableAndWriteDataWithLabels(tableName, 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.addColumn(fam, qual, 123l);
          table.delete(d);
        } catch (Throwable t) {
          throw new IOException(t);
        }
        return null;
      }
    };
    SUPERUSER.runAs(actiona);

    TEST_UTIL.getHBaseAdmin().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 55
Project: ditb   File: TestMinorCompaction.java   Source Code and License 5 votes vote down vote up
@Test
public void testMinorCompactionWithDeleteColumn2() throws Exception {
  Delete dc = new Delete(secondRowBytes);
  dc.deleteColumn(fam2, col2);
  /* compactionThreshold is 3. The table has 4 versions: 0, 1, 2, and 3.
   * we only delete the latest version. One might expect to see only
   * versions 1 and 2. HBase differs, and gives us 0, 1 and 2.
   * This is okay as well. Since there was no compaction done before the
   * delete, version 0 seems to stay on.
   */
  testMinorCompactionWithDelete(dc, 3);
}
 
Example 56
Project: ditb   File: TestBlocksRead.java   Source Code and License 5 votes vote down vote up
private void deleteFamily(String family, String row, long version)
    throws IOException {
  Delete del = new Delete(Bytes.toBytes(row));
  del.deleteFamily(Bytes.toBytes(family + "_ROWCOL"), version);
  del.deleteFamily(Bytes.toBytes(family + "_ROW"), version);
  del.deleteFamily(Bytes.toBytes(family + "_NONE"), version);
  region.delete(del);
}
 
Example 57
Project: ditb   File: TestHRegion.java   Source Code and License 5 votes vote down vote up
@Test
public void testDelete_multiDeleteColumn() throws IOException {
  byte[] row1 = Bytes.toBytes("row1");
  byte[] fam1 = Bytes.toBytes("fam1");
  byte[] qual = Bytes.toBytes("qualifier");
  byte[] value = Bytes.toBytes("value");

  Put put = new Put(row1);
  put.add(fam1, qual, 1, value);
  put.add(fam1, qual, 2, value);

  String method = this.getName();
  this.region = initHRegion(tableName, method, CONF, fam1);
  try {
    region.put(put);

    // We do support deleting more than 1 'latest' version
    Delete delete = new Delete(row1);
    delete.deleteColumn(fam1, qual);
    delete.deleteColumn(fam1, qual);
    region.delete(delete);

    Get get = new Get(row1);
    get.addFamily(fam1);
    Result r = region.get(get);
    assertEquals(0, r.size());
  } finally {
    HRegion.closeHRegion(this.region);
    this.region = null;
  }
}
 
Example 58
Project: ditb   File: MetaTableAccessor.java   Source Code and License 5 votes vote down vote up
/**
 * Delete the passed <code>deletes</code> from the <code>hbase:meta</code> table.
 * @param connection connection we're using
 * @param deletes Deletes to add to hbase:meta  This list should support #remove.
 * @throws IOException
 */
public static void deleteFromMetaTable(final Connection connection, final List<Delete> deletes)
  throws IOException {
  Table t = getMetaHTable(connection);
  try {
    t.delete(deletes);
  } finally {
    t.close();
  }
}
 
Example 59
Project: ditb   File: TestCellACLWithMultipleVersions.java   Source Code and License 5 votes vote down vote up
private AccessTestAction getDeleteFamilyAction(final byte[] fam) {
  AccessTestAction deleteFamilyAction = new AccessTestAction() {
    @Override
    public Object run() throws Exception {
      Delete delete = new Delete(TEST_ROW).addFamily(fam);
      try (Connection connection = ConnectionFactory.createConnection(conf)) {
        try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
          t.delete(delete);
        }
      }
      return null;
    }
  };
  return deleteFamilyAction;
}
 
Example 60
Project: ditb   File: RemoteHTable.java   Source Code and License 5 votes vote down vote up
@Override
public boolean checkAndDelete(byte[] row, byte[] family, byte[] qualifier,
    byte[] value, Delete delete) throws IOException {
  Put put = new Put(row);
  put.setFamilyCellMap(delete.getFamilyCellMap());
  // column to check-the-value
  put.add(new KeyValue(row, family, qualifier, value));
  CellSetModel model = buildModelFromPut(put);
  StringBuilder sb = new StringBuilder();
  sb.append('/');
  sb.append(Bytes.toStringBinary(name));
  sb.append('/');
  sb.append(Bytes.toStringBinary(row));
  sb.append("?check=delete");

  for (int i = 0; i < maxRetries; i++) {
    Response response = client.put(sb.toString(),
      Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput());
    int code = response.getCode();
    switch (code) {
    case 200:
      return true;
    case 304: // NOT-MODIFIED
      return false;
    case 509:
      try {
        Thread.sleep(sleepTime);
      } catch (final InterruptedException e) {
        throw (InterruptedIOException)new InterruptedIOException().initCause(e);
      }
      break;
    default:
      throw new IOException("checkAndDelete request failed with " + code);
    }
  }
  throw new IOException("checkAndDelete request timed out");
}