本文介绍了HBase批处理操作是否是原子的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  //创建一个Puts列表,并通过HTable的批处理方法保存在HBase中
HTable table = new HTable(HBaseConfiguration.create(),'table_name');
列表< Row> actions = new ArrayList< Row>();
actions.add(put1); // rowkey ='abc'
actions.add(put2); // rowkey ='def'
actions.add(put3); // rowkey ='ghi'
Object [] results = table.batch(actions);

是否有可能导致至少有一次(但不是全部)投入失败以保存到HBase?换句话说,是批次确保自动发生,其中所有 puts 都被保存,或者它们都不是全部?



如果 batch 无法保证这一点,我们如何识别哪些投入成功,哪些失败?或者,我们至少可以确定某些事情失败了,这会告诉我们要删除我们试图保存的所有行,以便将它们回滚?



当我投射结果到 Result 并打印出来,它返回 keyvalues = NONE ,但我可以看到我的puts成功。

解决方案

来自hbase client api文档:

code> public void batch(List< ;? extends Row> actions,Object [] results)

动作获取,放置,删除,增量,追加列表

objectsresults 空对象[],大小相同作为行动。提供对部分结果的访问,以防引发异常。结果数组中的空值意味着即使在重试之后,该操作的调用仍然失败



您可以检查每个结果是否成功,批处理操作在设计中并不是事务性的,行变异操作可能发生在不同的区域服务器上,因此不同的wal文件,所以它不能是事务性的,还有一些开源项目试图做到这一点,检查结果并回滚成功的项目。

// Create a list of Puts, and save in HBase via HTable's batch method
HTable table = new HTable(HBaseConfiguration.create(), 'table_name');
List<Row> actions = new ArrayList<Row>();
actions.add(put1); //rowkey = 'abc'
actions.add(put2); //rowkey = 'def'
actions.add(put3); //rowkey = 'ghi'
Object[] results = table.batch(actions);

Is it possible that this snippit could result in at least one, but not all, of the puts failing to to save to HBase? In other words, is batch guarenteed to happen atomically, where either all the puts are saved, or none of them all?

If batch cannot guarantee this, how can we identify which of the puts succeeded and which failed? Or, can we at least identify that something failed, which would tell us to go delete all the rows we tried to save in order to roll them back?

When I cast the results to Result and print them out, it returns keyvalues=NONE, but I can see that my puts succeeded.

解决方案

From hbase client api docs :

public void batch(List<? extends Row> actions, Object[] results)

actions list of Get, Put, Delete, Increment, Append

objectsresults Empty Object[], same size as actions. Provides access to partial results, in case an exception is thrown. A null in the result array means that the call for that action failed, even after retries

You can check if every result is success as you sad in your question, other than batch operations are not transactional in hbase by design, row mutating operations may happen different regions servers, thus different wal files, so it can not be transactional, there are some opensource project trying to make this happen as checking results and rolling back successful ones too.

这篇关于HBase批处理操作是否是原子的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 20:43