Search in sources :

Example 21 with PageCache

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

the class GraphStoreFixture method directStoreAccess.

public DirectStoreAccess directStoreAccess() {
    if (directStoreAccess == null) {
        fileSystem = new DefaultFileSystemAbstraction();
        PageCache pageCache = getPageCache(fileSystem);
        LogProvider logProvider = NullLogProvider.getInstance();
        StoreFactory storeFactory = new StoreFactory(directory, pageCache, fileSystem, logProvider);
        neoStore = storeFactory.openAllNeoStores();
        StoreAccess nativeStores;
        if (keepStatistics) {
            AccessStatistics accessStatistics = new AccessStatistics();
            statistics = new VerboseStatistics(accessStatistics, new DefaultCounts(defaultConsistencyCheckThreadsNumber()), NullLog.getInstance());
            nativeStores = new AccessStatsKeepingStoreAccess(neoStore, accessStatistics);
        } else {
            statistics = Statistics.NONE;
            nativeStores = new StoreAccess(neoStore);
        }
        nativeStores.initialize();
        Config config = Config.empty();
        OperationalMode operationalMode = OperationalMode.single;
        IndexStoreView indexStoreView = new NeoStoreIndexStoreView(LockService.NO_LOCK_SERVICE, nativeStores.getRawNeoStores());
        Dependencies dependencies = new Dependencies();
        dependencies.satisfyDependencies(Config.defaults(), fileSystem, new SimpleLogService(logProvider, logProvider), indexStoreView, pageCache);
        KernelContext kernelContext = new SimpleKernelContext(directory, UNKNOWN, dependencies);
        LabelScanStore labelScanStore = startLabelScanStore(config, dependencies, kernelContext);
        directStoreAccess = new DirectStoreAccess(nativeStores, labelScanStore, createIndexes(fileSystem, config, operationalMode));
    }
    return directStoreAccess;
}
Also used : LabelScanStore(org.neo4j.kernel.api.labelscan.LabelScanStore) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) AccessStatsKeepingStoreAccess(org.neo4j.consistency.statistics.AccessStatsKeepingStoreAccess) DirectStoreAccess(org.neo4j.kernel.api.direct.DirectStoreAccess) StoreAccess(org.neo4j.kernel.impl.store.StoreAccess) SimpleLogService(org.neo4j.kernel.impl.logging.SimpleLogService) Config(org.neo4j.kernel.configuration.Config) DirectStoreAccess(org.neo4j.kernel.api.direct.DirectStoreAccess) AccessStatsKeepingStoreAccess(org.neo4j.consistency.statistics.AccessStatsKeepingStoreAccess) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) OperationalMode(org.neo4j.kernel.impl.factory.OperationalMode) NullLogProvider(org.neo4j.logging.NullLogProvider) FormattedLogProvider(org.neo4j.logging.FormattedLogProvider) LogProvider(org.neo4j.logging.LogProvider) NeoStoreIndexStoreView(org.neo4j.kernel.impl.transaction.state.storeview.NeoStoreIndexStoreView) DefaultCounts(org.neo4j.consistency.statistics.DefaultCounts) AccessStatistics(org.neo4j.consistency.statistics.AccessStatistics) IndexStoreView(org.neo4j.kernel.impl.api.index.IndexStoreView) NeoStoreIndexStoreView(org.neo4j.kernel.impl.transaction.state.storeview.NeoStoreIndexStoreView) SimpleKernelContext(org.neo4j.kernel.impl.spi.SimpleKernelContext) VerboseStatistics(org.neo4j.consistency.statistics.VerboseStatistics) Dependencies(org.neo4j.kernel.impl.util.Dependencies) PageCache(org.neo4j.io.pagecache.PageCache) SimpleKernelContext(org.neo4j.kernel.impl.spi.SimpleKernelContext) KernelContext(org.neo4j.kernel.impl.spi.KernelContext)

Example 22 with PageCache

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

the class NodeStoreTest method shouldCloseStoreFileOnFailureToOpen.

