Search in sources :

Example 1 with IndexSampler

use of org.neo4j.kernel.api.index.IndexSampler in project neo4j by neo4j.

the class NativeIndexAccessorTests method shouldSampleIndex.

@Test
void shouldSampleIndex() throws Exception {
    // given
    ValueIndexEntryUpdate<IndexDescriptor>[] updates = someUpdatesSingleType();
    processAll(updates);
    try (var reader = accessor.newValueReader();
        IndexSampler sampler = reader.createSampler()) {
        // when
        IndexSample sample = sampler.sampleIndex(NULL);
        // then
        assertEquals(updates.length, sample.indexSize());
        assertEquals(updates.length, sample.sampleSize());
        assertEquals(countUniqueValues(updates), sample.uniqueValues());
    }
}
Also used : IndexSample(org.neo4j.kernel.api.index.IndexSample) ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) IndexSampler(org.neo4j.kernel.api.index.IndexSampler) Test(org.junit.jupiter.api.Test)

Example 2 with IndexSampler

use of org.neo4j.kernel.api.index.IndexSampler in project neo4j by neo4j.

the class PartitionedValueIndexReaderTest method samplingOverPartitions.

@Test
void samplingOverPartitions() throws IndexNotFoundKernelException {
    PartitionedValueIndexReader 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(NULL));
}
Also used : IndexSample(org.neo4j.kernel.api.index.IndexSample) IndexSampler(org.neo4j.kernel.api.index.IndexSampler) Test(org.junit.jupiter.api.Test)

Example 3 with IndexSampler

use of org.neo4j.kernel.api.index.IndexSampler in project neo4j by neo4j.

the class AggregatingIndexSamplerTest method samplePartitionedIndex.

@Test
void samplePartitionedIndex() {
    List<IndexSampler> samplers = Arrays.asList(createSampler(1), createSampler(2));
    AggregatingIndexSampler partitionedSampler = new AggregatingIndexSampler(samplers);
    IndexSample sample = partitionedSampler.sampleIndex(NULL);
    assertEquals(new IndexSample(3, 3, 6), sample);
}
Also used : IndexSample(org.neo4j.kernel.api.index.IndexSample) IndexSampler(org.neo4j.kernel.api.index.IndexSampler) Test(org.junit.jupiter.api.Test)

Example 4 with IndexSampler

use of org.neo4j.kernel.api.index.IndexSampler in project neo4j by neo4j.

the class IndexingServiceTest method setUp.

@BeforeEach
void setUp() throws IndexNotFoundKernelException {
    when(populator.sample(any(CursorContext.class))).thenReturn(new IndexSample());
    when(indexStatisticsStore.indexSample(anyLong())).thenReturn(new IndexSample());
    when(storeViewFactory.createTokenIndexStoreView(any())).thenReturn(storeView);
    when(storeView.newPropertyAccessor(any(CursorContext.class), any())).thenReturn(propertyAccessor);
    ValueIndexReader indexReader = mock(ValueIndexReader.class);
    IndexSampler indexSampler = mock(IndexSampler.class);
    when(indexSampler.sampleIndex(any())).thenReturn(new IndexSample());
    when(indexReader.createSampler()).thenReturn(indexSampler);
    when(accessor.newValueReader()).thenReturn(indexReader);
}
Also used : IndexSample(org.neo4j.kernel.api.index.IndexSample) CursorContext(org.neo4j.io.pagecache.context.CursorContext) ValueIndexReader(org.neo4j.kernel.api.index.ValueIndexReader) IndexSampler(org.neo4j.kernel.api.index.IndexSampler) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with IndexSampler

use of org.neo4j.kernel.api.index.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
    var indexReader = accessor.newValueReader();
    BinaryLatch dropLatch = new BinaryLatch();
    BinaryLatch sampleLatch = new BinaryLatch();
    LuceneIndexSampler indexSampler = spy((LuceneIndexSampler) indexReader.createSampler());
    doAnswer(inv -> {
        var obj = inv.callRealMethod();
        // We have now started the sampling, let the index try to drop
        dropLatch.release();
        // Wait for the drop to be blocked
        sampleLatch.await();
        return obj;
    }).when(indexSampler).newTask();
    List<Future<?>> futures = new ArrayList<>();
    try (var reader = indexReader;
        /* do not inline! */
        IndexSampler sampler = indexSampler) /* do not inline! */
    {
        futures.add(threading.execute((IOFunction<Void, Void>) nothing -> {
            try {
                indexSampler.sampleIndex(NULL);
                fail("expected exception");
            } catch (IndexNotFoundKernelException e) {
                assertEquals("Index dropped while sampling.", e.getMessage());
            } finally {
                dropLatch.release();
            }
            return nothing;
        }, null));
        futures.add(threading.executeAndAwait((IOFunction<Void, Void>) nothing -> {
            dropLatch.await();
            accessor.drop();
            return nothing;
        }, null, waitingWhileIn(TaskCoordinator.class, "awaitCompletion"), 10, MINUTES));
    } finally {
        // drop is blocked, okay to finish sampling (will fail since index is dropped)
        sampleLatch.release();
        for (Future<?> future : futures) {
            future.get();
        }
    }
}
Also used : IOFunction(org.neo4j.function.IOFunction) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) BinaryLatch(org.neo4j.util.concurrent.BinaryLatch) IndexSampler(org.neo4j.kernel.api.index.IndexSampler) Test(org.junit.Test)

Aggregations

IndexSampler (org.neo4j.kernel.api.index.IndexSampler)9 IndexSample (org.neo4j.kernel.api.index.IndexSample)7 IndexNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException)4 Test (org.junit.jupiter.api.Test)3 CursorContext (org.neo4j.io.pagecache.context.CursorContext)3 ArrayList (java.util.ArrayList)2 ValueIndexReader (org.neo4j.kernel.api.index.ValueIndexReader)2 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 Path (java.nio.file.Path)1 Future (java.util.concurrent.Future)1 ExceptionUtils.getRootCause (org.apache.commons.lang3.exception.ExceptionUtils.getRootCause)1 Test (org.junit.Test)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 ValueSource (org.junit.jupiter.params.provider.ValueSource)1 IOFunction (org.neo4j.function.IOFunction)1 GBPTree (org.neo4j.index.internal.gbptree.GBPTree)1 Seeker (org.neo4j.index.internal.gbptree.Seeker)1 IndexQueryConstraints (org.neo4j.internal.kernel.api.IndexQueryConstraints)1