waitingLock.clearPotentiallyGranted();
willQuitWait =
(wakeupReason != Constants.WAITING_LOCK_GRANT);
StandardException deadlockException = null;
if (((wakeupReason == Constants.WAITING_LOCK_IN_WAIT) &&
deadlockWait) ||
(wakeupReason == Constants.WAITING_LOCK_DEADLOCK))
{
// check for a deadlock, even if we were woken up
// because we were selected as a victim we still
// check because the situation may have changed.
deadlockData =
Deadlock.look(
factory, this, control, waitingLock,
wakeupReason);
if (deadlockData == null) {
// we don't have a deadlock
deadlockWait = false;
actualTimeout = timeout;
startWaitTime = 0;
willQuitWait = false;
} else {
willQuitWait = true;
}
}
nextWaitingLock =
control.getNextWaiter(
waitingLock, willQuitWait, this);
// If we were not woken by another then we have
// timed out. Either deadlock out or timeout
if (willQuitWait) {
// Even if we deadlocked trying to get the lock,
// still reget the latch so that client's need not
// know latch was released.
if (latch != null) {
lockObject(
compatabilitySpace, latch.getLockable(),
latch.getQualifier(),
C_LockFactory.WAIT_FOREVER, (Latch) null);
}
if (SanityManager.DEBUG)
{
if (SanityManager.DEBUG_ON("DeadlockTrace"))
{
SanityManager.showTrace(new Throwable());
// The following dumps the lock table as it
// exists at the time a timeout is about to
// cause a deadlock exception to be thrown.
lockDebug =
DiagnosticUtil.toDiagString(waitingLock) +
"\nGot deadlock/timeout, here's the table" +
this.toDebugString();
}
}
if (deadlockTrace && (deadlockData == null))
{
// if ending lock request due to lock timeout
// want a copy of the LockTable and the time,
// in case of deadlock deadlockData has the
// info we need.
currentTime = System.currentTimeMillis();
timeoutLockTable =
factory.makeVirtualLockTable();
}
}
} // synchronized block
// need to do this outside of the synchronized block as the
// message text building (timeouts and deadlocks) may
// involve getting locks to look up table names from
// identifiers.
if (willQuitWait)
{
if (SanityManager.DEBUG)
{
if (lockDebug != null)
{
String type =
((deadlockData != null) ?
"deadlock:" : "timeout:");
SanityManager.DEBUG_PRINT(
type,
"wait on lockitem caused " + type +
lockDebug);
}
}
if (deadlockData == null)
{
// ending wait because of lock timeout.
if (deadlockTrace)
{
// Turn ON derby.locks.deadlockTrace to build
// the lockTable.
throw Timeout.buildException(
waitingLock, timeoutLockTable, currentTime);
}
else
{
StandardException se =
StandardException.newException(
SQLState.LOCK_TIMEOUT);
throw se;
}