Search in sources :

Example 1 with IndexSampler

use of org.neo4j.storageengine.api.schema.IndexSampler in project neo4j by neo4j.

the class PartitionedIndexReaderTest method samplingOverPartitions.

@Test
public void samplingOverPartitions() throws IndexNotFoundKernelException {
    PartitionedIndexReader indexReader = createPartitionedReaderFromReaders();
    when(indexReader1.createSampler()).thenReturn(new SimpleSampler(1));
    when(indexReader2.createSampler()).thenReturn(new SimpleSampler(2));
    when(indexReader3.createSampler()).thenReturn(new SimpleSampler(3));
    IndexSampler sampler = indexReader.createSampler();
    assertEquals(new IndexSample(6, 6, 6), sampler.sampleIndex());
}
Also used : IndexSample(org.neo4j.storageengine.api.schema.IndexSample) IndexSampler(org.neo4j.storageengine.api.schema.IndexSampler) Test(org.junit.Test)

Example 2 with IndexSampler

use of org.neo4j.storageengine.api.schema.IndexSampler in project neo4j by neo4j.

the class LuceneSchemaIndexPopulationIT method partitionedIndexPopulation.

@Test
public void partitionedIndexPopulation() throws Exception {
    try (SchemaIndex uniqueIndex = LuceneSchemaIndexBuilder.create(descriptor).withFileSystem(fileSystemRule.get()).withIndexRootFolder(testDir.directory("partitionIndex" + affectedNodes)).withIndexIdentifier("uniqueIndex" + affectedNodes).build()) {
        uniqueIndex.open();
        // index is empty and not yet exist
        assertEquals(0, uniqueIndex.allDocumentsReader().maxCount());
        assertFalse(uniqueIndex.exists());
        try (LuceneIndexAccessor indexAccessor = new LuceneIndexAccessor(uniqueIndex, descriptor)) {
            generateUpdates(indexAccessor, affectedNodes);
            indexAccessor.force();
            // now index is online and should contain updates data
            assertTrue(uniqueIndex.isOnline());
            try (IndexReader indexReader = indexAccessor.newReader()) {
                long[] nodes = PrimitiveLongCollections.asArray(indexReader.query(IndexQuery.exists(1)));
                assertEquals(affectedNodes, nodes.length);
                IndexSampler indexSampler = indexReader.createSampler();
                IndexSample sample = indexSampler.sampleIndex();
                assertEquals(affectedNodes, sample.indexSize());
                assertEquals(affectedNodes, sample.uniqueValues());
                assertEquals(affectedNodes, sample.sampleSize());
            }
        }
    }
}
Also used : LuceneIndexAccessor(org.neo4j.kernel.api.impl.schema.LuceneIndexAccessor) IndexSample(org.neo4j.storageengine.api.schema.IndexSample) SchemaIndex(org.neo4j.kernel.api.impl.schema.SchemaIndex) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) IndexSampler(org.neo4j.storageengine.api.schema.IndexSampler) Test(org.junit.Test)

Example 3 with IndexSampler

use of org.neo4j.storageengine.api.schema.IndexSampler in project neo4j by neo4j.

the class DirectNonUniqueIndexSampler method result.

