public void remove(Session session, Row row) {
remove(session, row, false);
}
public void remove(Session session, Row row, boolean isUndo) {
HBaseRow hr = (HBaseRow) row;
if (hr.isForUpdate()) //Update这种类型的SQL不需要先删除再insert,只需直接insert即可
return;
try {
HBaseSession hs = (HBaseSession) session;
if (isUndo) {
Put oldPut = hr.getPut();
//撤消前面的add或remove操作
if (oldPut != null) {
Delete delete = new Delete(oldPut.getRow());
for (Map.Entry<byte[], List<KeyValue>> e : oldPut.getFamilyMap().entrySet()) {
for (KeyValue kv : e.getValue()) {
delete.deleteColumn(e.getKey(), kv.getQualifier(), kv.getTimestamp());
}
}
hs.getRegionServer().delete(hr.getRegionName(), delete);
} else
throw DbException.throwInternalError("oldPut is null???");
} else {
//正常的delete语句,
//这种场景会把要删除的记录找出来,此时用Put的方式,不能直接用Delete,因为用Delete后如果当前事务未提交
//那么其它并发事务就找不到之前的记录版本
Result result = hr.getResult();
if (result != null) {
Put put = hs.getTransaction().createHBasePutWithDeleteTag(defaultColumnFamilyName, result.getRow());
for (KeyValue kv : result.list()) {
if (Bytes.equals(kv.getQualifier(), HBaseConstants.TRANSACTION_META) //
&& Bytes.equals(kv.getFamily(), defaultColumnFamilyName))
continue;
put.add(kv.getFamily(), kv.getQualifier(), null);
}
hs.getRegionServer().put(hr.getRegionName(), put);
hr.setPut(put);
} else
throw DbException.throwInternalError("result is null???");
}
} catch (IOException e) {
throw DbException.convert(e);