Search in sources :

Example 1 with LockClientStoppedException

use of org.neo4j.kernel.impl.locking.LockClientStoppedException in project neo4j by neo4j.

the class ForsetiClient method tryUpgradeToExclusiveWithShareLockHeld.

/** Attempt to upgrade a share lock that we hold to an exclusive lock. */
private boolean tryUpgradeToExclusiveWithShareLockHeld(LockTracer tracer, LockWaitEvent priorEvent, ResourceType resourceType, long resourceId, SharedLock sharedLock, int tries, long waitStartMillis) throws AcquireLockTimeoutException {
    if (sharedLock.tryAcquireUpdateLock(this)) {
        LockWaitEvent waitEvent = null;
        try {
            // Now we just wait for all clients to release the the share lock
            while (sharedLock.numberOfHolders() > 1) {
                assertValid(waitStartMillis, resourceType, resourceId);
                if (waitEvent == null && priorEvent == null) {
                    waitEvent = tracer.waitForLock(true, resourceType, resourceId);
                }
                applyWaitStrategy(resourceType, tries++);
                markAsWaitingFor(sharedLock, resourceType, resourceId);
            }
            return true;
        } catch (DeadlockDetectedException e) {
            sharedLock.releaseUpdateLock();
            // markAsWaitingFor() before throwing DeadlockDetectedException
            throw e;
        } catch (LockClientStoppedException e) {
            handleUpgradeToExclusiveFailure(sharedLock);
            throw e;
        } catch (Throwable e) {
            handleUpgradeToExclusiveFailure(sharedLock);
            throw new RuntimeException(e);
        } finally {
            if (waitEvent != null) {
                waitEvent.close();
            }
        }
    }
    return false;
}
Also used : LockClientStoppedException(org.neo4j.kernel.impl.locking.LockClientStoppedException) DeadlockDetectedException(org.neo4j.kernel.DeadlockDetectedException) LockWaitEvent(org.neo4j.kernel.impl.locking.LockWaitEvent)

Aggregations

DeadlockDetectedException (org.neo4j.kernel.DeadlockDetectedException)1 LockClientStoppedException (org.neo4j.kernel.impl.locking.LockClientStoppedException)1 LockWaitEvent (org.neo4j.kernel.impl.locking.LockWaitEvent)1