Search in sources :

Example 6 with DatabaseHealth

use of org.neo4j.kernel.internal.DatabaseHealth in project neo4j by neo4j.

the class NeoStoreDataSourceTest method databaseHealthShouldBeHealedOnStart.

@Test
public void databaseHealthShouldBeHealedOnStart() throws Throwable {
    NeoStoreDataSource theDataSource = null;
    try {
        DatabaseHealth databaseHealth = new DatabaseHealth(mock(DatabasePanicEventGenerator.class), NullLogProvider.getInstance().getLog(DatabaseHealth.class));
        theDataSource = dsRule.getDataSource(dir.graphDbDir(), fs.get(), pageCacheRule.getPageCache(fs.get()), stringMap(), databaseHealth);
        databaseHealth.panic(new Throwable());
        theDataSource.start();
        databaseHealth.assertHealthy(Throwable.class);
    } finally {
        if (theDataSource != null) {
            theDataSource.stop();
            theDataSource.shutdown();
        }
    }
}
Also used : DatabaseHealth(org.neo4j.kernel.internal.DatabaseHealth) DatabasePanicEventGenerator(org.neo4j.kernel.impl.core.DatabasePanicEventGenerator) Test(org.junit.Test)

Example 7 with DatabaseHealth

use of org.neo4j.kernel.internal.DatabaseHealth in project neo4j by neo4j.

the class NeoStoreDataSourceTest method flushOfThePageCacheOnShutdownDoesNotHappenIfTheDbIsUnhealthy.

@Test
public void flushOfThePageCacheOnShutdownDoesNotHappenIfTheDbIsUnhealthy() throws IOException {
    DatabaseHealth health = mock(DatabaseHealth.class);
    when(health.isHealthy()).thenReturn(false);
    PageCache pageCache = spy(pageCacheRule.getPageCache(fs.get()));
    NeoStoreDataSource ds = dsRule.getDataSource(dir.graphDbDir(), fs.get(), pageCache, stringMap(), health);
    ds.init();
    ds.start();
    verify(pageCache, never()).flushAndForce();
    ds.stop();
    ds.shutdown();
    verify(pageCache, never()).flushAndForce(IOLimiter.unlimited());
}
Also used : DatabaseHealth(org.neo4j.kernel.internal.DatabaseHealth) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Example 8 with DatabaseHealth

use of org.neo4j.kernel.internal.DatabaseHealth in project neo4j by neo4j.

the class NeoStoreDataSourceTest method flushOfThePageCacheOnShutdownHappensIfTheDbIsHealthy.

@Test
public void flushOfThePageCacheOnShutdownHappensIfTheDbIsHealthy() throws IOException {
    DatabaseHealth health = mock(DatabaseHealth.class);
    when(health.isHealthy()).thenReturn(true);
    PageCache pageCache = spy(pageCacheRule.getPageCache(fs.get()));
    NeoStoreDataSource ds = dsRule.getDataSource(dir.graphDbDir(), fs.get(), pageCache, stringMap(), health);
    ds.init();
    ds.start();
    verify(pageCache, never()).flushAndForce();
    ds.stop();
    ds.shutdown();
    verify(pageCache).flushAndForce(IOLimiter.unlimited());
}
Also used : DatabaseHealth(org.neo4j.kernel.internal.DatabaseHealth) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Example 9 with DatabaseHealth

use of org.neo4j.kernel.internal.DatabaseHealth in project neo4j by neo4j.

the class TransactionLogAppendAndRotateIT method shouldKeepTransactionsIntactWhenConcurrentlyRotationAndAppending.

@Test
public void shouldKeepTransactionsIntactWhenConcurrentlyRotationAndAppending() throws Throwable {
    // GIVEN
    PhysicalLogFiles logFiles = new PhysicalLogFiles(directory.directory().getAbsoluteFile(), fileSystemRule.get());
    long rotationThreshold = mebiBytes(1);
    LogVersionRepository logVersionRepository = new DeadSimpleLogVersionRepository(0);
    final AtomicBoolean end = new AtomicBoolean();
    AllTheMonitoring monitoring = new AllTheMonitoring(end, 100);
    TransactionIdStore txIdStore = new DeadSimpleTransactionIdStore();
    TransactionMetadataCache metadataCache = new TransactionMetadataCache(100);
    LogHeaderCache logHeaderCache = new LogHeaderCache(10);
    LogFile logFile = life.add(new PhysicalLogFile(fileSystemRule.get(), logFiles, rotationThreshold, () -> txIdStore.getLastCommittedTransactionId(), logVersionRepository, monitoring, logHeaderCache));
    monitoring.setLogFile(logFile);
    DatabaseHealth health = new DatabaseHealth(mock(DatabasePanicEventGenerator.class), NullLog.getInstance());
    LogRotation rotation = new LogRotationImpl(monitoring, logFile, health);
    final TransactionAppender appender = life.add(new BatchingTransactionAppender(logFile, rotation, metadataCache, txIdStore, BYPASS, health));
    // WHEN
    Race race = new Race();
    for (int i = 0; i < 10; i++) {
        race.addContestant(new Runnable() {

            @Override
            public void run() {
                while (!end.get()) {
                    try {
                        appender.append(new TransactionToApply(sillyTransaction(1_000)), NULL);
                    } catch (Exception e) {
                        e.printStackTrace(System.out);
                        end.set(true);
                        fail(e.getMessage());
                    }
                }
            }
        });
    }
    race.addContestant(endAfterMax(10, SECONDS, end));
    race.go();
    // THEN
    assertTrue(monitoring.numberOfRotations() > 0);
}
Also used : DatabaseHealth(org.neo4j.kernel.internal.DatabaseHealth) TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) DeadSimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.DeadSimpleTransactionIdStore) DeadSimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.DeadSimpleTransactionIdStore) DatabasePanicEventGenerator(org.neo4j.kernel.impl.core.DatabasePanicEventGenerator) DeadSimpleLogVersionRepository(org.neo4j.kernel.impl.transaction.DeadSimpleLogVersionRepository) DeadSimpleLogVersionRepository(org.neo4j.kernel.impl.transaction.DeadSimpleLogVersionRepository) IOException(java.io.IOException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Race(org.neo4j.test.Race) LogRotation(org.neo4j.kernel.impl.transaction.log.rotation.LogRotation) LogRotationImpl(org.neo4j.kernel.impl.transaction.log.rotation.LogRotationImpl) Test(org.junit.Test)

Aggregations

DatabaseHealth (org.neo4j.kernel.internal.DatabaseHealth)9 Test (org.junit.Test)7 IOException (java.io.IOException)5 PageCache (org.neo4j.io.pagecache.PageCache)5 File (java.io.File)4 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)4 DatabasePanicEventGenerator (org.neo4j.kernel.impl.core.DatabasePanicEventGenerator)4 LogRotationImpl (org.neo4j.kernel.impl.transaction.log.rotation.LogRotationImpl)3 Exceptions (org.neo4j.helpers.Exceptions)2 IOLimiter (org.neo4j.io.pagecache.IOLimiter)2 BatchingTransactionAppender (org.neo4j.kernel.impl.transaction.log.BatchingTransactionAppender)2 TransactionIdStore (org.neo4j.kernel.impl.transaction.log.TransactionIdStore)2 Log (org.neo4j.logging.Log)2 StoreFileMetadata (org.neo4j.storageengine.api.StoreFileMetadata)2 Clock (java.time.Clock)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Optional (java.util.Optional)1 CountDownLatch (java.util.concurrent.CountDownLatch)1