@Test
public void shouldCloseStoreFileOnFailureToOpen() throws Exception {
    // GIVEN
    final AtomicBoolean fired = new AtomicBoolean();
    FileSystemAbstraction fs = new DelegatingFileSystemAbstraction(efs.get()) {

        @Override
        public StoreChannel open(File fileName, String mode) throws IOException {
            return new DelegatingStoreChannel(super.open(fileName, mode)) {

                @Override
                public int read(ByteBuffer dst) throws IOException {
                    Exception stack = new Exception();
                    if (containsStackTraceElement(stack, item -> item.getMethodName().equals("initGenerator")) && !containsStackTraceElement(stack, item -> item.getMethodName().equals("createNodeStore"))) {
                        fired.set(true);
                        throw new IOException("Proving a point here");
                    }
                    return super.read(dst);
                }
            };
        }
    };
    // WHEN
    try (PageCache pageCache = pageCacheRule.getPageCache(fs)) {
        newNodeStore(fs);
        fail("Should fail");
    }// Close the page cache here so that we can see failure to close (due to still mapped files)
     catch (Exception e) {
        // THEN
        assertTrue(contains(e, IOException.class));
        assertTrue(fired.get());
    }
}
Also used : IdGeneratorFactory(org.neo4j.kernel.impl.store.id.IdGeneratorFactory) EphemeralFileSystemRule(org.neo4j.test.rule.fs.EphemeralFileSystemRule) Matchers.not(org.hamcrest.Matchers.not) NORMAL(org.neo4j.kernel.impl.store.record.RecordLoad.NORMAL) NO_NEXT_RELATIONSHIP(org.neo4j.kernel.impl.store.record.Record.NO_NEXT_RELATIONSHIP) NullLogProvider(org.neo4j.logging.NullLogProvider) ByteBuffer(java.nio.ByteBuffer) Assert.assertThat(org.junit.Assert.assertThat) StoreChannel(org.neo4j.io.fs.StoreChannel) Arrays.asList(java.util.Arrays.asList) After(org.junit.After) Assert.fail(org.junit.Assert.fail) ClassRule(org.junit.ClassRule) PageCache(org.neo4j.io.pagecache.PageCache) DefaultIdGeneratorFactory(org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory) Predicate(java.util.function.Predicate) Collection(java.util.Collection) DelegatingStoreChannel(org.neo4j.graphdb.mockfs.DelegatingStoreChannel) DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) IdType(org.neo4j.kernel.impl.store.id.IdType) Assert.assertFalse(org.junit.Assert.assertFalse) PrimitiveLongSet(org.neo4j.collection.primitive.PrimitiveLongSet) Mockito.mock(org.mockito.Mockito.mock) Primitive(org.neo4j.collection.primitive.Primitive) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Mockito.spy(org.mockito.Mockito.spy) ArrayList(java.util.ArrayList) PageCacheRule(org.neo4j.test.rule.PageCacheRule) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) NO_NEXT_PROPERTY(org.neo4j.kernel.impl.store.record.Record.NO_NEXT_PROPERTY) DynamicArrayStore.allocateFromNumbers(org.neo4j.kernel.impl.store.DynamicArrayStore.allocateFromNumbers) NodeStore.readOwnerFromDynamicLabelsRecord(org.neo4j.kernel.impl.store.NodeStore.readOwnerFromDynamicLabelsRecord) DelegatingFileSystemAbstraction(org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction) Config(org.neo4j.kernel.configuration.Config) Matchers.empty(org.hamcrest.Matchers.empty) LongStream(java.util.stream.LongStream) ReusableRecordsAllocator(org.neo4j.kernel.impl.store.allocator.ReusableRecordsAllocator) IdGenerator(org.neo4j.kernel.impl.store.id.IdGenerator) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) File(java.io.File) Mockito.verify(org.mockito.Mockito.verify) EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) Exceptions.contains(org.neo4j.helpers.Exceptions.contains) Rule(org.junit.Rule) Iterables(org.neo4j.helpers.collection.Iterables) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) Visitor(org.neo4j.helpers.collection.Visitor) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DelegatingFileSystemAbstraction(org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction) EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DelegatingStoreChannel(org.neo4j.graphdb.mockfs.DelegatingStoreChannel) IOException(java.io.IOException) DelegatingFileSystemAbstraction(org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction) File(java.io.File) ByteBuffer(java.nio.ByteBuffer) IOException(java.io.IOException) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Example 23 with PageCache

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

