private void getLock(SimpleKVTransaction tx, byte[] minKey, byte[] maxKey, boolean write) {
LockManager.LockResult lockResult;
try {
lockResult = this.lockManager.lock(tx.lockOwner, minKey, maxKey, write, tx.waitTimeout);
} catch (InterruptedException e) {
this.rollback(tx);
Thread.currentThread().interrupt();
throw new RetryTransactionException(tx, "transaction interrupted while waiting to acquire lock", e);
}
switch (lockResult) {
case SUCCESS:
break;
case WAIT_TIMEOUT_EXPIRED:
this.rollback(tx);
throw new RetryTransactionException(tx, "could not acquire lock after " + tx.waitTimeout + "ms");
case HOLD_TIMEOUT_EXPIRED:
this.rollback(tx);
throw new TransactionTimeoutException(tx,
"transaction taking too long: hold timeout of " + this.lockManager.getHoldTimeout() + "ms has expired");
default:
throw new RuntimeException("internal error");
}
}