Search in sources :

Example 81 with PageCache

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

the class DetectAllRelationshipInconsistenciesIT method shouldDetectSabotagedRelationshipWhereEverItIs.

@Test
public void shouldDetectSabotagedRelationshipWhereEverItIs() throws Exception {
    // GIVEN a database which lots of relationships
    GraphDatabaseAPI db = getGraphDatabaseAPI();
    Sabotage sabotage;
    try {
        Node[] nodes = new Node[1_000];
        Relationship[] relationships = new Relationship[10_000];
        try (Transaction tx = db.beginTx()) {
            for (int i = 0; i < nodes.length; i++) {
                nodes[i] = db.createNode(label("Foo"));
            }
            for (int i = 0; i < 10_000; i++) {
                relationships[i] = random.among(nodes).createRelationshipTo(random.among(nodes), MyRelTypes.TEST);
            }
            tx.success();
        }
        // WHEN sabotaging a random relationship
        DependencyResolver resolver = db.getDependencyResolver();
        PageCache pageCache = resolver.resolveDependency(PageCache.class);
        StoreFactory storeFactory = newStoreFactory(pageCache);
        try (NeoStores neoStores = storeFactory.openNeoStores(false, StoreType.RELATIONSHIP)) {
            RelationshipStore relationshipStore = neoStores.getRelationshipStore();
            Relationship sabotagedRelationships = random.among(relationships);
            sabotage = sabotage(relationshipStore, sabotagedRelationships.getId());
        }
    } finally {
        db.shutdown();
    }
    // THEN the checker should find it, where ever it is in the store
    db = getGraphDatabaseAPI();
    try {
        DependencyResolver resolver = db.getDependencyResolver();
        PageCache pageCache = resolver.resolveDependency(PageCache.class);
        StoreFactory storeFactory = newStoreFactory(pageCache);
        try (NeoStores neoStores = storeFactory.openAllNeoStores()) {
            StoreAccess storeAccess = new StoreAccess(neoStores).initialize();
            DirectStoreAccess directStoreAccess = new DirectStoreAccess(storeAccess, db.getDependencyResolver().resolveDependency(LabelScanStore.class), db.getDependencyResolver().resolveDependency(SchemaIndexProvider.class));
            int threads = random.intBetween(2, 10);
            FullCheck checker = new FullCheck(getTuningConfiguration(), ProgressMonitorFactory.NONE, Statistics.NONE, threads);
            AssertableLogProvider logProvider = new AssertableLogProvider(true);
            ConsistencySummaryStatistics summary = checker.execute(directStoreAccess, logProvider.getLog(FullCheck.class));
            int relationshipInconsistencies = summary.getInconsistencyCountForRecordType(RecordType.RELATIONSHIP);
            assertTrue("Couldn't detect sabotaged relationship " + sabotage, relationshipInconsistencies > 0);
            logProvider.assertContainsLogCallContaining(sabotage.after.toString());
        }
    } finally {
        db.shutdown();
    }
}
Also used : LabelScanStore(org.neo4j.kernel.api.labelscan.LabelScanStore) SchemaIndexProvider(org.neo4j.kernel.api.index.SchemaIndexProvider) DirectStoreAccess(org.neo4j.kernel.api.direct.DirectStoreAccess) StoreAccess(org.neo4j.kernel.impl.store.StoreAccess) Node(org.neo4j.graphdb.Node) DirectStoreAccess(org.neo4j.kernel.api.direct.DirectStoreAccess) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) DependencyResolver(org.neo4j.graphdb.DependencyResolver) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) Relationship(org.neo4j.graphdb.Relationship) NeoStores(org.neo4j.kernel.impl.store.NeoStores) RelationshipStore(org.neo4j.kernel.impl.store.RelationshipStore) PageCache(org.neo4j.io.pagecache.PageCache) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) ConsistencySummaryStatistics(org.neo4j.consistency.report.ConsistencySummaryStatistics) Test(org.junit.Test)

Example 82 with PageCache

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

the class VersionCommand method execute.

