Search in sources :

Example 26 with Monitors

use of org.neo4j.kernel.monitoring.Monitors in project neo4j by neo4j.

the class TxPullRequestHandlerTest method shouldRespondWithoutTransactionsIfTheyDoNotExist.

@Test
public void shouldRespondWithoutTransactionsIfTheyDoNotExist() throws Exception {
    // given
    StoreId storeId = new StoreId(1, 2, 3, 4);
    TransactionIdStore transactionIdStore = mock(TransactionIdStore.class);
    when(transactionIdStore.getLastCommittedTransactionId()).thenReturn(15L);
    LogicalTransactionStore logicalTransactionStore = mock(LogicalTransactionStore.class);
    when(logicalTransactionStore.getTransactions(14L)).thenThrow(new NoSuchTransactionException(14));
    TxPullRequestHandler txPullRequestHandler = new TxPullRequestHandler(new CatchupServerProtocol(), () -> storeId, () -> true, () -> transactionIdStore, () -> logicalTransactionStore, BATCH_SIZE, new Monitors(), logProvider);
    // when
    txPullRequestHandler.channelRead0(context, new TxPullRequest(13, storeId));
    // then
    verify(context, never()).write(ResponseMessageType.TX);
    verify(context).write(ResponseMessageType.TX_STREAM_FINISHED);
    verify(context).write(new TxStreamFinishedResponse(E_TRANSACTION_PRUNED, 15L));
    logProvider.assertAtLeastOnce(inLog(TxPullRequestHandler.class).info("Failed to serve TxPullRequest for tx %d because the transaction does not exist.", 14L));
}
Also used : TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) StoreId(org.neo4j.causalclustering.identity.StoreId) Monitors(org.neo4j.kernel.monitoring.Monitors) LogicalTransactionStore(org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore) NoSuchTransactionException(org.neo4j.kernel.impl.transaction.log.NoSuchTransactionException) CatchupServerProtocol(org.neo4j.causalclustering.catchup.CatchupServerProtocol) Test(org.junit.Test)

Example 27 with Monitors

use of org.neo4j.kernel.monitoring.Monitors in project neo4j by neo4j.

the class RemoteStoreTest method shouldCopyStoreFilesAndPullTransactions.

@Test
public void shouldCopyStoreFilesAndPullTransactions() throws Exception {
    // given
    StoreId storeId = new StoreId(1, 2, 3, 4);
    StoreCopyClient storeCopyClient = mock(StoreCopyClient.class);
    TxPullClient txPullClient = mock(TxPullClient.class);
    when(txPullClient.pullTransactions(any(), any(), anyLong(), any())).thenReturn(new TxPullRequestResult(SUCCESS_END_OF_STREAM, 13));
    TransactionLogCatchUpWriter writer = mock(TransactionLogCatchUpWriter.class);
    RemoteStore remoteStore = new RemoteStore(NullLogProvider.getInstance(), mock(FileSystemAbstraction.class), null, storeCopyClient, txPullClient, factory(writer), new Monitors());
    // when
    MemberId localhost = new MemberId(UUID.randomUUID());
    remoteStore.copy(localhost, storeId, new File("destination"));
    // then
    verify(storeCopyClient).copyStoreFiles(eq(localhost), eq(storeId), any(StoreFileStreams.class));
    verify(txPullClient).pullTransactions(eq(localhost), eq(storeId), anyLong(), any(TxPullResponseListener.class));
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) TransactionLogCatchUpWriter(org.neo4j.causalclustering.catchup.tx.TransactionLogCatchUpWriter) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) StoreId(org.neo4j.causalclustering.identity.StoreId) TxPullResponseListener(org.neo4j.causalclustering.catchup.tx.TxPullResponseListener) Monitors(org.neo4j.kernel.monitoring.Monitors) TxPullRequestResult(org.neo4j.causalclustering.catchup.TxPullRequestResult) TxPullClient(org.neo4j.causalclustering.catchup.tx.TxPullClient) File(java.io.File) Test(org.junit.Test)

Example 28 with Monitors

use of org.neo4j.kernel.monitoring.Monitors in project neo4j by neo4j.

the class StoreCopyClient method writeTransactionsToActiveLogFile.

