Search in sources :

Example 1 with Health

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

the class BatchingTransactionAppenderRotationIT method correctLastAppliedToPreviousLogTransactionInHeaderOnLogFileRotation.

@Test
void correctLastAppliedToPreviousLogTransactionInHeaderOnLogFileRotation() throws IOException {
    LogFiles logFiles = getLogFiles(logVersionRepository, transactionIdStore);
    life.add(logFiles);
    Health databaseHealth = getDatabaseHealth();
    LogRotation logRotation = FileLogRotation.transactionLogRotation(logFiles, Clock.systemUTC(), databaseHealth, monitors.newMonitor(LogRotationMonitor.class));
    TransactionMetadataCache transactionMetadataCache = new TransactionMetadataCache();
    BatchingTransactionAppender transactionAppender = new BatchingTransactionAppender(logFiles, logRotation, transactionMetadataCache, transactionIdStore, databaseHealth);
    life.add(transactionAppender);
    LogAppendEvent logAppendEvent = new RotationLogAppendEvent(logRotation);
    TransactionToApply transactionToApply = prepareTransaction();
    transactionAppender.append(transactionToApply, logAppendEvent);
    LogFile logFile = logFiles.getLogFile();
    assertEquals(1, logFile.getHighestLogVersion());
    Path highestLogFile = logFile.getHighestLogFile();
    LogHeader logHeader = LogHeaderReader.readLogHeader(fileSystem, highestLogFile, INSTANCE);
    assertEquals(2, logHeader.getLastCommittedTxId());
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) LogFile(org.neo4j.kernel.impl.transaction.log.files.LogFile) Path(java.nio.file.Path) Health(org.neo4j.monitoring.Health) DatabaseHealth(org.neo4j.monitoring.DatabaseHealth) LogRotationMonitor(org.neo4j.kernel.impl.transaction.log.rotation.monitor.LogRotationMonitor) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) FileLogRotation(org.neo4j.kernel.impl.transaction.log.rotation.FileLogRotation) LogRotation(org.neo4j.kernel.impl.transaction.log.rotation.LogRotation) LogAppendEvent(org.neo4j.kernel.impl.transaction.tracing.LogAppendEvent) LogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeader) Test(org.junit.jupiter.api.Test)

Example 2 with Health

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

the class RecoveryCleanupIT method dirtyDatabase.

private void dirtyDatabase() throws IOException {
    db = startDatabase();
    Health databaseHealth = databaseHealth(db);
    index(db);
    someData(db);
    checkpoint(db);
    someData(db);
    databaseHealth.panic(new Throwable("Trigger recovery on next startup"));
    managementService.shutdown();
    db = null;
}
Also used : Health(org.neo4j.monitoring.Health) DatabaseHealth(org.neo4j.monitoring.DatabaseHealth)

Example 3 with Health

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

the class DatabaseHealthTest method shouldGenerateDatabasePanicEvents.

@Test
void shouldGenerateDatabasePanicEvents() {
    // GIVEN
    DatabasePanicEventGenerator generator = mock(DatabasePanicEventGenerator.class);
    Health databaseHealth = new DatabaseHealth(generator, NullLogProvider.getInstance().getLog(DatabaseHealth.class));
    databaseHealth.healed();
    // WHEN
    Exception cause = new Exception("My own fault");
    databaseHealth.panic(cause);
    databaseHealth.panic(cause);
    // THEN
    verify(generator).panic(cause);
}
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) Test(org.junit.jupiter.api.Test)

Example 4 with Health

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

the class DatabaseHealthTest method databaseWithCriticalErrorsCanNotBeHealed.

@Test
void databaseWithCriticalErrorsCanNotBeHealed() {
    AssertableLogProvider logProvider = new AssertableLogProvider();
    Health databaseHealth = new DatabaseHealth(mock(DatabasePanicEventGenerator.class), logProvider.getLog(DatabaseHealth.class));
    assertTrue(databaseHealth.isHealthy());
    IOException criticalException = new IOException("Space exception.", new OutOfMemoryError("Out of memory."));
    databaseHealth.panic(criticalException);
    assertFalse(databaseHealth.isHealthy());
    assertFalse(databaseHealth.healed());
    assertThat(logProvider).doesNotContainMessage("Database health set to OK").containsMessages("Database encountered a critical error and can't be healed. Restart required.");
}
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 5 with Health

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

the class DatabaseHealthTest method healDatabaseWithoutCriticalErrors.

@Test
void healDatabaseWithoutCriticalErrors() {
    AssertableLogProvider logProvider = new AssertableLogProvider();
    Health databaseHealth = new DatabaseHealth(mock(DatabasePanicEventGenerator.class), logProvider.getLog(DatabaseHealth.class));
    assertTrue(databaseHealth.isHealthy());
    databaseHealth.panic(new IOException("Space exception."));
    assertFalse(databaseHealth.isHealthy());
    assertTrue(databaseHealth.healed());
    assertThat(logProvider).containsMessages("Database health set to OK").doesNotContainMessage("Database encountered a critical error and can't be healed. Restart required.");
}
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)

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