Search in sources :

Example 6 with StoreAccess

use of org.neo4j.kernel.impl.store.StoreAccess in project neo4j by neo4j.

the class FullCheck method execute.

void execute(final DirectStoreAccess directStoreAccess, final CheckDecorator decorator, final RecordAccess recordAccess, final InconsistencyReport report, CacheAccess cacheAccess, Monitor reportMonitor) throws ConsistencyCheckIncompleteException {
    final ConsistencyReporter reporter = new ConsistencyReporter(recordAccess, report, reportMonitor);
    StoreProcessor processEverything = new StoreProcessor(decorator, reporter, Stage.SEQUENTIAL_FORWARD, cacheAccess);
    ProgressMonitorFactory.MultiPartBuilder progress = progressFactory.multipleParts("Full Consistency Check");
    final StoreAccess nativeStores = directStoreAccess.nativeStores();
    try (IndexAccessors indexes = new IndexAccessors(directStoreAccess.indexes(), nativeStores.getSchemaStore(), samplingConfig)) {
        MultiPassStore.Factory multiPass = new MultiPassStore.Factory(decorator, recordAccess, cacheAccess, report, reportMonitor);
        ConsistencyCheckTasks taskCreator = new ConsistencyCheckTasks(progress, processEverything, nativeStores, statistics, cacheAccess, directStoreAccess.labelScanStore(), indexes, multiPass, reporter, threads);
        List<ConsistencyCheckerTask> tasks = taskCreator.createTasksForFullCheck(checkLabelScanStore, checkIndexes, checkGraph);
        TaskExecutor.execute(tasks, decorator::prepare);
    } catch (Exception e) {
        throw new ConsistencyCheckIncompleteException(e);
    }
}
Also used : IndexAccessors(org.neo4j.consistency.checking.index.IndexAccessors) DirectStoreAccess(org.neo4j.kernel.api.direct.DirectStoreAccess) StoreAccess(org.neo4j.kernel.impl.store.StoreAccess) ConsistencyReporter(org.neo4j.consistency.report.ConsistencyReporter) ProgressMonitorFactory(org.neo4j.helpers.progress.ProgressMonitorFactory) ProgressMonitorFactory(org.neo4j.helpers.progress.ProgressMonitorFactory)

Example 7 with StoreAccess

use of org.neo4j.kernel.impl.store.StoreAccess in project neo4j by neo4j.

the class ConsistencyCheckService method runFullConsistencyCheck.

