Search in sources :

Example 6 with Health

use of org.neo4j.monitoring.Health in project neo4j by neo4j.

the class DatabaseHealthTest method shouldLogDatabasePanicEvent.

@Test
void shouldLogDatabasePanicEvent() {
    // GIVEN
    AssertableLogProvider logProvider = new AssertableLogProvider();
    Health databaseHealth = new DatabaseHealth(mock(DatabasePanicEventGenerator.class), logProvider.getLog(DatabaseHealth.class));
    databaseHealth.healed();
    // WHEN
    String message = "Listen everybody... panic!";
    Exception exception = new Exception(message);
    databaseHealth.panic(exception);
    // THEN
    assertThat(logProvider).forClass(DatabaseHealth.class).forLevel(ERROR).containsMessageWithException("Database panic: The database has encountered a critical error, " + "and needs to be restarted. Please see database logs for more details.", exception);
}
Also used : DatabaseHealth(org.neo4j.monitoring.DatabaseHealth) Health(org.neo4j.monitoring.Health) DatabaseHealth(org.neo4j.monitoring.DatabaseHealth) DatabasePanicEventGenerator(org.neo4j.kernel.monitoring.DatabasePanicEventGenerator) IOException(java.io.IOException) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.jupiter.api.Test)

Example 7 with Health

use of org.neo4j.monitoring.Health in project neo4j by neo4j.

the class Runner method createBatchingTransactionAppender.

private static BatchingTransactionAppender createBatchingTransactionAppender(TransactionIdStore transactionIdStore, TransactionMetadataCache transactionMetadataCache, LogFiles logFiles) {
    Log log = NullLog.getInstance();
    Health databaseHealth = new DatabaseHealth(PanicEventGenerator.NO_OP, log);
    LogRotation logRotation = transactionLogRotation(logFiles, Clock.systemUTC(), databaseHealth, EMPTY);
    return new BatchingTransactionAppender(logFiles, logRotation, transactionMetadataCache, transactionIdStore, databaseHealth);
}
Also used : DatabaseHealth(org.neo4j.monitoring.DatabaseHealth) Log(org.neo4j.logging.Log) NullLog(org.neo4j.logging.NullLog) Health(org.neo4j.monitoring.Health) DatabaseHealth(org.neo4j.monitoring.DatabaseHealth) BatchingTransactionAppender(org.neo4j.kernel.impl.transaction.log.BatchingTransactionAppender) FileLogRotation.transactionLogRotation(org.neo4j.kernel.impl.transaction.log.rotation.FileLogRotation.transactionLogRotation) LogRotation(org.neo4j.kernel.impl.transaction.log.rotation.LogRotation)

Example 8 with Health

use of org.neo4j.monitoring.Health in project neo4j by neo4j.

the class TransactionLogAppendAndRotateIT method shouldKeepTransactionsIntactWhenConcurrentlyRotationAndAppending.

@Test
void shouldKeepTransactionsIntactWhenConcurrentlyRotationAndAppending() throws Throwable {
    // GIVEN
    LogVersionRepository logVersionRepository = new SimpleLogVersionRepository();
    LogFiles logFiles = LogFilesBuilder.builder(databaseLayout, fileSystem).withLogVersionRepository(logVersionRepository).withRotationThreshold(ByteUnit.mebiBytes(1)).withTransactionIdStore(new SimpleTransactionIdStore()).withLogEntryReader(logEntryReader()).withStoreId(StoreId.UNKNOWN).build();
    life.add(logFiles);
    final AtomicBoolean end = new AtomicBoolean();
    AllTheMonitoring monitoring = new AllTheMonitoring(end, 100);
    TransactionIdStore txIdStore = new SimpleTransactionIdStore();
    TransactionMetadataCache metadataCache = new TransactionMetadataCache();
    monitoring.setLogFile(logFiles.getLogFile());
    Health health = new DatabaseHealth(mock(DatabasePanicEventGenerator.class), NullLog.getInstance());
    LogRotation rotation = transactionLogRotation(logFiles, Clock.systemUTC(), health, monitoring);
    final TransactionAppender appender = life.add(new BatchingTransactionAppender(logFiles, rotation, metadataCache, txIdStore, health));
    // WHEN
    Race race = new Race();
    for (int i = 0; i < 4; i++) {
        race.addContestant(() -> {
            while (!end.get()) {
                try {
                    appender.append(new TransactionToApply(sillyTransaction(1_000), CursorContext.NULL), LogAppendEvent.NULL);
                } catch (Exception e) {
                    e.printStackTrace(System.out);
                    end.set(true);
                    fail(e.getMessage(), e);
                }
            }
        });
    }
    race.addContestant(endAfterMax(250, MILLISECONDS, end, monitoring));
    race.go();
    // THEN
    assertTrue(monitoring.numberOfRotations() > 0);
}
Also used : DatabaseHealth(org.neo4j.monitoring.DatabaseHealth) TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) TransactionIdStore(org.neo4j.storageengine.api.TransactionIdStore) SimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore) SimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore) Health(org.neo4j.monitoring.Health) DatabaseHealth(org.neo4j.monitoring.DatabaseHealth) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) SimpleLogVersionRepository(org.neo4j.kernel.impl.transaction.SimpleLogVersionRepository) DatabasePanicEventGenerator(org.neo4j.kernel.monitoring.DatabasePanicEventGenerator) LogVersionRepository(org.neo4j.storageengine.api.LogVersionRepository) SimpleLogVersionRepository(org.neo4j.kernel.impl.transaction.SimpleLogVersionRepository) IOException(java.io.IOException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Race(org.neo4j.test.Race) LogRotation(org.neo4j.kernel.impl.transaction.log.rotation.LogRotation) FileLogRotation.transactionLogRotation(org.neo4j.kernel.impl.transaction.log.rotation.FileLogRotation.transactionLogRotation) Test(org.junit.jupiter.api.Test)

Aggregations

DatabaseHealth (org.neo4j.monitoring.DatabaseHealth)8 Health (org.neo4j.monitoring.Health)8 Test (org.junit.jupiter.api.Test)6 IOException (java.io.IOException)5 DatabasePanicEventGenerator (org.neo4j.kernel.monitoring.DatabasePanicEventGenerator)5 LogRotation (org.neo4j.kernel.impl.transaction.log.rotation.LogRotation)3 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)3 TransactionToApply (org.neo4j.kernel.impl.api.TransactionToApply)2 LogFiles (org.neo4j.kernel.impl.transaction.log.files.LogFiles)2 FileLogRotation.transactionLogRotation (org.neo4j.kernel.impl.transaction.log.rotation.FileLogRotation.transactionLogRotation)2 Path (java.nio.file.Path)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 SimpleLogVersionRepository (org.neo4j.kernel.impl.transaction.SimpleLogVersionRepository)1 SimpleTransactionIdStore (org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore)1 BatchingTransactionAppender (org.neo4j.kernel.impl.transaction.log.BatchingTransactionAppender)1 LogHeader (org.neo4j.kernel.impl.transaction.log.entry.LogHeader)1 LogFile (org.neo4j.kernel.impl.transaction.log.files.LogFile)1 FileLogRotation (org.neo4j.kernel.impl.transaction.log.rotation.FileLogRotation)1 LogRotationMonitor (org.neo4j.kernel.impl.transaction.log.rotation.monitor.LogRotationMonitor)1 LogAppendEvent (org.neo4j.kernel.impl.transaction.tracing.LogAppendEvent)1