Search in sources :

Example 1 with IllegalResourceException

use of org.neo4j.kernel.impl.transaction.IllegalResourceException in project neo4j by neo4j.

the class MasterImplTest method lockResultMustHaveMessageWhenAcquiringSharedLockThrowsIllegalResource.

@Test
public void lockResultMustHaveMessageWhenAcquiringSharedLockThrowsIllegalResource() 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 IllegalResourceException("")).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) RequestContext(org.neo4j.com.RequestContext) Client(org.neo4j.kernel.impl.locking.Locks.Client) IllegalResourceException(org.neo4j.kernel.impl.transaction.IllegalResourceException) Test(org.junit.Test)

Example 2 with IllegalResourceException

use of org.neo4j.kernel.impl.transaction.IllegalResourceException in project neo4j by neo4j.

the class MasterImplTest method lockResultMustHaveMessageWhenAcquiringExclusiveLockThrowsIllegalResource.

@Test
public void lockResultMustHaveMessageWhenAcquiringExclusiveLockThrowsIllegalResource() 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 IllegalResourceException("")).when(locks).acquireExclusive(LockTracer.NONE, type, 1);
    master.acquireExclusiveLock(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) RequestContext(org.neo4j.com.RequestContext) Client(org.neo4j.kernel.impl.locking.Locks.Client) IllegalResourceException(org.neo4j.kernel.impl.transaction.IllegalResourceException) Test(org.junit.Test)

Example 3 with IllegalResourceException

use of org.neo4j.kernel.impl.transaction.IllegalResourceException 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 IllegalResourceException

use of org.neo4j.kernel.impl.transaction.IllegalResourceException 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 5 with IllegalResourceException

use of org.neo4j.kernel.impl.transaction.IllegalResourceException 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

IllegalResourceException (org.neo4j.kernel.impl.transaction.IllegalResourceException)5 LockResult (org.neo4j.kernel.ha.lock.LockResult)4 DeadlockDetectedException (org.neo4j.kernel.DeadlockDetectedException)3 Test (org.junit.Test)2 RequestContext (org.neo4j.com.RequestContext)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 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 ConcurrentAccessException (org.neo4j.kernel.impl.util.collection.ConcurrentAccessException)2 NoSuchEntryException (org.neo4j.kernel.impl.util.collection.NoSuchEntryException)2 Transaction (javax.transaction.Transaction)1 LockReleaser (org.neo4j.kernel.impl.core.LockReleaser)1 LockManager (org.neo4j.kernel.impl.transaction.LockManager)1