Search in sources :

Example 11 with DeadlockDetectedException

use of org.neo4j.kernel.DeadlockDetectedException in project neo4j by neo4j.

the class Neo4jErrorTest method shouldConvertDeadlockException.

@Test
public void shouldConvertDeadlockException() throws Throwable {
    // When
    Neo4jError error = Neo4jError.from(new DeadlockDetectedException(null));
    // Then
    assertEquals(error.status(), Status.Transaction.DeadlockDetected);
}
Also used : DeadlockDetectedException(org.neo4j.kernel.DeadlockDetectedException) Test(org.junit.Test)

Example 12 with DeadlockDetectedException

use of org.neo4j.kernel.DeadlockDetectedException in project neo4j by neo4j.

the class MasterImpl method acquireExclusiveLock.

@Override
public Response<LockResult> acquireExclusiveLock(RequestContext context, ResourceType type, long... resourceIds) {
    assertCorrectEpoch(context);
    Locks.Client session;
    try {
        session = conversationManager.acquire(context).getLocks();
    } catch (NoSuchEntryException | ConcurrentAccessException e) {
        return spi.packTransactionObligationResponse(context, new LockResult(LockStatus.NOT_LOCKED, "Unable to acquire exclusive lock: " + e.getMessage()));
    }
    try {
        for (long resourceId : resourceIds) {
            session.acquireExclusive(LockTracer.NONE, type, resourceId);
        }
        return spi.packTransactionObligationResponse(context, new LockResult(LockStatus.OK_LOCKED));
    } catch (DeadlockDetectedException e) {
        return spi.packTransactionObligationResponse(context, new LockResult(LockStatus.DEAD_LOCKED, "Can't acquire exclusive lock, because it would have caused a deadlock: " + e.getMessage()));
    } catch (IllegalResourceException e) {
        return spi.packTransactionObligationResponse(context, new LockResult(LockStatus.NOT_LOCKED, "Attempted to lock illegal resource: " + e.getMessage()));
    } finally {
        conversationManager.release(context);
    }
}
Also used : LockResult(org.neo4j.kernel.ha.lock.LockResult) DeadlockDetectedException(org.neo4j.kernel.DeadlockDetectedException) NoSuchEntryException(org.neo4j.kernel.impl.util.collection.NoSuchEntryException) Locks(org.neo4j.kernel.impl.locking.Locks) ConcurrentAccessException(org.neo4j.kernel.impl.util.collection.ConcurrentAccessException) IllegalResourceException(org.neo4j.kernel.impl.transaction.IllegalResourceException)

Example 13 with DeadlockDetectedException

use of org.neo4j.kernel.DeadlockDetectedException in project neo4j by neo4j.

the class MasterImpl method acquireSharedLock.

@Override
public Response<LockResult> acquireSharedLock(RequestContext context, ResourceType type, long... resourceIds) {
    assertCorrectEpoch(context);
    Locks.Client session;
    try {
        session = conversationManager.acquire(context).getLocks();
    } catch (NoSuchEntryException | ConcurrentAccessException e) {
        return spi.packTransactionObligationResponse(context, new LockResult(LockStatus.NOT_LOCKED, "Unable to acquire shared lock: " + e.getMessage()));
    }
    try {
        for (long resourceId : resourceIds) {
            session.acquireShared(LockTracer.NONE, type, resourceId);
        }
        return spi.packTransactionObligationResponse(context, new LockResult(LockStatus.OK_LOCKED));
    } catch (DeadlockDetectedException e) {
        return spi.packTransactionObligationResponse(context, new LockResult(LockStatus.DEAD_LOCKED, e.getMessage()));
    } catch (IllegalResourceException e) {
        return spi.packTransactionObligationResponse(context, new LockResult(LockStatus.NOT_LOCKED, "Attempted to lock illegal resource: " + e.getMessage()));
    } finally {
        conversationManager.release(context);
    }
}
Also used : LockResult(org.neo4j.kernel.ha.lock.LockResult) DeadlockDetectedException(org.neo4j.kernel.DeadlockDetectedException) NoSuchEntryException(org.neo4j.kernel.impl.util.collection.NoSuchEntryException) Locks(org.neo4j.kernel.impl.locking.Locks) ConcurrentAccessException(org.neo4j.kernel.impl.util.collection.ConcurrentAccessException) IllegalResourceException(org.neo4j.kernel.impl.transaction.IllegalResourceException)

Example 14 with DeadlockDetectedException

use of org.neo4j.kernel.DeadlockDetectedException in project graphdb by neo4j-attic.

the class SlaveLockManager method getReadLock.

@Override
public void getReadLock(Object resource) throws DeadlockDetectedException, IllegalResourceException {
    try {
        Node node = resource instanceof Node ? (Node) resource : null;
        Relationship relationship = resource instanceof Relationship ? (Relationship) resource : null;
        if (node == null && relationship == null) {
            // This is a "fake" resource, only grab the lock locally
            super.getReadLock(resource);
            return;
        }
        //            if ( hasAlreadyGotLock() )
        //            {
        //                return;
        //            }
        LockResult result = null;
        do {
            int eventIdentifier = getLocalTxId();
            result = node != null ? receiver.receive(broker.getMaster().first().acquireNodeReadLock(receiver.getSlaveContext(eventIdentifier), node.getId())) : receiver.receive(broker.getMaster().first().acquireRelationshipReadLock(receiver.getSlaveContext(eventIdentifier), relationship.getId()));
            switch(result.getStatus()) {
                case OK_LOCKED:
                    super.getReadLock(resource);
                    return;
                case DEAD_LOCKED:
                    throw new DeadlockDetectedException(result.getDeadlockMessage());
            }
        } while (result.getStatus() == LockStatus.NOT_LOCKED);
    } catch (ZooKeeperException e) {
        receiver.newMaster(null, e);
        throw e;
    } catch (ComException e) {
        receiver.newMaster(null, e);
        throw e;
    }
}
Also used : ZooKeeperException(org.neo4j.kernel.ha.zookeeper.ZooKeeperException) ComException(org.neo4j.com.ComException) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) DeadlockDetectedException(org.neo4j.kernel.DeadlockDetectedException)

Aggregations

DeadlockDetectedException (org.neo4j.kernel.DeadlockDetectedException)14 Test (org.junit.Test)6 LockResult (org.neo4j.kernel.ha.lock.LockResult)4 Node (org.neo4j.graphdb.Node)3 IllegalResourceException (org.neo4j.kernel.impl.transaction.IllegalResourceException)3 ComException (org.neo4j.com.ComException)2 RequestContext (org.neo4j.com.RequestContext)2 Relationship (org.neo4j.graphdb.Relationship)2 Config (org.neo4j.kernel.configuration.Config)2 DefaultConversationSPI (org.neo4j.kernel.ha.cluster.DefaultConversationSPI)2 SPI (org.neo4j.kernel.ha.com.master.MasterImpl.SPI)2 ZooKeeperException (org.neo4j.kernel.ha.zookeeper.ZooKeeperException)2 Locks (org.neo4j.kernel.impl.locking.Locks)2 Client (org.neo4j.kernel.impl.locking.Locks.Client)2 ResourceTypes (org.neo4j.kernel.impl.locking.ResourceTypes)2 TransactionalContext (org.neo4j.kernel.impl.query.TransactionalContext)2 ConcurrentAccessException (org.neo4j.kernel.impl.util.collection.ConcurrentAccessException)2 NoSuchEntryException (org.neo4j.kernel.impl.util.collection.NoSuchEntryException)2 IOException (java.io.IOException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1