简体   繁体   中英

Are HBase Batch Operations Atomic?

// 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM