Search in sources :

Example 6 with LabelScanStoreProvider

use of org.neo4j.kernel.impl.api.scan.LabelScanStoreProvider in project neo4j by neo4j.

the class StoreMigration method run.

public void run(final FileSystemAbstraction fs, final File storeDirectory, Config config, LogProvider userLogProvider) throws IOException {
    StoreLogService logService = StoreLogService.withUserLogProvider(userLogProvider).inLogsDirectory(fs, storeDirectory);
    VisibleMigrationProgressMonitor progressMonitor = new VisibleMigrationProgressMonitor(logService.getUserLog(StoreMigration.class));
    LifeSupport life = new LifeSupport();
    life.add(logService);
    // Add participants from kernel extensions...
    LegacyIndexProvider legacyIndexProvider = new LegacyIndexProvider();
    Log log = userLogProvider.getLog(StoreMigration.class);
    try (PageCache pageCache = createPageCache(fs, config)) {
        Dependencies deps = new Dependencies();
        deps.satisfyDependencies(fs, config, legacyIndexProvider, pageCache, logService);
        KernelContext kernelContext = new SimpleKernelContext(storeDirectory, DatabaseInfo.UNKNOWN, deps);
        KernelExtensions kernelExtensions = life.add(new KernelExtensions(kernelContext, GraphDatabaseDependencies.newDependencies().kernelExtensions(), deps, ignore()));
        // Add the kernel store migrator
        life.start();
        SchemaIndexProvider schemaIndexProvider = kernelExtensions.resolveDependency(SchemaIndexProvider.class, HighestSelectionStrategy.getInstance());
        LabelScanStoreProvider labelScanStoreProvider = kernelExtensions.resolveDependency(LabelScanStoreProvider.class, new NamedLabelScanStoreSelectionStrategy(config));
        long startTime = System.currentTimeMillis();
        DatabaseMigrator migrator = new DatabaseMigrator(progressMonitor, fs, config, logService, schemaIndexProvider, labelScanStoreProvider, legacyIndexProvider.getIndexProviders(), pageCache, RecordFormatSelector.selectForConfig(config, userLogProvider));
        migrator.migrate(storeDirectory);
        long duration = System.currentTimeMillis() - startTime;
        log.info(format("Migration completed in %d s%n", duration / 1000));
    } catch (Exception e) {
        throw new StoreUpgrader.UnableToUpgradeException("Failure during upgrade", e);
    } finally {
        life.shutdown();
    }
}
Also used : SchemaIndexProvider(org.neo4j.kernel.api.index.SchemaIndexProvider) LabelScanStoreProvider(org.neo4j.kernel.impl.api.scan.LabelScanStoreProvider) VisibleMigrationProgressMonitor(org.neo4j.kernel.impl.storemigration.monitoring.VisibleMigrationProgressMonitor) StoreLogService(org.neo4j.kernel.impl.logging.StoreLogService) Log(org.neo4j.logging.Log) IOException(java.io.IOException) DatabaseMigrator(org.neo4j.kernel.impl.storemigration.DatabaseMigrator) KernelExtensions(org.neo4j.kernel.extension.KernelExtensions) SimpleKernelContext(org.neo4j.kernel.impl.spi.SimpleKernelContext) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) Dependencies(org.neo4j.kernel.impl.util.Dependencies) GraphDatabaseDependencies(org.neo4j.kernel.GraphDatabaseDependencies) StoreUpgrader(org.neo4j.kernel.impl.storemigration.StoreUpgrader) NamedLabelScanStoreSelectionStrategy(org.neo4j.kernel.extension.dependency.NamedLabelScanStoreSelectionStrategy) PageCache(org.neo4j.io.pagecache.PageCache) ConfigurableStandalonePageCacheFactory.createPageCache(org.neo4j.kernel.impl.pagecache.ConfigurableStandalonePageCacheFactory.createPageCache) SimpleKernelContext(org.neo4j.kernel.impl.spi.SimpleKernelContext) KernelContext(org.neo4j.kernel.impl.spi.KernelContext)

Example 7 with LabelScanStoreProvider

use of org.neo4j.kernel.impl.api.scan.LabelScanStoreProvider in project neo4j by neo4j.

the class NeoStoreDataSource method start.

