hbase:如何确定您的delete调用是否实际删除了一行?

chy5wohz  于 2021-06-10  发布在  Hbase
关注(0)|答案(1)|浏览(447)

在hbase1.x中,表对象上有一个delete方法,允许您删除整行。但是,不管该行是否在表中,它都“成功”(没有返回值)。有没有办法确定行是否已被hbase中对table.delete的特定调用删除?
我认为checkanddelete可能适合这种情况,例如,首先检查行是否存在。像这样:

boolean deleted = false;
try (Table table = getTable(TABLE_NAME)) {
  byte[] rowKey = Bytes.toBytes(rowId);
  deleted = table.checkAndDelete(???, new Delete(rowKey));
} catch (Exception e) {
  // handle exceptions here
}
// here I know if the row was deleted or not

我不确定在“??”部分加什么条件。我试着检查列值(我知道存在)是否为空,但没有效果。为了达到同样的效果,我不得不用两个调用替换checkanddelete(exists,然后delete):

if (table.exists(new Get(rowKey))) {
    table.delete(new Delete(rowKey));
    deleted = true;  // row deleted
  }

一个原子呼叫就更好了。肯定有人做过类似的事情。

lsmepo6l

lsmepo6l1#

有没有办法确定行是否已被hbase中对table.delete的特定调用删除?
我们在splice machine(开源)上使用更高级别的sql层,但是如果您想一下delete是什么,那么它是一个扫描,然后是一个delete(批处理puts用于逻辑删除,批处理deletes用于物理删除)。
支票和付款解释如下。。。

/**
   * Atomically checks if a row/family/qualifier value matches the expected
   * value. If it does, it adds the put.  If the passed value is null, the check
   * is for the lack of column (ie: non-existance)
   *
   * @param row to check
   * @param family column family to check
   * @param qualifier column qualifier to check
   * @param value the expected value
   * @param put data to put if check succeeds
   * @throws IOException e
   * @return true if the new put was executed, false otherwise
   */

您可以随时启动协处理器调用来覆盖现有功能。你可以作为观察者或终点来做。

相关问题