the class TestArrayStore method before.

@Before
public void before() throws Exception {
    File dir = testDirectory.graphDbDir();
    FileSystemAbstraction fs = fileSystemRule.get();
    DefaultIdGeneratorFactory idGeneratorFactory = new DefaultIdGeneratorFactory(fs);
    PageCache pageCache = pageCacheRule.getPageCache(fs);
    StoreFactory factory = new StoreFactory(dir, Config.empty(), idGeneratorFactory, pageCache, fs, NullLogProvider.getInstance());
    neoStores = factory.openAllNeoStores(true);
    arrayStore = neoStores.getPropertyStore().getArrayStore();
}
Also used : FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultIdGeneratorFactory(org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory) File(java.io.File) PageCache(org.neo4j.io.pagecache.PageCache) Before(org.junit.Before)

Example 24 with PageCache

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

the class RecordFormatsMigrationIT method assertStoreFormat.

private void assertStoreFormat(RecordFormats expected) throws IOException {
    Config config = Config.embeddedDefaults(stringMap(GraphDatabaseSettings.pagecache_memory.name(), "8m"));
    try (PageCache pageCache = ConfigurableStandalonePageCacheFactory.createPageCache(fileSystemRule.get(), config)) {
        RecordFormats actual = RecordFormatSelector.selectForStoreOrConfig(config, testDirectory.graphDbDir(), fileSystemRule.get(), pageCache, NullLogProvider.getInstance());
        assertNotNull(actual);
        assertEquals(expected.storeVersion(), actual.storeVersion());
    }
}
Also used : RecordFormats(org.neo4j.kernel.impl.store.format.RecordFormats) Config(org.neo4j.kernel.configuration.Config) PageCache(org.neo4j.io.pagecache.PageCache)

Example 25 with PageCache

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

the class StoreMigrationIT method data.

@Parameterized.Parameters(name = "Migrate: {0}->{1}")
public static Iterable<Object[]> data() throws IOException {
    FileSystemAbstraction fs = fileSystemRule.get();
    PageCache pageCache = pageCacheRule.getPageCache(fs);
    File dir = TestDirectory.testDirectory(StoreMigrationIT.class).prepareDirectoryForTest("migration");
    StoreVersionCheck storeVersionCheck = new StoreVersionCheck(pageCache);
    LegacyStoreVersionCheck legacyStoreVersionCheck = new LegacyStoreVersionCheck(fs);
    List<Object[]> data = new ArrayList<>();
    ArrayList<RecordFormats> recordFormatses = new ArrayList<>();
    RecordFormatSelector.allFormats().forEach((f) -> addIfNotThere(f, recordFormatses));
    for (RecordFormats toFormat : recordFormatses) {
        UpgradableDatabase upgradableDatabase = new UpgradableDatabase(fs, storeVersionCheck, legacyStoreVersionCheck, toFormat);
        for (RecordFormats fromFormat : recordFormatses) {
            File db = new File(dir, baseDirName(toFormat, fromFormat));
            try {
                createDb(fromFormat, db);
                if (!upgradableDatabase.hasCurrentVersion(db)) {
                    upgradableDatabase.checkUpgradeable(db);
                    data.add(new Object[] { fromFormat, toFormat });
                }
            } catch (Exception e) {
            //This means that the combination is not migratable.
            }
            fs.deleteRecursively(db);
        }
    }
    return data;
}
Also used : LegacyStoreVersionCheck(org.neo4j.kernel.impl.storemigration.legacystore.LegacyStoreVersionCheck) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) RecordFormats(org.neo4j.kernel.impl.store.format.RecordFormats) ArrayList(java.util.ArrayList) LegacyStoreVersionCheck(org.neo4j.kernel.impl.storemigration.legacystore.LegacyStoreVersionCheck) File(java.io.File) 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