Search in sources :

Example 6 with DeadlockDetectedException

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())));
}
Also used : SPI(org.neo4j.kernel.ha.com.master.MasterImpl.SPI) ResourceTypes(org.neo4j.kernel.impl.locking.ResourceTypes) DefaultConversationSPI(org.neo4j.kernel.ha.cluster.DefaultConversationSPI) LockResult(org.neo4j.kernel.ha.lock.LockResult) Config(org.neo4j.kernel.configuration.Config) DeadlockDetectedException(org.neo4j.kernel.DeadlockDetectedException) RequestContext(org.neo4j.com.RequestContext) Client(org.neo4j.kernel.impl.locking.Locks.Client) Test(org.junit.Test)

Example 7 with DeadlockDetectedException

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)));
}
Also used : QueryExecutionEngine(org.neo4j.kernel.impl.query.QueryExecutionEngine) HttpServletRequest(javax.servlet.http.HttpServletRequest) GraphDatabaseQueryService(org.neo4j.kernel.GraphDatabaseQueryService) DeadlockDetectedException(org.neo4j.kernel.DeadlockDetectedException) TransactionalContext(org.neo4j.kernel.impl.query.TransactionalContext) Test(org.junit.Test)

Example 8 with DeadlockDetectedException

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;
}
Also used : LockClientStoppedException(org.neo4j.kernel.impl.locking.LockClientStoppedException) DeadlockDetectedException(org.neo4j.kernel.DeadlockDetectedException) LockWaitEvent(org.neo4j.kernel.impl.locking.LockWaitEvent)

Example 9 with DeadlockDetectedException

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));
    }
}
Also used : InvalidSemanticsException(org.neo4j.cypher.InvalidSemanticsException) Status(org.neo4j.kernel.api.exceptions.Status) QueryExecutionKernelException(org.neo4j.kernel.impl.query.QueryExecutionKernelException) DeadlockDetectedException(org.neo4j.kernel.DeadlockDetectedException) IOException(java.io.IOException) QueryExecutionKernelException(org.neo4j.kernel.impl.query.QueryExecutionKernelException) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) CypherException(org.neo4j.cypher.CypherException) DeadlockDetectedException(org.neo4j.kernel.DeadlockDetectedException) IOException(java.io.IOException) KernelException(org.neo4j.kernel.api.exceptions.KernelException) InvalidSemanticsException(org.neo4j.cypher.InvalidSemanticsException) AuthorizationViolationException(org.neo4j.graphdb.security.AuthorizationViolationException) WriteOperationsNotAllowedException(org.neo4j.graphdb.security.WriteOperationsNotAllowedException) Result(org.neo4j.graphdb.Result) WriteOperationsNotAllowedException(org.neo4j.graphdb.security.WriteOperationsNotAllowedException) Neo4jError(org.neo4j.server.rest.transactional.error.Neo4jError) TransactionalContext(org.neo4j.kernel.impl.query.TransactionalContext) CypherException(org.neo4j.cypher.CypherException) QueryExecutionKernelException(org.neo4j.kernel.impl.query.QueryExecutionKernelException) KernelException(org.neo4j.kernel.api.exceptions.KernelException) AuthorizationViolationException(org.neo4j.graphdb.security.AuthorizationViolationException)

Example 10 with DeadlockDetectedException

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);
    }
}
Also used : LockManager(org.neo4j.kernel.impl.transaction.LockManager) LockReleaser(org.neo4j.kernel.impl.core.LockReleaser) Transaction(javax.transaction.Transaction) DeadlockDetectedException(org.neo4j.kernel.DeadlockDetectedException) IllegalResourceException(org.neo4j.kernel.impl.transaction.IllegalResourceException)

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