private void writeTransactionsToActiveLogFile(File tempStoreDir, Response<?> response) throws Exception {
    LifeSupport life = new LifeSupport();
    try {
        // Start the log and appender
        PhysicalLogFiles logFiles = new PhysicalLogFiles(tempStoreDir, fs);
        LogHeaderCache logHeaderCache = new LogHeaderCache(10);
        ReadOnlyLogVersionRepository logVersionRepository = new ReadOnlyLogVersionRepository(pageCache, tempStoreDir);
        ReadOnlyTransactionIdStore readOnlyTransactionIdStore = new ReadOnlyTransactionIdStore(pageCache, tempStoreDir);
        LogFile logFile = life.add(new PhysicalLogFile(fs, logFiles, Long.MAX_VALUE, /*don't rotate*/
        readOnlyTransactionIdStore::getLastCommittedTransactionId, logVersionRepository, new Monitors().newMonitor(PhysicalLogFile.Monitor.class), logHeaderCache));
        life.start();
        // Just write all transactions to the active log version. Remember that this is after a store copy
        // where there are no logs, and the transaction stream we're about to write will probably contain
        // transactions that goes some time back, before the last committed transaction id. So we cannot
        // use a TransactionAppender, since it has checks for which transactions one can append.
        FlushableChannel channel = logFile.getWriter();
        final TransactionLogWriter writer = new TransactionLogWriter(new LogEntryWriter(channel));
        final AtomicLong firstTxId = new AtomicLong(BASE_TX_ID);
        response.accept(new Response.Handler() {

            @Override
            public void obligation(long txId) throws IOException {
                throw new UnsupportedOperationException("Shouldn't be called");
            }

            @Override
            public Visitor<CommittedTransactionRepresentation, Exception> transactions() {
                return transaction -> {
                    long txId = transaction.getCommitEntry().getTxId();
                    if (firstTxId.compareAndSet(BASE_TX_ID, txId)) {
                        monitor.startReceivingTransactions(txId);
                    }
                    writer.append(transaction.getTransactionRepresentation(), txId);
                    return false;
                };
            }
        });
        long endTxId = firstTxId.get();
        if (endTxId != BASE_TX_ID) {
            monitor.finishReceivingTransactions(endTxId);
        }
        long currentLogVersion = logVersionRepository.getCurrentLogVersion();
        writer.checkPoint(new LogPosition(currentLogVersion, LOG_HEADER_SIZE));
        // And since we write this manually we need to set the correct transaction id in the
        // header of the log that we just wrote.
        File currentLogFile = logFiles.getLogFileForVersion(currentLogVersion);
        writeLogHeader(fs, currentLogFile, currentLogVersion, max(BASE_TX_ID, endTxId - 1));
        if (!forensics) {
            // since we just create new log and put checkpoint into it with offset equals to
            // LOG_HEADER_SIZE we need to update last transaction offset to be equal to this newly defined max
            // offset otherwise next checkpoint that use last transaction offset will be created for non
            // existing offset that is in most of the cases bigger than new log size.
            // Recovery will treat that as last checkpoint and will not try to recover store till new
            // last closed transaction offset will not overcome old one. Till that happens it will be
            // impossible for recovery process to restore the store
            File neoStore = new File(tempStoreDir, MetaDataStore.DEFAULT_NAME);
            MetaDataStore.setRecord(pageCache, neoStore, MetaDataStore.Position.LAST_CLOSED_TRANSACTION_LOG_BYTE_OFFSET, LOG_HEADER_SIZE);
        }
    } finally {
        life.shutdown();
    }
}
Also used : Visitor(org.neo4j.helpers.collection.Visitor) IOException(java.io.IOException) PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles) LogFile(org.neo4j.kernel.impl.transaction.log.LogFile) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile) Response(org.neo4j.com.Response) AtomicLong(java.util.concurrent.atomic.AtomicLong) ReadOnlyTransactionIdStore(org.neo4j.kernel.impl.transaction.log.ReadOnlyTransactionIdStore) FlushableChannel(org.neo4j.kernel.impl.transaction.log.FlushableChannel) Monitors(org.neo4j.kernel.monitoring.Monitors) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) TransactionLogWriter(org.neo4j.kernel.impl.transaction.log.TransactionLogWriter) LogEntryWriter(org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter) ReadOnlyLogVersionRepository(org.neo4j.kernel.impl.transaction.log.ReadOnlyLogVersionRepository) LogHeaderCache(org.neo4j.kernel.impl.transaction.log.LogHeaderCache) LogFile(org.neo4j.kernel.impl.transaction.log.LogFile) File(java.io.File) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