public Result runFullConsistencyCheck(final File storeDir, Config config, ProgressMonitorFactory progressFactory, final LogProvider logProvider, final FileSystemAbstraction fileSystem, final PageCache pageCache, final boolean verbose, File reportDir, CheckConsistencyConfig checkConsistencyConfig) throws ConsistencyCheckIncompleteException {
    Log log = logProvider.getLog(getClass());
    config = config.with(stringMap(GraphDatabaseSettings.read_only.name(), TRUE, GraphDatabaseSettings.label_index.name(), LabelIndex.AUTO.name()));
    StoreFactory factory = new StoreFactory(storeDir, config, new DefaultIdGeneratorFactory(fileSystem), pageCache, fileSystem, logProvider);
    ConsistencySummaryStatistics summary;
    final File reportFile = chooseReportPath(reportDir);
    Log reportLog = new ConsistencyReportLog(Suppliers.lazySingleton(() -> {
        try {
            return new PrintWriter(createOrOpenAsOuputStream(fileSystem, reportFile, true));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }));
    // Bootstrap kernel extensions
    LifeSupport life = new LifeSupport();
    try (NeoStores neoStores = factory.openAllNeoStores()) {
        IndexStoreView indexStoreView = new NeoStoreIndexStoreView(LockService.NO_LOCK_SERVICE, neoStores);
        Dependencies dependencies = new Dependencies();
        dependencies.satisfyDependencies(config, fileSystem, new SimpleLogService(logProvider, logProvider), indexStoreView, pageCache);
        KernelContext kernelContext = new SimpleKernelContext(storeDir, UNKNOWN, dependencies);
        KernelExtensions extensions = life.add(new KernelExtensions(kernelContext, (Iterable) load(KernelExtensionFactory.class), dependencies, ignore()));
        life.start();
        LabelScanStore labelScanStore = life.add(extensions.resolveDependency(LabelScanStoreProvider.class, new NamedLabelScanStoreSelectionStrategy(config)).getLabelScanStore());
        SchemaIndexProvider indexes = life.add(extensions.resolveDependency(SchemaIndexProvider.class, HighestSelectionStrategy.getInstance()));
        int numberOfThreads = defaultConsistencyCheckThreadsNumber();
        Statistics statistics;
        StoreAccess storeAccess;
        AccessStatistics stats = new AccessStatistics();
        if (verbose) {
            statistics = new VerboseStatistics(stats, new DefaultCounts(numberOfThreads), log);
            storeAccess = new AccessStatsKeepingStoreAccess(neoStores, stats);
        } else {
            statistics = Statistics.NONE;
            storeAccess = new StoreAccess(neoStores);
        }
        storeAccess.initialize();
        DirectStoreAccess stores = new DirectStoreAccess(storeAccess, labelScanStore, indexes);
        FullCheck check = new FullCheck(progressFactory, statistics, numberOfThreads, checkConsistencyConfig);
        summary = check.execute(stores, new DuplicatingLog(log, reportLog));
    } finally {
        life.shutdown();
    }
    if (!summary.isConsistent()) {
        log.warn("See '%s' for a detailed consistency report.", reportFile.getPath());
        return Result.failure(reportFile);
    }
    return Result.success(reportFile);
}
Also used : LabelScanStore(org.neo4j.kernel.api.labelscan.LabelScanStore) 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) DirectStoreAccess(org.neo4j.kernel.api.direct.DirectStoreAccess) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) DefaultCounts(org.neo4j.consistency.statistics.DefaultCounts) AccessStatistics(org.neo4j.consistency.statistics.AccessStatistics) SimpleKernelContext(org.neo4j.kernel.impl.spi.SimpleKernelContext) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) DuplicatingLog(org.neo4j.logging.DuplicatingLog) VerboseStatistics(org.neo4j.consistency.statistics.VerboseStatistics) Dependencies(org.neo4j.kernel.impl.util.Dependencies) NamedLabelScanStoreSelectionStrategy(org.neo4j.kernel.extension.dependency.NamedLabelScanStoreSelectionStrategy) ConsistencySummaryStatistics(org.neo4j.consistency.report.ConsistencySummaryStatistics) PrintWriter(java.io.PrintWriter) SimpleKernelContext(org.neo4j.kernel.impl.spi.SimpleKernelContext) KernelContext(org.neo4j.kernel.impl.spi.KernelContext) SchemaIndexProvider(org.neo4j.kernel.api.index.SchemaIndexProvider) Log(org.neo4j.logging.Log) DuplicatingLog(org.neo4j.logging.DuplicatingLog) DefaultIdGeneratorFactory(org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory) AccessStatsKeepingStoreAccess(org.neo4j.consistency.statistics.AccessStatsKeepingStoreAccess) IOException(java.io.IOException) KernelExtensionFactory(org.neo4j.kernel.extension.KernelExtensionFactory) Statistics(org.neo4j.consistency.statistics.Statistics) VerboseStatistics(org.neo4j.consistency.statistics.VerboseStatistics) ConsistencySummaryStatistics(org.neo4j.consistency.report.ConsistencySummaryStatistics) AccessStatistics(org.neo4j.consistency.statistics.AccessStatistics) NeoStoreIndexStoreView(org.neo4j.kernel.impl.transaction.state.storeview.NeoStoreIndexStoreView) FullCheck(org.neo4j.consistency.checking.full.FullCheck) KernelExtensions(org.neo4j.kernel.extension.KernelExtensions) NeoStores(org.neo4j.kernel.impl.store.NeoStores) IndexStoreView(org.neo4j.kernel.impl.api.index.IndexStoreView) NeoStoreIndexStoreView(org.neo4j.kernel.impl.transaction.state.storeview.NeoStoreIndexStoreView) File(java.io.File)

Example 8 with StoreAccess

use of org.neo4j.kernel.impl.store.StoreAccess in project neo4j by neo4j.

the class DatabaseRebuildTool method console.

