Search in sources :

Example 1 with Descriptor

use of org.neo4j.kernel.api.index.SchemaIndexProvider.Descriptor in project neo4j by neo4j.

the class IndexingService method createIndexes.

/**
     * Creates one or more indexes. They will all be populated by one and the same store scan.
     *
     * This code is called from the transaction infrastructure during transaction commits, which means that
     * it is *vital* that it is stable, and handles errors very well. Failing here means that the entire db
     * will shut down.
     */
public void createIndexes(IndexRule... rules) throws IOException {
    IndexMap indexMap = indexMapRef.indexMapSnapshot();
    IndexPopulationJob populationJob = null;
    for (IndexRule rule : rules) {
        long ruleId = rule.getId();
        IndexProxy index = indexMap.getIndexProxy(ruleId);
        if (index != null && state == State.NOT_STARTED) {
            // During recovery we might run into this scenario:
            // - We're starting recovery on a database, where init() is called and all indexes that
            //   are found in the store, instantiated and put into the IndexMap. Among them is index X.
            // - While we recover the database we bump into a transaction creating index Y, with the
            //   same IndexDescriptor, i.e. same label/property, as X. This is possible since this took
            //   place before the creation of X.
            // - When Y is dropped in between this creation and the creation of X (it will have to be
            //   otherwise X wouldn't have had an opportunity to be created) the index is removed from
            //   the IndexMap, both by id AND descriptor.
            //
            // Because of the scenario above we need to put this created index into the IndexMap
            // again, otherwise it will disappear from the IndexMap (at least for lookup by descriptor)
            // and not be able to accept changes applied from recovery later on.
            indexMap.putIndexProxy(ruleId, index);
            indexMapRef.setIndexMap(indexMap);
            continue;
        }
        final NewIndexDescriptor descriptor = rule.getIndexDescriptor();
        SchemaIndexProvider.Descriptor providerDescriptor = rule.getProviderDescriptor();
        boolean flipToTentative = rule.canSupportUniqueConstraint();
        if (state == State.RUNNING) {
            populationJob = populationJob == null ? newIndexPopulationJob() : populationJob;
            index = indexProxyCreator.createPopulatingIndexProxy(ruleId, descriptor, providerDescriptor, flipToTentative, monitor, populationJob);
            index.start();
        } else {
            index = indexProxyCreator.createRecoveringIndexProxy(descriptor, providerDescriptor);
        }
        indexMap.putIndexProxy(rule.getId(), index);
    }
    if (populationJob != null) {
        startIndexPopulation(populationJob);
    }
    indexMapRef.setIndexMap(indexMap);
}
Also used : IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) SchemaIndexProvider(org.neo4j.kernel.api.index.SchemaIndexProvider) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) Descriptor(org.neo4j.kernel.api.index.SchemaIndexProvider.Descriptor)

Example 2 with Descriptor

use of org.neo4j.kernel.api.index.SchemaIndexProvider.Descriptor in project neo4j by neo4j.

the class IndexingService method snapshotStoreFiles.

public ResourceIterator<File> snapshotStoreFiles() throws IOException {
    Collection<ResourceIterator<File>> snapshots = new ArrayList<>();
    Set<SchemaIndexProvider.Descriptor> fromProviders = new HashSet<>();
    for (IndexProxy indexProxy : indexMapRef.getAllIndexProxies()) {
        Descriptor providerDescriptor = indexProxy.getProviderDescriptor();
        if (fromProviders.add(providerDescriptor)) {
            snapshots.add(providerMap.apply(providerDescriptor).snapshotMetaFiles());
        }
        snapshots.add(indexProxy.snapshotFiles());
    }
    return Iterators.concatResourceIterators(snapshots.iterator());
}
Also used : ArrayList(java.util.ArrayList) LabelSchemaDescriptor(org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) Descriptor(org.neo4j.kernel.api.index.SchemaIndexProvider.Descriptor) ResourceIterator(org.neo4j.graphdb.ResourceIterator) HashSet(java.util.HashSet)

Aggregations

Descriptor (org.neo4j.kernel.api.index.SchemaIndexProvider.Descriptor)2 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ResourceIterator (org.neo4j.graphdb.ResourceIterator)1 SchemaIndexProvider (org.neo4j.kernel.api.index.SchemaIndexProvider)1 LabelSchemaDescriptor (org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor)1 IndexRule (org.neo4j.kernel.impl.store.record.IndexRule)1