Search in sources :

Example 1 with IndexProviderMap

use of org.neo4j.kernel.impl.api.index.IndexProviderMap in project neo4j by neo4j.

the class MultiIndexPopulationConcurrentUpdatesIT method launchCustomIndexPopulation.

private void launchCustomIndexPopulation(GraphDatabaseSettings.SchemaIndex schemaIndex, Map<String, Integer> labelNameIdMap, int propertyId, Runnable customAction) throws Throwable {
    RecordStorageEngine storageEngine = getStorageEngine();
    try (Transaction transaction = db.beginTx()) {
        Config config = Config.defaults();
        KernelTransaction ktx = ((InternalTransaction) transaction).kernelTransaction();
        JobScheduler scheduler = getJobScheduler();
        NullLogProvider nullLogProvider = NullLogProvider.getInstance();
        IndexStoreViewFactory indexStoreViewFactory = mock(IndexStoreViewFactory.class);
        when(indexStoreViewFactory.createTokenIndexStoreView(any())).thenAnswer(invocation -> dynamicIndexStoreViewWrapper(customAction, storageEngine::newReader, invocation.getArgument(0), config, scheduler));
        IndexProviderMap providerMap = getIndexProviderMap();
        indexService = IndexingServiceFactory.createIndexingService(config, scheduler, providerMap, indexStoreViewFactory, ktx.tokenRead(), initialSchemaRulesLoader(storageEngine), nullLogProvider, nullLogProvider, IndexingService.NO_MONITOR, getSchemaState(), mock(IndexStatisticsStore.class), PageCacheTracer.NULL, INSTANCE, "", writable());
        indexService.start();
        rules = createIndexRules(schemaIndex, labelNameIdMap, propertyId);
        schemaCache = new SchemaCache(new StandardConstraintSemantics(), providerMap);
        schemaCache.load(iterable(rules));
        indexService.createIndexes(AUTH_DISABLED, rules);
        transaction.commit();
    }
}
Also used : JobScheduler(org.neo4j.scheduler.JobScheduler) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) RecordStorageEngine(org.neo4j.internal.recordstorage.RecordStorageEngine) Config(org.neo4j.configuration.Config) NullLogProvider(org.neo4j.logging.NullLogProvider) SchemaCache(org.neo4j.internal.recordstorage.SchemaCache) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) IndexProviderMap(org.neo4j.kernel.impl.api.index.IndexProviderMap) StandardConstraintSemantics(org.neo4j.kernel.impl.constraints.StandardConstraintSemantics) IndexStoreViewFactory(org.neo4j.kernel.impl.transaction.state.storeview.IndexStoreViewFactory)

Example 2 with IndexProviderMap

use of org.neo4j.kernel.impl.api.index.IndexProviderMap in project neo4j by neo4j.

the class MultiIndexPopulationConcurrentUpdatesIT method createIndexRules.

private IndexDescriptor[] createIndexRules(GraphDatabaseSettings.SchemaIndex schemaIndex, Map<String, Integer> labelNameIdMap, int propertyId) {
    final IndexProviderMap indexProviderMap = getIndexProviderMap();
    IndexProvider indexProvider = indexProviderMap.lookup(schemaIndex.providerName());
    IndexProviderDescriptor providerDescriptor = indexProvider.getProviderDescriptor();
    List<IndexDescriptor> list = new ArrayList<>();
    for (Integer labelId : labelNameIdMap.values()) {
        final LabelSchemaDescriptor schema = SchemaDescriptor.forLabel(labelId, propertyId);
        IndexDescriptor index = IndexPrototype.forSchema(schema, providerDescriptor).withName("index_" + labelId).materialise(labelId);
        index = indexProvider.completeConfiguration(index);
        list.add(index);
    }
    return list.toArray(new IndexDescriptor[0]);
}
Also used : IndexProvider(org.neo4j.kernel.api.index.IndexProvider) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) ArrayList(java.util.ArrayList) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) IndexProviderMap(org.neo4j.kernel.impl.api.index.IndexProviderMap)

