Search in sources :

Example 6 with PartitionedIndexStorage

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

the class FulltextIndexProvider method getPopulator.

@Override
public IndexPopulator getPopulator(IndexDescriptor descriptor, IndexSamplingConfig samplingConfig, ByteBufferFactory bufferFactory, MemoryTracker memoryTracker, TokenNameLookup tokenNameLookup) {
    if (isReadOnly()) {
        throw new UnsupportedOperationException("Can't create populator for read only index");
    }
    try {
        PartitionedIndexStorage indexStorage = getIndexStorage(descriptor.getId());
        Analyzer analyzer = createAnalyzer(descriptor, tokenNameLookup);
        String[] propertyNames = createPropertyNames(descriptor, tokenNameLookup);
        DatabaseIndex<FulltextIndexReader> fulltextIndex = FulltextIndexBuilder.create(descriptor, config, readOnlyChecker, tokenHolders.propertyKeyTokens(), analyzer, propertyNames).withFileSystem(fileSystem).withIndexStorage(indexStorage).withPopulatingMode(true).build();
        log.debug("Creating populator for fulltext schema index: %s", descriptor);
        return new FulltextIndexPopulator(descriptor, fulltextIndex, propertyNames);
    } catch (Exception e) {
        PartitionedIndexStorage indexStorage = getIndexStorage(descriptor.getId());
        DatabaseIndex<FulltextIndexReader> fulltextIndex = new DroppableIndex<>(new DroppableLuceneIndex<>(indexStorage, new ReadOnlyIndexPartitionFactory(), descriptor));
        log.debug("Creating failed index populator for fulltext schema index: %s", descriptor, e);
        return new FailedFulltextIndexPopulator(descriptor, fulltextIndex, e);
    }
}
Also used : DatabaseIndex(org.neo4j.kernel.api.impl.index.DatabaseIndex) FulltextIndexSettings.createAnalyzer(org.neo4j.kernel.api.impl.fulltext.FulltextIndexSettings.createAnalyzer) Analyzer(org.apache.lucene.analysis.Analyzer) IOException(java.io.IOException) TokenNotFoundException(org.neo4j.token.api.TokenNotFoundException) DroppableLuceneIndex(org.neo4j.kernel.api.impl.index.DroppableLuceneIndex) PartitionedIndexStorage(org.neo4j.kernel.api.impl.index.storage.PartitionedIndexStorage) ReadOnlyIndexPartitionFactory(org.neo4j.kernel.api.impl.index.partition.ReadOnlyIndexPartitionFactory)

Example 7 with PartitionedIndexStorage

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

the class FulltextIndexProvider method getInitialState.

@Override
public InternalIndexState getInitialState(IndexDescriptor index, CursorContext cursorContext) {
    PartitionedIndexStorage indexStorage = getIndexStorage(index.getId());
    String failure = indexStorage.getStoredIndexFailure();
    if (failure != null) {
        return InternalIndexState.FAILED;
    }
    // For instance, that it doesn't refer to an analyzer that has since been removed.
    try {
        validateIndexRef(index);
    } catch (Exception e) {
        try {
            indexStorage.storeIndexFailure(Exceptions.stringify(e));
        } catch (IOException ex) {
            ex.addSuppressed(e);
            log.warn("Failed to persist index failure. Index failure added as suppressed exception.", ex);
        }
        return InternalIndexState.FAILED;
    }
    try {
        return indexIsOnline(indexStorage, index) ? InternalIndexState.ONLINE : InternalIndexState.POPULATING;
    } catch (IOException e) {
        return InternalIndexState.POPULATING;
    }
}
Also used : IOException(java.io.IOException) PartitionedIndexStorage(org.neo4j.kernel.api.impl.index.storage.PartitionedIndexStorage) IOException(java.io.IOException) TokenNotFoundException(org.neo4j.token.api.TokenNotFoundException)

Example 8 with PartitionedIndexStorage

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

the class AccessUniqueDatabaseIndexTest method shouldUpdateUniqueEntries.

