Search in sources :

Example 61 with PageCache

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

the class StreamToDiskTest method shouldLetPageCacheHandleRecordStoresAndNativeLabelScanStoreFiles.

@Test
public void shouldLetPageCacheHandleRecordStoresAndNativeLabelScanStoreFiles() throws Exception {
    // GIVEN
    PageCache pageCache = spy(pageCacheRule.getPageCache(fs));
    Monitors monitors = new Monitors();
    try (StreamToDisk writer = new StreamToDisk(directory.absolutePath(), fs, pageCache, monitors)) {
        ByteBuffer tempBuffer = ByteBuffer.allocate(128);
        // WHEN
        for (StoreType type : StoreType.values()) {
            if (type.isRecordStore()) {
                String fileName = type.getStoreFile().fileName(STORE);
                writeAndVerifyWrittenThroughPageCache(pageCache, writer, tempBuffer, fileName);
            }
        }
        writeAndVerifyWrittenThroughPageCache(pageCache, writer, tempBuffer, NativeLabelScanStore.FILE_NAME);
    }
}
Also used : StoreType(org.neo4j.kernel.impl.store.StoreType) Monitors(org.neo4j.kernel.monitoring.Monitors) ByteBuffer(java.nio.ByteBuffer) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Example 62 with PageCache

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

the class StoreFilesTest method deleteMustNotDeleteIgnoredFiles.

@Test
public void deleteMustNotDeleteIgnoredFiles() throws Exception {
    File dir = getBaseDir();
    File a = new File(dir, "a");
    File b = new File(dir, "b");
    File c = new File(dir, "c");
    File d = new File(dir, "d");
    createOnFileSystem(a);
    createOnFileSystem(c);
    createOnPageCache(b);
    createOnPageCache(d);
    FilenameFilter filter = (directory, name) -> !name.equals("c") && !name.equals("d");
    storeFiles = new StoreFiles(fs, pageCache, filter);
    storeFiles.delete(dir);
    assertFalse(fs.fileExists(a));
    assertFalse(pc.fileExists(b));
    assertTrue(fs.fileExists(c));
    assertTrue(pc.fileExists(d));
}
Also used : FilenameFilter(java.io.FilenameFilter) Arrays(java.util.Arrays) EphemeralFileSystemRule(org.neo4j.test.rule.fs.EphemeralFileSystemRule) Supplier(java.util.function.Supplier) Assert.assertThat(org.junit.Assert.assertThat) PageCacheRule(org.neo4j.test.rule.PageCacheRule) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Before(org.junit.Before) PageCache(org.neo4j.io.pagecache.PageCache) Position(org.neo4j.kernel.impl.store.MetaDataStore.Position) TestDirectory(org.neo4j.test.rule.TestDirectory) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) File(java.io.File) StoreId(org.neo4j.causalclustering.identity.StoreId) RuleChain(org.junit.rules.RuleChain) EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) List(java.util.List) Rule(org.junit.Rule) MetaDataStore(org.neo4j.kernel.impl.store.MetaDataStore) Assert.assertFalse(org.junit.Assert.assertFalse) Matchers.is(org.hamcrest.Matchers.is) Collections(java.util.Collections) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) FilenameFilter(java.io.FilenameFilter) File(java.io.File) Test(org.junit.Test)

Example 63 with PageCache

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

the class DumpStore method main.

public static void main(String... args) throws Exception {
    if (args == null || args.length == 0) {
        System.err.println("SYNTAX: [file[:id[,id]*]]+");
        return;
    }
    try (DefaultFileSystemAbstraction fs = new DefaultFileSystemAbstraction();
        PageCache pageCache = createPageCache(fs)) {
        final DefaultIdGeneratorFactory idGeneratorFactory = new DefaultIdGeneratorFactory(fs);
        Function<File, StoreFactory> createStoreFactory = file -> new StoreFactory(file.getParentFile(), Config.defaults(), idGeneratorFactory, pageCache, fs, logProvider());
        for (String arg : args) {
            dumpFile(createStoreFactory, arg);
        }
    }
}
Also used : LogProvider(org.neo4j.logging.LogProvider) StandalonePageCacheFactory.createPageCache(org.neo4j.io.pagecache.impl.muninn.StandalonePageCacheFactory.createPageCache) Token(org.neo4j.storageengine.api.Token) NullLogProvider(org.neo4j.logging.NullLogProvider) Function(java.util.function.Function) ByteBuffer(java.nio.ByteBuffer) NeoStores(org.neo4j.kernel.impl.store.NeoStores) AbstractBaseRecord(org.neo4j.kernel.impl.store.record.AbstractBaseRecord) FormattedLogProvider(org.neo4j.logging.FormattedLogProvider) CommonAbstractStore(org.neo4j.kernel.impl.store.CommonAbstractStore) TokenRecord(org.neo4j.kernel.impl.store.record.TokenRecord) PrintStream(java.io.PrintStream) PageCache(org.neo4j.io.pagecache.PageCache) Config(org.neo4j.kernel.configuration.Config) DefaultIdGeneratorFactory(org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory) FORCE(org.neo4j.kernel.impl.store.record.RecordLoad.FORCE) SchemaStorage(org.neo4j.kernel.impl.store.SchemaStorage) SchemaStore(org.neo4j.kernel.impl.store.SchemaStore) TokenStore(org.neo4j.kernel.impl.store.TokenStore) PrintStreamLogger(org.neo4j.logging.PrintStreamLogger) File(java.io.File) DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) RecordStore(org.neo4j.kernel.impl.store.RecordStore) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) HexPrinter(org.neo4j.kernel.impl.util.HexPrinter) StoreType(org.neo4j.kernel.impl.store.StoreType) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) NodeStore(org.neo4j.kernel.impl.store.NodeStore) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) DefaultIdGeneratorFactory(org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) File(java.io.File) StandalonePageCacheFactory.createPageCache(org.neo4j.io.pagecache.impl.muninn.StandalonePageCacheFactory.createPageCache) PageCache(org.neo4j.io.pagecache.PageCache)

Example 64 with PageCache

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

the class ReadReplicaReplicationIT method changeStoreId.

private void changeStoreId(ReadReplica replica) throws IOException {
    File neoStoreFile = new File(replica.storeDir(), MetaDataStore.DEFAULT_NAME);
    PageCache pageCache = replica.database().getDependencyResolver().resolveDependency(PageCache.class);
    MetaDataStore.setRecord(pageCache, neoStoreFile, TIME, System.currentTimeMillis());
}
Also used : File(java.io.File) PageCache(org.neo4j.io.pagecache.PageCache)

Example 65 with PageCache

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

the class SwitchToSlaveBranchThenCopyTest method mockPageCache.

private PageCache mockPageCache() throws IOException {
    PageCache pageCacheMock = mock(PageCache.class);
    PagedFile pagedFileMock = mock(PagedFile.class);
    when(pagedFileMock.getLastPageId()).thenReturn(1L);
    when(pageCacheMock.map(any(File.class), anyInt())).thenThrow(new IOException()).thenThrow(new IOException()).thenReturn(pagedFileMock);
    return pageCacheMock;
}
Also used : PagedFile(org.neo4j.io.pagecache.PagedFile) IOException(java.io.IOException) PagedFile(org.neo4j.io.pagecache.PagedFile) File(java.io.File) PageCache(org.neo4j.io.pagecache.PageCache)

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