Hbase中关于表中数据的添加(修改)的方法,常用的是void put(Put put),没有返回值
但是如果put了相同的数据,那么就会报错,其实不是很友好
所以,还有checkAndPut()方法
* Atomically checks if a row/family/qualifier value matches the expected
* value. If it does, it adds the put. If the passed value is null, the check
* is for the lack of column (ie: non-existance)
boolean checkAndPut(byte[] row, byte[] family, byte[] qualifier,
byte[] value, Put put) throws IOException
该方法会先进行校验,如果数据(row,family,qualifier,value)存在,则不会执行put,并返回false,否则,就会执行,返回true
因此,该方法相比于put()方法会安全一些。
本文探讨了HBase中用于数据写入的两种方法:put()与checkAndPut()。put()方法直接写入数据,若遇到重复数据将引发错误。而checkAndPut()则在写入前检查数据是否存在,确保数据一致性,提供更安全的写入操作。
899

被折叠的 条评论
为什么被折叠?



