@Override
public void mutateRowTs(ByteBuffer tableName, ByteBuffer row,
List<Mutation> mutations, long timestamp,
Map<ByteBuffer, ByteBuffer> attributes)
throws IOError, IllegalArgument {
HTable table = null;
try {
table = getTable(tableName);
Put put = new Put(getBytes(row), timestamp, null);
addAttributes(put, attributes);
Delete delete = new Delete(getBytes(row));
addAttributes(delete, attributes);
if (metrics != null) {
metrics.incNumRowKeysInBatchMutate(mutations.size());
}
// I apologize for all this mess :)
for (Mutation m : mutations) {
byte[][] famAndQf = KeyValue.parseColumn(getBytes(m.column));
if (m.isDelete) {
if (famAndQf.length == 1) {
delete.deleteFamily(famAndQf[0], timestamp);
} else {
delete.deleteColumns(famAndQf[0], famAndQf[1], timestamp);
}
delete.setWriteToWAL(m.writeToWAL);
} else {
if(famAndQf.length == 1) {
put.add(famAndQf[0], HConstants.EMPTY_BYTE_ARRAY,
m.value != null ? getBytes(m.value)
: HConstants.EMPTY_BYTE_ARRAY);
} else {
put.add(famAndQf[0], famAndQf[1],
m.value != null ? getBytes(m.value)
: HConstants.EMPTY_BYTE_ARRAY);
}
put.setWriteToWAL(m.writeToWAL);
}
}
if (!delete.isEmpty())
table.delete(delete);
if (!put.isEmpty())
table.put(put);
} catch (IOException e) {
LOG.warn(e.getMessage(), e);
throw new IOError(e.getMessage());
} catch (IllegalArgumentException e) {
LOG.warn(e.getMessage(), e);