@Override
public void start() throws IOException {
    dependencies = new Dependencies();
    life = new LifeSupport();
    schemaIndexProvider = dependencyResolver.resolveDependency(SchemaIndexProvider.class, HighestSelectionStrategy.getInstance());
    labelScanStoreProvider = dependencyResolver.resolveDependency(LabelScanStoreProvider.class, new NamedLabelScanStoreSelectionStrategy(config));
    dependencyResolver.resolveDependency(LabelScanStoreProvider.class, new DeleteStoresFromOtherLabelScanStoreProviders(labelScanStoreProvider));
    IndexConfigStore indexConfigStore = new IndexConfigStore(storeDir, fs);
    dependencies.satisfyDependency(lockService);
    dependencies.satisfyDependency(indexConfigStore);
    life.add(indexConfigStore);
    // Monitor listeners
    LoggingLogFileMonitor loggingLogMonitor = new LoggingLogFileMonitor(msgLog);
    monitors.addMonitorListener(loggingLogMonitor);
    life.add(new Delegate(Lifecycles.multiple(indexProviders.values())));
    // Upgrade the store before we begin
    RecordFormats formats = selectStoreFormats(config, storeDir, fs, pageCache, logService);
    upgradeStore(formats);
    // Build all modules and their services
    StorageEngine storageEngine = null;
    try {
        UpdateableSchemaState updateableSchemaState = new KernelSchemaStateStore(logProvider);
        SynchronizedArrayIdOrderingQueue legacyIndexTransactionOrdering = new SynchronizedArrayIdOrderingQueue(20);
        storageEngine = buildStorageEngine(propertyKeyTokenHolder, labelTokens, relationshipTypeTokens, legacyIndexProviderLookup, indexConfigStore, updateableSchemaState::clear, legacyIndexTransactionOrdering);
        LogEntryReader<ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader<>(storageEngine.commandReaderFactory());
        TransactionIdStore transactionIdStore = dependencies.resolveDependency(TransactionIdStore.class);
        LogVersionRepository logVersionRepository = dependencies.resolveDependency(LogVersionRepository.class);
        NeoStoreTransactionLogModule transactionLogModule = buildTransactionLogs(storeDir, config, logProvider, scheduler, fs, storageEngine, logEntryReader, legacyIndexTransactionOrdering, transactionIdStore, logVersionRepository);
        transactionLogModule.satisfyDependencies(dependencies);
        buildRecovery(fs, transactionIdStore, logVersionRepository, monitors.newMonitor(Recovery.Monitor.class), monitors.newMonitor(PositionToRecoverFrom.Monitor.class), transactionLogModule.logFiles(), startupStatistics, storageEngine, logEntryReader, transactionLogModule.logicalTransactionStore());
        // At the time of writing this comes from the storage engine (IndexStoreView)
        PropertyAccessor propertyAccessor = dependencies.resolveDependency(PropertyAccessor.class);
        final NeoStoreKernelModule kernelModule = buildKernel(transactionLogModule.transactionAppender(), dependencies.resolveDependency(IndexingService.class), storageEngine.storeReadLayer(), updateableSchemaState, dependencies.resolveDependency(LabelScanStore.class), storageEngine, indexConfigStore, transactionIdStore, availabilityGuard, clock, propertyAccessor);
        kernelModule.satisfyDependencies(dependencies);
        // Do these assignments last so that we can ensure no cyclical dependencies exist
        this.storageEngine = storageEngine;
        this.transactionLogModule = transactionLogModule;
        this.kernelModule = kernelModule;
        dependencies.satisfyDependency(this);
        dependencies.satisfyDependency(updateableSchemaState);
        dependencies.satisfyDependency(storageEngine.storeReadLayer());
        dependencies.satisfyDependency(logEntryReader);
        dependencies.satisfyDependency(storageEngine);
    } catch (Throwable e) {
        // Something unexpected happened during startup
        msgLog.warn("Exception occurred while setting up store modules. Attempting to close things down.", e);
        try {
            // Close the neostore, so that locks are released properly
            if (storageEngine != null) {
                storageEngine.forceClose();
            }
        } catch (Exception closeException) {
            msgLog.error("Couldn't close neostore after startup failure", closeException);
        }
        throw Exceptions.launderedException(e);
    }
    // NOTE: please make sure this is performed after having added everything to the life, in fact we would like
    // to perform the checkpointing as first step when the life is shutdown.
    life.add(lifecycleToTriggerCheckPointOnShutdown());
    try {
        life.start();
    } catch (Throwable e) {
        // Something unexpected happened during startup
        msgLog.warn("Exception occurred while starting the datasource. Attempting to close things down.", e);
        try {
            life.shutdown();
            // Close the neostore, so that locks are released properly
            storageEngine.forceClose();
        } catch (Exception closeException) {
            msgLog.error("Couldn't close neostore after startup failure", closeException);
        }
        throw Exceptions.launderedException(e);
    }
    /*
         * At this point recovery has completed and the datasource is ready for use. Whatever panic might have
         * happened before has been healed. So we can safely set the kernel health to ok.
         * This right now has any real effect only in the case of internal restarts (for example, after a store copy
         * in the case of HA). Standalone instances will have to be restarted by the user, as is proper for all
         * kernel panics.
         */
    databaseHealth.healed();
}
Also used : LabelScanStore(org.neo4j.kernel.api.labelscan.LabelScanStore) RecordStorageEngine(org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine) StorageEngine(org.neo4j.storageengine.api.StorageEngine) LogVersionRepository(org.neo4j.kernel.impl.transaction.log.LogVersionRepository) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel) TransactionMonitor(org.neo4j.kernel.impl.transaction.TransactionMonitor) LoggingLogFileMonitor(org.neo4j.kernel.impl.transaction.log.LoggingLogFileMonitor) VisibleMigrationProgressMonitor(org.neo4j.kernel.impl.storemigration.monitoring.VisibleMigrationProgressMonitor) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) KernelSchemaStateStore(org.neo4j.kernel.impl.api.KernelSchemaStateStore) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) Dependencies(org.neo4j.kernel.impl.util.Dependencies) DeleteStoresFromOtherLabelScanStoreProviders(org.neo4j.kernel.extension.dependency.DeleteStoresFromOtherLabelScanStoreProviders) NamedLabelScanStoreSelectionStrategy(org.neo4j.kernel.extension.dependency.NamedLabelScanStoreSelectionStrategy) SchemaIndexProvider(org.neo4j.kernel.api.index.SchemaIndexProvider) LabelScanStoreProvider(org.neo4j.kernel.impl.api.scan.LabelScanStoreProvider) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) PropertyAccessor(org.neo4j.kernel.api.index.PropertyAccessor) LoggingLogFileMonitor(org.neo4j.kernel.impl.transaction.log.LoggingLogFileMonitor) IndexConfigStore(org.neo4j.kernel.impl.index.IndexConfigStore) IOException(java.io.IOException) KernelException(org.neo4j.kernel.api.exceptions.KernelException) UpdateableSchemaState(org.neo4j.kernel.impl.api.UpdateableSchemaState) RecordFormats(org.neo4j.kernel.impl.store.format.RecordFormats) SynchronizedArrayIdOrderingQueue(org.neo4j.kernel.impl.util.SynchronizedArrayIdOrderingQueue)