Example 29 with Monitors

use of org.neo4j.kernel.monitoring.Monitors in project neo4j by neo4j.

the class MonitoredBoltWorkerFactoryTest method shouldReportStartedSessions.

@Test
public void shouldReportStartedSessions() {
    int workersCount = 42;
    Monitors monitors = new Monitors();
    CountingSessionMonitor monitor = new CountingSessionMonitor();
    monitors.addMonitorListener(monitor);
    WorkerFactory mockWorkers = mock(WorkerFactory.class);
    when(mockWorkers.newWorker(anyObject(), any())).thenReturn(mock(BoltWorker.class));
    MonitoredWorkerFactory workerFactory = new MonitoredWorkerFactory(monitors, mockWorkers, systemClock());
    for (int i = 0; i < workersCount; i++) {
        workerFactory.newWorker(CONNECTION_DESCRIPTOR);
    }
    assertEquals(workersCount, monitor.sessionsStarted);
}
Also used : MonitoredBoltWorker(org.neo4j.bolt.v1.runtime.MonitoredWorkerFactory.MonitoredBoltWorker) Monitors(org.neo4j.kernel.monitoring.Monitors) Test(org.junit.Test)

Example 30 with Monitors

use of org.neo4j.kernel.monitoring.Monitors in project neo4j by neo4j.

the class MonitoredBoltWorkerFactoryTest method shouldNotWrapWithMonitoredSessionIfNobodyIsListening.

@Test
public void shouldNotWrapWithMonitoredSessionIfNobodyIsListening() throws Throwable {
    // Given
    // Monitoring adds GC overhead, so we only want to do the work involved
    // if someone has actually registered a listener. We still allow plugging
    // monitoring in at runtime, but it will only apply to sessions started
    // after monitor listeners are added
    WorkerFactory workerFactory = mock(WorkerFactory.class);
    BoltWorker innerSession = mock(BoltWorker.class);
    when(workerFactory.newWorker(anyObject(), anyObject())).thenReturn(innerSession);
    Monitors monitors = new Monitors();
    MonitoredWorkerFactory monitoredWorkerFactory = new MonitoredWorkerFactory(monitors, workerFactory, Clocks.fakeClock());
    // When
    BoltWorker worker = monitoredWorkerFactory.newWorker(CONNECTION_DESCRIPTOR);
    // Then
    assertEquals(innerSession, worker);
    // But when I register a listener
    monitors.addMonitorListener(new CountingSessionMonitor());
    // Then new sessions should be monitored
    assertThat(monitoredWorkerFactory.newWorker(CONNECTION_DESCRIPTOR), instanceOf(MonitoredBoltWorker.class));
}
Also used : MonitoredBoltWorker(org.neo4j.bolt.v1.runtime.MonitoredWorkerFactory.MonitoredBoltWorker) Monitors(org.neo4j.kernel.monitoring.Monitors) MonitoredBoltWorker(org.neo4j.bolt.v1.runtime.MonitoredWorkerFactory.MonitoredBoltWorker) Test(org.junit.Test)

Aggregations

Monitors (org.neo4j.kernel.monitoring.Monitors)79 Test (org.junit.Test)53 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)12 TransactionIdStore (org.neo4j.kernel.impl.transaction.log.TransactionIdStore)11 File (java.io.File)10 ByteBuffer (java.nio.ByteBuffer)9 StoreId (org.neo4j.causalclustering.identity.StoreId)9 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)9 LogicalTransactionStore (org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore)9 ByteCounterMonitor (org.neo4j.kernel.monitoring.ByteCounterMonitor)9 IOException (java.io.IOException)8 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)8 BlockLogBuffer (org.neo4j.com.BlockLogBuffer)8 Config (org.neo4j.kernel.configuration.Config)8 PageCache (org.neo4j.io.pagecache.PageCache)7 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)7 DependencyResolver (org.neo4j.graphdb.DependencyResolver)6 URI (java.net.URI)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 ClusterConfiguration (org.neo4j.cluster.protocol.cluster.ClusterConfiguration)5