result.useLock,
locker.getTxnTimeOut(),
locker.getTxnStartMillis(),
System.currentTimeMillis(),
database);
throw new DeadlockException(errMsg);
}
}
boolean keepTime = (timeout > 0);
long startTime = (keepTime ? System.currentTimeMillis() : 0);
while (doWait) {
locker.setWaitingFor(result.useLock);
try {
locker.wait(timeout);
} catch (InterruptedException IE) {
throw new RunRecoveryException(envImpl, IE);
}
boolean lockerTimedOut = locker.isTimedOut();
long now = System.currentTimeMillis();
boolean thisLockTimedOut =
(keepTime && (now - startTime > timeout));
boolean isRestart =
(result.lockGrant == LockGrantType.WAIT_RESTART);
/*
* Re-check for ownership of the lock following wait. If
* we timed out and we don't have ownership then flush this
* lock from both the waiters and owners while under the
* lock table latch. See SR 10103.
*/
if (validateOwnership(nid, locker, type,
lockerTimedOut ||
thisLockTimedOut ||
isRestart,
memoryBudget)) {
break;
} else {
/*
* After a restart conflict the lock will not be held.
*/
if (isRestart) {
throw rangeRestartException;
}
if (thisLockTimedOut) {
locker.setOnlyAbortable();
String errMsg =
makeTimeoutMsg("Lock", locker, nodeId, type,
result.lockGrant,
result.useLock,
timeout, startTime, now,
database);
throw new DeadlockException(errMsg);
}
if (lockerTimedOut) {
locker.setOnlyAbortable();
String errMsg =
makeTimeoutMsg("Transaction", locker,
nodeId, type,
result.lockGrant,
result.useLock,
locker.getTxnTimeOut(),
locker.getTxnStartMillis(),
now, database);
throw new DeadlockException(errMsg);
}
}
}
} finally {
locker.setWaitingFor(null);