Example 8 with LabelScanStoreProvider

use of org.neo4j.kernel.impl.api.scan.LabelScanStoreProvider in project neo4j by neo4j.

the class NamedLabelScanStoreSelectionStrategy method select.

/**
     * Selects the {@link LabelScanStoreProvider} with the specific name for this strategy, or fail.
     *
     * @param type type of items.
     * @param candidates candidates to choose from, i.e. loaded {@link LabelScanStoreProvider} instances.
     * @return the {@link LabelScanStoreProvider} with the specific name.
     * @throws IllegalArgumentException if no candidate matched the name or if the candidates weren't
     * {@link LabelScanStoreProvider}.
     */
@Override
public <T> T select(Class<T> type, Iterable<T> candidates) throws IllegalArgumentException {
    if (!type.equals(LabelScanStoreProvider.class)) {
        throw new IllegalArgumentException("Was expecting " + LabelScanStoreProvider.class);
    }
    String name = specificallyConfigured;
    if (LabelIndex.AUTO.name().equalsIgnoreCase(name)) {
        // Auto-selection works by asking each individual label scan store provider if it has a store
        // present or not. If there's a single provider it will be selected, but if there are multiple
        // an exception will be thrown. If there's no provider with present store then default will be used.
        T present = selectSingleProviderWhichHasStore(candidates);
        if (present != null) {
            return present;
        }
        // There was no label scan store present from any provider, go for the default.
        // This will reassign the name we're looking for the loop below
        name = LabelIndex.valueOf(GraphDatabaseSettings.label_index.getDefaultValue()).name();
    }
    List<String> candidateNames = new ArrayList<>();
    for (T candidate : candidates) {
        LabelScanStoreProvider provider = (LabelScanStoreProvider) candidate;
        String candidateName = provider.getName();
        candidateNames.add(candidateName);
        if (name.equalsIgnoreCase(candidateName)) {
            return candidate;
        }
    }
    throw new IllegalArgumentException("Configured label index '" + specificallyConfigured + "', but couldn't find it among candidates " + candidateNames);
}
Also used : LabelScanStoreProvider(org.neo4j.kernel.impl.api.scan.LabelScanStoreProvider) ArrayList(java.util.ArrayList)

