Search in sources :

Example 71 with Monitors

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

the class KernelTransactionsTest method newKernelTransactions.

private static KernelTransactions newKernelTransactions(Locks locks, StorageEngine storageEngine, TransactionCommitProcess commitProcess, boolean testKernelTransactions) throws Throwable {
    LifeSupport life = new LifeSupport();
    life.start();
    TransactionIdStore transactionIdStore = mock(TransactionIdStore.class);
    when(transactionIdStore.getLastCommittedTransaction()).thenReturn(new TransactionId(0, 0, 0));
    Tracers tracers = new Tracers("null", NullLog.getInstance(), new Monitors(), mock(JobScheduler.class));
    StatementLocksFactory statementLocksFactory = new SimpleStatementLocksFactory(locks);
    StatementOperationContainer statementOperationsContianer = new StatementOperationContainer(null, null);
    KernelTransactions transactions;
    if (testKernelTransactions) {
        transactions = createTestTransactions(storageEngine, commitProcess, transactionIdStore, tracers, statementLocksFactory, statementOperationsContianer, clock, availabilityGuard);
    } else {
        transactions = createTransactions(storageEngine, commitProcess, transactionIdStore, tracers, statementLocksFactory, statementOperationsContianer, clock, availabilityGuard);
    }
    transactions.start();
    return transactions;
}
Also used : JobScheduler(org.neo4j.kernel.impl.util.JobScheduler) SimpleStatementLocksFactory(org.neo4j.kernel.impl.locking.SimpleStatementLocksFactory) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) StatementLocksFactory(org.neo4j.kernel.impl.locking.StatementLocksFactory) SimpleStatementLocksFactory(org.neo4j.kernel.impl.locking.SimpleStatementLocksFactory) Monitors(org.neo4j.kernel.monitoring.Monitors) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) TransactionId(org.neo4j.kernel.impl.store.TransactionId) Tracers(org.neo4j.kernel.monitoring.tracing.Tracers)

Example 72 with Monitors

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

the class PhysicalLogicalTransactionStoreTest method shouldOpenAndRecoverExistingData.

@Test
public void shouldOpenAndRecoverExistingData() throws Exception {
    // GIVEN
    TransactionIdStore transactionIdStore = new DeadSimpleTransactionIdStore();
    TransactionMetadataCache positionCache = new TransactionMetadataCache(100);
    LogHeaderCache logHeaderCache = new LogHeaderCache(10);
    final byte[] additionalHeader = new byte[] { 1, 2, 5 };
    final int masterId = 2, authorId = 1;
    final long timeStarted = 12345, latestCommittedTxWhenStarted = 4545, timeCommitted = timeStarted + 10;
    LifeSupport life = new LifeSupport();
    final PhysicalLogFiles logFiles = new PhysicalLogFiles(testDir, DEFAULT_NAME, fileSystemRule.get());
    Monitor monitor = new Monitors().newMonitor(PhysicalLogFile.Monitor.class);
    LogFile logFile = life.add(new PhysicalLogFile(fileSystemRule.get(), logFiles, 1000, transactionIdStore::getLastCommittedTransactionId, mock(LogVersionRepository.class), monitor, logHeaderCache));
    life.start();
    try {
        addATransactionAndRewind(life, logFile, positionCache, transactionIdStore, additionalHeader, masterId, authorId, timeStarted, latestCommittedTxWhenStarted, timeCommitted);
    } finally {
        life.shutdown();
    }
    life = new LifeSupport();
    final AtomicBoolean recoveryRequired = new AtomicBoolean();
    FakeRecoveryVisitor visitor = new FakeRecoveryVisitor(additionalHeader, masterId, authorId, timeStarted, timeCommitted, latestCommittedTxWhenStarted);
    logFile = life.add(new PhysicalLogFile(fileSystemRule.get(), logFiles, 1000, transactionIdStore::getLastCommittedTransactionId, mock(LogVersionRepository.class), monitor, logHeaderCache));
    LogicalTransactionStore txStore = new PhysicalLogicalTransactionStore(logFile, positionCache, new VersionAwareLogEntryReader<>());
    life.add(new BatchingTransactionAppender(logFile, NO_ROTATION, positionCache, transactionIdStore, BYPASS, DATABASE_HEALTH));
    life.add(new Recovery(new Recovery.SPI() {

        @Override
        public void forceEverything() {
        }

        @Override
        public Visitor<CommittedTransactionRepresentation, Exception> startRecovery() {
            recoveryRequired.set(true);
            return visitor;
        }

        @Override
        public LogPosition getPositionToRecoverFrom() throws IOException {
            return LogPosition.start(0);
        }

        @Override
        public TransactionCursor getTransactions(LogPosition position) throws IOException {
            return txStore.getTransactions(position);
        }

        @Override
        public void allTransactionsRecovered(CommittedTransactionRepresentation lastRecoveredTransaction, LogPosition positionAfterLastRecoveredTransaction) throws Exception {
        }
    }, mock(Recovery.Monitor.class)));
    // WHEN
    try {
        life.start();
    } finally {
        life.shutdown();
    }
    // THEN
    assertEquals(1, visitor.getVisitedTransactions());
    assertTrue(recoveryRequired.get());
}
Also used : DeadSimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.DeadSimpleTransactionIdStore) Recovery(org.neo4j.kernel.recovery.Recovery) Monitor(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile.Monitor) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) DeadSimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.DeadSimpleTransactionIdStore) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Monitors(org.neo4j.kernel.monitoring.Monitors) Test(org.junit.Test)

Example 73 with Monitors

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

the class PhysicalLogicalTransactionStoreTest method shouldExtractMetadataFromExistingTransaction.

