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);
}
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);
}
}
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);
}
}
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;
}
}
Aggregations