Example 9 with LabelScanStoreProvider

use of org.neo4j.kernel.impl.api.scan.LabelScanStoreProvider in project neo4j by neo4j.

the class NamedLabelScanStoreSelectionStrategyTest method shouldAutoSelectDefaultProviderIfNoProviderWithPresentStore.

@Test
public void shouldAutoSelectDefaultProviderIfNoProviderWithPresentStore() throws Exception {
    // GIVEN
    NamedLabelScanStoreSelectionStrategy strategy = strategy(LabelIndex.AUTO);
    LabelScanStoreProvider nativeProvider = provider(LabelIndex.NATIVE, store(false));
    LabelScanStoreProvider luceneProvider = provider(LabelIndex.LUCENE, store(false));
    // WHEN
    LabelScanStoreProvider selected = select(strategy, nativeProvider, luceneProvider);
    // THEN
    assertEquals(GraphDatabaseSettings.label_index.getDefaultValue(), selected.getName());
}
Also used : LabelScanStoreProvider(org.neo4j.kernel.impl.api.scan.LabelScanStoreProvider) Test(org.junit.Test)

Example 10 with LabelScanStoreProvider

use of org.neo4j.kernel.impl.api.scan.LabelScanStoreProvider in project neo4j by neo4j.

the class NamedLabelScanStoreSelectionStrategyTest method shouldAutoSelectSingleProviderWithPresentStoreAmongMultipleProviders.

@Test
public void shouldAutoSelectSingleProviderWithPresentStoreAmongMultipleProviders() throws Exception {
    // GIVEN
    NamedLabelScanStoreSelectionStrategy strategy = strategy(LabelIndex.AUTO);
    LabelScanStoreProvider nativeProvider = provider(LabelIndex.NATIVE, store(false));
    LabelScanStoreProvider luceneProvider = provider(LabelIndex.LUCENE, store(true));
    // WHEN
    LabelScanStoreProvider selected = select(strategy, nativeProvider, luceneProvider);
    // THEN
    assertSame(luceneProvider, selected);
}
Also used : LabelScanStoreProvider(org.neo4j.kernel.impl.api.scan.LabelScanStoreProvider) Test(org.junit.Test)

Aggregations

LabelScanStoreProvider (org.neo4j.kernel.impl.api.scan.LabelScanStoreProvider)17 Test (org.junit.Test)9 IOException (java.io.IOException)4 Dependencies (org.neo4j.kernel.impl.util.Dependencies)3 SchemaIndexProvider (org.neo4j.kernel.api.index.SchemaIndexProvider)2 Config (org.neo4j.kernel.configuration.Config)2 NamedLabelScanStoreSelectionStrategy (org.neo4j.kernel.extension.dependency.NamedLabelScanStoreSelectionStrategy)2 StandardConstraintSemantics (org.neo4j.kernel.impl.constraints.StandardConstraintSemantics)2 IndexConfigStore (org.neo4j.kernel.impl.index.IndexConfigStore)2 KernelContext (org.neo4j.kernel.impl.spi.KernelContext)2 SimpleKernelContext (org.neo4j.kernel.impl.spi.SimpleKernelContext)2 VisibleMigrationProgressMonitor (org.neo4j.kernel.impl.storemigration.monitoring.VisibleMigrationProgressMonitor)2 SynchronizedArrayIdOrderingQueue (org.neo4j.kernel.impl.util.SynchronizedArrayIdOrderingQueue)2 ArrayList (java.util.ArrayList)1 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)1 PageCache (org.neo4j.io.pagecache.PageCache)1 AvailabilityGuard (org.neo4j.kernel.AvailabilityGuard)1 GraphDatabaseDependencies (org.neo4j.kernel.GraphDatabaseDependencies)1 NeoStoreDataSource (org.neo4j.kernel.NeoStoreDataSource)1 KernelException (org.neo4j.kernel.api.exceptions.KernelException)1