问题
HBase supports single row atomic transaction.
For checking that practically. I had written the following code
Increment inc=new Increment();//For writing it to WAL
inc.getWritetoWAL();
Put p = new Put(Bytes.toBytes("name10"));
p.add(Bytes.toBytes("cf"), Bytes.toBytes("name"),Bytes.toBytes("Some Value 10"));
table.setAutoFlush(false);
table.put(p);
table.close();
To Check the recovery i had stopped the hbase immediately after executing(debugging in eclipse) the table.put(p) when i restarted the hbase the new row is not updated in the table. As per the documentation in HBase once it has written into memstore(cache) it can be recovered although crash happens but here it's not recovering although WAL has been enabled.....
Is there any wrong in my understanding.....
Thanx in advance for the replies.....
回答1:
What happens with your code above is that the client never gets to submit the put to the server so HBase never writes it to the WAL not it can recover...
You have table.setAutoFlush(false) in the line above the put. If you check out the documentation it says:
"When performing a lot of Puts, make sure that setAutoFlush is set to false on your HTable instance. Otherwise, the Puts will be sent one at a time to the RegionServer. Puts added via htable.add(Put) and htable.add( Put) wind up in the same write buffer. If autoFlush = false, these messages are not sent until the write-buffer is filled. To explicitly flush the messages, call flushCommits. Calling close on the HTable instance will invoke flushCommits."
So while normally setting AutoFlush to false is good in this case it means the put isn't sent to the server yet.
来源:https://stackoverflow.com/questions/15427857/recovery-in-hbase