如何在 HBase 中设置 autoflush=false table

How to set autoflush=false in HBase table

我有保存到 HBase HTABLE 的代码。预期的行为是 table 将为每个分区将提交或 "flush" 推送到 hbase。

注意:这是更新后的代码

rdd.foreachPartition(p => {
  val table = connection.getTable(TableName.valueOf(HTABLE))
  val mutator = connection.getBufferedMutator(TableName.valueOf(HTABLE))

  p.foreach(row => {
    val hRow = new Put(rowkey)
    hRow.addColumn....
    // use table.exists instead of table.checkAndPut (in favor of BufferedMutator's flushCommits)
    val exists = table.exists(new Get(rowkey))
    if (!exists) {
      hRow.addColumn...
    }
    mutator.mutate(hRow)
  })
  table.close()
  mutator.flush()
  mutator.close()
})

在 HBase 1.1 中,HTable 已弃用,org.apache.hadoop.hbase.client.Table 中没有可用的 flushCommits()。

替换 BufferedMutator.mutate(put) 对于普通 put 是可以的,但是 mutator 没有任何类似于 Table.

的 checkAndPut

您需要将 autoFlush 设置为 false 参见第 11.7.4 节 在 http://hbase.apache.org/0.94/book/perf.writing.html

您不需要执行任何操作,因为您DONT 想在客户端缓冲放置。 By default, HBase client will not buffer the PUTS at client side.

仅当客户端处理何时向 HBase RegionServers 发送数据时才需要显式调用 flushCommits()。

在新的API中,使用了BufferedMutator

您可以将 Table t = connection.getTable(TableName.valueOf("foo")) 更改为 BufferedMutator t = connection.getBufferedMutator(TableName.valueOf("foo"))。然后将 t.put(p); 更改为 t.mutate(p);

对我有用!

我搜索的时候,连官方文档都没有。希望我的回答对你有帮助,有人可以更新文档。