Search in sources :

Example 11 with IndexSample

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

the class UniqueDatabaseIndexPopulatingUpdaterTest method verifySamplingResult.

private static void verifySamplingResult(UniqueIndexSampler sampler, long expectedValue) {
    IndexSample sample = sampler.result();
    assertEquals(expectedValue, sample.indexSize());
    assertEquals(expectedValue, sample.uniqueValues());
    assertEquals(expectedValue, sample.sampleSize());
}
Also used : IndexSample(org.neo4j.storageengine.api.schema.IndexSample)

Example 12 with IndexSample

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

the class UniqueDatabaseIndexPopulatorTest method sampleIncludedUpdates.

@Test
public void sampleIncludedUpdates() throws Exception {
    LabelSchemaDescriptor schemaDescriptor = SchemaDescriptorFactory.forLabel(1, 1);
    populator = newPopulator();
    List<IndexEntryUpdate> updates = Arrays.asList(IndexEntryUpdate.add(1, schemaDescriptor, "foo"), IndexEntryUpdate.add(2, schemaDescriptor, "bar"), IndexEntryUpdate.add(3, schemaDescriptor, "baz"), IndexEntryUpdate.add(4, schemaDescriptor, "qux"));
    updates.forEach(populator::includeSample);
    IndexSample sample = populator.sampleResult();
    assertEquals(new IndexSample(4, 4, 4), sample);
}
Also used : IndexEntryUpdate(org.neo4j.kernel.api.index.IndexEntryUpdate) IndexSample(org.neo4j.storageengine.api.schema.IndexSample) LabelSchemaDescriptor(org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor) Test(org.junit.Test)

Example 13 with IndexSample

use of org.neo4j.storageengine.api.schema.IndexSample 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 14 with IndexSample

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

the class AggregatingIndexSamplerTest method samplePartitionedIndex.

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

Example 15 with IndexSample

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

the class OnlineIndexSamplingJob method run.

@Override
public void run() {
    try (DurationLogger durationLogger = new DurationLogger(log, "Sampling index " + indexUserDescription)) {
        try {
            try (IndexReader reader = indexProxy.newReader()) {
                IndexSampler sampler = reader.createSampler();
                IndexSample sample = sampler.sampleIndex();
                // check again if the index is online before saving the counts in the store
                if (indexProxy.getState() == ONLINE) {
                    storeView.replaceIndexCounts(indexId, sample.uniqueValues(), sample.sampleSize(), sample.indexSize());
                    durationLogger.markAsFinished();
                    log.info(format("Sampled index %s with %d unique values in sample of avg size %d taken from " + "index containing %d entries", indexUserDescription, sample.uniqueValues(), sample.sampleSize(), sample.indexSize()));
                } else {
                    durationLogger.markAsAborted("Index no longer ONLINE");
                }
            }
        } catch (IndexNotFoundKernelException e) {
            durationLogger.markAsAborted("Attempted to sample missing/already deleted index " + indexUserDescription);
        }
    }
}
Also used : DurationLogger(org.neo4j.kernel.impl.util.DurationLogger) IndexSample(org.neo4j.storageengine.api.schema.IndexSample) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) IndexSampler(org.neo4j.storageengine.api.schema.IndexSampler)

Aggregations

IndexSample (org.neo4j.storageengine.api.schema.IndexSample)21 Test (org.junit.Test)12 IndexEntryUpdate (org.neo4j.kernel.api.index.IndexEntryUpdate)4 IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)4 IndexSampler (org.neo4j.storageengine.api.schema.IndexSampler)4 Before (org.junit.Before)2 IndexSamplingConfig (org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig)2 IndexReader (org.neo4j.storageengine.api.schema.IndexReader)2 File (java.io.File)1 IOException (java.io.IOException)1 Terms (org.apache.lucene.index.Terms)1 RAMDirectory (org.apache.lucene.store.RAMDirectory)1 IndexNotFoundKernelException (org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException)1 IndexReaderStub (org.neo4j.kernel.api.impl.index.IndexReaderStub)1 PartitionSearcher (org.neo4j.kernel.api.impl.index.partition.PartitionSearcher)1 WritableIndexPartition (org.neo4j.kernel.api.impl.index.partition.WritableIndexPartition)1 LuceneIndexAccessor (org.neo4j.kernel.api.impl.schema.LuceneIndexAccessor)1 SchemaIndex (org.neo4j.kernel.api.impl.schema.SchemaIndex)1 IndexAccessor (org.neo4j.kernel.api.index.IndexAccessor)1 LabelSchemaDescriptor (org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor)1