Example 3 with IndexProviderMap

use of org.neo4j.kernel.impl.api.index.IndexProviderMap in project neo4j by neo4j.

the class CheckerTestBase method context.

CheckerContext context(int numberOfThreads, ConsistencyFlags consistencyFlags, ConsistencySummaryStatistics inconsistenciesSummary) throws Exception {
    if (context != null) {
        return context;
    }
    // We do this as late as possible because of how it eagerly caches which indexes exist so if the test creates an index
    // this lazy instantiation allows the context to pick it up
    Config config = Config.defaults(neo4j_home, directory.homePath());
    DependencyResolver dependencies = db.getDependencyResolver();
    IndexProviderMap indexProviders = dependencies.resolveDependency(IndexProviderMap.class);
    IndexingService indexingService = dependencies.resolveDependency(IndexingService.class);
    IndexAccessors indexAccessors = new IndexAccessors(indexProviders, neoStores, new IndexSamplingConfig(config), new LookupAccessorsFromRunningDb(indexingService), PageCacheTracer.NULL, tokenHolders, neoStores.getMetaDataStore());
    InconsistencyReport report = new InconsistencyReport(new InconsistencyMessageLogger(NullLog.getInstance()), inconsistenciesSummary);
    monitor = mock(ConsistencyReporter.Monitor.class);
    reporter = new ConsistencyReporter(report, monitor);
    countsState = new CountsState(neoStores, cacheAccess, INSTANCE);
    NodeBasedMemoryLimiter limiter = new NodeBasedMemoryLimiter(pageCache.pageSize() * pageCache.maxCachedPages(), Runtime.getRuntime().maxMemory(), Long.MAX_VALUE, CacheSlots.CACHE_LINE_SIZE_BYTES, nodeStore.getHighId(), 1);
    ProgressMonitorFactory.MultiPartBuilder progress = ProgressMonitorFactory.NONE.multipleParts("Test");
    ParallelExecution execution = new ParallelExecution(numberOfThreads, NOOP_EXCEPTION_HANDLER, IDS_PER_CHUNK);
    context = new CheckerContext(neoStores, indexAccessors, execution, reporter, cacheAccess, tokenHolders, new RecordLoading(neoStores), countsState, limiter, progress, pageCache, PageCacheTracer.NULL, INSTANCE, DebugContext.NO_DEBUG, consistencyFlags);
    context.initialize();
    return context;
}
Also used : IndexSamplingConfig(org.neo4j.kernel.impl.api.index.IndexSamplingConfig) IndexAccessors(org.neo4j.consistency.checking.index.IndexAccessors) InconsistencyReport(org.neo4j.consistency.report.InconsistencyReport) ConsistencyReporter(org.neo4j.consistency.report.ConsistencyReporter) ProgressMonitorFactory(org.neo4j.internal.helpers.progress.ProgressMonitorFactory) Config(org.neo4j.configuration.Config) IndexSamplingConfig(org.neo4j.kernel.impl.api.index.IndexSamplingConfig) IndexProviderMap(org.neo4j.kernel.impl.api.index.IndexProviderMap) DependencyResolver(org.neo4j.common.DependencyResolver) LookupAccessorsFromRunningDb(org.neo4j.consistency.LookupAccessorsFromRunningDb) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) InconsistencyMessageLogger(org.neo4j.consistency.report.InconsistencyMessageLogger)

Example 4 with IndexProviderMap

use of org.neo4j.kernel.impl.api.index.IndexProviderMap in project neo4j by neo4j.

the class DatabaseMigrator method migrate.

/**
 * Performs construction of {@link StoreUpgrader} and all of the necessary participants and performs store
 * migration if that is required.
 *
 * @param forceUpgrade Ignore the value of the {@link GraphDatabaseSettings#allow_upgrade} setting.
 */