@Override
public void execute(String[] args) throws IncorrectUsage, CommandFailed {
    final Path storeDir = arguments.parseMandatoryPath("store", args);
    Validators.CONTAINS_EXISTING_DATABASE.validate(storeDir.toFile());
    try (DefaultFileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
        PageCache pageCache = StandalonePageCacheFactory.createPageCache(fileSystem)) {
        final String storeVersion = new StoreVersionCheck(pageCache).getVersion(storeDir.resolve(MetaDataStore.DEFAULT_NAME).toFile()).orElseThrow(() -> new CommandFailed(String.format("Could not find version metadata in store '%s'", storeDir)));
        final String fmt = "%-25s%s";
        out.accept(String.format(fmt, "Store format version:", storeVersion));
        RecordFormats format = RecordFormatSelector.selectForVersion(storeVersion);
        out.accept(String.format(fmt, "Introduced in version:", format.introductionVersion()));
        findSuccessor(format).map(next -> String.format(fmt, "Superseded in version:", next.introductionVersion())).ifPresent(out);
        out.accept(String.format(fmt, "Current version:", Version.getNeo4jVersion()));
    } catch (IOException e) {
        throw new CommandFailed(e.getMessage(), e);
    }
}
Also used : MandatoryCanonicalPath(org.neo4j.commandline.arguments.common.MandatoryCanonicalPath) Path(java.nio.file.Path) PageCache(org.neo4j.io.pagecache.PageCache) Validators(org.neo4j.kernel.impl.util.Validators) StandalonePageCacheFactory(org.neo4j.io.pagecache.impl.muninn.StandalonePageCacheFactory) Version(org.neo4j.kernel.internal.Version) IOException(java.io.IOException) RecordFormatSelector(org.neo4j.kernel.impl.store.format.RecordFormatSelector) StoreVersionCheck(org.neo4j.kernel.impl.storemigration.StoreVersionCheck) AdminCommand(org.neo4j.commandline.admin.AdminCommand) RecordFormats(org.neo4j.kernel.impl.store.format.RecordFormats) Consumer(java.util.function.Consumer) MandatoryCanonicalPath(org.neo4j.commandline.arguments.common.MandatoryCanonicalPath) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) Arguments(org.neo4j.commandline.arguments.Arguments) OutsideWorld(org.neo4j.commandline.admin.OutsideWorld) RecordFormatSelector.findSuccessor(org.neo4j.kernel.impl.store.format.RecordFormatSelector.findSuccessor) MetaDataStore(org.neo4j.kernel.impl.store.MetaDataStore) CommandFailed(org.neo4j.commandline.admin.CommandFailed) IncorrectUsage(org.neo4j.commandline.admin.IncorrectUsage) Path(java.nio.file.Path) StoreVersionCheck(org.neo4j.kernel.impl.storemigration.StoreVersionCheck) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) RecordFormats(org.neo4j.kernel.impl.store.format.RecordFormats) CommandFailed(org.neo4j.commandline.admin.CommandFailed) IOException(java.io.IOException) PageCache(org.neo4j.io.pagecache.PageCache)

Example 83 with PageCache

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

the class FormatCompatibilityTest method shouldDetectFormatChange.

@Test
public void shouldDetectFormatChange() throws Throwable {
    // GIVEN stored tree
    File storeFile = directory.file(STORE);
    try {
        unzipTo(storeFile);
    } catch (FileNotFoundException e) {
        // First time this test is run, eh?
        createAndZipTree(storeFile);
        tellDeveloperToCommitThisFormatVersion();
    }
    assertTrue(CURRENT_FORMAT_ZIP + " seems to be missing from resources directory", fsRule.get().fileExists(storeFile));
    // WHEN reading from the tree
    // THEN everything should work, otherwise there has likely been a format change
    PageCache pageCache = pageCacheRule.getPageCache(fsRule.get());
    try (GBPTree<MutableLong, MutableLong> tree = new GBPTree<>(pageCache, storeFile, new SimpleLongLayout(), 0, NO_MONITOR, NO_HEADER)) {
        try {
            tree.consistencyCheck();
            try (RawCursor<Hit<MutableLong, MutableLong>, IOException> cursor = tree.seek(new MutableLong(0), new MutableLong(KEY_COUNT))) {
                for (long expectedKey = 0; cursor.next(); expectedKey++) {
                    Hit<MutableLong, MutableLong> hit = cursor.get();
                    assertEquals(expectedKey, hit.key().longValue());
                    assertEquals(value(expectedKey), hit.value().longValue());
                }
                assertFalse(cursor.next());
            }
        } catch (Throwable t) {
            throw new AssertionError(format("If this is the single failing test for %s this failure is a strong indication that format " + "has changed without also incrementing %s.FORMAT_VERSION. " + "Please go ahead and increment the format version", TREE_CLASS_NAME, TREE_CLASS_NAME), t);
        }
    } catch (MetadataMismatchException e) {
        // Good actually, or?
        assertThat(e.getMessage(), containsString("format version"));
        fsRule.get().deleteFile(storeFile);
        createAndZipTree(storeFile);
        tellDeveloperToCommitThisFormatVersion();
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) MutableLong(org.apache.commons.lang3.mutable.MutableLong) ZipFile(java.util.zip.ZipFile) File(java.io.File) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Example 84 with PageCache

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

the class FormatCompatibilityTest method createAndZipTree.

private void createAndZipTree(File storeFile) throws IOException {
    PageCache pageCache = pageCacheRule.getPageCache(fsRule.get());
    try (GBPTree<MutableLong, MutableLong> tree = new GBPTree<>(pageCache, storeFile, new SimpleLongLayout(), 0, NO_MONITOR, NO_HEADER)) {
        MutableLong insertKey = new MutableLong();
        MutableLong insertValue = new MutableLong();
        int batchSize = KEY_COUNT / 10;
        for (int i = 0, key = 0; i < 10; i++) {
            try (Writer<MutableLong, MutableLong> writer = tree.writer()) {
                for (int j = 0; j < batchSize; j++, key++) {
                    insertKey.setValue(key);
                    insertValue.setValue(value(key));
                    writer.put(insertKey, insertValue);
                }
            }
            tree.checkpoint(IOLimiter.unlimited());
        }
    }
    zip(storeFile);
}
Also used : MutableLong(org.apache.commons.lang3.mutable.MutableLong) PageCache(org.neo4j.io.pagecache.PageCache)

Example 85 with PageCache

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

the class GBPTreeConcurrencyIT method createIndex.

private GBPTree<MutableLong, MutableLong> createIndex(GBPTree.Monitor monitor) throws IOException {
    int pageSize = 256;
    PageCache pageCache = pageCacheRule.getPageCache(fs.get(), config().withPageSize(pageSize).withAccessChecks(true));
    return index = new GBPTree<>(pageCache, directory.file("index"), layout, 0, /*use whatever page cache says*/
    monitor, NO_HEADER);
}
Also used : 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