@Override
public IndexSample result() {
    try {
        // lucene index needs to be flushed to be sure that reader will see all the data :(
        luceneIndex.flush();
        luceneIndex.maybeRefreshBlocking();
        try (IndexReader indexReader = luceneIndex.getIndexReader()) {
            IndexSampler sampler = indexReader.createSampler();
            return sampler.sampleIndex();
        } catch (IOException | IndexNotFoundKernelException e) {
            throw new RuntimeException(e);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : IndexReader(org.neo4j.storageengine.api.schema.IndexReader) IOException(java.io.IOException) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) NonUniqueIndexSampler(org.neo4j.kernel.impl.api.index.sampling.NonUniqueIndexSampler) IndexSampler(org.neo4j.storageengine.api.schema.IndexSampler)

Example 4 with IndexSampler

use of org.neo4j.storageengine.api.schema.IndexSampler in project neo4j by neo4j.

the class DatabaseCompositeIndexAccessorTest method shouldStopSamplingWhenIndexIsDropped.

@Test
public void shouldStopSamplingWhenIndexIsDropped() throws Exception {
    // given
    updateAndCommit(asList(add(nodeId, values), add(nodeId2, values2)));
    // when
    // needs to be acquired before drop() is called
    IndexReader indexReader = accessor.newReader();
    IndexSampler indexSampler = indexReader.createSampler();
    Future<Void> drop = threading.executeAndAwait(new IOFunction<Void, Void>() {

        @Override
        public Void apply(Void nothing) throws IOException {
            accessor.drop();
            return nothing;
        }
    }, null, waitingWhileIn(TaskCoordinator.class, "awaitCompletion"), 3, SECONDS);
    try (IndexReader reader = indexReader) /* do not inline! */
    {
        indexSampler.sampleIndex();
        fail("expected exception");
    } catch (IndexNotFoundKernelException e) {
        assertEquals("Index dropped while sampling.", e.getMessage());
    } finally {
        drop.get();
    }
}
Also used : IndexReader(org.neo4j.storageengine.api.schema.IndexReader) TaskCoordinator(org.neo4j.helpers.TaskCoordinator) IOException(java.io.IOException) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) IndexSampler(org.neo4j.storageengine.api.schema.IndexSampler) Test(org.junit.Test)

Example 5 with IndexSampler

use of org.neo4j.storageengine.api.schema.IndexSampler in project neo4j by neo4j.

the class DatabaseIndexAccessorTest method shouldStopSamplingWhenIndexIsDropped.

@Test
public void shouldStopSamplingWhenIndexIsDropped() throws Exception {
    // given
    updateAndCommit(asList(add(nodeId, value), add(nodeId2, value2)));
    // when
    // needs to be acquired before drop() is called
    IndexReader indexReader = accessor.newReader();
    IndexSampler indexSampler = indexReader.createSampler();
    Future<Void> drop = threading.executeAndAwait((IOFunction<Void, Void>) nothing -> {
        accessor.drop();
        return nothing;
    }, null, waitingWhileIn(TaskCoordinator.class, "awaitCompletion"), 3, SECONDS);
    try (IndexReader reader = indexReader) /* do not inline! */
    {
        indexSampler.sampleIndex();
        fail("expected exception");
    } catch (IndexNotFoundKernelException e) {
        assertEquals("Index dropped while sampling.", e.getMessage());
    } finally {
        drop.get();
    }
}
Also used : DirectoryFactory(org.neo4j.kernel.api.impl.index.storage.DirectoryFactory) Arrays(java.util.Arrays) EphemeralFileSystemRule(org.neo4j.test.rule.fs.EphemeralFileSystemRule) Iterators.asSet(org.neo4j.helpers.collection.Iterators.asSet) RunWith(org.junit.runner.RunWith) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) TaskCoordinator(org.neo4j.helpers.TaskCoordinator) Assert.assertThat(org.junit.Assert.assertThat) Future(java.util.concurrent.Future) IndexEntryConflictException(org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Arrays.asList(java.util.Arrays.asList) After(org.junit.After) IndexQuery.exact(org.neo4j.kernel.api.schema_new.IndexQuery.exact) Assert.fail(org.junit.Assert.fail) IndexUpdateMode(org.neo4j.kernel.impl.api.index.IndexUpdateMode) ClassRule(org.junit.ClassRule) Parameterized(org.junit.runners.Parameterized) Before(org.junit.Before) PrimitiveLongCollections(org.neo4j.collection.primitive.PrimitiveLongCollections) IndexQuery(org.neo4j.kernel.api.schema_new.IndexQuery) Collection(java.util.Collection) IndexEntryUpdate(org.neo4j.kernel.api.index.IndexEntryUpdate) NewIndexDescriptorFactory(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptorFactory) Test(org.junit.Test) IOException(java.io.IOException) IndexQuery.range(org.neo4j.kernel.api.schema_new.IndexQuery.range) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) IOFunction(org.neo4j.function.IOFunction) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) File(java.io.File) List(java.util.List) Rule(org.junit.Rule) ThreadingRule(org.neo4j.test.rule.concurrent.ThreadingRule) IndexSampler(org.neo4j.storageengine.api.schema.IndexSampler) Iterators.emptySetOf(org.neo4j.helpers.collection.Iterators.emptySetOf) ThreadingRule.waitingWhileIn(org.neo4j.test.rule.concurrent.ThreadingRule.waitingWhileIn) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Assert.assertEquals(org.junit.Assert.assertEquals) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) TaskCoordinator(org.neo4j.helpers.TaskCoordinator) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) IndexSampler(org.neo4j.storageengine.api.schema.IndexSampler) Test(org.junit.Test)

Aggregations

IndexSampler (org.neo4j.storageengine.api.schema.IndexSampler)5 Test (org.junit.Test)4 IndexReader (org.neo4j.storageengine.api.schema.IndexReader)4 IOException (java.io.IOException)3 IndexNotFoundKernelException (org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException)3 TaskCoordinator (org.neo4j.helpers.TaskCoordinator)2 IndexSample (org.neo4j.storageengine.api.schema.IndexSample)2 File (java.io.File)1 Arrays (java.util.Arrays)1 Arrays.asList (java.util.Arrays.asList)1 Collection (java.util.Collection)1 List (java.util.List)1 Future (java.util.concurrent.Future)1 SECONDS (java.util.concurrent.TimeUnit.SECONDS)1 After (org.junit.After)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertThat (org.junit.Assert.assertThat)1 Assert.fail (org.junit.Assert.fail)1 Before (org.junit.Before)1 ClassRule (org.junit.ClassRule)1