use of org.neo4j.kernel.DeadlockDetectedException in project neo4j by neo4j.
the class MasterImplTest method lockResultMustHaveMessageWhenAcquiringSharedLockDeadlocks.
@Test
public void lockResultMustHaveMessageWhenAcquiringSharedLockDeadlocks() throws Exception {
MasterImpl.SPI spi = mockedSpi();
DefaultConversationSPI conversationSpi = mockedConversationSpi();
Config config = config();
ConversationManager conversationManager = new ConversationManager(conversationSpi, config);
conversationManager.start();
Client locks = mock(Client.class);
MasterImpl master = new MasterImpl(spi, conversationManager, null, config);
RequestContext context = createRequestContext(master);
when(conversationSpi.acquireClient()).thenReturn(locks);
ResourceTypes type = ResourceTypes.NODE;
doThrow(new DeadlockDetectedException("")).when(locks).acquireExclusive(LockTracer.NONE, type, 1);
master.acquireSharedLock(context, type, 1);
ArgumentCaptor<LockResult> captor = ArgumentCaptor.forClass(LockResult.class);
verify(spi).packTransactionObligationResponse(argThat(is(context)), captor.capture());
assertThat(captor.getValue().getMessage(), is(not(nullValue())));
}
use of org.neo4j.kernel.DeadlockDetectedException in project neo4j by neo4j.
the class TransactionHandleTest method deadlockExceptionHasCorrectStatus.
@Test
@SuppressWarnings("unchecked")
public void deadlockExceptionHasCorrectStatus() throws Exception {
// given
QueryExecutionEngine executionEngine = mock(QueryExecutionEngine.class);
when(executionEngine.executeQuery(anyString(), anyMap(), any(TransactionalContext.class))).thenThrow(new DeadlockDetectedException("deadlock"));
GraphDatabaseQueryService queryService = mock(GraphDatabaseQueryService.class);
TransactionHandle handle = new TransactionHandle(mockKernel(), executionEngine, queryService, mock(TransactionRegistry.class), uriScheme, true, AUTH_DISABLED, anyLong(), NullLogProvider.getInstance());
ExecutionResultSerializer output = mock(ExecutionResultSerializer.class);
// when
handle.execute(statements(new Statement("query", map(), false, (ResultDataContent[]) null)), output, mock(HttpServletRequest.class));
// then
verify(output).errors(argThat(hasErrors(Status.Transaction.DeadlockDetected)));
}
use of org.neo4j.kernel.DeadlockDetectedException 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;
}
use of org.neo4j.kernel.DeadlockDetectedException in project neo4j by neo4j.
the class TransactionHandle method executeStatements.
private void executeStatements(StatementDeserializer statements, ExecutionResultSerializer output, List<Neo4jError> errors, HttpServletRequest request) {
try {
boolean hasPrevious = false;
while (statements.hasNext()) {
Statement statement = statements.next();
try {
boolean hasPeriodicCommit = engine.isPeriodicCommit(statement.statement());
if ((statements.hasNext() || hasPrevious) && hasPeriodicCommit) {
throw new QueryExecutionKernelException(new InvalidSemanticsException("Cannot execute another statement after executing " + "PERIODIC COMMIT statement in the same transaction"));
}
if (!hasPrevious && hasPeriodicCommit) {
context.closeTransactionForPeriodicCommit();
}
hasPrevious = true;
TransactionalContext tc = txManagerFacade.create(request, queryService, type, securityContext, statement.statement(), statement.parameters());
Result result = safelyExecute(statement, hasPeriodicCommit, tc);
output.statementResult(result, statement.includeStats(), statement.resultDataContents());
output.notifications(result.getNotifications());
} catch (KernelException | CypherException | AuthorizationViolationException | WriteOperationsNotAllowedException e) {
errors.add(new Neo4jError(e.status(), e));
break;
} catch (DeadlockDetectedException e) {
errors.add(new Neo4jError(Status.Transaction.DeadlockDetected, e));
} catch (IOException e) {
errors.add(new Neo4jError(Status.Network.CommunicationError, e));
break;
} catch (Exception e) {
Throwable cause = e.getCause();
if (cause instanceof Status.HasStatus) {
errors.add(new Neo4jError(((Status.HasStatus) cause).status(), cause));
} else {
errors.add(new Neo4jError(Status.Statement.ExecutionFailed, e));
}
break;
}
}
addToCollection(statements.errors(), errors);
} catch (Throwable e) {
errors.add(new Neo4jError(Status.General.UnknownError, e));
}
}
use of org.neo4j.kernel.DeadlockDetectedException in project graphdb by neo4j-attic.
the class MasterImpl method acquireLock.
private <T extends PropertyContainer> Response<LockResult> acquireLock(SlaveContext context, LockGrabber lockGrabber, T... entities) {
Transaction otherTx = suspendOtherAndResumeThis(context);
try {
LockManager lockManager = graphDbConfig.getLockManager();
LockReleaser lockReleaser = graphDbConfig.getLockReleaser();
for (T entity : entities) {
lockGrabber.grab(lockManager, lockReleaser, entity);
}
return packResponse(context, new LockResult(LockStatus.OK_LOCKED));
} catch (DeadlockDetectedException e) {
return packResponse(context, new LockResult(e.getMessage()));
} catch (IllegalResourceException e) {
return packResponse(context, new LockResult(LockStatus.NOT_LOCKED));
} finally {
suspendThisAndResumeOther(otherTx, context);
}
}
Aggregations