Search in sources :

Example 26 with RequestContext

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

the class MasterImplTest method shouldNotEndLockSessionWhereThereIsAnActiveLockAcquisition.

@Test
public void shouldNotEndLockSessionWhereThereIsAnActiveLockAcquisition() throws Throwable {
    // GIVEN
    CountDownLatch latch = new CountDownLatch(1);
    try {
        Client client = newWaitingLocksClient(latch);
        MasterImpl master = newMasterWithLocksClient(client);
        HandshakeResult handshake = master.handshake(1, newStoreIdForCurrentVersion()).response();
        // WHEN
        RequestContext context = new RequestContext(handshake.epoch(), 1, 2, 0, 0);
        master.newLockSession(context);
        Future<Void> acquireFuture = otherThread.execute(state -> {
            master.acquireExclusiveLock(context, ResourceTypes.NODE, 1L);
            return null;
        });
        otherThread.get().waitUntilWaiting();
        master.endLockSession(context, true);
        verify(client, never()).stop();
        verify(client, never()).close();
        latch.countDown();
        acquireFuture.get();
        // THEN
        verify(client).close();
    } finally {
        latch.countDown();
    }
}
Also used : RequestContext(org.neo4j.com.RequestContext) CountDownLatch(java.util.concurrent.CountDownLatch) Client(org.neo4j.kernel.impl.locking.Locks.Client) Test(org.junit.Test)

Example 27 with RequestContext

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

the class MasterServerTest method shouldCleanExistentLockSessionOnFinishOffChannel.

@Test
public void shouldCleanExistentLockSessionOnFinishOffChannel() throws Exception {
    Master master = mock(Master.class);
    ConversationManager conversationManager = mock(ConversationManager.class);
    LogEntryReader<ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader<>();
    MasterServer masterServer = new MasterServer(master, mock(LogProvider.class), mock(Server.Configuration.class), mock(TxChecksumVerifier.class), mock(ByteCounterMonitor.class), mock(RequestMonitor.class), conversationManager, logEntryReader);
    RequestContext requestContext = new RequestContext(1L, 1, 1, 0, 0L);
    masterServer.stopConversation(requestContext);
    Mockito.verify(conversationManager).stop(requestContext);
}
Also used : LogProvider(org.neo4j.logging.LogProvider) ByteCounterMonitor(org.neo4j.kernel.monitoring.ByteCounterMonitor) TxChecksumVerifier(org.neo4j.com.TxChecksumVerifier) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) RequestContext(org.neo4j.com.RequestContext) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel) RequestMonitor(org.neo4j.com.monitor.RequestMonitor) Test(org.junit.Test)

Example 28 with RequestContext

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

the class ResponsePacker method packTransactionStreamResponse.

public <T> Response<T> packTransactionStreamResponse(RequestContext context, T response) {
    final long toStartFrom = context.lastAppliedTransaction() + 1;
    final long toEndAt = transactionIdStore.getLastCommittedTransactionId();
    TransactionStream transactions = visitor -> {
        if (toStartFrom > BASE_TX_ID && toStartFrom <= toEndAt) {
            extractTransactions(toStartFrom, filterVisitor(visitor, toEndAt));
        }
    };
    return new TransactionStreamResponse<>(response, storeId.get(), transactions, ResourceReleaser.NO_OP);
}
Also used : Response(org.neo4j.com.Response) StoreId(org.neo4j.kernel.impl.store.StoreId) TransactionStream(org.neo4j.com.TransactionStream) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) LogicalTransactionStore(org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore) Supplier(java.util.function.Supplier) RequestContext(org.neo4j.com.RequestContext) IOCursor(org.neo4j.cursor.IOCursor) TransactionStreamResponse(org.neo4j.com.TransactionStreamResponse) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) ResourceReleaser(org.neo4j.com.ResourceReleaser) Visitor(org.neo4j.helpers.collection.Visitor) TransactionObligationResponse(org.neo4j.com.TransactionObligationResponse) BASE_TX_ID(org.neo4j.kernel.impl.transaction.log.TransactionIdStore.BASE_TX_ID) TransactionStreamResponse(org.neo4j.com.TransactionStreamResponse) TransactionStream(org.neo4j.com.TransactionStream)

Example 29 with RequestContext

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

the class ResponsePackerIT method shouldPackTheHighestTxCommittedAsObligation.

@Test
public void shouldPackTheHighestTxCommittedAsObligation() throws Exception {
    // GIVEN
    LogicalTransactionStore transactionStore = mock(LogicalTransactionStore.class);
    FileSystemAbstraction fs = fsRule.get();
    PageCache pageCache = pageCacheRule.getPageCache(fs);
    try (NeoStores neoStore = createNeoStore(fs, pageCache)) {
        MetaDataStore store = neoStore.getMetaDataStore();
        store.transactionCommitted(2, 111, BASE_TX_COMMIT_TIMESTAMP);
        store.transactionCommitted(3, 222, BASE_TX_COMMIT_TIMESTAMP);
        store.transactionCommitted(4, 333, BASE_TX_COMMIT_TIMESTAMP);
        store.transactionCommitted(5, 444, BASE_TX_COMMIT_TIMESTAMP);
        store.transactionCommitted(6, 555, BASE_TX_COMMIT_TIMESTAMP);
        // skip 7 to emulate the fact we have an hole in the committed tx ids list
        final long expectedTxId = 8L;
        store.transactionCommitted(expectedTxId, 777, BASE_TX_COMMIT_TIMESTAMP);
        ResponsePacker packer = new ResponsePacker(transactionStore, store, Suppliers.singleton(newStoreIdForCurrentVersion()));
        // WHEN
        Response<Object> response = packer.packTransactionObligationResponse(new RequestContext(0, 0, 0, 0, 0), new Object());
        // THEN
        assertTrue(response instanceof TransactionObligationResponse);
        ((TransactionObligationResponse) response).accept(new Response.Handler() {

            @Override
            public void obligation(long txId) throws IOException {
                assertEquals(expectedTxId, txId);
            }

            @Override
            public Visitor<CommittedTransactionRepresentation, Exception> transactions() {
                throw new UnsupportedOperationException("not expected");
            }
        });
    }
}
Also used : FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) Visitor(org.neo4j.helpers.collection.Visitor) MetaDataStore(org.neo4j.kernel.impl.store.MetaDataStore) LogicalTransactionStore(org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore) IOException(java.io.IOException) Response(org.neo4j.com.Response) TransactionObligationResponse(org.neo4j.com.TransactionObligationResponse) NeoStores(org.neo4j.kernel.impl.store.NeoStores) TransactionObligationResponse(org.neo4j.com.TransactionObligationResponse) RequestContext(org.neo4j.com.RequestContext) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Example 30 with RequestContext

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

the class SwitchToSlave method catchUpWithMaster.

private boolean catchUpWithMaster(UpdatePuller updatePuller) throws IllegalArgumentException, InterruptedException {
    monitor.catchupStarted();
    RequestContext catchUpRequestContext = requestContextFactory.newRequestContext();
    userLog.info("Catching up with master. I'm at %s", catchUpRequestContext);
    if (!updatePuller.tryPullUpdates()) {
        return false;
    }
    userLog.info("Now caught up with master");
    monitor.catchupCompleted();
    return true;
}
Also used : RequestContext(org.neo4j.com.RequestContext)

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