Search in sources :

Example 76 with PageCache

use of org.neo4j.io.pagecache.PageCache 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 77 with PageCache

use of org.neo4j.io.pagecache.PageCache in project neo4j by neo4j.

the class RunOutOfDiskSpaceIT method shouldPropagateIOExceptions.

@Test
public void shouldPropagateIOExceptions() throws Exception {
    // Given
    TransactionFailureException exceptionThrown = null;
    File storeDir = testDirectory.absolutePath();
    LimitedFileSystemGraphDatabase db = new LimitedFileSystemGraphDatabase(storeDir);
    try (Transaction tx = db.beginTx()) {
        db.createNode();
        tx.success();
    }
    long logVersion = db.getDependencyResolver().resolveDependency(LogVersionRepository.class).getCurrentLogVersion();
    db.runOutOfDiskSpaceNao();
    // When
    try (Transaction tx = db.beginTx()) {
        db.createNode();
        tx.success();
    } catch (TransactionFailureException e) {
        exceptionThrown = e;
    } finally {
        Assert.assertNotNull("Expected tx finish to throw TransactionFailureException when filesystem is full.", exceptionThrown);
        assertTrue(Exceptions.contains(exceptionThrown, IOException.class));
    }
    // to help shutting down the db
    db.somehowGainMoreDiskSpace();
    db.shutdown();
    PageCache pageCache = pageCacheRule.getPageCache(db.getFileSystem());
    File neoStore = new File(storeDir, MetaDataStore.DEFAULT_NAME);
    assertEquals(logVersion, MetaDataStore.getRecord(pageCache, neoStore, MetaDataStore.Position.LOG_VERSION));
}
Also used : IOException(java.io.IOException) File(java.io.File) LogVersionRepository(org.neo4j.kernel.impl.transaction.log.LogVersionRepository) LimitedFileSystemGraphDatabase(org.neo4j.test.LimitedFileSystemGraphDatabase) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Example 78 with PageCache

use of org.neo4j.io.pagecache.PageCache in project neo4j by neo4j.

the class RunOutOfDiskSpaceIT method shouldStopDatabaseWhenOutOfDiskSpace.

@Test
public void shouldStopDatabaseWhenOutOfDiskSpace() throws Exception {
    // Given
    TransactionFailureException expectedCommitException = null;
    TransactionFailureException expectedStartException = null;
    File storeDir = testDirectory.absolutePath();
    LimitedFileSystemGraphDatabase db = cleanup.add(new LimitedFileSystemGraphDatabase(storeDir));
    try (Transaction tx = db.beginTx()) {
        db.createNode();
        tx.success();
    }
    long logVersion = db.getDependencyResolver().resolveDependency(LogVersionRepository.class).getCurrentLogVersion();
    db.runOutOfDiskSpaceNao();
    try (Transaction tx = db.beginTx()) {
        db.createNode();
        tx.success();
    } catch (TransactionFailureException e) {
        expectedCommitException = e;
    } finally {
        Assert.assertNotNull("Expected tx finish to throw TransactionFailureException when filesystem is full.", expectedCommitException);
    }
    // When
    try (Transaction transaction = db.beginTx()) {
        fail("Expected tx begin to throw TransactionFailureException when tx manager breaks.");
    } catch (TransactionFailureException e) {
        expectedStartException = e;
    } finally {
        Assert.assertNotNull("Expected tx begin to throw TransactionFailureException when tx manager breaks.", expectedStartException);
    }
    // Then
    // to help shutting down the db
    db.somehowGainMoreDiskSpace();
    db.shutdown();
    PageCache pageCache = pageCacheRule.getPageCache(db.getFileSystem());
    File neoStore = new File(storeDir, MetaDataStore.DEFAULT_NAME);
    assertEquals(logVersion, MetaDataStore.getRecord(pageCache, neoStore, MetaDataStore.Position.LOG_VERSION));
}
Also used : File(java.io.File) LogVersionRepository(org.neo4j.kernel.impl.transaction.log.LogVersionRepository) LimitedFileSystemGraphDatabase(org.neo4j.test.LimitedFileSystemGraphDatabase) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Example 79 with PageCache

use of org.neo4j.io.pagecache.PageCache in project neo4j by neo4j.

