Search in sources :

Example 1 with RequestContext

use of org.neo4j.com.RequestContext in project neo4j by neo4j.

the class SlaveLocksClient method acquireSharedOnMaster.

private void acquireSharedOnMaster(ResourceType resourceType, long... resourceIds) {
    if (resourceType == ResourceTypes.NODE || resourceType == ResourceTypes.RELATIONSHIP || resourceType == ResourceTypes.GRAPH_PROPS || resourceType == ResourceTypes.LEGACY_INDEX) {
        makeSureTxHasBeenInitialized();
        RequestContext requestContext = newRequestContextFor(this);
        try (Response<LockResult> response = master.acquireSharedLock(requestContext, resourceType, resourceIds)) {
            receiveLockResponse(response);
        } catch (ComException e) {
            throw new DistributedLockFailureException("Cannot get shared lock(s) on master", master, e);
        }
    }
}
Also used : ComException(org.neo4j.com.ComException) RequestContext(org.neo4j.com.RequestContext)

Example 2 with RequestContext

use of org.neo4j.com.RequestContext in project neo4j by neo4j.

the class MasterImplTest method lockResultMustHaveMessageWhenAcquiringExclusiveLockDeadlocks.

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

Example 3 with RequestContext

use of org.neo4j.com.RequestContext 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 4 with RequestContext

use of org.neo4j.com.RequestContext in project neo4j by neo4j.

the class MasterImplTest method givenStartedAndInaccessibleWhenNewLockSessionThrowException.

@Test
public void givenStartedAndInaccessibleWhenNewLockSessionThrowException() throws Throwable {
    // Given
    MasterImpl.SPI spi = mock(MasterImpl.SPI.class);
    Config config = config();
    when(spi.isAccessible()).thenReturn(false);
    MasterImpl instance = new MasterImpl(spi, mock(ConversationManager.class), mock(MasterImpl.Monitor.class), config);
    instance.start();
    // When
    try {
        instance.newLockSession(new RequestContext(0, 1, 2, 0, 0));
        fail();
    } catch (org.neo4j.kernel.api.exceptions.TransactionFailureException e) {
    // Ok
    }
}
Also used : SPI(org.neo4j.kernel.ha.com.master.MasterImpl.SPI) Monitor(org.neo4j.kernel.ha.com.master.MasterImpl.Monitor) Config(org.neo4j.kernel.configuration.Config) RequestContext(org.neo4j.com.RequestContext) Test(org.junit.Test)

Example 5 with RequestContext

use of org.neo4j.com.RequestContext 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)

Aggregations

RequestContext (org.neo4j.com.RequestContext)38 Test (org.junit.Test)21 Config (org.neo4j.kernel.configuration.Config)13 SPI (org.neo4j.kernel.ha.com.master.MasterImpl.SPI)12 Response (org.neo4j.com.Response)10 LockResult (org.neo4j.kernel.ha.lock.LockResult)10 StoreId (org.neo4j.kernel.impl.store.StoreId)9 IOException (java.io.IOException)8 StoreWriter (org.neo4j.com.storecopy.StoreWriter)8 DefaultConversationSPI (org.neo4j.kernel.ha.cluster.DefaultConversationSPI)8 MasterClient (org.neo4j.kernel.ha.com.slave.MasterClient)8 Client (org.neo4j.kernel.impl.locking.Locks.Client)8 TransactionRepresentation (org.neo4j.kernel.impl.transaction.TransactionRepresentation)8 ResponseUnpacker (org.neo4j.com.storecopy.ResponseUnpacker)7 HandshakeResult (org.neo4j.kernel.ha.com.master.HandshakeResult)7 Master (org.neo4j.kernel.ha.com.master.Master)7 RequestMonitor (org.neo4j.com.monitor.RequestMonitor)6 ReadableClosablePositionAwareChannel (org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel)6 String.format (java.lang.String.format)5 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)4