Search in sources :

Example 1 with TransactionNotPresentOnMasterException

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

the class MasterImplTest method shouldNotAllowCommitIfThereIsNoMatchingLockSession.

@Test
public void shouldNotAllowCommitIfThereIsNoMatchingLockSession() throws Throwable {
    // Given
    MasterImpl.SPI spi = mock(MasterImpl.SPI.class);
    DefaultConversationSPI conversationSpi = mockedConversationSpi();
    Config config = config();
    ConversationManager conversationManager = new ConversationManager(conversationSpi, config);
    when(spi.isAccessible()).thenReturn(true);
    when(spi.getTransactionChecksum(anyLong())).thenReturn(1L);
    mockEmptyResponse(spi);
    MasterImpl master = new MasterImpl(spi, conversationManager, mock(MasterImpl.Monitor.class), config);
    master.start();
    HandshakeResult handshake = master.handshake(1, newStoreIdForCurrentVersion()).response();
    RequestContext ctx = new RequestContext(handshake.epoch(), 1, 2, 0, 0);
    // When
    try {
        master.commit(ctx, mock(TransactionRepresentation.class));
        fail("Should have failed.");
    } catch (TransactionNotPresentOnMasterException e) {
        // Then
        assertThat(e.getMessage(), equalTo(new TransactionNotPresentOnMasterException(ctx).getMessage()));
    }
}
Also used : SPI(org.neo4j.kernel.ha.com.master.MasterImpl.SPI) DefaultConversationSPI(org.neo4j.kernel.ha.cluster.DefaultConversationSPI) Monitor(org.neo4j.kernel.ha.com.master.MasterImpl.Monitor) Config(org.neo4j.kernel.configuration.Config) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) TransactionNotPresentOnMasterException(org.neo4j.com.TransactionNotPresentOnMasterException) RequestContext(org.neo4j.com.RequestContext) Test(org.junit.Test)

Example 2 with TransactionNotPresentOnMasterException

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

Aggregations

TransactionNotPresentOnMasterException (org.neo4j.com.TransactionNotPresentOnMasterException)2 Test (org.junit.Test)1 RequestContext (org.neo4j.com.RequestContext)1 Config (org.neo4j.kernel.configuration.Config)1 DefaultConversationSPI (org.neo4j.kernel.ha.cluster.DefaultConversationSPI)1 Monitor (org.neo4j.kernel.ha.com.master.MasterImpl.Monitor)1 SPI (org.neo4j.kernel.ha.com.master.MasterImpl.SPI)1 Locks (org.neo4j.kernel.impl.locking.Locks)1 TransactionRepresentation (org.neo4j.kernel.impl.transaction.TransactionRepresentation)1 ConcurrentAccessException (org.neo4j.kernel.impl.util.collection.ConcurrentAccessException)1 NoSuchEntryException (org.neo4j.kernel.impl.util.collection.NoSuchEntryException)1