public void migrate(boolean forceUpgrade) throws IOException {
    StoreVersionCheck versionCheck = storageEngineFactory.versionCheck(fs, databaseLayout, config, pageCache, logService, pageCacheTracer);
    LogsUpgrader logsUpgrader = new LogsUpgrader(fs, storageEngineFactory, databaseLayout, pageCache, legacyLogsLocator, config, dependencyResolver, pageCacheTracer, memoryTracker, databaseHealth, forceUpgrade);
    Log userLog = logService.getUserLog(DatabaseMigrator.class);
    VisibleMigrationProgressMonitor progress = new VisibleMigrationProgressMonitor(userLog);
    LogProvider logProvider = logService.getInternalLogProvider();
    StoreUpgrader storeUpgrader = new StoreUpgrader(versionCheck, progress, config, fs, logProvider, logsUpgrader, pageCacheTracer);
    // Get all the participants from the storage engine and add them where they want to be
    var storeParticipants = storageEngineFactory.migrationParticipants(fs, config, pageCache, jobScheduler, logService, pageCacheTracer, memoryTracker);
    storeParticipants.forEach(storeUpgrader::addParticipant);
    IndexProviderMap indexProviderMap = dependencyResolver.resolveDependency(IndexProviderMap.class);
    IndexConfigMigrator indexConfigMigrator = new IndexConfigMigrator(fs, config, pageCache, logService, storageEngineFactory, indexProviderMap, logService.getUserLog(IndexConfigMigrator.class), pageCacheTracer, memoryTracker);
    storeUpgrader.addParticipant(indexConfigMigrator);
    IndexProviderMigrator indexProviderMigrator = new IndexProviderMigrator(fs, config, pageCache, logService, storageEngineFactory, pageCacheTracer, memoryTracker);
    storeUpgrader.addParticipant(indexProviderMigrator);
    // Do individual index provider migration last because they may delete files that we need in earlier steps.
    indexProviderMap.accept(provider -> storeUpgrader.addParticipant(provider.storeMigrationParticipant(fs, pageCache, storageEngineFactory)));
    try {
        storeUpgrader.migrateIfNeeded(databaseLayout, forceUpgrade);
    } catch (Exception e) {
        userLog.error("Error upgrading database. Database left intact and will likely not be able to start: " + e.toString());
        throw e;
    }
}
Also used : LogProvider(org.neo4j.logging.LogProvider) StoreVersionCheck(org.neo4j.storageengine.api.StoreVersionCheck) Log(org.neo4j.logging.Log) IndexProviderMap(org.neo4j.kernel.impl.api.index.IndexProviderMap) IOException(java.io.IOException)

Aggregations

IndexProviderMap (org.neo4j.kernel.impl.api.index.IndexProviderMap)4 Config (org.neo4j.configuration.Config)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 DependencyResolver (org.neo4j.common.DependencyResolver)1 LookupAccessorsFromRunningDb (org.neo4j.consistency.LookupAccessorsFromRunningDb)1 IndexAccessors (org.neo4j.consistency.checking.index.IndexAccessors)1 ConsistencyReporter (org.neo4j.consistency.report.ConsistencyReporter)1 InconsistencyMessageLogger (org.neo4j.consistency.report.InconsistencyMessageLogger)1 InconsistencyReport (org.neo4j.consistency.report.InconsistencyReport)1 Transaction (org.neo4j.graphdb.Transaction)1 ProgressMonitorFactory (org.neo4j.internal.helpers.progress.ProgressMonitorFactory)1 RecordStorageEngine (org.neo4j.internal.recordstorage.RecordStorageEngine)1 SchemaCache (org.neo4j.internal.recordstorage.SchemaCache)1 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)1 IndexProviderDescriptor (org.neo4j.internal.schema.IndexProviderDescriptor)1 LabelSchemaDescriptor (org.neo4j.internal.schema.LabelSchemaDescriptor)1 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)1 IndexProvider (org.neo4j.kernel.api.index.IndexProvider)1 IndexSamplingConfig (org.neo4j.kernel.impl.api.index.IndexSamplingConfig)1