Search in sources :

Example 36 with IndexSample

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

the class MultipleIndexPopulatorTest method shouldIncludeIndexSampleUpdatesInStatsOnFlip.

@Test
void shouldIncludeIndexSampleUpdatesInStatsOnFlip() {
    IndexProxyFactory indexProxyFactory = mock(IndexProxyFactory.class);
    FailedIndexProxyFactory failedIndexProxyFactory = mock(FailedIndexProxyFactory.class);
    FlippableIndexProxy flipper = new FlippableIndexProxy();
    flipper.setFlipTarget(indexProxyFactory);
    IndexPopulator indexPopulator = createIndexPopulator();
    addPopulator(indexPopulator, 1, flipper, failedIndexProxyFactory);
    int indexSize = 100;
    int uniqueValues = 110;
    int sampleSize = 120;
    int updates = 130;
    IndexSample sample = new IndexSample(indexSize, uniqueValues, sampleSize, updates);
    when(indexPopulator.sample(any(CursorContext.class))).thenReturn(sample);
    multipleIndexPopulator.createStoreScan(PageCacheTracer.NULL);
    multipleIndexPopulator.flipAfterStoreScan(false, NULL);
    verify(indexPopulator).close(true, NULL);
    verify(indexStatisticsStore).replaceStats(1, sample);
    verify(schemaState).clear();
}
Also used : IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) IndexSample(org.neo4j.kernel.api.index.IndexSample) CursorContext(org.neo4j.io.pagecache.context.CursorContext) Test(org.junit.jupiter.api.Test)

Example 37 with IndexSample

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

the class UniqueDatabaseIndexSamplerTest method uniqueSamplingUseDocumentsNumber.

@Test
void uniqueSamplingUseDocumentsNumber() throws IndexNotFoundKernelException {
    when(indexSearcher.getIndexReader().numDocs()).thenReturn(17);
    UniqueLuceneIndexSampler sampler = new UniqueLuceneIndexSampler(indexSearcher, taskControl);
    IndexSample sample = sampler.sampleIndex(NULL);
    assertEquals(17, sample.indexSize());
}
Also used : IndexSample(org.neo4j.kernel.api.index.IndexSample) Test(org.junit.jupiter.api.Test)

Example 38 with IndexSample

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

the class LuceneSchemaIndexPopulationIT method partitionedIndexPopulation.

@ParameterizedTest
@ValueSource(ints = { 7, 11, 14, 20, 35, 58 })
void partitionedIndexPopulation(int affectedNodes) throws Exception {
    Path rootFolder = testDir.directory("partitionIndex" + affectedNodes).resolve("uniqueIndex" + affectedNodes);
    try (SchemaIndex uniqueIndex = LuceneSchemaIndexBuilder.create(descriptor, writable(), Config.defaults()).withFileSystem(fileSystem).withIndexRootFolder(rootFolder).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, SIMPLE_TOKEN_LOOKUP)) {
            generateUpdates(indexAccessor, affectedNodes);
            indexAccessor.force(NULL);
            // now index is online and should contain updates data
            assertTrue(uniqueIndex.isOnline());
            try (var indexReader = indexAccessor.newValueReader();
                NodeValueIterator results = new NodeValueIterator();
                IndexSampler indexSampler = indexReader.createSampler()) {
                indexReader.query(NULL_CONTEXT, results, unconstrained(), PropertyIndexQuery.exists(1));
                long[] nodes = PrimitiveLongCollections.asArray(results);
                assertEquals(affectedNodes, nodes.length);
                IndexSample sample = indexSampler.sampleIndex(NULL);
                assertEquals(affectedNodes, sample.indexSize());
                assertEquals(affectedNodes, sample.uniqueValues());
                assertEquals(affectedNodes, sample.sampleSize());
            }
        }
    }
}
Also used : Path(java.nio.file.Path) NodeValueIterator(org.neo4j.kernel.impl.index.schema.NodeValueIterator) LuceneIndexAccessor(org.neo4j.kernel.api.impl.schema.LuceneIndexAccessor) IndexSample(org.neo4j.kernel.api.index.IndexSample) SchemaIndex(org.neo4j.kernel.api.impl.schema.SchemaIndex) IndexSampler(org.neo4j.kernel.api.index.IndexSampler) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 39 with IndexSample

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

the class NonUniqueDatabaseIndexPopulatorTest method sampleEmptyIndex.

@Test
void sampleEmptyIndex() {
    populator = newPopulator();
    IndexSample sample = populator.sample(NULL);
    assertEquals(new IndexSample(), sample);
}
Also used : IndexSample(org.neo4j.kernel.api.index.IndexSample) Test(org.junit.jupiter.api.Test)

Example 40 with IndexSample

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

the class DefaultNonUniqueIndexSamplerTest method assertSampledValues.

private static void assertSampledValues(NonUniqueIndexSampler sampler, long expectedIndexSize, long expectedUniqueValues, long expectedSampledSize) {
    IndexSample sample = sampler.sample(NULL);
    assertEquals(expectedIndexSize, sample.indexSize());
    assertEquals(expectedUniqueValues, sample.uniqueValues());
    assertEquals(expectedSampledSize, sample.sampleSize());
}
Also used : IndexSample(org.neo4j.kernel.api.index.IndexSample)

Aggregations

IndexSample (org.neo4j.kernel.api.index.IndexSample)56 Test (org.junit.jupiter.api.Test)43 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)14 CursorContext (org.neo4j.io.pagecache.context.CursorContext)13 IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)10 IndexAccessor (org.neo4j.kernel.api.index.IndexAccessor)8 IndexEntryUpdate (org.neo4j.storageengine.api.IndexEntryUpdate)8 NodePropertyAccessor (org.neo4j.storageengine.api.NodePropertyAccessor)8 IndexProvider (org.neo4j.kernel.api.index.IndexProvider)7 IndexSampler (org.neo4j.kernel.api.index.IndexSampler)7 ArrayList (java.util.ArrayList)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 Config (org.neo4j.configuration.Config)6 Transaction (org.neo4j.graphdb.Transaction)6 IOException (java.io.IOException)5 Path (java.nio.file.Path)4 Arrays.asList (java.util.Arrays.asList)4 HashSet (java.util.HashSet)4 Set (java.util.Set)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4