private ConsoleInput console(final File fromPath, final GraphDatabaseBuilder dbBuilder, InputStream in, Listener<PrintStream> prompt, LifeSupport life) throws Exception {
    // We must have this indirection here since in order to perform CC (one of the commands) we must shut down
    // the database and let CC instantiate its own to run on. After that completes the db
    // should be restored. The commands has references to providers of things to accommodate for this.
    final AtomicReference<Store> store = new AtomicReference<>(new Store(dbBuilder));
    final Supplier<StoreAccess> storeAccess = () -> store.get().access;
    final Supplier<GraphDatabaseAPI> dbAccess = () -> store.get().db;
    ConsoleInput consoleInput = life.add(new ConsoleInput(in, out, prompt));
    consoleInput.add("apply", new ApplyTransactionsCommand(fromPath, dbAccess));
    consoleInput.add(DumpRecordsCommand.NAME, new DumpRecordsCommand(storeAccess));
    consoleInput.add("cc", new ArgsCommand() {

        @Override
        public void run(Args action, PrintStream out) throws Exception {
            File storeDir = store.get().storeDir;
            store.get().shutdown();
            try {
                Result result = new ConsistencyCheckService().runFullConsistencyCheck(storeDir, Config.defaults(), ProgressMonitorFactory.textual(out), FormattedLogProvider.toOutputStream(System.out), false);
                out.println(result.isSuccessful() ? "consistent" : "INCONSISTENT");
            } finally {
                store.set(new Store(dbBuilder));
            }
        }

        @Override
        public String toString() {
            return "Runs consistency check on the database for data that has been applied up to this point";
        }
    });
    life.add(new LifecycleAdapter() {

        @Override
        public void shutdown() {
            store.get().shutdown();
        }
    });
    return consoleInput;
}
Also used : PrintStream(java.io.PrintStream) Args(org.neo4j.helpers.Args) StoreAccess(org.neo4j.kernel.impl.store.StoreAccess) AtomicReference(java.util.concurrent.atomic.AtomicReference) LifecycleAdapter(org.neo4j.kernel.lifecycle.LifecycleAdapter) IOException(java.io.IOException) Result(org.neo4j.consistency.ConsistencyCheckService.Result) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) ConsoleInput(org.neo4j.tools.console.input.ConsoleInput) ArgsCommand(org.neo4j.tools.console.input.ArgsCommand) ConsistencyCheckService(org.neo4j.consistency.ConsistencyCheckService) File(java.io.File)

Example 9 with StoreAccess

use of org.neo4j.kernel.impl.store.StoreAccess in project neo4j by neo4j.

the class GraphStoreFixture method generateInitialData.

private void generateInitialData() {
    GraphDatabaseBuilder builder = new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder(directory);
    GraphDatabaseAPI graphDb = (GraphDatabaseAPI) builder.setConfig(GraphDatabaseSettings.record_format, formatName).setConfig(GraphDatabaseSettings.label_block_size, "60").newGraphDatabase();
    try {
        generateInitialData(graphDb);
        StoreAccess stores = new StoreAccess(graphDb.getDependencyResolver().resolveDependency(RecordStorageEngine.class).testAccessNeoStores()).initialize();
        schemaId = stores.getSchemaStore().getHighId();
        nodeId = stores.getNodeStore().getHighId();
        labelId = (int) stores.getLabelTokenStore().getHighId();
        nodeLabelsId = stores.getNodeDynamicLabelStore().getHighId();
        relId = stores.getRelationshipStore().getHighId();
        relGroupId = stores.getRelationshipGroupStore().getHighId();
        propId = (int) stores.getPropertyStore().getHighId();
        stringPropId = stores.getStringStore().getHighId();
        arrayPropId = stores.getArrayStore().getHighId();
        relTypeId = (int) stores.getRelationshipTypeTokenStore().getHighId();
        propKeyId = (int) stores.getPropertyKeyNameStore().getHighId();
    } finally {
        graphDb.shutdown();
    }
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) AccessStatsKeepingStoreAccess(org.neo4j.consistency.statistics.AccessStatsKeepingStoreAccess) DirectStoreAccess(org.neo4j.kernel.api.direct.DirectStoreAccess) StoreAccess(org.neo4j.kernel.impl.store.StoreAccess) RecordStorageEngine(org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) GraphDatabaseBuilder(org.neo4j.graphdb.factory.GraphDatabaseBuilder)

Example 10 with StoreAccess

use of org.neo4j.kernel.impl.store.StoreAccess 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)

Aggregations

StoreAccess (org.neo4j.kernel.impl.store.StoreAccess)13 DirectStoreAccess (org.neo4j.kernel.api.direct.DirectStoreAccess)10 ConsistencySummaryStatistics (org.neo4j.consistency.report.ConsistencySummaryStatistics)8 Test (org.junit.Test)7 File (java.io.File)3 GraphStoreFixture (org.neo4j.consistency.checking.GraphStoreFixture)3 IdGenerator (org.neo4j.consistency.checking.GraphStoreFixture.IdGenerator)3 TransactionDataBuilder (org.neo4j.consistency.checking.GraphStoreFixture.TransactionDataBuilder)3 AccessStatsKeepingStoreAccess (org.neo4j.consistency.statistics.AccessStatsKeepingStoreAccess)3 DefaultCounts (org.neo4j.consistency.statistics.DefaultCounts)3 PageCache (org.neo4j.io.pagecache.PageCache)3 LabelScanStore (org.neo4j.kernel.api.labelscan.LabelScanStore)3 StoreFactory (org.neo4j.kernel.impl.store.StoreFactory)3 DynamicRecord (org.neo4j.kernel.impl.store.record.DynamicRecord)3 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)3 IOException (java.io.IOException)2 AccessStatistics (org.neo4j.consistency.statistics.AccessStatistics)2 VerboseStatistics (org.neo4j.consistency.statistics.VerboseStatistics)2 Node (org.neo4j.graphdb.Node)2 Transaction (org.neo4j.graphdb.Transaction)2