@Override
public void commitPrimary(HaeinsaRowTransaction rowTxState, byte[] row) throws IOException {
byte[] currentRowLockBytes = TRowLocks.serialize(rowTxState.getCurrent());
HaeinsaTransaction transaction = rowTxState.getTableTransaction().getTransaction();
long commitTimestamp = transaction.getCommitTimestamp();
TRowLock newRowLock = rowTxState.getCurrent().deepCopy();
newRowLock.setCommitTimestamp(commitTimestamp);
newRowLock.setState(TRowLockState.COMMITTED);
// if tx is already committed, we can't change current timestamp.
if (rowTxState.getCurrent().getState() != TRowLockState.COMMITTED) {
newRowLock.setCurrentTimestamp(newRowLock.getCurrentTimestamp() + 1);
}
// make prewritten to null
newRowLock.setPrewrittenIsSet(false);
// extend expiry by ROW_LOCK_TIMEOUT
newRowLock.setExpiry(transaction.getExpiry());
byte[] newRowLockBytes = TRowLocks.serialize(newRowLock);
Put put = new Put(row);
put.add(LOCK_FAMILY, LOCK_QUALIFIER, newRowLock.getCurrentTimestamp(), newRowLockBytes);
if (!table.checkAndPut(row, LOCK_FAMILY, LOCK_QUALIFIER, currentRowLockBytes, put)) {
// We don't need abort current transaction. Because the transaction is already aborted.
// Consider as conflict because another transaction might acquire lock of primary row.
throw new ConflictException("can't acquire primary row's lock");