Search in sources :

Example 36 with PageCache

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

the class PlatformModule method createPageCache.

protected PageCache createPageCache(FileSystemAbstraction fileSystem, Config config, LogService logging, Tracers tracers) {
    Log pageCacheLog = logging.getInternalLog(PageCache.class);
    ConfiguringPageCacheFactory pageCacheFactory = new ConfiguringPageCacheFactory(fileSystem, config, tracers.pageCacheTracer, tracers.pageCursorTracerSupplier, pageCacheLog);
    PageCache pageCache = pageCacheFactory.getOrCreatePageCache();
    if (config.get(GraphDatabaseSettings.dump_configuration)) {
        pageCacheFactory.dumpConfiguration();
    }
    return pageCache;
}
Also used : Log(org.neo4j.logging.Log) ConfiguringPageCacheFactory(org.neo4j.kernel.impl.pagecache.ConfiguringPageCacheFactory) PageCache(org.neo4j.io.pagecache.PageCache)

Example 37 with PageCache

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

the class RecoveryRequiredCheckerTest method shouldWantToRecoverBrokenStore.

@Test
public void shouldWantToRecoverBrokenStore() throws Exception {
    try (FileSystemAbstraction fileSystemAbstraction = createSomeDataAndCrash(storeDir, fileSystem)) {
        PageCache pageCache = pageCacheRule.getPageCache(fileSystemAbstraction);
        RecoveryRequiredChecker recoverer = new RecoveryRequiredChecker(fileSystemAbstraction, pageCache);
        assertThat(recoverer.isRecoveryRequiredAt(storeDir), is(true));
    }
}
Also used : EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Example 38 with PageCache

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

the class RecordStorageEngineTest method mustFlushStoresWithGivenIOLimiter.

@Test
public void mustFlushStoresWithGivenIOLimiter() throws Exception {
    IOLimiter limiter = (stamp, completedIOs, swapper) -> 0;
    FileSystemAbstraction fs = fsRule.get();
    AtomicReference<IOLimiter> observedLimiter = new AtomicReference<>();
    PageCache pageCache = new DelegatingPageCache(pageCacheRule.getPageCache(fs)) {

        @Override
        public void flushAndForce(IOLimiter limiter) throws IOException {
            super.flushAndForce(limiter);
            observedLimiter.set(limiter);
        }
    };
    RecordStorageEngine engine = storageEngineRule.getWith(fs, pageCache).build();
    engine.flushAndForce(limiter);
    assertThat(observedLimiter.get(), sameInstance(limiter));
}
Also used : RecordFormat(org.neo4j.kernel.impl.store.format.RecordFormat) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) StoreFileMetadata(org.neo4j.storageengine.api.StoreFileMetadata) EphemeralFileSystemRule(org.neo4j.test.rule.fs.EphemeralFileSystemRule) Exceptions(org.neo4j.helpers.Exceptions) BatchTransactionApplierFacade(org.neo4j.kernel.impl.api.BatchTransactionApplierFacade) IOLimiter(org.neo4j.io.pagecache.IOLimiter) AtomicReference(java.util.concurrent.atomic.AtomicReference) TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) DelegatingPageCache(org.neo4j.io.pagecache.DelegatingPageCache) RecordStorageEngineRule(org.neo4j.test.rule.RecordStorageEngineRule) Assert.assertSame(org.junit.Assert.assertSame) Assert.assertThat(org.junit.Assert.assertThat) Mockito.doThrow(org.mockito.Mockito.doThrow) PageCacheRule(org.neo4j.test.rule.PageCacheRule) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) TransactionApplicationMode(org.neo4j.storageengine.api.TransactionApplicationMode) CountsTracker(org.neo4j.kernel.impl.store.counts.CountsTracker) Assert.fail(org.junit.Assert.fail) StoreFile(org.neo4j.kernel.impl.storemigration.StoreFile) PageCache(org.neo4j.io.pagecache.PageCache) UnderlyingStorageException(org.neo4j.kernel.impl.store.UnderlyingStorageException) BatchTransactionApplier(org.neo4j.kernel.impl.api.BatchTransactionApplier) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) Assert.assertNotNull(org.junit.Assert.assertNotNull) Collection(java.util.Collection) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) File(java.io.File) Mockito.verify(org.mockito.Mockito.verify) RuleChain(org.junit.rules.RuleChain) Matchers.any(org.mockito.Matchers.any) Rule(org.junit.Rule) CountsAccessor(org.neo4j.kernel.impl.api.CountsAccessor) StoreFileType(org.neo4j.kernel.impl.storemigration.StoreFileType) DatabaseHealth(org.neo4j.kernel.internal.DatabaseHealth) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) StoreType(org.neo4j.kernel.impl.store.StoreType) Matchers.equalTo(org.hamcrest.Matchers.equalTo) CommandsToApply(org.neo4j.storageengine.api.CommandsToApply) Optional(java.util.Optional) FakeCommitment(org.neo4j.kernel.impl.transaction.log.FakeCommitment) Matchers.anyOf(org.hamcrest.Matchers.anyOf) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) Mockito.mock(org.mockito.Mockito.mock) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DelegatingPageCache(org.neo4j.io.pagecache.DelegatingPageCache) IOLimiter(org.neo4j.io.pagecache.IOLimiter) AtomicReference(java.util.concurrent.atomic.AtomicReference) DelegatingPageCache(org.neo4j.io.pagecache.DelegatingPageCache) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Example 39 with PageCache

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