@Test
public void shouldExtractMetadataFromExistingTransaction() throws Exception {
    // GIVEN
    TransactionIdStore txIdStore = new DeadSimpleTransactionIdStore();
    TransactionMetadataCache positionCache = new TransactionMetadataCache(100);
    LogHeaderCache logHeaderCache = new LogHeaderCache(10);
    final byte[] additionalHeader = new byte[] { 1, 2, 5 };
    final int masterId = 2, authorId = 1;
    final long timeStarted = 12345, latestCommittedTxWhenStarted = 4545, timeCommitted = timeStarted + 10;
    LifeSupport life = new LifeSupport();
    PhysicalLogFiles logFiles = new PhysicalLogFiles(testDir, DEFAULT_NAME, fileSystemRule.get());
    Monitor monitor = new Monitors().newMonitor(PhysicalLogFile.Monitor.class);
    LogFile logFile = life.add(new PhysicalLogFile(fileSystemRule.get(), logFiles, 1000, txIdStore::getLastCommittedTransactionId, mock(LogVersionRepository.class), monitor, logHeaderCache));
    life.start();
    try {
        addATransactionAndRewind(life, logFile, positionCache, txIdStore, additionalHeader, masterId, authorId, timeStarted, latestCommittedTxWhenStarted, timeCommitted);
    } finally {
        life.shutdown();
    }
    life = new LifeSupport();
    logFile = life.add(new PhysicalLogFile(fileSystemRule.get(), logFiles, 1000, txIdStore::getLastCommittedTransactionId, mock(LogVersionRepository.class), monitor, logHeaderCache));
    final LogicalTransactionStore store = new PhysicalLogicalTransactionStore(logFile, positionCache, new VersionAwareLogEntryReader<>());
    // WHEN
    life.start();
    try {
        verifyTransaction(txIdStore, positionCache, additionalHeader, masterId, authorId, timeStarted, latestCommittedTxWhenStarted, timeCommitted, store);
    } finally {
        life.shutdown();
    }
}
Also used : DeadSimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.DeadSimpleTransactionIdStore) DeadSimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.DeadSimpleTransactionIdStore) Monitor(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile.Monitor) Monitors(org.neo4j.kernel.monitoring.Monitors) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) Test(org.junit.Test)

Example 74 with Monitors

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

the class PhysicalLogicalTransactionStoreTest method extractTransactionFromLogFilesSkippingLastLogFileWithoutHeader.

@Test
public void extractTransactionFromLogFilesSkippingLastLogFileWithoutHeader() throws IOException {
    TransactionIdStore transactionIdStore = new DeadSimpleTransactionIdStore();
    TransactionMetadataCache positionCache = new TransactionMetadataCache(100);
    LogHeaderCache logHeaderCache = new LogHeaderCache(10);
    final byte[] additionalHeader = new byte[] { 1, 2, 5 };
    final int masterId = 2, authorId = 1;
    final long timeStarted = 12345, latestCommittedTxWhenStarted = 4545, timeCommitted = timeStarted + 10;
    LifeSupport life = new LifeSupport();
    final PhysicalLogFiles logFiles = new PhysicalLogFiles(testDir, DEFAULT_NAME, fileSystemRule.get());
    Monitor monitor = new Monitors().newMonitor(PhysicalLogFile.Monitor.class);
    LogFile logFile = life.add(new PhysicalLogFile(fileSystemRule.get(), logFiles, 1000, transactionIdStore::getLastCommittedTransactionId, mock(LogVersionRepository.class), monitor, logHeaderCache));
    life.start();
    try {
        addATransactionAndRewind(life, logFile, positionCache, transactionIdStore, additionalHeader, masterId, authorId, timeStarted, latestCommittedTxWhenStarted, timeCommitted);
    } finally {
        life.shutdown();
    }
    PhysicalLogFile emptyLogFile = new PhysicalLogFile(fileSystemRule.get(), logFiles, 1000, transactionIdStore::getLastCommittedTransactionId, mock(LogVersionRepository.class), monitor, logHeaderCache);
    // create empty transaction log file and clear transaction cache to force re-read
    fileSystemRule.get().create(logFiles.getLogFileForVersion(logFiles.getHighestLogVersion() + 1)).close();
    positionCache.clear();
    final LogicalTransactionStore store = new PhysicalLogicalTransactionStore(emptyLogFile, positionCache, new VersionAwareLogEntryReader<>());
    verifyTransaction(transactionIdStore, positionCache, additionalHeader, masterId, authorId, timeStarted, latestCommittedTxWhenStarted, timeCommitted, store);
}
Also used : DeadSimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.DeadSimpleTransactionIdStore) DeadSimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.DeadSimpleTransactionIdStore) Monitor(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile.Monitor) Monitors(org.neo4j.kernel.monitoring.Monitors) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) Test(org.junit.Test)

Example 75 with Monitors

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

the class LoggingListenerTest method shouldNotLogWhenMatchingClassIsNotRegisteredInTheMonitorListener.

@Test
public void shouldNotLogWhenMatchingClassIsNotRegisteredInTheMonitorListener() {
    // Given
    Monitors monitors = new Monitors();
    AssertableLogProvider logProvider = new AssertableLogProvider();
    InterestingMonitor1 aMonitor = monitors.newMonitor(InterestingMonitor1.class);
    LoggingListener listener = new LoggingListener(Collections.<Class<?>, Logger>singletonMap(InterestingMonitor2.class, logProvider.getLog(InterestingMonitor2.class).infoLogger()));
    monitors.addMonitorListener(listener, listener.predicate);
    // When
    aMonitor.touch();
    // Then
    logProvider.assertNoLoggingOccurred();
}
Also used : Monitors(org.neo4j.kernel.monitoring.Monitors) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) 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