Search in sources :

Example 11 with AbstractIndexPartition

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

the class AbstractLuceneIndex method isOnline.

/**
 * Check if this index is marked as online.
 *
 * @return <code>true</code> if index is online, <code>false</code> otherwise
 * @throws IOException
 */
public boolean isOnline() throws IOException {
    ensureOpen();
    AbstractIndexPartition partition = getFirstPartition(getPartitions());
    Directory directory = partition.getDirectory();
    try (DirectoryReader reader = DirectoryReader.open(directory)) {
        Map<String, String> userData = reader.getIndexCommit().getUserData();
        return ONLINE.equals(userData.get(KEY_STATUS));
    }
}
Also used : DirectoryReader(org.apache.lucene.index.DirectoryReader) AbstractIndexPartition(org.neo4j.kernel.api.impl.index.partition.AbstractIndexPartition) Directory(org.apache.lucene.store.Directory)

Example 12 with AbstractIndexPartition

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

the class AbstractLuceneIndex method allDocumentsReader.

/**
 * Creates an iterable over all {@link Document document}s in all partitions.
 *
 * @return LuceneAllDocumentsReader over all documents
 */
public LuceneAllDocumentsReader allDocumentsReader() {
    ensureOpen();
    List<SearcherReference> searchers = new ArrayList<>(partitions.size());
    try {
        for (AbstractIndexPartition partition : partitions) {
            searchers.add(partition.acquireSearcher());
        }
        List<LucenePartitionAllDocumentsReader> partitionReaders = searchers.stream().map(LucenePartitionAllDocumentsReader::new).collect(toList());
        return new LuceneAllDocumentsReader(partitionReaders);
    } catch (IOException e) {
        IOUtils.closeAllSilently(searchers);
        throw new UncheckedIOException(e);
    }
}
Also used : ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) AbstractIndexPartition(org.neo4j.kernel.api.impl.index.partition.AbstractIndexPartition)

Example 13 with AbstractIndexPartition

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

the class AbstractLuceneIndex method snapshot.

/**
 * Snapshot of all file in all index partitions.
 *
 * @return iterator over all index files.
 * @throws IOException
 * @see WritableIndexSnapshotFileIterator
 */
public ResourceIterator<Path> snapshot() throws IOException {
    ensureOpen();
    List<ResourceIterator<Path>> snapshotIterators = null;
    try {
        List<AbstractIndexPartition> partitions = getPartitions();
        snapshotIterators = new ArrayList<>(partitions.size());
        for (AbstractIndexPartition partition : partitions) {
            snapshotIterators.add(partition.snapshot());
        }
        return Iterators.concatResourceIterators(snapshotIterators.iterator());
    } catch (Exception e) {
        if (snapshotIterators != null) {
            try {
                IOUtils.closeAll(snapshotIterators);
            } catch (IOException ex) {
                e.addSuppressed(ex);
            }
        }
        throw e;
    }
}
Also used : IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) ResourceIterator(org.neo4j.graphdb.ResourceIterator) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) 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