我有保存到HBase HTABLE的代码。预期的行为是该表将每个分区的提交或“刷新”提交到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。
发布于 2015-07-11 11:57:32
您需要将autoFlush设置为false参见http://hbase.apache.org/0.94/book/perf.writing.html中的11.7.4节
发布于 2016-01-06 03:29:48
在新的API中,使用了BufferedMutator。
您可以将Table t = connection.getTable(TableName.valueOf("foo"))改为BufferedMutator t = connection.getBufferedMutator(TableName.valueOf("foo"))。然后将t.put(p);更改为t.mutate(p);
这对我有用!
在我搜索的时候,几乎没有关于这方面的信息,甚至在官方文件中也是如此。希望我的回答是有帮助的,有人可以更新文件。
发布于 2015-07-11 21:19:51
您不需要做任何事情,因为您的DONT想在客户端缓冲放置。By default, HBase client will not buffer the PUTS at client side.
只有当客户端处理何时向HBase RegionServers发送数据时,才需要显式调用HBase()。
https://stackoverflow.com/questions/31356639
复制相似问题