Search in sources :

Example 1 with NoSuchEntryException

use of org.neo4j.kernel.impl.util.collection.NoSuchEntryException in project neo4j by neo4j.

the class MasterImplTest method lockResultMustHaveMessageWhenAcquiringExclusiveLockWithoutConversation.

@Test
public void lockResultMustHaveMessageWhenAcquiringExclusiveLockWithoutConversation() throws Exception {
    MasterImpl.SPI spi = mockedSpi();
    ConversationManager conversationManager = mock(ConversationManager.class);
    Config config = config();
    MasterImpl master = new MasterImpl(spi, conversationManager, null, config);
    RequestContext context = createRequestContext(master);
    when(conversationManager.acquire(context)).thenThrow(new NoSuchEntryException(""));
    master.acquireExclusiveLock(context, ResourceTypes.NODE, 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) LockResult(org.neo4j.kernel.ha.lock.LockResult) Config(org.neo4j.kernel.configuration.Config) NoSuchEntryException(org.neo4j.kernel.impl.util.collection.NoSuchEntryException) RequestContext(org.neo4j.com.RequestContext) Test(org.junit.Test)

Example 2 with NoSuchEntryException

use of org.neo4j.kernel.impl.util.collection.NoSuchEntryException in project neo4j by neo4j.

the class MasterImplTest method lockResultMustHaveMessageWhenAcquiringSharedLockWithoutConversation.

@Test
public void lockResultMustHaveMessageWhenAcquiringSharedLockWithoutConversation() throws Exception {
    MasterImpl.SPI spi = mockedSpi();
    ConversationManager conversationManager = mock(ConversationManager.class);
    Config config = config();
    MasterImpl master = new MasterImpl(spi, conversationManager, null, config);
    RequestContext context = createRequestContext(master);
    when(conversationManager.acquire(context)).thenThrow(new NoSuchEntryException(""));
    master.acquireSharedLock(context, ResourceTypes.NODE, 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) LockResult(org.neo4j.kernel.ha.lock.LockResult) Config(org.neo4j.kernel.configuration.Config) NoSuchEntryException(org.neo4j.kernel.impl.util.collection.NoSuchEntryException) RequestContext(org.neo4j.com.RequestContext) Test(org.junit.Test)

Example 3 with NoSuchEntryException

use of org.neo4j.kernel.impl.util.collection.NoSuchEntryException 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 4 with NoSuchEntryException

use of org.neo4j.kernel.impl.util.collection.NoSuchEntryException in project neo4j by neo4j.

the class MasterImpl method commit.

@Override
public Response<Long> commit(RequestContext context, TransactionRepresentation preparedTransaction) throws IOException, org.neo4j.kernel.api.exceptions.TransactionFailureException {
    assertCorrectEpoch(context);
    if (context.getEventIdentifier() == Locks.Client.NO_LOCK_SESSION_ID) {
        // Client is not holding locks, use a temporary lock client
        try (Conversation conversation = conversationManager.acquire()) {
            return commit0(context, preparedTransaction, conversation.getLocks());
        }
    } else {
        // Client is holding locks, use the clients lock session
        try {
            Conversation conversation = conversationManager.acquire(context);
            Locks.Client locks = conversation.getLocks();
            try {
                return commit0(context, preparedTransaction, locks);
            } finally {
                conversationManager.release(context);
            }
        } catch (NoSuchEntryException | ConcurrentAccessException e) {
            throw new TransactionNotPresentOnMasterException(context);
        }
    }
}
Also used : NoSuchEntryException(org.neo4j.kernel.impl.util.collection.NoSuchEntryException) TransactionNotPresentOnMasterException(org.neo4j.com.TransactionNotPresentOnMasterException) Locks(org.neo4j.kernel.impl.locking.Locks) ConcurrentAccessException(org.neo4j.kernel.impl.util.collection.ConcurrentAccessException)

Example 5 with NoSuchEntryException

use of org.neo4j.kernel.impl.util.collection.NoSuchEntryException 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)

Aggregations

NoSuchEntryException (org.neo4j.kernel.impl.util.collection.NoSuchEntryException)5 LockResult (org.neo4j.kernel.ha.lock.LockResult)4 Locks (org.neo4j.kernel.impl.locking.Locks)3 ConcurrentAccessException (org.neo4j.kernel.impl.util.collection.ConcurrentAccessException)3 Test (org.junit.Test)2 RequestContext (org.neo4j.com.RequestContext)2 DeadlockDetectedException (org.neo4j.kernel.DeadlockDetectedException)2 Config (org.neo4j.kernel.configuration.Config)2 SPI (org.neo4j.kernel.ha.com.master.MasterImpl.SPI)2 IllegalResourceException (org.neo4j.kernel.impl.transaction.IllegalResourceException)2 TransactionNotPresentOnMasterException (org.neo4j.com.TransactionNotPresentOnMasterException)1