Search in sources :

Example 6 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 7 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)

Example 8 with PageCache

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

the class ConfiguringPageCacheFactoryTest method shouldFitAsManyPagesAsItCan.

@Test
public void shouldFitAsManyPagesAsItCan() throws Throwable {
    // Given
    final int pageSize = 8192;
    final int maxPages = 60;
    Config config = Config.embeddedDefaults(stringMap(pagecache_memory.name(), Integer.toString(pageSize * maxPages)));
    // When
    ConfiguringPageCacheFactory factory = new ConfiguringPageCacheFactory(fsRule.get(), config, PageCacheTracer.NULL, PageCursorTracerSupplier.NULL, NullLog.getInstance());
    // Then
    try (PageCache cache = factory.getOrCreatePageCache()) {
        assertThat(cache.pageSize(), equalTo(pageSize));
        assertThat(cache.maxCachedPages(), equalTo(maxPages));
    }
}
Also used : Config(org.neo4j.kernel.configuration.Config) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Example 9 with PageCache

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

the class ConfigurablePageCacheRule method createPageCache.

private PageCache createPageCache(FileSystemAbstraction fs, PageCacheConfig pageCacheConfig, Config config) {
    PageCacheTracer tracer = selectConfig(baseConfig.tracer, pageCacheConfig.tracer, PageCacheTracer.NULL);
    PageCursorTracerSupplier cursorTracerSupplier = selectConfig(baseConfig.pageCursorTracerSupplier, pageCacheConfig.pageCursorTracerSupplier, DefaultPageCursorTracerSupplier.INSTANCE);
    Config finalConfig = config.withDefaults(MapUtil.stringMap(GraphDatabaseSettings.pagecache_memory.name(), "8M"));
    FormattedLogProvider logProvider = FormattedLogProvider.toOutputStream(System.err);
    ConfiguringPageCacheFactory pageCacheFactory = new ConfiguringPageCacheFactory(fs, finalConfig, tracer, cursorTracerSupplier, logProvider.getLog(PageCache.class)) {

        @Override
        public int calculatePageSize(Config config, PageSwapperFactory swapperFactory) {
            if (pageCacheConfig.pageSize != null) {
                return pageCacheConfig.pageSize;
            }
            return super.calculatePageSize(config, swapperFactory);
        }
    };
    return pageCacheFactory.getOrCreatePageCache();
}
Also used : PageSwapperFactory(org.neo4j.io.pagecache.PageSwapperFactory) PageCursorTracerSupplier(org.neo4j.io.pagecache.tracing.cursor.PageCursorTracerSupplier) DefaultPageCursorTracerSupplier(org.neo4j.io.pagecache.tracing.cursor.DefaultPageCursorTracerSupplier) Config(org.neo4j.kernel.configuration.Config) PageCacheTracer(org.neo4j.io.pagecache.tracing.PageCacheTracer) ConfiguringPageCacheFactory(org.neo4j.kernel.impl.pagecache.ConfiguringPageCacheFactory) PageCache(org.neo4j.io.pagecache.PageCache) FormattedLogProvider(org.neo4j.logging.FormattedLogProvider)

Example 10 with PageCache

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

the class BatchInserterImplTest method testHonorsPassedInParams.

@Test
public void testHonorsPassedInParams() throws Exception {
    BatchInserter inserter = BatchInserters.inserter(testDirectory.graphDbDir(), fileSystemRule.get(), stringMap(GraphDatabaseSettings.pagecache_memory.name(), "280K"));
    NeoStores neoStores = ReflectionUtil.getPrivateField(inserter, "neoStores", NeoStores.class);
    PageCache pageCache = ReflectionUtil.getPrivateField(neoStores, "pageCache", PageCache.class);
    inserter.shutdown();
    int mappedMemoryTotalSize = pageCache.maxCachedPages() * pageCache.pageSize();
    assertThat("memory mapped config is active", mappedMemoryTotalSize, is(280 * 1024));
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) NeoStores(org.neo4j.kernel.impl.store.NeoStores) 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