the class ConfigurableStandalonePageCacheFactoryTest method mustAutomaticallyStartEvictionThread.

@Test(timeout = 10000)
public void mustAutomaticallyStartEvictionThread() throws IOException {
    try (FileSystemAbstraction fs = new DelegateFileSystemAbstraction(Jimfs.newFileSystem(jimConfig()))) {
        File file = new File("/a").getCanonicalFile();
        fs.create(file).close();
        try (PageCache cache = ConfigurableStandalonePageCacheFactory.createPageCache(fs);
            PagedFile pf = cache.map(file, 4096);
            PageCursor cursor = pf.io(0, PagedFile.PF_SHARED_WRITE_LOCK)) {
            // If the eviction thread has not been started, then this test will block forever.
            for (int i = 0; i < 10_000; i++) {
                assertTrue(cursor.next());
                cursor.putInt(42);
            }
        }
    }
}
Also used : DelegateFileSystemAbstraction(org.neo4j.io.fs.DelegateFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) PagedFile(org.neo4j.io.pagecache.PagedFile) DelegateFileSystemAbstraction(org.neo4j.io.fs.DelegateFileSystemAbstraction) PagedFile(org.neo4j.io.pagecache.PagedFile) File(java.io.File) PageCache(org.neo4j.io.pagecache.PageCache) PageCursor(org.neo4j.io.pagecache.PageCursor) Test(org.junit.Test)

Example 40 with PageCache

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

the class ConfiguringPageCacheFactoryTest method mustIgnoreExplicitlySpecifiedCachePageSizeIfPageSwapperHintIsStrict.

@Test
public void mustIgnoreExplicitlySpecifiedCachePageSizeIfPageSwapperHintIsStrict() throws Exception {
    // Given
    int cachePageSizeHint = 16 * 1024;
    PageSwapperFactoryForTesting.cachePageSizeHint.set(cachePageSizeHint);
    PageSwapperFactoryForTesting.cachePageSizeHintIsStrict.set(true);
    Config config = Config.embeddedDefaults(stringMap(GraphDatabaseSettings.pagecache_swapper.name(), TEST_PAGESWAPPER_NAME));
    // When
    ConfiguringPageCacheFactory factory = new ConfiguringPageCacheFactory(fsRule.get(), config, PageCacheTracer.NULL, PageCursorTracerSupplier.NULL, NullLog.getInstance());
    // Then
    try (PageCache cache = factory.getOrCreatePageCache()) {
        assertThat(cache.pageSize(), is(cachePageSizeHint));
    }
}
Also used : Config(org.neo4j.kernel.configuration.Config) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

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