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());
}
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);
}
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());
}
}
}
}
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);
}
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);
}
}
}
Aggregations