Search in sources :

Example 6 with StoreFactory

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

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

the class NeoStoresRule method open.

public NeoStores open(FileSystemAbstraction fs, PageCache pageCache, RecordFormats format, String... config) throws IOException {
    assert neoStores == null : "Already opened";
    TestDirectory testDirectory = TestDirectory.testDirectory(testClass, fs);
    File storeDir = testDirectory.makeGraphDbDir();
    Config configuration = Config.embeddedDefaults(stringMap(config));
    StoreFactory storeFactory = new StoreFactory(storeDir, configuration, new DefaultIdGeneratorFactory(fs), pageCache, fs, format, NullLogProvider.getInstance());
    return neoStores = stores.length == 0 ? storeFactory.openAllNeoStores(true) : storeFactory.openNeoStores(true, stores);
}
Also used : Config(org.neo4j.kernel.configuration.Config) DefaultIdGeneratorFactory(org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) File(java.io.File)

Example 8 with StoreFactory

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

the class StoreMigrator method createStore.

private void createStore(File migrationDir, RecordFormats newFormat) {
    StoreFactory storeFactory = new StoreFactory(new File(migrationDir.getPath()), pageCache, fileSystem, newFormat, NullLogProvider.getInstance());
    try (NeoStores neoStores = storeFactory.openAllNeoStores(true)) {
        neoStores.getMetaDataStore();
        neoStores.getLabelTokenStore();
        neoStores.getNodeStore();
        neoStores.getPropertyStore();
        neoStores.getRelationshipGroupStore();
        neoStores.getRelationshipStore();
        neoStores.getSchemaStore();
    }
}
Also used : NeoStores(org.neo4j.kernel.impl.store.NeoStores) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) PagedFile(org.neo4j.io.pagecache.PagedFile) StoreFile(org.neo4j.kernel.impl.storemigration.StoreFile) File(java.io.File)

Example 9 with StoreFactory

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

the class StoreMigrator method rebuildCountsFromScratch.

private void rebuildCountsFromScratch(File storeDir, long lastTxId, PageCache pageCache) {
    final File storeFileBase = new File(storeDir, MetaDataStore.DEFAULT_NAME + StoreFactory.COUNTS_STORE);
    StoreFactory storeFactory = new StoreFactory(storeDir, pageCache, fileSystem, NullLogProvider.getInstance());
    try (NeoStores neoStores = storeFactory.openAllNeoStores()) {
        NodeStore nodeStore = neoStores.getNodeStore();
        RelationshipStore relationshipStore = neoStores.getRelationshipStore();
        try (Lifespan life = new Lifespan()) {
            int highLabelId = (int) neoStores.getLabelTokenStore().getHighId();
            int highRelationshipTypeId = (int) neoStores.getRelationshipTypeTokenStore().getHighId();
            CountsComputer initializer = new CountsComputer(lastTxId, nodeStore, relationshipStore, highLabelId, highRelationshipTypeId);
            life.add(new CountsTracker(logService.getInternalLogProvider(), fileSystem, pageCache, config, storeFileBase).setInitializer(initializer));
        }
    }
}
Also used : NodeStore(org.neo4j.kernel.impl.store.NodeStore) CountsComputer(org.neo4j.kernel.impl.store.CountsComputer) NeoStores(org.neo4j.kernel.impl.store.NeoStores) RelationshipStore(org.neo4j.kernel.impl.store.RelationshipStore) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) CountsTracker(org.neo4j.kernel.impl.store.counts.CountsTracker) PagedFile(org.neo4j.io.pagecache.PagedFile) StoreFile(org.neo4j.kernel.impl.storemigration.StoreFile) File(java.io.File) Lifespan(org.neo4j.kernel.lifecycle.Lifespan)

Example 10 with StoreFactory

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

the class DirectRecordStoreMigrator method migrate.

public void migrate(File fromStoreDir, RecordFormats fromFormat, File toStoreDir, RecordFormats toFormat, MigrationProgressMonitor.Section progressMonitor, StoreType[] types, StoreType... additionalTypesToOpen) {
    StoreType[] storesToOpen = ArrayUtil.concat(types, additionalTypesToOpen);
    progressMonitor.start(storesToOpen.length);
    try (NeoStores fromStores = new StoreFactory(fromStoreDir, config, new DefaultIdGeneratorFactory(fs), pageCache, fs, fromFormat, NullLogProvider.getInstance()).openNeoStores(true, storesToOpen);
        NeoStores toStores = new StoreFactory(toStoreDir, withPersistedStoreHeadersAsConfigFrom(fromStores, storesToOpen), new DefaultIdGeneratorFactory(fs), pageCache, fs, toFormat, NullLogProvider.getInstance()).openNeoStores(true, storesToOpen)) {
        for (StoreType type : types) {
            // This condition will exclude counts store first and foremost.
            if (type.isRecordStore()) {
                migrate(fromStores.getRecordStore(type), toStores.getRecordStore(type));
                progressMonitor.progress(1);
            }
        }
    }
}
Also used : StoreType(org.neo4j.kernel.impl.store.StoreType) NeoStores(org.neo4j.kernel.impl.store.NeoStores) DefaultIdGeneratorFactory(org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory)

Aggregations

StoreFactory (org.neo4j.kernel.impl.store.StoreFactory)64 NeoStores (org.neo4j.kernel.impl.store.NeoStores)31 DefaultIdGeneratorFactory (org.neo4j.internal.id.DefaultIdGeneratorFactory)30 File (java.io.File)18 BeforeEach (org.junit.jupiter.api.BeforeEach)15 PageCache (org.neo4j.io.pagecache.PageCache)12 DefaultIdGeneratorFactory (org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory)11 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 MethodSource (org.junit.jupiter.params.provider.MethodSource)7 IOException (java.io.IOException)6 Path (java.nio.file.Path)6 Before (org.junit.Before)6 Test (org.junit.Test)6 Config (org.neo4j.configuration.Config)6 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)6 CursorContext (org.neo4j.io.pagecache.context.CursorContext)6 Config (org.neo4j.kernel.configuration.Config)6 LogProvider (org.neo4j.logging.LogProvider)6 NullLogProvider (org.neo4j.logging.NullLogProvider)6 ScanOnOpenOverwritingIdGeneratorFactory (org.neo4j.internal.id.ScanOnOpenOverwritingIdGeneratorFactory)5