@Test
void shouldUpdateUniqueEntries() throws Exception {
    // given
    PartitionedIndexStorage indexStorage = getIndexStorage();
    LuceneIndexAccessor accessor = createAccessor(indexStorage);
    // when
    updateAndCommit(accessor, singletonList(add(1L, "value1")));
    updateAndCommit(accessor, singletonList(change(1L, "value1", "value2")));
    accessor.close();
    // then
    assertEquals(singletonList(1L), getAllNodes(indexStorage, "value2"));
    assertEquals(emptyList(), getAllNodes(indexStorage, "value1"));
}
Also used : PartitionedIndexStorage(org.neo4j.kernel.api.impl.index.storage.PartitionedIndexStorage) Test(org.junit.jupiter.api.Test)

Example 9 with PartitionedIndexStorage

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

the class DatabaseIndexIntegrationTest method createTestLuceneIndex.

private WritableTestDatabaseIndex createTestLuceneIndex(DirectoryFactory dirFactory, Path folder) throws IOException {
    PartitionedIndexStorage indexStorage = new PartitionedIndexStorage(dirFactory, fileSystem, folder);
    WritableTestDatabaseIndex index = new WritableTestDatabaseIndex(indexStorage);
    index.create();
    index.open();
    return index;
}
Also used : PartitionedIndexStorage(org.neo4j.kernel.api.impl.index.storage.PartitionedIndexStorage)

Example 10 with PartitionedIndexStorage

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

the class LuceneSchemaIndexBuilder method build.

/**
     * Build lucene schema index with specified configuration
     *
     * @return lucene schema index
     */
public SchemaIndex build() {
    if (isReadOnly()) {
        return new ReadOnlyDatabaseSchemaIndex(storageBuilder.build(), descriptor, samplingConfig, new ReadOnlyIndexPartitionFactory());
    } else {
        Boolean archiveFailed = getConfig(GraphDatabaseSettings.archive_failed_index);
        PartitionedIndexStorage storage = storageBuilder.archivingFailed(archiveFailed).build();
        return new WritableDatabaseSchemaIndex(storage, descriptor, samplingConfig, new WritableIndexPartitionFactory(writerConfigFactory));
    }
}
Also used : WritableIndexPartitionFactory(org.neo4j.kernel.api.impl.index.partition.WritableIndexPartitionFactory) PartitionedIndexStorage(org.neo4j.kernel.api.impl.index.storage.PartitionedIndexStorage) ReadOnlyIndexPartitionFactory(org.neo4j.kernel.api.impl.index.partition.ReadOnlyIndexPartitionFactory)

Aggregations

PartitionedIndexStorage (org.neo4j.kernel.api.impl.index.storage.PartitionedIndexStorage)21 ReadOnlyIndexPartitionFactory (org.neo4j.kernel.api.impl.index.partition.ReadOnlyIndexPartitionFactory)5 IOException (java.io.IOException)4 Test (org.junit.jupiter.api.Test)4 Path (java.nio.file.Path)2 Analyzer (org.apache.lucene.analysis.Analyzer)2 Before (org.junit.Before)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 FulltextIndexSettings.createAnalyzer (org.neo4j.kernel.api.impl.fulltext.FulltextIndexSettings.createAnalyzer)2 DroppableIndex (org.neo4j.kernel.api.impl.index.DroppableIndex)2 LuceneMinimalIndexAccessor (org.neo4j.kernel.api.impl.index.LuceneMinimalIndexAccessor)2 Config (org.neo4j.kernel.configuration.Config)2 TokenNotFoundException (org.neo4j.token.api.TokenNotFoundException)2 File (java.io.File)1 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)1 DatabaseIndex (org.neo4j.kernel.api.impl.index.DatabaseIndex)1 DroppableLuceneIndex (org.neo4j.kernel.api.impl.index.DroppableLuceneIndex)1 WritableIndexPartitionFactory (org.neo4j.kernel.api.impl.index.partition.WritableIndexPartitionFactory)1 DirectoryFactory (org.neo4j.kernel.api.impl.index.storage.DirectoryFactory)1 ValueIndexReader (org.neo4j.kernel.api.index.ValueIndexReader)1