Search in sources :

Example 6 with AbstractIndexPartition

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

the class AbstractLuceneIndex method addNewPartition.

/**
 * Add new partition to the index.
 *
 * @return newly created partition
 * @throws IOException
 */
AbstractIndexPartition addNewPartition() throws IOException {
    ensureOpen();
    Path partitionFolder = createNewPartitionFolder();
    Directory directory = indexStorage.openDirectory(partitionFolder);
    AbstractIndexPartition indexPartition = partitionFactory.createPartition(partitionFolder, directory);
    partitions.add(indexPartition);
    return indexPartition;
}
Also used : Path(java.nio.file.Path) Directory(org.apache.lucene.store.Directory) AbstractIndexPartition(org.neo4j.kernel.api.impl.index.partition.AbstractIndexPartition)

Example 7 with AbstractIndexPartition

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

the class AbstractLuceneIndex method markAsOnline.

/**
 * Marks index as online by including "status" -> "online" map into commit metadata of the first partition.
 *
 * @throws IOException
 */
public void markAsOnline() throws IOException {
    ensureOpen();
    AbstractIndexPartition partition = getFirstPartition(getPartitions());
    IndexWriter indexWriter = partition.getIndexWriter();
    indexWriter.setLiveCommitData(ONLINE_COMMIT_USER_DATA);
    flush(false);
}
Also used : LuceneIndexWriter(org.neo4j.kernel.api.impl.schema.writer.LuceneIndexWriter) PartitionedIndexWriter(org.neo4j.kernel.api.impl.schema.writer.PartitionedIndexWriter) IndexWriter(org.apache.lucene.index.IndexWriter) AbstractIndexPartition(org.neo4j.kernel.api.impl.index.partition.AbstractIndexPartition)

Example 8 with AbstractIndexPartition

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

the class DatabaseIndexIntegrationTest method firstPartitionWriter.

private IndexWriter firstPartitionWriter() {
    List<AbstractIndexPartition> partitions = luceneIndex.getPartitions();
    assertEquals(1, partitions.size());
    AbstractIndexPartition partition = partitions.get(0);
    return partition.getIndexWriter();
}
Also used : AbstractIndexPartition(org.neo4j.kernel.api.impl.index.partition.AbstractIndexPartition)

Example 9 with AbstractIndexPartition

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

the class PartitionedLuceneLabelScanWriter method flush.

private void flush() throws IOException {
    if (currentRange < 0) {
        return;
    }
    AbstractIndexPartition partition = getCurrentPartition();
    try (PartitionSearcher partitionSearcher = partition.acquireSearcher()) {
        IndexSearcher searcher = partitionSearcher.getIndexSearcher();
        Map<Long, Bitmap> /*label*/
        fields = readLabelBitMapsInRange(searcher, currentRange);
        updateFields(updates, fields);
        Document document = new Document();
        format.addRangeValuesField(document, currentRange);
        for (Map.Entry<Long, Bitmap> /*label*/
        field : fields.entrySet()) {
            // one field per label
            Bitmap value = field.getValue();
            if (value.hasContent()) {
                format.addLabelAndSearchFields(document, field.getKey(), value);
            }
        }
        if (isEmpty(document)) {
            partition.getIndexWriter().deleteDocuments(format.rangeTerm(document));
        } else {
            partition.getIndexWriter().updateDocument(format.rangeTerm(document), document);
        }
        updates.clear();
    }
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) Bitmap(org.neo4j.kernel.api.impl.labelscan.bitmaps.Bitmap) PartitionSearcher(org.neo4j.kernel.api.impl.index.partition.PartitionSearcher) Document(org.apache.lucene.document.Document) HashMap(java.util.HashMap) Map(java.util.Map) AbstractIndexPartition(org.neo4j.kernel.api.impl.index.partition.AbstractIndexPartition)

Example 10 with AbstractIndexPartition

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

the class PartitionedIndexWriter method unsafeGetIndexWriter.

private IndexWriter unsafeGetIndexWriter(int numDocs) throws IOException {
    List<AbstractIndexPartition> indexPartitions = index.getPartitions();
    int size = indexPartitions.size();
    // noinspection ForLoopReplaceableByForEach
    for (int i = 0; i < size; i++) {
        // We should find the *first* writable partition, so we can fill holes left by index deletes,
        // after they were merged away:
        AbstractIndexPartition partition = indexPartitions.get(i);
        if (writablePartition(partition, numDocs)) {
            return partition.getIndexWriter();
        }
    }
    AbstractIndexPartition indexPartition = index.addNewPartition();
    return indexPartition.getIndexWriter();
}
Also used : AbstractIndexPartition(org.neo4j.kernel.api.impl.index.partition.AbstractIndexPartition)

Aggregations

AbstractIndexPartition (org.neo4j.kernel.api.impl.index.partition.AbstractIndexPartition)13 IndexWriter (org.apache.lucene.index.IndexWriter)3 Directory (org.apache.lucene.store.Directory)3 LuceneIndexWriter (org.neo4j.kernel.api.impl.schema.writer.LuceneIndexWriter)3 PartitionedIndexWriter (org.neo4j.kernel.api.impl.schema.writer.PartitionedIndexWriter)3 IOException (java.io.IOException)2 UncheckedIOException (java.io.UncheckedIOException)2 DirectoryReader (org.apache.lucene.index.DirectoryReader)2 PartitionSearcher (org.neo4j.kernel.api.impl.index.partition.PartitionSearcher)2 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 Document (org.apache.lucene.document.Document)1 IndexSearcher (org.apache.lucene.search.IndexSearcher)1 ResourceIterator (org.neo4j.graphdb.ResourceIterator)1 SearcherReference (org.neo4j.kernel.api.impl.index.SearcherReference)1 Bitmap (org.neo4j.kernel.api.impl.labelscan.bitmaps.Bitmap)1 SimpleLuceneLabelScanStoreReader (org.neo4j.kernel.api.impl.labelscan.reader.SimpleLuceneLabelScanStoreReader)1