the class BatchingNeoStores method batchingNeoStores.

public static BatchingNeoStores batchingNeoStores(FileSystemAbstraction fileSystem, File storeDir, RecordFormats recordFormats, Configuration config, LogService logService, AdditionalInitialIds initialIds, Config dbConfig) {
    Config neo4jConfig = getNeo4jConfig(config, dbConfig);
    final PageCacheTracer tracer = new DefaultPageCacheTracer();
    PageCache pageCache = createPageCache(fileSystem, neo4jConfig, logService.getInternalLogProvider(), tracer, DefaultPageCursorTracerSupplier.INSTANCE);
    BatchingNeoStores batchingNeoStores = new BatchingNeoStores(fileSystem, pageCache, storeDir, recordFormats, neo4jConfig, logService, initialIds, false, tracer::bytesWritten);
    return batchingNeoStores;
}
Also used : Config(org.neo4j.kernel.configuration.Config) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) PageCacheTracer(org.neo4j.io.pagecache.tracing.PageCacheTracer) PageCache(org.neo4j.io.pagecache.PageCache) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer)

Example 80 with PageCache

use of org.neo4j.io.pagecache.PageCache in project neo4j by neo4j.

the class ConsistencyCheckService method runFullConsistencyCheck.

public Result runFullConsistencyCheck(File storeDir, Config config, ProgressMonitorFactory progressFactory, LogProvider logProvider, FileSystemAbstraction fileSystem, boolean verbose, File reportDir, CheckConsistencyConfig checkConsistencyConfig) throws ConsistencyCheckIncompleteException, IOException {
    Log log = logProvider.getLog(getClass());
    ConfiguringPageCacheFactory pageCacheFactory = new ConfiguringPageCacheFactory(fileSystem, config, PageCacheTracer.NULL, PageCursorTracerSupplier.NULL, logProvider.getLog(PageCache.class));
    PageCache pageCache = pageCacheFactory.getOrCreatePageCache();
    try {
        return runFullConsistencyCheck(storeDir, config, progressFactory, logProvider, fileSystem, pageCache, verbose, reportDir, checkConsistencyConfig);
    } finally {
        try {
            pageCache.close();
        } catch (Exception e) {
            log.error("Failure during shutdown of the page cache", e);
        }
    }
}
Also used : Log(org.neo4j.logging.Log) DuplicatingLog(org.neo4j.logging.DuplicatingLog) ConfiguringPageCacheFactory(org.neo4j.kernel.impl.pagecache.ConfiguringPageCacheFactory) PageCache(org.neo4j.io.pagecache.PageCache) IOException(java.io.IOException) ConsistencyCheckIncompleteException(org.neo4j.consistency.checking.full.ConsistencyCheckIncompleteException)

Aggregations

PageCache (org.neo4j.io.pagecache.PageCache)134 Test (org.junit.Test)90 File (java.io.File)74 Config (org.neo4j.kernel.configuration.Config)39 IOException (java.io.IOException)32 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)31 StoreVersionCheck (org.neo4j.kernel.impl.storemigration.StoreVersionCheck)19 LegacyStoreVersionCheck (org.neo4j.kernel.impl.storemigration.legacystore.LegacyStoreVersionCheck)17 UpgradableDatabase (org.neo4j.kernel.impl.storemigration.UpgradableDatabase)16 PagedFile (org.neo4j.io.pagecache.PagedFile)15 LogService (org.neo4j.kernel.impl.logging.LogService)13 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)12 NullLogService (org.neo4j.kernel.impl.logging.NullLogService)12 StoreFactory (org.neo4j.kernel.impl.store.StoreFactory)12 NeoStores (org.neo4j.kernel.impl.store.NeoStores)11 RecordFormatSelector.selectForConfig (org.neo4j.kernel.impl.store.format.RecordFormatSelector.selectForConfig)11 RecordFormatSelector.selectForStoreOrConfig (org.neo4j.kernel.impl.store.format.RecordFormatSelector.selectForStoreOrConfig)11 Before (org.junit.Before)10 TransactionId (org.neo4j.kernel.impl.store.TransactionId)10 StoreCopyClient (org.neo4j.com.storecopy.StoreCopyClient)9